1 """Provides the StashView dialog."""
3 from qtpy
import QtCore
4 from qtpy
import QtWidgets
10 from .standard
import Dialog
13 def gitignore_view(context
):
14 """Launches a gitignore dialog"""
15 view
= AddToGitIgnore(context
, parent
=qtutils
.active_window())
20 class AddToGitIgnore(Dialog
):
21 def __init__(self
, context
, parent
=None):
22 Dialog
.__init
__(self
, parent
=parent
)
23 self
.context
= context
24 self
.selection
= context
.selection
25 if parent
is not None:
26 self
.setWindowModality(QtCore
.Qt
.WindowModal
)
27 self
.setWindowTitle(N_('Add to exclusions'))
30 self
.text_description
= QtWidgets
.QLabel()
31 self
.text_description
.setText(N_('Ignore filename or pattern'))
33 # Create edit filename
34 self
.edit_filename
= QtWidgets
.QLineEdit()
37 self
.filename_layt
= qtutils
.vbox(
38 defs
.no_margin
, defs
.spacing
, self
.text_description
, self
.edit_filename
41 # Create radio options
42 self
.radio_filename
= qtutils
.radio(
43 text
=N_('Ignore exact filename'), checked
=True
45 self
.radio_pattern
= qtutils
.radio(text
=N_('Ignore custom pattern'))
46 self
.name_radio_group
= qtutils
.buttongroup(
47 self
.radio_filename
, self
.radio_pattern
49 self
.name_radio_layt
= qtutils
.vbox(
50 defs
.no_margin
, defs
.spacing
, self
.radio_filename
, self
.radio_pattern
53 self
.radio_in_repo
= qtutils
.radio(text
=N_('Add to .gitignore'), checked
=True)
54 self
.radio_local
= qtutils
.radio(text
=N_('Add to local .git/info/exclude'))
55 self
.location_radio_group
= qtutils
.buttongroup(
56 self
.radio_in_repo
, self
.radio_local
58 self
.location_radio_layt
= qtutils
.vbox(
59 defs
.no_margin
, defs
.spacing
, self
.radio_in_repo
, self
.radio_local
63 self
.button_apply
= qtutils
.ok_button(text
=N_('Add'))
64 self
.button_close
= qtutils
.close_button()
65 self
.btn_layt
= qtutils
.hbox(
74 self
.main_layout
= qtutils
.vbox(
81 self
.location_radio_layt
,
85 self
.setLayout(self
.main_layout
)
88 qtutils
.connect_toggle(self
.radio_pattern
, self
.check_pattern
)
89 qtutils
.connect_toggle(self
.radio_filename
, self
.check_filename
)
90 qtutils
.connect_button(self
.button_apply
, self
.apply)
91 qtutils
.connect_button(self
.button_close
, self
.close
)
93 self
.init_state(None, self
.resize_widget
, parent
)
95 def resize_widget(self
, parent
):
96 """Set the initial size of the widget"""
97 width
, height
= qtutils
.default_size(parent
, 720, 400)
98 self
.resize(width
, max(400, height
// 2))
100 def check_pattern(self
):
101 self
.edit_filename
.setDisabled(False)
103 def check_filename(self
):
104 self
.edit_filename
.setText('/' + ';/'.join(self
.selection
.untracked
))
105 self
.edit_filename
.setDisabled(True)
111 context
= self
.context
115 self
.edit_filename
.text().split(';'),
116 self
.radio_local
.isChecked(),