Remove use of stringlists
This commit is contained in:
parent
5ba4205862
commit
546a54f6d7
|
@ -20,10 +20,6 @@ MainWin::MainWin()
|
||||||
drop_overlay.add_overlay(dropdown);
|
drop_overlay.add_overlay(dropdown);
|
||||||
drop_frame.set_child(drop_overlay);
|
drop_frame.set_child(drop_overlay);
|
||||||
|
|
||||||
// Create string list
|
|
||||||
dropdown_list = Gtk::StringList::create({"Longterm", "Stable", "Develop"});
|
|
||||||
dropdown.set_model(dropdown_list);
|
|
||||||
|
|
||||||
// Create List for column View
|
// Create List for column View
|
||||||
main_list = Gio::ListStore<ModelColumns>::create();
|
main_list = Gio::ListStore<ModelColumns>::create();
|
||||||
selection = Gtk::SingleSelection::create(main_list);
|
selection = Gtk::SingleSelection::create(main_list);
|
||||||
|
@ -34,6 +30,16 @@ MainWin::MainWin()
|
||||||
main_list->append(ModelColumns::create("Stable", "9.1"));
|
main_list->append(ModelColumns::create("Stable", "9.1"));
|
||||||
main_list->append(ModelColumns::create("Develop", "10.0"));
|
main_list->append(ModelColumns::create("Develop", "10.0"));
|
||||||
|
|
||||||
|
// Create string list
|
||||||
|
dropdown.set_model(main_list);
|
||||||
|
|
||||||
|
// Add factory for dropdown
|
||||||
|
drop_factory = Gtk::SignalListItemFactory::create();
|
||||||
|
drop_factory->signal_bind().connect(sigc::mem_fun(*this, &MainWin::bind_drop));
|
||||||
|
drop_factory->signal_setup().connect(sigc::mem_fun(*this, &MainWin::setup_drop));
|
||||||
|
dropdown.set_factory(drop_factory);
|
||||||
|
dropdown.set_list_factory(drop_factory);
|
||||||
|
|
||||||
// Add a factory to the branch column
|
// Add a factory to the branch column
|
||||||
branch_factory = Gtk::SignalListItemFactory::create();
|
branch_factory = Gtk::SignalListItemFactory::create();
|
||||||
branch_factory->signal_bind().connect(sigc::mem_fun(*this, &MainWin::bind_branch));
|
branch_factory->signal_bind().connect(sigc::mem_fun(*this, &MainWin::bind_branch));
|
||||||
|
@ -66,7 +72,7 @@ MainWin::MainWin()
|
||||||
btn_add.set_halign(Gtk::Align::CENTER);
|
btn_add.set_halign(Gtk::Align::CENTER);
|
||||||
btn_remove.set_halign(Gtk::Align::CENTER);
|
btn_remove.set_halign(Gtk::Align::CENTER);
|
||||||
btn_show.set_halign(Gtk::Align::CENTER);
|
btn_show.set_halign(Gtk::Align::CENTER);
|
||||||
lists_box.append(item_entry);
|
// lists_box.append(item_entry);
|
||||||
lists_box.append(btn_add);
|
lists_box.append(btn_add);
|
||||||
lists_box.append(btn_remove);
|
lists_box.append(btn_remove);
|
||||||
lists_box.append(btn_show);
|
lists_box.append(btn_show);
|
||||||
|
@ -78,6 +84,29 @@ MainWin::MainWin()
|
||||||
set_child(main_box);
|
set_child(main_box);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWin::setup_drop(const Glib::RefPtr<Gtk::ListItem> &item)
|
||||||
|
{
|
||||||
|
// Set label for item
|
||||||
|
item->set_child(*Gtk::make_managed<Gtk::Label>());
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWin::bind_drop(const Glib::RefPtr<Gtk::ListItem> &item)
|
||||||
|
{
|
||||||
|
// Get position
|
||||||
|
auto pos = item->get_position();
|
||||||
|
|
||||||
|
// Get label widget
|
||||||
|
auto label = dynamic_cast<Gtk::Label *>(item->get_child());
|
||||||
|
if (!label)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set text to the label
|
||||||
|
auto item1 = main_list->get_item(pos);
|
||||||
|
label->set_text(item1->get_branch_str());
|
||||||
|
}
|
||||||
|
|
||||||
void MainWin::setup_branch(const Glib::RefPtr<Gtk::ListItem> &item)
|
void MainWin::setup_branch(const Glib::RefPtr<Gtk::ListItem> &item)
|
||||||
{
|
{
|
||||||
// Set label for item
|
// Set label for item
|
||||||
|
@ -132,16 +161,16 @@ void MainWin::bind_version(const Glib::RefPtr<Gtk::ListItem> &item)
|
||||||
|
|
||||||
void MainWin::btnadd_clicked()
|
void MainWin::btnadd_clicked()
|
||||||
{
|
{
|
||||||
Glib::ustring entry_str;
|
// Glib::ustring entry_str;
|
||||||
|
|
||||||
// Get String from entry
|
// // Get String from entry
|
||||||
entry_str = item_entry.get_text();
|
// entry_str = item_entry.get_text();
|
||||||
|
|
||||||
// Append text to the list
|
// // Append text to the list
|
||||||
if (!entry_str.empty())
|
// if (!entry_str.empty())
|
||||||
{
|
// {
|
||||||
dropdown_list->append(entry_str);
|
// dropdown_list->append(entry_str);
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWin::btnremove_clicked()
|
void MainWin::btnremove_clicked()
|
||||||
|
@ -150,14 +179,15 @@ void MainWin::btnremove_clicked()
|
||||||
auto pos = selection->get_selected();
|
auto pos = selection->get_selected();
|
||||||
|
|
||||||
// Remove item
|
// Remove item
|
||||||
dropdown_list->remove(pos);
|
main_list->remove(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWin::btnshow_clicked()
|
void MainWin::btnshow_clicked()
|
||||||
{
|
{
|
||||||
// Show all items
|
// Show all items and sync the main list to drop down
|
||||||
auto length = main_list->get_n_items();
|
auto length = main_list->get_n_items();
|
||||||
for(int i = 0; i < length; i++)
|
|
||||||
|
for (int i = 0; i < length; i++)
|
||||||
{
|
{
|
||||||
auto item = main_list->get_item(i);
|
auto item = main_list->get_item(i);
|
||||||
std::cout << item->get_branch_str().c_str() << " "
|
std::cout << item->get_branch_str().c_str() << " "
|
||||||
|
|
|
@ -50,6 +50,7 @@ private:
|
||||||
Glib::Property<Glib::ustring> branch_prep, version_prep;
|
Glib::Property<Glib::ustring> branch_prep, version_prep;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
// Register type and initalize properties
|
||||||
ModelColumns(Glib::ustring branch, Glib::ustring version)
|
ModelColumns(Glib::ustring branch, Glib::ustring version)
|
||||||
: Glib::ObjectBase(typeid(ModelColumns)),
|
: Glib::ObjectBase(typeid(ModelColumns)),
|
||||||
Glib::Object(),
|
Glib::Object(),
|
||||||
|
@ -66,13 +67,15 @@ public:
|
||||||
MainWin();
|
MainWin();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Use StringList for dropdown and json file
|
|
||||||
Glib::RefPtr<Gtk::StringList> dropdown_list;
|
|
||||||
|
|
||||||
// Main list object for branchs and versions
|
// Main list object for branchs and versions
|
||||||
Glib::RefPtr<Gio::ListStore<ModelColumns>> main_list;
|
Glib::RefPtr<Gio::ListStore<ModelColumns>> main_list;
|
||||||
Glib::RefPtr<Gtk::SingleSelection> selection;
|
Glib::RefPtr<Gtk::SingleSelection> selection;
|
||||||
|
|
||||||
|
// Factory to renderer string for dropdown
|
||||||
|
Glib::RefPtr<Gtk::SignalListItemFactory> drop_factory;
|
||||||
|
void setup_drop(const Glib::RefPtr<Gtk::ListItem> &item);
|
||||||
|
void bind_drop(const Glib::RefPtr<Gtk::ListItem> &item);
|
||||||
|
|
||||||
// Factory to renderer branch string
|
// Factory to renderer branch string
|
||||||
Glib::RefPtr<Gtk::ColumnViewColumn> branch_column;
|
Glib::RefPtr<Gtk::ColumnViewColumn> branch_column;
|
||||||
Glib::RefPtr<Gtk::SignalListItemFactory> branch_factory;
|
Glib::RefPtr<Gtk::SignalListItemFactory> branch_factory;
|
||||||
|
@ -93,7 +96,7 @@ private:
|
||||||
Gtk::ScrolledWindow m_sw;
|
Gtk::ScrolledWindow m_sw;
|
||||||
Gtk::ListView main_list_view;
|
Gtk::ListView main_list_view;
|
||||||
Gtk::ColumnView main_column_view;
|
Gtk::ColumnView main_column_view;
|
||||||
Gtk::Entry item_entry;
|
// Gtk::Entry item_entry;
|
||||||
Gtk::Button btn_add, btn_remove, btn_show;
|
Gtk::Button btn_add, btn_remove, btn_show;
|
||||||
|
|
||||||
// Signal Handlers
|
// Signal Handlers
|
||||||
|
|
Loading…
Reference in New Issue