/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
from commit import OliveCommit
35
from diff import OliveDiff
36
37
class OliveMenu:
38
    """ This class is responsible for building the context menus. """
39
    def __init__(self, gladefile, comm, dialog):
40
        # Load the UI file
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"
45
        
46
        self.gladefile = gladefile
47
        self.comm = comm
48
        self.dialog = dialog
49
        
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
50
        # Create the file list context menu
51
        self.ui = gtk.UIManager()
52
        
53
        self.actiongroup = gtk.ActionGroup('context')
54
        self.actiongroup.add_actions([('add', gtk.STOCK_ADD,
55
                                       'Add', None,
56
                                       'Add the selected file',
57
                                       self.add_file),
58
                                      ('remove', gtk.STOCK_REMOVE,
59
                                       'Remove', None,
60
                                       'Remove the selected file',
61
                                       self.remove_file),
62
                                      ('commit', gtk.STOCK_REDO,
63
                                       'Commit', None,
64
                                       'Commit the changes',
65
                                       self.commit),
66
                                      ('diff', None,
67
                                       'Diff', None,
68
                                       'Show the diff of the file',
69
                                       self.diff),
70
                                      ('log', None,
71
                                       'Log', None,
72
                                       'Show the log of the file',
73
                                       self.log),
74
                                      ('bookmark', None,
75
                                       'Bookmark', None,
76
                                       'Bookmark current location',
77
                                       self.bookmark),
78
                                      ('remove_bookmark', gtk.STOCK_REMOVE,
79
                                       'Remove', None,
80
                                       'Remove the selected bookmark',
81
                                       self.remove_bookmark)
82
                                     ])
83
        
84
        self.ui.insert_action_group(self.actiongroup, 0)
85
        self.ui.add_ui_from_file(self.uifile)
86
        
87
        self.cmenu_right = self.ui.get_widget('/context_right')
88
        
89
        self.cmenu_left = self.ui.get_widget('/context_left')
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
90
91
    def right_context_menu(self):
92
        return self.cmenu_right
93
    
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
94
    def left_context_menu(self):
95
        return self.cmenu_left
96
    
0.8.26 by Szilveszter Farkas (Phanatic)
Implemented Diff window; added menu.py (was missing from last commit)
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()
102
            
103
        if filename is None:
104
            self.dialog.error_dialog('No file was selected.')
105
            return
106
        
107
        try:
108
            fileops.add([directory + '/' + filename])
109
        except errors.NotBranchError:
110
            self.dialog.error_dialog('The directory is not a branch.')
111
            return
112
        except:
113
            raise
114
        
115
        self.comm.refresh_right()
116
    
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()
122
        
123
        if filename is None:
124
            self.dialog.error_dialog('No file was selected.')
125
            return
126
        
127
        try:
128
            fileops.remove([directory + '/' + filename])
129
        except errors.NotBranchError:
130
            self.dialog.error_dialog('The directory is not a branch.')
131
            return
132
        except errors.NotVersionedError:
133
            self.dialog.error_dialog('Selected file is not versioned.')
134
            return
135
        except:
136
            raise
137
        
138
        self.comm.refresh_right()
139
140
    def commit(self, action):
141
        """ Right context menu -> Commit """
142
        commit = OliveCommit(self.gladefile, self.comm)
143
        commit.display()
144
    
145
    def diff(self, action):
146
        """ Right context menu -> Diff """
147
        diff = OliveDiff(self.gladefile, self.comm)
148
        diff.display()
149
    
150
    def log(self, action):
151
        """ Right context menu -> Log """
152
        self.dialog.error_dialog('This feature is not yet implemented.')
0.8.33 by Szilveszter Farkas (Phanatic)
Implemented bookmarking.
153
    
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.')
158
        else:
159
            self.dialog.warning_dialog('Location already bookmarked.')
160
        
161
        self.comm.refresh_left()
162
163
    def remove_bookmark(self, action):
164
        """ Left context menu -> Remove """
165
        self.comm.pref.remove_bookmark(self.comm.get_selected_left())
166
        
167
        self.comm.refresh_left()