/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: Scott James Remnant
  • Date: 2005-10-17 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

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