1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29
import bzrlib.errors as errors
30
from bzrlib.branch import Branch
31
from bzrlib.workingtree import WorkingTree
33
from dialog import about, error_dialog, info_dialog
34
from launch import launch
37
""" Signal handler class for Olive. """
38
def __init__(self, path):
39
self.wt, self.path = WorkingTree.open_containing(path)
41
def on_about_activate(self, widget):
44
def on_menuitem_add_files_activate(self, widget):
45
""" Add file(s)... menu handler. """
46
from add import OliveAdd
47
add = OliveAdd(self.wt, self.path, self.comm.get_selected_right())
50
def on_menuitem_branch_get_activate(self, widget):
51
""" Branch/Get... menu handler. """
52
from branch import OliveBranch
53
branch = OliveBranch()
56
def on_menuitem_branch_checkout_activate(self, widget):
57
""" Branch/Checkout... menu handler. """
58
from checkout import OliveCheckout
59
checkout = OliveCheckout()
62
def on_menuitem_branch_commit_activate(self, widget):
63
""" Branch/Commit... menu handler. """
64
from commit import OliveCommit
65
commit = OliveCommit(self.wt, self.path)
68
def on_menuitem_branch_missing_revisions_activate(self, widget):
69
""" Branch/Missing revisions menu handler. """
71
self.comm.set_busy(self.comm.window_main)
76
local_branch = self.wt.branch
78
other_branch = local_branch.get_parent()
79
if other_branch is None:
80
error_dialog(_('Parent location is unknown'),
81
_('Cannot determine missing revisions if no parent location is known.'))
84
remote_branch = Branch.open(other_branch)
86
if remote_branch.base == local_branch.base:
87
remote_branch = local_branch
89
ret = len(local_branch.missing_revisions(remote_branch))
92
info_dialog(_('There are missing revisions'),
93
_('%d revision(s) missing.') % ret)
95
info_dialog(_('Local branch up to date'),
96
_('There are no missing revisions.'))
98
self.comm.set_busy(self.comm.window_main, False)
100
def on_menuitem_branch_pull_activate(self, widget):
101
""" Branch/Pull menu handler. """
103
self.comm.set_busy(self.comm.window_main)
105
branch_to = self.wt.branch
107
location = branch_to.get_parent()
109
error_dialog(_('Parent location is unknown'),
110
_('Pulling is not possible until there is a parent location.'))
114
branch_from = Branch.open(location)
115
except errors.NotBranchError:
116
error_dialog(_('Directory is not a branch'),
117
_('You can perform this action only in a branch.'))
119
if branch_to.get_parent() is None:
120
branch_to.set_parent(branch_from.base)
122
old_rh = branch_to.revision_history()
123
if tree_to is not None:
124
tree_to.pull(branch_from)
126
branch_to.pull(branch_from)
128
info_dialog(_('Pull successful'), _('%d revision(s) pulled.') % ret)
130
def on_menuitem_branch_push_activate(self, widget):
131
""" Branch/Push... menu handler. """
132
from push import OlivePush
133
push = OlivePush(self.comm)
136
def on_menuitem_branch_status_activate(self, widget):
137
""" Branch/Status... menu handler. """
138
from status import OliveStatus
139
status = OliveStatus(self.wt, self.path)
142
def on_menuitem_branch_initialize_activate(self, widget):
143
""" Initialize current directory. """
145
location = self.comm.get_path()
146
from bzrlib.builtins import get_format_type
148
format = get_format_type('default')
150
if not os.path.exists(location):
154
existing_bzrdir = bzrdir.BzrDir.open(location)
155
except NotBranchError:
156
bzrdir.BzrDir.create_branch_convenience(location, format=format)
158
if existing_bzrdir.has_branch():
159
if existing_bzrdir.has_workingtree():
160
raise AlreadyBranchError(location)
162
raise BranchExistsWithoutWorkingTree(location)
164
existing_bzrdir.create_branch()
165
existing_bzrdir.create_workingtree()
166
except errors.AlreadyBranchError, errmsg:
167
error_dialog(_('Directory is already a branch'),
168
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
169
except errors.BranchExistsWithoutWorkingTree, errmsg:
170
error_dialog(_('Branch without a working tree'),
171
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
173
info_dialog(_('Initialize successful'),
174
_('Directory successfully initialized.'))
175
self.comm.refresh_right()
177
def on_menuitem_file_make_directory_activate(self, widget):
178
""" File/Make directory... menu handler. """
179
from mkdir import OliveMkdir
180
mkdir = OliveMkdir(self.comm)
183
def on_menuitem_file_move_activate(self, widget):
184
""" File/Move... menu handler. """
185
from move import OliveMove
186
move = OliveMove(self.comm)
189
def on_menuitem_file_rename_activate(self, widget):
190
""" File/Rename... menu handler. """
191
from rename import OliveRename
192
rename = OliveRename(self.comm)
195
def on_menuitem_remove_file_activate(self, widget):
196
""" Remove (unversion) selected file. """
197
from remove import OliveRemove
198
remove = OliveRemove(self.comm)
201
def on_menuitem_stats_diff_activate(self, widget):
202
""" Statistics/Differences... menu handler. """
203
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
204
window = DiffWindow()
205
parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
206
window.set_diff(self.wt.branch.nick, self.wt, parent_tree)
209
def on_menuitem_stats_infos_activate(self, widget):
210
""" Statistics/Informations... menu handler. """
211
from info import OliveInfo
212
info = OliveInfo(self.comm)
215
def on_menuitem_stats_log_activate(self, widget):
216
""" Statistics/Log... menu handler. """
217
from log import OliveLog
218
log = OliveLog(self.comm)
221
def on_menuitem_view_refresh_activate(self, widget):
222
""" View/Refresh menu handler. """
223
# Refresh the left pane
224
self.comm.refresh_left()
225
# Refresh the right pane
226
self.comm.refresh_right()
228
def on_menuitem_view_show_hidden_files_activate(self, widget):
229
""" View/Show hidden files menu handler. """
230
if widget.get_active():
232
self.comm.pref.set_preference('dotted_files', True)
233
self.comm.pref.refresh()
234
self.comm.refresh_right()
236
# Do not show hidden files
237
self.comm.pref.set_preference('dotted_files', False)
238
self.comm.pref.refresh()
239
self.comm.refresh_right()
241
def on_treeview_left_button_press_event(self, widget, event):
242
""" Occurs when somebody right-clicks in the bookmark list. """
243
if event.button == 3:
244
# Don't show context with nothing selected
245
if self.comm.get_selected_left() == None:
248
self.menu.left_context_menu().popup(None, None, None, 0,
251
def on_treeview_left_row_activated(self, treeview, path, view_column):
252
""" Occurs when somebody double-clicks or enters an item in the
255
newdir = self.comm.get_selected_left()
259
self.comm.set_busy(treeview)
260
self.comm.set_path(newdir)
261
self.comm.refresh_right()
262
self.comm.set_busy(treeview, False)
264
def on_treeview_right_button_press_event(self, widget, event):
265
""" Occurs when somebody right-clicks in the file list. """
266
if event.button == 3:
268
m_add = self.menu.ui.get_widget('/context_right/add')
269
m_remove = self.menu.ui.get_widget('/context_right/remove')
270
m_commit = self.menu.ui.get_widget('/context_right/commit')
271
m_diff = self.menu.ui.get_widget('/context_right/diff')
272
# check if we're in a branch
274
from bzrlib.branch import Branch
275
Branch.open_containing(self.comm.get_path())
276
m_add.set_sensitive(False)
277
m_remove.set_sensitive(False)
278
m_commit.set_sensitive(False)
279
m_diff.set_sensitive(False)
280
except errors.NotBranchError:
281
m_add.set_sensitive(True)
282
m_remove.set_sensitive(True)
283
m_commit.set_sensitive(True)
284
m_diff.set_sensitive(True)
285
self.menu.right_context_menu().popup(None, None, None, 0,
288
def on_treeview_right_row_activated(self, treeview, path, view_column):
289
""" Occurs when somebody double-clicks or enters an item in the
293
newdir = self.comm.get_selected_right()
296
self.comm.set_path(os.path.split(self.comm.get_path())[0])
298
fullpath = self.comm.get_path() + os.sep + newdir
299
if os.path.isdir(fullpath):
300
# selected item is an existant directory
301
self.comm.set_path(fullpath)
305
self.comm.refresh_right()
307
def on_window_main_delete_event(self, widget, event=None):
308
""" Do some stuff before exiting. """
309
width, height = self.comm.window_main.get_size()
310
self.comm.pref.set_preference('window_width', width)
311
self.comm.pref.set_preference('window_height', height)
312
x, y = self.comm.window_main.get_position()
313
self.comm.pref.set_preference('window_x', x)
314
self.comm.pref.set_preference('window_y', y)
315
self.comm.pref.set_preference('paned_position',
316
self.comm.hpaned_main.get_position())
318
self.comm.pref.write()
319
self.comm.window_main.destroy()