/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 commit.py

  • Committer: Jelmer Vernooij
  • Date: 2008-06-29 16:24:24 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629162424-48a6rrjmmpejfcyr
Stop emitting no longer used revisions-loaded message.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
from bzrlib import errors, osutils
31
31
from bzrlib.trace import mutter
 
32
from bzrlib.util import bencode
32
33
 
 
34
from bzrlib.plugins.gtk import _i18n
33
35
from dialog import error_dialog, question_dialog
34
36
from errors import show_bzr_error
35
37
 
103
105
                                  parent=parent,
104
106
                                  flags=0,
105
107
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
108
        self._question_dialog = question_dialog
 
109
 
106
110
        self._wt = wt
 
111
        # TODO: Do something with this value, it is used by Olive
 
112
        #       It used to set all changes but this one to False
107
113
        self._selected = selected
 
114
        self._enable_per_file_commits = True
 
115
        self._commit_all_changes = True
 
116
        self.committed_revision_id = None # Nothing has been committed yet
108
117
 
109
118
        self.setup_params()
110
119
        self.construct()
123
132
        self._fill_in_pending()
124
133
        self._fill_in_diff()
125
134
        self._fill_in_files()
 
135
        self._fill_in_checkout()
 
136
        self._fill_in_per_file_info()
126
137
 
127
138
    def _fill_in_pending(self):
128
139
        if not self._pending:
149
160
        self._pending_box.show()
150
161
 
151
162
    def _fill_in_files(self):
152
 
        # We should really use _iter_changes, and then add a progress bar of
153
 
        # some kind.
 
163
        # We should really use add a progress bar of some kind.
154
164
        # While we fill in the view, hide the store
155
165
        store = self._files_store
156
166
        self._treeview_files.set_model(None)
157
167
 
158
 
        added = _('added')
159
 
        removed = _('removed')
160
 
        renamed = _('renamed')
161
 
        renamed_and_modified = _('renamed and modified')
162
 
        modified = _('modified')
163
 
        kind_changed = _('kind changed')
 
168
        added = _i18n('added')
 
169
        removed = _i18n('removed')
 
170
        renamed = _i18n('renamed')
 
171
        renamed_and_modified = _i18n('renamed and modified')
 
172
        modified = _i18n('modified')
 
173
        kind_changed = _i18n('kind changed')
164
174
 
165
175
        # The store holds:
166
176
        # [file_id, real path, checkbox, display path, changes type, message]
167
 
        # _iter_changes returns:
 
177
        # iter_changes returns:
168
178
        # (file_id, (path_in_source, path_in_target),
169
179
        #  changed_content, versioned, parent, name, kind,
170
180
        #  executable)
171
181
 
 
182
        all_enabled = (self._selected is None)
172
183
        # The first entry is always the 'whole tree'
173
 
        store.append([None, None, True, 'All Files', '', ''])
 
184
        all_iter = store.append([None, None, all_enabled, 'All Files', '', ''])
 
185
        initial_cursor = store.get_path(all_iter)
174
186
        # should we pass specific_files?
175
187
        self._wt.lock_read()
176
188
        self._basis_tree.lock_read()
177
189
        try:
178
 
            for (file_id, paths, changed_content, versioned, parent_ids, names,
179
 
                 kinds, executables) in self._wt._iter_changes(self._basis_tree):
180
 
 
181
 
                # Skip the root entry.
182
 
                if parent_ids == (None, None):
183
 
                    continue
184
 
 
185
 
                change_type = None
186
 
                if kinds[0] is None:
187
 
                    source_marker = ''
188
 
                else:
189
 
                    source_marker = osutils.kind_marker(kinds[0])
190
 
                if kinds[1] is None:
191
 
                    assert kinds[0] is not None
192
 
                    marker = osutils.kind_marker(kinds[0])
193
 
                else:
194
 
                    marker = osutils.kind_marker(kinds[1])
195
 
 
196
 
                real_path = paths[1]
197
 
                if real_path is None:
198
 
                    real_path = paths[0]
199
 
                assert real_path is not None
200
 
                display_path = real_path + marker
201
 
 
202
 
                present_source = versioned[0] and kinds[0] is not None
203
 
                present_target = versioned[1] and kinds[1] is not None
204
 
 
205
 
                if present_source != present_target:
206
 
                    if present_target:
207
 
                        change_type = added
208
 
                    else:
209
 
                        change_type = removed
210
 
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
211
 
                    # Renamed
212
 
                    if changed_content or executables[0] != executables[1]:
213
 
                        # and modified
214
 
                        change_type = renamed_and_modified
215
 
                    else:
216
 
                        change_type = renamed
217
 
                    display_path = (paths[0] + source_marker
218
 
                                    + ' => ' + paths[1] + marker)
219
 
                elif kinds[0] != kinds[1]:
220
 
                    change_type = kind_changed
221
 
                    display_path = (paths[0] + source_marker
222
 
                                    + ' => ' + paths[1] + marker)
223
 
                elif changed_content is True or executables[0] != executables[1]:
224
 
                    change_type = modified
225
 
                else:
226
 
                    assert False, "How did we get here?"
227
 
 
228
 
                store.append([file_id, real_path, True, display_path,
229
 
                              change_type, ''])
 
190
            from diff import iter_changes_to_status
 
191
            for (file_id, real_path, change_type, display_path
 
192
                ) in iter_changes_to_status(self._basis_tree, self._wt):
 
193
                if self._selected and real_path != self._selected:
 
194
                    enabled = False
 
195
                else:
 
196
                    enabled = True
 
197
                item_iter = store.append([
 
198
                    file_id,
 
199
                    real_path.encode('UTF-8'),
 
200
                    enabled,
 
201
                    display_path.encode('UTF-8'),
 
202
                    change_type,
 
203
                    '', # Initial comment
 
204
                    ])
 
205
                if self._selected and enabled:
 
206
                    initial_cursor = store.get_path(item_iter)
230
207
        finally:
231
208
            self._basis_tree.unlock()
232
209
            self._wt.unlock()
233
210
 
234
211
        self._treeview_files.set_model(store)
235
212
        self._last_selected_file = None
236
 
        self._treeview_files.set_cursor(0)
 
213
        # This sets the cursor, which causes the expander to close, which
 
214
        # causes the _file_message_text_view to never get realized. So we have
 
215
        # to give it a little kick, or it warns when we try to grab the focus
 
216
        self._treeview_files.set_cursor(initial_cursor)
 
217
 
 
218
        def _realize_file_message_tree_view(*args):
 
219
            self._file_message_text_view.realize()
 
220
        self.connect_after('realize', _realize_file_message_tree_view)
237
221
 
238
222
    def _fill_in_diff(self):
239
223
        self._diff_view.set_trees(self._wt, self._basis_tree)
240
224
 
 
225
    def _fill_in_checkout(self):
 
226
        if not self._is_checkout:
 
227
            self._check_local.hide()
 
228
            return
 
229
        if have_dbus:
 
230
            bus = dbus.SystemBus()
 
231
            try:
 
232
                proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
 
233
                                           '/org/freedesktop/NetworkManager')
 
234
            except dbus.DBusException:
 
235
                mutter("networkmanager not available.")
 
236
                self._check_local.show()
 
237
                return
 
238
            
 
239
            dbus_iface = dbus.Interface(proxy_obj,
 
240
                                        'org.freedesktop.NetworkManager')
 
241
            try:
 
242
                # 3 is the enum value for STATE_CONNECTED
 
243
                self._check_local.set_active(dbus_iface.state() != 3)
 
244
            except dbus.DBusException, e:
 
245
                # Silently drop errors. While DBus may be
 
246
                # available, NetworkManager doesn't necessarily have to be
 
247
                mutter("unable to get networkmanager state: %r" % e)
 
248
        self._check_local.show()
 
249
 
 
250
    def _fill_in_per_file_info(self):
 
251
        config = self._wt.branch.get_config()
 
252
        enable_per_file_commits = config.get_user_option('per_file_commits')
 
253
        if (enable_per_file_commits is None
 
254
            or enable_per_file_commits.lower()
 
255
                not in ('y', 'yes', 'on', 'enable', '1', 't', 'true')):
 
256
            self._enable_per_file_commits = False
 
257
        else:
 
258
            self._enable_per_file_commits = True
 
259
        if not self._enable_per_file_commits:
 
260
            self._file_message_expander.hide()
 
261
            self._global_message_label.set_markup(_i18n('<b>Commit Message</b>'))
 
262
 
241
263
    def _compute_delta(self):
242
264
        self._delta = self._wt.changes_from(self._basis_tree)
243
265
 
249
271
 
250
272
        self._construct_left_pane()
251
273
        self._construct_right_pane()
 
274
        self._construct_action_pane()
252
275
 
253
276
        self.vbox.pack_start(self._hpane)
254
277
        self._hpane.show()
255
278
        self.set_focus(self._global_message_text_view)
256
279
 
 
280
        self._construct_accelerators()
 
281
        self._set_sizes()
 
282
 
 
283
    def _set_sizes(self):
257
284
        # This seems like a reasonable default, we might like it to
258
285
        # be a bit wider, so that by default we can fit an 80-line diff in the
259
286
        # diff window.
270
297
        self.set_default_size(width, height)
271
298
        self._hpane.set_position(300)
272
299
 
 
300
    def _construct_accelerators(self):
 
301
        group = gtk.AccelGroup()
 
302
        group.connect_group(gtk.gdk.keyval_from_name('N'),
 
303
                            gtk.gdk.CONTROL_MASK, 0, self._on_accel_next)
 
304
        self.add_accel_group(group)
 
305
 
 
306
        # ignore the escape key (avoid closing the window)
 
307
        self.connect_object('close', self.emit_stop_by_name, 'close')
 
308
 
273
309
    def _construct_left_pane(self):
274
310
        self._left_pane_box = gtk.VBox(homogeneous=False, spacing=5)
275
311
        self._construct_file_list()
276
312
        self._construct_pending_list()
277
313
 
 
314
        self._check_local = gtk.CheckButton(_i18n("_Only commit locally"),
 
315
                                            use_underline=True)
 
316
        self._left_pane_box.pack_end(self._check_local, False, False)
 
317
        self._check_local.set_active(False)
 
318
 
278
319
        self._hpane.pack1(self._left_pane_box, resize=False, shrink=False)
279
320
        self._left_pane_box.show()
280
321
 
296
337
        self._right_pane_table.show()
297
338
        self._hpane.pack2(self._right_pane_table, resize=True, shrink=True)
298
339
 
 
340
    def _construct_action_pane(self):
 
341
        self._button_commit = gtk.Button(_i18n("Comm_it"), use_underline=True)
 
342
        self._button_commit.connect('clicked', self._on_commit_clicked)
 
343
        self._button_commit.set_flags(gtk.CAN_DEFAULT)
 
344
        self._button_commit.show()
 
345
        self.action_area.pack_end(self._button_commit)
 
346
        self._button_commit.grab_default()
 
347
 
299
348
    def _add_to_right_table(self, widget, weight, expanding=False):
300
349
        """Add another widget to the table
301
350
 
315
364
 
316
365
    def _construct_file_list(self):
317
366
        self._files_box = gtk.VBox(homogeneous=False, spacing=0)
318
 
        file_label = gtk.Label(_('Files'))
319
 
        file_label.show()
 
367
        file_label = gtk.Label(_i18n('Files'))
 
368
        # file_label.show()
320
369
        self._files_box.pack_start(file_label, expand=False)
321
370
 
 
371
        self._commit_all_files_radio = gtk.RadioButton(
 
372
            None, _i18n("Commit all changes"))
 
373
        self._files_box.pack_start(self._commit_all_files_radio, expand=False)
 
374
        self._commit_all_files_radio.show()
 
375
        self._commit_all_files_radio.connect('toggled',
 
376
            self._toggle_commit_selection)
 
377
        self._commit_selected_radio = gtk.RadioButton(
 
378
            self._commit_all_files_radio, _i18n("Only commit selected changes"))
 
379
        self._files_box.pack_start(self._commit_selected_radio, expand=False)
 
380
        self._commit_selected_radio.show()
 
381
        self._commit_selected_radio.connect('toggled',
 
382
            self._toggle_commit_selection)
 
383
        if self._pending:
 
384
            self._commit_all_files_radio.set_label(_i18n('Commit all changes*'))
 
385
            self._commit_all_files_radio.set_sensitive(False)
 
386
            self._commit_selected_radio.set_sensitive(False)
 
387
 
322
388
        scroller = gtk.ScrolledWindow()
323
389
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
324
390
        self._treeview_files = gtk.TreeView()
325
391
        self._treeview_files.show()
326
392
        scroller.add(self._treeview_files)
 
393
        scroller.set_shadow_type(gtk.SHADOW_IN)
327
394
        scroller.show()
328
 
        scroller.set_shadow_type(gtk.SHADOW_IN)
329
395
        self._files_box.pack_start(scroller,
330
396
                                   expand=True, fill=True)
331
397
        self._files_box.show()
332
398
        self._left_pane_box.pack_start(self._files_box)
333
399
 
 
400
        # Keep note that all strings stored in a ListStore must be UTF-8
 
401
        # strings. GTK does not support directly setting and restoring Unicode
 
402
        # objects.
334
403
        liststore = gtk.ListStore(
335
404
            gobject.TYPE_STRING,  # [0] file_id
336
405
            gobject.TYPE_STRING,  # [1] real path
342
411
        self._files_store = liststore
343
412
        self._treeview_files.set_model(liststore)
344
413
        crt = gtk.CellRendererToggle()
345
 
        crt.set_active(not bool(self._pending))
 
414
        crt.set_property('activatable', not bool(self._pending))
346
415
        crt.connect("toggled", self._toggle_commit, self._files_store)
347
416
        if self._pending:
348
 
            name = _('Commit*')
 
417
            name = _i18n('Commit*')
349
418
        else:
350
 
            name = _('Commit')
351
 
        self._treeview_files.append_column(gtk.TreeViewColumn(name,
352
 
                                           crt, active=2))
353
 
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
 
419
            name = _i18n('Commit')
 
420
        commit_col = gtk.TreeViewColumn(name, crt, active=2)
 
421
        commit_col.set_visible(False)
 
422
        self._treeview_files.append_column(commit_col)
 
423
        self._treeview_files.append_column(gtk.TreeViewColumn(_i18n('Path'),
354
424
                                           gtk.CellRendererText(), text=3))
355
 
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
 
425
        self._treeview_files.append_column(gtk.TreeViewColumn(_i18n('Type'),
356
426
                                           gtk.CellRendererText(), text=4))
357
427
        self._treeview_files.connect('cursor-changed',
358
428
                                     self._on_treeview_files_cursor_changed)
365
435
        else:
366
436
            model[path][2] = not model[path][2]
367
437
 
 
438
    def _toggle_commit_selection(self, button):
 
439
        all_files = self._commit_all_files_radio.get_active()
 
440
        if self._commit_all_changes != all_files:
 
441
            checked_col = self._treeview_files.get_column(0)
 
442
            self._commit_all_changes = all_files
 
443
            if all_files:
 
444
                checked_col.set_visible(False)
 
445
            else:
 
446
                checked_col.set_visible(True)
 
447
            renderer = checked_col.get_cell_renderers()[0]
 
448
            renderer.set_property('activatable', not all_files)
 
449
 
368
450
    def _construct_pending_list(self):
369
451
        # Pending information defaults to hidden, we put it all in 1 box, so
370
452
        # that we can show/hide all of them at once
373
455
 
374
456
        pending_message = gtk.Label()
375
457
        pending_message.set_markup(
376
 
            _('<i>* Cannot select specific files when merging</i>'))
 
458
            _i18n('<i>* Cannot select specific files when merging</i>'))
377
459
        self._pending_box.pack_start(pending_message, expand=False, padding=5)
378
460
        pending_message.show()
379
461
 
380
 
        pending_label = gtk.Label(_('Pending Revisions'))
 
462
        pending_label = gtk.Label(_i18n('Pending Revisions'))
381
463
        self._pending_box.pack_start(pending_label, expand=False, padding=0)
382
464
        pending_label.show()
383
465
 
385
467
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
386
468
        self._treeview_pending = gtk.TreeView()
387
469
        scroller.add(self._treeview_pending)
 
470
        scroller.set_shadow_type(gtk.SHADOW_IN)
388
471
        scroller.show()
389
 
        scroller.set_shadow_type(gtk.SHADOW_IN)
390
472
        self._pending_box.pack_start(scroller,
391
473
                                     expand=True, fill=True, padding=5)
392
474
        self._treeview_pending.show()
399
481
                                 )
400
482
        self._pending_store = liststore
401
483
        self._treeview_pending.set_model(liststore)
402
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Date'),
 
484
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Date'),
403
485
                                             gtk.CellRendererText(), text=1))
404
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Committer'),
 
486
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Committer'),
405
487
                                             gtk.CellRendererText(), text=2))
406
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Summary'),
 
488
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Summary'),
407
489
                                             gtk.CellRendererText(), text=3))
408
490
 
409
491
    def _construct_diff_view(self):
410
492
        from diff import DiffView
411
493
 
412
 
        self._diff_label = gtk.Label(_('Diff for whole tree'))
 
494
        # TODO: jam 2007-10-30 The diff label is currently disabled. If we
 
495
        #       decide that we really don't ever want to display it, we should
 
496
        #       actually remove it, and other references to it, along with the
 
497
        #       tests that it is set properly.
 
498
        self._diff_label = gtk.Label(_i18n('Diff for whole tree'))
413
499
        self._diff_label.set_alignment(0, 0)
414
500
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
415
501
        self._add_to_right_table(self._diff_label, 1, False)
416
 
        self._diff_label.show()
 
502
        # self._diff_label.show()
417
503
 
418
504
        self._diff_view = DiffView()
419
505
        self._add_to_right_table(self._diff_view, 4, True)
420
506
        self._diff_view.show()
421
507
 
422
508
    def _construct_file_message(self):
423
 
        file_message_box = gtk.VBox()
424
509
        scroller = gtk.ScrolledWindow()
425
510
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
426
511
 
427
512
        self._file_message_text_view = gtk.TextView()
428
513
        scroller.add(self._file_message_text_view)
 
514
        scroller.set_shadow_type(gtk.SHADOW_IN)
429
515
        scroller.show()
430
 
        scroller.set_shadow_type(gtk.SHADOW_IN)
431
 
        file_message_box.pack_start(scroller, expand=True, fill=True)
432
516
 
433
517
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
434
518
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
435
519
        self._file_message_text_view.set_accepts_tab(False)
436
520
        self._file_message_text_view.show()
437
521
 
438
 
        self._file_message_expander = gtk.Expander(_('File commit message'))
439
 
        self._file_message_expander.add(file_message_box)
440
 
        file_message_box.show()
 
522
        self._file_message_expander = gtk.Expander(_i18n('File commit message'))
 
523
        self._file_message_expander.set_expanded(True)
 
524
        self._file_message_expander.add(scroller)
441
525
        self._add_to_right_table(self._file_message_expander, 1, False)
442
526
        self._file_message_expander.show()
443
527
 
444
528
    def _construct_global_message(self):
445
 
        self._global_message_label = gtk.Label(_('Global Commit Message'))
 
529
        self._global_message_label = gtk.Label(_i18n('Global Commit Message'))
 
530
        self._global_message_label.set_markup(
 
531
            _i18n('<b>Global Commit Message</b>'))
446
532
        self._global_message_label.set_alignment(0, 0)
447
533
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
448
534
        self._add_to_right_table(self._global_message_label, 1, False)
455
541
        self._global_message_text_view = gtk.TextView()
456
542
        self._global_message_text_view.modify_font(pango.FontDescription("Monospace"))
457
543
        scroller.add(self._global_message_text_view)
 
544
        scroller.set_shadow_type(gtk.SHADOW_IN)
458
545
        scroller.show()
459
 
        scroller.set_shadow_type(gtk.SHADOW_IN)
460
546
        self._add_to_right_table(scroller, 2, True)
461
547
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
462
548
        self._file_message_text_view.set_accepts_tab(False)
468
554
 
469
555
        if selection is not None:
470
556
            path, display_path = model.get(selection, 1, 3)
471
 
            self._diff_label.set_text(_('Diff for ') + display_path)
 
557
            self._diff_label.set_text(_i18n('Diff for ') + display_path)
472
558
            if path is None:
473
559
                self._diff_view.show_diff(None)
474
560
            else:
475
 
                self._diff_view.show_diff([path])
 
561
                self._diff_view.show_diff([path.decode('UTF-8')])
476
562
            self._update_per_file_info(selection)
477
563
 
 
564
    def _on_accel_next(self, accel_group, window, keyval, modifier):
 
565
        # We don't really care about any of the parameters, because we know
 
566
        # where this message came from
 
567
        tree_selection = self._treeview_files.get_selection()
 
568
        (model, selection) = tree_selection.get_selected()
 
569
        if selection is None:
 
570
            next = None
 
571
        else:
 
572
            next = model.iter_next(selection)
 
573
 
 
574
        if next is None:
 
575
            # We have either made it to the end of the list, or nothing was
 
576
            # selected. Either way, select All Files, and jump to the global
 
577
            # commit message.
 
578
            self._treeview_files.set_cursor((0,))
 
579
            self._global_message_text_view.grab_focus()
 
580
        else:
 
581
            # Set the cursor to this entry, and jump to the per-file commit
 
582
            # message
 
583
            self._treeview_files.set_cursor(model.get_path(next))
 
584
            self._file_message_text_view.grab_focus()
 
585
 
478
586
    def _save_current_file_message(self):
479
587
        if self._last_selected_file is None:
480
588
            return # Nothing to save
486
594
 
487
595
    def _update_per_file_info(self, selection):
488
596
        # The node is changing, so cache the current message
 
597
        if not self._enable_per_file_commits:
 
598
            return
 
599
 
489
600
        self._save_current_file_message()
490
601
        text_buffer = self._file_message_text_view.get_buffer()
491
602
        file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
492
603
        if file_id is None: # Whole tree
493
 
            self._file_message_expander.set_label(_('File commit message'))
 
604
            self._file_message_expander.set_label(_i18n('File commit message'))
494
605
            self._file_message_expander.set_expanded(False)
495
606
            self._file_message_expander.set_sensitive(False)
496
607
            text_buffer.set_text('')
497
608
            self._last_selected_file = None
498
609
        else:
499
 
            self._file_message_expander.set_label(_('Commit message for ')
 
610
            self._file_message_expander.set_label(_i18n('Commit message for ')
500
611
                                                  + display_path)
501
612
            self._file_message_expander.set_expanded(True)
502
613
            self._file_message_expander.set_sensitive(True)
503
614
            text_buffer.set_text(message)
504
615
            self._last_selected_file = self._files_store.get_path(selection)
505
616
 
 
617
    def _get_specific_files(self):
 
618
        """Return the list of selected paths, and file info.
 
619
 
 
620
        :return: ([unicode paths], [{utf-8 file info}]
 
621
        """
 
622
        self._save_current_file_message()
 
623
        files = []
 
624
        records = iter(self._files_store)
 
625
        rec = records.next() # Skip the All Files record
 
626
        assert rec[0] is None, "Are we skipping the wrong record?"
 
627
 
 
628
        file_info = []
 
629
        for record in records:
 
630
            if self._commit_all_changes or record[2]:# [2] checkbox
 
631
                file_id = record[0] # [0] file_id
 
632
                path = record[1]    # [1] real path
 
633
                file_message = record[5] # [5] commit message
 
634
                files.append(path.decode('UTF-8'))
 
635
                if self._enable_per_file_commits and file_message:
 
636
                    # All of this needs to be utf-8 information
 
637
                    file_info.append({'path':path, 'file_id':file_id,
 
638
                                     'message':file_message})
 
639
        file_info.sort(key=lambda x:(x['path'], x['file_id']))
 
640
        if self._enable_per_file_commits:
 
641
            return files, file_info
 
642
        else:
 
643
            return files, []
 
644
 
 
645
    @show_bzr_error
 
646
    def _on_commit_clicked(self, button):
 
647
        """ Commit button clicked handler. """
 
648
        self._do_commit()
 
649
 
 
650
    def _do_commit(self):
 
651
        message = self._get_global_commit_message()
 
652
 
 
653
        if message == '':
 
654
            response = self._question_dialog(
 
655
                _i18n('Commit with an empty message?'),
 
656
                _i18n('You can describe your commit intent in the message.'))
 
657
            if response == gtk.RESPONSE_NO:
 
658
                # Kindly give focus to message area
 
659
                self._global_message_text_view.grab_focus()
 
660
                return
 
661
 
 
662
        specific_files, file_info = self._get_specific_files()
 
663
        if self._pending:
 
664
            specific_files = None
 
665
 
 
666
        local = self._check_local.get_active()
 
667
 
 
668
        # All we care about is if there is a single unknown, so if this loop is
 
669
        # entered, then there are unknown files.
 
670
        # TODO: jam 20071002 It seems like this should cancel the dialog
 
671
        #       entirely, since there isn't a way for them to add the unknown
 
672
        #       files at this point.
 
673
        for path in self._wt.unknowns():
 
674
            response = self._question_dialog(
 
675
                _i18n("Commit with unknowns?"),
 
676
                _i18n("Unknown files exist in the working tree. Commit anyway?"))
 
677
            if response == gtk.RESPONSE_NO:
 
678
                return
 
679
            break
 
680
 
 
681
        rev_id = None
 
682
        revprops = {}
 
683
        if file_info:
 
684
            revprops['file-info'] = bencode.bencode(file_info).decode('UTF-8')
 
685
        try:
 
686
            rev_id = self._wt.commit(message,
 
687
                       allow_pointless=False,
 
688
                       strict=False,
 
689
                       local=local,
 
690
                       specific_files=specific_files,
 
691
                       revprops=revprops)
 
692
        except errors.PointlessCommit:
 
693
            response = self._question_dialog(
 
694
                _i18n('Commit with no changes?'),
 
695
                _i18n('There are no changes in the working tree.'
 
696
                      ' Do you want to commit anyway?'))
 
697
            if response == gtk.RESPONSE_YES:
 
698
                rev_id = self._wt.commit(message,
 
699
                               allow_pointless=True,
 
700
                               strict=False,
 
701
                               local=local,
 
702
                               specific_files=specific_files,
 
703
                               revprops=revprops)
 
704
        self.committed_revision_id = rev_id
 
705
        self.response(gtk.RESPONSE_OK)
 
706
 
 
707
    def _get_global_commit_message(self):
 
708
        buf = self._global_message_text_view.get_buffer()
 
709
        start, end = buf.get_bounds()
 
710
        return buf.get_text(start, end).decode('utf-8')
 
711
 
 
712
    def _set_global_commit_message(self, message):
 
713
        """Just a helper for the test suite."""
 
714
        if isinstance(message, unicode):
 
715
            message = message.encode('UTF-8')
 
716
        self._global_message_text_view.get_buffer().set_text(message)
 
717
 
 
718
    def _set_file_commit_message(self, message):
 
719
        """Helper for the test suite."""
 
720
        if isinstance(message, unicode):
 
721
            message = message.encode('UTF-8')
 
722
        self._file_message_text_view.get_buffer().set_text(message)
 
723
 
506
724
    @staticmethod
507
725
    def _rev_to_pending_info(rev):
508
726
        """Get the information from a pending merge."""
509
727
        from bzrlib.osutils import format_date
510
 
 
511
728
        rev_dict = {}
512
729
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
513
730
        rev_dict['summary'] = rev.get_summary()
517
734
                                       show_offset=False)
518
735
        rev_dict['revision_id'] = rev.revision_id
519
736
        return rev_dict
520
 
 
521
 
 
522
 
# class CommitDialog(gtk.Dialog):
523
 
#     """ New implementation of the Commit dialog. """
524
 
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
525
 
#         """ Initialize the Commit Dialog. """
526
 
#         gtk.Dialog.__init__(self, title="Commit - Olive",
527
 
#                                   parent=parent,
528
 
#                                   flags=0,
529
 
#                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
530
 
#         
531
 
#         # Get arguments
532
 
#         self.wt = wt
533
 
#         self.wtpath = wtpath
534
 
#         self.notbranch = notbranch
535
 
#         self.selected = selected
536
 
#         
537
 
#         # Set the delta
538
 
#         self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
539
 
#         self.delta = self.wt.changes_from(self.old_tree)
540
 
#         
541
 
#         # Get pending merges
542
 
#         self.pending = self._pending_merges(self.wt)
543
 
#         
544
 
#         # Do some preliminary checks
545
 
#         self._is_checkout = False
546
 
#         self._is_pending = False
547
 
#         if self.wt is None and not self.notbranch:
548
 
#             error_dialog(_('Directory does not have a working tree'),
549
 
#                          _('Operation aborted.'))
550
 
#             self.close()
551
 
#             return
552
 
553
 
#         if self.notbranch:
554
 
#             error_dialog(_('Directory is not a branch'),
555
 
#                          _('You can perform this action only in a branch.'))
556
 
#             self.close()
557
 
#             return
558
 
#         else:
559
 
#             if self.wt.branch.get_bound_location() is not None:
560
 
#                 # we have a checkout, so the local commit checkbox must appear
561
 
#                 self._is_checkout = True
562
 
#             
563
 
#             if self.pending:
564
 
#                 # There are pending merges, file selection not supported
565
 
#                 self._is_pending = True
566
 
#         
567
 
#         # Create the widgets
568
 
#         # This is the main horizontal box, which is used to separate the commit
569
 
#         # info from the diff window.
570
 
#         self._hpane = gtk.HPaned()
571
 
#         self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
572
 
#         self._expander_files = gtk.Expander(_("File(s) to commit"))
573
 
#         self._vpaned_main = gtk.VPaned()
574
 
#         self._scrolledwindow_files = gtk.ScrolledWindow()
575
 
#         self._scrolledwindow_message = gtk.ScrolledWindow()
576
 
#         self._treeview_files = gtk.TreeView()
577
 
#         self._vbox_message = gtk.VBox()
578
 
#         self._label_message = gtk.Label(_("Commit message:"))
579
 
#         self._textview_message = gtk.TextView()
580
 
#         
581
 
#         if self._is_pending:
582
 
#             self._expander_merges = gtk.Expander(_("Pending merges"))
583
 
#             self._vpaned_list = gtk.VPaned()
584
 
#             self._scrolledwindow_merges = gtk.ScrolledWindow()
585
 
#             self._treeview_merges = gtk.TreeView()
586
 
587
 
#         # Set callbacks
588
 
#         self._button_commit.connect('clicked', self._on_commit_clicked)
589
 
#         self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
590
 
#         self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
591
 
#         
592
 
#         # Set properties
593
 
#         self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
594
 
#                                               gtk.POLICY_AUTOMATIC)
595
 
#         self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
596
 
#                                                 gtk.POLICY_AUTOMATIC)
597
 
#         self._textview_message.modify_font(pango.FontDescription("Monospace"))
598
 
#         self.set_default_size(500, 500)
599
 
#         self._vpaned_main.set_position(200)
600
 
#         self._button_commit.set_flags(gtk.CAN_DEFAULT)
601
 
602
 
#         if self._is_pending:
603
 
#             self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
604
 
#                                                    gtk.POLICY_AUTOMATIC)
605
 
#             self._treeview_files.set_sensitive(False)
606
 
#         
607
 
#         # Construct the dialog
608
 
#         self.action_area.pack_end(self._button_commit)
609
 
#         
610
 
#         self._scrolledwindow_files.add(self._treeview_files)
611
 
#         self._scrolledwindow_message.add(self._textview_message)
612
 
#         
613
 
#         self._expander_files.add(self._scrolledwindow_files)
614
 
#         
615
 
#         self._vbox_message.pack_start(self._label_message, False, False)
616
 
#         self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
617
 
#         
618
 
#         if self._is_pending:        
619
 
#             self._expander_merges.add(self._scrolledwindow_merges)
620
 
#             self._scrolledwindow_merges.add(self._treeview_merges)
621
 
#             self._vpaned_list.add1(self._expander_files)
622
 
#             self._vpaned_list.add2(self._expander_merges)
623
 
#             self._vpaned_main.add1(self._vpaned_list)
624
 
#         else:
625
 
#             self._vpaned_main.add1(self._expander_files)
626
 
627
 
#         self._vpaned_main.add2(self._vbox_message)
628
 
#         
629
 
#         self._hpane.pack1(self._vpaned_main)
630
 
#         self.vbox.pack_start(self._hpane, expand=True, fill=True)
631
 
#         if self._is_checkout: 
632
 
#             self._check_local = gtk.CheckButton(_("_Only commit locally"),
633
 
#                                                 use_underline=True)
634
 
#             self.vbox.pack_start(self._check_local, False, False)
635
 
#             if have_dbus:
636
 
#                 bus = dbus.SystemBus()
637
 
#                 proxy_obj = bus.get_object('org.freedesktop.NetworkManager', 
638
 
#                               '/org/freedesktop/NetworkManager')
639
 
#                 dbus_iface = dbus.Interface(
640
 
#                         proxy_obj, 'org.freedesktop.NetworkManager')
641
 
#                 try:
642
 
#                     # 3 is the enum value for STATE_CONNECTED
643
 
#                     self._check_local.set_active(dbus_iface.state() != 3)
644
 
#                 except dbus.DBusException, e:
645
 
#                     # Silently drop errors. While DBus may be 
646
 
#                     # available, NetworkManager doesn't necessarily have to be
647
 
#                     mutter("unable to get networkmanager state: %r" % e)
648
 
#                 
649
 
#         # Create the file list
650
 
#         self._create_file_view()
651
 
#         # Create the pending merges
652
 
#         self._create_pending_merges()
653
 
#         self._create_diff_view()
654
 
#         
655
 
#         # Expand the corresponding expander
656
 
#         if self._is_pending:
657
 
#             self._expander_merges.set_expanded(True)
658
 
#         else:
659
 
#             self._expander_files.set_expanded(True)
660
 
#         
661
 
#         # Display dialog
662
 
#         self.vbox.show_all()
663
 
#         
664
 
#         # Default to Commit button
665
 
#         self._button_commit.grab_default()
666
 
#     
667
 
#     def _show_diff_view(self, treeview):
668
 
#         # FIXME: the diff window freezes for some reason
669
 
#         treeselection = treeview.get_selection()
670
 
#         (model, iter) = treeselection.get_selected()
671
 
672
 
#         if iter is not None:
673
 
#             selected = model.get_value(iter, 3) # Get the real_path attribute
674
 
#             self._diff_display.show_diff([selected])
675
 
676
 
#     def _on_treeview_files_cursor_changed(self, treeview):
677
 
#         self._show_diff_view(treeview)
678
 
#         
679
 
#     def _on_treeview_files_row_activated(self, treeview, path, view_column):
680
 
#         self._show_diff_view(treeview)
681
 
#     
682
 
#     @show_bzr_error
683
 
#     def _on_commit_clicked(self, button):
684
 
#         """ Commit button clicked handler. """
685
 
#         textbuffer = self._textview_message.get_buffer()
686
 
#         start, end = textbuffer.get_bounds()
687
 
#         message = textbuffer.get_text(start, end).decode('utf-8')
688
 
#         
689
 
#         if not self.pending:
690
 
#             specific_files = self._get_specific_files()
691
 
#         else:
692
 
#             specific_files = None
693
 
694
 
#         if message == '':
695
 
#             response = question_dialog(_('Commit with an empty message?'),
696
 
#                                        _('You can describe your commit intent in the message.'))
697
 
#             if response == gtk.RESPONSE_NO:
698
 
#                 # Kindly give focus to message area
699
 
#                 self._textview_message.grab_focus()
700
 
#                 return
701
 
702
 
#         if self._is_checkout:
703
 
#             local = self._check_local.get_active()
704
 
#         else:
705
 
#             local = False
706
 
707
 
#         if list(self.wt.unknowns()) != []:
708
 
#             response = question_dialog(_("Commit with unknowns?"),
709
 
#                _("Unknown files exist in the working tree. Commit anyway?"))
710
 
#             if response == gtk.RESPONSE_NO:
711
 
#                 return
712
 
#         
713
 
#         try:
714
 
#             self.wt.commit(message,
715
 
#                        allow_pointless=False,
716
 
#                        strict=False,
717
 
#                        local=local,
718
 
#                        specific_files=specific_files)
719
 
#         except errors.PointlessCommit:
720
 
#             response = question_dialog(_('Commit with no changes?'),
721
 
#                                        _('There are no changes in the working tree.'))
722
 
#             if response == gtk.RESPONSE_YES:
723
 
#                 self.wt.commit(message,
724
 
#                                allow_pointless=True,
725
 
#                                strict=False,
726
 
#                                local=local,
727
 
#                                specific_files=specific_files)
728
 
#         self.response(gtk.RESPONSE_OK)
729
 
730
 
#     def _pending_merges(self, wt):
731
 
#         """ Return a list of pending merges or None if there are none of them. """
732
 
#         parents = wt.get_parent_ids()
733
 
#         if len(parents) < 2:
734
 
#             return None
735
 
#         
736
 
#         import re
737
 
#         from bzrlib.osutils import format_date
738
 
#         
739
 
#         pending = parents[1:]
740
 
#         branch = wt.branch
741
 
#         last_revision = parents[0]
742
 
#         
743
 
#         if last_revision is not None:
744
 
#             try:
745
 
#                 ignore = set(branch.repository.get_ancestry(last_revision))
746
 
#             except errors.NoSuchRevision:
747
 
#                 # the last revision is a ghost : assume everything is new 
748
 
#                 # except for it
749
 
#                 ignore = set([None, last_revision])
750
 
#         else:
751
 
#             ignore = set([None])
752
 
#         
753
 
#         pm = []
754
 
#         for merge in pending:
755
 
#             ignore.add(merge)
756
 
#             try:
757
 
#                 m_revision = branch.repository.get_revision(merge)
758
 
#                 
759
 
#                 rev = {}
760
 
#                 rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
761
 
#                 rev['summary'] = m_revision.get_summary()
762
 
#                 rev['date'] = format_date(m_revision.timestamp,
763
 
#                                           m_revision.timezone or 0, 
764
 
#                                           'original', date_fmt="%Y-%m-%d",
765
 
#                                           show_offset=False)
766
 
#                 
767
 
#                 pm.append(rev)
768
 
#                 
769
 
#                 inner_merges = branch.repository.get_ancestry(merge)
770
 
#                 assert inner_merges[0] is None
771
 
#                 inner_merges.pop(0)
772
 
#                 inner_merges.reverse()
773
 
#                 for mmerge in inner_merges:
774
 
#                     if mmerge in ignore:
775
 
#                         continue
776
 
#                     mm_revision = branch.repository.get_revision(mmerge)
777
 
#                     
778
 
#                     rev = {}
779
 
#                     rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
780
 
#                     rev['summary'] = mm_revision.get_summary()
781
 
#                     rev['date'] = format_date(mm_revision.timestamp,
782
 
#                                               mm_revision.timezone or 0, 
783
 
#                                               'original', date_fmt="%Y-%m-%d",
784
 
#                                               show_offset=False)
785
 
#                 
786
 
#                     pm.append(rev)
787
 
#                     
788
 
#                     ignore.add(mmerge)
789
 
#             except errors.NoSuchRevision:
790
 
#                 print "DEBUG: NoSuchRevision:", merge
791
 
#         
792
 
#         return pm
793
 
794
 
#     def _create_file_view(self):
795
 
#         self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
796
 
#                                          gobject.TYPE_STRING,    # [1] path to display
797
 
#                                          gobject.TYPE_STRING,    # [2] changes type
798
 
#                                          gobject.TYPE_STRING)    # [3] real path
799
 
#         self._treeview_files.set_model(self._file_store)
800
 
#         crt = gtk.CellRendererToggle()
801
 
#         crt.set_property("activatable", True)
802
 
#         crt.connect("toggled", self._toggle_commit, self._file_store)
803
 
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
804
 
#                                      crt, active=0))
805
 
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
806
 
#                                      gtk.CellRendererText(), text=1))
807
 
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
808
 
#                                      gtk.CellRendererText(), text=2))
809
 
810
 
#         for path, id, kind in self.delta.added:
811
 
#             marker = osutils.kind_marker(kind)
812
 
#             if self.selected is not None:
813
 
#                 if path == os.path.join(self.wtpath, self.selected):
814
 
#                     self._file_store.append([ True, path+marker, _('added'), path ])
815
 
#                 else:
816
 
#                     self._file_store.append([ False, path+marker, _('added'), path ])
817
 
#             else:
818
 
#                 self._file_store.append([ True, path+marker, _('added'), path ])
819
 
820
 
#         for path, id, kind in self.delta.removed:
821
 
#             marker = osutils.kind_marker(kind)
822
 
#             if self.selected is not None:
823
 
#                 if path == os.path.join(self.wtpath, self.selected):
824
 
#                     self._file_store.append([ True, path+marker, _('removed'), path ])
825
 
#                 else:
826
 
#                     self._file_store.append([ False, path+marker, _('removed'), path ])
827
 
#             else:
828
 
#                 self._file_store.append([ True, path+marker, _('removed'), path ])
829
 
830
 
#         for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
831
 
#             marker = osutils.kind_marker(kind)
832
 
#             if text_modified or meta_modified:
833
 
#                 changes = _('renamed and modified')
834
 
#             else:
835
 
#                 changes = _('renamed')
836
 
#             if self.selected is not None:
837
 
#                 if newpath == os.path.join(self.wtpath, self.selected):
838
 
#                     self._file_store.append([ True,
839
 
#                                               oldpath+marker + '  =>  ' + newpath+marker,
840
 
#                                               changes,
841
 
#                                               newpath
842
 
#                                             ])
843
 
#                 else:
844
 
#                     self._file_store.append([ False,
845
 
#                                               oldpath+marker + '  =>  ' + newpath+marker,
846
 
#                                               changes,
847
 
#                                               newpath
848
 
#                                             ])
849
 
#             else:
850
 
#                 self._file_store.append([ True,
851
 
#                                           oldpath+marker + '  =>  ' + newpath+marker,
852
 
#                                           changes,
853
 
#                                           newpath
854
 
#                                         ])
855
 
856
 
#         for path, id, kind, text_modified, meta_modified in self.delta.modified:
857
 
#             marker = osutils.kind_marker(kind)
858
 
#             if self.selected is not None:
859
 
#                 if path == os.path.join(self.wtpath, self.selected):
860
 
#                     self._file_store.append([ True, path+marker, _('modified'), path ])
861
 
#                 else:
862
 
#                     self._file_store.append([ False, path+marker, _('modified'), path ])
863
 
#             else:
864
 
#                 self._file_store.append([ True, path+marker, _('modified'), path ])
865
 
#     
866
 
#     def _create_pending_merges(self):
867
 
#         if not self.pending:
868
 
#             return
869
 
#         
870
 
#         liststore = gtk.ListStore(gobject.TYPE_STRING,
871
 
#                                   gobject.TYPE_STRING,
872
 
#                                   gobject.TYPE_STRING)
873
 
#         self._treeview_merges.set_model(liststore)
874
 
#         
875
 
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
876
 
#                                             gtk.CellRendererText(), text=0))
877
 
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
878
 
#                                             gtk.CellRendererText(), text=1))
879
 
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
880
 
#                                             gtk.CellRendererText(), text=2))
881
 
#         
882
 
#         for item in self.pending:
883
 
#             liststore.append([ item['date'],
884
 
#                                item['committer'],
885
 
#                                item['summary'] ])
886
 
#     
887
 
888
 
#     def _create_diff_view(self):
889
 
#         from diff import DiffView
890
 
891
 
#         self._diff_display = DiffView()
892
 
#         self._diff_display.set_trees(self.wt, self.wt.basis_tree())
893
 
#         self._diff_display.show_diff(None)
894
 
#         self._diff_display.show()
895
 
#         self._hpane.pack2(self._diff_display)
896
 
897
 
#     def _get_specific_files(self):
898
 
#         ret = []
899
 
#         it = self._file_store.get_iter_first()
900
 
#         while it:
901
 
#             if self._file_store.get_value(it, 0):
902
 
#                 # get real path from hidden column 3
903
 
#                 ret.append(self._file_store.get_value(it, 3))
904
 
#             it = self._file_store.iter_next(it)
905
 
906
 
#         return ret
907
 
#     
908
 
#     def _toggle_commit(self, cell, path, model):
909
 
#         model[path][0] = not model[path][0]
910
 
#         return