Skip to content

Commit f11e430

Browse files
committed
Use checkboxes in the FormActions UI to indicate which actions to run
1 parent 66a1041 commit f11e430

File tree

1 file changed

+29
-14
lines changed

1 file changed

+29
-14
lines changed

Form/formactions.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ class FormActions(object):
7373
"""
7474
Form Action selector.
7575
"""
76+
RUN_ACTION_COL = 0
77+
ACTION_COL = 1
78+
DETAIL_COL = 2
79+
ACTION_COMMAND_COL = 3
7680

7781
def __init__(self, dbstate, uistate, track, citation):
7882
self.dbstate = dbstate
@@ -117,12 +121,19 @@ def _create_dialog(self, title):
117121
box = Gtk.Box()
118122
top.vbox.pack_start(box, True, True, 5)
119123

120-
self.model = Gtk.TreeStore(str, str, GObject.TYPE_PYOBJECT)
124+
self.model = Gtk.TreeStore(bool, str, str, GObject.TYPE_PYOBJECT)
121125
self.tree = Gtk.TreeView(model=self.model)
122-
renderer = Gtk.CellRendererText()
123-
column1 = Gtk.TreeViewColumn(_("Action"), renderer, text=0)
124-
column1.set_sort_column_id(1)
125-
column2 = Gtk.TreeViewColumn(_("Detail"), renderer, text=1)
126+
renderer_text = Gtk.CellRendererText()
127+
column1 = Gtk.TreeViewColumn(_("Action"))
128+
renderer_action_toggle = Gtk.CellRendererToggle()
129+
renderer_action_toggle.connect('toggled', self.on_action_toggled)
130+
column1.pack_start(renderer_action_toggle, False)
131+
column1.add_attribute(renderer_action_toggle, 'active', self.RUN_ACTION_COL)
132+
column1.pack_start(renderer_text, True)
133+
column1.add_attribute(renderer_text, 'text', self.ACTION_COL)
134+
column1.set_cell_data_func(renderer_action_toggle, FormActions.action_data_func)
135+
136+
column2 = Gtk.TreeViewColumn(_("Detail"), renderer_text, text=self.DETAIL_COL)
126137
self.tree.append_column(column1)
127138
self.tree.append_column(column2)
128139

@@ -141,6 +152,12 @@ def _create_dialog(self, title):
141152

142153
return top
143154

155+
def on_action_toggled(self, widget, path):
156+
self.model[path][self.RUN_ACTION_COL] = not self.model[path][self.RUN_ACTION_COL]
157+
158+
def action_data_func(col, cell, model, iter, user_data):
159+
cell.set_property("visible", model.get_value(iter, FormActions.ACTION_COMMAND_COL))
160+
144161
def _populate_model(self):
145162
form_id = get_form_id(self.source)
146163
if self.actions_module:
@@ -151,9 +168,9 @@ def _populate_model(self):
151168
action = (action_class[1])()
152169
(title, action_details) = action.get_actions(self.dbstate, self.citation, self.event)
153170
if action_details:
154-
parent = self.model.append(None, (title, None, None))
171+
parent = self.model.append(None, (False, title, None, None))
155172
for action_detail in action_details:
156-
self.model.append(parent, action_detail)
173+
self.model.append(parent, (False, ) + action_detail)
157174

158175
def run(self):
159176
"""
@@ -177,13 +194,11 @@ def run(self):
177194
self._config.save()
178195

179196
# run the selected actions
180-
(model, pathlist) = self.tree.get_selection().get_selected_rows()
181-
for path in pathlist :
182-
tree_iter = model.get_iter(path)
183-
184-
command = model.get_value(tree_iter, 2)
185-
if command:
186-
(command)(self.dbstate, self.uistate, self.track)
197+
for action_type_row in self.model:
198+
for action_row in action_type_row.iterchildren():
199+
if action_row.model.get_value(action_row.iter, self.RUN_ACTION_COL):
200+
command = action_row.model.get_value(action_row.iter, self.ACTION_COMMAND_COL)
201+
(command)(self.dbstate, self.uistate, self.track)
187202

188203
self.top.destroy()
189204

0 commit comments

Comments
 (0)