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/config.json b/juci/config.json index efc9003..6587e57 100644 --- a/juci/config.json +++ b/juci/config.json @@ -2,7 +2,6 @@ "source": { "colors": { "text_color": "black", - "search": "orange", "string": "#CC0000", "namespace_ref": "#990099", "type": "#0066FF", @@ -58,10 +57,11 @@ "edit_undo": "z", "edit_redo": "y", "edit_find": "f", - "goto_declaration": "d", - "goto_method": "m", - "compile_and_run": "r", - "compile": "r" + "source_goto_declaration": "d", + "source_goto_method": "m", + "source_rename": "r", + "compile_and_run": "Return", + "compile": "Return" }, "directoryfilter": { "ignore": [ diff --git a/juci/entry.cc b/juci/entry.cc deleted file mode 100644 index 429016c..0000000 --- a/juci/entry.cc +++ /dev/null @@ -1,61 +0,0 @@ -#include "entry.h" - -Entry::Entry() : - Gtk::Box(Gtk::ORIENTATION_HORIZONTAL), - button_apply_set_filename(Gtk::Stock::APPLY), - button_close(Gtk::Stock::CLOSE), - button_next("Next"), - button_prev("Prev"){ - entry.signal_activate().connect([this](){ - if(activate) { - activate(); - } - }); - entry.signal_key_press_event().connect(sigc::mem_fun(*this, &Entry::on_key_press), false); -} - -bool Entry::on_key_press(GdkEventKey* key) { - if(key->keyval==GDK_KEY_Escape) - hide(); - return false; -} - -void Entry::show_set_filename() { - hide(); - entry.set_max_length(50); - entry.set_text(""); - pack_start(entry); - pack_end(button_close, Gtk::PACK_SHRINK); - pack_end(button_apply_set_filename, Gtk::PACK_SHRINK); - show_all(); - entry.grab_focus(); - entry.set_position(0); - activate=[this](){ - button_apply_set_filename.clicked(); - }; -} - -void Entry::show_search(const std::string& current){ - hide(); - entry.set_max_length(50); - entry.set_text(current); - pack_start(entry); - pack_start(button_next, Gtk::PACK_SHRINK); - pack_start(button_prev, Gtk::PACK_SHRINK); - pack_end(button_close, Gtk::PACK_SHRINK); - show_all(); - entry.grab_focus(); - entry.set_position(0); - activate=[this](){ - button_next.clicked(); - }; -} -void Entry::hide() { - auto widgets=get_children(); - for(auto &w: widgets) - remove(*w); -} - -std::string Entry::operator()() { - return entry.get_text(); -} 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/entrybox.cc b/juci/entrybox.cc new file mode 100644 index 0000000..05e5986 --- /dev/null +++ b/juci/entrybox.cc @@ -0,0 +1,68 @@ +#include "entrybox.h" + +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) { + set_focus_on_click(false); + signal_clicked().connect([this](){ + if(this->on_activate) + this->on_activate(); + }); +} + +EntryBox::ToggleButton::ToggleButton(const std::string& label, std::function on_activate) : Gtk::ToggleButton(label), on_activate(on_activate) { + set_focus_on_click(false); + signal_clicked().connect([this](){ + if(this->on_activate) + this->on_activate(); + }); +} + +EntryBox::Label::Label(std::function update) : Gtk::Label(), update(update) { + if(this->update) + this->update(-1, ""); +} + +EntryBox::EntryBox() : Gtk::Box(Gtk::ORIENTATION_VERTICAL), upper_box(Gtk::ORIENTATION_HORIZONTAL), lower_box(Gtk::ORIENTATION_HORIZONTAL) { + pack_start(upper_box, Gtk::PACK_SHRINK); + pack_start(lower_box, Gtk::PACK_SHRINK); +} + +void EntryBox::clear() { + hide(); + entries.clear(); + buttons.clear(); + toggle_buttons.clear(); + labels.clear(); +} + +void EntryBox::show() { + std::vector focus_chain; + for(auto& entry: entries) { + upper_box.pack_start(entry, Gtk::PACK_SHRINK); + focus_chain.emplace_back(&entry); + } + for(auto& button: buttons) + upper_box.pack_start(button, Gtk::PACK_SHRINK); + for(auto& toggle_button: toggle_buttons) + upper_box.pack_start(toggle_button, Gtk::PACK_SHRINK); + for(auto& label: labels) + lower_box.pack_start(label, Gtk::PACK_SHRINK); + upper_box.set_focus_chain(focus_chain); + show_all(); + if(entries.size()>0) { + entries.begin()->grab_focus(); + entries.begin()->select_region(0, entries.begin()->get_text_length()); + } +} diff --git a/juci/entrybox.h b/juci/entrybox.h new file mode 100644 index 0000000..06632e7 --- /dev/null +++ b/juci/entrybox.h @@ -0,0 +1,43 @@ +#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; + }; + class ToggleButton : public Gtk::ToggleButton { + public: + ToggleButton(const std::string& label, std::function on_activate=nullptr); + std::function on_activate; + }; + class Label : public Gtk::Label { + public: + Label(std::function update=nullptr); + std::function update; + }; + +public: + EntryBox(); + Gtk::Box upper_box; + Gtk::Box lower_box; + void clear(); + void show(); + std::list entries; + std::list