61
61
# Get pending merges
62
62
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. """
64
# Do some preliminary checks
65
self._is_checkout = False
66
self._is_pending = False
67
if self.wt is None and not self.notbranch:
68
error_dialog(_('Directory does not have a working tree'),
69
_('Operation aborted.'))
79
74
error_dialog(_('Directory is not a branch'),
80
75
_('You can perform this action only in a branch.'))
83
79
if self.wt.branch.get_bound_location() is not None:
84
80
# we have a checkout, so the local commit checkbox must appear
85
self.checkbutton_local.show()
81
self._is_checkout = True
88
84
# 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))
85
self._is_pending = True
88
self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
89
self._expander_files = gtk.Expander(_("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(_("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)
116
self._button_commit.set_flags(gtk.CAN_DEFAULT)
119
self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
120
gtk.POLICY_AUTOMATIC)
121
self._treeview_files.set_sensitive(False)
123
# Construct the dialog
124
self.action_area.pack_end(self._button_commit)
126
self._scrolledwindow_files.add(self._treeview_files)
127
self._scrolledwindow_message.add(self._textview_message)
129
self._expander_files.add(self._scrolledwindow_files)
131
self._vbox_message.pack_start(self._label_message, False, False)
132
self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
135
self._expander_merges.add(self._scrolledwindow_merges)
136
self._scrolledwindow_merges.add(self._treeview_merges)
137
self._vpaned_list.add1(self._expander_files)
138
self._vpaned_list.add2(self._expander_merges)
139
self._vpaned_main.add1(self._vpaned_list)
141
self._vpaned_main.add1(self._expander_files)
143
self._vpaned_main.add2(self._vbox_message)
145
self.vbox.pack_start(self._vpaned_main, True, True)
146
if self._is_checkout:
147
self._check_local = gtk.CheckButton(_("_Only commit locally"),
149
self.vbox.pack_start(self._check_local, False, False)
151
bus = dbus.SystemBus()
152
proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
153
'/org/freedesktop/NetworkManager')
154
dbus_iface = dbus.Interface(
155
proxy_obj, 'org.freedesktop.NetworkManager')
157
# 3 is the enum value for STATE_CONNECTED
158
self._check_local.set_active(dbus_iface.state() != 3)
159
except dbus.DBusException, e:
160
# Silently drop errors. While DBus may be
161
# available, NetworkManager doesn't necessarily have to be
162
mutter("unable to get networkmanager state: %r" % e)
164
# Create the file list
165
self._create_file_view()
166
# Create the pending merges
167
self._create_pending_merges()
169
# Expand the corresponding expander
171
self._expander_merges.set_expanded(True)
173
self._expander_files.set_expanded(True)
178
# Default to Commit button
179
self._button_commit.grab_default()
181
def _on_treeview_files_row_activated(self, treeview, path, view_column):
182
# FIXME: the diff window freezes for some reason
183
treeselection = treeview.get_selection()
184
(model, iter) = treeselection.get_selected()
187
from diff import DiffWindow
189
_selected = model.get_value(iter, 1)
192
diff.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
194
parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
195
diff.set_diff(self.wt.branch.nick, self.wt, parent_tree)
197
diff.set_file(_selected)
198
except errors.NoSuchFile:
203
def _on_commit_clicked(self, button):
204
""" Commit button clicked handler. """
205
textbuffer = self._textview_message.get_buffer()
206
start, end = textbuffer.get_bounds()
207
message = textbuffer.get_text(start, end).decode('utf-8')
138
209
if not self.pending:
210
specific_files = self._get_specific_files()
212
specific_files = None
215
response = question_dialog(_('Commit with an empty message?'),
216
_('You can describe your commit intent in the message.'))
217
if response == gtk.RESPONSE_NO:
218
# Kindly give focus to message area
219
self._textview_message.grab_focus()
222
if self._is_checkout:
223
local = self._check_local.get_active()
227
if list(self.wt.unknowns()) != []:
228
response = question_dialog(_("Commit with unknowns?"),
229
_("Unknown files exist in the working tree. Commit anyway?"))
230
if response == gtk.RESPONSE_NO:
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)
234
self.wt.commit(message,
235
allow_pointless=False,
238
specific_files=specific_files)
239
except errors.PointlessCommit:
240
response = question_dialog(_('Commit with no changes?'),
241
_('There are no changes in the working tree.'))
242
if response == gtk.RESPONSE_YES:
243
self.wt.commit(message,
244
allow_pointless=True,
247
specific_files=specific_files)
248
self.response(gtk.RESPONSE_OK)
156
def _toggle_commit(self, cell, path, model):
157
model[path][0] = not model[path][0]
160
250
def _pending_merges(self, wt):
161
251
""" Return a list of pending merges or None if there are none of them. """
162
252
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')
314
def _create_file_view(self):
315
self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, # [0] checkbox
316
gobject.TYPE_STRING, # [1] path to display
317
gobject.TYPE_STRING, # [2] changes type
318
gobject.TYPE_STRING) # [3] real path
319
self._treeview_files.set_model(self._file_store)
320
crt = gtk.CellRendererToggle()
321
crt.set_property("activatable", True)
322
crt.connect("toggled", self._toggle_commit, self._file_store)
323
self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
325
self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
326
gtk.CellRendererText(), text=1))
327
self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
328
gtk.CellRendererText(), text=2))
330
for path, id, kind in self.delta.added:
331
marker = osutils.kind_marker(kind)
332
if self.selected is not None:
333
if path == os.path.join(self.wtpath, self.selected):
334
self._file_store.append([ True, path+marker, _('added'), path ])
336
self._file_store.append([ False, path+marker, _('added'), path ])
338
self._file_store.append([ True, path+marker, _('added'), path ])
340
for path, id, kind in self.delta.removed:
341
marker = osutils.kind_marker(kind)
342
if self.selected is not None:
343
if path == os.path.join(self.wtpath, self.selected):
344
self._file_store.append([ True, path+marker, _('removed'), path ])
346
self._file_store.append([ False, path+marker, _('removed'), path ])
348
self._file_store.append([ True, path+marker, _('removed'), path ])
350
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
351
marker = osutils.kind_marker(kind)
352
if text_modified or meta_modified:
353
changes = _('renamed and modified')
355
changes = _('renamed')
356
if self.selected is not None:
357
if newpath == os.path.join(self.wtpath, self.selected):
358
self._file_store.append([ True,
359
oldpath+marker + ' => ' + newpath+marker,
364
self._file_store.append([ False,
365
oldpath+marker + ' => ' + newpath+marker,
370
self._file_store.append([ True,
371
oldpath+marker + ' => ' + newpath+marker,
376
for path, id, kind, text_modified, meta_modified in self.delta.modified:
377
marker = osutils.kind_marker(kind)
378
if self.selected is not None:
379
if path == os.path.join(self.wtpath, self.selected):
380
self._file_store.append([ True, path+marker, _('modified'), path ])
382
self._file_store.append([ False, path+marker, _('modified'), path ])
384
self._file_store.append([ True, path+marker, _('modified'), path ])
386
def _create_pending_merges(self):
232
387
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()
390
liststore = gtk.ListStore(gobject.TYPE_STRING,
393
self._treeview_merges.set_model(liststore)
395
self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
396
gtk.CellRendererText(), text=0))
397
self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
398
gtk.CellRendererText(), text=1))
399
self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
400
gtk.CellRendererText(), text=2))
402
for item in self.pending:
403
liststore.append([ item['date'],
407
def _get_specific_files(self):
409
it = self._file_store.get_iter_first()
411
if self._file_store.get_value(it, 0):
412
# get real path from hidden column 3
413
ret.append(self._file_store.get_value(it, 3))
414
it = self._file_store.iter_next(it)
418
def _toggle_commit(self, cell, path, model):
419
model[path][0] = not model[path][0]