@@ -74,9 +74,10 @@ class FormActions(object):
74
74
Form Action selector.
75
75
"""
76
76
RUN_ACTION_COL = 0
77
- ACTION_COL = 1
78
- DETAIL_COL = 2
79
- ACTION_COMMAND_COL = 3
77
+ RUN_INCONSISTENT_COL = 1
78
+ ACTION_COL = 2
79
+ DETAIL_COL = 3
80
+ ACTION_COMMAND_COL = 4
80
81
81
82
def __init__ (self , dbstate , uistate , track , citation ):
82
83
self .dbstate = dbstate
@@ -121,17 +122,17 @@ def _create_dialog(self, title):
121
122
box = Gtk .Box ()
122
123
top .vbox .pack_start (box , True , True , 5 )
123
124
124
- self .model = Gtk .TreeStore (bool , str , str , GObject .TYPE_PYOBJECT )
125
+ self .model = Gtk .TreeStore (bool , bool , str , str , GObject .TYPE_PYOBJECT )
125
126
self .tree = Gtk .TreeView (model = self .model )
126
127
renderer_text = Gtk .CellRendererText ()
127
128
column1 = Gtk .TreeViewColumn (_ ("Action" ))
128
129
renderer_action_toggle = Gtk .CellRendererToggle ()
129
130
renderer_action_toggle .connect ('toggled' , self .on_action_toggled )
130
131
column1 .pack_start (renderer_action_toggle , False )
131
132
column1 .add_attribute (renderer_action_toggle , 'active' , self .RUN_ACTION_COL )
133
+ column1 .add_attribute (renderer_action_toggle , 'inconsistent' , self .RUN_INCONSISTENT_COL )
132
134
column1 .pack_start (renderer_text , True )
133
135
column1 .add_attribute (renderer_text , 'text' , self .ACTION_COL )
134
- column1 .set_cell_data_func (renderer_action_toggle , FormActions .action_data_func )
135
136
136
137
column2 = Gtk .TreeViewColumn (_ ("Detail" ), renderer_text , text = self .DETAIL_COL )
137
138
self .tree .append_column (column1 )
@@ -153,10 +154,39 @@ def _create_dialog(self, title):
153
154
return top
154
155
155
156
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 ))
157
+ row_iter = self .model .get_iter (path )
158
+ parent = self .model .iter_parent (row_iter )
159
+ if not parent :
160
+ # user clicked an action category row. toggle all children
161
+ new_state = not self .model [row_iter ][self .RUN_ACTION_COL ]
162
+ child = self .model .iter_children (row_iter )
163
+ while child :
164
+ self .model [child ][self .RUN_ACTION_COL ] = new_state
165
+ child = self .model .iter_next (child )
166
+ # all children are now consistent
167
+ self .model [row_iter ][self .RUN_INCONSISTENT_COL ] = False
168
+ # toggle RUN_ACTION_COL for the row that was clicked
169
+ self .model [row_iter ][self .RUN_ACTION_COL ] = not self .model [row_iter ][self .RUN_ACTION_COL ]
170
+ if parent :
171
+ # update the status of the parent
172
+ (consistent , value ) = FormActions .all_children_consistent (self .model , parent , FormActions .RUN_ACTION_COL )
173
+ self .model [parent ][self .RUN_INCONSISTENT_COL ] = not consistent
174
+ self .model [parent ][self .RUN_ACTION_COL ] = consistent and value
175
+
176
+ def all_children_consistent (model , parent , col ):
177
+ consistent = True
178
+ value = False
179
+ child = model .iter_children (parent )
180
+ if child : # handle case of no children
181
+ # start with value of first child
182
+ value = model .get_value (child , col )
183
+ # advance to second child (if there is one)
184
+ child = model .iter_next (child )
185
+ # loop over all remaining children until we find an inconsistent value or reach the end
186
+ while consistent and child :
187
+ consistent = model .get_value (child , col ) == value
188
+ child = model .iter_next (child )
189
+ return (consistent , value )
160
190
161
191
def _populate_model (self ):
162
192
form_id = get_form_id (self .source )
@@ -168,9 +198,11 @@ def _populate_model(self):
168
198
action = (action_class [1 ])()
169
199
(title , action_details ) = action .get_actions (self .dbstate , self .citation , self .event )
170
200
if action_details :
171
- parent = self .model .append (None , (False , title , None , None ))
201
+ # add the action category
202
+ parent = self .model .append (None , (False , False , title , None , None ))
172
203
for action_detail in action_details :
173
- self .model .append (parent , (False , ) + action_detail )
204
+ # add available actions within this category
205
+ self .model .append (parent , (False , False ) + action_detail )
174
206
175
207
def run (self ):
176
208
"""
0 commit comments