1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
import olive.backend.fileops as fileops
32
import olive.backend.errors as errors
34
from commit import OliveCommit
35
from diff import OliveDiff
38
""" This class is responsible for building the context menus. """
39
def __init__(self, gladefile, comm, dialog):
41
self.uifile = "/usr/share/olive/cmenu.ui"
42
if not os.path.exists(self.uifile):
43
# Load from current directory if not installed
44
self.uifile = "cmenu.ui"
46
self.gladefile = gladefile
50
# Create the file list context menu
51
self.ui = gtk.UIManager()
53
self.actiongroup = gtk.ActionGroup('context')
54
self.actiongroup.add_actions([('add', gtk.STOCK_ADD,
56
'Add the selected file',
58
('remove', gtk.STOCK_REMOVE,
60
'Remove the selected file',
62
('commit', gtk.STOCK_REDO,
68
'Show the diff of the file',
72
'Show the log of the file',
76
'Bookmark current location',
78
('remove_bookmark', gtk.STOCK_REMOVE,
80
'Remove the selected bookmark',
84
self.ui.insert_action_group(self.actiongroup, 0)
85
self.ui.add_ui_from_file(self.uifile)
87
self.cmenu_right = self.ui.get_widget('/context_right')
89
self.cmenu_left = self.ui.get_widget('/context_left')
91
def right_context_menu(self):
92
return self.cmenu_right
94
def left_context_menu(self):
95
return self.cmenu_left
97
def add_file(self, action):
98
""" Right context menu -> Add """
99
# Add only the selected file
100
directory = self.comm.get_path()
101
filename = self.comm.get_selected_right()
104
self.dialog.error_dialog('No file was selected.')
108
fileops.add([directory + '/' + filename])
109
except errors.NotBranchError:
110
self.dialog.error_dialog('The directory is not a branch.')
115
self.comm.refresh_right()
117
def remove_file(self, action):
118
""" Right context menu -> Remove """
119
# Remove only the selected file
120
directory = self.comm.get_path()
121
filename = self.comm.get_selected_right()
124
self.dialog.error_dialog('No file was selected.')
128
fileops.remove([directory + '/' + filename])
129
except errors.NotBranchError:
130
self.dialog.error_dialog('The directory is not a branch.')
132
except errors.NotVersionedError:
133
self.dialog.error_dialog('Selected file is not versioned.')
138
self.comm.refresh_right()
140
def commit(self, action):
141
""" Right context menu -> Commit """
142
commit = OliveCommit(self.gladefile, self.comm)
145
def diff(self, action):
146
""" Right context menu -> Diff """
147
diff = OliveDiff(self.gladefile, self.comm)
150
def log(self, action):
151
""" Right context menu -> Log """
152
self.dialog.error_dialog('This feature is not yet implemented.')
154
def bookmark(self, action):
155
""" Right context menu -> Bookmark """
156
if self.comm.pref.add_bookmark(self.comm.get_path()):
157
self.dialog.info_dialog('Bookmark successfully added.')
159
self.dialog.warning_dialog('Location already bookmarked.')
161
self.comm.refresh_left()
163
def remove_bookmark(self, action):
164
""" Left context menu -> Remove """
165
self.comm.pref.remove_bookmark(self.comm.get_selected_left())
167
self.comm.refresh_left()