/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
2
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
7
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
12
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
try:
18
    import pygtk
19
    pygtk.require("2.0")
20
except:
21
    pass
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
22
0.13.11 by Jelmer Vernooij
Bunch of small fixes, cleanups and simplifications.
23
import gtk
24
import gobject
25
import pango
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
26
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
27
import os.path
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
28
import re
126.1.10 by Szilveszter Farkas (Phanatic)
Allow to commit single files from the context menu (Fixed: #54983)
29
248 by Jelmer Vernooij
Merge fixes for #127392 and #127381)
30
from bzrlib import errors, osutils
235.1.5 by Mateusz Korniak
Missing mutter import added.
31
from bzrlib.trace import mutter
0.8.20 by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
32
153 by Jelmer Vernooij
Fix references to dialog.
33
from dialog import error_dialog, question_dialog
132 by Jelmer Vernooij
Use decorator for catching and showing bzr-gtk errors graphically. Eventually, this should go away and should be handled by the ui factory.
34
from errors import show_bzr_error
93.1.6 by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile)
35
158 by Jelmer Vernooij
If available, use NetworkManager to find out whether a commit should be local or not.
36
try:
37
    import dbus
38
    import dbus.glib
180 by Jelmer Vernooij
Don't obtain handle to network manager until it's actually needed.
39
    have_dbus = True
158 by Jelmer Vernooij
If available, use NetworkManager to find out whether a commit should be local or not.
40
except ImportError:
180 by Jelmer Vernooij
Don't obtain handle to network manager until it's actually needed.
41
    have_dbus = False
158 by Jelmer Vernooij
If available, use NetworkManager to find out whether a commit should be local or not.
42
278.1.4 by John Arbash Meinel
Just playing around.
43
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
44
def pending_revisions(wt):
45
    """Return a list of pending merges or None if there are none of them.
46
47
    Arguably this should be a core function, and
48
    ``bzrlib.status.show_pending_merges`` should be built on top of it.
49
50
    :return: [(rev, [children])]
51
    """
52
    parents = wt.get_parent_ids()
53
    if len(parents) < 2:
54
        return None
55
56
    # The basic pending merge algorithm uses the same algorithm as
57
    # bzrlib.status.show_pending_merges
58
    pending = parents[1:]
59
    branch = wt.branch
60
    last_revision = parents[0]
61
62
    if last_revision is not None:
63
        try:
64
            ignore = set(branch.repository.get_ancestry(last_revision,
65
                                                        topo_sorted=False))
66
        except errors.NoSuchRevision:
67
            # the last revision is a ghost : assume everything is new
68
            # except for it
69
            ignore = set([None, last_revision])
70
    else:
71
        ignore = set([None])
72
73
    pm = []
74
    for merge in pending:
75
        ignore.add(merge)
76
        try:
77
            rev = branch.repository.get_revision(merge)
78
            children = []
79
            pm.append((rev, children))
80
81
            # This does need to be topo sorted, so we search backwards
82
            inner_merges = branch.repository.get_ancestry(merge)
83
            assert inner_merges[0] is None
84
            inner_merges.pop(0)
85
            for mmerge in reversed(inner_merges):
86
                if mmerge in ignore:
87
                    continue
88
                rev = branch.repository.get_revision(mmerge)
89
                children.append(rev)
90
91
                ignore.add(mmerge)
92
        except errors.NoSuchRevision:
93
            print "DEBUG: NoSuchRevision:", merge
94
95
    return pm
96
97
135 by Jelmer Vernooij
Throw out the old CommitDialog code and use the new code instead, also for 'gcommit'.
98
class CommitDialog(gtk.Dialog):
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
99
    """Implementation of Commit."""
100
101
    def __init__(self, wt, selected=None, parent=None):
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
102
        gtk.Dialog.__init__(self, title="Commit - Olive",
103
                                  parent=parent,
104
                                  flags=0,
105
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
106
        self._wt = wt
107
        self._selected = selected
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
108
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
109
        self.setup_params()
110
        self.construct()
111
        self.fill_in_data()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
112
113
    def setup_params(self):
114
        """Setup the member variables for state."""
115
        self._basis_tree = self._wt.basis_tree()
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
116
        self._delta = None
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
117
        self._pending = pending_revisions(self._wt)
118
119
        self._is_checkout = (self._wt.branch.get_bound_location() is not None)
120
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
121
    def fill_in_data(self):
122
        # Now that we are built, handle changes to the view based on the state
123
        self._fill_in_pending()
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
124
        self._fill_in_files()
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
125
        self._fill_in_diff()
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
126
127
    def _fill_in_pending(self):
128
        if not self._pending:
129
            self._pending_box.hide()
130
            return
131
132
        # TODO: We'd really prefer this to be a nested list
133
        for rev, children in self._pending:
134
            rev_info = self._rev_to_pending_info(rev)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
135
            self._pending_store.append([
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
136
                rev_info['revision_id'],
137
                rev_info['date'],
138
                rev_info['committer'],
139
                rev_info['summary'],
140
                ])
141
            for child in children:
142
                rev_info = self._rev_to_pending_info(child)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
143
                self._pending_store.append([
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
144
                    rev_info['revision_id'],
145
                    rev_info['date'],
146
                    rev_info['committer'],
147
                    rev_info['summary'],
148
                    ])
149
        self._pending_box.show()
150
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
151
    def _fill_in_files(self):
152
        # We should really use _iter_changes, and then add a progress bar of
153
        # some kind.
154
        # While we fill in the view, hide the store
155
        store = self._files_store
156
        self._treeview_files.set_model(None)
157
158
        added = _('added')
159
        removed = _('removed')
160
        renamed = _('renamed')
161
        renamed_and_modified = _('renamed and modified')
162
        modified = _('modified')
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
163
        kind_changed = _('kind changed')
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
164
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
165
        # The store holds:
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
166
        # [file_id, real path, checkbox, display path, changes type]
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
167
        # _iter_changes returns:
168
        # (file_id, (path_in_source, path_in_target),
169
        #  changed_content, versioned, parent, name, kind,
170
        #  executable)
171
172
        # should we pass specific_files?
173
        self._wt.lock_read()
174
        self._basis_tree.lock_read()
175
        try:
176
            for (file_id, paths, changed_content, versioned, parent_ids, names,
177
                 kinds, executables) in self._wt._iter_changes(self._basis_tree):
178
179
                # Skip the root entry.
180
                if parent_ids == (None, None):
181
                    continue
182
183
                change_type = None
184
                if kinds[0] is None:
185
                    source_marker = ''
186
                else:
187
                    source_marker = osutils.kind_marker(kinds[0])
188
                if kinds[1] is None:
189
                    assert kinds[0] is not None
190
                    marker = osutils.kind_marker(kinds[0])
191
                else:
192
                    marker = osutils.kind_marker(kinds[1])
193
194
                real_path = paths[1]
195
                if real_path is None:
196
                    real_path = paths[0]
197
                assert real_path is not None
198
                display_path = real_path + marker
199
200
                present_source = versioned[0] and kinds[0] is not None
201
                present_target = versioned[1] and kinds[1] is not None
202
203
                if present_source != present_target:
204
                    if present_target:
205
                        change_type = added
206
                    else:
207
                        change_type = removed
208
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
209
                    # Renamed
210
                    if changed_content or executables[0] != executables[1]:
211
                        # and modified
212
                        change_type = renamed_and_modified
213
                    else:
214
                        change_type = renamed
215
                    display_path = (paths[0] + source_marker
216
                                    + ' => ' + paths[1] + marker)
217
                elif kinds[0] != kinds[1]:
218
                    change_type = kind_changed
219
                    display_path = (paths[0] + source_marker
220
                                    + ' => ' + paths[1] + marker)
221
                elif changed_content is True or executables[0] != executables[1]:
222
                    change_type = modified
223
                else:
224
                    assert False, "How did we get here?"
225
226
                store.append([file_id, real_path, True, display_path, change_type])
227
        finally:
228
            self._basis_tree.unlock()
229
            self._wt.unlock()
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
230
231
        self._treeview_files.set_model(store)
232
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
233
    def _fill_in_diff(self):
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
234
        self._diff_label.set_text(_('Diff for whole tree'))
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
235
        self._diff_view.set_trees(self._wt, self._basis_tree)
236
        self._diff_view.show_diff(None)
237
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
238
    def _compute_delta(self):
239
        self._delta = self._wt.changes_from(self._basis_tree)
240
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
241
    def construct(self):
242
        """Build up the dialog widgets."""
243
        # The primary pane which splits it into left and right (adjustable)
244
        # sections.
278.1.4 by John Arbash Meinel
Just playing around.
245
        self._hpane = gtk.HPaned()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
246
247
        self._construct_left_pane()
248
        self._construct_right_pane()
249
250
        self.vbox.pack_start(self._hpane)
251
        self._hpane.show()
252
        self.set_focus(self._global_message_text_view)
253
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
254
        # This seems like a reasonable default, we might like it to
255
        # be a bit wider, so that by default we can fit an 80-line diff in the
256
        # diff window.
257
        # Alternatively, we should be saving the last position/size rather than
258
        # setting it to a fixed value every time we start up.
259
        screen = self.get_screen()
260
        monitor = 0 # We would like it to be the monitor we are going to
261
                    # display on, but I don't know how to figure that out
262
                    # Only really useful for freaks like me that run dual
263
                    # monitor, with different sizes on the monitors
264
        monitor_rect = screen.get_monitor_geometry(monitor)
265
        width = int(monitor_rect.width * 0.66)
266
        height = int(monitor_rect.height * 0.66)
267
        self.set_default_size(width, height)
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
268
        self._hpane.set_position(300)
269
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
270
    def _construct_left_pane(self):
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
271
        self._left_pane_box = gtk.VBox(homogeneous=False, spacing=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
272
        self._construct_file_list()
273
        self._construct_pending_list()
274
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
275
        self._hpane.pack1(self._left_pane_box, resize=False, shrink=False)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
276
        self._left_pane_box.show()
277
278
    def _construct_right_pane(self):
279
        # TODO: I really want to make it so the diff view gets more space than
280
        # the global commit message, and the per-file commit message gets even
281
        # less. When I did it with wxGlade, I set it to 4 for diff, 2 for
282
        # commit, and 1 for file commit, and it looked good. But I don't seem
283
        # to have a way to do that with the gtk boxes... :( (Which is extra
284
        # weird since wx uses gtk on Linux...)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
285
        self._right_pane_table = gtk.Table(rows=10, columns=1, homogeneous=False)
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
286
        self._right_pane_table.set_row_spacings(5)
287
        self._right_pane_table.set_col_spacings(5)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
288
        self._right_pane_table_row = 0
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
289
        self._construct_diff_view()
290
        self._construct_file_message()
291
        self._construct_global_message()
292
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
293
        self._right_pane_table.show()
294
        self._hpane.pack2(self._right_pane_table, resize=True, shrink=True)
295
296
    def _add_to_right_table(self, widget, weight, expanding=False):
297
        """Add another widget to the table
298
299
        :param widget: The object to add
300
        :param weight: How many rows does this widget get to request
301
        :param expanding: Should expand|fill|shrink be set?
302
        """
303
        end_row = self._right_pane_table_row + weight
304
        options = 0
305
        expand_opts = gtk.EXPAND | gtk.FILL | gtk.SHRINK
306
        if expanding:
307
            options = expand_opts
308
        self._right_pane_table.attach(widget, 0, 1,
309
                                      self._right_pane_table_row, end_row,
310
                                      xoptions=expand_opts, yoptions=options)
311
        self._right_pane_table_row = end_row
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
312
313
    def _construct_file_list(self):
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
314
        self._files_box = gtk.VBox(homogeneous=False, spacing=0)
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
315
        file_label = gtk.Label(_('Files'))
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
316
        file_label.show()
317
        self._files_box.pack_start(file_label, expand=False)
318
319
        scroller = gtk.ScrolledWindow()
320
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
321
        self._treeview_files = gtk.TreeView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
322
        self._treeview_files.show()
323
        scroller.add(self._treeview_files)
324
        scroller.show()
325
        scroller.set_shadow_type(gtk.SHADOW_IN)
326
        self._files_box.pack_start(scroller,
327
                                   expand=True, fill=True)
328
        self._files_box.show()
329
        self._left_pane_box.pack_start(self._files_box)
330
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
331
        liststore = gtk.ListStore(
332
            gobject.TYPE_STRING,  # [0] file_id
333
            gobject.TYPE_STRING,  # [1] real path
334
            gobject.TYPE_BOOLEAN, # [2] checkbox
335
            gobject.TYPE_STRING,  # [3] display path
336
            gobject.TYPE_STRING,  # [4] changes type
337
            )
338
        self._files_store = liststore
339
        self._treeview_files.set_model(liststore)
340
        crt = gtk.CellRendererToggle()
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
341
        crt.set_property("activatable", not bool(self._pending))
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
342
        crt.connect("toggled", self._toggle_commit, self._files_store)
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
343
        if self._pending:
344
            name = _('Commit*')
345
        else:
346
            name = _('Commit')
347
        self._treeview_files.append_column(gtk.TreeViewColumn(name,
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
348
                                           crt, active=2))
349
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
350
                                           gtk.CellRendererText(), text=3))
351
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
352
                                           gtk.CellRendererText(), text=4))
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
353
        self._treeview_files.connect('cursor-changed',
354
                                     self._on_treeview_files_cursor_changed)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
355
356
    def _toggle_commit(self, cell, path, model):
357
        model[path][2] = not model[path][2]
358
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
359
    def _construct_pending_list(self):
360
        # Pending information defaults to hidden, we put it all in 1 box, so
361
        # that we can show/hide all of them at once
362
        self._pending_box = gtk.VBox()
363
        self._pending_box.hide()
364
365
        pending_message = gtk.Label()
366
        pending_message.set_markup(
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
367
            _('<i>* Cannot select specific files when merging</i>'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
368
        self._pending_box.pack_start(pending_message, expand=False, padding=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
369
        pending_message.show()
370
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
371
        pending_label = gtk.Label(_('Pending Revisions'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
372
        self._pending_box.pack_start(pending_label, expand=False, padding=0)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
373
        pending_label.show()
374
375
        scroller = gtk.ScrolledWindow()
376
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
377
        self._treeview_pending = gtk.TreeView()
378
        scroller.add(self._treeview_pending)
379
        scroller.show()
380
        scroller.set_shadow_type(gtk.SHADOW_IN)
381
        self._pending_box.pack_start(scroller,
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
382
                                     expand=True, fill=True, padding=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
383
        self._treeview_pending.show()
384
        self._left_pane_box.pack_start(self._pending_box)
385
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
386
        liststore = gtk.ListStore(gobject.TYPE_STRING, # revision_id
387
                                  gobject.TYPE_STRING, # date
388
                                  gobject.TYPE_STRING, # committer
389
                                  gobject.TYPE_STRING, # summary
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
390
                                 )
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
391
        self._pending_store = liststore
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
392
        self._treeview_pending.set_model(liststore)
393
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Date'),
394
                                             gtk.CellRendererText(), text=1))
395
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Committer'),
396
                                             gtk.CellRendererText(), text=2))
397
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Summary'),
398
                                             gtk.CellRendererText(), text=3))
399
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
400
    def _construct_diff_view(self):
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
401
        from diff import DiffView
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
402
403
        self._diff_label = gtk.Label(_('Diff for whole tree'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
404
        self._diff_label.set_alignment(0, 0)
405
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
406
        self._add_to_right_table(self._diff_label, 1, False)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
407
        self._diff_label.show()
408
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
409
        self._diff_view = DiffView()
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
410
        self._add_to_right_table(self._diff_view, 4, True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
411
        self._diff_view.show()
412
413
    def _construct_file_message(self):
414
        file_message_box = gtk.VBox()
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
415
        scroller = gtk.ScrolledWindow()
416
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
417
418
        self._file_message_text_view = gtk.TextView()
419
        scroller.add(self._file_message_text_view)
420
        scroller.show()
421
        scroller.set_shadow_type(gtk.SHADOW_IN)
422
        file_message_box.pack_start(scroller, expand=True, fill=True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
423
424
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
425
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
426
        self._file_message_text_view.set_accepts_tab(False)
427
        self._file_message_text_view.show()
428
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
429
        self._file_message_expander = gtk.Expander(_('Per File Message'))
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
430
        self._file_message_expander.add(file_message_box)
431
        file_message_box.show()
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
432
        self._add_to_right_table(self._file_message_expander, 1, False)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
433
        self._file_message_expander.show()
434
435
    def _construct_global_message(self):
436
        self._global_message_label = gtk.Label(_('Global Commit Message'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
437
        self._global_message_label.set_alignment(0, 0)
438
        self._right_pane_table.set_row_spacing(self._right_pane_table_row, 0)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
439
        self._add_to_right_table(self._global_message_label, 1, False)
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
440
        # Can we remove the spacing between the label and the box?
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
441
        self._global_message_label.show()
442
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
443
        scroller = gtk.ScrolledWindow()
444
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
445
446
        self._global_message_text_view = gtk.TextView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
447
        self._global_message_text_view.modify_font(pango.FontDescription("Monospace"))
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
448
        scroller.add(self._global_message_text_view)
449
        scroller.show()
450
        scroller.set_shadow_type(gtk.SHADOW_IN)
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
451
        self._add_to_right_table(scroller, 2, True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
452
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
453
        self._file_message_text_view.set_accepts_tab(False)
454
        self._global_message_text_view.show()
455
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
456
    def _on_treeview_files_cursor_changed(self, treeview):
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
457
        treeselection = treeview.get_selection()
458
        (model, iterable) = treeselection.get_selected()
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
459
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
460
        if iterable is not None:
461
            path, display_path = model.get(iterable, 1, 3) # Get the real_path attribute
462
            self._diff_label.set_text(_('Diff for ') + display_path)
463
            self._diff_view.show_diff([path])
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
464
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
465
    @staticmethod
466
    def _rev_to_pending_info(rev):
467
        """Get the information from a pending merge."""
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
468
        from bzrlib.osutils import format_date
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
469
470
        rev_dict = {}
471
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
472
        rev_dict['summary'] = rev.get_summary()
473
        rev_dict['date'] = format_date(rev.timestamp,
474
                                       rev.timezone or 0,
475
                                       'original', date_fmt="%Y-%m-%d",
476
                                       show_offset=False)
477
        rev_dict['revision_id'] = rev.revision_id
478
        return rev_dict
479
480
481
# class CommitDialog(gtk.Dialog):
482
#     """ New implementation of the Commit dialog. """
483
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
484
#         """ Initialize the Commit Dialog. """
485
#         gtk.Dialog.__init__(self, title="Commit - Olive",
486
#                                   parent=parent,
487
#                                   flags=0,
488
#                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
489
#         
490
#         # Get arguments
491
#         self.wt = wt
492
#         self.wtpath = wtpath
493
#         self.notbranch = notbranch
494
#         self.selected = selected
495
#         
496
#         # Set the delta
497
#         self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
498
#         self.delta = self.wt.changes_from(self.old_tree)
499
#         
500
#         # Get pending merges
501
#         self.pending = self._pending_merges(self.wt)
502
#         
503
#         # Do some preliminary checks
504
#         self._is_checkout = False
505
#         self._is_pending = False
506
#         if self.wt is None and not self.notbranch:
507
#             error_dialog(_('Directory does not have a working tree'),
508
#                          _('Operation aborted.'))
509
#             self.close()
510
#             return
511
# 
512
#         if self.notbranch:
513
#             error_dialog(_('Directory is not a branch'),
514
#                          _('You can perform this action only in a branch.'))
515
#             self.close()
516
#             return
517
#         else:
518
#             if self.wt.branch.get_bound_location() is not None:
519
#                 # we have a checkout, so the local commit checkbox must appear
520
#                 self._is_checkout = True
521
#             
522
#             if self.pending:
523
#                 # There are pending merges, file selection not supported
524
#                 self._is_pending = True
525
#         
526
#         # Create the widgets
527
#         # This is the main horizontal box, which is used to separate the commit
528
#         # info from the diff window.
529
#         self._hpane = gtk.HPaned()
530
#         self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
531
#         self._expander_files = gtk.Expander(_("File(s) to commit"))
532
#         self._vpaned_main = gtk.VPaned()
533
#         self._scrolledwindow_files = gtk.ScrolledWindow()
534
#         self._scrolledwindow_message = gtk.ScrolledWindow()
535
#         self._treeview_files = gtk.TreeView()
536
#         self._vbox_message = gtk.VBox()
537
#         self._label_message = gtk.Label(_("Commit message:"))
538
#         self._textview_message = gtk.TextView()
539
#         
540
#         if self._is_pending:
541
#             self._expander_merges = gtk.Expander(_("Pending merges"))
542
#             self._vpaned_list = gtk.VPaned()
543
#             self._scrolledwindow_merges = gtk.ScrolledWindow()
544
#             self._treeview_merges = gtk.TreeView()
545
# 
546
#         # Set callbacks
547
#         self._button_commit.connect('clicked', self._on_commit_clicked)
548
#         self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
549
#         self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
550
#         
551
#         # Set properties
552
#         self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
553
#                                               gtk.POLICY_AUTOMATIC)
554
#         self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
555
#                                                 gtk.POLICY_AUTOMATIC)
556
#         self._textview_message.modify_font(pango.FontDescription("Monospace"))
557
#         self.set_default_size(500, 500)
558
#         self._vpaned_main.set_position(200)
559
#         self._button_commit.set_flags(gtk.CAN_DEFAULT)
560
# 
561
#         if self._is_pending:
562
#             self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
563
#                                                    gtk.POLICY_AUTOMATIC)
564
#             self._treeview_files.set_sensitive(False)
565
#         
566
#         # Construct the dialog
567
#         self.action_area.pack_end(self._button_commit)
568
#         
569
#         self._scrolledwindow_files.add(self._treeview_files)
570
#         self._scrolledwindow_message.add(self._textview_message)
571
#         
572
#         self._expander_files.add(self._scrolledwindow_files)
573
#         
574
#         self._vbox_message.pack_start(self._label_message, False, False)
575
#         self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
576
#         
577
#         if self._is_pending:        
578
#             self._expander_merges.add(self._scrolledwindow_merges)
579
#             self._scrolledwindow_merges.add(self._treeview_merges)
580
#             self._vpaned_list.add1(self._expander_files)
581
#             self._vpaned_list.add2(self._expander_merges)
582
#             self._vpaned_main.add1(self._vpaned_list)
583
#         else:
584
#             self._vpaned_main.add1(self._expander_files)
585
# 
586
#         self._vpaned_main.add2(self._vbox_message)
587
#         
588
#         self._hpane.pack1(self._vpaned_main)
589
#         self.vbox.pack_start(self._hpane, expand=True, fill=True)
590
#         if self._is_checkout: 
591
#             self._check_local = gtk.CheckButton(_("_Only commit locally"),
592
#                                                 use_underline=True)
593
#             self.vbox.pack_start(self._check_local, False, False)
594
#             if have_dbus:
595
#                 bus = dbus.SystemBus()
596
#                 proxy_obj = bus.get_object('org.freedesktop.NetworkManager', 
597
#                               '/org/freedesktop/NetworkManager')
598
#                 dbus_iface = dbus.Interface(
599
#                         proxy_obj, 'org.freedesktop.NetworkManager')
600
#                 try:
601
#                     # 3 is the enum value for STATE_CONNECTED
602
#                     self._check_local.set_active(dbus_iface.state() != 3)
603
#                 except dbus.DBusException, e:
604
#                     # Silently drop errors. While DBus may be 
605
#                     # available, NetworkManager doesn't necessarily have to be
606
#                     mutter("unable to get networkmanager state: %r" % e)
607
#                 
608
#         # Create the file list
609
#         self._create_file_view()
610
#         # Create the pending merges
611
#         self._create_pending_merges()
612
#         self._create_diff_view()
613
#         
614
#         # Expand the corresponding expander
615
#         if self._is_pending:
616
#             self._expander_merges.set_expanded(True)
617
#         else:
618
#             self._expander_files.set_expanded(True)
619
#         
620
#         # Display dialog
621
#         self.vbox.show_all()
622
#         
623
#         # Default to Commit button
624
#         self._button_commit.grab_default()
625
#     
626
#     def _show_diff_view(self, treeview):
627
#         # FIXME: the diff window freezes for some reason
628
#         treeselection = treeview.get_selection()
629
#         (model, iter) = treeselection.get_selected()
630
# 
631
#         if iter is not None:
632
#             selected = model.get_value(iter, 3) # Get the real_path attribute
633
#             self._diff_display.show_diff([selected])
634
# 
635
#     def _on_treeview_files_cursor_changed(self, treeview):
636
#         self._show_diff_view(treeview)
637
#         
638
#     def _on_treeview_files_row_activated(self, treeview, path, view_column):
639
#         self._show_diff_view(treeview)
640
#     
641
#     @show_bzr_error
642
#     def _on_commit_clicked(self, button):
643
#         """ Commit button clicked handler. """
644
#         textbuffer = self._textview_message.get_buffer()
645
#         start, end = textbuffer.get_bounds()
646
#         message = textbuffer.get_text(start, end).decode('utf-8')
647
#         
648
#         if not self.pending:
649
#             specific_files = self._get_specific_files()
650
#         else:
651
#             specific_files = None
652
# 
653
#         if message == '':
654
#             response = question_dialog(_('Commit with an empty message?'),
655
#                                        _('You can describe your commit intent in the message.'))
656
#             if response == gtk.RESPONSE_NO:
657
#                 # Kindly give focus to message area
658
#                 self._textview_message.grab_focus()
659
#                 return
660
# 
661
#         if self._is_checkout:
662
#             local = self._check_local.get_active()
663
#         else:
664
#             local = False
665
# 
666
#         if list(self.wt.unknowns()) != []:
667
#             response = question_dialog(_("Commit with unknowns?"),
668
#                _("Unknown files exist in the working tree. Commit anyway?"))
669
#             if response == gtk.RESPONSE_NO:
670
#                 return
671
#         
672
#         try:
673
#             self.wt.commit(message,
674
#                        allow_pointless=False,
675
#                        strict=False,
676
#                        local=local,
677
#                        specific_files=specific_files)
678
#         except errors.PointlessCommit:
679
#             response = question_dialog(_('Commit with no changes?'),
680
#                                        _('There are no changes in the working tree.'))
681
#             if response == gtk.RESPONSE_YES:
682
#                 self.wt.commit(message,
683
#                                allow_pointless=True,
684
#                                strict=False,
685
#                                local=local,
686
#                                specific_files=specific_files)
687
#         self.response(gtk.RESPONSE_OK)
688
# 
689
#     def _pending_merges(self, wt):
690
#         """ Return a list of pending merges or None if there are none of them. """
691
#         parents = wt.get_parent_ids()
692
#         if len(parents) < 2:
693
#             return None
694
#         
695
#         import re
696
#         from bzrlib.osutils import format_date
697
#         
698
#         pending = parents[1:]
699
#         branch = wt.branch
700
#         last_revision = parents[0]
701
#         
702
#         if last_revision is not None:
703
#             try:
704
#                 ignore = set(branch.repository.get_ancestry(last_revision))
705
#             except errors.NoSuchRevision:
706
#                 # the last revision is a ghost : assume everything is new 
707
#                 # except for it
708
#                 ignore = set([None, last_revision])
709
#         else:
710
#             ignore = set([None])
711
#         
712
#         pm = []
713
#         for merge in pending:
714
#             ignore.add(merge)
715
#             try:
716
#                 m_revision = branch.repository.get_revision(merge)
717
#                 
718
#                 rev = {}
719
#                 rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
720
#                 rev['summary'] = m_revision.get_summary()
721
#                 rev['date'] = format_date(m_revision.timestamp,
722
#                                           m_revision.timezone or 0, 
723
#                                           'original', date_fmt="%Y-%m-%d",
724
#                                           show_offset=False)
725
#                 
726
#                 pm.append(rev)
727
#                 
728
#                 inner_merges = branch.repository.get_ancestry(merge)
729
#                 assert inner_merges[0] is None
730
#                 inner_merges.pop(0)
731
#                 inner_merges.reverse()
732
#                 for mmerge in inner_merges:
733
#                     if mmerge in ignore:
734
#                         continue
735
#                     mm_revision = branch.repository.get_revision(mmerge)
736
#                     
737
#                     rev = {}
738
#                     rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
739
#                     rev['summary'] = mm_revision.get_summary()
740
#                     rev['date'] = format_date(mm_revision.timestamp,
741
#                                               mm_revision.timezone or 0, 
742
#                                               'original', date_fmt="%Y-%m-%d",
743
#                                               show_offset=False)
744
#                 
745
#                     pm.append(rev)
746
#                     
747
#                     ignore.add(mmerge)
748
#             except errors.NoSuchRevision:
749
#                 print "DEBUG: NoSuchRevision:", merge
750
#         
751
#         return pm
752
# 
753
#     def _create_file_view(self):
754
#         self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
755
#                                          gobject.TYPE_STRING,    # [1] path to display
756
#                                          gobject.TYPE_STRING,    # [2] changes type
757
#                                          gobject.TYPE_STRING)    # [3] real path
758
#         self._treeview_files.set_model(self._file_store)
759
#         crt = gtk.CellRendererToggle()
760
#         crt.set_property("activatable", True)
761
#         crt.connect("toggled", self._toggle_commit, self._file_store)
762
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
763
#                                      crt, active=0))
764
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
765
#                                      gtk.CellRendererText(), text=1))
766
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
767
#                                      gtk.CellRendererText(), text=2))
768
# 
769
#         for path, id, kind in self.delta.added:
770
#             marker = osutils.kind_marker(kind)
771
#             if self.selected is not None:
772
#                 if path == os.path.join(self.wtpath, self.selected):
773
#                     self._file_store.append([ True, path+marker, _('added'), path ])
774
#                 else:
775
#                     self._file_store.append([ False, path+marker, _('added'), path ])
776
#             else:
777
#                 self._file_store.append([ True, path+marker, _('added'), path ])
778
# 
779
#         for path, id, kind in self.delta.removed:
780
#             marker = osutils.kind_marker(kind)
781
#             if self.selected is not None:
782
#                 if path == os.path.join(self.wtpath, self.selected):
783
#                     self._file_store.append([ True, path+marker, _('removed'), path ])
784
#                 else:
785
#                     self._file_store.append([ False, path+marker, _('removed'), path ])
786
#             else:
787
#                 self._file_store.append([ True, path+marker, _('removed'), path ])
788
# 
789
#         for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
790
#             marker = osutils.kind_marker(kind)
791
#             if text_modified or meta_modified:
792
#                 changes = _('renamed and modified')
793
#             else:
794
#                 changes = _('renamed')
795
#             if self.selected is not None:
796
#                 if newpath == os.path.join(self.wtpath, self.selected):
797
#                     self._file_store.append([ True,
798
#                                               oldpath+marker + '  =>  ' + newpath+marker,
799
#                                               changes,
800
#                                               newpath
801
#                                             ])
802
#                 else:
803
#                     self._file_store.append([ False,
804
#                                               oldpath+marker + '  =>  ' + newpath+marker,
805
#                                               changes,
806
#                                               newpath
807
#                                             ])
808
#             else:
809
#                 self._file_store.append([ True,
810
#                                           oldpath+marker + '  =>  ' + newpath+marker,
811
#                                           changes,
812
#                                           newpath
813
#                                         ])
814
# 
815
#         for path, id, kind, text_modified, meta_modified in self.delta.modified:
816
#             marker = osutils.kind_marker(kind)
817
#             if self.selected is not None:
818
#                 if path == os.path.join(self.wtpath, self.selected):
819
#                     self._file_store.append([ True, path+marker, _('modified'), path ])
820
#                 else:
821
#                     self._file_store.append([ False, path+marker, _('modified'), path ])
822
#             else:
823
#                 self._file_store.append([ True, path+marker, _('modified'), path ])
824
#     
825
#     def _create_pending_merges(self):
826
#         if not self.pending:
827
#             return
828
#         
829
#         liststore = gtk.ListStore(gobject.TYPE_STRING,
830
#                                   gobject.TYPE_STRING,
831
#                                   gobject.TYPE_STRING)
832
#         self._treeview_merges.set_model(liststore)
833
#         
834
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
835
#                                             gtk.CellRendererText(), text=0))
836
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
837
#                                             gtk.CellRendererText(), text=1))
838
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
839
#                                             gtk.CellRendererText(), text=2))
840
#         
841
#         for item in self.pending:
842
#             liststore.append([ item['date'],
843
#                                item['committer'],
844
#                                item['summary'] ])
845
#     
846
# 
847
#     def _create_diff_view(self):
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
848
#         from diff import DiffView
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
849
# 
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
850
#         self._diff_display = DiffView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
851
#         self._diff_display.set_trees(self.wt, self.wt.basis_tree())
852
#         self._diff_display.show_diff(None)
853
#         self._diff_display.show()
854
#         self._hpane.pack2(self._diff_display)
855
# 
856
#     def _get_specific_files(self):
857
#         ret = []
858
#         it = self._file_store.get_iter_first()
859
#         while it:
860
#             if self._file_store.get_value(it, 0):
861
#                 # get real path from hidden column 3
862
#                 ret.append(self._file_store.get_value(it, 3))
863
#             it = self._file_store.iter_next(it)
864
# 
865
#         return ret
866
#     
867
#     def _toggle_commit(self, cell, path, model):
868
#         model[path][0] = not model[path][0]
869
#         return