28
28
import bzrlib.errors as errors
29
29
from bzrlib.workingtree import WorkingTree
31
from dialog import error_dialog, info_dialog, warning_dialog
31
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
32
from bzrlib.plugins.gtk.errors import show_bzr_error
33
from bzrlib.plugins.gtk.annotate.gannotate import GAnnotateWindow
34
from bzrlib.plugins.gtk.annotate.config import GAnnotateConfig
35
from bzrlib.plugins.gtk.diff import DiffWindow
32
36
from launch import launch
33
from olive import OlivePreferences
37
from olive import Preferences
36
40
""" This class is responsible for building the context menus. """
37
def __init__(self, path, selected):
41
def __init__(self, path, selected, app=None):
39
if sys.platform == 'win32':
40
self.uifile = os.path.dirname(sys.executable) + "/share/olive/cmenu.ui"
42
self.uifile = "/usr/share/olive/cmenu.ui"
44
if not os.path.exists(self.uifile):
45
# Load from current directory if not installed
46
self.uifile = "cmenu.ui"
48
if not os.path.exists(self.uifile):
50
print _('UI description file cannot be found.')
43
from guifiles import UIFILENAME
45
self.uifile = UIFILENAME
53
47
# Preferences handler
54
self.pref = OlivePreferences()
48
self.pref = Preferences()
56
50
# Set default values
58
52
self.selected = selected
60
55
# Create the file list context menu
61
56
self.ui = gtk.UIManager()
70
65
_('Remove the selected file'),
69
_('Rename the selected file'),
72
71
('open', gtk.STOCK_OPEN,
74
73
_('Open the selected file'),
77
_('Revert the changes'),
78
81
_('Commit the changes'),
85
_('Annotate the selected file'),
82
89
_('Show the diff of the file'),
104
111
('diff_all', None,
105
112
_('All...'), None,
106
113
_('Show the differences of all files'),
115
('view_remote', None,
116
_('View contents'), None,
117
_('View the contents of the file in a builtin viewer'),
119
('diff_remote', None,
120
_('Show differences'), None,
121
_('Show the differences between two revisions of the file'),
123
('revert_remote', None,
124
_('Revert to this revision'), None,
125
_('Revert the selected file to the selected revision'),
110
129
self.ui.insert_action_group(self.actiongroup, 0)
113
132
self.cmenu_right = self.ui.get_widget('/context_right')
114
133
self.cmenu_left = self.ui.get_widget('/context_left')
115
134
self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
135
self.cmenu_remote = self.ui.get_widget('/context_remote')
118
138
# TODO: do it without using deprecated comm
135
155
def left_context_menu(self):
136
156
return self.cmenu_left
158
def remote_context_menu(self):
159
return self.cmenu_remote
138
162
def add_file(self, action):
139
163
""" Right context menu -> Add """
140
164
import bzrlib.add
148
172
_('Please select a file from the list,\nor choose the other option.'))
175
bzrlib.add.smart_add([os.path.join(directory, filename)])
178
def annotate(self, action):
179
""" Right context menu -> Annotate """
180
directory = self.path
181
filename = self.selected
184
error_dialog(_('No file was selected'),
185
_('Please select a file from the list.'))
188
wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
191
file_id = wt.path2id(wt.relpath(os.path.join(directory, filename)))
193
window = GAnnotateWindow(all=False, plain=False)
194
window.set_title(os.path.join(directory, filename) + " - Annotate")
195
config = GAnnotateConfig(window)
152
bzrlib.add.smart_add([directory + os.sep + filename])
153
except errors.NotBranchError:
154
error_dialog(_('Directory is not a branch'),
155
_('You can perform this action only in a branch.'))
199
window.annotate(wt, branch, file_id)
158
204
def remove_file(self, action):
159
205
""" Right context menu -> Remove """
160
206
# Remove only the selected file
166
212
_('Please select a file from the list,\nor choose the other option.'))
170
wt, path = WorkingTree.open_containing(directory + os.sep + filename)
173
except errors.NotBranchError:
174
error_dialog(_('Directory is not a branch'),
175
_('You can perform this action only in a branch.'))
177
except errors.NotVersionedError:
178
error_dialog(_('File not versioned'),
179
_('The selected file is not versioned.'))
215
wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
217
self.app.set_path(self.path)
218
self.app.refresh_right()
220
def rename_file(self, action):
221
""" Right context menu -> Rename """
222
from rename import OliveRename
223
wt = WorkingTree.open_containing(self.path + os.sep + self.selected)[0]
224
rename = OliveRename(wt, wt.relpath(self.path), self.selected)
182
227
def open_file(self, action):
183
228
""" Right context menu -> Open """
184
229
# Open only the selected file
249
def revert(self, action):
250
""" Right context menu -> Revert """
251
wt, path = WorkingTree.open_containing(self.path)
252
ret = wt.revert([os.path.join(path, self.selected)])
254
warning_dialog(_('Conflicts detected'),
255
_('Please have a look at the working tree before continuing.'))
257
info_dialog(_('Revert successful'),
258
_('All files reverted to last revision.'))
259
self.app.refresh_right()
204
261
def commit(self, action):
205
262
""" Right context menu -> Commit """
206
from commit import OliveCommit
207
wt, path = WorkingTree.open_containing(self.path)
208
commit = OliveCommit(wt, path)
263
from commit import CommitDialog
266
wt, path = WorkingTree.open_containing(self.path)
268
except NotBranchError, e:
271
commit = CommitDialog(wt, path, not branch, self.selected)
272
response = commit.run()
273
if response != gtk.RESPONSE_NONE:
276
if response == gtk.RESPONSE_OK:
277
self.app.refresh_right()
211
282
def diff(self, action):
212
283
""" Right context menu -> Diff """
213
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
216
wt = WorkingTree.open_containing(self.path)[0]
217
except errors.NotBranchError:
218
error_dialog(_('File is not in a branch'),
219
_('The selected file is not in a branch.'))
284
wt = WorkingTree.open_containing(self.path)[0]
222
285
window = DiffWindow()
223
286
parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
224
287
window.set_diff(wt.branch.nick, wt, parent_tree)
288
window.set_file(wt.relpath(self.path + os.sep + self.selected))
227
291
def bookmark(self, action):
234
298
warning_dialog(_('Location already bookmarked'),
235
299
_('The current directory is already bookmarked.\nSee the left panel for reference.'))
301
self.app.refresh_left()
237
303
def edit_bookmark(self, action):
238
304
""" Left context menu -> Edit """
239
from bookmark import OliveBookmark
305
from bookmark import BookmarkDialog
241
307
if self.selected != None:
242
bookmark = OliveBookmark(self.selected)
308
bookmark = BookmarkDialog(self.selected, self.app.window)
309
response = bookmark.run()
311
if response != gtk.RESPONSE_NONE:
314
if response == gtk.RESPONSE_OK:
315
self.app.refresh_left()
245
319
def remove_bookmark(self, action):
246
320
""" Left context menu -> Remove """
248
322
if self.selected != None:
249
self.pref.remove_bookmark(self.comm.get_selected_left())
250
self.comm.refresh_left()
323
self.pref.remove_bookmark(self.selected)
326
self.app.refresh_left()
252
328
def open_folder(self, action):
253
329
""" Left context menu -> Open Folder """
265
341
from diff import OliveDiff
266
342
diff = OliveDiff(self.comm)
345
def view_remote(self, action):
346
""" Remote context menu -> View contents """
347
print "DEBUG: view contents."
349
def diff_remote(self, action):
350
""" Remote context menu -> Show differences """
351
print "DEBUG: show differences."
353
def revert_remote(self, action):
354
""" Remote context menu -> Revert to this revision """
355
print "DEBUG: revert to this revision."