/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: John Arbash Meinel
  • Date: 2007-10-02 19:15:41 UTC
  • mto: (322.1.1 trunk) (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071002191541-qra1s73obzvgrf7j
Ensure that we can set per-file messages even during a merge.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
from bzrlib.trace import mutter
32
32
from bzrlib.util import bencode
33
33
 
34
 
from bzrlib.plugins.gtk import _i18n
35
34
from dialog import error_dialog, question_dialog
36
35
from errors import show_bzr_error
37
36
 
108
107
        self._question_dialog = question_dialog
109
108
 
110
109
        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
113
110
        self._selected = selected
114
 
        self._enable_per_file_commits = True
115
 
        self._commit_all_changes = True
116
111
        self.committed_revision_id = None # Nothing has been committed yet
117
112
 
118
113
        self.setup_params()
133
128
        self._fill_in_diff()
134
129
        self._fill_in_files()
135
130
        self._fill_in_checkout()
136
 
        self._fill_in_per_file_info()
137
131
 
138
132
    def _fill_in_pending(self):
139
133
        if not self._pending:
160
154
        self._pending_box.show()
161
155
 
162
156
    def _fill_in_files(self):
163
 
        # We should really use add a progress bar of some kind.
 
157
        # We should really use _iter_changes, and then add a progress bar of
 
158
        # some kind.
164
159
        # While we fill in the view, hide the store
165
160
        store = self._files_store
166
161
        self._treeview_files.set_model(None)
167
162
 
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')
 
163
        added = _('added')
 
164
        removed = _('removed')
 
165
        renamed = _('renamed')
 
166
        renamed_and_modified = _('renamed and modified')
 
167
        modified = _('modified')
 
168
        kind_changed = _('kind changed')
174
169
 
175
170
        # The store holds:
176
171
        # [file_id, real path, checkbox, display path, changes type, message]
177
 
        # iter_changes returns:
 
172
        # _iter_changes returns:
178
173
        # (file_id, (path_in_source, path_in_target),
179
174
        #  changed_content, versioned, parent, name, kind,
180
175
        #  executable)
181
176
 
182
 
        all_enabled = (self._selected is None)
183
177
        # The first entry is always the 'whole tree'
184
 
        all_iter = store.append([None, None, all_enabled, 'All Files', '', ''])
185
 
        initial_cursor = store.get_path(all_iter)
 
178
        store.append([None, None, True, 'All Files', '', ''])
186
179
        # should we pass specific_files?
187
180
        self._wt.lock_read()
188
181
        self._basis_tree.lock_read()
189
182
        try:
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)
 
183
            for (file_id, paths, changed_content, versioned, parent_ids, names,
 
184
                 kinds, executables) in self._wt._iter_changes(self._basis_tree):
 
185
 
 
186
                # Skip the root entry.
 
187
                if parent_ids == (None, None):
 
188
                    continue
 
189
 
 
190
                change_type = None
 
191
                if kinds[0] is None:
 
192
                    source_marker = ''
 
193
                else:
 
194
                    source_marker = osutils.kind_marker(kinds[0])
 
195
                if kinds[1] is None:
 
196
                    assert kinds[0] is not None
 
197
                    marker = osutils.kind_marker(kinds[0])
 
198
                else:
 
199
                    marker = osutils.kind_marker(kinds[1])
 
200
 
 
201
                real_path = paths[1]
 
202
                if real_path is None:
 
203
                    real_path = paths[0]
 
204
                assert real_path is not None
 
205
                display_path = real_path + marker
 
206
 
 
207
                present_source = versioned[0] and kinds[0] is not None
 
208
                present_target = versioned[1] and kinds[1] is not None
 
209
 
 
210
                if present_source != present_target:
 
211
                    if present_target:
 
212
                        change_type = added
 
213
                    else:
 
214
                        change_type = removed
 
215
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
 
216
                    # Renamed
 
217
                    if changed_content or executables[0] != executables[1]:
 
218
                        # and modified
 
219
                        change_type = renamed_and_modified
 
220
                    else:
 
221
                        change_type = renamed
 
222
                    display_path = (paths[0] + source_marker
 
223
                                    + ' => ' + paths[1] + marker)
 
224
                elif kinds[0] != kinds[1]:
 
225
                    change_type = kind_changed
 
226
                    display_path = (paths[0] + source_marker
 
227
                                    + ' => ' + paths[1] + marker)
 
228
                elif changed_content is True or executables[0] != executables[1]:
 
229
                    change_type = modified
 
230
                else:
 
231
                    assert False, "How did we get here?"
 
232
 
 
233
                store.append([file_id, real_path, True, display_path,
 
234
                              change_type, ''])
207
235
        finally:
208
236
            self._basis_tree.unlock()
209
237
            self._wt.unlock()
210
238
 
211
239
        self._treeview_files.set_model(store)
212
240
        self._last_selected_file = None
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)
 
241
        self._treeview_files.set_cursor(0)
221
242
 
222
243
    def _fill_in_diff(self):
223
244
        self._diff_view.set_trees(self._wt, self._basis_tree)
228
249
            return
229
250
        if have_dbus:
230
251
            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
 
            
 
252
            proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
 
253
                                       '/org/freedesktop/NetworkManager')
239
254
            dbus_iface = dbus.Interface(proxy_obj,
240
255
                                        'org.freedesktop.NetworkManager')
241
256
            try:
247
262
                mutter("unable to get networkmanager state: %r" % e)
248
263
        self._check_local.show()
249
264
 
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
 
 
263
265
    def _compute_delta(self):
264
266
        self._delta = self._wt.changes_from(self._basis_tree)
265
267
 
277
279
        self._hpane.show()
278
280
        self.set_focus(self._global_message_text_view)
279
281
 
280
 
        self._construct_accelerators()
281
 
        self._set_sizes()
282
 
 
283
 
    def _set_sizes(self):
284
282
        # This seems like a reasonable default, we might like it to
285
283
        # be a bit wider, so that by default we can fit an 80-line diff in the
286
284
        # diff window.
297
295
        self.set_default_size(width, height)
298
296
        self._hpane.set_position(300)
299
297
 
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
 
 
309
298
    def _construct_left_pane(self):
310
299
        self._left_pane_box = gtk.VBox(homogeneous=False, spacing=5)
311
300
        self._construct_file_list()
312
301
        self._construct_pending_list()
313
302
 
314
 
        self._check_local = gtk.CheckButton(_i18n("_Only commit locally"),
 
303
        self._check_local = gtk.CheckButton(_("_Only commit locally"),
315
304
                                            use_underline=True)
316
305
        self._left_pane_box.pack_end(self._check_local, False, False)
317
306
        self._check_local.set_active(False)
338
327
        self._hpane.pack2(self._right_pane_table, resize=True, shrink=True)
339
328
 
340
329
    def _construct_action_pane(self):
341
 
        self._button_commit = gtk.Button(_i18n("Comm_it"), use_underline=True)
 
330
        self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
342
331
        self._button_commit.connect('clicked', self._on_commit_clicked)
343
332
        self._button_commit.set_flags(gtk.CAN_DEFAULT)
344
333
        self._button_commit.show()
364
353
 
365
354
    def _construct_file_list(self):
366
355
        self._files_box = gtk.VBox(homogeneous=False, spacing=0)
367
 
        file_label = gtk.Label(_i18n('Files'))
368
 
        # file_label.show()
 
356
        file_label = gtk.Label(_('Files'))
 
357
        file_label.show()
369
358
        self._files_box.pack_start(file_label, expand=False)
370
359
 
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
 
 
388
360
        scroller = gtk.ScrolledWindow()
389
361
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
390
362
        self._treeview_files = gtk.TreeView()
391
363
        self._treeview_files.show()
392
364
        scroller.add(self._treeview_files)
 
365
        scroller.show()
393
366
        scroller.set_shadow_type(gtk.SHADOW_IN)
394
 
        scroller.show()
395
367
        self._files_box.pack_start(scroller,
396
368
                                   expand=True, fill=True)
397
369
        self._files_box.show()
398
370
        self._left_pane_box.pack_start(self._files_box)
399
371
 
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.
403
372
        liststore = gtk.ListStore(
404
373
            gobject.TYPE_STRING,  # [0] file_id
405
374
            gobject.TYPE_STRING,  # [1] real path
411
380
        self._files_store = liststore
412
381
        self._treeview_files.set_model(liststore)
413
382
        crt = gtk.CellRendererToggle()
414
 
        crt.set_property('activatable', not bool(self._pending))
 
383
        crt.set_active(not bool(self._pending))
415
384
        crt.connect("toggled", self._toggle_commit, self._files_store)
416
385
        if self._pending:
417
 
            name = _i18n('Commit*')
 
386
            name = _('Commit*')
418
387
        else:
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'),
 
388
            name = _('Commit')
 
389
        self._treeview_files.append_column(gtk.TreeViewColumn(name,
 
390
                                           crt, active=2))
 
391
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
424
392
                                           gtk.CellRendererText(), text=3))
425
 
        self._treeview_files.append_column(gtk.TreeViewColumn(_i18n('Type'),
 
393
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
426
394
                                           gtk.CellRendererText(), text=4))
427
395
        self._treeview_files.connect('cursor-changed',
428
396
                                     self._on_treeview_files_cursor_changed)
435
403
        else:
436
404
            model[path][2] = not model[path][2]
437
405
 
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
 
 
450
406
    def _construct_pending_list(self):
451
407
        # Pending information defaults to hidden, we put it all in 1 box, so
452
408
        # that we can show/hide all of them at once
455
411
 
456
412
        pending_message = gtk.Label()
457
413
        pending_message.set_markup(
458
 
            _i18n('<i>* Cannot select specific files when merging</i>'))
 
414
            _('<i>* Cannot select specific files when merging</i>'))
459
415
        self._pending_box.pack_start(pending_message, expand=False, padding=5)
460
416
        pending_message.show()
461
417
 
462
 
        pending_label = gtk.Label(_i18n('Pending Revisions'))
 
418
        pending_label = gtk.Label(_('Pending Revisions'))
463
419
        self._pending_box.pack_start(pending_label, expand=False, padding=0)
464
420
        pending_label.show()
465
421
 
467
423
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
468
424
        self._treeview_pending = gtk.TreeView()
469
425
        scroller.add(self._treeview_pending)
 
426
        scroller.show()
470
427
        scroller.set_shadow_type(gtk.SHADOW_IN)
471
 
        scroller.show()
472
428
        self._pending_box.pack_start(scroller,
473
429
                                     expand=True, fill=True, padding=5)
474
430
        self._treeview_pending.show()
481
437
                                 )
482
438
        self._pending_store = liststore
483
439
        self._treeview_pending.set_model(liststore)
484
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Date'),
 
440
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Date'),
485
441
                                             gtk.CellRendererText(), text=1))
486
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Committer'),
 
442
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Committer'),
487
443
                                             gtk.CellRendererText(), text=2))
488
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Summary'),
 
444
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Summary'),
489
445
                                             gtk.CellRendererText(), text=3))
490
446
 
491
447
    def _construct_diff_view(self):
492
448
        from diff import DiffView
493
449
 
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'))
 
450
        self._diff_label = gtk.Label(_('Diff for whole tree'))
499
451
        self._diff_label.set_alignment(0, 0)
500
452
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
501
453
        self._add_to_right_table(self._diff_label, 1, False)
502
 
        # self._diff_label.show()
 
454
        self._diff_label.show()
503
455
 
504
456
        self._diff_view = DiffView()
505
457
        self._add_to_right_table(self._diff_view, 4, True)
506
458
        self._diff_view.show()
507
459
 
508
460
    def _construct_file_message(self):
 
461
        file_message_box = gtk.VBox()
509
462
        scroller = gtk.ScrolledWindow()
510
463
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
511
464
 
512
465
        self._file_message_text_view = gtk.TextView()
513
466
        scroller.add(self._file_message_text_view)
 
467
        scroller.show()
514
468
        scroller.set_shadow_type(gtk.SHADOW_IN)
515
 
        scroller.show()
 
469
        file_message_box.pack_start(scroller, expand=True, fill=True)
516
470
 
517
471
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
518
472
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
519
473
        self._file_message_text_view.set_accepts_tab(False)
520
474
        self._file_message_text_view.show()
521
475
 
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)
 
476
        self._file_message_expander = gtk.Expander(_('File commit message'))
 
477
        self._file_message_expander.add(file_message_box)
 
478
        file_message_box.show()
525
479
        self._add_to_right_table(self._file_message_expander, 1, False)
526
480
        self._file_message_expander.show()
527
481
 
528
482
    def _construct_global_message(self):
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>'))
 
483
        self._global_message_label = gtk.Label(_('Global Commit Message'))
532
484
        self._global_message_label.set_alignment(0, 0)
533
485
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
534
486
        self._add_to_right_table(self._global_message_label, 1, False)
541
493
        self._global_message_text_view = gtk.TextView()
542
494
        self._global_message_text_view.modify_font(pango.FontDescription("Monospace"))
543
495
        scroller.add(self._global_message_text_view)
 
496
        scroller.show()
544
497
        scroller.set_shadow_type(gtk.SHADOW_IN)
545
 
        scroller.show()
546
498
        self._add_to_right_table(scroller, 2, True)
547
499
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
548
500
        self._file_message_text_view.set_accepts_tab(False)
554
506
 
555
507
        if selection is not None:
556
508
            path, display_path = model.get(selection, 1, 3)
557
 
            self._diff_label.set_text(_i18n('Diff for ') + display_path)
 
509
            self._diff_label.set_text(_('Diff for ') + display_path)
558
510
            if path is None:
559
511
                self._diff_view.show_diff(None)
560
512
            else:
561
 
                self._diff_view.show_diff([path.decode('UTF-8')])
 
513
                self._diff_view.show_diff([path])
562
514
            self._update_per_file_info(selection)
563
515
 
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
 
 
586
516
    def _save_current_file_message(self):
587
517
        if self._last_selected_file is None:
588
518
            return # Nothing to save
594
524
 
595
525
    def _update_per_file_info(self, selection):
596
526
        # The node is changing, so cache the current message
597
 
        if not self._enable_per_file_commits:
598
 
            return
599
 
 
600
527
        self._save_current_file_message()
601
528
        text_buffer = self._file_message_text_view.get_buffer()
602
529
        file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
603
530
        if file_id is None: # Whole tree
604
 
            self._file_message_expander.set_label(_i18n('File commit message'))
 
531
            self._file_message_expander.set_label(_('File commit message'))
605
532
            self._file_message_expander.set_expanded(False)
606
533
            self._file_message_expander.set_sensitive(False)
607
534
            text_buffer.set_text('')
608
535
            self._last_selected_file = None
609
536
        else:
610
 
            self._file_message_expander.set_label(_i18n('Commit message for ')
 
537
            self._file_message_expander.set_label(_('Commit message for ')
611
538
                                                  + display_path)
612
539
            self._file_message_expander.set_expanded(True)
613
540
            self._file_message_expander.set_sensitive(True)
615
542
            self._last_selected_file = self._files_store.get_path(selection)
616
543
 
617
544
    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
545
        self._save_current_file_message()
623
546
        files = []
624
547
        records = iter(self._files_store)
627
550
 
628
551
        file_info = []
629
552
        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
 
553
            if record[2]: # [2] checkbox
 
554
                file_id = record[0]
 
555
                path = record[1]
 
556
                file_message = record[5]
 
557
                files.append(record[1]) # [1] real path
 
558
                if file_message:
637
559
                    file_info.append({'path':path, 'file_id':file_id,
638
560
                                     'message':file_message})
639
561
        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, []
 
562
        return files, file_info
644
563
 
645
564
    @show_bzr_error
646
565
    def _on_commit_clicked(self, button):
652
571
 
653
572
        if message == '':
654
573
            response = self._question_dialog(
655
 
                _i18n('Commit with an empty message?'),
656
 
                _i18n('You can describe your commit intent in the message.'))
 
574
                            _('Commit with an empty message?'),
 
575
                            _('You can describe your commit intent in the message.'))
657
576
            if response == gtk.RESPONSE_NO:
658
577
                # Kindly give focus to message area
659
578
                self._global_message_text_view.grab_focus()
672
591
        #       files at this point.
673
592
        for path in self._wt.unknowns():
674
593
            response = self._question_dialog(
675
 
                _i18n("Commit with unknowns?"),
676
 
                _i18n("Unknown files exist in the working tree. Commit anyway?"))
 
594
                _("Commit with unknowns?"),
 
595
                _("Unknown files exist in the working tree. Commit anyway?"))
677
596
            if response == gtk.RESPONSE_NO:
678
597
                return
679
598
            break
681
600
        rev_id = None
682
601
        revprops = {}
683
602
        if file_info:
684
 
            revprops['file-info'] = bencode.bencode(file_info).decode('UTF-8')
 
603
            revprops['file-info'] = bencode.bencode(file_info)
685
604
        try:
686
605
            rev_id = self._wt.commit(message,
687
606
                       allow_pointless=False,
691
610
                       revprops=revprops)
692
611
        except errors.PointlessCommit:
693
612
            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?'))
 
613
                                _('Commit with no changes?'),
 
614
                                _('There are no changes in the working tree.'
 
615
                                  ' Do you want to commit anyway?'))
697
616
            if response == gtk.RESPONSE_YES:
698
617
                rev_id = self._wt.commit(message,
699
618
                               allow_pointless=True,
711
630
 
712
631
    def _set_global_commit_message(self, message):
713
632
        """Just a helper for the test suite."""
714
 
        if isinstance(message, unicode):
715
 
            message = message.encode('UTF-8')
716
633
        self._global_message_text_view.get_buffer().set_text(message)
717
634
 
718
635
    def _set_file_commit_message(self, message):
719
636
        """Helper for the test suite."""
720
 
        if isinstance(message, unicode):
721
 
            message = message.encode('UTF-8')
722
637
        self._file_message_text_view.get_buffer().set_text(message)
723
638
 
724
639
    @staticmethod
725
640
    def _rev_to_pending_info(rev):
726
641
        """Get the information from a pending merge."""
727
642
        from bzrlib.osutils import format_date
 
643
 
728
644
        rev_dict = {}
729
645
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
730
646
        rev_dict['summary'] = rev.get_summary()
734
650
                                       show_offset=False)
735
651
        rev_dict['revision_id'] = rev.revision_id
736
652
        return rev_dict
 
653
 
 
654
 
 
655
# class CommitDialog(gtk.Dialog):
 
656
#     """ New implementation of the Commit dialog. """
 
657
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
 
658
#         """ Initialize the Commit Dialog. """
 
659
#         gtk.Dialog.__init__(self, title="Commit - Olive",
 
660
#                                   parent=parent,
 
661
#                                   flags=0,
 
662
#                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
 
663
#         
 
664
#         # Get arguments
 
665
#         self.wt = wt
 
666
#         self.wtpath = wtpath
 
667
#         self.notbranch = notbranch
 
668
#         self.selected = selected
 
669
#         
 
670
#         # Set the delta
 
671
#         self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
 
672
#         self.delta = self.wt.changes_from(self.old_tree)
 
673
#         
 
674
#         # Get pending merges
 
675
#         self.pending = self._pending_merges(self.wt)
 
676
#         
 
677
#         # Do some preliminary checks
 
678
#         self._is_checkout = False
 
679
#         self._is_pending = False
 
680
#         if self.wt is None and not self.notbranch:
 
681
#             error_dialog(_('Directory does not have a working tree'),
 
682
#                          _('Operation aborted.'))
 
683
#             self.close()
 
684
#             return
 
685
 
686
#         if self.notbranch:
 
687
#             error_dialog(_('Directory is not a branch'),
 
688
#                          _('You can perform this action only in a branch.'))
 
689
#             self.close()
 
690
#             return
 
691
#         else:
 
692
#             if self.wt.branch.get_bound_location() is not None:
 
693
#                 # we have a checkout, so the local commit checkbox must appear
 
694
#                 self._is_checkout = True
 
695
#             
 
696
#             if self.pending:
 
697
#                 # There are pending merges, file selection not supported
 
698
#                 self._is_pending = True
 
699
#         
 
700
#         # Create the widgets
 
701
#         # This is the main horizontal box, which is used to separate the commit
 
702
#         # info from the diff window.
 
703
#         self._hpane = gtk.HPaned()
 
704
#         self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
 
705
#         self._expander_files = gtk.Expander(_("File(s) to commit"))
 
706
#         self._vpaned_main = gtk.VPaned()
 
707
#         self._scrolledwindow_files = gtk.ScrolledWindow()
 
708
#         self._scrolledwindow_message = gtk.ScrolledWindow()
 
709
#         self._treeview_files = gtk.TreeView()
 
710
#         self._vbox_message = gtk.VBox()
 
711
#         self._label_message = gtk.Label(_("Commit message:"))
 
712
#         self._textview_message = gtk.TextView()
 
713
#         
 
714
#         if self._is_pending:
 
715
#             self._expander_merges = gtk.Expander(_("Pending merges"))
 
716
#             self._vpaned_list = gtk.VPaned()
 
717
#             self._scrolledwindow_merges = gtk.ScrolledWindow()
 
718
#             self._treeview_merges = gtk.TreeView()
 
719
 
720
#         # Set callbacks
 
721
#         self._button_commit.connect('clicked', self._on_commit_clicked)
 
722
#         self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
 
723
#         self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
 
724
#         
 
725
#         # Set properties
 
726
#         self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
 
727
#                                               gtk.POLICY_AUTOMATIC)
 
728
#         self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
 
729
#                                                 gtk.POLICY_AUTOMATIC)
 
730
#         self._textview_message.modify_font(pango.FontDescription("Monospace"))
 
731
#         self.set_default_size(500, 500)
 
732
#         self._vpaned_main.set_position(200)
 
733
#         self._button_commit.set_flags(gtk.CAN_DEFAULT)
 
734
 
735
#         if self._is_pending:
 
736
#             self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
 
737
#                                                    gtk.POLICY_AUTOMATIC)
 
738
#             self._treeview_files.set_sensitive(False)
 
739
#         
 
740
#         # Construct the dialog
 
741
#         self.action_area.pack_end(self._button_commit)
 
742
#         
 
743
#         self._scrolledwindow_files.add(self._treeview_files)
 
744
#         self._scrolledwindow_message.add(self._textview_message)
 
745
#         
 
746
#         self._expander_files.add(self._scrolledwindow_files)
 
747
#         
 
748
#         self._vbox_message.pack_start(self._label_message, False, False)
 
749
#         self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
 
750
#         
 
751
#         if self._is_pending:        
 
752
#             self._expander_merges.add(self._scrolledwindow_merges)
 
753
#             self._scrolledwindow_merges.add(self._treeview_merges)
 
754
#             self._vpaned_list.add1(self._expander_files)
 
755
#             self._vpaned_list.add2(self._expander_merges)
 
756
#             self._vpaned_main.add1(self._vpaned_list)
 
757
#         else:
 
758
#             self._vpaned_main.add1(self._expander_files)
 
759
 
760
#         self._vpaned_main.add2(self._vbox_message)
 
761
#         
 
762
#         self._hpane.pack1(self._vpaned_main)
 
763
#         self.vbox.pack_start(self._hpane, expand=True, fill=True)
 
764
#         if self._is_checkout: 
 
765
#             self._check_local = gtk.CheckButton(_("_Only commit locally"),
 
766
#                                                 use_underline=True)
 
767
#             self.vbox.pack_start(self._check_local, False, False)
 
768
#             if have_dbus:
 
769
#                 bus = dbus.SystemBus()
 
770
#                 proxy_obj = bus.get_object('org.freedesktop.NetworkManager', 
 
771
#                               '/org/freedesktop/NetworkManager')
 
772
#                 dbus_iface = dbus.Interface(
 
773
#                         proxy_obj, 'org.freedesktop.NetworkManager')
 
774
#                 try:
 
775
#                     # 3 is the enum value for STATE_CONNECTED
 
776
#                     self._check_local.set_active(dbus_iface.state() != 3)
 
777
#                 except dbus.DBusException, e:
 
778
#                     # Silently drop errors. While DBus may be 
 
779
#                     # available, NetworkManager doesn't necessarily have to be
 
780
#                     mutter("unable to get networkmanager state: %r" % e)
 
781
#                 
 
782
#         # Create the file list
 
783
#         self._create_file_view()
 
784
#         # Create the pending merges
 
785
#         self._create_pending_merges()
 
786
#         self._create_diff_view()
 
787
#         
 
788
#         # Expand the corresponding expander
 
789
#         if self._is_pending:
 
790
#             self._expander_merges.set_expanded(True)
 
791
#         else:
 
792
#             self._expander_files.set_expanded(True)
 
793
#         
 
794
#         # Display dialog
 
795
#         self.vbox.show_all()
 
796
#         
 
797
#         # Default to Commit button
 
798
#         self._button_commit.grab_default()
 
799
#     
 
800
#     def _show_diff_view(self, treeview):
 
801
#         # FIXME: the diff window freezes for some reason
 
802
#         treeselection = treeview.get_selection()
 
803
#         (model, iter) = treeselection.get_selected()
 
804
 
805
#         if iter is not None:
 
806
#             selected = model.get_value(iter, 3) # Get the real_path attribute
 
807
#             self._diff_display.show_diff([selected])
 
808
 
809
#     def _on_treeview_files_cursor_changed(self, treeview):
 
810
#         self._show_diff_view(treeview)
 
811
#         
 
812
#     def _on_treeview_files_row_activated(self, treeview, path, view_column):
 
813
#         self._show_diff_view(treeview)
 
814
#     
 
815
#     @show_bzr_error
 
816
#     def _on_commit_clicked(self, button):
 
817
#         """ Commit button clicked handler. """
 
818
#         textbuffer = self._textview_message.get_buffer()
 
819
#         start, end = textbuffer.get_bounds()
 
820
#         message = textbuffer.get_text(start, end).decode('utf-8')
 
821
#         
 
822
#         if not self.pending:
 
823
#             specific_files = self._get_specific_files()
 
824
#         else:
 
825
#             specific_files = None
 
826
 
827
#         if message == '':
 
828
#             response = question_dialog(_('Commit with an empty message?'),
 
829
#                                        _('You can describe your commit intent in the message.'))
 
830
#             if response == gtk.RESPONSE_NO:
 
831
#                 # Kindly give focus to message area
 
832
#                 self._textview_message.grab_focus()
 
833
#                 return
 
834
 
835
#         if self._is_checkout:
 
836
#             local = self._check_local.get_active()
 
837
#         else:
 
838
#             local = False
 
839
 
840
#         if list(self.wt.unknowns()) != []:
 
841
#             response = question_dialog(_("Commit with unknowns?"),
 
842
#                _("Unknown files exist in the working tree. Commit anyway?"))
 
843
#             if response == gtk.RESPONSE_NO:
 
844
#                 return
 
845
#         
 
846
#         try:
 
847
#             self.wt.commit(message,
 
848
#                        allow_pointless=False,
 
849
#                        strict=False,
 
850
#                        local=local,
 
851
#                        specific_files=specific_files)
 
852
#         except errors.PointlessCommit:
 
853
#             response = question_dialog(_('Commit with no changes?'),
 
854
#                                        _('There are no changes in the working tree.'))
 
855
#             if response == gtk.RESPONSE_YES:
 
856
#                 self.wt.commit(message,
 
857
#                                allow_pointless=True,
 
858
#                                strict=False,
 
859
#                                local=local,
 
860
#                                specific_files=specific_files)
 
861
#         self.response(gtk.RESPONSE_OK)
 
862
 
863
#     def _pending_merges(self, wt):
 
864
#         """ Return a list of pending merges or None if there are none of them. """
 
865
#         parents = wt.get_parent_ids()
 
866
#         if len(parents) < 2:
 
867
#             return None
 
868
#         
 
869
#         import re
 
870
#         from bzrlib.osutils import format_date
 
871
#         
 
872
#         pending = parents[1:]
 
873
#         branch = wt.branch
 
874
#         last_revision = parents[0]
 
875
#         
 
876
#         if last_revision is not None:
 
877
#             try:
 
878
#                 ignore = set(branch.repository.get_ancestry(last_revision))
 
879
#             except errors.NoSuchRevision:
 
880
#                 # the last revision is a ghost : assume everything is new 
 
881
#                 # except for it
 
882
#                 ignore = set([None, last_revision])
 
883
#         else:
 
884
#             ignore = set([None])
 
885
#         
 
886
#         pm = []
 
887
#         for merge in pending:
 
888
#             ignore.add(merge)
 
889
#             try:
 
890
#                 m_revision = branch.repository.get_revision(merge)
 
891
#                 
 
892
#                 rev = {}
 
893
#                 rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
 
894
#                 rev['summary'] = m_revision.get_summary()
 
895
#                 rev['date'] = format_date(m_revision.timestamp,
 
896
#                                           m_revision.timezone or 0, 
 
897
#                                           'original', date_fmt="%Y-%m-%d",
 
898
#                                           show_offset=False)
 
899
#                 
 
900
#                 pm.append(rev)
 
901
#                 
 
902
#                 inner_merges = branch.repository.get_ancestry(merge)
 
903
#                 assert inner_merges[0] is None
 
904
#                 inner_merges.pop(0)
 
905
#                 inner_merges.reverse()
 
906
#                 for mmerge in inner_merges:
 
907
#                     if mmerge in ignore:
 
908
#                         continue
 
909
#                     mm_revision = branch.repository.get_revision(mmerge)
 
910
#                     
 
911
#                     rev = {}
 
912
#                     rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
 
913
#                     rev['summary'] = mm_revision.get_summary()
 
914
#                     rev['date'] = format_date(mm_revision.timestamp,
 
915
#                                               mm_revision.timezone or 0, 
 
916
#                                               'original', date_fmt="%Y-%m-%d",
 
917
#                                               show_offset=False)
 
918
#                 
 
919
#                     pm.append(rev)
 
920
#                     
 
921
#                     ignore.add(mmerge)
 
922
#             except errors.NoSuchRevision:
 
923
#                 print "DEBUG: NoSuchRevision:", merge
 
924
#         
 
925
#         return pm
 
926
 
927
#     def _create_file_view(self):
 
928
#         self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
 
929
#                                          gobject.TYPE_STRING,    # [1] path to display
 
930
#                                          gobject.TYPE_STRING,    # [2] changes type
 
931
#                                          gobject.TYPE_STRING)    # [3] real path
 
932
#         self._treeview_files.set_model(self._file_store)
 
933
#         crt = gtk.CellRendererToggle()
 
934
#         crt.set_property("activatable", True)
 
935
#         crt.connect("toggled", self._toggle_commit, self._file_store)
 
936
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
 
937
#                                      crt, active=0))
 
938
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
 
939
#                                      gtk.CellRendererText(), text=1))
 
940
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
 
941
#                                      gtk.CellRendererText(), text=2))
 
942
 
943
#         for path, id, kind in self.delta.added:
 
944
#             marker = osutils.kind_marker(kind)
 
945
#             if self.selected is not None:
 
946
#                 if path == os.path.join(self.wtpath, self.selected):
 
947
#                     self._file_store.append([ True, path+marker, _('added'), path ])
 
948
#                 else:
 
949
#                     self._file_store.append([ False, path+marker, _('added'), path ])
 
950
#             else:
 
951
#                 self._file_store.append([ True, path+marker, _('added'), path ])
 
952
 
953
#         for path, id, kind in self.delta.removed:
 
954
#             marker = osutils.kind_marker(kind)
 
955
#             if self.selected is not None:
 
956
#                 if path == os.path.join(self.wtpath, self.selected):
 
957
#                     self._file_store.append([ True, path+marker, _('removed'), path ])
 
958
#                 else:
 
959
#                     self._file_store.append([ False, path+marker, _('removed'), path ])
 
960
#             else:
 
961
#                 self._file_store.append([ True, path+marker, _('removed'), path ])
 
962
 
963
#         for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
 
964
#             marker = osutils.kind_marker(kind)
 
965
#             if text_modified or meta_modified:
 
966
#                 changes = _('renamed and modified')
 
967
#             else:
 
968
#                 changes = _('renamed')
 
969
#             if self.selected is not None:
 
970
#                 if newpath == os.path.join(self.wtpath, self.selected):
 
971
#                     self._file_store.append([ True,
 
972
#                                               oldpath+marker + '  =>  ' + newpath+marker,
 
973
#                                               changes,
 
974
#                                               newpath
 
975
#                                             ])
 
976
#                 else:
 
977
#                     self._file_store.append([ False,
 
978
#                                               oldpath+marker + '  =>  ' + newpath+marker,
 
979
#                                               changes,
 
980
#                                               newpath
 
981
#                                             ])
 
982
#             else:
 
983
#                 self._file_store.append([ True,
 
984
#                                           oldpath+marker + '  =>  ' + newpath+marker,
 
985
#                                           changes,
 
986
#                                           newpath
 
987
#                                         ])
 
988
 
989
#         for path, id, kind, text_modified, meta_modified in self.delta.modified:
 
990
#             marker = osutils.kind_marker(kind)
 
991
#             if self.selected is not None:
 
992
#                 if path == os.path.join(self.wtpath, self.selected):
 
993
#                     self._file_store.append([ True, path+marker, _('modified'), path ])
 
994
#                 else:
 
995
#                     self._file_store.append([ False, path+marker, _('modified'), path ])
 
996
#             else:
 
997
#                 self._file_store.append([ True, path+marker, _('modified'), path ])
 
998
#     
 
999
#     def _create_pending_merges(self):
 
1000
#         if not self.pending:
 
1001
#             return
 
1002
#         
 
1003
#         liststore = gtk.ListStore(gobject.TYPE_STRING,
 
1004
#                                   gobject.TYPE_STRING,
 
1005
#                                   gobject.TYPE_STRING)
 
1006
#         self._treeview_merges.set_model(liststore)
 
1007
#         
 
1008
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
 
1009
#                                             gtk.CellRendererText(), text=0))
 
1010
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
 
1011
#                                             gtk.CellRendererText(), text=1))
 
1012
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
 
1013
#                                             gtk.CellRendererText(), text=2))
 
1014
#         
 
1015
#         for item in self.pending:
 
1016
#             liststore.append([ item['date'],
 
1017
#                                item['committer'],
 
1018
#                                item['summary'] ])
 
1019
#     
 
1020
 
1021
#     def _create_diff_view(self):
 
1022
#         from diff import DiffView
 
1023
 
1024
#         self._diff_display = DiffView()
 
1025
#         self._diff_display.set_trees(self.wt, self.wt.basis_tree())
 
1026
#         self._diff_display.show_diff(None)
 
1027
#         self._diff_display.show()
 
1028
#         self._hpane.pack2(self._diff_display)
 
1029
 
1030
#     def _get_specific_files(self):
 
1031
#         ret = []
 
1032
#         it = self._file_store.get_iter_first()
 
1033
#         while it:
 
1034
#             if self._file_store.get_value(it, 0):
 
1035
#                 # get real path from hidden column 3
 
1036
#                 ret.append(self._file_store.get_value(it, 3))
 
1037
#             it = self._file_store.iter_next(it)
 
1038
 
1039
#         return ret
 
1040
#     
 
1041
#     def _toggle_commit(self, cell, path, model):
 
1042
#         model[path][0] = not model[path][0]
 
1043
#         return