Class: Fugit::TabToolbar

Inherits:
ToolBar
  • Object
show all
Defined in:
lib/fugit/tab_toolbar.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, is_commit_bar = true) ⇒ TabToolbar

Returns a new instance of TabToolbar.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/fugit/tab_toolbar.rb', line 6

def initialize(parent, is_commit_bar = true)
	super(parent, ID_ANY, nil, nil, TB_HORIZONTAL|NO_BORDER|TB_NODIVIDER)

	self.set_tool_bitmap_size(Size.new(16,16))

	if is_commit_bar
		stage_all_button = self.add_tool(ID_ANY, "Stage all", get_icon("folder_add.png"), "Stage all")
		evt_tool(stage_all_button, :on_stage_all_clicked)

		stage_button = self.add_tool(ID_ANY, "Stage", get_icon("page_add.png"), "Stage changed files")
		evt_tool(stage_button, :on_stage_changed_clicked)

		unstage_all_button = self.add_tool(ID_ANY, "Unstage all", get_icon("folder_delete.png"), "Unstage all")
		evt_tool(unstage_all_button, :on_unstage_all_clicked)

		self.add_separator

		commit = self.add_tool(ID_ANY, "Commit", get_icon("disk.png"), "Commit")
		evt_tool(commit, :on_commit_clicked)
	end

	refresh = self.add_tool(ID_ANY, "Refresh", get_icon("arrow_refresh.png"), "Refresh")
	evt_tool(refresh, :on_refresh_clicked)

	self.add_separator

	push = self.add_tool(ID_ANY, "Push", get_icon("page_up.gif"), "Push")
	evt_tool(push, :on_push_clicked)

	fetch = self.add_tool(ID_ANY, "Fetch", get_icon("page_down.gif"), "Fetch")
	evt_tool(fetch, :on_fetch_clicked)

	self.add_separator

	self.add_control(@branch = Choice.new(self, ID_ANY))
	set_branches
	evt_choice(@branch, :on_branch_choice)

	create_branch_button = self.add_tool(ID_ANY, "Create branch", get_icon("arrow_divide_add.png"), "Create branch")
	evt_tool(create_branch_button, :on_create_branch_clicked)

	merge_branch_button = self.add_tool(ID_ANY, "Merge branch", get_icon("arrow_join.png"), "Merge branch")
	evt_tool(merge_branch_button, :on_merge_branch_clicked)

	delete_branch_button = self.add_tool(ID_ANY, "Delete branch", get_icon("arrow_divide_delete.png"), "Delete branch")
	evt_tool(delete_branch_button, :on_delete_branch_clicked)

	self.add_separator

	run_command_button = self.add_tool(ID_ANY, "Run command", get_icon("application_go.png"), "Run command")
	evt_tool(run_command_button, :on_run_command_clicked)

	self.realize

	register_for_message(:tab_switch, :update_tools)
	register_for_message(:branch_created, :update_tools)
	register_for_message(:branch_deleted, :update_tools)
	register_for_message(:refresh, :update_tools)
	register_for_message(:save_clicked, :on_commit_clicked)
	register_for_message(:push_clicked, :on_push_clicked)
end

Instance Method Details

#on_branch_choice(event) ⇒ Object



113
114
115
116
117
118
119
120
121
122
# File 'lib/fugit/tab_toolbar.rb', line 113

def on_branch_choice(event)
	branch = @branch.get_string(event.get_selection)
	success, err = repo.checkout(branch)
	if success
		send_message(:branch_checkout)
	else
		MessageDialog.new(self, err, "Branch checkout error", OK|ICON_ERROR).show_modal
		@branch.set_string_selection(repo.head.name)
	end
end

#on_commit_clickedObject



94
95
96
97
# File 'lib/fugit/tab_toolbar.rb', line 94

def on_commit_clicked
	@commit_dialog ||= CommitDialog.new(self)
	send_message(:commit_saved) if @commit_dialog.show_modal == ID_OK
end

#on_create_branch_clickedObject



124
125
126
127
# File 'lib/fugit/tab_toolbar.rb', line 124

def on_create_branch_clicked
	@create_branch_dialog ||= CreateBranchDialog.new(self)
	@create_branch_dialog.show
end

#on_delete_branch_clickedObject



129
130
131
132
# File 'lib/fugit/tab_toolbar.rb', line 129

def on_delete_branch_clicked
	@delete_branch_dialog ||= DeleteBranchDialog.new(self)
	@delete_branch_dialog.show
end

#on_fetch_clickedObject



108
109
110
111
# File 'lib/fugit/tab_toolbar.rb', line 108

def on_fetch_clicked
	@fetch_dialog ||= FetchDialog.new(self)
	@fetch_dialog.show
end

#on_merge_branch_clickedObject



134
135
136
137
# File 'lib/fugit/tab_toolbar.rb', line 134

def on_merge_branch_clicked
	@merge_branch_dialog ||= MergeDialog.new(self)
	@merge_branch_dialog.show
end

#on_push_clickedObject



103
104
105
106
# File 'lib/fugit/tab_toolbar.rb', line 103

def on_push_clicked
	@push_dialog ||= PushDialog.new(self)
	@push_dialog.show
end

#on_refresh_clickedObject



99
100
101
# File 'lib/fugit/tab_toolbar.rb', line 99

def on_refresh_clicked
	send_message(:refresh)
end

#on_run_command_clickedObject



139
140
141
142
# File 'lib/fugit/tab_toolbar.rb', line 139

def on_run_command_clicked
	@run_command_dialog ||= RunCommandDialog.new(self)
	@run_command_dialog.show
end

#on_stage_all_clicked(event) ⇒ Object



79
80
81
82
# File 'lib/fugit/tab_toolbar.rb', line 79

def on_stage_all_clicked(event)
	repo.add_all
	send_message(:index_changed)
end

#on_stage_changed_clicked(event) ⇒ Object



84
85
86
87
# File 'lib/fugit/tab_toolbar.rb', line 84

def on_stage_changed_clicked(event)
	repo.add_updated
	send_message(:index_changed)
end

#on_unstage_all_clicked(event) ⇒ Object



89
90
91
92
# File 'lib/fugit/tab_toolbar.rb', line 89

def on_unstage_all_clicked(event)
	repo.reset_all
	send_message(:index_changed)
end

#set_branchesObject



73
74
75
76
77
# File 'lib/fugit/tab_toolbar.rb', line 73

def set_branches
	@branch.clear
	repo.branches.each {|b| @branch.append(b.name)}
	@branch.set_string_selection(repo.head.name)
end

#update_toolsObject



68
69
70
71
# File 'lib/fugit/tab_toolbar.rb', line 68

def update_tools
	return unless is_shown_on_screen
	set_branches
end