/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
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.
7
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.
12
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
16
17
import os.path
18
import sys
19
20
try:
21
    import pygtk
22
    pygtk.require("2.0")
23
except:
24
    pass
25
try:
26
    import gtk
27
    import gtk.glade
28
except:
29
    sys.exit(1)
30
31
import olive.backend.fileops as fileops
32
import olive.backend.errors as errors
33
34
class OliveMenu:
35
    """ This class is responsible for building the context menus. """
36
    def __init__(self, gladefile, comm, dialog):
37
        # Load the UI file
38
        self.uifile = "/usr/share/olive/cmenu.ui"
39
        if not os.path.exists(self.uifile):
40
            # Load from current directory if not installed
41
            self.uifile = "cmenu.ui"
42
        
43
        self.gladefile = gladefile
44
        self.comm = comm
45
        self.dialog = dialog
46
        
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
47
        # Create the file list context menu
48
        self.ui = gtk.UIManager()
49
        
50
        self.actiongroup = gtk.ActionGroup('context')
51
        self.actiongroup.add_actions([('add', gtk.STOCK_ADD,
52
                                       'Add', None,
53
                                       'Add the selected file',
54
                                       self.add_file),
55
                                      ('remove', gtk.STOCK_REMOVE,
56
                                       'Remove', None,
57
                                       'Remove the selected file',
58
                                       self.remove_file),
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
59
                                      ('commit', None,
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
60
                                       'Commit', None,
61
                                       'Commit the changes',
62
                                       self.commit),
63
                                      ('diff', None,
64
                                       'Diff', None,
65
                                       'Show the diff of the file',
66
                                       self.diff),
67
                                      ('log', None,
68
                                       'Log', None,
69
                                       'Show the log of the file',
70
                                       self.log),
71
                                      ('bookmark', None,
72
                                       'Bookmark', None,
73
                                       'Bookmark current location',
74
                                       self.bookmark),
75
                                      ('remove_bookmark', gtk.STOCK_REMOVE,
76
                                       'Remove', None,
77
                                       'Remove the selected bookmark',
78
                                       self.remove_bookmark)
79
                                     ])
80
        
81
        self.ui.insert_action_group(self.actiongroup, 0)
82
        self.ui.add_ui_from_file(self.uifile)
83
        
84
        self.cmenu_right = self.ui.get_widget('/context_right')
85
        
86
        self.cmenu_left = self.ui.get_widget('/context_left')
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
87
        
88
        # Set icons
89
        commit_menu = self.ui.get_widget('/context_right/commit')
90
        commit_image = self.comm.menuitem_branch_commit.get_image()
91
        commit_pixbuf = commit_image.get_pixbuf()
92
        commit_icon = gtk.Image()
93
        commit_icon.set_from_pixbuf(commit_pixbuf)
94
        commit_menu.set_image(commit_icon)
95
        diff_menu = self.ui.get_widget('/context_right/diff')
96
        diff_image = self.comm.menuitem_stats_diff.get_image()
97
        diff_pixbuf = diff_image.get_pixbuf()
98
        diff_icon = gtk.Image()
99
        diff_icon.set_from_pixbuf(diff_pixbuf)
100
        diff_menu.set_image(diff_icon)
101
        log_menu = self.ui.get_widget('/context_right/log')
102
        log_image = self.comm.menuitem_stats_log.get_image()
103
        log_pixbuf = log_image.get_pixbuf()
104
        log_icon = gtk.Image()
105
        log_icon.set_from_pixbuf(log_pixbuf)
106
        log_menu.set_image(log_icon)
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
107
108
    def right_context_menu(self):
109
        return self.cmenu_right
110
    
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
111
    def left_context_menu(self):
112
        return self.cmenu_left
113
    
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
114
    def add_file(self, action):
115
        """ Right context menu -> Add """
116
        # Add only the selected file
117
        directory = self.comm.get_path()
118
        filename = self.comm.get_selected_right()
119
            
120
        if filename is None:
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
121
            self.dialog.error_dialog('No file was selected',
122
                                     'Please select a file from the list,\nor choose the other option.')
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
123
            return
124
        
125
        try:
126
            fileops.add([directory + '/' + filename])
127
        except errors.NotBranchError:
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
128
            self.dialog.error_dialog('Directory is not a branch',
129
                                     'You can perform this action only in a branch.')
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
130
            return
131
        except:
132
            raise
133
        
134
        self.comm.refresh_right()
135
    
136
    def remove_file(self, action):
137
        """ Right context menu -> Remove """
138
        # Remove only the selected file
139
        directory = self.comm.get_path()
140
        filename = self.comm.get_selected_right()
141
        
142
        if filename is None:
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
143
            self.dialog.error_dialog('No file was selected',
144
                                     'Please select a file from the list,\nor choose the other option.')
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
145
            return
146
        
147
        try:
148
            fileops.remove([directory + '/' + filename])
149
        except errors.NotBranchError:
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
150
            self.dialog.error_dialog('Directory is not a branch',
151
                                     'You can perform this action only in a branch.')
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
152
            return
153
        except errors.NotVersionedError:
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
154
            self.dialog.error_dialog('File not versioned',
155
                                     'The selected file is not versioned.')
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
156
            return
157
        except:
158
            raise
159
        
160
        self.comm.refresh_right()
161
162
    def commit(self, action):
163
        """ Right context menu -> Commit """
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
164
        from commit import OliveCommit
165
        commit = OliveCommit(self.gladefile, self.comm, self.dialog)
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
166
        commit.display()
167
    
168
    def diff(self, action):
169
        """ Right context menu -> Diff """
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
170
        from diff import OliveDiff
171
        diff = OliveDiff(self.gladefile, self.comm, self.dialog)
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
172
        diff.display()
173
    
174
    def log(self, action):
175
        """ Right context menu -> Log """
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
176
        from log import OliveLog
177
        log = OliveLog(self.gladefile, self.comm, self.dialog)
178
        log.display()
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
179
    
180
    def bookmark(self, action):
181
        """ Right context menu -> Bookmark """
182
        if self.comm.pref.add_bookmark(self.comm.get_path()):
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
183
            self.dialog.info_dialog('Bookmark successfully added',
184
                                    'The current directory was bookmarked. You can reach\nit by selecting it from the left panel.')
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
185
        else:
0.8.50 by Szilveszter Farkas (Phanatic)
Major updates in the OliveMenu class.
186
            self.dialog.warning_dialog('Location already bookmarked'
187
                                       'The current directory is already bookmarked.\nSee the left panel for reference.')
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
188
        
189
        self.comm.refresh_left()
190
191
    def remove_bookmark(self, action):
192
        """ Left context menu -> Remove """
193
        self.comm.pref.remove_bookmark(self.comm.get_selected_left())
194
        
195
        self.comm.refresh_left()