From 279d081abc5777056dbc7d166be565e7cf0c4c1e Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Thu, 5 Jun 2008 02:05:38 -0700 Subject: [PATCH] controllers: add a remote controller Signed-off-by: David Aguilar --- ugit/controllers/{push.py => remote.py} | 115 ++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 43 deletions(-) rename ugit/controllers/{push.py => remote.py} (54%) diff --git a/ugit/controllers/push.py b/ugit/controllers/remote.py similarity index 54% rename from ugit/controllers/push.py rename to ugit/controllers/remote.py index eba18a7..d2606c2 100644 --- a/ugit/controllers/push.py +++ b/ugit/controllers/remote.py @@ -3,19 +3,25 @@ from PyQt4.QtGui import QDialog from ugit import utils from ugit import qtutils -from ugit.views import PushView +from ugit.views import RemoteView from ugit.qobserver import QObserver -def push_branches(model, parent): +def remote_action(model, parent, action): model = model.clone() - model.create( remotename='' ) - view = PushView(parent) - controller = PushController(model, view) + model.create( + remotename='', + tags_checkbox=False, + ffwd_only_checkbox=True, + ) + if action == "Fetch" or action == "Pull": + model.set_tags_checkbox(True) + view = RemoteView(parent, action) + controller = RemoteController(model, view, action) view.show() return view.exec_() == QDialog.Accepted -class PushController(QObserver): - def init(self, model, view): +class RemoteController(QObserver): + def init(self, model, view, action): self.add_observables( 'remotename', 'remotes', @@ -23,15 +29,26 @@ class PushController(QObserver): 'local_branches', 'remote_branch', 'remote_branches', + 'tags_checkbox', + 'ffwd_only_checkbox', ) + + self.action_method = { + "Fetch": self.fetch_action, + "Push": self.push_action, + "Pull": self.pull_action, + }[action] + self.add_actions( remotes = self.display_remotes ) self.add_callbacks( + action_button = self.action_method, remotes = self.update_remotes, local_branches = self.update_local_branches, remote_branches = self.update_remote_branches, - push_button = self.push_to_remote_branch, ) self.refresh_view() + if self.view.select_first_remote(): + self.model.set_remotename(self.model.get_remotes()[0]) def display_remotes(self, widget): displayed = [] @@ -42,41 +59,6 @@ class PushController(QObserver): displayed.append(display) qtutils.set_items(widget,displayed) - def push_to_remote_branch(self): - if not self.model.get_remotename(): - errmsg = self.tr('No repository selected.') - qtutils.show_output(errmsg) - return - - if not self.model.get_remote_branch(): - errmsg = self.tr('Please supply a branch name.') - qtutils.show_output(errmsg) - return - - if not self.model.get_local_branch(): - msg = self.tr('Pushing with an empty local branch ' - + 'will remove the remote branch.\n' - + 'Continue?') - if not qtutils.question(self.view, self.tr('warning'), msg): - return - - remotename = self.model.get_remotename() - local_branch = self.model.get_local_branch() - remote_branch = self.model.get_remote_branch() - ffwd = self.view.ffwd_only_checkbox.isChecked() - tags = self.view.tags_checkbox.isChecked() - - status, output = self.model.push_helper( - remotename, - local_branch, - remote_branch, - ffwd=ffwd, - tags=tags - ) - qtutils.show_output(output) - if not status: - self.view.accept() - def update_remotes(self,*rest): widget = self.view.remotes remotes = self.model.get_remotes() @@ -107,3 +89,50 @@ class PushController(QObserver): if branch == 'HEAD': return self.model.set_remote_branch(branch) self.view.remote_branch.selectAll() + + def check_remote(self): + if not self.model.get_remotename(): + errmsg = self.tr('No repository selected.') + qtutils.show_output(errmsg) + return False + else: + return True + + def get_common_args(self): + return ( + (self.model.get_remotename(),), + { + "local_branch": self.model.get_local_branch(), + "remote_branch": self.model.get_remote_branch(), + "ffwd": self.model.get_ffwd_only_checkbox(), + "tags": self.model.get_tags_checkbox(), + }, + ) + + def show_results(self, status, output): + if not status: + qtutils.log(output) + self.view.accept() + else: + qtutils.raise_logger() + + #+------------------------------------------------------------- + #+ Actions + def fetch_action(self): + if not self.check_remote(): + return + args, kwargs = self.get_common_args() + self.show_results(*self.model.fetch_helper(*args, **kwargs)) + return + + def pull_action(self): + if not self.check_remote(): + return + args, kwargs = self.get_common_args() + self.show_results(*self.model.pull_helper(*args, **kwargs)) + + def push_action(self): + if not self.check_remote(): + return + args, kwargs = self.get_common_args() + self.show_results(*self.model.push_helper(*args, **kwargs)) -- 2.11.4.GIT