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
31
import bzrlib.errors as errors
32
from bzrlib.branch import Branch
33
from bzrlib.workingtree import WorkingTree
35
from dialog import about, error_dialog, info_dialog
36
from menu import OliveMenu
37
from launch import launch
40
""" Signal handler class for Olive. """
41
def __init__(self, gladefile, comm):
42
self.gladefile = gladefile
45
self.menu = OliveMenu(self.gladefile, self.comm)
47
def on_about_activate(self, widget):
50
def on_menuitem_add_files_activate(self, widget):
51
""" Add file(s)... menu handler. """
52
from add import OliveAdd
53
wt, path = WorkingTree.open_containing(self.comm.get_path())
54
add = OliveAdd(self.gladefile, wt, path,
55
self.comm.get_selected_right())
58
def on_menuitem_branch_get_activate(self, widget):
59
""" Branch/Get... menu handler. """
60
from branch import OliveBranch
61
branch = OliveBranch(self.gladefile, self.comm)
64
def on_menuitem_branch_checkout_activate(self, widget):
65
""" Branch/Checkout... menu handler. """
66
from checkout import OliveCheckout
67
checkout = OliveCheckout(self.gladefile, self.comm)
70
def on_menuitem_branch_commit_activate(self, widget):
71
""" Branch/Commit... menu handler. """
72
from commit import OliveCommit
73
wt, path = WorkingTree.open_containing(self.comm.get_path())
74
commit = OliveCommit(self.gladefile, wt, path)
77
def on_menuitem_branch_missing_revisions_activate(self, widget):
78
""" Branch/Missing revisions menu handler. """
80
self.comm.set_busy(self.comm.window_main)
86
local_branch = Branch.open_containing(self.comm.get_path())[0]
87
except NotBranchError:
88
error_dialog(_('Directory is not a branch'),
89
_('You can perform this action only in a branch.'))
92
other_branch = local_branch.get_parent()
93
if other_branch is None:
94
error_dialog(_('Parent location is unknown'),
95
_('Cannot determine missing revisions if no parent location is known.'))
98
remote_branch = Branch.open(other_branch)
100
if remote_branch.base == local_branch.base:
101
remote_branch = local_branch
103
ret = len(local_branch.missing_revisions(remote_branch))
106
info_dialog(_('There are missing revisions'),
107
_('%d revision(s) missing.') % ret)
109
info_dialog(_('Local branch up to date'),
110
_('There are no missing revisions.'))
112
self.comm.set_busy(self.comm.window_main, False)
114
def on_menuitem_branch_pull_activate(self, widget):
115
""" Branch/Pull menu handler. """
117
self.comm.set_busy(self.comm.window_main)
121
from bzrlib.workingtree import WorkingTree
122
tree_to = WorkingTree.open_containing(self.comm.get_path())[0]
123
branch_to = tree_to.branch
124
except errors.NoWorkingTree:
126
branch_to = Branch.open_containing(self.comm.get_path())[0]
127
except errors.NotBranchError:
128
error_dialog(_('Directory is not a branch'),
129
_('You can perform this action only in a branch.'))
131
location = branch_to.get_parent()
133
error_dialog(_('Parent location is unknown'),
134
_('Pulling is not possible until there is a parent location.'))
138
branch_from = Branch.open(location)
139
except errors.NotBranchError:
140
error_dialog(_('Directory is not a branch'),
141
_('You can perform this action only in a branch.'))
143
if branch_to.get_parent() is None:
144
branch_to.set_parent(branch_from.base)
146
old_rh = branch_to.revision_history()
147
if tree_to is not None:
148
tree_to.pull(branch_from)
150
branch_to.pull(branch_from)
152
info_dialog(_('Pull successful'),
153
_('%d revision(s) pulled.') % ret)
156
self.comm.set_busy(self.comm.window_main, False)
158
def on_menuitem_branch_push_activate(self, widget):
159
""" Branch/Push... menu handler. """
160
from push import OlivePush
161
push = OlivePush(self.gladefile, self.comm)
164
def on_menuitem_branch_status_activate(self, widget):
165
""" Branch/Status... menu handler. """
166
from status import OliveStatus
167
wt, wtpath = WorkingTree.open_containing(self.comm.get_path())
168
status = OliveStatus(self.gladefile, wt, wtpath)
171
def on_menuitem_branch_initialize_activate(self, widget):
172
""" Initialize current directory. """
174
location = self.comm.get_path()
175
from bzrlib.builtins import get_format_type
177
format = get_format_type('default')
179
if not os.path.exists(location):
183
existing_bzrdir = bzrdir.BzrDir.open(location)
184
except NotBranchError:
185
bzrdir.BzrDir.create_branch_convenience(location, format=format)
187
if existing_bzrdir.has_branch():
188
if existing_bzrdir.has_workingtree():
189
raise AlreadyBranchError(location)
191
raise BranchExistsWithoutWorkingTree(location)
193
existing_bzrdir.create_branch()
194
existing_bzrdir.create_workingtree()
195
except errors.AlreadyBranchError, errmsg:
196
error_dialog(_('Directory is already a branch'),
197
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
198
except errors.BranchExistsWithoutWorkingTree, errmsg:
199
error_dialog(_('Branch without a working tree'),
200
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
202
info_dialog(_('Initialize successful'),
203
_('Directory successfully initialized.'))
204
self.comm.refresh_right()
206
def on_menuitem_file_make_directory_activate(self, widget):
207
""" File/Make directory... menu handler. """
208
from mkdir import OliveMkdir
209
mkdir = OliveMkdir(self.gladefile, self.comm)
212
def on_menuitem_file_move_activate(self, widget):
213
""" File/Move... menu handler. """
214
from move import OliveMove
215
move = OliveMove(self.gladefile, self.comm)
218
def on_menuitem_file_rename_activate(self, widget):
219
""" File/Rename... menu handler. """
220
from rename import OliveRename
221
rename = OliveRename(self.gladefile, self.comm)
224
def on_menuitem_remove_file_activate(self, widget):
225
""" Remove (unversion) selected file. """
226
from remove import OliveRemove
227
remove = OliveRemove(self.gladefile, self.comm)
230
def on_menuitem_stats_diff_activate(self, widget):
231
""" Statistics/Differences... menu handler. """
232
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
233
window = DiffWindow()
234
wt = WorkingTree.open_containing(self.comm.get_path())[0]
235
parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
236
window.set_diff(wt.branch.nick, wt, parent_tree)
239
def on_menuitem_stats_infos_activate(self, widget):
240
""" Statistics/Informations... menu handler. """
241
from info import OliveInfo
242
info = OliveInfo(self.gladefile, self.comm)
245
def on_menuitem_stats_log_activate(self, widget):
246
""" Statistics/Log... menu handler. """
247
from log import OliveLog
248
log = OliveLog(self.gladefile, self.comm)
251
def on_menuitem_view_refresh_activate(self, widget):
252
""" View/Refresh menu handler. """
253
# Refresh the left pane
254
self.comm.refresh_left()
255
# Refresh the right pane
256
self.comm.refresh_right()
258
def on_menuitem_view_show_hidden_files_activate(self, widget):
259
""" View/Show hidden files menu handler. """
260
if widget.get_active():
262
self.comm.pref.set_preference('dotted_files', True)
263
self.comm.pref.refresh()
264
self.comm.refresh_right()
266
# Do not show hidden files
267
self.comm.pref.set_preference('dotted_files', False)
268
self.comm.pref.refresh()
269
self.comm.refresh_right()
271
def on_treeview_left_button_press_event(self, widget, event):
272
""" Occurs when somebody right-clicks in the bookmark list. """
273
if event.button == 3:
274
# Don't show context with nothing selected
275
if self.comm.get_selected_left() == None:
278
self.menu.left_context_menu().popup(None, None, None, 0,
281
def on_treeview_left_row_activated(self, treeview, path, view_column):
282
""" Occurs when somebody double-clicks or enters an item in the
285
newdir = self.comm.get_selected_left()
289
self.comm.set_busy(treeview)
290
self.comm.set_path(newdir)
291
self.comm.refresh_right()
292
self.comm.set_busy(treeview, False)
294
def on_treeview_right_button_press_event(self, widget, event):
295
""" Occurs when somebody right-clicks in the file list. """
296
if event.button == 3:
298
m_add = self.menu.ui.get_widget('/context_right/add')
299
m_remove = self.menu.ui.get_widget('/context_right/remove')
300
m_commit = self.menu.ui.get_widget('/context_right/commit')
301
m_diff = self.menu.ui.get_widget('/context_right/diff')
302
# check if we're in a branch
304
from bzrlib.branch import Branch
305
Branch.open_containing(self.comm.get_path())
306
m_add.set_sensitive(False)
307
m_remove.set_sensitive(False)
308
m_commit.set_sensitive(False)
309
m_diff.set_sensitive(False)
310
except errors.NotBranchError:
311
m_add.set_sensitive(True)
312
m_remove.set_sensitive(True)
313
m_commit.set_sensitive(True)
314
m_diff.set_sensitive(True)
315
self.menu.right_context_menu().popup(None, None, None, 0,
318
def on_treeview_right_row_activated(self, treeview, path, view_column):
319
""" Occurs when somebody double-clicks or enters an item in the
323
newdir = self.comm.get_selected_right()
326
self.comm.set_path(os.path.split(self.comm.get_path())[0])
328
fullpath = self.comm.get_path() + os.sep + newdir
329
if os.path.isdir(fullpath):
330
# selected item is an existant directory
331
self.comm.set_path(fullpath)
335
self.comm.refresh_right()
337
def on_window_main_delete_event(self, widget, event=None):
338
""" Do some stuff before exiting. """
339
width, height = self.comm.window_main.get_size()
340
self.comm.pref.set_preference('window_width', width)
341
self.comm.pref.set_preference('window_height', height)
342
x, y = self.comm.window_main.get_position()
343
self.comm.pref.set_preference('window_x', x)
344
self.comm.pref.set_preference('window_y', y)
345
self.comm.pref.set_preference('paned_position',
346
self.comm.hpaned_main.get_position())
348
self.comm.pref.write()
349
self.comm.window_main.destroy()