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
30
from olive.backend.info import is_branch
31
import olive.backend.errors as errors
33
from dialog import OliveDialog
34
from menu import OliveMenu
35
from launch import launch
38
""" Signal handler class for Olive. """
39
def __init__(self, gladefile, comm):
40
self.gladefile = gladefile
43
self.dialog = OliveDialog(self.gladefile)
45
self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
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
add = OliveAdd(self.gladefile, self.comm, self.dialog)
56
def on_menuitem_branch_get_activate(self, widget):
57
""" Branch/Get... menu handler. """
58
from branch import OliveBranch
59
branch = OliveBranch(self.gladefile, self.comm, self.dialog)
62
def on_menuitem_branch_checkout_activate(self, widget):
63
""" Branch/Checkout... menu handler. """
64
from checkout import OliveCheckout
65
checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
68
def on_menuitem_branch_commit_activate(self, widget):
69
""" Branch/Commit... menu handler. """
70
from commit import OliveCommit
71
commit = OliveCommit(self.gladefile, self.comm, self.dialog)
74
def on_menuitem_branch_missing_revisions_activate(self, widget):
75
""" Branch/Missing revisions menu handler. """
76
import olive.backend.update as update
78
self.comm.set_busy(self.comm.window_main)
81
ret = update.missing(self.comm.get_path())
82
except errors.NotBranchError:
83
self.dialog.error_dialog(_('Directory is not a branch'),
84
_('You can perform this action only in a branch.'))
85
except errors.ConnectionError:
86
self.dialog.error_dialog(_('Connection error'),
87
_('Cannot connect to remote location.\nPlease try again later.'))
88
except errors.NoLocationKnown:
89
self.dialog.error_dialog(_('Parent location is unknown'),
90
_('Cannot determine missing revisions if no parent location is known.'))
93
self.dialog.info_dialog(_('There are missing revisions'),
94
_('%d revision(s) missing.') % ret)
96
self.dialog.info_dialog(_('Local branch up to date'),
97
_('There are no missing revisions.'))
99
self.comm.set_busy(self.comm.window_main, False)
101
def on_menuitem_branch_pull_activate(self, widget):
102
""" Branch/Pull menu handler. """
103
import olive.backend.update as update
105
self.comm.set_busy(self.comm.window_main)
108
ret = update.pull(self.comm.get_path())
109
except errors.NotBranchError:
110
self.dialog.error_dialog(_('Directory is not a branch'),
111
_('You can perform this action only in a branch.'))
112
except errors.NoLocationKnown:
113
self.dialog.error_dialog(_('Parent location is unknown'),
114
_('Pulling is not possible until there is no parent location.'))
116
self.dialog.info_dialog(_('Pull successful'),
117
_('%d revision(s) pulled.') % ret)
119
self.comm.set_busy(self.comm.window_main, False)
121
def on_menuitem_branch_push_activate(self, widget):
122
""" Branch/Push... menu handler. """
123
from push import OlivePush
124
push = OlivePush(self.gladefile, self.comm, self.dialog)
127
def on_menuitem_branch_status_activate(self, widget):
128
""" Branch/Status... menu handler. """
129
from status import OliveStatus
130
status = OliveStatus(self.gladefile, self.comm, self.dialog)
133
def on_menuitem_branch_initialize_activate(self, widget):
134
""" Initialize current directory. """
135
import olive.backend.init as init
138
init.init(self.comm.get_path())
139
except errors.AlreadyBranchError, errmsg:
140
self.dialog.error_dialog(_('Directory is already a branch'),
141
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
except errors.BranchExistsWithoutWorkingTree, errmsg:
143
self.dialog.error_dialog(_('Branch without a working tree'),
144
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
148
self.dialog.info_dialog(_('Ininialize successful'),
149
_('Directory successfully initialized.'))
150
self.comm.refresh_right()
152
def on_menuitem_file_make_directory_activate(self, widget):
153
""" File/Make directory... menu handler. """
154
from mkdir import OliveMkdir
155
mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
158
def on_menuitem_file_move_activate(self, widget):
159
""" File/Move... menu handler. """
160
from move import OliveMove
161
move = OliveMove(self.gladefile, self.comm, self.dialog)
164
def on_menuitem_file_rename_activate(self, widget):
165
""" File/Rename... menu handler. """
166
from rename import OliveRename
167
rename = OliveRename(self.gladefile, self.comm, self.dialog)
170
def on_menuitem_remove_file_activate(self, widget):
171
""" Remove (unversion) selected file. """
172
from remove import OliveRemove
173
remove = OliveRemove(self.gladefile, self.comm, self.dialog)
176
def on_menuitem_stats_diff_activate(self, widget):
177
""" Statistics/Differences... menu handler. """
178
from diff import OliveDiff
179
diff = OliveDiff(self.gladefile, self.comm, self.dialog)
182
def on_menuitem_stats_infos_activate(self, widget):
183
""" Statistics/Informations... menu handler. """
184
from info import OliveInfo
185
info = OliveInfo(self.gladefile, self.comm, self.dialog)
188
def on_menuitem_stats_log_activate(self, widget):
189
""" Statistics/Log... menu handler. """
190
from log import OliveLog
191
log = OliveLog(self.gladefile, self.comm, self.dialog)
194
def on_menuitem_view_refresh_activate(self, widget):
195
""" View/Refresh menu handler. """
196
# Refresh the left pane
197
self.comm.refresh_left()
198
# Refresh the right pane
199
self.comm.refresh_right()
201
def on_menuitem_view_show_hidden_files_activate(self, widget):
202
""" View/Show hidden files menu handler. """
203
if widget.get_active():
205
self.comm.pref.set_preference('dotted_files', True)
206
self.comm.pref.refresh()
207
self.comm.refresh_right()
209
# Do not show hidden files
210
self.comm.pref.set_preference('dotted_files', False)
211
self.comm.pref.refresh()
212
self.comm.refresh_right()
214
def on_treeview_left_button_press_event(self, widget, event):
215
""" Occurs when somebody right-clicks in the bookmark list. """
216
if event.button == 3:
217
# Don't show context with nothing selected
218
if self.comm.get_selected_left() == None:
221
self.menu.left_context_menu().popup(None, None, None, 0,
224
def on_treeview_left_row_activated(self, treeview, path, view_column):
225
""" Occurs when somebody double-clicks or enters an item in the
228
newdir = self.comm.get_selected_left()
232
self.comm.set_busy(treeview)
233
self.comm.set_path(newdir)
234
self.comm.refresh_right()
235
self.comm.set_busy(treeview, False)
237
def on_treeview_right_button_press_event(self, widget, event):
238
""" Occurs when somebody right-clicks in the file list. """
239
if event.button == 3:
241
m_add = self.menu.ui.get_widget('/context_right/add')
242
m_remove = self.menu.ui.get_widget('/context_right/remove')
243
m_commit = self.menu.ui.get_widget('/context_right/commit')
244
m_diff = self.menu.ui.get_widget('/context_right/diff')
245
# check if we're in a branch
246
if not is_branch(self.comm.get_path()):
247
m_add.set_sensitive(False)
248
m_remove.set_sensitive(False)
249
m_commit.set_sensitive(False)
250
m_diff.set_sensitive(False)
252
m_add.set_sensitive(True)
253
m_remove.set_sensitive(True)
254
m_commit.set_sensitive(True)
255
m_diff.set_sensitive(True)
256
self.menu.right_context_menu().popup(None, None, None, 0,
259
def on_treeview_right_row_activated(self, treeview, path, view_column):
260
""" Occurs when somebody double-clicks or enters an item in the
264
newdir = self.comm.get_selected_right()
267
self.comm.set_path(os.path.split(self.comm.get_path())[0])
269
fullpath = self.comm.get_path() + os.sep + newdir
270
if os.path.isdir(fullpath):
271
# selected item is an existant directory
272
self.comm.set_path(fullpath)
276
self.comm.refresh_right()
278
def on_window_main_delete_event(self, widget, event=None):
279
""" Do some stuff before exiting. """
280
width, height = self.comm.window_main.get_size()
281
self.comm.pref.set_preference('window_width', width)
282
self.comm.pref.set_preference('window_height', height)
283
x, y = self.comm.window_main.get_position()
284
self.comm.pref.set_preference('window_x', x)
285
self.comm.pref.set_preference('window_y', y)
286
self.comm.pref.set_preference('paned_position',
287
self.comm.hpaned_main.get_position())
289
self.comm.pref.write()
290
self.comm.window_main.destroy()
292
def not_implemented(self, widget):
293
""" Display a Not implemented error message. """
294
self.dialog.error_dialog(_('We feel sorry'),
295
_('This feature is not yet implemented.'))