dag: rename `text` to `rev_text`
[git-cola.git] / cola / widgets / createtag.py
bloba9ebd393ddc6dc48a79f64119ca931cf8e25b3ac
1 from __future__ import absolute_import, division, print_function, unicode_literals
3 from qtpy import QtWidgets
4 from qtpy.QtCore import Qt
6 from .. import cmds
7 from .. import icons
8 from .. import qtutils
9 from ..i18n import N_
10 from ..qtutils import get
11 from . import defs
12 from . import completion
13 from . import standard
14 from . import text
17 def new_create_tag(context, name='', ref='', sign=False, parent=None):
18 """Entry point for external callers."""
19 opts = TagOptions(name, ref, sign)
20 view = CreateTag(context, opts, parent=parent)
21 return view
24 def create_tag(context, name='', ref='', sign=False):
25 """Entry point for external callers."""
26 view = new_create_tag(
27 context,
28 name=name,
29 ref=ref,
30 sign=sign,
31 parent=qtutils.active_window(),
33 view.show()
34 view.raise_()
35 return view
38 class TagOptions(object):
39 """Simple data container for the CreateTag dialog."""
41 def __init__(self, name, ref, sign):
42 self.name = name or ''
43 self.ref = ref or 'HEAD'
44 self.sign = sign
47 class CreateTag(standard.Dialog):
48 def __init__(self, context, opts, parent=None):
49 standard.Dialog.__init__(self, parent=parent)
51 self.context = context
52 self.model = model = context.model
53 self.opts = opts
55 self.setWindowTitle(N_('Create Tag'))
56 if parent is not None:
57 self.setWindowModality(Qt.WindowModal)
59 # Tag label
60 self.tag_name_label = QtWidgets.QLabel(self)
61 self.tag_name_label.setText(N_('Name'))
63 self.tag_name = text.HintedLineEdit(context, N_('vX.Y.Z'), parent=self)
64 self.tag_name.set_value(opts.name)
65 self.tag_name.setToolTip(N_('Specifies the tag name'))
67 qtutils.add_completer(self.tag_name, model.tags)
69 # Sign Tag
70 self.sign_label = QtWidgets.QLabel(self)
71 self.sign_label.setText(N_('Sign Tag'))
73 tooltip = N_('Whether to sign the tag (git tag -s)')
74 self.sign_tag = qtutils.checkbox(checked=True, tooltip=tooltip)
76 # Tag message
77 self.tag_msg_label = QtWidgets.QLabel(self)
78 self.tag_msg_label.setText(N_('Message'))
80 self.tag_msg = text.HintedPlainTextEdit(context, N_('Tag message...'), self)
81 self.tag_msg.setToolTip(N_('Specifies the tag message'))
82 # Revision
83 self.rev_label = QtWidgets.QLabel(self)
84 self.rev_label.setText(N_('Revision'))
86 self.revision = completion.GitRefLineEdit(context)
87 self.revision.setText(self.opts.ref)
88 self.revision.setToolTip(N_('Specifies the SHA-1 to tag'))
89 # Buttons
90 self.create_button = qtutils.create_button(
91 text=N_('Create Tag'), icon=icons.tag(), default=True
93 self.close_button = qtutils.close_button()
95 # Form layout for inputs
96 self.input_layout = qtutils.form(
97 defs.margin,
98 defs.spacing,
99 (self.tag_name_label, self.tag_name),
100 (self.tag_msg_label, self.tag_msg),
101 (self.rev_label, self.revision),
102 (self.sign_label, self.sign_tag),
105 self.button_layout = qtutils.hbox(
106 defs.no_margin,
107 defs.button_spacing,
108 qtutils.STRETCH,
109 self.close_button,
110 self.create_button,
113 self.main_layt = qtutils.vbox(
114 defs.margin, defs.spacing, self.input_layout, self.button_layout
116 self.setLayout(self.main_layt)
118 qtutils.connect_button(self.close_button, self.close)
119 qtutils.connect_button(self.create_button, self.create_tag)
121 settings = context.settings
122 self.init_state(settings, self.resize, defs.scale(720), defs.scale(210))
124 def create_tag(self):
125 """Verifies inputs and emits a notifier tag message."""
127 context = self.context
128 revision = get(self.revision)
129 tag_name = get(self.tag_name)
130 tag_msg = get(self.tag_msg)
131 sign_tag = get(self.sign_tag)
133 ok = cmds.do(
134 cmds.Tag, context, tag_name, revision, sign=sign_tag, message=tag_msg
136 if ok:
137 self.close()