/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 17:33:27 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-20071002173327-3td5w3r03q4thu5j
Add a test-gtk command to make testing faster

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
33
32
 
34
 
from bzrlib.plugins.gtk import _i18n
35
33
from dialog import error_dialog, question_dialog
36
34
from errors import show_bzr_error
37
35
 
105
103
                                  parent=parent,
106
104
                                  flags=0,
107
105
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
108
 
        self._question_dialog = question_dialog
109
 
 
110
106
        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
107
        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
117
108
 
118
109
        self.setup_params()
119
110
        self.construct()
132
123
        self._fill_in_pending()
133
124
        self._fill_in_diff()
134
125
        self._fill_in_files()
135
 
        self._fill_in_checkout()
136
 
        self._fill_in_per_file_info()
137
126
 
138
127
    def _fill_in_pending(self):
139
128
        if not self._pending:
160
149
        self._pending_box.show()
161
150
 
162
151
    def _fill_in_files(self):
163
 
        # We should really use add a progress bar of some kind.
 
152
        # We should really use _iter_changes, and then add a progress bar of
 
153
        # some kind.
164
154
        # While we fill in the view, hide the store
165
155
        store = self._files_store
166
156
        self._treeview_files.set_model(None)
167
157
 
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')
 
158
        added = _('added')
 
159
        removed = _('removed')
 
160
        renamed = _('renamed')
 
161
        renamed_and_modified = _('renamed and modified')
 
162
        modified = _('modified')
 
163
        kind_changed = _('kind changed')
174
164
 
175
165
        # The store holds:
176
166
        # [file_id, real path, checkbox, display path, changes type, message]
177
 
        # iter_changes returns:
 
167
        # _iter_changes returns:
178
168
        # (file_id, (path_in_source, path_in_target),
179
169
        #  changed_content, versioned, parent, name, kind,
180
170
        #  executable)
181
171
 
182
 
        all_enabled = (self._selected is None)
183
172
        # 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)
 
173
        store.append([None, None, True, 'All Files', '', ''])
186
174
        # should we pass specific_files?
187
175
        self._wt.lock_read()
188
176
        self._basis_tree.lock_read()
189
177
        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)
 
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, ''])
207
230
        finally:
208
231
            self._basis_tree.unlock()
209
232
            self._wt.unlock()
210
233
 
211
234
        self._treeview_files.set_model(store)
212
235
        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)
 
236
        self._treeview_files.set_cursor(0)
221
237
 
222
238
    def _fill_in_diff(self):
223
239
        self._diff_view.set_trees(self._wt, self._basis_tree)
224
240
 
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
 
 
263
241
    def _compute_delta(self):
264
242
        self._delta = self._wt.changes_from(self._basis_tree)
265
243
 
271
249
 
272
250
        self._construct_left_pane()
273
251
        self._construct_right_pane()
274
 
        self._construct_action_pane()
275
252
 
276
253
        self.vbox.pack_start(self._hpane)
277
254
        self._hpane.show()
278
255
        self.set_focus(self._global_message_text_view)
279
256
 
280
 
        self._construct_accelerators()
281
 
        self._set_sizes()
282
 
 
283
 
    def _set_sizes(self):
284
257
        # This seems like a reasonable default, we might like it to
285
258
        # be a bit wider, so that by default we can fit an 80-line diff in the
286
259
        # diff window.
297
270
        self.set_default_size(width, height)
298
271
        self._hpane.set_position(300)
299
272
 
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
273
    def _construct_left_pane(self):
310
274
        self._left_pane_box = gtk.VBox(homogeneous=False, spacing=5)
311
275
        self._construct_file_list()
312
276
        self._construct_pending_list()
313
277
 
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
 
 
319
278
        self._hpane.pack1(self._left_pane_box, resize=False, shrink=False)
320
279
        self._left_pane_box.show()
321
280
 
337
296
        self._right_pane_table.show()
338
297
        self._hpane.pack2(self._right_pane_table, resize=True, shrink=True)
339
298
 
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
 
 
348
299
    def _add_to_right_table(self, widget, weight, expanding=False):
349
300
        """Add another widget to the table
350
301
 
364
315
 
365
316
    def _construct_file_list(self):
366
317
        self._files_box = gtk.VBox(homogeneous=False, spacing=0)
367
 
        file_label = gtk.Label(_i18n('Files'))
368
 
        # file_label.show()
 
318
        file_label = gtk.Label(_('Files'))
 
319
        file_label.show()
369
320
        self._files_box.pack_start(file_label, expand=False)
370
321
 
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
322
        scroller = gtk.ScrolledWindow()
389
323
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
390
324
        self._treeview_files = gtk.TreeView()
391
325
        self._treeview_files.show()
392
326
        scroller.add(self._treeview_files)
 
327
        scroller.show()
393
328
        scroller.set_shadow_type(gtk.SHADOW_IN)
394
 
        scroller.show()
395
329
        self._files_box.pack_start(scroller,
396
330
                                   expand=True, fill=True)
397
331
        self._files_box.show()
398
332
        self._left_pane_box.pack_start(self._files_box)
399
333
 
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
334
        liststore = gtk.ListStore(
404
335
            gobject.TYPE_STRING,  # [0] file_id
405
336
            gobject.TYPE_STRING,  # [1] real path
411
342
        self._files_store = liststore
412
343
        self._treeview_files.set_model(liststore)
413
344
        crt = gtk.CellRendererToggle()
414
 
        crt.set_property('activatable', not bool(self._pending))
 
345
        crt.set_active(not bool(self._pending))
415
346
        crt.connect("toggled", self._toggle_commit, self._files_store)
416
347
        if self._pending:
417
 
            name = _i18n('Commit*')
 
348
            name = _('Commit*')
418
349
        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'),
 
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'),
424
354
                                           gtk.CellRendererText(), text=3))
425
 
        self._treeview_files.append_column(gtk.TreeViewColumn(_i18n('Type'),
 
355
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
426
356
                                           gtk.CellRendererText(), text=4))
427
357
        self._treeview_files.connect('cursor-changed',
428
358
                                     self._on_treeview_files_cursor_changed)
435
365
        else:
436
366
            model[path][2] = not model[path][2]
437
367
 
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
368
    def _construct_pending_list(self):
451
369
        # Pending information defaults to hidden, we put it all in 1 box, so
452
370
        # that we can show/hide all of them at once
455
373
 
456
374
        pending_message = gtk.Label()
457
375
        pending_message.set_markup(
458
 
            _i18n('<i>* Cannot select specific files when merging</i>'))
 
376
            _('<i>* Cannot select specific files when merging</i>'))
459
377
        self._pending_box.pack_start(pending_message, expand=False, padding=5)
460
378
        pending_message.show()
461
379
 
462
 
        pending_label = gtk.Label(_i18n('Pending Revisions'))
 
380
        pending_label = gtk.Label(_('Pending Revisions'))
463
381
        self._pending_box.pack_start(pending_label, expand=False, padding=0)
464
382
        pending_label.show()
465
383
 
467
385
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
468
386
        self._treeview_pending = gtk.TreeView()
469
387
        scroller.add(self._treeview_pending)
 
388
        scroller.show()
470
389
        scroller.set_shadow_type(gtk.SHADOW_IN)
471
 
        scroller.show()
472
390
        self._pending_box.pack_start(scroller,
473
391
                                     expand=True, fill=True, padding=5)
474
392
        self._treeview_pending.show()
481
399
                                 )
482
400
        self._pending_store = liststore
483
401
        self._treeview_pending.set_model(liststore)
484
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Date'),
 
402
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Date'),
485
403
                                             gtk.CellRendererText(), text=1))
486
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Committer'),
 
404
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Committer'),
487
405
                                             gtk.CellRendererText(), text=2))
488
 
        self._treeview_pending.append_column(gtk.TreeViewColumn(_i18n('Summary'),
 
406
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Summary'),
489
407
                                             gtk.CellRendererText(), text=3))
490
408
 
491
409
    def _construct_diff_view(self):
492
410
        from diff import DiffView
493
411
 
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'))
 
412
        self._diff_label = gtk.Label(_('Diff for whole tree'))
499
413
        self._diff_label.set_alignment(0, 0)
500
414
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
501
415
        self._add_to_right_table(self._diff_label, 1, False)
502
 
        # self._diff_label.show()
 
416
        self._diff_label.show()
503
417
 
504
418
        self._diff_view = DiffView()
505
419
        self._add_to_right_table(self._diff_view, 4, True)
506
420
        self._diff_view.show()
507
421
 
508
422
    def _construct_file_message(self):
 
423
        file_message_box = gtk.VBox()
509
424
        scroller = gtk.ScrolledWindow()
510
425
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
511
426
 
512
427
        self._file_message_text_view = gtk.TextView()
513
428
        scroller.add(self._file_message_text_view)
 
429
        scroller.show()
514
430
        scroller.set_shadow_type(gtk.SHADOW_IN)
515
 
        scroller.show()
 
431
        file_message_box.pack_start(scroller, expand=True, fill=True)
516
432
 
517
433
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
518
434
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
519
435
        self._file_message_text_view.set_accepts_tab(False)
520
436
        self._file_message_text_view.show()
521
437
 
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)
 
438
        self._file_message_expander = gtk.Expander(_('File commit message'))
 
439
        self._file_message_expander.add(file_message_box)
 
440
        file_message_box.show()
525
441
        self._add_to_right_table(self._file_message_expander, 1, False)
526
442
        self._file_message_expander.show()
527
443
 
528
444
    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>'))
 
445
        self._global_message_label = gtk.Label(_('Global Commit Message'))
532
446
        self._global_message_label.set_alignment(0, 0)
533
447
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
534
448
        self._add_to_right_table(self._global_message_label, 1, False)
541
455
        self._global_message_text_view = gtk.TextView()
542
456
        self._global_message_text_view.modify_font(pango.FontDescription("Monospace"))
543
457
        scroller.add(self._global_message_text_view)
 
458
        scroller.show()
544
459
        scroller.set_shadow_type(gtk.SHADOW_IN)
545
 
        scroller.show()
546
460
        self._add_to_right_table(scroller, 2, True)
547
461
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
548
462
        self._file_message_text_view.set_accepts_tab(False)
554
468
 
555
469
        if selection is not None:
556
470
            path, display_path = model.get(selection, 1, 3)
557
 
            self._diff_label.set_text(_i18n('Diff for ') + display_path)
 
471
            self._diff_label.set_text(_('Diff for ') + display_path)
558
472
            if path is None:
559
473
                self._diff_view.show_diff(None)
560
474
            else:
561
 
                self._diff_view.show_diff([path.decode('UTF-8')])
 
475
                self._diff_view.show_diff([path])
562
476
            self._update_per_file_info(selection)
563
477
 
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
478
    def _save_current_file_message(self):
587
479
        if self._last_selected_file is None:
588
480
            return # Nothing to save
594
486
 
595
487
    def _update_per_file_info(self, selection):
596
488
        # The node is changing, so cache the current message
597
 
        if not self._enable_per_file_commits:
598
 
            return
599
 
 
600
489
        self._save_current_file_message()
601
490
        text_buffer = self._file_message_text_view.get_buffer()
602
491
        file_id, display_path, message = self._files_store.get(selection, 0, 3, 5)
603
492
        if file_id is None: # Whole tree
604
 
            self._file_message_expander.set_label(_i18n('File commit message'))
 
493
            self._file_message_expander.set_label(_('File commit message'))
605
494
            self._file_message_expander.set_expanded(False)
606
495
            self._file_message_expander.set_sensitive(False)
607
496
            text_buffer.set_text('')
608
497
            self._last_selected_file = None
609
498
        else:
610
 
            self._file_message_expander.set_label(_i18n('Commit message for ')
 
499
            self._file_message_expander.set_label(_('Commit message for ')
611
500
                                                  + display_path)
612
501
            self._file_message_expander.set_expanded(True)
613
502
            self._file_message_expander.set_sensitive(True)
614
503
            text_buffer.set_text(message)
615
504
            self._last_selected_file = self._files_store.get_path(selection)
616
505
 
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
 
 
724
506
    @staticmethod
725
507
    def _rev_to_pending_info(rev):
726
508
        """Get the information from a pending merge."""
727
509
        from bzrlib.osutils import format_date
 
510
 
728
511
        rev_dict = {}
729
512
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
730
513
        rev_dict['summary'] = rev.get_summary()
734
517
                                       show_offset=False)
735
518
        rev_dict['revision_id'] = rev.revision_id
736
519
        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