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. """
73
local_branch = self.wt.branch
75
other_branch = local_branch.get_parent()
76
if other_branch is None:
77
error_dialog(_('Parent location is unknown'),
78
_('Cannot determine missing revisions if no parent location is known.'))
81
remote_branch = Branch.open(other_branch)
83
if remote_branch.base == local_branch.base:
84
remote_branch = local_branch
86
ret = len(local_branch.missing_revisions(remote_branch))
89
info_dialog(_('There are missing revisions'),
90
_('%d revision(s) missing.') % ret)
92
info_dialog(_('Local branch up to date'),
93
_('There are no missing revisions.'))
95
def on_menuitem_branch_pull_activate(self, widget):
96
""" Branch/Pull menu handler. """
98
branch_to = self.wt.branch
100
location = branch_to.get_parent()
102
error_dialog(_('Parent location is unknown'),
103
_('Pulling is not possible until there is a parent location.'))
107
branch_from = Branch.open(location)
108
except errors.NotBranchError:
109
error_dialog(_('Directory is not a branch'),
110
_('You can perform this action only in a branch.'))
112
if branch_to.get_parent() is None:
113
branch_to.set_parent(branch_from.base)
115
old_rh = branch_to.revision_history()
116
if tree_to is not None:
117
tree_to.pull(branch_from)
119
branch_to.pull(branch_from)
121
info_dialog(_('Pull successful'), _('%d revision(s) pulled.') % ret)
123
def on_menuitem_branch_push_activate(self, widget):
124
""" Branch/Push... menu handler. """
125
from push import OlivePush
126
push = OlivePush(self.comm)
129
def on_menuitem_branch_status_activate(self, widget):
130
""" Branch/Status... menu handler. """
131
from status import OliveStatus
132
status = OliveStatus(self.wt, self.path)
135
def on_menuitem_branch_initialize_activate(self, widget):
136
""" Initialize current directory. """
138
location = self.comm.get_path()
139
from bzrlib.builtins import get_format_type
141
format = get_format_type('default')
143
if not os.path.exists(location):
147
existing_bzrdir = bzrdir.BzrDir.open(location)
148
except NotBranchError:
149
bzrdir.BzrDir.create_branch_convenience(location, format=format)
151
if existing_bzrdir.has_branch():
152
if existing_bzrdir.has_workingtree():
153
raise AlreadyBranchError(location)
155
raise BranchExistsWithoutWorkingTree(location)
157
existing_bzrdir.create_branch()
158
existing_bzrdir.create_workingtree()
159
except errors.AlreadyBranchError, errmsg:
160
error_dialog(_('Directory is already a branch'),
161
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
162
except errors.BranchExistsWithoutWorkingTree, errmsg:
163
error_dialog(_('Branch without a working tree'),
164
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
166
info_dialog(_('Initialize successful'),
167
_('Directory successfully initialized.'))
168
self.comm.refresh_right()
170
def on_menuitem_file_make_directory_activate(self, widget):
171
""" File/Make directory... menu handler. """
172
from mkdir import OliveMkdir
173
mkdir = OliveMkdir(self.comm)
176
def on_menuitem_file_move_activate(self, widget):
177
""" File/Move... menu handler. """
178
from move import OliveMove
179
move = OliveMove(self.comm)
182
def on_menuitem_file_rename_activate(self, widget):
183
""" File/Rename... menu handler. """
184
from rename import OliveRename
185
rename = OliveRename(self.comm)
188
def on_menuitem_remove_file_activate(self, widget):
189
""" Remove (unversion) selected file. """
190
from remove import OliveRemove
191
remove = OliveRemove(self.comm)
194
def on_menuitem_stats_diff_activate(self, widget):
195
""" Statistics/Differences... menu handler. """
196
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
197
window = DiffWindow()
198
parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
199
window.set_diff(self.wt.branch.nick, self.wt, parent_tree)
202
def on_menuitem_stats_infos_activate(self, widget):
203
""" Statistics/Informations... menu handler. """
204
from info import OliveInfo
205
info = OliveInfo(self.wt)
208
def on_menuitem_stats_log_activate(self, widget):
209
""" Statistics/Log... menu handler. """
210
from bzrlib.plugins.gtk.viz.branchwin import BranchWindow
211
window = BranchWindow()
212
window.set_branch(self.wt.branch, self.wt.branch.last_revision(), None)
215
def on_menuitem_view_refresh_activate(self, widget):
216
""" View/Refresh menu handler. """
217
# Refresh the left pane
218
self.comm.refresh_left()
219
# Refresh the right pane
220
self.comm.refresh_right()
222
def on_menuitem_view_show_hidden_files_activate(self, widget):
223
""" View/Show hidden files menu handler. """
224
if widget.get_active():
226
self.comm.pref.set_preference('dotted_files', True)
227
self.comm.pref.refresh()
228
self.comm.refresh_right()
230
# Do not show hidden files
231
self.comm.pref.set_preference('dotted_files', False)
232
self.comm.pref.refresh()
233
self.comm.refresh_right()
235
def on_treeview_left_button_press_event(self, widget, event):
236
""" Occurs when somebody right-clicks in the bookmark list. """
237
if event.button == 3:
238
# Don't show context with nothing selected
239
if self.comm.get_selected_left() == None:
242
self.menu.left_context_menu().popup(None, None, None, 0,
245
def on_treeview_left_row_activated(self, treeview, path, view_column):
246
""" Occurs when somebody double-clicks or enters an item in the
249
newdir = self.comm.get_selected_left()
253
self.comm.set_path(newdir)
254
self.comm.refresh_right()
256
def on_treeview_right_button_press_event(self, widget, event):
257
""" Occurs when somebody right-clicks in the file list. """
258
if event.button == 3:
260
m_add = self.menu.ui.get_widget('/context_right/add')
261
m_remove = self.menu.ui.get_widget('/context_right/remove')
262
m_commit = self.menu.ui.get_widget('/context_right/commit')
263
m_diff = self.menu.ui.get_widget('/context_right/diff')
264
# check if we're in a branch
266
from bzrlib.branch import Branch
267
Branch.open_containing(self.comm.get_path())
268
m_add.set_sensitive(False)
269
m_remove.set_sensitive(False)
270
m_commit.set_sensitive(False)
271
m_diff.set_sensitive(False)
272
except errors.NotBranchError:
273
m_add.set_sensitive(True)
274
m_remove.set_sensitive(True)
275
m_commit.set_sensitive(True)
276
m_diff.set_sensitive(True)
277
self.menu.right_context_menu().popup(None, None, None, 0,
280
def on_treeview_right_row_activated(self, treeview, path, view_column):
281
""" Occurs when somebody double-clicks or enters an item in the
285
newdir = self.comm.get_selected_right()
288
self.comm.set_path(os.path.split(self.comm.get_path())[0])
290
fullpath = self.comm.get_path() + os.sep + newdir
291
if os.path.isdir(fullpath):
292
# selected item is an existant directory
293
self.comm.set_path(fullpath)
297
self.comm.refresh_right()
299
def on_window_main_delete_event(self, widget, event=None):
300
""" Do some stuff before exiting. """
301
width, height = self.comm.window_main.get_size()
302
self.comm.pref.set_preference('window_width', width)
303
self.comm.pref.set_preference('window_height', height)
304
x, y = self.comm.window_main.get_position()
305
self.comm.pref.set_preference('window_x', x)
306
self.comm.pref.set_preference('window_y', y)
307
self.comm.pref.set_preference('paned_position',
308
self.comm.hpaned_main.get_position())
310
self.comm.pref.write()
311
self.comm.window_main.destroy()