/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
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 sys
18
19
try:
20
    import pygtk
21
    pygtk.require("2.0")
22
except:
23
    pass
24
try:
25
    import gtk
26
    import gtk.glade
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
27
    import gobject
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
28
except:
29
    sys.exit(1)
30
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
31
from bzrlib.delta import compare_trees
32
import bzrlib.errors as errors
33
from bzrlib.workingtree import WorkingTree
34
35
from dialog import OliveDialog
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
36
37
class OliveCommit:
38
    """ Display Commit dialog and perform the needed actions. """
39
    def __init__(self, gladefile, comm):
40
        """ Initialize the Commit dialog. """
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
41
        import bzrlib
42
        
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
43
        self.gladefile = gladefile
44
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit')
45
        
46
        self.comm = comm
47
        
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
48
        self.dialog = OliveDialog(self.gladefile)
49
        
50
        # Check if current location is a branch
51
        try:
52
            (self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
53
            branch = self.wt.branch
54
        except errors.NotBranchError:
55
            self.notbranch = True
56
            return
57
        except:
58
            raise
59
60
        file_id = self.wt.path2id(path)
61
62
        self.notbranch = False
63
        if file_id is None:
64
            self.notbranch = True
65
            return
66
        
67
        # Set the delta
68
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
69
        if bzrlib.version_info[1] < 9:
70
            self.delta = compare_trees(self.old_tree, self.wt)
71
        else:
72
            self.delta = self.wt.changes_from(self.old_tree)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
73
        
74
        # Get the Commit dialog widget
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
75
        self.window = self.glade.get_widget('window_commit')
76
        
77
        # Dictionary for signal_autoconnect
78
        dic = { "on_button_commit_commit_clicked": self.commit,
79
                "on_button_commit_cancel_clicked": self.close }
80
        
81
        # Connect the signals to the handlers
82
        self.glade.signal_autoconnect(dic)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
83
        
84
        # Create the file list
85
        self._create_file_view()
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
86
        
87
        # Some additional widgets
88
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
89
    
90
    def display(self):
91
        """ Display the Push dialog. """
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
92
        if self.notbranch:
93
            self.dialog.error_dialog('Directory is not a branch.')
94
        else:
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
95
            from olive.backend.info import is_checkout
96
            if is_checkout(self.comm.get_path()):
97
                # we have a checkout, so the local commit checkbox must appear
98
                self.checkbutton_local.show()
99
            
100
            self.window.show()
101
            
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
102
    
103
    # This code is from Jelmer Vernooij's bzr-gtk branch
104
    def _create_file_view(self):
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
105
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
106
                                        gobject.TYPE_STRING,
107
                                        gobject.TYPE_STRING)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
108
        self.file_view = self.glade.get_widget('treeview_commit_select')
109
        self.file_view.set_model(self.file_store)
110
        crt = gtk.CellRendererToggle()
111
        crt.set_property("activatable", True)
112
        crt.connect("toggled", self._toggle_commit, self.file_store)
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
113
        self.file_view.append_column(gtk.TreeViewColumn("Commit",
114
                                     crt, active=0))
115
        self.file_view.append_column(gtk.TreeViewColumn("Path",
116
                                     gtk.CellRendererText(), text=1))
117
        self.file_view.append_column(gtk.TreeViewColumn("Type",
118
                                     gtk.CellRendererText(), text=2))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
119
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
120
        for path, _, _ in self.delta.added:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
121
            self.file_store.append([ True, path, "added" ])
122
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
123
        for path, _, _ in self.delta.removed:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
124
            self.file_store.append([ True, path, "removed" ])
125
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
126
        for oldpath, _, _, _, _, _ in self.delta.renamed:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
127
            self.file_store.append([ True, oldpath, "renamed"])
128
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
129
        for path, _, _, _, _ in self.delta.modified:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
130
            self.file_store.append([ True, path, "modified"])
131
    
132
    def _get_specific_files(self):
133
        ret = []
134
        it = self.file_store.get_iter_first()
135
        while it:
136
            if self.file_store.get_value(it, 0):
0.8.21 by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
137
                ret.append(self.file_store.get_value(it, 1))
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
138
            it = self.file_store.iter_next(it)
139
140
        return ret
141
    # end of bzr-gtk code
142
    
143
    def _toggle_commit(self, cell, path, model):
144
        model[path][0] = not model[path][0]
145
        return
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
146
    
147
    def commit(self, widget):
148
        textview = self.glade.get_widget('textview_commit')
149
        textbuffer = textview.get_buffer()
150
        start, end = textbuffer.get_bounds()
151
        message = textbuffer.get_text(start, end)
152
        
153
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
154
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
155
        
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
156
        specific_files = self._get_specific_files()
157
        
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
158
        self.comm.set_busy(self.window)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
159
        # merged from Jelmer Vernooij's olive integration branch
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
160
        try:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
161
            self.wt.commit(message, 
162
                           allow_pointless=checkbutton_force.get_active(),
163
                           strict=checkbutton_strict.get_active(),
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
164
                           local=self.checkbutton_local.get_active(),
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
165
                           specific_files=specific_files)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
166
        except errors.NotBranchError:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
167
            self.dialog.error_dialog('Directory is not a branch.')
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
168
            self.comm.set_busy(self.window, False)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
169
            return
170
        except errors.LocalRequiresBoundBranch:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
171
            self.dialog.error_dialog('Local commit requires a bound branch.')
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
172
            self.comm.set_busy(self.window, False)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
173
            return
174
        except errors.PointlessCommit:
175
            self.dialog.error_dialog('No changes to commit. Try force commit.')
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
176
            self.comm.set_busy(self.window, False)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
177
            return
178
        except errors.ConflictsInTree:
179
            self.dialog.error_dialog('Conflicts in tree. Please resolve them first.')
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
180
            self.comm.set_busy(self.window, False)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
181
            return
182
        except errors.StrictCommitFailed:
183
            self.dialog.error_dialog('Strict commit failed. There are unknown files.')
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
184
            self.comm.set_busy(self.window, False)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
185
            return
186
        except errors.BoundBranchOutOfDate, errmsg:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
187
            self.dialog.error_dialog('Bound branch is out of date: %s' % errmsg)
0.8.23 by Szilveszter Farkas (Phanatic)
Visual feedback when Olive is busy; follow bzr API changes; commit dialog update
188
            self.comm.set_busy(self.window, False)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
189
            return
190
        except:
191
            raise
192
        
193
        self.close()
194
        self.comm.refresh_right()
195
        
196
    def close(self, widget=None):
197
        self.window.destroy()