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
from olive.backend.info import is_branch
32
import olive.backend.errors as errors
34
from dialog import OliveDialog
35
from menu import OliveMenu
36
from launch import launch
39
""" Signal handler class for Olive. """
40
def __init__(self, gladefile, comm):
41
self.gladefile = gladefile
44
self.dialog = OliveDialog(self.gladefile)
46
self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
48
def on_about_activate(self, widget):
51
def on_menuitem_add_files_activate(self, widget):
52
""" Add file(s)... menu handler. """
53
from add import OliveAdd
54
add = OliveAdd(self.gladefile, self.comm, self.dialog)
57
def on_menuitem_branch_get_activate(self, widget):
58
""" Branch/Get... menu handler. """
59
from branch import OliveBranch
60
branch = OliveBranch(self.gladefile, self.comm, self.dialog)
63
def on_menuitem_branch_checkout_activate(self, widget):
64
""" Branch/Checkout... menu handler. """
65
from checkout import OliveCheckout
66
checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
69
def on_menuitem_branch_commit_activate(self, widget):
70
""" Branch/Commit... menu handler. """
71
from commit import OliveCommit
72
commit = OliveCommit(self.gladefile, self.comm, self.dialog)
75
def on_menuitem_branch_missing_revisions_activate(self, widget):
76
""" Branch/Missing revisions menu handler. """
77
import olive.backend.update as update
79
self.comm.set_busy(self.comm.window_main)
82
ret = update.missing(self.comm.get_path())
83
except errors.NotBranchError:
84
self.dialog.error_dialog(_('Directory is not a branch'),
85
_('You can perform this action only in a branch.'))
86
except errors.ConnectionError:
87
self.dialog.error_dialog(_('Connection error'),
88
_('Cannot connect to remote location.\nPlease try again later.'))
89
except errors.NoLocationKnown:
90
self.dialog.error_dialog(_('Parent location is unknown'),
91
_('Cannot determine missing revisions if no parent location is known.'))
94
self.dialog.info_dialog(_('There are missing revisions'),
95
_('%d revision(s) missing.') % ret)
97
self.dialog.info_dialog(_('Local branch up to date'),
98
_('There are no missing revisions.'))
100
self.comm.set_busy(self.comm.window_main, False)
102
def on_menuitem_branch_pull_activate(self, widget):
103
""" Branch/Pull menu handler. """
104
import olive.backend.update as update
106
self.comm.set_busy(self.comm.window_main)
109
ret = update.pull(self.comm.get_path())
110
except errors.NotBranchError:
111
self.dialog.error_dialog(_('Directory is not a branch'),
112
_('You can perform this action only in a branch.'))
113
except errors.NoLocationKnown:
114
self.dialog.error_dialog(_('Parent location is unknown'),
115
_('Pulling is not possible until there is no parent location.'))
117
self.dialog.info_dialog(_('Pull successful'),
118
_('%d revision(s) pulled.') % ret)
120
self.comm.set_busy(self.comm.window_main, False)
122
def on_menuitem_branch_push_activate(self, widget):
123
""" Branch/Push... menu handler. """
124
from push import OlivePush
125
push = OlivePush(self.gladefile, self.comm, self.dialog)
128
def on_menuitem_branch_status_activate(self, widget):
129
""" Branch/Status... menu handler. """
130
from status import OliveStatus
131
status = OliveStatus(self.gladefile, self.comm, self.dialog)
134
def on_menuitem_branch_initialize_activate(self, widget):
135
""" Initialize current directory. """
136
import olive.backend.init as init
139
init.init(self.comm.get_path())
140
except errors.AlreadyBranchError, errmsg:
141
self.dialog.error_dialog(_('Directory is already a branch'),
142
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
143
except errors.BranchExistsWithoutWorkingTree, errmsg:
144
self.dialog.error_dialog(_('Branch without a working tree'),
145
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
149
self.dialog.info_dialog(_('Ininialize successful'),
150
_('Directory successfully initialized.'))
151
self.comm.refresh_right()
153
def on_menuitem_file_make_directory_activate(self, widget):
154
""" File/Make directory... menu handler. """
155
from mkdir import OliveMkdir
156
mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
159
def on_menuitem_file_move_activate(self, widget):
160
""" File/Move... menu handler. """
161
from move import OliveMove
162
move = OliveMove(self.gladefile, self.comm, self.dialog)
165
def on_menuitem_file_rename_activate(self, widget):
166
""" File/Rename... menu handler. """
167
from rename import OliveRename
168
rename = OliveRename(self.gladefile, self.comm, self.dialog)
171
def on_menuitem_remove_file_activate(self, widget):
172
""" Remove (unversion) selected file. """
173
from remove import OliveRemove
174
remove = OliveRemove(self.gladefile, self.comm, self.dialog)
177
def on_menuitem_stats_diff_activate(self, widget):
178
""" Statistics/Differences... menu handler. """
179
from diff import OliveDiff
180
diff = OliveDiff(self.gladefile, self.comm, self.dialog)
183
def on_menuitem_stats_infos_activate(self, widget):
184
""" Statistics/Informations... menu handler. """
185
from info import OliveInfo
186
info = OliveInfo(self.gladefile, self.comm, self.dialog)
189
def on_menuitem_stats_log_activate(self, widget):
190
""" Statistics/Log... menu handler. """
191
from log import OliveLog
192
log = OliveLog(self.gladefile, self.comm, self.dialog)
195
def on_menuitem_view_refresh_activate(self, widget):
196
""" View/Refresh menu handler. """
197
# Refresh the left pane
198
self.comm.refresh_left()
199
# Refresh the right pane
200
self.comm.refresh_right()
202
def on_menuitem_view_show_hidden_files_activate(self, widget):
203
""" View/Show hidden files menu handler. """
204
if widget.get_active():
206
self.comm.pref.set_preference('dotted_files', True)
207
self.comm.pref.refresh()
208
self.comm.refresh_right()
210
# Do not show hidden files
211
self.comm.pref.set_preference('dotted_files', False)
212
self.comm.pref.refresh()
213
self.comm.refresh_right()
215
def on_treeview_left_button_press_event(self, widget, event):
216
""" Occurs when somebody right-clicks in the bookmark list. """
217
if event.button == 3:
218
# Don't show context with nothing selected
219
if self.comm.get_selected_left() == None:
222
self.menu.left_context_menu().popup(None, None, None, 0,
225
def on_treeview_left_row_activated(self, treeview, path, view_column):
226
""" Occurs when somebody double-clicks or enters an item in the
229
newdir = self.comm.get_selected_left()
233
self.comm.set_busy(treeview)
234
self.comm.set_path(newdir)
235
self.comm.refresh_right()
236
self.comm.set_busy(treeview, False)
238
def on_treeview_right_button_press_event(self, widget, event):
239
""" Occurs when somebody right-clicks in the file list. """
240
if event.button == 3:
242
m_add = self.menu.ui.get_widget('/context_right/add')
243
m_remove = self.menu.ui.get_widget('/context_right/remove')
244
m_commit = self.menu.ui.get_widget('/context_right/commit')
245
m_diff = self.menu.ui.get_widget('/context_right/diff')
246
# check if we're in a branch
247
if not is_branch(self.comm.get_path()):
248
m_add.set_sensitive(False)
249
m_remove.set_sensitive(False)
250
m_commit.set_sensitive(False)
251
m_diff.set_sensitive(False)
253
m_add.set_sensitive(True)
254
m_remove.set_sensitive(True)
255
m_commit.set_sensitive(True)
256
m_diff.set_sensitive(True)
257
self.menu.right_context_menu().popup(None, None, None, 0,
260
def on_treeview_right_row_activated(self, treeview, path, view_column):
261
""" Occurs when somebody double-clicks or enters an item in the
265
newdir = self.comm.get_selected_right()
268
self.comm.set_path(os.path.split(self.comm.get_path())[0])
270
fullpath = self.comm.get_path() + os.sep + newdir
271
if os.path.isdir(fullpath):
272
# selected item is an existant directory
273
self.comm.set_path(fullpath)
277
self.comm.refresh_right()
279
def on_window_main_delete_event(self, widget, event=None):
280
""" Do some stuff before exiting. """
281
width, height = self.comm.window_main.get_size()
282
self.comm.pref.set_preference('window_width', width)
283
self.comm.pref.set_preference('window_height', height)
284
x, y = self.comm.window_main.get_position()
285
self.comm.pref.set_preference('window_x', x)
286
self.comm.pref.set_preference('window_y', y)
287
self.comm.pref.set_preference('paned_position',
288
self.comm.hpaned_main.get_position())
290
self.comm.pref.write()
291
self.comm.window_main.destroy()
293
def not_implemented(self, widget):
294
""" Display a Not implemented error message. """
295
self.dialog.error_dialog(_('We feel sorry'),
296
_('This feature is not yet implemented.'))