Skip to content

Commit 263db4c

Browse files
committed
Add UI elements to allow user to select which actions they wish to edit
1 parent 52c52de commit 263db4c

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Form/formactions.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ class FormActions(object):
9595
DETAIL_COL = 3
9696
CAN_EDIT_DETAIL_COL = 4 # actionutils.CANNOT_EDIT_DETAIL, actionutils.CAN_EDIT_DETAIL or actionutils.MUST_EDIT_DETAIL
9797
ACTION_COMMAND_COL = 5
98+
EDIT_DETAIL_COL = 6
9899

99100
def __init__(self, dbstate, uistate, track, citation):
100101
self.dbstate = dbstate
@@ -154,7 +155,7 @@ def _create_dialog(self, title):
154155
top.vbox.pack_start(box, True, True, 5)
155156

156157
self.model = Gtk.TreeStore(
157-
bool, bool, str, str, int, GObject.TYPE_PYOBJECT)
158+
bool, bool, str, str, int, GObject.TYPE_PYOBJECT, bool)
158159
self.tree = Gtk.TreeView(model=self.model)
159160
renderer_text = Gtk.CellRendererText()
160161
column1 = Gtk.TreeViewColumn(_("Action"))
@@ -168,10 +169,20 @@ def _create_dialog(self, title):
168169
column1.pack_start(renderer_text, True)
169170
column1.add_attribute(renderer_text, 'text', self.ACTION_COL)
170171

172+
render_edit_detail_toggle = Gtk.CellRendererToggle()
173+
render_edit_detail_toggle.connect(
174+
"toggled", self.on_edit_detail_toggled)
171175
column2 = Gtk.TreeViewColumn(
176+
_("Edit"), render_edit_detail_toggle, active=self.EDIT_DETAIL_COL)
177+
column2.set_cell_data_func(
178+
render_edit_detail_toggle, FormActions.detail_data_func)
179+
180+
column3 = Gtk.TreeViewColumn(
172181
_("Detail"), renderer_text, text=self.DETAIL_COL)
182+
173183
self.tree.append_column(column1)
174184
self.tree.append_column(column2)
185+
self.tree.append_column(column3)
175186

176187
self.tree.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE)
177188

@@ -210,6 +221,18 @@ def on_action_toggled(self, widget, path):
210221
self.model[parent][self.RUN_INCONSISTENT_COL] = not consistent
211222
self.model[parent][self.RUN_ACTION_COL] = consistent and value
212223

224+
@staticmethod
225+
def detail_data_func(col, cell, model, iter, user_data):
226+
can_edit_detail = model.get_value(
227+
iter, FormActions.CAN_EDIT_DETAIL_COL)
228+
cell.set_property("visible", can_edit_detail !=
229+
actionutils.CANNOT_EDIT_DETAIL)
230+
cell.set_property("activatable", (can_edit_detail != actionutils.MUST_EDIT_DETAIL) and (
231+
model.get_value(iter, FormActions.RUN_ACTION_COL)))
232+
233+
def on_edit_detail_toggled(self, widget, path):
234+
self.model[path][self.EDIT_DETAIL_COL] = not self.model[path][self.EDIT_DETAIL_COL]
235+
213236
@staticmethod
214237
def all_children_consistent(model, parent, col):
215238
consistent = True
@@ -240,7 +263,7 @@ def _populate_model(self):
240263
for action_detail in actions:
241264
# add available actions within this category
242265
self.model.append(
243-
parent, (False, False) + action_detail)
266+
parent, (False, False) + action_detail + (action_detail[2] == actionutils.MUST_EDIT_DETAIL,))
244267

245268
def run(self):
246269
"""

0 commit comments

Comments
 (0)