/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.20 by John Arbash Meinel
We always select the All Files record in the files view,
124
        self._fill_in_diff()
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
125
        self._fill_in_files()
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
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
172
        # The first entry is always the 'whole tree'
173
        store.append([None, None, True, 'All Files', ''])
278.1.16 by John Arbash Meinel
Implement the file changes list on top of _iter_changes rather than
174
        # should we pass specific_files?
175
        self._wt.lock_read()
176
        self._basis_tree.lock_read()
177
        try:
178
            for (file_id, paths, changed_content, versioned, parent_ids, names,
179
                 kinds, executables) in self._wt._iter_changes(self._basis_tree):
180
181
                # Skip the root entry.
182
                if parent_ids == (None, None):
183
                    continue
184
185
                change_type = None
186
                if kinds[0] is None:
187
                    source_marker = ''
188
                else:
189
                    source_marker = osutils.kind_marker(kinds[0])
190
                if kinds[1] is None:
191
                    assert kinds[0] is not None
192
                    marker = osutils.kind_marker(kinds[0])
193
                else:
194
                    marker = osutils.kind_marker(kinds[1])
195
196
                real_path = paths[1]
197
                if real_path is None:
198
                    real_path = paths[0]
199
                assert real_path is not None
200
                display_path = real_path + marker
201
202
                present_source = versioned[0] and kinds[0] is not None
203
                present_target = versioned[1] and kinds[1] is not None
204
205
                if present_source != present_target:
206
                    if present_target:
207
                        change_type = added
208
                    else:
209
                        change_type = removed
210
                elif names[0] != names[1] or parent_ids[0] != parent_ids[1]:
211
                    # Renamed
212
                    if changed_content or executables[0] != executables[1]:
213
                        # and modified
214
                        change_type = renamed_and_modified
215
                    else:
216
                        change_type = renamed
217
                    display_path = (paths[0] + source_marker
218
                                    + ' => ' + paths[1] + marker)
219
                elif kinds[0] != kinds[1]:
220
                    change_type = kind_changed
221
                    display_path = (paths[0] + source_marker
222
                                    + ' => ' + paths[1] + marker)
223
                elif changed_content is True or executables[0] != executables[1]:
224
                    change_type = modified
225
                else:
226
                    assert False, "How did we get here?"
227
228
                store.append([file_id, real_path, True, display_path, change_type])
229
        finally:
230
            self._basis_tree.unlock()
231
            self._wt.unlock()
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
232
233
        self._treeview_files.set_model(store)
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
234
        self._treeview_files.set_cursor(0)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
235
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
236
    def _fill_in_diff(self):
237
        self._diff_view.set_trees(self._wt, self._basis_tree)
238
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
239
    def _compute_delta(self):
240
        self._delta = self._wt.changes_from(self._basis_tree)
241
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
242
    def construct(self):
243
        """Build up the dialog widgets."""
244
        # The primary pane which splits it into left and right (adjustable)
245
        # sections.
278.1.4 by John Arbash Meinel
Just playing around.
246
        self._hpane = gtk.HPaned()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
247
248
        self._construct_left_pane()
249
        self._construct_right_pane()
250
251
        self.vbox.pack_start(self._hpane)
252
        self._hpane.show()
253
        self.set_focus(self._global_message_text_view)
254
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
255
        # This seems like a reasonable default, we might like it to
256
        # be a bit wider, so that by default we can fit an 80-line diff in the
257
        # diff window.
258
        # Alternatively, we should be saving the last position/size rather than
259
        # setting it to a fixed value every time we start up.
260
        screen = self.get_screen()
261
        monitor = 0 # We would like it to be the monitor we are going to
262
                    # display on, but I don't know how to figure that out
263
                    # Only really useful for freaks like me that run dual
264
                    # monitor, with different sizes on the monitors
265
        monitor_rect = screen.get_monitor_geometry(monitor)
266
        width = int(monitor_rect.width * 0.66)
267
        height = int(monitor_rect.height * 0.66)
268
        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
269
        self._hpane.set_position(300)
270
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
271
    def _construct_left_pane(self):
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
272
        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.
273
        self._construct_file_list()
274
        self._construct_pending_list()
275
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
276
        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.
277
        self._left_pane_box.show()
278
279
    def _construct_right_pane(self):
280
        # TODO: I really want to make it so the diff view gets more space than
281
        # the global commit message, and the per-file commit message gets even
282
        # less. When I did it with wxGlade, I set it to 4 for diff, 2 for
283
        # commit, and 1 for file commit, and it looked good. But I don't seem
284
        # to have a way to do that with the gtk boxes... :( (Which is extra
285
        # 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.
286
        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.
287
        self._right_pane_table.set_row_spacings(5)
288
        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.
289
        self._right_pane_table_row = 0
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
290
        self._construct_diff_view()
291
        self._construct_file_message()
292
        self._construct_global_message()
293
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
294
        self._right_pane_table.show()
295
        self._hpane.pack2(self._right_pane_table, resize=True, shrink=True)
296
297
    def _add_to_right_table(self, widget, weight, expanding=False):
298
        """Add another widget to the table
299
300
        :param widget: The object to add
301
        :param weight: How many rows does this widget get to request
302
        :param expanding: Should expand|fill|shrink be set?
303
        """
304
        end_row = self._right_pane_table_row + weight
305
        options = 0
306
        expand_opts = gtk.EXPAND | gtk.FILL | gtk.SHRINK
307
        if expanding:
308
            options = expand_opts
309
        self._right_pane_table.attach(widget, 0, 1,
310
                                      self._right_pane_table_row, end_row,
311
                                      xoptions=expand_opts, yoptions=options)
312
        self._right_pane_table_row = end_row
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
313
314
    def _construct_file_list(self):
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
315
        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.
316
        file_label = gtk.Label(_('Files'))
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
317
        file_label.show()
318
        self._files_box.pack_start(file_label, expand=False)
319
320
        scroller = gtk.ScrolledWindow()
321
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
322
        self._treeview_files = gtk.TreeView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
323
        self._treeview_files.show()
324
        scroller.add(self._treeview_files)
325
        scroller.show()
326
        scroller.set_shadow_type(gtk.SHADOW_IN)
327
        self._files_box.pack_start(scroller,
328
                                   expand=True, fill=True)
329
        self._files_box.show()
330
        self._left_pane_box.pack_start(self._files_box)
331
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
332
        liststore = gtk.ListStore(
333
            gobject.TYPE_STRING,  # [0] file_id
334
            gobject.TYPE_STRING,  # [1] real path
335
            gobject.TYPE_BOOLEAN, # [2] checkbox
336
            gobject.TYPE_STRING,  # [3] display path
337
            gobject.TYPE_STRING,  # [4] changes type
338
            )
339
        self._files_store = liststore
340
        self._treeview_files.set_model(liststore)
341
        crt = gtk.CellRendererToggle()
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
342
        crt.set_active(not bool(self._pending))
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
343
        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.
344
        if self._pending:
345
            name = _('Commit*')
346
        else:
347
            name = _('Commit')
348
        self._treeview_files.append_column(gtk.TreeViewColumn(name,
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
349
                                           crt, active=2))
350
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
351
                                           gtk.CellRendererText(), text=3))
352
        self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
353
                                           gtk.CellRendererText(), text=4))
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
354
        self._treeview_files.connect('cursor-changed',
355
                                     self._on_treeview_files_cursor_changed)
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
356
357
    def _toggle_commit(self, cell, path, model):
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
358
        if model[path][0] is None: # No file_id means 'All Files'
359
            new_val = not model[path][2]
360
            for node in model:
361
                node[2] = new_val
362
        else:
363
            model[path][2] = not model[path][2]
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
364
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
365
    def _construct_pending_list(self):
366
        # Pending information defaults to hidden, we put it all in 1 box, so
367
        # that we can show/hide all of them at once
368
        self._pending_box = gtk.VBox()
369
        self._pending_box.hide()
370
371
        pending_message = gtk.Label()
372
        pending_message.set_markup(
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
373
            _('<i>* Cannot select specific files when merging</i>'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
374
        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.
375
        pending_message.show()
376
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
377
        pending_label = gtk.Label(_('Pending Revisions'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
378
        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.
379
        pending_label.show()
380
381
        scroller = gtk.ScrolledWindow()
382
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
383
        self._treeview_pending = gtk.TreeView()
384
        scroller.add(self._treeview_pending)
385
        scroller.show()
386
        scroller.set_shadow_type(gtk.SHADOW_IN)
387
        self._pending_box.pack_start(scroller,
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
388
                                     expand=True, fill=True, padding=5)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
389
        self._treeview_pending.show()
390
        self._left_pane_box.pack_start(self._pending_box)
391
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
392
        liststore = gtk.ListStore(gobject.TYPE_STRING, # revision_id
393
                                  gobject.TYPE_STRING, # date
394
                                  gobject.TYPE_STRING, # committer
395
                                  gobject.TYPE_STRING, # summary
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
396
                                 )
278.1.15 by John Arbash Meinel
Hook up the list of modified files.
397
        self._pending_store = liststore
278.1.14 by John Arbash Meinel
Tests that we fill out the pending list correctly.
398
        self._treeview_pending.set_model(liststore)
399
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Date'),
400
                                             gtk.CellRendererText(), text=1))
401
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Committer'),
402
                                             gtk.CellRendererText(), text=2))
403
        self._treeview_pending.append_column(gtk.TreeViewColumn(_('Summary'),
404
                                             gtk.CellRendererText(), text=3))
405
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
406
    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.
407
        from diff import DiffView
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
408
409
        self._diff_label = gtk.Label(_('Diff for whole tree'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
410
        self._diff_label.set_alignment(0, 0)
411
        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.
412
        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.
413
        self._diff_label.show()
414
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
415
        self._diff_view = DiffView()
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
416
        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.
417
        self._diff_view.show()
418
419
    def _construct_file_message(self):
420
        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.
421
        scroller = gtk.ScrolledWindow()
422
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
423
424
        self._file_message_text_view = gtk.TextView()
425
        scroller.add(self._file_message_text_view)
426
        scroller.show()
427
        scroller.set_shadow_type(gtk.SHADOW_IN)
428
        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.
429
430
        self._file_message_text_view.modify_font(pango.FontDescription("Monospace"))
431
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
432
        self._file_message_text_view.set_accepts_tab(False)
433
        self._file_message_text_view.show()
434
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
435
        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.
436
        self._file_message_expander.add(file_message_box)
437
        file_message_box.show()
278.1.10 by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table.
438
        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.
439
        self._file_message_expander.show()
440
441
    def _construct_global_message(self):
442
        self._global_message_label = gtk.Label(_('Global Commit Message'))
278.1.11 by John Arbash Meinel
Worked out the rest of the spacing.
443
        self._global_message_label.set_alignment(0, 0)
444
        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.
445
        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.
446
        # 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.
447
        self._global_message_label.show()
448
278.1.9 by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly.
449
        scroller = gtk.ScrolledWindow()
450
        scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
451
452
        self._global_message_text_view = gtk.TextView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
453
        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.
454
        scroller.add(self._global_message_text_view)
455
        scroller.show()
456
        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.
457
        self._add_to_right_table(scroller, 2, True)
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
458
        self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD)
459
        self._file_message_text_view.set_accepts_tab(False)
460
        self._global_message_text_view.show()
461
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
462
    def _on_treeview_files_cursor_changed(self, treeview):
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
463
        treeselection = treeview.get_selection()
464
        (model, iterable) = treeselection.get_selected()
278.1.17 by John Arbash Meinel
Add a * reference for why you can't change the commit selection.
465
278.1.18 by John Arbash Meinel
Start checking the diff view is correct.
466
        if iterable is not None:
467
            path, display_path = model.get(iterable, 1, 3) # Get the real_path attribute
468
            self._diff_label.set_text(_('Diff for ') + display_path)
278.1.20 by John Arbash Meinel
We always select the All Files record in the files view,
469
            if path is None:
470
                self._diff_view.show_diff(None)
471
            else:
472
                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.
473
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
474
    @staticmethod
475
    def _rev_to_pending_info(rev):
476
        """Get the information from a pending merge."""
126.1.1 by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade).
477
        from bzrlib.osutils import format_date
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
478
479
        rev_dict = {}
480
        rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ')
481
        rev_dict['summary'] = rev.get_summary()
482
        rev_dict['date'] = format_date(rev.timestamp,
483
                                       rev.timezone or 0,
484
                                       'original', date_fmt="%Y-%m-%d",
485
                                       show_offset=False)
486
        rev_dict['revision_id'] = rev.revision_id
487
        return rev_dict
488
489
490
# class CommitDialog(gtk.Dialog):
491
#     """ New implementation of the Commit dialog. """
492
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
493
#         """ Initialize the Commit Dialog. """
494
#         gtk.Dialog.__init__(self, title="Commit - Olive",
495
#                                   parent=parent,
496
#                                   flags=0,
497
#                                   buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
498
#         
499
#         # Get arguments
500
#         self.wt = wt
501
#         self.wtpath = wtpath
502
#         self.notbranch = notbranch
503
#         self.selected = selected
504
#         
505
#         # Set the delta
506
#         self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
507
#         self.delta = self.wt.changes_from(self.old_tree)
508
#         
509
#         # Get pending merges
510
#         self.pending = self._pending_merges(self.wt)
511
#         
512
#         # Do some preliminary checks
513
#         self._is_checkout = False
514
#         self._is_pending = False
515
#         if self.wt is None and not self.notbranch:
516
#             error_dialog(_('Directory does not have a working tree'),
517
#                          _('Operation aborted.'))
518
#             self.close()
519
#             return
520
# 
521
#         if self.notbranch:
522
#             error_dialog(_('Directory is not a branch'),
523
#                          _('You can perform this action only in a branch.'))
524
#             self.close()
525
#             return
526
#         else:
527
#             if self.wt.branch.get_bound_location() is not None:
528
#                 # we have a checkout, so the local commit checkbox must appear
529
#                 self._is_checkout = True
530
#             
531
#             if self.pending:
532
#                 # There are pending merges, file selection not supported
533
#                 self._is_pending = True
534
#         
535
#         # Create the widgets
536
#         # This is the main horizontal box, which is used to separate the commit
537
#         # info from the diff window.
538
#         self._hpane = gtk.HPaned()
539
#         self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
540
#         self._expander_files = gtk.Expander(_("File(s) to commit"))
541
#         self._vpaned_main = gtk.VPaned()
542
#         self._scrolledwindow_files = gtk.ScrolledWindow()
543
#         self._scrolledwindow_message = gtk.ScrolledWindow()
544
#         self._treeview_files = gtk.TreeView()
545
#         self._vbox_message = gtk.VBox()
546
#         self._label_message = gtk.Label(_("Commit message:"))
547
#         self._textview_message = gtk.TextView()
548
#         
549
#         if self._is_pending:
550
#             self._expander_merges = gtk.Expander(_("Pending merges"))
551
#             self._vpaned_list = gtk.VPaned()
552
#             self._scrolledwindow_merges = gtk.ScrolledWindow()
553
#             self._treeview_merges = gtk.TreeView()
554
# 
555
#         # Set callbacks
556
#         self._button_commit.connect('clicked', self._on_commit_clicked)
557
#         self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
558
#         self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
559
#         
560
#         # Set properties
561
#         self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
562
#                                               gtk.POLICY_AUTOMATIC)
563
#         self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
564
#                                                 gtk.POLICY_AUTOMATIC)
565
#         self._textview_message.modify_font(pango.FontDescription("Monospace"))
566
#         self.set_default_size(500, 500)
567
#         self._vpaned_main.set_position(200)
568
#         self._button_commit.set_flags(gtk.CAN_DEFAULT)
569
# 
570
#         if self._is_pending:
571
#             self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
572
#                                                    gtk.POLICY_AUTOMATIC)
573
#             self._treeview_files.set_sensitive(False)
574
#         
575
#         # Construct the dialog
576
#         self.action_area.pack_end(self._button_commit)
577
#         
578
#         self._scrolledwindow_files.add(self._treeview_files)
579
#         self._scrolledwindow_message.add(self._textview_message)
580
#         
581
#         self._expander_files.add(self._scrolledwindow_files)
582
#         
583
#         self._vbox_message.pack_start(self._label_message, False, False)
584
#         self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
585
#         
586
#         if self._is_pending:        
587
#             self._expander_merges.add(self._scrolledwindow_merges)
588
#             self._scrolledwindow_merges.add(self._treeview_merges)
589
#             self._vpaned_list.add1(self._expander_files)
590
#             self._vpaned_list.add2(self._expander_merges)
591
#             self._vpaned_main.add1(self._vpaned_list)
592
#         else:
593
#             self._vpaned_main.add1(self._expander_files)
594
# 
595
#         self._vpaned_main.add2(self._vbox_message)
596
#         
597
#         self._hpane.pack1(self._vpaned_main)
598
#         self.vbox.pack_start(self._hpane, expand=True, fill=True)
599
#         if self._is_checkout: 
600
#             self._check_local = gtk.CheckButton(_("_Only commit locally"),
601
#                                                 use_underline=True)
602
#             self.vbox.pack_start(self._check_local, False, False)
603
#             if have_dbus:
604
#                 bus = dbus.SystemBus()
605
#                 proxy_obj = bus.get_object('org.freedesktop.NetworkManager', 
606
#                               '/org/freedesktop/NetworkManager')
607
#                 dbus_iface = dbus.Interface(
608
#                         proxy_obj, 'org.freedesktop.NetworkManager')
609
#                 try:
610
#                     # 3 is the enum value for STATE_CONNECTED
611
#                     self._check_local.set_active(dbus_iface.state() != 3)
612
#                 except dbus.DBusException, e:
613
#                     # Silently drop errors. While DBus may be 
614
#                     # available, NetworkManager doesn't necessarily have to be
615
#                     mutter("unable to get networkmanager state: %r" % e)
616
#                 
617
#         # Create the file list
618
#         self._create_file_view()
619
#         # Create the pending merges
620
#         self._create_pending_merges()
621
#         self._create_diff_view()
622
#         
623
#         # Expand the corresponding expander
624
#         if self._is_pending:
625
#             self._expander_merges.set_expanded(True)
626
#         else:
627
#             self._expander_files.set_expanded(True)
628
#         
629
#         # Display dialog
630
#         self.vbox.show_all()
631
#         
632
#         # Default to Commit button
633
#         self._button_commit.grab_default()
634
#     
635
#     def _show_diff_view(self, treeview):
636
#         # FIXME: the diff window freezes for some reason
637
#         treeselection = treeview.get_selection()
638
#         (model, iter) = treeselection.get_selected()
639
# 
640
#         if iter is not None:
641
#             selected = model.get_value(iter, 3) # Get the real_path attribute
642
#             self._diff_display.show_diff([selected])
643
# 
644
#     def _on_treeview_files_cursor_changed(self, treeview):
645
#         self._show_diff_view(treeview)
646
#         
647
#     def _on_treeview_files_row_activated(self, treeview, path, view_column):
648
#         self._show_diff_view(treeview)
649
#     
650
#     @show_bzr_error
651
#     def _on_commit_clicked(self, button):
652
#         """ Commit button clicked handler. """
653
#         textbuffer = self._textview_message.get_buffer()
654
#         start, end = textbuffer.get_bounds()
655
#         message = textbuffer.get_text(start, end).decode('utf-8')
656
#         
657
#         if not self.pending:
658
#             specific_files = self._get_specific_files()
659
#         else:
660
#             specific_files = None
661
# 
662
#         if message == '':
663
#             response = question_dialog(_('Commit with an empty message?'),
664
#                                        _('You can describe your commit intent in the message.'))
665
#             if response == gtk.RESPONSE_NO:
666
#                 # Kindly give focus to message area
667
#                 self._textview_message.grab_focus()
668
#                 return
669
# 
670
#         if self._is_checkout:
671
#             local = self._check_local.get_active()
672
#         else:
673
#             local = False
674
# 
675
#         if list(self.wt.unknowns()) != []:
676
#             response = question_dialog(_("Commit with unknowns?"),
677
#                _("Unknown files exist in the working tree. Commit anyway?"))
678
#             if response == gtk.RESPONSE_NO:
679
#                 return
680
#         
681
#         try:
682
#             self.wt.commit(message,
683
#                        allow_pointless=False,
684
#                        strict=False,
685
#                        local=local,
686
#                        specific_files=specific_files)
687
#         except errors.PointlessCommit:
688
#             response = question_dialog(_('Commit with no changes?'),
689
#                                        _('There are no changes in the working tree.'))
690
#             if response == gtk.RESPONSE_YES:
691
#                 self.wt.commit(message,
692
#                                allow_pointless=True,
693
#                                strict=False,
694
#                                local=local,
695
#                                specific_files=specific_files)
696
#         self.response(gtk.RESPONSE_OK)
697
# 
698
#     def _pending_merges(self, wt):
699
#         """ Return a list of pending merges or None if there are none of them. """
700
#         parents = wt.get_parent_ids()
701
#         if len(parents) < 2:
702
#             return None
703
#         
704
#         import re
705
#         from bzrlib.osutils import format_date
706
#         
707
#         pending = parents[1:]
708
#         branch = wt.branch
709
#         last_revision = parents[0]
710
#         
711
#         if last_revision is not None:
712
#             try:
713
#                 ignore = set(branch.repository.get_ancestry(last_revision))
714
#             except errors.NoSuchRevision:
715
#                 # the last revision is a ghost : assume everything is new 
716
#                 # except for it
717
#                 ignore = set([None, last_revision])
718
#         else:
719
#             ignore = set([None])
720
#         
721
#         pm = []
722
#         for merge in pending:
723
#             ignore.add(merge)
724
#             try:
725
#                 m_revision = branch.repository.get_revision(merge)
726
#                 
727
#                 rev = {}
728
#                 rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
729
#                 rev['summary'] = m_revision.get_summary()
730
#                 rev['date'] = format_date(m_revision.timestamp,
731
#                                           m_revision.timezone or 0, 
732
#                                           'original', date_fmt="%Y-%m-%d",
733
#                                           show_offset=False)
734
#                 
735
#                 pm.append(rev)
736
#                 
737
#                 inner_merges = branch.repository.get_ancestry(merge)
738
#                 assert inner_merges[0] is None
739
#                 inner_merges.pop(0)
740
#                 inner_merges.reverse()
741
#                 for mmerge in inner_merges:
742
#                     if mmerge in ignore:
743
#                         continue
744
#                     mm_revision = branch.repository.get_revision(mmerge)
745
#                     
746
#                     rev = {}
747
#                     rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
748
#                     rev['summary'] = mm_revision.get_summary()
749
#                     rev['date'] = format_date(mm_revision.timestamp,
750
#                                               mm_revision.timezone or 0, 
751
#                                               'original', date_fmt="%Y-%m-%d",
752
#                                               show_offset=False)
753
#                 
754
#                     pm.append(rev)
755
#                     
756
#                     ignore.add(mmerge)
757
#             except errors.NoSuchRevision:
758
#                 print "DEBUG: NoSuchRevision:", merge
759
#         
760
#         return pm
761
# 
762
#     def _create_file_view(self):
763
#         self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,   # [0] checkbox
764
#                                          gobject.TYPE_STRING,    # [1] path to display
765
#                                          gobject.TYPE_STRING,    # [2] changes type
766
#                                          gobject.TYPE_STRING)    # [3] real path
767
#         self._treeview_files.set_model(self._file_store)
768
#         crt = gtk.CellRendererToggle()
769
#         crt.set_property("activatable", True)
770
#         crt.connect("toggled", self._toggle_commit, self._file_store)
771
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
772
#                                      crt, active=0))
773
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
774
#                                      gtk.CellRendererText(), text=1))
775
#         self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
776
#                                      gtk.CellRendererText(), text=2))
777
# 
778
#         for path, id, kind in self.delta.added:
779
#             marker = osutils.kind_marker(kind)
780
#             if self.selected is not None:
781
#                 if path == os.path.join(self.wtpath, self.selected):
782
#                     self._file_store.append([ True, path+marker, _('added'), path ])
783
#                 else:
784
#                     self._file_store.append([ False, path+marker, _('added'), path ])
785
#             else:
786
#                 self._file_store.append([ True, path+marker, _('added'), path ])
787
# 
788
#         for path, id, kind in self.delta.removed:
789
#             marker = osutils.kind_marker(kind)
790
#             if self.selected is not None:
791
#                 if path == os.path.join(self.wtpath, self.selected):
792
#                     self._file_store.append([ True, path+marker, _('removed'), path ])
793
#                 else:
794
#                     self._file_store.append([ False, path+marker, _('removed'), path ])
795
#             else:
796
#                 self._file_store.append([ True, path+marker, _('removed'), path ])
797
# 
798
#         for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
799
#             marker = osutils.kind_marker(kind)
800
#             if text_modified or meta_modified:
801
#                 changes = _('renamed and modified')
802
#             else:
803
#                 changes = _('renamed')
804
#             if self.selected is not None:
805
#                 if newpath == os.path.join(self.wtpath, self.selected):
806
#                     self._file_store.append([ True,
807
#                                               oldpath+marker + '  =>  ' + newpath+marker,
808
#                                               changes,
809
#                                               newpath
810
#                                             ])
811
#                 else:
812
#                     self._file_store.append([ False,
813
#                                               oldpath+marker + '  =>  ' + newpath+marker,
814
#                                               changes,
815
#                                               newpath
816
#                                             ])
817
#             else:
818
#                 self._file_store.append([ True,
819
#                                           oldpath+marker + '  =>  ' + newpath+marker,
820
#                                           changes,
821
#                                           newpath
822
#                                         ])
823
# 
824
#         for path, id, kind, text_modified, meta_modified in self.delta.modified:
825
#             marker = osutils.kind_marker(kind)
826
#             if self.selected is not None:
827
#                 if path == os.path.join(self.wtpath, self.selected):
828
#                     self._file_store.append([ True, path+marker, _('modified'), path ])
829
#                 else:
830
#                     self._file_store.append([ False, path+marker, _('modified'), path ])
831
#             else:
832
#                 self._file_store.append([ True, path+marker, _('modified'), path ])
833
#     
834
#     def _create_pending_merges(self):
835
#         if not self.pending:
836
#             return
837
#         
838
#         liststore = gtk.ListStore(gobject.TYPE_STRING,
839
#                                   gobject.TYPE_STRING,
840
#                                   gobject.TYPE_STRING)
841
#         self._treeview_merges.set_model(liststore)
842
#         
843
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
844
#                                             gtk.CellRendererText(), text=0))
845
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
846
#                                             gtk.CellRendererText(), text=1))
847
#         self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
848
#                                             gtk.CellRendererText(), text=2))
849
#         
850
#         for item in self.pending:
851
#             liststore.append([ item['date'],
852
#                                item['committer'],
853
#                                item['summary'] ])
854
#     
855
# 
856
#     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.
857
#         from diff import DiffView
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
858
# 
278.1.12 by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names.
859
#         self._diff_display = DiffView()
278.1.5 by John Arbash Meinel
Starting to flesh out the dialog with actual windows.
860
#         self._diff_display.set_trees(self.wt, self.wt.basis_tree())
861
#         self._diff_display.show_diff(None)
862
#         self._diff_display.show()
863
#         self._hpane.pack2(self._diff_display)
864
# 
865
#     def _get_specific_files(self):
866
#         ret = []
867
#         it = self._file_store.get_iter_first()
868
#         while it:
869
#             if self._file_store.get_value(it, 0):
870
#                 # get real path from hidden column 3
871
#                 ret.append(self._file_store.get_value(it, 3))
872
#             it = self._file_store.iter_next(it)
873
# 
874
#         return ret
875
#     
876
#     def _toggle_commit(self, cell, path, model):
877
#         model[path][0] = not model[path][0]
878
#         return