28
28
import bzrlib.errors as errors
29
from dialog import error_dialog
29
from bzrlib.workingtree import WorkingTree
31
from dialog import error_dialog, info_dialog, warning_dialog
31
32
from launch import launch
33
from olive import OlivePreferences
34
36
""" This class is responsible for building the context menus. """
37
def __init__(self, path, selected):
37
39
if sys.platform == 'win32':
38
40
self.uifile = os.path.dirname(sys.executable) + "/share/olive/cmenu.ui"
48
50
print _('UI description file cannot be found.')
54
self.pref = OlivePreferences()
58
self.selected = selected
59
print "DEBUG: path =", self.path
60
print "DEBUG: selected =", self.selected
51
62
# Create the file list context menu
52
63
self.ui = gtk.UIManager()
106
117
self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
109
commit_menu = self.ui.get_widget('/context_right/commit')
110
commit_image = self.comm.menuitem_branch_commit.get_image()
111
commit_pixbuf = commit_image.get_pixbuf()
112
commit_icon = gtk.Image()
113
commit_icon.set_from_pixbuf(commit_pixbuf)
114
commit_menu.set_image(commit_icon)
115
diff_menu = self.ui.get_widget('/context_right/diff')
116
diff_image = self.comm.menuitem_stats_diff.get_image()
117
diff_pixbuf = diff_image.get_pixbuf()
118
diff_icon = gtk.Image()
119
diff_icon.set_from_pixbuf(diff_pixbuf)
120
diff_menu.set_image(diff_icon)
120
# TODO: do it without using deprecated comm
121
#commit_menu = self.ui.get_widget('/context_right/commit')
122
#commit_image = self.comm.menuitem_branch_commit.get_image()
123
#commit_pixbuf = commit_image.get_pixbuf()
124
#commit_icon = gtk.Image()
125
#commit_icon.set_from_pixbuf(commit_pixbuf)
126
#commit_menu.set_image(commit_icon)
127
#diff_menu = self.ui.get_widget('/context_right/diff')
128
#diff_image = self.comm.menuitem_stats_diff.get_image()
129
#diff_pixbuf = diff_image.get_pixbuf()
130
#diff_icon = gtk.Image()
131
#diff_icon.set_from_pixbuf(diff_pixbuf)
132
#diff_menu.set_image(diff_icon)
122
134
def right_context_menu(self):
123
135
return self.cmenu_right
128
140
def add_file(self, action):
129
141
""" Right context menu -> Add """
130
144
# Add only the selected file
131
directory = self.comm.get_path()
132
filename = self.comm.get_selected_right()
145
directory = self.path
146
filename = self.selected
134
148
if filename is None:
135
149
error_dialog(_('No file was selected'),
142
156
error_dialog(_('Directory is not a branch'),
143
157
_('You can perform this action only in a branch.'))
146
self.comm.refresh_right()
148
160
def remove_file(self, action):
149
161
""" Right context menu -> Remove """
150
162
# Remove only the selected file
151
directory = self.comm.get_path()
152
filename = self.comm.get_selected_right()
163
directory = self.path
164
filename = self.selected
154
166
if filename is None:
155
167
error_dialog(_('No file was selected'),
160
wt, path = WorkingTree.open_containing(directory+'/'+filename)
172
wt, path = WorkingTree.open_containing(directory + os.sep + filename)
163
175
except errors.NotBranchError:
164
176
error_dialog(_('Directory is not a branch'),
165
_('You can perform this action only in a branch.'))
177
_('You can perform this action only in a branch.'))
167
179
except errors.NotVersionedError:
168
180
error_dialog(_('File not versioned'),
169
_('The selected file is not versioned.'))
181
_('The selected file is not versioned.'))
172
self.comm.refresh_right()
174
184
def open_file(self, action):
175
185
""" Right context menu -> Open """
176
186
# Open only the selected file
177
filename = self.comm.get_selected_right()
187
filename = self.selected
179
189
if filename is None:
180
190
error_dialog(_('No file was selected'),
181
_('Please select a file from the list,\nor choose the other option.'))
191
_('Please select a file from the list,\nor choose the other option.'))
184
194
if filename == '..':
185
self.comm.set_path(os.path.split(self.comm.get_path())[0])
195
# TODO: how to enter a directory?
187
fullpath = self.comm.get_path() + os.sep + filename
198
fullpath = self.path + os.sep + filename
188
199
if os.path.isdir(fullpath):
189
200
# selected item is an existant directory
190
self.comm.set_path(fullpath)
201
# TODO: how to enter a directory?
194
self.comm.refresh_right()
196
206
def commit(self, action):
197
207
""" Right context menu -> Commit """
198
208
from commit import OliveCommit
199
wt, path = WorkingTree.open_containing(self.comm.get_path())
209
wt, path = WorkingTree.open_containing(self.path)
200
210
commit = OliveCommit(wt, path)
209
219
def bookmark(self, action):
210
220
""" Right context menu -> Bookmark """
211
if self.comm.pref.add_bookmark(self.comm.get_path()):
221
if self.pref.add_bookmark(self.comm.get_path()):
212
222
info_dialog(_('Bookmark successfully added'),
213
_('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
223
_('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
215
225
warning_dialog(_('Location already bookmarked'),
216
_('The current directory is already bookmarked.\nSee the left panel for reference.'))
218
self.comm.refresh_left()
226
_('The current directory is already bookmarked.\nSee the left panel for reference.'))
220
228
def edit_bookmark(self, action):
221
229
""" Left context menu -> Edit """
222
230
from bookmark import OliveBookmark
224
if self.comm.get_selected_left() != None:
225
bookmark = OliveBookmark(self.comm)
232
if self.selected != None:
233
bookmark = OliveBookmark()
226
234
bookmark.display()
228
236
def remove_bookmark(self, action):
229
237
""" Left context menu -> Remove """
231
if self.comm.get_selected_left() != None:
232
self.comm.pref.remove_bookmark(self.comm.get_selected_left())
239
if self.selected != None:
240
self.pref.remove_bookmark(self.comm.get_selected_left())
233
241
self.comm.refresh_left()
235
243
def open_folder(self, action):
236
244
""" Left context menu -> Open Folder """
237
path = self.comm.get_selected_left()