text: defer calls to setStyleSheet()
[git-cola.git] / cola / widgets / gitignore.py
blobdba8f8a1adfe9eb798f4f3989005e0b5fd0ebd10
1 """Provides the StashView dialog."""
2 from __future__ import division, absolute_import, unicode_literals
4 from qtpy import QtCore
5 from qtpy import QtWidgets
7 from .. import cmds
8 from .. import qtutils
9 from ..i18n import N_
10 from . import defs
11 from .standard import Dialog
14 def gitignore_view(context):
15 """Launches a gitignore dialog
16 """
17 view = AddToGitIgnore(context, parent=qtutils.active_window())
18 view.show()
19 return view
22 class AddToGitIgnore(Dialog):
24 def __init__(self, context, parent=None):
25 Dialog.__init__(self, parent=parent)
26 self.context = context
27 self.selection = context.selection
28 if parent is not None:
29 self.setWindowModality(QtCore.Qt.WindowModal)
30 self.setWindowTitle(N_('Add to .gitignore'))
32 # Create text
33 self.text_description = QtWidgets.QLabel()
34 self.text_description.setText(N_('Ignore filename or pattern'))
36 # Create edit filename
37 self.edit_filename = QtWidgets.QLineEdit()
38 self.check_filename()
40 self.filename_layt = qtutils.vbox(defs.no_margin, defs.spacing,
41 self.text_description,
42 self.edit_filename)
44 # Create radio options
45 self.radio_filename = qtutils.radio(text=N_('Ignore exact filename'),
46 checked=True)
47 self.radio_pattern = qtutils.radio(text=N_('Ignore custom pattern'))
49 self.radio_layt = qtutils.vbox(defs.no_margin, defs.spacing,
50 self.radio_filename, self.radio_pattern)
52 # Create buttons
53 self.button_apply = qtutils.ok_button(text=N_('Add'))
54 self.button_close = qtutils.close_button()
55 self.btn_layt = qtutils.hbox(defs.no_margin, defs.spacing,
56 qtutils.STRETCH,
57 self.button_close,
58 self.button_apply)
60 # Layout
61 self.main_layout = qtutils.vbox(defs.margin, defs.spacing,
62 self.radio_layt,
63 defs.button_spacing,
64 self.filename_layt,
65 qtutils.STRETCH,
66 self.btn_layt)
67 self.setLayout(self.main_layout)
69 # Connect actions
70 qtutils.connect_toggle(self.radio_pattern, self.check_pattern)
71 qtutils.connect_toggle(self.radio_filename, self.check_filename)
72 qtutils.connect_button(self.button_apply, self.apply)
73 qtutils.connect_button(self.button_close, self.close)
75 self.init_state(None, self.resize_widget, parent)
77 def resize_widget(self, parent):
78 """Set the initial size of the widget"""
79 width, height = qtutils.default_size(parent, 720, 400)
80 self.resize(width, max(400, height//2))
82 def check_pattern(self):
83 self.edit_filename.setDisabled(False)
85 def check_filename(self):
86 self.edit_filename.setText('/' + ';/'.join(self.selection.untracked))
87 self.edit_filename.setDisabled(True)
89 def close(self):
90 self.reject()
92 def apply(self):
93 context = self.context
94 cmds.do(cmds.Ignore, context, self.edit_filename.text().split(';'))
95 self.accept()