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>
|
2 |
||
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.
|
|
7 |
||
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.
|
|
12 |
||
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 |
import sys |
|
18 |
||
19 |
try: |
|
20 |
import pygtk |
|
21 |
pygtk.require("2.0") |
|
22 |
except: |
|
23 |
pass
|
|
24 |
try: |
|
25 |
import gtk |
|
26 |
import gtk.glade |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
27 |
import gobject |
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
28 |
except: |
29 |
sys.exit(1) |
|
30 |
||
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
31 |
from bzrlib.delta import compare_trees |
32 |
import bzrlib.errors as errors |
|
33 |
from bzrlib.workingtree import WorkingTree |
|
34 |
||
35 |
from dialog import OliveDialog |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
36 |
|
37 |
class OliveCommit: |
|
38 |
""" Display Commit dialog and perform the needed actions. """ |
|
39 |
def __init__(self, gladefile, comm): |
|
40 |
""" Initialize the Commit dialog. """ |
|
41 |
self.gladefile = gladefile |
|
42 |
self.glade = gtk.glade.XML(self.gladefile, 'window_commit') |
|
43 |
||
44 |
self.comm = comm |
|
45 |
||
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
46 |
self.dialog = OliveDialog(self.gladefile) |
47 |
||
48 |
# Check if current location is a branch
|
|
49 |
try: |
|
50 |
(self.wt, path) = WorkingTree.open_containing(self.comm.get_path()) |
|
51 |
branch = self.wt.branch |
|
52 |
except errors.NotBranchError: |
|
53 |
self.notbranch = True |
|
54 |
return
|
|
55 |
except: |
|
56 |
raise
|
|
57 |
||
58 |
file_id = self.wt.path2id(path) |
|
59 |
||
60 |
self.notbranch = False |
|
61 |
if file_id is None: |
|
62 |
self.notbranch = True |
|
63 |
return
|
|
64 |
||
65 |
# Set the delta
|
|
66 |
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision()) |
|
67 |
self.delta = compare_trees(self.old_tree, self.wt) |
|
68 |
||
69 |
# Get the Commit dialog widget
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
70 |
self.window = self.glade.get_widget('window_commit') |
71 |
||
72 |
# Dictionary for signal_autoconnect
|
|
73 |
dic = { "on_button_commit_commit_clicked": self.commit, |
|
74 |
"on_button_commit_cancel_clicked": self.close } |
|
75 |
||
76 |
# Connect the signals to the handlers
|
|
77 |
self.glade.signal_autoconnect(dic) |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
78 |
|
79 |
# Create the file list
|
|
80 |
self._create_file_view() |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
81 |
|
82 |
def display(self): |
|
83 |
""" Display the Push dialog. """ |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
84 |
if self.notbranch: |
85 |
self.dialog.error_dialog('Directory is not a branch.') |
|
86 |
else: |
|
87 |
self.window.show_all() |
|
88 |
||
89 |
# This code is from Jelmer Vernooij's bzr-gtk branch
|
|
90 |
def _create_file_view(self): |
|
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
91 |
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN, |
92 |
gobject.TYPE_STRING, |
|
93 |
gobject.TYPE_STRING) |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
94 |
self.file_view = self.glade.get_widget('treeview_commit_select') |
95 |
self.file_view.set_model(self.file_store) |
|
96 |
crt = gtk.CellRendererToggle() |
|
97 |
crt.set_property("activatable", True) |
|
98 |
crt.connect("toggled", self._toggle_commit, self.file_store) |
|
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
99 |
self.file_view.append_column(gtk.TreeViewColumn("Commit", |
100 |
crt, active=0)) |
|
101 |
self.file_view.append_column(gtk.TreeViewColumn("Path", |
|
102 |
gtk.CellRendererText(), text=1)) |
|
103 |
self.file_view.append_column(gtk.TreeViewColumn("Type", |
|
104 |
gtk.CellRendererText(), text=2)) |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
105 |
|
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
106 |
for path, _, _ in self.delta.added: |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
107 |
self.file_store.append([ True, path, "added" ]) |
108 |
||
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
109 |
for path, _, _ in self.delta.removed: |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
110 |
self.file_store.append([ True, path, "removed" ]) |
111 |
||
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
112 |
for oldpath, _, _, _, _, _ in self.delta.renamed: |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
113 |
self.file_store.append([ True, oldpath, "renamed"]) |
114 |
||
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
115 |
for path, _, _, _, _ in self.delta.modified: |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
116 |
self.file_store.append([ True, path, "modified"]) |
117 |
||
118 |
def _get_specific_files(self): |
|
119 |
ret = [] |
|
120 |
it = self.file_store.get_iter_first() |
|
121 |
while it: |
|
122 |
if self.file_store.get_value(it, 0): |
|
0.8.21
by Szilveszter Farkas (Phanatic)
2006-07-25 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
123 |
ret.append(self.file_store.get_value(it, 1)) |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
124 |
it = self.file_store.iter_next(it) |
125 |
||
126 |
return ret |
|
127 |
# end of bzr-gtk code
|
|
128 |
||
129 |
def _toggle_commit(self, cell, path, model): |
|
130 |
model[path][0] = not model[path][0] |
|
131 |
return
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
132 |
|
133 |
def commit(self, widget): |
|
134 |
textview = self.glade.get_widget('textview_commit') |
|
135 |
textbuffer = textview.get_buffer() |
|
136 |
start, end = textbuffer.get_bounds() |
|
137 |
message = textbuffer.get_text(start, end) |
|
138 |
||
139 |
checkbutton_local = self.glade.get_widget('checkbutton_commit_local') |
|
140 |
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict') |
|
141 |
checkbutton_force = self.glade.get_widget('checkbutton_commit_force') |
|
142 |
||
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
143 |
specific_files = self._get_specific_files() |
144 |
||
145 |
# merged from Jelmer Vernooij's olive integration branch
|
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
146 |
try: |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
147 |
self.wt.commit(message, |
148 |
allow_pointless=checkbutton_force.get_active(), |
|
149 |
strict=checkbutton_strict.get_active(), |
|
150 |
local=checkbutton_local.get_active(), |
|
151 |
specific_files=specific_files) |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
152 |
except errors.NotBranchError: |
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
153 |
self.dialog.error_dialog('Directory is not a branch.') |
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
154 |
return
|
155 |
except errors.LocalRequiresBoundBranch: |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
156 |
self.dialog.error_dialog('Local commit requires a bound branch.') |
157 |
return
|
|
158 |
except errors.PointlessCommit: |
|
159 |
self.dialog.error_dialog('No changes to commit. Try force commit.') |
|
160 |
return
|
|
161 |
except errors.ConflictsInTree: |
|
162 |
self.dialog.error_dialog('Conflicts in tree. Please resolve them first.') |
|
163 |
return
|
|
164 |
except errors.StrictCommitFailed: |
|
165 |
self.dialog.error_dialog('Strict commit failed. There are unknown files.') |
|
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
166 |
return
|
167 |
except errors.BoundBranchOutOfDate, errmsg: |
|
0.8.20
by Szilveszter Farkas (Phanatic)
2006-07-24 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
168 |
self.dialog.error_dialog('Bound branch is out of date: %s' % errmsg) |
0.8.19
by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com> |
169 |
return
|
170 |
except: |
|
171 |
raise
|
|
172 |
||
173 |
self.close() |
|
174 |
self.comm.refresh_right() |
|
175 |
||
176 |
def close(self, widget=None): |
|
177 |
self.window.destroy() |