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
28
import bzrlib.errors as errors
30
from dialog import error_dialog
31
from olive import gladefile
34
""" Display Commit dialog and perform the needed actions. """
35
def __init__(self, wt, wtpath):
36
""" Initialize the Commit dialog. """
37
self.glade = gtk.glade.XML(gladefile, 'window_commit', 'olive-gtk')
42
# Get some important widgets
43
self.window = self.glade.get_widget('window_commit')
44
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
45
self.textview = self.glade.get_widget('textview_commit')
46
self.file_view = self.glade.get_widget('treeview_commit_select')
48
file_id = self.wt.path2id(wtpath)
50
self.notbranch = False
56
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
57
self.delta = self.wt.changes_from(self.old_tree)
59
# Dictionary for signal_autoconnect
60
dic = { "on_button_commit_commit_clicked": self.commit,
61
"on_button_commit_cancel_clicked": self.close }
63
# Connect the signals to the handlers
64
self.glade.signal_autoconnect(dic)
66
# Create the file list
67
self._create_file_view()
70
""" Display the Push dialog. """
72
error_dialog(_('Directory is not a branch'),
73
_('You can perform this action only in a branch.'))
76
if self.wt.branch.get_bound_location() is not None:
77
# we have a checkout, so the local commit checkbox must appear
78
self.checkbutton_local.show()
80
self.textview.modify_font(pango.FontDescription("Monospace"))
84
def _create_file_view(self):
85
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
88
self.file_view.set_model(self.file_store)
89
crt = gtk.CellRendererToggle()
90
crt.set_property("activatable", True)
91
crt.connect("toggled", self._toggle_commit, self.file_store)
92
self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
94
self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
95
gtk.CellRendererText(), text=1))
96
self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
97
gtk.CellRendererText(), text=2))
99
for path, id, kind in self.delta.added:
100
self.file_store.append([ True, path, _('added') ])
102
for path, id, kind in self.delta.removed:
103
self.file_store.append([ True, path, _('removed') ])
105
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
106
self.file_store.append([ True, oldpath, _('renamed') ])
108
for path, id, kind, text_modified, meta_modified in self.delta.modified:
109
self.file_store.append([ True, path, _('modified') ])
111
def _get_specific_files(self):
113
it = self.file_store.get_iter_first()
115
if self.file_store.get_value(it, 0):
116
ret.append(self.file_store.get_value(it, 1))
117
it = self.file_store.iter_next(it)
121
def _toggle_commit(self, cell, path, model):
122
model[path][0] = not model[path][0]
125
def commit(self, widget):
126
textbuffer = self.textview.get_buffer()
127
start, end = textbuffer.get_bounds()
128
message = textbuffer.get_text(start, end)
130
checkbutton_strict = self.glade.get_widget('checkbutton_commit_strict')
131
checkbutton_force = self.glade.get_widget('checkbutton_commit_force')
133
specific_files = self._get_specific_files()
136
self.wt.commit(message,
137
allow_pointless=checkbutton_force.get_active(),
138
strict=checkbutton_strict.get_active(),
139
local=self.checkbutton_local.get_active(),
140
specific_files=specific_files)
141
except errors.NotBranchError:
142
error_dialog(_('Directory is not a branch'),
143
_('You can perform this action only in a branch.'))
145
except errors.LocalRequiresBoundBranch:
146
error_dialog(_('Directory is not a checkout'),
147
_('You can perform local commit only on checkouts.'))
149
except errors.PointlessCommit:
150
error_dialog(_('No changes to commit'),
151
_('Try force commit if you want to commit anyway.'))
153
except errors.ConflictsInTree:
154
error_dialog(_('Conflicts in tree'),
155
_('You need to resolve the conflicts before committing.'))
157
except errors.StrictCommitFailed:
158
error_dialog(_('Strict commit failed'),
159
_('There are unknown files in the working tree.\nPlease add or delete them.'))
161
except errors.BoundBranchOutOfDate, errmsg:
162
error_dialog(_('Bound branch is out of date'),
165
except errors.BzrError, msg:
166
error_dialog(_('Unknown bzr error'), str(msg))
168
except Exception, msg:
169
error_dialog(_('Unknown error'), str(msg))
174
def close(self, widget=None):
175
self.window.destroy()