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
37
""" Signal handler class for Olive. """
38
def __init__(self, gladefile, comm):
39
self.gladefile = gladefile
42
self.dialog = OliveDialog(self.gladefile)
44
self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
46
def on_about_activate(self, widget):
49
def on_menuitem_add_files_activate(self, widget):
50
""" Add file(s)... menu handler. """
51
from add import OliveAdd
52
add = OliveAdd(self.gladefile, self.comm, self.dialog)
55
def on_menuitem_branch_get_activate(self, widget):
56
""" Branch/Get... menu handler. """
57
from branch import OliveBranch
58
branch = OliveBranch(self.gladefile, self.comm, self.dialog)
61
def on_menuitem_branch_checkout_activate(self, widget):
62
""" Branch/Checkout... menu handler. """
63
from checkout import OliveCheckout
64
checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
67
def on_menuitem_branch_commit_activate(self, widget):
68
""" Branch/Commit... menu handler. """
69
from commit import OliveCommit
70
commit = OliveCommit(self.gladefile, self.comm, self.dialog)
73
def on_menuitem_branch_missing_revisions_activate(self, widget):
74
""" Branch/Missing revisions menu handler. """
75
import olive.backend.update as update
77
self.comm.set_busy(self.comm.window_main)
80
ret = update.missing(self.comm.get_path())
81
except errors.NotBranchError:
82
self.dialog.error_dialog(_('Directory is not a branch'),
83
_('You can perform this action only in a branch.'))
84
except errors.ConnectionError:
85
self.dialog.error_dialog(_('Connection error'),
86
_('Cannot connect to remote location.\nPlease try again later.'))
87
except errors.NoLocationKnown:
88
self.dialog.error_dialog(_('Parent location is unknown'),
89
_('Cannot determine missing revisions if no parent location is known.'))
92
self.dialog.info_dialog(_('There are missing revisions'),
93
_('%d revision(s) missing.') % ret)
95
self.dialog.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. """
102
import olive.backend.update as update
104
self.comm.set_busy(self.comm.window_main)
107
ret = update.pull(self.comm.get_path())
108
except errors.NotBranchError:
109
self.dialog.error_dialog(_('Directory is not a branch'),
110
_('You can perform this action only in a branch.'))
111
except errors.NoLocationKnown:
112
self.dialog.error_dialog(_('Parent location is unknown'),
113
_('Pulling is not possible until there is no parent location.'))
115
self.dialog.info_dialog(_('Pull successful'),
116
_('%d revision(s) pulled.') % ret)
118
self.comm.set_busy(self.comm.window_main, False)
120
def on_menuitem_branch_push_activate(self, widget):
121
""" Branch/Push... menu handler. """
122
from push import OlivePush
123
push = OlivePush(self.gladefile, self.comm, self.dialog)
126
def on_menuitem_branch_status_activate(self, widget):
127
""" Branch/Status... menu handler. """
128
from status import OliveStatus
129
status = OliveStatus(self.gladefile, self.comm, self.dialog)
132
def on_menuitem_branch_initialize_activate(self, widget):
133
""" Initialize current directory. """
134
import olive.backend.init as init
137
init.init(self.comm.get_path())
138
except errors.AlreadyBranchError, errmsg:
139
self.dialog.error_dialog(_('Directory is already a branch'),
140
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
141
except errors.BranchExistsWithoutWorkingTree, errmsg:
142
self.dialog.error_dialog(_('Branch without a working tree'),
143
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
147
self.dialog.info_dialog(_('Ininialize successful'),
148
_('Directory successfully initialized.'))
149
self.comm.refresh_right()
151
def on_menuitem_file_make_directory_activate(self, widget):
152
""" File/Make directory... menu handler. """
153
from mkdir import OliveMkdir
154
mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
157
def on_menuitem_file_move_activate(self, widget):
158
""" File/Move... menu handler. """
159
from move import OliveMove
160
move = OliveMove(self.gladefile, self.comm, self.dialog)
163
def on_menuitem_file_rename_activate(self, widget):
164
""" File/Rename... menu handler. """
165
from rename import OliveRename
166
rename = OliveRename(self.gladefile, self.comm, self.dialog)
169
def on_menuitem_remove_file_activate(self, widget):
170
""" Remove (unversion) selected file. """
171
from remove import OliveRemove
172
remove = OliveRemove(self.gladefile, self.comm, self.dialog)
175
def on_menuitem_stats_diff_activate(self, widget):
176
""" Statistics/Differences... menu handler. """
177
from diff import OliveDiff
178
diff = OliveDiff(self.gladefile, self.comm, self.dialog)
181
def on_menuitem_stats_infos_activate(self, widget):
182
""" Statistics/Informations... menu handler. """
183
from info import OliveInfo
184
info = OliveInfo(self.gladefile, self.comm, self.dialog)
187
def on_menuitem_stats_log_activate(self, widget):
188
""" Statistics/Log... menu handler. """
189
from log import OliveLog
190
log = OliveLog(self.gladefile, self.comm, self.dialog)
193
def on_menuitem_view_refresh_activate(self, widget):
194
""" View/Refresh menu handler. """
195
# Refresh the left pane
196
self.comm.refresh_left()
197
# Refresh the right pane
198
self.comm.refresh_right()
200
def on_menuitem_view_show_hidden_files_activate(self, widget):
201
""" View/Show hidden files menu handler. """
202
if widget.get_active():
204
self.comm.pref.set_preference('dotted_files', True)
205
self.comm.pref.refresh()
206
self.comm.refresh_right()
208
# Do not show hidden files
209
self.comm.pref.set_preference('dotted_files', False)
210
self.comm.pref.refresh()
211
self.comm.refresh_right()
213
def on_treeview_left_button_press_event(self, widget, event):
214
""" Occurs when somebody right-clicks in the bookmark list. """
215
if event.button == 3:
216
self.menu.left_context_menu().popup(None, None, None, 0,
219
def on_treeview_left_row_activated(self, treeview, path, view_column):
220
""" Occurs when somebody double-clicks or enters an item in the
222
self.comm.set_busy(treeview)
224
newdir = self.comm.get_selected_left()
225
self.comm.set_path(newdir)
227
self.comm.refresh_right()
229
self.comm.set_busy(treeview, False)
231
def on_treeview_right_button_press_event(self, widget, event):
232
""" Occurs when somebody right-clicks in the file list. """
233
if event.button == 3:
235
m_add = self.menu.ui.get_widget('/context_right/add')
236
m_remove = self.menu.ui.get_widget('/context_right/remove')
237
m_commit = self.menu.ui.get_widget('/context_right/commit')
238
m_diff = self.menu.ui.get_widget('/context_right/diff')
239
# check if we're in a branch
240
if not is_branch(self.comm.get_path()):
241
m_add.set_sensitive(False)
242
m_remove.set_sensitive(False)
243
m_commit.set_sensitive(False)
244
m_diff.set_sensitive(False)
246
m_add.set_sensitive(True)
247
m_remove.set_sensitive(True)
248
m_commit.set_sensitive(True)
249
m_diff.set_sensitive(True)
250
self.menu.right_context_menu().popup(None, None, None, 0,
253
def on_treeview_right_row_activated(self, treeview, path, view_column):
254
""" Occurs when somebody double-clicks or enters an item in the
258
newdir = self.comm.get_selected_right()
261
self.comm.set_path(os.path.split(self.comm.get_path())[0])
263
fullpath = self.comm.get_path() + '/' + newdir
264
if os.path.isdir(fullpath):
265
# selected item is an existant directory
266
self.comm.set_path(fullpath)
268
if sys.platform == 'win32':
269
# open the file with the default application
270
os.startfile(fullpath)
272
# TODO: support other OSes
273
print "DEBUG: double-click on non-Win32 platforms not supported."
275
self.comm.refresh_right()
277
def on_window_main_delete_event(self, widget, event=None):
278
""" Do some stuff before exiting. """
279
width, height = self.comm.window_main.get_size()
280
self.comm.pref.set_preference('window_width', width)
281
self.comm.pref.set_preference('window_height', height)
282
x, y = self.comm.window_main.get_position()
283
self.comm.pref.set_preference('window_x', x)
284
self.comm.pref.set_preference('window_y', y)
285
self.comm.pref.set_preference('paned_position',
286
self.comm.hpaned_main.get_position())
288
self.comm.pref.write()
289
self.comm.window_main.destroy()
291
def not_implemented(self, widget):
292
""" Display a Not implemented error message. """
293
self.dialog.error_dialog(_('We feel sorry'),
294
_('This feature is not yet implemented.'))