21
21
pygtk.require("2.0")
29
from bzrlib import version_info
34
if bzrlib.version_info < (0, 9):
35
# function deprecated after 0.9
36
from bzrlib.delta import compare_trees
31
38
import bzrlib.errors as errors
32
39
from bzrlib.workingtree import WorkingTree
34
from dialog import error_dialog
35
from olive import gladefile
38
42
""" Display Commit dialog and perform the needed actions. """
39
def __init__(self, wt, wtpath):
43
def __init__(self, gladefile, comm, dialog):
40
44
""" Initialize the Commit dialog. """
41
self.glade = gtk.glade.XML(gladefile, 'window_commit', 'olive-gtk')
46
# Get some important widgets
45
self.gladefile = gladefile
46
self.glade = gtk.glade.XML(self.gladefile, 'window_commit')
48
# Communication object
53
# Get the Commit dialog widget
47
54
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')
52
file_id = self.wt.path2id(wtpath)
56
# Check if current location is a branch
58
(self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
59
branch = self.wt.branch
60
except errors.NotBranchError:
66
file_id = self.wt.path2id(path)
54
68
self.notbranch = False
55
69
if file_id is None:
60
74
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
61
self.delta = self.wt.changes_from(self.old_tree)
75
if bzrlib.version_info < (0, 9):
76
self.delta = compare_trees(self.old_tree, self.wt)
78
self.delta = self.wt.changes_from(self.old_tree)
63
80
# Dictionary for signal_autoconnect
64
81
dic = { "on_button_commit_commit_clicked": self.commit,
70
87
# Create the file list
71
88
self._create_file_view()
90
# Some additional widgets
91
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
92
self.textview = self.glade.get_widget('textview_commit')
74
95
""" Display the Push dialog. """
76
error_dialog(_('Directory is not a branch'),
77
_('You can perform this action only in a branch.'))
97
self.dialog.error_dialog('Directory is not a branch',
98
'You can perform this action only in a branch.')
80
if self.wt.branch.get_bound_location() is not None:
101
from olive.backend.info import is_checkout
102
if is_checkout(self.comm.get_path()):
81
103
# we have a checkout, so the local commit checkbox must appear
82
104
self.checkbutton_local.show()
85
107
self.window.show()
110
# This code is from Jelmer Vernooij's bzr-gtk branch
88
111
def _create_file_view(self):
89
112
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
90
113
gobject.TYPE_STRING,
91
114
gobject.TYPE_STRING)
115
self.file_view = self.glade.get_widget('treeview_commit_select')
92
116
self.file_view.set_model(self.file_store)
93
117
crt = gtk.CellRendererToggle()
94
118
crt.set_property("activatable", True)
95
119
crt.connect("toggled", self._toggle_commit, self.file_store)
96
self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
120
self.file_view.append_column(gtk.TreeViewColumn("Commit",
98
self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
122
self.file_view.append_column(gtk.TreeViewColumn("Path",
99
123
gtk.CellRendererText(), text=1))
100
self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
124
self.file_view.append_column(gtk.TreeViewColumn("Type",
101
125
gtk.CellRendererText(), text=2))
103
for path, id, kind in self.delta.added:
104
self.file_store.append([ True, path, _('added') ])
106
for path, id, kind in self.delta.removed:
107
self.file_store.append([ True, path, _('removed') ])
109
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
110
self.file_store.append([ True, oldpath, _('renamed') ])
112
for path, id, kind, text_modified, meta_modified in self.delta.modified:
113
self.file_store.append([ True, path, _('modified') ])
127
for path, _, _ in self.delta.added:
128
self.file_store.append([ True, path, "added" ])
130
for path, _, _ in self.delta.removed:
131
self.file_store.append([ True, path, "removed" ])
133
for oldpath, _, _, _, _, _ in self.delta.renamed:
134
self.file_store.append([ True, oldpath, "renamed"])
136
for path, _, _, _, _ in self.delta.modified:
137
self.file_store.append([ True, path, "modified"])
115
139
def _get_specific_files(self):
143
170
local=self.checkbutton_local.get_active(),
144
171
specific_files=specific_files)
145
172
except errors.NotBranchError:
146
error_dialog(_('Directory is not a branch'),
147
_('You can perform this action only in a branch.'))
173
self.dialog.error_dialog('Directory is not a branch',
174
'You can perform this action only in a branch.')
175
self.comm.set_busy(self.window, False)
149
177
except errors.LocalRequiresBoundBranch:
150
error_dialog(_('Directory is not a checkout'),
151
_('You can perform local commit only on checkouts.'))
178
self.dialog.error_dialog('Directory is not a checkout',
179
'You can perform local commit only on checkouts.')
180
self.comm.set_busy(self.window, False)
153
182
except errors.PointlessCommit:
154
error_dialog(_('No changes to commit'),
155
_('Try force commit if you want to commit anyway.'))
183
self.dialog.error_dialog('No changes to commit',
184
'Try force commit if you want to commit anyway.')
185
self.comm.set_busy(self.window, False)
157
187
except errors.ConflictsInTree:
158
error_dialog(_('Conflicts in tree'),
159
_('You need to resolve the conflicts before committing.'))
188
self.dialog.error_dialog('Conflicts in tree'
189
'You need to resolve the conflicts before committing.')
190
self.comm.set_busy(self.window, False)
161
192
except errors.StrictCommitFailed:
162
error_dialog(_('Strict commit failed'),
163
_('There are unknown files in the working tree.\nPlease add or delete them.'))
193
self.dialog.error_dialog('Strict commit failed'
194
'There are unknown files in the working tree.\nPlease add or delete them.')
195
self.comm.set_busy(self.window, False)
165
197
except errors.BoundBranchOutOfDate, errmsg:
166
error_dialog(_('Bound branch is out of date'),
169
except errors.BzrError, msg:
170
error_dialog(_('Unknown bzr error'), str(msg))
172
except Exception, msg:
173
error_dialog(_('Unknown error'), str(msg))
198
self.dialog.error_dialog('Bound branch is out of date',
200
self.comm.set_busy(self.window, False)
206
self.comm.refresh_right()
178
208
def close(self, widget=None):
179
209
self.window.destroy()