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): |
|
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 |
|
108 |
||
109 |
self.setup_params() |
|
110 |
self.construct() |
|
111 |
self.set_default_size(800, 600) |
|
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
112 |
self.fill_in_data() |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
113 |
|
114 |
def setup_params(self): |
|
115 |
"""Setup the member variables for state.""" |
|
116 |
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. |
117 |
self._delta = None |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
118 |
self._pending = pending_revisions(self._wt) |
119 |
||
120 |
self._is_checkout = (self._wt.branch.get_bound_location() is not None) |
|
121 |
||
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
122 |
def fill_in_data(self): |
123 |
# Now that we are built, handle changes to the view based on the state
|
|
124 |
self._fill_in_pending() |
|
125 |
||
126 |
def _fill_in_pending(self): |
|
127 |
if not self._pending: |
|
128 |
self._pending_box.hide() |
|
129 |
return
|
|
130 |
||
131 |
# TODO: We'd really prefer this to be a nested list
|
|
132 |
for rev, children in self._pending: |
|
133 |
rev_info = self._rev_to_pending_info(rev) |
|
134 |
self._pending_liststore.append([ |
|
135 |
rev_info['revision_id'], |
|
136 |
rev_info['date'], |
|
137 |
rev_info['committer'], |
|
138 |
rev_info['summary'], |
|
139 |
])
|
|
140 |
for child in children: |
|
141 |
rev_info = self._rev_to_pending_info(child) |
|
142 |
self._pending_liststore.append([ |
|
143 |
rev_info['revision_id'], |
|
144 |
rev_info['date'], |
|
145 |
rev_info['committer'], |
|
146 |
rev_info['summary'], |
|
147 |
])
|
|
148 |
self._pending_box.show() |
|
149 |
||
278.1.12
by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names. |
150 |
def _compute_delta(self): |
151 |
self._delta = self._wt.changes_from(self._basis_tree) |
|
152 |
||
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
153 |
def construct(self): |
154 |
"""Build up the dialog widgets.""" |
|
155 |
# The primary pane which splits it into left and right (adjustable)
|
|
156 |
# sections.
|
|
278.1.4
by John Arbash Meinel
Just playing around. |
157 |
self._hpane = gtk.HPaned() |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
158 |
|
159 |
self._construct_left_pane() |
|
160 |
self._construct_right_pane() |
|
161 |
||
162 |
self.vbox.pack_start(self._hpane) |
|
163 |
self._hpane.show() |
|
164 |
self.set_focus(self._global_message_text_view) |
|
165 |
||
166 |
def _construct_left_pane(self): |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
167 |
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. |
168 |
self._construct_file_list() |
169 |
self._construct_pending_list() |
|
170 |
||
171 |
self._hpane.pack1(self._left_pane_box, resize=False, shrink=True) |
|
172 |
self._left_pane_box.show() |
|
173 |
||
174 |
def _construct_right_pane(self): |
|
175 |
# TODO: I really want to make it so the diff view gets more space than
|
|
176 |
# the global commit message, and the per-file commit message gets even
|
|
177 |
# less. When I did it with wxGlade, I set it to 4 for diff, 2 for
|
|
178 |
# commit, and 1 for file commit, and it looked good. But I don't seem
|
|
179 |
# to have a way to do that with the gtk boxes... :( (Which is extra
|
|
180 |
# 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. |
181 |
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. |
182 |
self._right_pane_table.set_row_spacings(5) |
183 |
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. |
184 |
self._right_pane_table_row = 0 |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
185 |
self._construct_diff_view() |
186 |
self._construct_file_message() |
|
187 |
self._construct_global_message() |
|
188 |
||
278.1.10
by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table. |
189 |
self._right_pane_table.show() |
190 |
self._hpane.pack2(self._right_pane_table, resize=True, shrink=True) |
|
191 |
||
192 |
def _add_to_right_table(self, widget, weight, expanding=False): |
|
193 |
"""Add another widget to the table |
|
194 |
||
195 |
:param widget: The object to add
|
|
196 |
:param weight: How many rows does this widget get to request
|
|
197 |
:param expanding: Should expand|fill|shrink be set?
|
|
198 |
"""
|
|
199 |
end_row = self._right_pane_table_row + weight |
|
200 |
options = 0 |
|
201 |
expand_opts = gtk.EXPAND | gtk.FILL | gtk.SHRINK |
|
202 |
if expanding: |
|
203 |
options = expand_opts |
|
204 |
self._right_pane_table.attach(widget, 0, 1, |
|
205 |
self._right_pane_table_row, end_row, |
|
206 |
xoptions=expand_opts, yoptions=options) |
|
207 |
self._right_pane_table_row = end_row |
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
208 |
|
209 |
def _construct_file_list(self): |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
210 |
self._files_box = gtk.VBox(homogeneous=False, spacing=0) |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
211 |
file_label = gtk.Label() |
212 |
file_label.set_markup(_('<b>Files</b>')) |
|
213 |
file_label.show() |
|
214 |
self._files_box.pack_start(file_label, expand=False) |
|
215 |
||
216 |
scroller = gtk.ScrolledWindow() |
|
217 |
scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|
126.1.1
by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade). |
218 |
self._treeview_files = gtk.TreeView() |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
219 |
self._treeview_files.show() |
220 |
scroller.add(self._treeview_files) |
|
221 |
scroller.show() |
|
222 |
scroller.set_shadow_type(gtk.SHADOW_IN) |
|
223 |
self._files_box.pack_start(scroller, |
|
224 |
expand=True, fill=True) |
|
225 |
self._files_box.show() |
|
226 |
self._left_pane_box.pack_start(self._files_box) |
|
227 |
||
228 |
def _construct_pending_list(self): |
|
229 |
# Pending information defaults to hidden, we put it all in 1 box, so
|
|
230 |
# that we can show/hide all of them at once
|
|
231 |
self._pending_box = gtk.VBox() |
|
232 |
self._pending_box.hide() |
|
233 |
||
234 |
pending_message = gtk.Label() |
|
235 |
pending_message.set_markup( |
|
236 |
_('<i>Cannot select specific files when merging</i>')) |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
237 |
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. |
238 |
pending_message.show() |
239 |
||
240 |
pending_label = gtk.Label() |
|
241 |
pending_label.set_markup(_('<b>Pending Revisions</b>')) |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
242 |
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. |
243 |
pending_label.show() |
244 |
||
245 |
scroller = gtk.ScrolledWindow() |
|
246 |
scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|
247 |
self._treeview_pending = gtk.TreeView() |
|
248 |
scroller.add(self._treeview_pending) |
|
249 |
scroller.show() |
|
250 |
scroller.set_shadow_type(gtk.SHADOW_IN) |
|
251 |
self._pending_box.pack_start(scroller, |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
252 |
expand=True, fill=True, padding=5) |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
253 |
self._treeview_pending.show() |
254 |
self._left_pane_box.pack_start(self._pending_box) |
|
255 |
||
278.1.14
by John Arbash Meinel
Tests that we fill out the pending list correctly. |
256 |
liststore = gtk.ListStore(gobject.TYPE_STRING, |
257 |
gobject.TYPE_STRING, |
|
258 |
gobject.TYPE_STRING, |
|
259 |
gobject.TYPE_STRING, |
|
260 |
)
|
|
261 |
self._pending_liststore = liststore |
|
262 |
self._treeview_pending.set_model(liststore) |
|
263 |
self._treeview_pending.append_column(gtk.TreeViewColumn(_('Date'), |
|
264 |
gtk.CellRendererText(), text=1)) |
|
265 |
self._treeview_pending.append_column(gtk.TreeViewColumn(_('Committer'), |
|
266 |
gtk.CellRendererText(), text=2)) |
|
267 |
self._treeview_pending.append_column(gtk.TreeViewColumn(_('Summary'), |
|
268 |
gtk.CellRendererText(), text=3)) |
|
269 |
||
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
270 |
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. |
271 |
from diff import DiffView |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
272 |
|
273 |
self._diff_label = gtk.Label(_('Diff for whole tree')) |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
274 |
self._diff_label.set_alignment(0, 0) |
275 |
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. |
276 |
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. |
277 |
self._diff_label.show() |
278 |
||
278.1.12
by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names. |
279 |
self._diff_view = DiffView() |
278.1.10
by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table. |
280 |
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. |
281 |
self._diff_view.show() |
282 |
||
283 |
def _construct_file_message(self): |
|
284 |
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. |
285 |
scroller = gtk.ScrolledWindow() |
286 |
scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|
287 |
||
288 |
self._file_message_text_view = gtk.TextView() |
|
289 |
scroller.add(self._file_message_text_view) |
|
290 |
scroller.show() |
|
291 |
scroller.set_shadow_type(gtk.SHADOW_IN) |
|
292 |
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. |
293 |
|
294 |
self._file_message_text_view.modify_font(pango.FontDescription("Monospace")) |
|
295 |
self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD) |
|
296 |
self._file_message_text_view.set_accepts_tab(False) |
|
297 |
self._file_message_text_view.show() |
|
298 |
||
299 |
self._file_message_expander = gtk.Expander(_('Message for XXX')) |
|
300 |
self._file_message_expander.add(file_message_box) |
|
301 |
file_message_box.show() |
|
278.1.10
by John Arbash Meinel
To get the space weighting I wanted, I turned to a Table. |
302 |
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. |
303 |
self._file_message_expander.show() |
304 |
||
305 |
def _construct_global_message(self): |
|
306 |
self._global_message_label = gtk.Label(_('Global Commit Message')) |
|
278.1.11
by John Arbash Meinel
Worked out the rest of the spacing. |
307 |
self._global_message_label.set_alignment(0, 0) |
308 |
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. |
309 |
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. |
310 |
# 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. |
311 |
self._global_message_label.show() |
312 |
||
278.1.9
by John Arbash Meinel
Move all text entry boxes into a ScrolledWindow, so that they don't change size constantly. |
313 |
scroller = gtk.ScrolledWindow() |
314 |
scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) |
|
315 |
||
316 |
self._global_message_text_view = gtk.TextView() |
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
317 |
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. |
318 |
scroller.add(self._global_message_text_view) |
319 |
scroller.show() |
|
320 |
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. |
321 |
self._add_to_right_table(scroller, 2, True) |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
322 |
self._file_message_text_view.set_wrap_mode(gtk.WRAP_WORD) |
323 |
self._file_message_text_view.set_accepts_tab(False) |
|
324 |
self._global_message_text_view.show() |
|
325 |
||
326 |
@staticmethod
|
|
327 |
def _rev_to_pending_info(rev): |
|
328 |
"""Get the information from a pending merge.""" |
|
126.1.1
by Szilveszter Farkas (Phanatic)
New Commit dialog implementation (no more Glade). |
329 |
from bzrlib.osutils import format_date |
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
330 |
|
331 |
rev_dict = {} |
|
332 |
rev_dict['committer'] = re.sub('<.*@.*>', '', rev.committer).strip(' ') |
|
333 |
rev_dict['summary'] = rev.get_summary() |
|
334 |
rev_dict['date'] = format_date(rev.timestamp, |
|
335 |
rev.timezone or 0, |
|
336 |
'original', date_fmt="%Y-%m-%d", |
|
337 |
show_offset=False) |
|
338 |
rev_dict['revision_id'] = rev.revision_id |
|
339 |
return rev_dict |
|
340 |
||
341 |
||
342 |
# class CommitDialog(gtk.Dialog):
|
|
343 |
# """ New implementation of the Commit dialog. """
|
|
344 |
# def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
|
|
345 |
# """ Initialize the Commit Dialog. """
|
|
346 |
# gtk.Dialog.__init__(self, title="Commit - Olive",
|
|
347 |
# parent=parent,
|
|
348 |
# flags=0,
|
|
349 |
# buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
|
|
350 |
#
|
|
351 |
# # Get arguments
|
|
352 |
# self.wt = wt
|
|
353 |
# self.wtpath = wtpath
|
|
354 |
# self.notbranch = notbranch
|
|
355 |
# self.selected = selected
|
|
356 |
#
|
|
357 |
# # Set the delta
|
|
358 |
# self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
|
|
359 |
# self.delta = self.wt.changes_from(self.old_tree)
|
|
360 |
#
|
|
361 |
# # Get pending merges
|
|
362 |
# self.pending = self._pending_merges(self.wt)
|
|
363 |
#
|
|
364 |
# # Do some preliminary checks
|
|
365 |
# self._is_checkout = False
|
|
366 |
# self._is_pending = False
|
|
367 |
# if self.wt is None and not self.notbranch:
|
|
368 |
# error_dialog(_('Directory does not have a working tree'),
|
|
369 |
# _('Operation aborted.'))
|
|
370 |
# self.close()
|
|
371 |
# return
|
|
372 |
#
|
|
373 |
# if self.notbranch:
|
|
374 |
# error_dialog(_('Directory is not a branch'),
|
|
375 |
# _('You can perform this action only in a branch.'))
|
|
376 |
# self.close()
|
|
377 |
# return
|
|
378 |
# else:
|
|
379 |
# if self.wt.branch.get_bound_location() is not None:
|
|
380 |
# # we have a checkout, so the local commit checkbox must appear
|
|
381 |
# self._is_checkout = True
|
|
382 |
#
|
|
383 |
# if self.pending:
|
|
384 |
# # There are pending merges, file selection not supported
|
|
385 |
# self._is_pending = True
|
|
386 |
#
|
|
387 |
# # Create the widgets
|
|
388 |
# # This is the main horizontal box, which is used to separate the commit
|
|
389 |
# # info from the diff window.
|
|
390 |
# self._hpane = gtk.HPaned()
|
|
391 |
# self._button_commit = gtk.Button(_("Comm_it"), use_underline=True)
|
|
392 |
# self._expander_files = gtk.Expander(_("File(s) to commit"))
|
|
393 |
# self._vpaned_main = gtk.VPaned()
|
|
394 |
# self._scrolledwindow_files = gtk.ScrolledWindow()
|
|
395 |
# self._scrolledwindow_message = gtk.ScrolledWindow()
|
|
396 |
# self._treeview_files = gtk.TreeView()
|
|
397 |
# self._vbox_message = gtk.VBox()
|
|
398 |
# self._label_message = gtk.Label(_("Commit message:"))
|
|
399 |
# self._textview_message = gtk.TextView()
|
|
400 |
#
|
|
401 |
# if self._is_pending:
|
|
402 |
# self._expander_merges = gtk.Expander(_("Pending merges"))
|
|
403 |
# self._vpaned_list = gtk.VPaned()
|
|
404 |
# self._scrolledwindow_merges = gtk.ScrolledWindow()
|
|
405 |
# self._treeview_merges = gtk.TreeView()
|
|
406 |
#
|
|
407 |
# # Set callbacks
|
|
408 |
# self._button_commit.connect('clicked', self._on_commit_clicked)
|
|
409 |
# self._treeview_files.connect('cursor-changed', self._on_treeview_files_cursor_changed)
|
|
410 |
# self._treeview_files.connect('row-activated', self._on_treeview_files_row_activated)
|
|
411 |
#
|
|
412 |
# # Set properties
|
|
413 |
# self._scrolledwindow_files.set_policy(gtk.POLICY_AUTOMATIC,
|
|
414 |
# gtk.POLICY_AUTOMATIC)
|
|
415 |
# self._scrolledwindow_message.set_policy(gtk.POLICY_AUTOMATIC,
|
|
416 |
# gtk.POLICY_AUTOMATIC)
|
|
417 |
# self._textview_message.modify_font(pango.FontDescription("Monospace"))
|
|
418 |
# self.set_default_size(500, 500)
|
|
419 |
# self._vpaned_main.set_position(200)
|
|
420 |
# self._button_commit.set_flags(gtk.CAN_DEFAULT)
|
|
421 |
#
|
|
422 |
# if self._is_pending:
|
|
423 |
# self._scrolledwindow_merges.set_policy(gtk.POLICY_AUTOMATIC,
|
|
424 |
# gtk.POLICY_AUTOMATIC)
|
|
425 |
# self._treeview_files.set_sensitive(False)
|
|
426 |
#
|
|
427 |
# # Construct the dialog
|
|
428 |
# self.action_area.pack_end(self._button_commit)
|
|
429 |
#
|
|
430 |
# self._scrolledwindow_files.add(self._treeview_files)
|
|
431 |
# self._scrolledwindow_message.add(self._textview_message)
|
|
432 |
#
|
|
433 |
# self._expander_files.add(self._scrolledwindow_files)
|
|
434 |
#
|
|
435 |
# self._vbox_message.pack_start(self._label_message, False, False)
|
|
436 |
# self._vbox_message.pack_start(self._scrolledwindow_message, True, True)
|
|
437 |
#
|
|
438 |
# if self._is_pending:
|
|
439 |
# self._expander_merges.add(self._scrolledwindow_merges)
|
|
440 |
# self._scrolledwindow_merges.add(self._treeview_merges)
|
|
441 |
# self._vpaned_list.add1(self._expander_files)
|
|
442 |
# self._vpaned_list.add2(self._expander_merges)
|
|
443 |
# self._vpaned_main.add1(self._vpaned_list)
|
|
444 |
# else:
|
|
445 |
# self._vpaned_main.add1(self._expander_files)
|
|
446 |
#
|
|
447 |
# self._vpaned_main.add2(self._vbox_message)
|
|
448 |
#
|
|
449 |
# self._hpane.pack1(self._vpaned_main)
|
|
450 |
# self.vbox.pack_start(self._hpane, expand=True, fill=True)
|
|
451 |
# if self._is_checkout:
|
|
452 |
# self._check_local = gtk.CheckButton(_("_Only commit locally"),
|
|
453 |
# use_underline=True)
|
|
454 |
# self.vbox.pack_start(self._check_local, False, False)
|
|
455 |
# if have_dbus:
|
|
456 |
# bus = dbus.SystemBus()
|
|
457 |
# proxy_obj = bus.get_object('org.freedesktop.NetworkManager',
|
|
458 |
# '/org/freedesktop/NetworkManager')
|
|
459 |
# dbus_iface = dbus.Interface(
|
|
460 |
# proxy_obj, 'org.freedesktop.NetworkManager')
|
|
461 |
# try:
|
|
462 |
# # 3 is the enum value for STATE_CONNECTED
|
|
463 |
# self._check_local.set_active(dbus_iface.state() != 3)
|
|
464 |
# except dbus.DBusException, e:
|
|
465 |
# # Silently drop errors. While DBus may be
|
|
466 |
# # available, NetworkManager doesn't necessarily have to be
|
|
467 |
# mutter("unable to get networkmanager state: %r" % e)
|
|
468 |
#
|
|
469 |
# # Create the file list
|
|
470 |
# self._create_file_view()
|
|
471 |
# # Create the pending merges
|
|
472 |
# self._create_pending_merges()
|
|
473 |
# self._create_diff_view()
|
|
474 |
#
|
|
475 |
# # Expand the corresponding expander
|
|
476 |
# if self._is_pending:
|
|
477 |
# self._expander_merges.set_expanded(True)
|
|
478 |
# else:
|
|
479 |
# self._expander_files.set_expanded(True)
|
|
480 |
#
|
|
481 |
# # Display dialog
|
|
482 |
# self.vbox.show_all()
|
|
483 |
#
|
|
484 |
# # Default to Commit button
|
|
485 |
# self._button_commit.grab_default()
|
|
486 |
#
|
|
487 |
# def _show_diff_view(self, treeview):
|
|
488 |
# # FIXME: the diff window freezes for some reason
|
|
489 |
# treeselection = treeview.get_selection()
|
|
490 |
# (model, iter) = treeselection.get_selected()
|
|
491 |
#
|
|
492 |
# if iter is not None:
|
|
493 |
# selected = model.get_value(iter, 3) # Get the real_path attribute
|
|
494 |
# self._diff_display.show_diff([selected])
|
|
495 |
#
|
|
496 |
# def _on_treeview_files_cursor_changed(self, treeview):
|
|
497 |
# self._show_diff_view(treeview)
|
|
498 |
#
|
|
499 |
# def _on_treeview_files_row_activated(self, treeview, path, view_column):
|
|
500 |
# self._show_diff_view(treeview)
|
|
501 |
#
|
|
502 |
# @show_bzr_error
|
|
503 |
# def _on_commit_clicked(self, button):
|
|
504 |
# """ Commit button clicked handler. """
|
|
505 |
# textbuffer = self._textview_message.get_buffer()
|
|
506 |
# start, end = textbuffer.get_bounds()
|
|
507 |
# message = textbuffer.get_text(start, end).decode('utf-8')
|
|
508 |
#
|
|
509 |
# if not self.pending:
|
|
510 |
# specific_files = self._get_specific_files()
|
|
511 |
# else:
|
|
512 |
# specific_files = None
|
|
513 |
#
|
|
514 |
# if message == '':
|
|
515 |
# response = question_dialog(_('Commit with an empty message?'),
|
|
516 |
# _('You can describe your commit intent in the message.'))
|
|
517 |
# if response == gtk.RESPONSE_NO:
|
|
518 |
# # Kindly give focus to message area
|
|
519 |
# self._textview_message.grab_focus()
|
|
520 |
# return
|
|
521 |
#
|
|
522 |
# if self._is_checkout:
|
|
523 |
# local = self._check_local.get_active()
|
|
524 |
# else:
|
|
525 |
# local = False
|
|
526 |
#
|
|
527 |
# if list(self.wt.unknowns()) != []:
|
|
528 |
# response = question_dialog(_("Commit with unknowns?"),
|
|
529 |
# _("Unknown files exist in the working tree. Commit anyway?"))
|
|
530 |
# if response == gtk.RESPONSE_NO:
|
|
531 |
# return
|
|
532 |
#
|
|
533 |
# try:
|
|
534 |
# self.wt.commit(message,
|
|
535 |
# allow_pointless=False,
|
|
536 |
# strict=False,
|
|
537 |
# local=local,
|
|
538 |
# specific_files=specific_files)
|
|
539 |
# except errors.PointlessCommit:
|
|
540 |
# response = question_dialog(_('Commit with no changes?'),
|
|
541 |
# _('There are no changes in the working tree.'))
|
|
542 |
# if response == gtk.RESPONSE_YES:
|
|
543 |
# self.wt.commit(message,
|
|
544 |
# allow_pointless=True,
|
|
545 |
# strict=False,
|
|
546 |
# local=local,
|
|
547 |
# specific_files=specific_files)
|
|
548 |
# self.response(gtk.RESPONSE_OK)
|
|
549 |
#
|
|
550 |
# def _pending_merges(self, wt):
|
|
551 |
# """ Return a list of pending merges or None if there are none of them. """
|
|
552 |
# parents = wt.get_parent_ids()
|
|
553 |
# if len(parents) < 2:
|
|
554 |
# return None
|
|
555 |
#
|
|
556 |
# import re
|
|
557 |
# from bzrlib.osutils import format_date
|
|
558 |
#
|
|
559 |
# pending = parents[1:]
|
|
560 |
# branch = wt.branch
|
|
561 |
# last_revision = parents[0]
|
|
562 |
#
|
|
563 |
# if last_revision is not None:
|
|
564 |
# try:
|
|
565 |
# ignore = set(branch.repository.get_ancestry(last_revision))
|
|
566 |
# except errors.NoSuchRevision:
|
|
567 |
# # the last revision is a ghost : assume everything is new
|
|
568 |
# # except for it
|
|
569 |
# ignore = set([None, last_revision])
|
|
570 |
# else:
|
|
571 |
# ignore = set([None])
|
|
572 |
#
|
|
573 |
# pm = []
|
|
574 |
# for merge in pending:
|
|
575 |
# ignore.add(merge)
|
|
576 |
# try:
|
|
577 |
# m_revision = branch.repository.get_revision(merge)
|
|
578 |
#
|
|
579 |
# rev = {}
|
|
580 |
# rev['committer'] = re.sub('<.*@.*>', '', m_revision.committer).strip(' ')
|
|
581 |
# rev['summary'] = m_revision.get_summary()
|
|
582 |
# rev['date'] = format_date(m_revision.timestamp,
|
|
583 |
# m_revision.timezone or 0,
|
|
584 |
# 'original', date_fmt="%Y-%m-%d",
|
|
585 |
# show_offset=False)
|
|
586 |
#
|
|
587 |
# pm.append(rev)
|
|
588 |
#
|
|
589 |
# inner_merges = branch.repository.get_ancestry(merge)
|
|
590 |
# assert inner_merges[0] is None
|
|
591 |
# inner_merges.pop(0)
|
|
592 |
# inner_merges.reverse()
|
|
593 |
# for mmerge in inner_merges:
|
|
594 |
# if mmerge in ignore:
|
|
595 |
# continue
|
|
596 |
# mm_revision = branch.repository.get_revision(mmerge)
|
|
597 |
#
|
|
598 |
# rev = {}
|
|
599 |
# rev['committer'] = re.sub('<.*@.*>', '', mm_revision.committer).strip(' ')
|
|
600 |
# rev['summary'] = mm_revision.get_summary()
|
|
601 |
# rev['date'] = format_date(mm_revision.timestamp,
|
|
602 |
# mm_revision.timezone or 0,
|
|
603 |
# 'original', date_fmt="%Y-%m-%d",
|
|
604 |
# show_offset=False)
|
|
605 |
#
|
|
606 |
# pm.append(rev)
|
|
607 |
#
|
|
608 |
# ignore.add(mmerge)
|
|
609 |
# except errors.NoSuchRevision:
|
|
610 |
# print "DEBUG: NoSuchRevision:", merge
|
|
611 |
#
|
|
612 |
# return pm
|
|
613 |
#
|
|
614 |
# def _create_file_view(self):
|
|
615 |
# self._file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, # [0] checkbox
|
|
616 |
# gobject.TYPE_STRING, # [1] path to display
|
|
617 |
# gobject.TYPE_STRING, # [2] changes type
|
|
618 |
# gobject.TYPE_STRING) # [3] real path
|
|
619 |
# self._treeview_files.set_model(self._file_store)
|
|
620 |
# crt = gtk.CellRendererToggle()
|
|
621 |
# crt.set_property("activatable", True)
|
|
622 |
# crt.connect("toggled", self._toggle_commit, self._file_store)
|
|
623 |
# self._treeview_files.append_column(gtk.TreeViewColumn(_('Commit'),
|
|
624 |
# crt, active=0))
|
|
625 |
# self._treeview_files.append_column(gtk.TreeViewColumn(_('Path'),
|
|
626 |
# gtk.CellRendererText(), text=1))
|
|
627 |
# self._treeview_files.append_column(gtk.TreeViewColumn(_('Type'),
|
|
628 |
# gtk.CellRendererText(), text=2))
|
|
629 |
#
|
|
630 |
# for path, id, kind in self.delta.added:
|
|
631 |
# marker = osutils.kind_marker(kind)
|
|
632 |
# if self.selected is not None:
|
|
633 |
# if path == os.path.join(self.wtpath, self.selected):
|
|
634 |
# self._file_store.append([ True, path+marker, _('added'), path ])
|
|
635 |
# else:
|
|
636 |
# self._file_store.append([ False, path+marker, _('added'), path ])
|
|
637 |
# else:
|
|
638 |
# self._file_store.append([ True, path+marker, _('added'), path ])
|
|
639 |
#
|
|
640 |
# for path, id, kind in self.delta.removed:
|
|
641 |
# marker = osutils.kind_marker(kind)
|
|
642 |
# if self.selected is not None:
|
|
643 |
# if path == os.path.join(self.wtpath, self.selected):
|
|
644 |
# self._file_store.append([ True, path+marker, _('removed'), path ])
|
|
645 |
# else:
|
|
646 |
# self._file_store.append([ False, path+marker, _('removed'), path ])
|
|
647 |
# else:
|
|
648 |
# self._file_store.append([ True, path+marker, _('removed'), path ])
|
|
649 |
#
|
|
650 |
# for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
|
|
651 |
# marker = osutils.kind_marker(kind)
|
|
652 |
# if text_modified or meta_modified:
|
|
653 |
# changes = _('renamed and modified')
|
|
654 |
# else:
|
|
655 |
# changes = _('renamed')
|
|
656 |
# if self.selected is not None:
|
|
657 |
# if newpath == os.path.join(self.wtpath, self.selected):
|
|
658 |
# self._file_store.append([ True,
|
|
659 |
# oldpath+marker + ' => ' + newpath+marker,
|
|
660 |
# changes,
|
|
661 |
# newpath
|
|
662 |
# ])
|
|
663 |
# else:
|
|
664 |
# self._file_store.append([ False,
|
|
665 |
# oldpath+marker + ' => ' + newpath+marker,
|
|
666 |
# changes,
|
|
667 |
# newpath
|
|
668 |
# ])
|
|
669 |
# else:
|
|
670 |
# self._file_store.append([ True,
|
|
671 |
# oldpath+marker + ' => ' + newpath+marker,
|
|
672 |
# changes,
|
|
673 |
# newpath
|
|
674 |
# ])
|
|
675 |
#
|
|
676 |
# for path, id, kind, text_modified, meta_modified in self.delta.modified:
|
|
677 |
# marker = osutils.kind_marker(kind)
|
|
678 |
# if self.selected is not None:
|
|
679 |
# if path == os.path.join(self.wtpath, self.selected):
|
|
680 |
# self._file_store.append([ True, path+marker, _('modified'), path ])
|
|
681 |
# else:
|
|
682 |
# self._file_store.append([ False, path+marker, _('modified'), path ])
|
|
683 |
# else:
|
|
684 |
# self._file_store.append([ True, path+marker, _('modified'), path ])
|
|
685 |
#
|
|
686 |
# def _create_pending_merges(self):
|
|
687 |
# if not self.pending:
|
|
688 |
# return
|
|
689 |
#
|
|
690 |
# liststore = gtk.ListStore(gobject.TYPE_STRING,
|
|
691 |
# gobject.TYPE_STRING,
|
|
692 |
# gobject.TYPE_STRING)
|
|
693 |
# self._treeview_merges.set_model(liststore)
|
|
694 |
#
|
|
695 |
# self._treeview_merges.append_column(gtk.TreeViewColumn(_('Date'),
|
|
696 |
# gtk.CellRendererText(), text=0))
|
|
697 |
# self._treeview_merges.append_column(gtk.TreeViewColumn(_('Committer'),
|
|
698 |
# gtk.CellRendererText(), text=1))
|
|
699 |
# self._treeview_merges.append_column(gtk.TreeViewColumn(_('Summary'),
|
|
700 |
# gtk.CellRendererText(), text=2))
|
|
701 |
#
|
|
702 |
# for item in self.pending:
|
|
703 |
# liststore.append([ item['date'],
|
|
704 |
# item['committer'],
|
|
705 |
# item['summary'] ])
|
|
706 |
#
|
|
707 |
#
|
|
708 |
# 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. |
709 |
# from diff import DiffView
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
710 |
#
|
278.1.12
by John Arbash Meinel
Delay computing the delta, and clean up some of the diff view names. |
711 |
# self._diff_display = DiffView()
|
278.1.5
by John Arbash Meinel
Starting to flesh out the dialog with actual windows. |
712 |
# self._diff_display.set_trees(self.wt, self.wt.basis_tree())
|
713 |
# self._diff_display.show_diff(None)
|
|
714 |
# self._diff_display.show()
|
|
715 |
# self._hpane.pack2(self._diff_display)
|
|
716 |
#
|
|
717 |
# def _get_specific_files(self):
|
|
718 |
# ret = []
|
|
719 |
# it = self._file_store.get_iter_first()
|
|
720 |
# while it:
|
|
721 |
# if self._file_store.get_value(it, 0):
|
|
722 |
# # get real path from hidden column 3
|
|
723 |
# ret.append(self._file_store.get_value(it, 3))
|
|
724 |
# it = self._file_store.iter_next(it)
|
|
725 |
#
|
|
726 |
# return ret
|
|
727 |
#
|
|
728 |
# def _toggle_commit(self, cell, path, model):
|
|
729 |
# model[path][0] = not model[path][0]
|
|
730 |
# return
|