2 from PyQt4
.QtGui
import QDialog
6 from qobserver
import QObserver
7 from views
import PushGUI
9 def push_branches(model
, parent
):
11 view
= PushGUI(parent
)
12 controller
= PushController(model
,view
)
14 return view
.exec_() == QDialog
.Accepted
16 class PushController(QObserver
):
17 def __init__(self
, model
, view
):
18 QObserver
.__init
__(self
,model
,view
)
29 self
.add_actions('remotes', self
.display_remotes
)
31 remotes
= self
.update_remotes
,
32 local_branches
= self
.update_local_branches
,
33 remote_branches
= self
.update_remote_branches
,
34 push_button
= self
.push_to_remote_branch
,
38 def display_remotes(self
, widget
):
40 for remote
in self
.model
.get_remotes():
41 url
= self
.model
.remote_url(remote
)
42 display
= '%s\t(%s %s)' \
43 % (remote
, unicode(self
.tr('URL:')), url
)
44 displayed
.append(display
)
45 qtutils
.set_items(widget
,displayed
)
47 def push_to_remote_branch(self
):
48 if not self
.model
.get_remote():
49 errmsg
= self
.tr('No repository selected.')
50 qtutils
.show_output(errmsg
)
53 if not self
.model
.get_remote_branch():
54 errmsg
= self
.tr('Please supply a branch name.')
55 qtutils
.show_output(errmsg
)
58 if not self
.model
.get_local_branch():
59 msg
= self
.tr('Pushing with an empty local branch '
60 + 'will remove the remote branch.\n'
62 if not qtutils
.question(self
.view
, self
.tr('warning'), msg
):
65 remote
= self
.model
.get_remote()
66 local_branch
= self
.model
.get_local_branch()
67 remote_branch
= self
.model
.get_remote_branch()
68 ffwd
= self
.view
.ffwd_only_checkbox
.isChecked()
69 tags
= self
.view
.tags_checkbox
.isChecked()
71 status
, output
= self
.model
.push_helper(
78 qtutils
.show_output(output
)
82 def update_remotes(self
,*rest
):
83 widget
= self
.view
.remotes
84 remotes
= self
.model
.get_remotes()
85 selection
= qtutils
.get_selected_item(widget
,remotes
)
86 if not selection
: return
87 self
.model
.set_remote(selection
)
88 self
.view
.remote
.selectAll()
90 def update_local_branches(self
,*rest
):
91 branches
= self
.model
.get_local_branches()
92 widget
= self
.view
.local_branches
93 selection
= qtutils
.get_selected_item(widget
,branches
)
94 if not selection
: return
96 self
.model
.set_local_branch(selection
)
97 self
.model
.set_remote_branch(selection
)
99 self
.view
.local_branch
.selectAll()
100 self
.view
.remote_branch
.selectAll()
102 def update_remote_branches(self
,*rest
):
103 widget
= self
.view
.remote_branches
104 branches
= self
.model
.get_remote_branches()
105 selection
= qtutils
.get_selected_item(widget
,branches
)
106 if not selection
: return
108 branch
= utils
.basename(selection
)
109 if branch
== 'HEAD': return
110 self
.model
.set_remote_branch(branch
)
111 self
.view
.remote_branch
.selectAll()