1 from PyQt4
import QtGui
2 from PyQt4
import QtCore
3 from PyQt4
.QtCore
import Qt
7 from cola
import qtutils
8 from cola
import signals
9 from cola
.prefs
import diff_font
10 from cola
.qtutils
import connect_button
11 from cola
.qtutils
import critical
12 from cola
.qtutils
import information
13 from cola
.widgets
import completion
14 from cola
.widgets
import standard
15 from cola
.widgets
import text
18 def create_tag(revision
=''):
19 """Entry point for external callers."""
20 opts
= TagOptions(revision
)
21 view
= CreateTag(opts
, qtutils
.active_window())
27 class TagOptions(object):
28 """Simple data container for the CreateTag dialog."""
30 def __init__(self
, revision
):
31 self
.revision
= revision
or 'HEAD'
34 class CreateTag(standard
.Dialog
):
35 def __init__(self
, opts
, parent
):
36 standard
.Dialog
.__init
__(self
, parent
=parent
)
37 self
.setWindowModality(QtCore
.Qt
.WindowModal
)
38 self
.setAttribute(Qt
.WA_MacMetalStyle
)
39 self
.setWindowTitle(self
.tr('Create Tag'))
43 self
.main_layt
= QtGui
.QVBoxLayout(self
)
44 self
.main_layt
.setContentsMargins(6, 12, 6, 6)
46 # Form layout for inputs
47 self
.input_form_layt
= QtGui
.QFormLayout()
48 self
.input_form_layt
.setFieldGrowthPolicy(QtGui
.QFormLayout
.ExpandingFieldsGrow
)
51 self
.tag_name_label
= QtGui
.QLabel(self
)
52 self
.tag_name_label
.setText(self
.tr('Name'))
53 self
.input_form_layt
.setWidget(0, QtGui
.QFormLayout
.LabelRole
,
56 self
.tag_name
= text
.HintedLineEdit('vX.Y.Z', self
)
57 self
.tag_name
.setToolTip(self
.tr('Specifies the tag name'))
58 self
.input_form_layt
.setWidget(0, QtGui
.QFormLayout
.FieldRole
,
62 self
.sign_label
= QtGui
.QLabel(self
)
63 self
.sign_label
.setText(self
.tr('Sign Tag'))
64 self
.input_form_layt
.setWidget(1, QtGui
.QFormLayout
.LabelRole
,
67 self
.sign_tag
= QtGui
.QCheckBox(self
)
68 self
.sign_tag
.setToolTip(
69 self
.tr('Whether to sign the tag (git tag -s)'))
70 self
.input_form_layt
.setWidget(1, QtGui
.QFormLayout
.FieldRole
,
72 self
.main_layt
.addLayout(self
.input_form_layt
)
75 self
.tag_msg_label
= QtGui
.QLabel(self
)
76 self
.tag_msg_label
.setText(self
.tr('Message'))
77 self
.input_form_layt
.setWidget(2, QtGui
.QFormLayout
.LabelRole
,
80 self
.tag_msg
= text
.HintedTextEdit('Tag message...', self
)
81 self
.tag_msg
.setToolTip(self
.tr('Specifies the tag message'))
82 self
.tag_msg
.enable_hint(True)
83 self
.input_form_layt
.setWidget(2, QtGui
.QFormLayout
.FieldRole
,
86 self
.rev_label
= QtGui
.QLabel(self
)
87 self
.rev_label
.setText(self
.tr('Revision'))
88 self
.input_form_layt
.setWidget(3, QtGui
.QFormLayout
.LabelRole
,
91 self
.revision
= completion
.GitRefLineEdit()
92 self
.revision
.setText(self
.opts
.revision
)
93 self
.revision
.setToolTip(self
.tr('Specifies the SHA-1 to tag'))
94 self
.input_form_layt
.setWidget(3, QtGui
.QFormLayout
.FieldRole
,
98 self
.button_hbox_layt
= QtGui
.QHBoxLayout()
99 self
.button_hbox_layt
.addStretch()
101 self
.create_button
= qt
.create_button(text
='Create Tag',
102 icon
=qtutils
.git_icon())
103 self
.button_hbox_layt
.addWidget(self
.create_button
)
104 self
.main_layt
.addLayout(self
.button_hbox_layt
)
106 self
.close_button
= qt
.create_button(text
='Close')
107 self
.button_hbox_layt
.addWidget(self
.close_button
)
109 connect_button(self
.close_button
, self
.accept
)
110 connect_button(self
.create_button
, self
.create_tag
)
112 self
.resize(506, 295)
114 def create_tag(self
):
115 """Verifies inputs and emits a notifier tag message."""
117 revision
= self
.revision
.value()
118 tag_name
= self
.tag_name
.value()
119 tag_msg
= self
.tag_msg
.value()
120 sign_tag
= self
.sign_tag
.isChecked()
123 critical('Missing Revision', 'Please specify a revision to tag.')
126 critical('Missing Name', 'Please specify a name for the new tag.')
128 elif (sign_tag
and not tag_msg
and
129 not qtutils
.confirm('Missing Tag Message',
130 'Tag-signing was requested but the tag '
132 'An unsigned, lightweight tag will be '
134 'Create an unsigned tag?',
135 'Create Unsigned Tag',
137 icon
=qtutils
.save_icon())):
140 cola
.notifier().broadcast(signals
.tag
, tag_name
, revision
,
141 sign
=sign_tag
, message
=tag_msg
)
142 information('Tag Created', 'Created a new tag named "%s"' % tag_name
,
143 details
=tag_msg
or None)