summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-04-03 14:23:50 -0700
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2019-07-10 20:55:02 +0200
commit4e4210b0f349e08cf71a71c3e4a72f65cfd2535e (patch)
tree4762d17b6a61f1ff1af7b0bef16c30566ea1f11d /src/lib/ecore
parentbe37c47fff3a7baba486c927a5224bec528c1a96 (diff)
ecore: improve usability of Efl.Select_Model to provide helpers in manipulating selection information.
Reviewed-by: Marcel Hollerbach <mail@marcel-hollerbach.de> Differential Revision: https://phab.enlightenment.org/D8570
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_select_model.c52
-rw-r--r--src/lib/ecore/efl_select_model.eo23
2 files changed, 61 insertions, 14 deletions
diff --git a/src/lib/ecore/efl_select_model.c b/src/lib/ecore/efl_select_model.c
index 52100e681c..1140fbf0f3 100644
--- a/src/lib/ecore/efl_select_model.c
+++ b/src/lib/ecore/efl_select_model.c
@@ -18,7 +18,7 @@ struct _Efl_Select_Model_Data
18 Efl_Select_Model_Data *parent; 18 Efl_Select_Model_Data *parent;
19 unsigned long last; 19 unsigned long last;
20 20
21 Eina_Bool exclusive : 1; 21 Eina_Bool single_selection : 1;
22 Eina_Bool none : 1; 22 Eina_Bool none : 1;
23}; 23};
24 24
@@ -247,7 +247,7 @@ _efl_select_model_efl_model_properties_get(const Eo *obj,
247 EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props, 247 EFL_COMPOSITE_MODEL_PROPERTIES_SUPER(props,
248 obj, EFL_SELECT_MODEL_CLASS, 248 obj, EFL_SELECT_MODEL_CLASS,
249 NULL, 249 NULL,
250 "self.selected", "child.selected", "exclusive"); 250 "self.selected", "child.selected", "single_selection");
251 return props; 251 return props;
252} 252}
253 253
@@ -258,19 +258,19 @@ _efl_select_model_efl_model_property_set(Eo *obj,
258{ 258{
259 Eina_Value vf = EINA_VALUE_EMPTY; 259 Eina_Value vf = EINA_VALUE_EMPTY;
260 260
261 if (!strcmp("exclusive", property)) 261 if (!strcmp("single_selection", property))
262 { 262 {
263 Eina_Bool exclusive = pd->exclusive; 263 Eina_Bool single_selection = pd->single_selection;
264 Eina_Bool changed; 264 Eina_Bool changed;
265 265
266 vf = eina_value_bool_init(exclusive); 266 vf = eina_value_bool_init(single_selection);
267 eina_value_convert(value, &vf); 267 eina_value_convert(value, &vf);
268 eina_value_bool_get(&vf, &exclusive); 268 eina_value_bool_get(&vf, &single_selection);
269 269
270 changed = (!pd->exclusive != !exclusive); 270 changed = (!pd->single_selection != !single_selection);
271 pd->exclusive = !!exclusive; 271 pd->single_selection = !!single_selection;
272 272
273 if (changed) efl_model_properties_changed(obj, "exclusive"); 273 if (changed) efl_model_properties_changed(obj, "single_selection");
274 274
275 return efl_loop_future_resolved(obj, vf); 275 return efl_loop_future_resolved(obj, vf);
276 } 276 }
@@ -291,7 +291,7 @@ _efl_select_model_efl_model_property_set(Eo *obj,
291 if (pd->parent && !strcmp("self.selected", property)) 291 if (pd->parent && !strcmp("self.selected", property))
292 { 292 {
293 Eina_Bool prevflag = EINA_FALSE, newflag = EINA_FALSE; 293 Eina_Bool prevflag = EINA_FALSE, newflag = EINA_FALSE;
294 Eina_Bool exclusive = EINA_FALSE; 294 Eina_Bool single_selection = EINA_FALSE;
295 Eina_Bool success; 295 Eina_Bool success;
296 Eina_Value *prev; 296 Eina_Value *prev;
297 Eina_Future *chain; 297 Eina_Future *chain;
@@ -306,14 +306,14 @@ _efl_select_model_efl_model_property_set(Eo *obj,
306 if (newflag == prevflag) 306 if (newflag == prevflag)
307 return efl_loop_future_resolved(obj, eina_value_bool_init(newflag)); 307 return efl_loop_future_resolved(obj, eina_value_bool_init(newflag));
308 308
309 exclusive = pd->parent->exclusive; 309 single_selection = pd->parent->single_selection;
310 310
311 // First store the new value in the boolean model we inherit from 311 // First store the new value in the boolean model we inherit from
312 chain = efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS), 312 chain = efl_model_property_set(efl_super(obj, EFL_SELECT_MODEL_CLASS),
313 "selected", value); 313 "selected", value);
314 314
315 // Now act ! 315 // Now act !
316 if (exclusive) 316 if (single_selection)
317 { 317 {
318 // We are here either, because we weren't and are after this call 318 // We are here either, because we weren't and are after this call
319 // or because we were selected and are not anymore. In the later case, 319 // or because we were selected and are not anymore. In the later case,
@@ -364,8 +364,8 @@ _efl_select_model_efl_model_property_set(Eo *obj,
364static Eina_Value * 364static Eina_Value *
365_efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *pd, const char *property) 365_efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *pd, const char *property)
366{ 366{
367 if (!strcmp("exclusive", property)) 367 if (!strcmp("single_selection", property))
368 return eina_value_bool_new(pd->exclusive); 368 return eina_value_bool_new(pd->single_selection);
369 // Last selected child 369 // Last selected child
370 if (!strcmp("child.selected", property)) 370 if (!strcmp("child.selected", property))
371 { 371 {
@@ -383,4 +383,28 @@ _efl_select_model_efl_model_property_get(const Eo *obj, Efl_Select_Model_Data *p
383 return efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), property); 383 return efl_model_property_get(efl_super(obj, EFL_SELECT_MODEL_CLASS), property);
384} 384}
385 385
386static void
387_efl_select_model_single_selection_set(Eo *obj EINA_UNUSED, Efl_Select_Model_Data *pd, Eina_Bool enable)
388{
389 pd->single_selection = enable;
390}
391
392static Eina_Bool
393_efl_select_model_single_selection_get(const Eo *obj EINA_UNUSED, Efl_Select_Model_Data *pd)
394{
395 return pd->single_selection;
396}
397
398static Eina_Iterator *
399_efl_select_model_selected_get(Eo *obj, Efl_Select_Model_Data *pd EINA_UNUSED)
400{
401 return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_TRUE);
402}
403
404static Eina_Iterator *
405_efl_select_model_unselected_get(Eo *obj, Efl_Select_Model_Data *pd EINA_UNUSED)
406{
407 return efl_boolean_model_boolean_iterator_get(obj, "selected", EINA_FALSE);
408}
409
386#include "efl_select_model.eo.c" 410#include "efl_select_model.eo.c"
diff --git a/src/lib/ecore/efl_select_model.eo b/src/lib/ecore/efl_select_model.eo
index ed7821fa68..0d21db3c33 100644
--- a/src/lib/ecore/efl_select_model.eo
+++ b/src/lib/ecore/efl_select_model.eo
@@ -1,6 +1,29 @@
1class @beta Efl.Select_Model extends Efl.Boolean_Model 1class @beta Efl.Select_Model extends Efl.Boolean_Model
2{ 2{
3 [[Efl select model class]] 3 [[Efl select model class]]
4 methods {
5 selected_get {
6 [[Get an iterator of all the selected child of this model.
7 ]]
8 return: iterator<uint64>; [[The iterator give indexes of selected child. It is valid until any change is made on the model.]]
9 }
10 unselected_get {
11 [[Get an iterator of all the child of this model that are not selected.
12 ]]
13 return: iterator<uint64>; [[The iterator give indexes of unselected child. It is valid until any change is made on the model.]]
14 }
15 @property single_selection {
16 [[Define if we support only one exclusive selection at a time when set to $true.
17
18 If disable with $false, it will have the behavior of a multi select mode.
19 ]]
20 set { }
21 get { }
22 values {
23 enable: bool; [[$true will enable the exclusive mode.]]
24 }
25 }
26 }
4 implements { 27 implements {
5 Efl.Object.constructor; 28 Efl.Object.constructor;
6 Efl.Model.property { get; set; } 29 Efl.Model.property { get; set; }