1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import os.path
import sys
try:
import pygtk
pygtk.require("2.0")
except:
pass
try:
import gtk
import gtk.glade
except:
sys.exit(1)
import olive.backend.fileops as fileops
import olive.backend.errors as errors
from commit import OliveCommit
from diff import OliveDiff
class OliveMenu:
""" This class is responsible for building the context menus. """
def __init__(self, gladefile, comm, dialog):
# Load the UI file
self.uifile = "/usr/share/olive/cmenu.ui"
if not os.path.exists(self.uifile):
# Load from current directory if not installed
self.uifile = "cmenu.ui"
self.gladefile = gladefile
self.comm = comm
self.dialog = dialog
self.ui_right = gtk.UIManager()
self.actiongroup_right = gtk.ActionGroup('context_right')
self.actiongroup_right.add_actions([('add', gtk.STOCK_ADD,
'Add', None,
'Add the selected file',
self.add_file),
('remove', gtk.STOCK_REMOVE,
'Remove', None,
'Remove the selected file',
self.remove_file),
('commit', gtk.STOCK_REDO,
'Commit', None,
'Commit the changes',
self.commit),
('diff', None,
'Diff', None,
'Show the diff of the file',
self.diff),
('log', None,
'Log', None,
'Show the log of the file',
self.log)])
self.ui_right.insert_action_group(self.actiongroup_right, 0)
self.ui_right.add_ui_from_file(self.uifile)
self.cmenu_right = self.ui_right.get_widget('/context_right')
def right_context_menu(self):
return self.cmenu_right
def add_file(self, action):
""" Right context menu -> Add """
# Add only the selected file
directory = self.comm.get_path()
filename = self.comm.get_selected_right()
if filename is None:
self.dialog.error_dialog('No file was selected.')
return
try:
fileops.add([directory + '/' + filename])
except errors.NotBranchError:
self.dialog.error_dialog('The directory is not a branch.')
return
except:
raise
self.comm.refresh_right()
def remove_file(self, action):
""" Right context menu -> Remove """
# Remove only the selected file
directory = self.comm.get_path()
filename = self.comm.get_selected_right()
if filename is None:
self.dialog.error_dialog('No file was selected.')
return
try:
fileops.remove([directory + '/' + filename])
except errors.NotBranchError:
self.dialog.error_dialog('The directory is not a branch.')
return
except errors.NotVersionedError:
self.dialog.error_dialog('Selected file is not versioned.')
return
except:
raise
self.comm.refresh_right()
def commit(self, action):
""" Right context menu -> Commit """
commit = OliveCommit(self.gladefile, self.comm)
commit.display()
def diff(self, action):
""" Right context menu -> Diff """
diff = OliveDiff(self.gladefile, self.comm)
diff.display()
def log(self, action):
""" Right context menu -> Log """
self.dialog.error_dialog('This feature is not yet implemented.')
|