2 from PyQt4
import QtGui
3 from PyQt4
.QtCore
import SIGNAL
8 from cola
import qtutils
9 from cola
import signals
10 from cola
import gitcfg
11 from cola
import gitcmds
12 from cola
.qtutils
import SLOT
13 from cola
.views
import revselect
14 from cola
.views
import standard
17 def install_command_wrapper(parent
):
18 cmd_wrapper
= ActionCommandWrapper(parent
)
19 cola
.factory().add_command_wrapper(cmd_wrapper
)
22 def install_config_actions(menu
):
23 cfg
= gitcfg
.instance()
24 names
= cfg
.get_guitool_names()
29 menu
.addAction(name
, SLOT(signals
.run_config_action
, name
))
32 class ActionCommandWrapper(object):
33 def __init__(self
, parent
):
36 signals
.run_config_action
: self
._run
_config
_action
,
39 def _run_config_action(self
, name
, opts
):
40 dlg
= ActionDialog(self
.parent
, name
, opts
)
42 if dlg
.exec_() != QtGui
.QDialog
.Accepted
:
44 rev
= unicode(dlg
.revision())
46 opts
['revision'] = rev
47 args
= unicode(dlg
.args())
53 class ActionDialog(standard
.StandardDialog
):
54 def __init__(self
, parent
, name
, opts
):
55 standard
.StandardDialog
.__init
__(self
, parent
)
59 self
.layt
= QtGui
.QVBoxLayout()
60 self
.layt
.setMargin(10)
61 self
.setLayout(self
.layt
)
63 cmd
= self
.opts
.get('cmd')
64 title
= self
.opts
.get('title')
66 self
.setWindowTitle(os
.path
.expandvars(title
))
68 self
.prompt
= QtGui
.QLabel()
70 prompt
= self
.opts
.get('prompt')
72 self
.prompt
.setText(os
.path
.expandvars(prompt
))
73 self
.layt
.addWidget(self
.prompt
)
76 self
.argslabel
= QtGui
.QLabel()
77 argprompt
= self
.opts
.get('argprompt', i18n
.gettext('Arguments'))
78 self
.argslabel
.setText(argprompt
)
80 self
.argstxt
= QtGui
.QLineEdit()
81 self
.argslayt
= QtGui
.QHBoxLayout()
82 self
.argslayt
.addWidget(self
.argslabel
)
83 self
.argslayt
.addWidget(self
.argstxt
)
84 self
.layt
.addLayout(self
.argslayt
)
86 if not self
.opts
.get('argprompt'):
87 self
.argslabel
.setMinimumSize(1, 1)
88 self
.argstxt
.setMinimumSize(1, 1)
92 ('Local Branch', gitcmds
.branch_list(remote
=False)),
93 ('Tracking Branch', gitcmds
.branch_list(remote
=True)),
94 ('Tag', gitcmds
.tag_list()),
96 revprompt
= self
.opts
.get('revprompt', i18n
.gettext('Revision'))
97 self
.revselect
= revselect
.RevisionSelector(self
, revs
=revs
)
98 self
.revselect
.set_revision_label(revprompt
)
99 self
.layt
.addWidget(self
.revselect
)
100 if not opts
.get('revprompt'):
101 self
.revselect
.hide()
104 self
.btnlayt
= QtGui
.QHBoxLayout()
105 self
.btnspacer
= QtGui
.QSpacerItem(1, 1,
106 QtGui
.QSizePolicy
.MinimumExpanding
,
107 QtGui
.QSizePolicy
.Minimum
)
108 self
.btnlayt
.addItem(self
.btnspacer
)
109 self
.closebtn
= qt
.create_button(self
.tr('Close'), self
.btnlayt
)
110 self
.runbtn
= qt
.create_button(self
.tr('Run'), self
.btnlayt
)
111 self
.runbtn
.setDefault(True)
112 self
.layt
.addLayout(self
.btnlayt
)
114 self
.connect(self
.closebtn
, SIGNAL('clicked()'), self
.reject
)
115 self
.connect(self
.runbtn
, SIGNAL('clicked()'), self
.accept
)
117 # Widen the dialog by default
118 self
.resize(666, self
.height())
121 return self
.revselect
.revision()
124 return self
.argstxt
.text()