]> git.tdb.fi Git - libs/gltk.git/commitdiff
Add a selection_cleared signal to List
authorMikko Rasa <tdb@tdb.fi>
Fri, 6 Mar 2015 00:03:34 +0000 (02:03 +0200)
committerMikko Rasa <tdb@tdb.fi>
Fri, 6 Mar 2015 00:03:34 +0000 (02:03 +0200)
source/dropdown.cpp
source/dropdown.h
source/list.cpp
source/list.h

index e48303317b809601514ce71db7dded49dffbc068..5b1d19b4f4d6c04576e76a9a015b945b0a956a93 100644 (file)
@@ -62,13 +62,6 @@ void Dropdown::autosize_special(const Part &part, Geometry &ageom) const
        }
 }
 
-void Dropdown::set_selected_index(int index)
-{
-       list.set_selected_index(index);
-       if(index<0)
-               text.set(string());
-}
-
 void Dropdown::rebuild_special(const Part &part)
 {
        if(part.get_name()=="text")
index 24c62cf862254136bcf0de2ed112ecc81b55882e..ad8b4619bc4a00789e6bd53ab6ac6dae3ba83829 100644 (file)
@@ -49,7 +49,7 @@ public:
        template<typename T>
        void set_item_type() { list.set_item_type<T>(); }
 
-       void set_selected_index(int);
+       void set_selected_index(int i) { list.set_selected_index(i); }
        int get_selected_index() const { return list.get_selected_index(); }
 
 private:
index f61d7c26dec8f3ba194058050a4411f423e6e646..0f887f3a6641316a6610da9f403a4bc5abefb7f4 100644 (file)
@@ -147,13 +147,16 @@ void List::set_selected_index(int i)
        if(i>=static_cast<int>(data->size()))
                throw out_of_range("List::set_selected_index");
 
-       if(i==sel_index)
+       if(i==sel_index || (i<0 && sel_index<0))
                return;
 
        if(sel_index>=0)
                items[sel_index]->set_active(false);
        if(i<0)
+       {
                sel_index = -1;
+               signal_selection_cleared.emit();
+       }
        else
        {
                sel_index = i;
@@ -312,6 +315,7 @@ void List::DataObserver::item_added(unsigned i)
 
 void List::DataObserver::item_removed(unsigned i)
 {
+       bool had_selection = (list.sel_index>=0);
        if(list.sel_index>static_cast<int>(i))
                --list.sel_index;
        else if(list.sel_index==static_cast<int>(i))
@@ -320,6 +324,9 @@ void List::DataObserver::item_removed(unsigned i)
        delete list.items[i];
        list.items.erase(list.items.begin()+i);
        list.items_changed();
+
+       if(had_selection && list.sel_index<0)
+               list.signal_selection_cleared.emit();
 }
 
 void List::DataObserver::cleared()
@@ -329,6 +336,8 @@ void List::DataObserver::cleared()
                delete *i;
        list.items.clear();
        list.items_changed();
+
+       list.signal_selection_cleared.emit();
 }
 
 void List::DataObserver::refresh_item(unsigned i)
index 8e9a851ca23d8c9dc9bf8e2107c565c1175ea77a..246a7294d6da99e457d81d6f0e529bb78e4fbf67 100644 (file)
@@ -130,6 +130,7 @@ private:
 
 public:
        sigc::signal<void, unsigned> signal_item_selected;
+       sigc::signal<void> signal_selection_cleared;
 
 private:
        ListData *data;