1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
|
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
from olive.backend.info import is_branch
import olive.backend.errors as errors
from dialog import OliveDialog
from menu import OliveMenu
class OliveHandler:
""" Signal handler class for Olive. """
def __init__(self, gladefile, comm):
self.gladefile = gladefile
self.comm = comm
self.dialog = OliveDialog(self.gladefile)
self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
def on_about_activate(self, widget):
self.dialog.about()
def on_menuitem_add_files_activate(self, widget):
""" Add file(s)... menu handler. """
from add import OliveAdd
add = OliveAdd(self.gladefile, self.comm, self.dialog)
add.display()
def on_menuitem_branch_get_activate(self, widget):
""" Branch/Get... menu handler. """
from branch import OliveBranch
branch = OliveBranch(self.gladefile, self.comm, self.dialog)
branch.display()
def on_menuitem_branch_checkout_activate(self, widget):
""" Branch/Checkout... menu handler. """
from checkout import OliveCheckout
checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
checkout.display()
def on_menuitem_branch_commit_activate(self, widget):
""" Branch/Commit... menu handler. """
from commit import OliveCommit
commit = OliveCommit(self.gladefile, self.comm, self.dialog)
commit.display()
def on_menuitem_branch_pull_activate(self, widget):
""" Branch/Pull menu handler. """
import olive.backend.update as update
self.comm.set_busy(self.comm.window_main)
try:
ret = update.pull(self.comm.get_path())
except errors.NotBranchError:
self.dialog.error_dialog(_('Directory is not a branch'),
_('You can perform this action only in a branch.'))
except errors.NoLocationKnown:
self.dialog.error_dialog(_('Parent location is unknown'),
_('Pulling is not possible until there is no parent location.'))
else:
self.dialog.info_dialog(_('Pull successful'),
_('%d revision(s) pulled.') % ret)
self.comm.set_busy(self.comm.window_main, False)
def on_menuitem_branch_push_activate(self, widget):
""" Branch/Push... menu handler. """
from push import OlivePush
push = OlivePush(self.gladefile, self.comm, self.dialog)
push.display()
def on_menuitem_branch_status_activate(self, widget):
""" Branch/Status... menu handler. """
from status import OliveStatus
status = OliveStatus(self.gladefile, self.comm, self.dialog)
status.display()
def on_menuitem_branch_initialize_activate(self, widget):
""" Initialize current directory. """
import olive.backend.init as init
try:
init.init(self.comm.get_path())
except errors.AlreadyBranchError, errmsg:
self.dialog.error_dialog(_('Directory is already a branch'),
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
except errors.BranchExistsWithoutWorkingTree, errmsg:
self.dialog.error_dialog(_('Branch without a working tree'),
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
except:
raise
else:
self.dialog.info_dialog(_('Ininialize successful'),
_('Directory successfully initialized.'))
self.comm.refresh_right()
def on_menuitem_file_make_directory_activate(self, widget):
""" File/Make directory... menu handler. """
from mkdir import OliveMkdir
mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
mkdir.display()
def on_menuitem_file_move_activate(self, widget):
""" File/Move... menu handler. """
from move import OliveMove
move = OliveMove(self.gladefile, self.comm, self.dialog)
move.display()
def on_menuitem_file_rename_activate(self, widget):
""" File/Rename... menu handler. """
from rename import OliveRename
rename = OliveRename(self.gladefile, self.comm, self.dialog)
rename.display()
def on_menuitem_remove_file_activate(self, widget):
""" Remove (unversion) selected file. """
from remove import OliveRemove
remove = OliveRemove(self.gladefile, self.comm, self.dialog)
remove.display()
def on_menuitem_stats_diff_activate(self, widget):
""" Statistics/Differences... menu handler. """
from diff import OliveDiff
diff = OliveDiff(self.gladefile, self.comm, self.dialog)
diff.display()
def on_menuitem_stats_infos_activate(self, widget):
""" Statistics/Informations... menu handler. """
from info import OliveInfo
info = OliveInfo(self.gladefile, self.comm, self.dialog)
info.display()
def on_menuitem_stats_log_activate(self, widget):
""" Statistics/Log... menu handler. """
from log import OliveLog
log = OliveLog(self.gladefile, self.comm, self.dialog)
log.display()
def on_menuitem_view_refresh_activate(self, widget):
""" View/Refresh menu handler. """
# Refresh the left pane
self.comm.refresh_left()
# Refresh the right pane
self.comm.refresh_right()
def on_menuitem_view_show_hidden_files_activate(self, widget):
""" View/Show hidden files menu handler. """
if widget.get_active():
# Show hidden files
self.comm.pref.set_preference('dotted_files', True)
self.comm.pref.refresh()
self.comm.refresh_right()
else:
# Do not show hidden files
self.comm.pref.set_preference('dotted_files', False)
self.comm.pref.refresh()
self.comm.refresh_right()
def on_treeview_left_button_press_event(self, widget, event):
""" Occurs when somebody right-clicks in the bookmark list. """
if event.button == 3:
self.menu.left_context_menu().popup(None, None, None, 0,
event.time)
def on_treeview_left_row_activated(self, treeview, path, view_column):
""" Occurs when somebody double-clicks or enters an item in the
bookmark list. """
self.comm.set_busy(treeview)
newdir = self.comm.get_selected_left()
self.comm.set_path(newdir)
self.comm.refresh_right()
self.comm.set_busy(treeview, False)
def on_treeview_right_button_press_event(self, widget, event):
""" Occurs when somebody right-clicks in the file list. """
if event.button == 3:
# get the menu items
m_add = self.menu.ui.get_widget('/context_right/add')
m_remove = self.menu.ui.get_widget('/context_right/remove')
m_commit = self.menu.ui.get_widget('/context_right/commit')
m_diff = self.menu.ui.get_widget('/context_right/diff')
# check if we're in a branch
if not is_branch(self.comm.get_path()):
m_add.set_sensitive(False)
m_remove.set_sensitive(False)
m_commit.set_sensitive(False)
m_diff.set_sensitive(False)
else:
m_add.set_sensitive(True)
m_remove.set_sensitive(True)
m_commit.set_sensitive(True)
m_diff.set_sensitive(True)
self.menu.right_context_menu().popup(None, None, None, 0,
event.time)
def on_treeview_right_row_activated(self, treeview, path, view_column):
""" Occurs when somebody double-clicks or enters an item in the
file list. """
import os.path
newdir = self.comm.get_selected_right()
if newdir == '..':
self.comm.set_path(os.path.split(self.comm.get_path())[0])
else:
fullpath = self.comm.get_path() + '/' + newdir
if os.path.isdir(fullpath):
# selected item is an existant directory
self.comm.set_path(fullpath)
else:
if sys.platform == 'win32':
# open the file with the default application
os.startfile(fullpath)
else:
# TODO: support other OSes
print "DEBUG: double-click on non-Win32 platforms not supported."
self.comm.refresh_right()
def on_window_main_delete_event(self, widget, event=None):
""" Do some stuff before exiting. """
width, height = self.comm.window_main.get_size()
self.comm.pref.set_preference('window_width', width)
self.comm.pref.set_preference('window_height', height)
x, y = self.comm.window_main.get_position()
self.comm.pref.set_preference('window_x', x)
self.comm.pref.set_preference('window_y', y)
self.comm.pref.set_preference('paned_position',
self.comm.hpaned_main.get_position())
self.comm.pref.write()
self.comm.window_main.destroy()
def not_implemented(self, widget):
""" Display a Not implemented error message. """
self.dialog.error_dialog(_('We feel sorry'),
_('This feature is not yet implemented.'))
|