/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: Jelmer Vernooij
  • Date: 2006-09-27 17:56:26 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927175626-4462e9dc20d422b1
Bunch of random cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
2
 
 
 
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
7
 
 
 
7
#
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
11
# GNU General Public License for more details.
12
 
 
 
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29
29
except:
30
30
    sys.exit(1)
31
31
 
32
 
import bzrlib
33
 
 
34
 
if bzrlib.version_info[1] < 9:
35
 
    # function deprecated after 0.9
36
 
    from bzrlib.delta import compare_trees
 
32
from bzrlib import version_info
37
33
 
38
34
import bzrlib.errors as errors
39
35
from bzrlib.workingtree import WorkingTree
40
36
 
41
 
from dialog import OliveDialog
 
37
from dialog import error_dialog
42
38
 
43
39
class OliveCommit:
44
40
    """ Display Commit dialog and perform the needed actions. """
45
 
    def __init__(self, gladefile, comm):
 
41
    def __init__(self, gladefile, wt, wtpath):
46
42
        """ Initialize the Commit dialog. """
47
43
        self.gladefile = gladefile
48
 
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit')
49
 
        
50
 
        self.comm = comm
51
 
        
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)
 
44
        self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
 
45
        
 
46
        self.wt = wt
 
47
        self.wtpath = wtpath
 
48
 
 
49
        # Get some important widgets
 
50
        self.window = self.glade.get_widget('window_commit')
 
51
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
 
52
        self.textview = self.glade.get_widget('textview_commit')
 
53
        self.file_view = self.glade.get_widget('treeview_commit_select')
 
54
 
 
55
        file_id = self.wt.path2id(wtpath)
65
56
 
66
57
        self.notbranch = False
67
58
        if file_id is None:
70
61
        
71
62
        # Set the delta
72
63
        self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
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)
77
 
        
78
 
        # Get the Commit dialog widget
79
 
        self.window = self.glade.get_widget('window_commit')
 
64
        self.delta = self.wt.changes_from(self.old_tree)
80
65
        
81
66
        # Dictionary for signal_autoconnect
82
67
        dic = { "on_button_commit_commit_clicked": self.commit,
87
72
        
88
73
        # Create the file list
89
74
        self._create_file_view()
90
 
        
91
 
        # Some additional widgets
92
 
        self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
93
 
        self.textview = self.glade.get_widget('textview_commit')
94
75
    
95
76
    def display(self):
96
77
        """ Display the Push dialog. """
97
78
        if self.notbranch:
98
 
            self.dialog.error_dialog('Directory is not a branch.')
 
79
            error_dialog(_('Directory is not a branch'),
 
80
                                     _('You can perform this action only in a branch.'))
 
81
            self.close()
99
82
        else:
100
 
            from olive.backend.info import is_checkout
101
 
            if is_checkout(self.comm.get_path()):
 
83
            if self.wt.branch.get_bound_location() is not None:
102
84
                # we have a checkout, so the local commit checkbox must appear
103
85
                self.checkbutton_local.show()
104
86
            
106
88
            self.window.show()
107
89
            
108
90
    
109
 
    # This code is from Jelmer Vernooij's bzr-gtk branch
110
91
    def _create_file_view(self):
111
92
        self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
112
93
                                        gobject.TYPE_STRING,
113
94
                                        gobject.TYPE_STRING)
114
 
        self.file_view = self.glade.get_widget('treeview_commit_select')
115
95
        self.file_view.set_model(self.file_store)
116
96
        crt = gtk.CellRendererToggle()
117
97
        crt.set_property("activatable", True)
118
98
        crt.connect("toggled", self._toggle_commit, self.file_store)
119
 
        self.file_view.append_column(gtk.TreeViewColumn("Commit",
 
99
        self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
120
100
                                     crt, active=0))
121
 
        self.file_view.append_column(gtk.TreeViewColumn("Path",
 
101
        self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
122
102
                                     gtk.CellRendererText(), text=1))
123
 
        self.file_view.append_column(gtk.TreeViewColumn("Type",
 
103
        self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
124
104
                                     gtk.CellRendererText(), text=2))
125
105
 
126
 
        for path, _, _ in self.delta.added:
127
 
            self.file_store.append([ True, path, "added" ])
128
 
 
129
 
        for path, _, _ in self.delta.removed:
130
 
            self.file_store.append([ True, path, "removed" ])
131
 
 
132
 
        for oldpath, _, _, _, _, _ in self.delta.renamed:
133
 
            self.file_store.append([ True, oldpath, "renamed"])
134
 
 
135
 
        for path, _, _, _, _ in self.delta.modified:
136
 
            self.file_store.append([ True, path, "modified"])
 
106
        for path, id, kind in self.delta.added:
 
107
            self.file_store.append([ True, path, _('added') ])
 
108
 
 
109
        for path, id, kind in self.delta.removed:
 
110
            self.file_store.append([ True, path, _('removed') ])
 
111
 
 
112
        for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
 
113
            self.file_store.append([ True, oldpath, _('renamed') ])
 
114
 
 
115
        for path, id, kind, text_modified, meta_modified in self.delta.modified:
 
116
            self.file_store.append([ True, path, _('modified') ])
137
117
    
138
118
    def _get_specific_files(self):
139
119
        ret = []
160
140
        
161
141
        specific_files = self._get_specific_files()
162
142
        
163
 
        self.comm.set_busy(self.window)
164
 
        # merged from Jelmer Vernooij's olive integration branch
165
143
        try:
166
144
            self.wt.commit(message, 
167
145
                           allow_pointless=checkbutton_force.get_active(),
169
147
                           local=self.checkbutton_local.get_active(),
170
148
                           specific_files=specific_files)
171
149
        except errors.NotBranchError:
172
 
            self.dialog.error_dialog('Directory is not a branch.')
173
 
            self.comm.set_busy(self.window, False)
 
150
            error_dialog(_('Directory is not a branch'),
 
151
                                     _('You can perform this action only in a branch.'))
174
152
            return
175
153
        except errors.LocalRequiresBoundBranch:
176
 
            self.dialog.error_dialog('Local commit requires a bound branch.')
177
 
            self.comm.set_busy(self.window, False)
 
154
            error_dialog(_('Directory is not a checkout'),
 
155
                                     _('You can perform local commit only on checkouts.'))
178
156
            return
179
157
        except errors.PointlessCommit:
180
 
            self.dialog.error_dialog('No changes to commit. Try force commit.')
181
 
            self.comm.set_busy(self.window, False)
 
158
            error_dialog(_('No changes to commit'),
 
159
                                     _('Try force commit if you want to commit anyway.'))
182
160
            return
183
161
        except errors.ConflictsInTree:
184
 
            self.dialog.error_dialog('Conflicts in tree. Please resolve them first.')
185
 
            self.comm.set_busy(self.window, False)
 
162
            error_dialog(_('Conflicts in tree'),
 
163
                                     _('You need to resolve the conflicts before committing.'))
186
164
            return
187
165
        except errors.StrictCommitFailed:
188
 
            self.dialog.error_dialog('Strict commit failed. There are unknown files.')
189
 
            self.comm.set_busy(self.window, False)
 
166
            error_dialog(_('Strict commit failed'),
 
167
                                     _('There are unknown files in the working tree.\nPlease add or delete them.'))
190
168
            return
191
169
        except errors.BoundBranchOutOfDate, errmsg:
192
 
            self.dialog.error_dialog('Bound branch is out of date: %s' % errmsg)
193
 
            self.comm.set_busy(self.window, False)
194
 
            return
195
 
        except:
196
 
            raise
 
170
            error_dialog(_('Bound branch is out of date'),
 
171
                                     _('%s') % errmsg)
 
172
            return
 
173
        except errors.BzrError, msg:
 
174
            error_dialog(_('Unknown bzr error'), str(msg))
 
175
            return
 
176
        except Exception, msg:
 
177
            error_dialog(_('Unknown error'), str(msg))
 
178
            return
197
179
        
198
180
        self.close()
199
181
        self.comm.refresh_right()