21
22
pygtk.require("2.0")
30
from olive.backend.info import is_branch
31
import olive.backend.errors as errors
33
from dialog import OliveDialog
34
from menu import OliveMenu
29
import bzrlib.errors as errors
30
from bzrlib.branch import Branch
31
from bzrlib.workingtree import WorkingTree
33
from dialog import about, error_dialog, info_dialog
35
34
from launch import launch
37
36
class OliveHandler:
38
37
""" Signal handler class for Olive. """
39
def __init__(self, gladefile, comm):
40
self.gladefile = gladefile
43
self.dialog = OliveDialog(self.gladefile)
45
self.menu = OliveMenu(self.gladefile, self.comm, self.dialog)
38
def __init__(self, path):
39
self.wt, self.path = WorkingTree.open_containing(path)
47
41
def on_about_activate(self, widget):
50
44
def on_menuitem_add_files_activate(self, widget):
51
45
""" Add file(s)... menu handler. """
52
46
from add import OliveAdd
53
add = OliveAdd(self.gladefile, self.comm, self.dialog)
47
add = OliveAdd(self.wt, self.path, self.comm.get_selected_right())
56
50
def on_menuitem_branch_get_activate(self, widget):
57
51
""" Branch/Get... menu handler. """
58
52
from branch import OliveBranch
59
branch = OliveBranch(self.gladefile, self.comm, self.dialog)
53
branch = OliveBranch()
62
56
def on_menuitem_branch_checkout_activate(self, widget):
63
57
""" Branch/Checkout... menu handler. """
64
58
from checkout import OliveCheckout
65
checkout = OliveCheckout(self.gladefile, self.comm, self.dialog)
59
checkout = OliveCheckout()
68
62
def on_menuitem_branch_commit_activate(self, widget):
69
63
""" Branch/Commit... menu handler. """
70
64
from commit import OliveCommit
71
commit = OliveCommit(self.gladefile, self.comm, self.dialog)
65
commit = OliveCommit(self.wt, self.path)
74
68
def on_menuitem_branch_missing_revisions_activate(self, widget):
75
69
""" Branch/Missing revisions menu handler. """
76
import olive.backend.update as update
78
71
self.comm.set_busy(self.comm.window_main)
81
ret = update.missing(self.comm.get_path())
82
except errors.NotBranchError:
83
self.dialog.error_dialog(_('Directory is not a branch'),
84
_('You can perform this action only in a branch.'))
85
except errors.ConnectionError:
86
self.dialog.error_dialog(_('Connection error'),
87
_('Cannot connect to remote location.\nPlease try again later.'))
88
except errors.NoLocationKnown:
89
self.dialog.error_dialog(_('Parent location is unknown'),
90
_('Cannot determine missing revisions if no parent location is known.'))
76
local_branch = self.wt.branch
78
other_branch = local_branch.get_parent()
79
if other_branch is None:
80
error_dialog(_('Parent location is unknown'),
81
_('Cannot determine missing revisions if no parent location is known.'))
84
remote_branch = Branch.open(other_branch)
86
if remote_branch.base == local_branch.base:
87
remote_branch = local_branch
89
ret = len(local_branch.missing_revisions(remote_branch))
93
self.dialog.info_dialog(_('There are missing revisions'),
92
info_dialog(_('There are missing revisions'),
94
93
_('%d revision(s) missing.') % ret)
96
self.dialog.info_dialog(_('Local branch up to date'),
95
info_dialog(_('Local branch up to date'),
97
96
_('There are no missing revisions.'))
99
self.comm.set_busy(self.comm.window_main, False)
98
self.comm.set_busy(self.comm.window_main, False)
101
100
def on_menuitem_branch_pull_activate(self, widget):
102
101
""" Branch/Pull menu handler. """
103
import olive.backend.update as update
105
103
self.comm.set_busy(self.comm.window_main)
105
branch_to = self.wt.branch
107
location = branch_to.get_parent()
109
error_dialog(_('Parent location is unknown'),
110
_('Pulling is not possible until there is a parent location.'))
108
ret = update.pull(self.comm.get_path())
114
branch_from = Branch.open(location)
109
115
except errors.NotBranchError:
110
self.dialog.error_dialog(_('Directory is not a branch'),
116
error_dialog(_('Directory is not a branch'),
111
117
_('You can perform this action only in a branch.'))
112
except errors.NoLocationKnown:
113
self.dialog.error_dialog(_('Parent location is unknown'),
114
_('Pulling is not possible until there is no parent location.'))
119
if branch_to.get_parent() is None:
120
branch_to.set_parent(branch_from.base)
122
old_rh = branch_to.revision_history()
123
if tree_to is not None:
124
tree_to.pull(branch_from)
116
self.dialog.info_dialog(_('Pull successful'),
117
_('%d revision(s) pulled.') % ret)
126
branch_to.pull(branch_from)
119
self.comm.set_busy(self.comm.window_main, False)
128
info_dialog(_('Pull successful'), _('%d revision(s) pulled.') % ret)
121
130
def on_menuitem_branch_push_activate(self, widget):
122
131
""" Branch/Push... menu handler. """
123
132
from push import OlivePush
124
push = OlivePush(self.gladefile, self.comm, self.dialog)
133
push = OlivePush(self.comm)
127
136
def on_menuitem_branch_status_activate(self, widget):
128
137
""" Branch/Status... menu handler. """
129
138
from status import OliveStatus
130
status = OliveStatus(self.gladefile, self.comm, self.dialog)
139
status = OliveStatus(self.wt, self.path)
133
142
def on_menuitem_branch_initialize_activate(self, widget):
134
143
""" Initialize current directory. """
135
import olive.backend.init as init
138
init.init(self.comm.get_path())
145
location = self.comm.get_path()
146
from bzrlib.builtins import get_format_type
148
format = get_format_type('default')
150
if not os.path.exists(location):
154
existing_bzrdir = bzrdir.BzrDir.open(location)
155
except NotBranchError:
156
bzrdir.BzrDir.create_branch_convenience(location, format=format)
158
if existing_bzrdir.has_branch():
159
if existing_bzrdir.has_workingtree():
160
raise AlreadyBranchError(location)
162
raise BranchExistsWithoutWorkingTree(location)
164
existing_bzrdir.create_branch()
165
existing_bzrdir.create_workingtree()
139
166
except errors.AlreadyBranchError, errmsg:
140
self.dialog.error_dialog(_('Directory is already a branch'),
167
error_dialog(_('Directory is already a branch'),
141
168
_('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
142
169
except errors.BranchExistsWithoutWorkingTree, errmsg:
143
self.dialog.error_dialog(_('Branch without a working tree'),
170
error_dialog(_('Branch without a working tree'),
144
171
_('The current directory (%s)\nis a branch without a working tree.') % errmsg)
148
self.dialog.info_dialog(_('Ininialize successful'),
173
info_dialog(_('Initialize successful'),
149
174
_('Directory successfully initialized.'))
150
175
self.comm.refresh_right()
152
177
def on_menuitem_file_make_directory_activate(self, widget):
153
178
""" File/Make directory... menu handler. """
154
179
from mkdir import OliveMkdir
155
mkdir = OliveMkdir(self.gladefile, self.comm, self.dialog)
180
mkdir = OliveMkdir(self.comm)
158
183
def on_menuitem_file_move_activate(self, widget):
159
184
""" File/Move... menu handler. """
160
185
from move import OliveMove
161
move = OliveMove(self.gladefile, self.comm, self.dialog)
186
move = OliveMove(self.comm)
164
189
def on_menuitem_file_rename_activate(self, widget):
165
190
""" File/Rename... menu handler. """
166
191
from rename import OliveRename
167
rename = OliveRename(self.gladefile, self.comm, self.dialog)
192
rename = OliveRename(self.comm)
170
195
def on_menuitem_remove_file_activate(self, widget):
171
196
""" Remove (unversion) selected file. """
172
197
from remove import OliveRemove
173
remove = OliveRemove(self.gladefile, self.comm, self.dialog)
198
remove = OliveRemove(self.comm)
176
201
def on_menuitem_stats_diff_activate(self, widget):
177
202
""" Statistics/Differences... menu handler. """
178
from diff import OliveDiff
179
diff = OliveDiff(self.gladefile, self.comm, self.dialog)
203
from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
204
window = DiffWindow()
205
parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
206
window.set_diff(self.wt.branch.nick, self.wt, parent_tree)
182
209
def on_menuitem_stats_infos_activate(self, widget):
183
210
""" Statistics/Informations... menu handler. """
184
211
from info import OliveInfo
185
info = OliveInfo(self.gladefile, self.comm, self.dialog)
212
info = OliveInfo(self.comm)
188
215
def on_menuitem_stats_log_activate(self, widget):
189
216
""" Statistics/Log... menu handler. """
190
217
from log import OliveLog
191
log = OliveLog(self.gladefile, self.comm, self.dialog)
218
log = OliveLog(self.comm)
194
221
def on_menuitem_view_refresh_activate(self, widget):