2 from PyQt4
.QtGui
import QDialog
4 from qobserver
import QObserver
5 from views
import BranchDialog
6 from views
import CommitBrowser
8 def choose_branch(title
, parent
, branches
):
9 dlg
= BranchDialog(parent
,branches
)
10 dlg
.setWindowTitle(dlg
.tr(title
))
11 return dlg
.get_selected()
13 def select_commits(model
, parent
, revs
, summaries
):
14 '''Use the CommitBrowser to select commits from a list.'''
15 model
= model
.clone(init
=False)
16 model
.set_revisions(revs
)
17 model
.set_summaries(summaries
)
18 view
= CommitBrowser(parent
)
19 ctl
= SelectCommitsController(model
, view
)
20 return ctl
.select_commits()
22 class SelectCommitsController(QObserver
):
23 def __init__(self
, model
, view
):
24 QObserver
.__init
__(self
, model
, view
)
25 self
.connect(view
.commitList
, 'itemSelectionChanged()',
26 self
.commit_sha1_selected
)
28 def select_commits(self
):
29 summaries
= self
.model
.get_summaries()
31 msg
= self
.tr('No commits exist in this branch.')
35 qtutils
.set_items(self
.view
.commitList
, summaries
)
38 result
= self
.view
.exec_()
39 if result
!= QDialog
.Accepted
: return([],[])
41 revs
= self
.model
.get_revisions()
42 list_widget
= self
.view
.commitList
43 selection
= qtutils
.get_selection_list(list_widget
, revs
)
44 if not selection
: return([],[])
46 # also return the selected index numbers
47 index_nums
= range(len(revs
))
48 idxs
= qtutils
.get_selection_list(list_widget
, index_nums
)
50 return(selection
, idxs
)
52 def commit_sha1_selected(self
):
53 row
, selected
= qtutils
.get_selected_row(self
.view
.commitList
)
55 self
.view
.commitText
.setText('')
56 self
.view
.revisionLine
.setText('')
59 # Get the sha1 and put it in the revision line
60 sha1
= self
.model
.get_revision_sha1(row
)
61 self
.view
.revisionLine
.setText(sha1
)
62 self
.view
.revisionLine
.selectAll()
64 # Lookup the sha1's commit
65 commit_diff
= self
.model
.get_commit_diff(sha1
)
66 self
.view
.commitText
.setText(commit_diff
)
68 # Copy the sha1 into the clipboard
69 qtutils
.set_clipboard(sha1
)