/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/commit.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-07-16 16:27:59 UTC
  • mto: (0.14.1 main) (93.1.1 win32.bialix)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060716162759-f3e8596921edc374
2006-07-16  Szilveszter Farkas <Szilveszter.Farkas@gmail.com>

    * Done some directory reorganization.
    * setup.py: added some basic install script
    * Began to implement the GTK UI.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
27
 
    import gobject
28
 
    import pango
29
 
except:
30
 
    sys.exit(1)
31
 
 
32
 
from bzrlib import version_info
33
 
 
34
 
import bzrlib.errors as errors
35
 
from bzrlib.workingtree import WorkingTree
36
 
 
37
 
class OliveCommit:
38
 
    """ Display Commit dialog and perform the needed actions. """
39
 
    def __init__(self, gladefile, wt, wtpath, dialog):
40
 
        """ Initialize the Commit dialog. """
41
 
        self.gladefile = gladefile
42
 
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
43
 
        
44
 
        self.wt = wt
45
 
        self.wtpath = wtpath
46
 
 
47
 
        # Dialog object
48
 
        self.dialog = dialog
49
 
        
50
 
        # Get some important widgets
51
 
        self.window = self.glade.get_widget('window_commit')
52
 
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
53
 
        self.textview = self.glade.get_widget('textview_commit')
54
 
        self.file_view = self.glade.get_widget('treeview_commit_select')
55
 
 
56
 
        file_id = self.wt.path2id(wtpath)
57
 
 
58
 
        self.notbranch = False
59
 
        if file_id is None:
60
 
            self.notbranch = True
61
 
            return
62
 
        
63
 
        # Set the delta
64
 
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
65
 
        if version_info < (0, 9):
66
 
            self.delta = compare_trees(self.old_tree, self.wt)
67
 
        else:
68
 
            self.delta = self.wt.changes_from(self.old_tree)
69
 
        
70
 
        # Dictionary for signal_autoconnect
71
 
        dic = { "on_button_commit_commit_clicked": self.commit,
72
 
                "on_button_commit_cancel_clicked": self.close }
73
 
        
74
 
        # Connect the signals to the handlers
75
 
        self.glade.signal_autoconnect(dic)
76
 
        
77
 
        # Create the file list
78
 
        self._create_file_view()
79
 
    
80
 
    def display(self):
81
 
        """ Display the Push dialog. """
82
 
        if self.notbranch:
83
 
            self.dialog.error_dialog(_('Directory is not a branch'),
84
 
                                     _('You can perform this action only in a branch.'))
85
 
            self.close()
86
 
        else:
87
 
            if self.wt.branch.get_bound_location() is not None:
88
 
                # we have a checkout, so the local commit checkbox must appear
89
 
                self.checkbutton_local.show()
90
 
            
91
 
            self.textview.modify_font(pango.FontDescription("Monospace"))
92
 
            self.window.show()
93
 
            
94
 
    
95
 
    def _create_file_view(self):
96
 
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
97
 
                                        gobject.TYPE_STRING,
98
 
                                        gobject.TYPE_STRING)
99
 
        self.file_view.set_model(self.file_store)
100
 
        crt = gtk.CellRendererToggle()
101
 
        crt.set_property("activatable", True)
102
 
        crt.connect("toggled", self._toggle_commit, self.file_store)
103
 
        self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
104
 
                                     crt, active=0))
105
 
        self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
106
 
                                     gtk.CellRendererText(), text=1))
107
 
        self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
108
 
                                     gtk.CellRendererText(), text=2))
109
 
 
110
 
        for path, id, kind in self.delta.added:
111
 
            self.file_store.append([ True, path, _('added') ])
112
 
 
113
 
        for path, id, kind in self.delta.removed:
114
 
            self.file_store.append([ True, path, _('removed') ])
115
 
 
116
 
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
117
 
            self.file_store.append([ True, oldpath, _('renamed') ])
118
 
 
119
 
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
120
 
            self.file_store.append([ True, path, _('modified') ])
121
 
    
122
 
    def _get_specific_files(self):
123
 
        ret = []
124
 
        it = self.file_store.get_iter_first()
125
 
        while it:
126
 
            if self.file_store.get_value(it, 0):
127
 
                ret.append(self.file_store.get_value(it, 1))
128
 
            it = self.file_store.iter_next(it)
129
 
 
130
 
        return ret
131
 
    # end of bzr-gtk code
132
 
    
133
 
    def _toggle_commit(self, cell, path, model):
134
 
        model[path][0] = not model[path][0]
135
 
        return
136
 
    
137
 
    def commit(self, widget):
138
 
        textbuffer = self.textview.get_buffer()
139
 
        start, end = textbuffer.get_bounds()
140
 
        message = textbuffer.get_text(start, end)
141
 
        
142
 
        checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
143
 
        checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
144
 
        
145
 
        specific_files = self._get_specific_files()
146
 
        
147
 
        try:
148
 
            self.wt.commit(message, 
149
 
                           allow_pointless=checkbutton_force.get_active(),
150
 
                           strict=checkbutton_strict.get_active(),
151
 
                           local=self.checkbutton_local.get_active(),
152
 
                           specific_files=specific_files)
153
 
        except errors.NotBranchError:
154
 
            self.dialog.error_dialog(_('Directory is not a branch'),
155
 
                                     _('You can perform this action only in a branch.'))
156
 
            return
157
 
        except errors.LocalRequiresBoundBranch:
158
 
            self.dialog.error_dialog(_('Directory is not a checkout'),
159
 
                                     _('You can perform local commit only on checkouts.'))
160
 
            return
161
 
        except errors.PointlessCommit:
162
 
            self.dialog.error_dialog(_('No changes to commit'),
163
 
                                     _('Try force commit if you want to commit anyway.'))
164
 
            return
165
 
        except errors.ConflictsInTree:
166
 
            self.dialog.error_dialog(_('Conflicts in tree'),
167
 
                                     _('You need to resolve the conflicts before committing.'))
168
 
            return
169
 
        except errors.StrictCommitFailed:
170
 
            self.dialog.error_dialog(_('Strict commit failed'),
171
 
                                     _('There are unknown files in the working tree.\nPlease add or delete them.'))
172
 
            return
173
 
        except errors.BoundBranchOutOfDate, errmsg:
174
 
            self.dialog.error_dialog(_('Bound branch is out of date'),
175
 
                                     _('%s') % errmsg)
176
 
            return
177
 
        except:
178
 
            raise
179
 
        
180
 
        self.close()
181
 
        self.comm.refresh_right()
182
 
        
183
 
    def close(self, widget=None):
184
 
        self.window.destroy()