1
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
5
5
# the Free Software Foundation; either version 2 of the License, or
6
6
# (at your option) any later version.
8
8
# This program is distributed in the hope that it will be useful,
9
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
11
# GNU General Public License for more details.
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
21
pygtk.require("2.0")
34
if bzrlib.version_info[1] < 9:
35
# function deprecated after 0.9
36
from bzrlib.delta import compare_trees
29
from bzrlib import version_info
38
31
import bzrlib.errors as errors
39
32
from bzrlib.workingtree import WorkingTree
41
from dialog import OliveDialog
34
from dialog import error_dialog
35
from olive import gladefile
44
38
""" Display Commit dialog and perform the needed actions. """
45
def __init__(self, gladefile, comm):
39
def __init__(self, wt, wtpath):
46
40
""" Initialize the Commit dialog. """
47
self.gladefile = gladefile
48
self.glade = gtk.glade.XML(self.gladefile, 'window_commit')
52
self.dialog = OliveDialog(self.gladefile)
54
# Check if current location is a branch
56
(self.wt, path) = WorkingTree.open_containing(self.comm.get_path())
57
branch = self.wt.branch
58
except errors.NotBranchError:
64
file_id = self.wt.path2id(path)
41
self.glade = gtk.glade.XML(gladefile, 'window_commit', 'olive-gtk')
46
# Get some important widgets
47
self.window = self.glade.get_widget('window_commit')
48
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
49
self.textview = self.glade.get_widget('textview_commit')
50
self.file_view = self.glade.get_widget('treeview_commit_select')
52
file_id = self.wt.path2id(wtpath)
66
54
self.notbranch = False
67
55
if file_id is None:
72
60
self.old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
73
if bzrlib.version_info[1] < 9:
74
self.delta = compare_trees(self.old_tree, self.wt)
76
self.delta = self.wt.changes_from(self.old_tree)
78
# Get the Commit dialog widget
79
self.window = self.glade.get_widget('window_commit')
61
self.delta = self.wt.changes_from(self.old_tree)
81
63
# Dictionary for signal_autoconnect
82
64
dic = { "on_button_commit_commit_clicked": self.commit,
88
70
# Create the file list
89
71
self._create_file_view()
91
# Some additional widgets
92
self.checkbutton_local = self.glade.get_widget('checkbutton_commit_local')
93
self.textview = self.glade.get_widget('textview_commit')
96
74
""" Display the Push dialog. """
98
self.dialog.error_dialog('Directory is not a branch.')
76
error_dialog(_('Directory is not a branch'),
77
_('You can perform this action only in a branch.'))
100
from olive.backend.info import is_checkout
101
if is_checkout(self.comm.get_path()):
80
if self.wt.branch.get_bound_location() is not None:
102
81
# we have a checkout, so the local commit checkbox must appear
103
82
self.checkbutton_local.show()
106
85
self.window.show()
109
# This code is from Jelmer Vernooij's bzr-gtk branch
110
88
def _create_file_view(self):
111
89
self.file_store = gtk.ListStore(gobject.TYPE_BOOLEAN,
112
90
gobject.TYPE_STRING,
113
91
gobject.TYPE_STRING)
114
self.file_view = self.glade.get_widget('treeview_commit_select')
115
92
self.file_view.set_model(self.file_store)
116
93
crt = gtk.CellRendererToggle()
117
94
crt.set_property("activatable", True)
118
95
crt.connect("toggled", self._toggle_commit, self.file_store)
119
self.file_view.append_column(gtk.TreeViewColumn("Commit",
96
self.file_view.append_column(gtk.TreeViewColumn(_('Commit'),
121
self.file_view.append_column(gtk.TreeViewColumn("Path",
98
self.file_view.append_column(gtk.TreeViewColumn(_('Path'),
122
99
gtk.CellRendererText(), text=1))
123
self.file_view.append_column(gtk.TreeViewColumn("Type",
100
self.file_view.append_column(gtk.TreeViewColumn(_('Type'),
124
101
gtk.CellRendererText(), text=2))
126
for path, _, _ in self.delta.added:
127
self.file_store.append([ True, path, "added" ])
129
for path, _, _ in self.delta.removed:
130
self.file_store.append([ True, path, "removed" ])
132
for oldpath, _, _, _, _, _ in self.delta.renamed:
133
self.file_store.append([ True, oldpath, "renamed"])
135
for path, _, _, _, _ in self.delta.modified:
136
self.file_store.append([ True, path, "modified"])
103
for path, id, kind in self.delta.added:
104
self.file_store.append([ True, path, _('added') ])
106
for path, id, kind in self.delta.removed:
107
self.file_store.append([ True, path, _('removed') ])
109
for oldpath, newpath, id, kind, text_modified, meta_modified in self.delta.renamed:
110
self.file_store.append([ True, oldpath, _('renamed') ])
112
for path, id, kind, text_modified, meta_modified in self.delta.modified:
113
self.file_store.append([ True, path, _('modified') ])
138
115
def _get_specific_files(self):
169
143
local=self.checkbutton_local.get_active(),
170
144
specific_files=specific_files)
171
145
except errors.NotBranchError:
172
self.dialog.error_dialog('Directory is not a branch.')
173
self.comm.set_busy(self.window, False)
146
error_dialog(_('Directory is not a branch'),
147
_('You can perform this action only in a branch.'))
175
149
except errors.LocalRequiresBoundBranch:
176
self.dialog.error_dialog('Local commit requires a bound branch.')
177
self.comm.set_busy(self.window, False)
150
error_dialog(_('Directory is not a checkout'),
151
_('You can perform local commit only on checkouts.'))
179
153
except errors.PointlessCommit:
180
self.dialog.error_dialog('No changes to commit. Try force commit.')
181
self.comm.set_busy(self.window, False)
154
error_dialog(_('No changes to commit'),
155
_('Try force commit if you want to commit anyway.'))
183
157
except errors.ConflictsInTree:
184
self.dialog.error_dialog('Conflicts in tree. Please resolve them first.')
185
self.comm.set_busy(self.window, False)
158
error_dialog(_('Conflicts in tree'),
159
_('You need to resolve the conflicts before committing.'))
187
161
except errors.StrictCommitFailed:
188
self.dialog.error_dialog('Strict commit failed. There are unknown files.')
189
self.comm.set_busy(self.window, False)
162
error_dialog(_('Strict commit failed'),
163
_('There are unknown files in the working tree.\nPlease add or delete them.'))
191
165
except errors.BoundBranchOutOfDate, errmsg:
192
self.dialog.error_dialog('Bound branch is out of date: %s' % errmsg)
193
self.comm.set_busy(self.window, False)
166
error_dialog(_('Bound branch is out of date'),
169
except errors.BzrError, msg:
170
error_dialog(_('Unknown bzr error'), str(msg))
172
except Exception, msg:
173
error_dialog(_('Unknown error'), str(msg))
199
self.comm.refresh_right()
201
178
def close(self, widget=None):
202
179
self.window.destroy()