1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <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.
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.
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
32
from bzrlib import version_info
34
import bzrlib.errors as errors
35
from bzrlib.workingtree import WorkingTree
38
""" Display Commit dialog and perform the needed actions. """
39
def __init__(self, gladefile, comm, dialog):
40
""" Initialize the Commit dialog. """
41
self.gladefile = gladefile
42
self.glade = gtk.glade.XML(self.gladefile, 'window_commit', 'olive-gtk')
44
# Communication object
49
# Get some important widgets
50
self.window = self.glade.get_widget('window_commit')
51
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
52
self.textview = self.glade.get_widget('textview_commit')
53
self.file_view = self.glade.get_widget('treeview_commit_select')
55
# Check if current location is a branch
57
(self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
58
branch = self.wt.branch
59
except errors.NotBranchError:
65
file_id = self.wt.path2id(path)
67
self.notbranch = False
73
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
74
if version_info < (0, 9):
75
self.delta = compare_trees(self.old_tree, self.wt)
77
self.delta = self.wt.changes_from(self.old_tree)
79
# Dictionary for signal_autoconnect
80
dic = { "on_button_commit_commit_clicked": self.commit,
81
"on_button_commit_cancel_clicked": self.close }
83
# Connect the signals to the handlers
84
self.glade.signal_autoconnect(dic)
86
# Create the file list
87
self._create_file_view()
90
""" Display the Push dialog. """
92
self.dialog.error_dialog(_('Directory is not a branch'),
93
_('You can perform this action only in a branch.'))
96
from bzrlib.branch import Branch
97
branch = Branch.open_containing(self.comm.get_path())[0]
99
if branch.get_bound_location() is not None:
100
# we have a checkout, so the local commit checkbox must appear
101
self.checkbutton_local.show()
103
self.textview.modify_font(pango.FontDescription("Monospace"))
107
# This code is from Jelmer Vernooij's bzr-gtk branch
108
def _create_file_view(self):
109
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
112
self.file_view.set_model(self.file_store)
113
crt = gtk.CellRendererToggle()
114
crt.set_property("activatable", True)
115
crt.connect("toggled", self._toggle_commit, self.file_store)
116
self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
118
self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
119
gtk.CellRendererText(), text=1))
120
self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
121
gtk.CellRendererText(), text=2))
123
for path, id, kind in self.delta.added:
124
self.file_store.append([ True, path, _('added') ])
126
for path, id, kind in self.delta.removed:
127
self.file_store.append([ True, path, _('removed') ])
129
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
130
self.file_store.append([ True, oldpath, _('renamed') ])
132
for path, id, kind, text_modified, meta_modified in self.delta.modified:
133
self.file_store.append([ True, path, _('modified') ])
135
def _get_specific_files(self):
137
it = self.file_store.get_iter_first()
139
if self.file_store.get_value(it, 0):
140
ret.append(self.file_store.get_value(it, 1))
141
it = self.file_store.iter_next(it)
144
# end of bzr-gtk code
146
def _toggle_commit(self, cell, path, model):
147
model[path][0] = not model[path][0]
150
def commit(self, widget):
151
textbuffer = self.textview.get_buffer()
152
start, end = textbuffer.get_bounds()
153
message = textbuffer.get_text(start, end)
155
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
156
checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
158
specific_files = self._get_specific_files()
160
self.comm.set_busy(self.window)
161
# merged from Jelmer Vernooij's olive integration branch
163
self.wt.commit(message,
164
allow_pointless=checkbutton_force.get_active(),
165
strict=checkbutton_strict.get_active(),
166
local=self.checkbutton_local.get_active(),
167
specific_files=specific_files)
168
except errors.NotBranchError:
169
self.dialog.error_dialog(_('Directory is not a branch'),
170
_('You can perform this action only in a branch.'))
171
self.comm.set_busy(self.window, False)
173
except errors.LocalRequiresBoundBranch:
174
self.dialog.error_dialog(_('Directory is not a checkout'),
175
_('You can perform local commit only on checkouts.'))
176
self.comm.set_busy(self.window, False)
178
except errors.PointlessCommit:
179
self.dialog.error_dialog(_('No changes to commit'),
180
_('Try force commit if you want to commit anyway.'))
181
self.comm.set_busy(self.window, False)
183
except errors.ConflictsInTree:
184
self.dialog.error_dialog(_('Conflicts in tree'),
185
_('You need to resolve the conflicts before committing.'))
186
self.comm.set_busy(self.window, False)
188
except errors.StrictCommitFailed:
189
self.dialog.error_dialog(_('Strict commit failed'),
190
_('There are unknown files in the working tree.\nPlease add or delete them.'))
191
self.comm.set_busy(self.window, False)
193
except errors.BoundBranchOutOfDate, errmsg:
194
self.dialog.error_dialog(_('Bound branch is out of date'),
196
self.comm.set_busy(self.window, False)
202
self.comm.refresh_right()
204
def close(self, widget=None):
205
self.window.destroy()