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