28
30
import bzrlib.errors as errors
30
from dialog import error_dialog
31
from olive import gladefile
34
""" Display Commit dialog and perform the needed actions. """
35
def __init__(self, wt, wtpath):
36
""" Initialize the Commit dialog. """
37
self.glade = gtk.glade.XML(gladefile, 'window_commit', 'olive-gtk')
31
from bzrlib import osutils
33
from dialog import error_dialog, question_dialog
34
from errors import show_bzr_error
35
from guifiles import GLADEFILENAME
37
class CommitDialog(gtk.Dialog):
38
""" New implementation of the Commit dialog. """
39
def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
40
""" Initialize the Commit Dialog. """
41
gtk.Dialog.__init__(self, title="Commit - Olive",
44
buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
40
48
self.wtpath = wtpath
42
# Get some important widgets
43
self.window = self.glade.get_widget('window_commit')
44
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
45
self.textview = self.glade.get_widget('textview_commit')
46
self.file_view = self.glade.get_widget('treeview_commit_select')
47
self.pending_label = self.glade.get_widget('label_commit_pending')
48
self.pending_view = self.glade.get_widget('treeview_commit_pending')
50
file_id = self.wt.path2id(wtpath)
52
self.notbranch = False
49
self.notbranch = notbranch
50
self.selected = selected
58
53
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
61
56
# Get pending merges
62
57
self.pending = self._pending_merges(self.wt)
64
# Dictionary for signal_autoconnect
65
dic = { "on_button_commit_commit_clicked": self.commit,
66
"on_button_commit_cancel_clicked": self.close }
68
# Connect the signals to the handlers
69
self.glade.signal_autoconnect(dic)
71
# Create the file list
72
self._create_file_view()
73
# Create the pending merges
74
self._create_pending_merges()
77
""" Display the Push dialog. """
59
# Do some preliminary checks
60
self._is_checkout = False
61
self._is_pending = False
62
if self.wt is None and not self.notbranch:
63
error_dialog(_('Directory does not have a working tree'),
64
_('Operation aborted.'))
79
69
error_dialog(_('Directory is not a branch'),
80
70
_('You can perform this action only in a branch.'))
83
74
if self.wt.branch.get_bound_location() is not None:
84
75
# we have a checkout, so the local commit checkbox must appear
85
self.checkbutton_local.show()
76
self._is_checkout = True
88
79
# There are pending merges, file selection not supported
89
self.file_view.set_sensitive(False)
92
self.pending_view.set_sensitive(False)
94
self.textview.modify_font(pango.FontDescription("Monospace"))
98
def _create_file_view(self):
99
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
102
self.file_view.set_model(self.file_store)
103
crt = gtk.CellRendererToggle()
104
crt.set_property("activatable", True)
105
crt.connect("toggled", self._toggle_commit, self.file_store)
106
self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
108
self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
109
gtk.CellRendererText(), text=1))
110
self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
111
gtk.CellRendererText(), text=2))
113
for path, id, kind in self.delta.added:
114
self.file_store.append([ True, path, _('added') ])
116
for path, id, kind in self.delta.removed:
117
self.file_store.append([ True, path, _('removed') ])
119
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
120
self.file_store.append([ True, oldpath, _('renamed') ])
122
for path, id, kind, text_modified, meta_modified in self.delta.modified:
123
self.file_store.append([ True, path, _('modified') ])
125
def _create_pending_merges(self):
126
liststore = gtk.ListStore(gobject.TYPE_STRING,
129
self.pending_view.set_model(liststore)
131
self.pending_view.append_column(gtk.TreeViewColumn(_('Date'),
132
gtk.CellRendererText(), text=0))
133
self.pending_view.append_column(gtk.TreeViewColumn(_('Committer'),
134
gtk.CellRendererText(), text=1))
135
self.pending_view.append_column(gtk.TreeViewColumn(_('Summary'),
136
gtk.CellRendererText(), text=2))
80
self._is_pending = True
83
self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
85
self._check_local = gtk.CheckButton(_("_Local only commit (works in checkouts)"),
87
self._check_strict = gtk.CheckButton(_("_Strict commit (fails if unknown files are present)"),
89
self._expander_files = gtk.Expander(_("Please select the file(s) to commit"))
90
self._vpaned_main = gtk.VPaned()
91
self._scrolledwindow_files = gtk.ScrolledWindow()
92
self._scrolledwindow_message = gtk.ScrolledWindow()
93
self._treeview_files = gtk.TreeView()
94
self._vbox_message = gtk.VBox()
95
self._label_message = gtk.Label(_("Please specify a commit message:"))
96
self._textview_message = gtk.TextView()
99
self._expander_merges = gtk.Expander(_("Pending merges"))
100
self._vpaned_list = gtk.VPaned()
101
self._scrolledwindow_merges = gtk.ScrolledWindow()
102
self._treeview_merges = gtk.TreeView()
105
self._button_commit.connect('clicked', self._on_commit_clicked)
106
self._treeview_files.connect('row_activated', self._on_treeview_files_row_activated)
109
self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
110
gtk.POLICY_AUTOMATIC)
111
self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
112
gtk.POLICY_AUTOMATIC)
113
self._textview_message.modify_font(pango.FontDescription("Monospace"))
114
self.set_default_size(500, 500)
115
self._vpaned_main.set_position(200)
118
self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
119
gtk.POLICY_AUTOMATIC)
120
self._treeview_files.set_sensitive(False)
122
# Construct the dialog
123
self.action_area.pack_end(self._button_commit)
125
self._scrolledwindow_files.add(self._treeview_files)
126
self._scrolledwindow_message.add(self._textview_message)
128
self._expander_files.add(self._scrolledwindow_files)
130
self._vbox_message.pack_start(self._label_message, False, False)
131
self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
134
self._expander_merges.add(self._scrolledwindow_merges)
135
self._scrolledwindow_merges.add(self._treeview_merges)
136
self._vpaned_list.add1(self._expander_files)
137
self._vpaned_list.add2(self._expander_merges)
138
self._vpaned_main.add1(self._vpaned_list)
140
self._vpaned_main.add1(self._expander_files)
142
self._vpaned_main.add2(self._vbox_message)
144
self.vbox.pack_start(self._vpaned_main, True, True)
145
if self._is_checkout:
146
self.vbox.pack_start(self._check_local, False, False)
147
self.vbox.pack_start(self._check_strict, False, False)
149
# Create the file list
150
self._create_file_view()
151
# Create the pending merges
152
self._create_pending_merges()
154
# Expand the corresponding expander
156
self._expander_merges.set_expanded(True)
158
self._expander_files.set_expanded(True)
163
def _on_treeview_files_row_activated(self, treeview, path, view_column):
164
# FIXME: the diff window freezes for some reason
165
treeselection = treeview.get_selection()
166
(model, iter) = treeselection.get_selected()
169
from olive import DiffWindow
171
_selected = model.get_value(iter, 1)
174
parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
175
diff.set_diff(self.wt.branch.nick, self.wt, parent_tree)
177
diff.set_file(_selected)
178
except errors.NoSuchFile:
183
def _on_commit_clicked(self, button):
184
""" Commit button clicked handler. """
185
textbuffer = self._textview_message.get_buffer()
186
start, end = textbuffer.get_bounds()
187
message = textbuffer.get_text(start, end).decode('utf-8')
138
189
if not self.pending:
190
specific_files = self._get_specific_files()
192
specific_files = None
195
response = question_dialog(_('Commit with an empty message?'),
196
_('You can describe your commit intent in the message.'))
197
if response == gtk.RESPONSE_NO:
198
# Kindly give focus to message area
199
self._textview_message.grab_focus()
202
if self._is_checkout:
203
local = self._check_local.get_active()
141
for item in self.pending:
142
liststore.append([ item['date'],
146
def _get_specific_files(self):
148
it = self.file_store.get_iter_first()
150
if self.file_store.get_value(it, 0):
151
ret.append(self.file_store.get_value(it, 1))
152
it = self.file_store.iter_next(it)
208
self.wt.commit(message,
209
allow_pointless=False,
210
strict=self._check_strict.get_active(),
212
specific_files=specific_files)
213
except errors.PointlessCommit:
214
response = question_dialog(_('Commit with no changes?'),
215
_('There are no changes in the working tree.'))
216
if response == gtk.RESPONSE_YES:
217
self.wt.commit(message,
218
allow_pointless=True,
219
strict=self._check_strict.get_active(),
221
specific_files=specific_files)
222
self.response(gtk.RESPONSE_OK)
156
def _toggle_commit(self, cell, path, model):
157
model[path][0] = not model[path][0]
160
224
def _pending_merges(self, wt):
161
225
""" Return a list of pending merges or None if there are none of them. """
162
226
parents = wt.get_parent_ids()
224
def commit(self, widget):
225
textbuffer = self.textview.get_buffer()
226
start, end = textbuffer.get_bounds()
227
message = textbuffer.get_text(start, end)
229
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
230
checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
288
def _create_file_view(self):
289
self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, # [0] checkbox
290
gobject.TYPE_STRING, # [1] path to display
291
gobject.TYPE_STRING, # [2] changes type
292
gobject.TYPE_STRING) # [3] real path
293
self._treeview_files.set_model(self._file_store)
294
crt = gtk.CellRendererToggle()
295
crt.set_property("activatable", True)
296
crt.connect("toggled", self._toggle_commit, self._file_store)
297
self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
299
self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
300
gtk.CellRendererText(), text=1))
301
self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
302
gtk.CellRendererText(), text=2))
304
for path, id, kind in self.delta.added:
305
marker = osutils.kind_marker(kind)
306
if self.selected is not None:
307
if path == os.path.join(self.wtpath, self.selected):
308
self._file_store.append([ True, path+marker, _('added'), path ])
310
self._file_store.append([ False, path+marker, _('added'), path ])
312
self._file_store.append([ True, path+marker, _('added'), path ])
314
for path, id, kind in self.delta.removed:
315
marker = osutils.kind_marker(kind)
316
if self.selected is not None:
317
if path == os.path.join(self.wtpath, self.selected):
318
self._file_store.append([ True, path+marker, _('removed'), path ])
320
self._file_store.append([ False, path+marker, _('removed'), path ])
322
self._file_store.append([ True, path+marker, _('removed'), path ])
324
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
325
marker = osutils.kind_marker(kind)
326
if text_modified or meta_modified:
327
changes = _('renamed and modified')
329
changes = _('renamed')
330
if self.selected is not None:
331
if newpath == os.path.join(self.wtpath, self.selected):
332
self._file_store.append([ True,
333
oldpath+marker + ' => ' + newpath+marker,
338
self._file_store.append([ False,
339
oldpath+marker + ' => ' + newpath+marker,
344
self._file_store.append([ True,
345
oldpath+marker + ' => ' + newpath+marker,
350
for path, id, kind, text_modified, meta_modified in self.delta.modified:
351
marker = osutils.kind_marker(kind)
352
if self.selected is not None:
353
if path == os.path.join(self.wtpath, self.selected):
354
self._file_store.append([ True, path+marker, _('modified'), path ])
356
self._file_store.append([ False, path+marker, _('modified'), path ])
358
self._file_store.append([ True, path+marker, _('modified'), path ])
360
def _create_pending_merges(self):
232
361
if not self.pending:
233
specific_files = self._get_specific_files()
235
specific_files = None
238
self.wt.commit(message,
239
allow_pointless=checkbutton_force.get_active(),
240
strict=checkbutton_strict.get_active(),
241
local=self.checkbutton_local.get_active(),
242
specific_files=specific_files)
243
except errors.NotBranchError:
244
error_dialog(_('Directory is not a branch'),
245
_('You can perform this action only in a branch.'))
247
except errors.LocalRequiresBoundBranch:
248
error_dialog(_('Directory is not a checkout'),
249
_('You can perform local commit only on checkouts.'))
251
except errors.PointlessCommit:
252
error_dialog(_('No changes to commit'),
253
_('Try force commit if you want to commit anyway.'))
255
except errors.ConflictsInTree:
256
error_dialog(_('Conflicts in tree'),
257
_('You need to resolve the conflicts before committing.'))
259
except errors.StrictCommitFailed:
260
error_dialog(_('Strict commit failed'),
261
_('There are unknown files in the working tree.\nPlease add or delete them.'))
263
except errors.BoundBranchOutOfDate, errmsg:
264
error_dialog(_('Bound branch is out of date'),
267
except errors.BzrError, msg:
268
error_dialog(_('Unknown bzr error'), str(msg))
270
except Exception, msg:
271
error_dialog(_('Unknown error'), str(msg))
276
def close(self, widget=None):
277
self.window.destroy()
364
liststore = gtk.ListStore(gobject.TYPE_STRING,
367
self._treeview_merges.set_model(liststore)
369
self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
370
gtk.CellRendererText(), text=0))
371
self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
372
gtk.CellRendererText(), text=1))
373
self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
374
gtk.CellRendererText(), text=2))
376
for item in self.pending:
377
liststore.append([ item['date'],
381
def _get_specific_files(self):
383
it = self._file_store.get_iter_first()
385
if self._file_store.get_value(it, 0):
386
# get real path from hidden column 3
387
ret.append(self._file_store.get_value(it, 3))
388
it = self._file_store.iter_next(it)
392
def _toggle_commit(self, cell, path, model):
393
model[path][0] = not model[path][0]