/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. """
41
        self.gladefile = gladefile
42
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit')
43
        
44
        self.comm = comm
45
        
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
46
        self.dialog = OliveDialog(self.gladefile)
47
        
48
        # Check if current location is a branch
49
        try:
50
            (self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
51
            branch = self.wt.branch
52
        except errors.NotBranchError:
53
            self.notbranch = True
54
            return
55
        except:
56
            raise
57
58
        file_id = self.wt.path2id(path)
59
60
        self.notbranch = False
61
        if file_id is None:
62
            self.notbranch = True
63
            return
64
        
65
        # Set the delta
66
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
67
        self.delta = compare_trees(self.old_tree, self.wt)
68
        
69
        # Get the Commit dialog widget
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
70
        self.window = self.glade.get_widget('window_commit')
71
        
72
        # Dictionary for signal_autoconnect
73
        dic = { "on_button_commit_commit_clicked": self.commit,
74
                "on_button_commit_cancel_clicked": self.close }
75
        
76
        # Connect the signals to the handlers
77
        self.glade.signal_autoconnect(dic)
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
78
        
79
        # Create the file list
80
        self._create_file_view()
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
81
    
82
    def display(self):
83
        """ Display the Push dialog. """
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
84
        if self.notbranch:
85
            self.dialog.error_dialog('Directory is not a branch.')
86
        else:
87
            self.window.show_all()
88
    
89
    # This code is from Jelmer Vernooij's bzr-gtk branch
90
    def _create_file_view(self):
91
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING, gobject.TYPE_STRING)
92
        self.file_view = self.glade.get_widget('treeview_commit_select')
93
        self.file_view.set_model(self.file_store)
94
        crt = gtk.CellRendererToggle()
95
        crt.set_property("activatable", True)
96
        crt.connect("toggled", self._toggle_commit, self.file_store)
97
        self.file_view.append_column(gtk.TreeViewColumn("Commit",crt,active=0))
98
        self.file_view.append_column(gtk.TreeViewColumn("Path",gtk.CellRendererText(),text=1))
99
        self.file_view.append_column(gtk.TreeViewColumn("Type",gtk.CellRendererText(),text=2))
100
101
        for path, id, kind in self.delta.added:
102
            self.file_store.append([ True, path, "added" ])
103
104
        for path, id, kind in self.delta.removed:
105
            self.file_store.append([ True, path, "removed" ])
106
107
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
108
            self.file_store.append([ True, oldpath, "renamed"])
109
110
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
111
            self.file_store.append([ True, path, "modified"])
112
    
113
    def _get_specific_files(self):
114
        ret = []
115
        it = self.file_store.get_iter_first()
116
        while it:
117
            if self.file_store.get_value(it, 0):
118
                ret.append(self.file_store.get_value(it,1))
119
            it = self.file_store.iter_next(it)
120
121
        return ret
122
    # end of bzr-gtk code
123
    
124
    def _toggle_commit(self, cell, path, model):
125
        model[path][0] = not model[path][0]
126
        return
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
127
    
128
    def commit(self, widget):
129
        textview = self.glade.get_widget('textview_commit')
130
        textbuffer = textview.get_buffer()
131
        start, end = textbuffer.get_bounds()
132
        message = textbuffer.get_text(start, end)
133
        
134
        checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
135
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
136
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
137
        
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
138
        specific_files = self._get_specific_files()
139
        
140
        # merged from Jelmer Vernooij's olive integration branch
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
141
        try:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
142
            self.wt.commit(message, 
143
                           allow_pointless=checkbutton_force.get_active(),
144
                           strict=checkbutton_strict.get_active(),
145
                           local=checkbutton_local.get_active(),
146
                           specific_files=specific_files)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
147
        except errors.NotBranchError:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
148
            self.dialog.error_dialog('Directory is not a branch.')
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
149
            return
150
        except errors.LocalRequiresBoundBranch:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
151
            self.dialog.error_dialog('Local commit requires a bound branch.')
152
            return
153
        except errors.PointlessCommit:
154
            self.dialog.error_dialog('No changes to commit. Try force commit.')
155
            return
156
        except errors.ConflictsInTree:
157
            self.dialog.error_dialog('Conflicts in tree. Please resolve them first.')
158
            return
159
        except errors.StrictCommitFailed:
160
            self.dialog.error_dialog('Strict commit failed. There are unknown files.')
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
161
            return
162
        except errors.BoundBranchOutOfDate, errmsg:
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
163
            self.dialog.error_dialog('Bound branch is out of date: %s' % errmsg)
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
164
            return
165
        except:
166
            raise
167
        
168
        self.close()
169
        self.comm.refresh_right()
170
        
171
    def close(self, widget=None):
172
        self.window.destroy()