28
28
import bzrlib.errors as errors
29
29
from bzrlib.workingtree import WorkingTree
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
31
from dialog import error_dialog, info_dialog, warning_dialog
36
32
from launch import launch
37
from olive import Preferences
33
from olive import OlivePreferences
40
36
""" This class is responsible for building the context menus. """
41
def __init__(self, path, selected, app=None):
37
def __init__(self, path, selected):
43
from guifiles import UIFILENAME
45
self.uifile = UIFILENAME
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.')
47
53
# Preferences handler
48
self.pref = Preferences()
54
self.pref = OlivePreferences()
50
56
# Set default values
52
58
self.selected = selected
59
print "DEBUG: path =", self.path
60
print "DEBUG: selected =", self.selected
55
62
# Create the file list context menu
56
63
self.ui = gtk.UIManager()
111
106
('diff_all', None,
112
107
_('All...'), None,
113
108
_('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'),
129
112
self.ui.insert_action_group(self.actiongroup, 0)
172
150
_('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)
199
window.annotate(wt, branch, file_id)
154
bzrlib.add.smart_add([directory + '/' + filename])
155
except errors.NotBranchError:
156
error_dialog(_('Directory is not a branch'),
157
_('You can perform this action only in a branch.'))
204
160
def remove_file(self, action):
205
161
""" Right context menu -> Remove """
206
162
# Remove only the selected file
212
168
_('Please select a file from the list,\nor choose the other option.'))
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)
172
wt, path = WorkingTree.open_containing(directory + os.sep + filename)
175
except errors.NotBranchError:
176
error_dialog(_('Directory is not a branch'),
177
_('You can perform this action only in a branch.'))
179
except errors.NotVersionedError:
180
error_dialog(_('File not versioned'),
181
_('The selected file is not versioned.'))
227
184
def open_file(self, action):
228
185
""" Right context menu -> Open """
229
186
# 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()
261
206
def commit(self, action):
262
207
""" Right context menu -> Commit """
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()
208
from commit import OliveCommit
209
wt, path = WorkingTree.open_containing(self.path)
210
commit = OliveCommit(wt, path)
282
213
def diff(self, action):
283
214
""" Right context menu -> Diff """
284
wt = WorkingTree.open_containing(self.path)[0]
285
window = DiffWindow()
286
parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
287
window.set_diff(wt.branch.nick, wt, parent_tree)
288
window.set_file(wt.relpath(self.path + os.sep + self.selected))
215
from diff import OliveDiff
216
diff = OliveDiff(self.comm)
291
219
def bookmark(self, action):
292
220
""" Right context menu -> Bookmark """
293
if self.pref.add_bookmark(self.path):
221
if self.pref.add_bookmark(self.comm.get_path()):
294
222
info_dialog(_('Bookmark successfully added'),
295
223
_('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
298
225
warning_dialog(_('Location already bookmarked'),
299
226
_('The current directory is already bookmarked.\nSee the left panel for reference.'))
301
self.app.refresh_left()
303
228
def edit_bookmark(self, action):
304
229
""" Left context menu -> Edit """
305
from bookmark import BookmarkDialog
230
from bookmark import OliveBookmark
307
232
if self.selected != None:
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()
233
bookmark = OliveBookmark(self.selected)
319
236
def remove_bookmark(self, action):
320
237
""" Left context menu -> Remove """
322
239
if self.selected != None:
323
self.pref.remove_bookmark(self.selected)
326
self.app.refresh_left()
240
self.pref.remove_bookmark(self.comm.get_selected_left())
241
self.comm.refresh_left()
328
243
def open_folder(self, action):
329
244
""" Left context menu -> Open Folder """
341
256
from diff import OliveDiff
342
257
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."