From bd42aca5b6dc4f85a434833d07955b5aabc48073 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 23 Jul 2015 14:12:54 +0200 Subject: [PATCH] The entrybox is remade to be more general and easy to use. Search code to new entrybox will be finished next commit. --- juci/CMakeLists.txt | 4 +-- juci/entry.h | 22 ------------ juci/{entry.cc => entrybox.cc} | 47 ++++++++++++++++++++++-- juci/entrybox.h | 42 ++++++++++++++++++++++ juci/notebook.cc | 66 +++++++++++++++++++++++++--------- juci/notebook.h | 4 +-- juci/selectiondialog.cc | 2 ++ juci/window.cc | 13 ++++++- 8 files changed, 154 insertions(+), 46 deletions(-) delete mode 100644 juci/entry.h rename juci/{entry.cc => entrybox.cc} (54%) create mode 100644 juci/entrybox.h diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index b6f672f..694961c 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -117,8 +117,8 @@ add_executable(${project_name} api.cc notebook.cc notebook.h - entry.h - entry.cc + entrybox.h + entrybox.cc directories.h directories.cc terminal.h diff --git a/juci/entry.h b/juci/entry.h deleted file mode 100644 index 36a45e2..0000000 --- a/juci/entry.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef JUCI_ENTRY_H_ -#define JUCI_ENTRY_H_ - -#include -#include -#include "gtkmm.h" - -class Entry: public Gtk::Box { -public: - Entry(); - void show_set_filename(); - void show_search(const std::string& current); - void hide(); - std::string operator()(); - Gtk::Entry entry; - Gtk::Button button_apply_set_filename, button_close, button_next, button_prev; -private: - bool on_key_press(GdkEventKey* key); - std::function activate; -}; - -#endif // JUCI_ENTRY_H_ diff --git a/juci/entry.cc b/juci/entrybox.cc similarity index 54% rename from juci/entry.cc rename to juci/entrybox.cc index 429016c..dff6550 100644 --- a/juci/entry.cc +++ b/juci/entrybox.cc @@ -1,6 +1,47 @@ -#include "entry.h" +#include "entrybox.h" -Entry::Entry() : +namespace sigc { + SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE +} + +EntryBox::Entry::Entry(const std::string& content, std::function on_activate, unsigned length) : Gtk::Entry(), on_activate(on_activate) { + set_max_length(length); + set_text(content); + signal_activate().connect([this](){ + if(this->on_activate) + this->on_activate(get_text()); + }); +} + +EntryBox::Button::Button(const std::string& label, std::function on_activate) : Gtk::Button(label), on_activate(on_activate) { + signal_clicked().connect([this](){ + if(this->on_activate) + this->on_activate(); + }); +} + +EntryBox::EntryBox() : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL) {} + +void EntryBox::clear() { + hide(); + entries.clear(); + buttons.clear(); +} + +void EntryBox::show() { + for(auto& entry: entries) { + pack_start(entry, Gtk::PACK_SHRINK); + } + for(auto& button: buttons) + pack_start(button, Gtk::PACK_SHRINK); + show_all(); + if(entries.size()>0) { + entries.begin()->grab_focus(); + entries.begin()->select_region(0, entries.begin()->get_text_length()); + } +} + +/*Entry::Entry() : Gtk::Box(Gtk::ORIENTATION_HORIZONTAL), button_apply_set_filename(Gtk::Stock::APPLY), button_close(Gtk::Stock::CLOSE), @@ -58,4 +99,4 @@ void Entry::hide() { std::string Entry::operator()() { return entry.get_text(); -} +}*/ diff --git a/juci/entrybox.h b/juci/entrybox.h new file mode 100644 index 0000000..e4b748d --- /dev/null +++ b/juci/entrybox.h @@ -0,0 +1,42 @@ +#ifndef JUCI_ENTRYBOX_H_ +#define JUCI_ENTRYBOX_H_ + +#include +#include +#include "gtkmm.h" + +class EntryBox : public Gtk::Box { +public: + class Entry : public Gtk::Entry { + public: + Entry(const std::string& content="", std::function on_activate=nullptr, unsigned length=50); + std::function on_activate; + }; + class Button : public Gtk::Button { + public: + Button(const std::string& label, std::function on_activate=nullptr); + std::function on_activate; + }; +public: + EntryBox(); + void clear(); + void show(); + std::list entries; + std::list