1 """Provides the StashView dialog."""
2 from __future__
import division
, absolute_import
, unicode_literals
4 from qtpy
import QtCore
5 from qtpy
import QtWidgets
11 from .standard
import Dialog
14 def gitignore_view(context
):
15 """Launches a gitignore dialog
17 view
= AddToGitIgnore(context
, parent
=qtutils
.active_window())
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'))
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()
40 self
.filename_layt
= qtutils
.vbox(defs
.no_margin
, defs
.spacing
,
41 self
.text_description
,
44 # Create radio options
45 self
.radio_filename
= qtutils
.radio(text
=N_('Ignore exact filename'),
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
)
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
,
61 self
.main_layout
= qtutils
.vbox(defs
.margin
, defs
.spacing
,
67 self
.setLayout(self
.main_layout
)
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)
93 context
= self
.context
94 cmds
.do(cmds
.Ignore
, context
, self
.edit_filename
.text().split(';'))