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 errors import show_bzr_error
31
from dialog import error_dialog, info_dialog, warning_dialog
33
32
from launch import launch
34
from olive import Preferences, DiffWindow
33
from olive import OlivePreferences
37
36
""" This class is responsible for building the context menus. """
38
def __init__(self, path, selected, app=None):
37
def __init__(self, path, selected):
40
from guifiles import UIFILENAME
42
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.')
44
53
# Preferences handler
45
self.pref = Preferences()
54
self.pref = OlivePreferences()
47
56
# Set default values
49
58
self.selected = selected
59
print "DEBUG: path =", self.path
60
print "DEBUG: selected =", self.selected
52
62
# Create the file list context menu
53
63
self.ui = gtk.UIManager()
149
150
_('Please select a file from the list,\nor choose the other option.'))
152
bzrlib.add.smart_add([os.path.join(directory, filename)])
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.'))
155
160
def remove_file(self, action):
156
161
""" Right context menu -> Remove """
157
162
# Remove only the selected file
163
168
_('Please select a file from the list,\nor choose the other option.'))
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)
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.'))
178
184
def open_file(self, action):
179
185
""" Right context menu -> Open """
180
186
# 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()
212
206
def commit(self, action):
213
207
""" Right context menu -> Commit """
214
from commit import CommitDialog
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()
208
from commit import OliveCommit
209
wt, path = WorkingTree.open_containing(self.path)
210
commit = OliveCommit(wt, path)
233
213
def diff(self, action):
234
214
""" Right context menu -> Diff """
235
wt = WorkingTree.open_containing(self.path)[0]
236
window = DiffWindow()
237
parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
238
window.set_diff(wt.branch.nick, wt, parent_tree)
239
window.set_file(wt.relpath(self.path + os.sep + self.selected))
215
from diff import OliveDiff
216
diff = OliveDiff(self.comm)
242
219
def bookmark(self, action):
243
220
""" Right context menu -> Bookmark """
244
if self.pref.add_bookmark(self.path):
221
if self.pref.add_bookmark(self.comm.get_path()):
245
222
info_dialog(_('Bookmark successfully added'),
246
223
_('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
249
225
warning_dialog(_('Location already bookmarked'),
250
226
_('The current directory is already bookmarked.\nSee the left panel for reference.'))
252
self.app.refresh_left()
254
228
def edit_bookmark(self, action):
255
229
""" Left context menu -> Edit """
256
from bookmark import BookmarkDialog
230
from bookmark import OliveBookmark
258
232
if self.selected != None:
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()
233
bookmark = OliveBookmark(self.selected)
270
236
def remove_bookmark(self, action):
271
237
""" Left context menu -> Remove """
273
239
if self.selected != None:
274
self.pref.remove_bookmark(self.selected)
277
self.app.refresh_left()
240
self.pref.remove_bookmark(self.comm.get_selected_left())
241
self.comm.refresh_left()
279
243
def open_folder(self, action):
280
244
""" Left context menu -> Open Folder """