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 errors import show_bzr_error
32
33
from launch import launch
33
from olive import OlivePreferences
34
from olive import Preferences, DiffWindow
36
37
""" This class is responsible for building the context menus. """
37
def __init__(self, path, selected):
38
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.')
40
from guifiles import UIFILENAME
42
self.uifile = UIFILENAME
53
44
# Preferences handler
54
self.pref = OlivePreferences()
45
self.pref = Preferences()
56
47
# Set default values
58
49
self.selected = selected
60
52
# Create the file list context menu
61
53
self.ui = gtk.UIManager()
148
149
_('Please select a file from the list,\nor choose the other option.'))
152
bzrlib.add.smart_add([directory + '/' + filename])
153
except errors.NotBranchError:
154
error_dialog(_('Directory is not a branch'),
155
_('You can perform this action only in a branch.'))
152
bzrlib.add.smart_add([os.path.join(directory, filename)])
158
155
def remove_file(self, action):
159
156
""" Right context menu -> Remove """
160
157
# Remove only the selected file
166
163
_('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.'))
166
wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
168
self.app.set_path(self.path)
169
self.app.refresh_right()
171
def rename_file(self, action):
172
""" Right context menu -> Rename """
173
from rename import OliveRename
174
wt = WorkingTree.open_containing(self.path + os.sep + self.selected)[0]
175
rename = OliveRename(wt, wt.relpath(self.path), self.selected)
182
178
def open_file(self, action):
183
179
""" Right context menu -> Open """
184
180
# Open only the selected file
200
def revert(self, action):
201
""" Right context menu -> Revert """
202
wt, path = WorkingTree.open_containing(self.path)
203
ret = wt.revert([os.path.join(path, self.selected)])
205
warning_dialog(_('Conflicts detected'),
206
_('Please have a look at the working tree before continuing.'))
208
info_dialog(_('Revert successful'),
209
_('All files reverted to last revision.'))
210
self.app.refresh_right()
204
212
def commit(self, action):
205
213
""" Right context menu -> Commit """
206
214
from commit import CommitDialog
207
wt, path = WorkingTree.open_containing(self.path)
208
commit = CommitDialog(wt, path)
217
wt, path = WorkingTree.open_containing(self.path)
219
except NotBranchError, e:
222
commit = CommitDialog(wt, path, not branch, self.selected)
223
response = commit.run()
224
if response != gtk.RESPONSE_NONE:
227
if response == gtk.RESPONSE_OK:
228
self.app.refresh_right()
211
233
def diff(self, action):
212
234
""" 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.'))
235
wt = WorkingTree.open_containing(self.path)[0]
222
236
window = DiffWindow()
223
237
parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
224
238
window.set_diff(wt.branch.nick, wt, parent_tree)
239
window.set_file(wt.relpath(self.path + os.sep + self.selected))
227
242
def bookmark(self, action):
234
249
warning_dialog(_('Location already bookmarked'),
235
250
_('The current directory is already bookmarked.\nSee the left panel for reference.'))
252
self.app.refresh_left()
237
254
def edit_bookmark(self, action):
238
255
""" Left context menu -> Edit """
239
from bookmark import OliveBookmark
256
from bookmark import BookmarkDialog
241
258
if self.selected != None:
242
bookmark = OliveBookmark(self.selected)
259
bookmark = BookmarkDialog(self.selected, self.app.window)
260
response = bookmark.run()
262
if response != gtk.RESPONSE_NONE:
265
if response == gtk.RESPONSE_OK:
266
self.app.refresh_left()
245
270
def remove_bookmark(self, action):
246
271
""" Left context menu -> Remove """
248
273
if self.selected != None:
249
self.pref.remove_bookmark(self.comm.get_selected_left())
250
self.comm.refresh_left()
274
self.pref.remove_bookmark(self.selected)
277
self.app.refresh_left()
252
279
def open_folder(self, action):
253
280
""" Left context menu -> Open Folder """