diff --git a/juci/controller.h b/juci/controller.h index f863adf..b9e79a9 100644 --- a/juci/controller.h +++ b/juci/controller.h @@ -18,21 +18,24 @@ public: Menu(); virtual ~Menu(); - Gtk::Box &get_view(); + Gtk::Box &view(); - Glib::RefPtr get_action_group() { - return menu_view.get_action_group(); - }; - Glib::RefPtr get_ui_manager() { - return menu_view.get_ui_manager(); + Glib::RefPtr ui_manager() { + return menu_view_.ui_manager(); }; private: - View::Menu menu_view; - Model::Menu menu_model; - void onNewEmptyfile(); - void onNewCCFile(); - void onNewHeaderFile(); + View::Menu menu_view_; + Model::Menu menu_model_; + /*Signal handlers*/ + void onFileNewEmptyfile(); + void onFileNewCCFile(); + void onFileNewHeaderFile(); + void onFileOpenFile(); + void onFileOpenFolder(); + void onSystemQuit(); + void onPluginAddSnippet(); + }; }; diff --git a/juci/controllers.cc b/juci/controllers.cc index 012e3c3..f6ab2e7 100644 --- a/juci/controllers.cc +++ b/juci/controllers.cc @@ -1,33 +1,80 @@ #include "controller.h" Controller::Menu::Menu() : - menu_view(Gtk::ORIENTATION_VERTICAL), - menu_model() { + menu_view_(Gtk::ORIENTATION_VERTICAL), + menu_model_() { /*Add action to menues*/ - menu_view.get_action_group()->add(Gtk::Action::create("FileMenu", "File")); +/*File menu*/ + menu_view_.action_group()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE)); + /*File->New files*/ + menu_view_.action_group()->add(Gtk::Action::create("FileNew", "New")); - menu_view.get_action_group()->add(Gtk::Action::create("FileNewStandard", + menu_view_.action_group()->add(Gtk::Action::create("FileNewStandard", Gtk::Stock::NEW, "New empty file", "Create a new file"), [this]() { - onNewEmptyfile(); + onFileNewEmptyfile(); }); + menu_view_.action_group()->add(Gtk::Action::create("FileNewCC", + Gtk::Stock::NEW, "New cc file", "Create a new cc file"), + Gtk::AccelKey("c"), + [this]() { + onFileNewCCFile(); + }); + menu_view_.action_group()->add(Gtk::Action::create("FileNewH", + Gtk::Stock::NEW, "New h file", "Create a new h file"), + Gtk::AccelKey("h"), + [this]() { + onFileNewHeaderFile(); + }); + /* File-> New files end */ + menu_view_.action_group()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN), + [this]() { + onFileNewEmptyfile(); + }); + menu_view_.action_group()->add(Gtk::Action::create("FileOpenFolder", "Open folder"), + [this]() { + onFileNewEmptyfile(); + }); + menu_view_.action_group()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), + [this]() { + onSystemQuit(); + }); + menu_view_.action_group()->add(Gtk::Action::create("PluginMenu", "Plugins")); + menu_view_.action_group()->add(Gtk::Action::create("PluginSnippet", "Snippet")); + menu_view_.action_group()->add(Gtk::Action::create("PluginAddSnippet", "Add snippet"), + Gtk::AccelKey("space"), + [this]() { + onPluginAddSnippet(); + }); + - menu_view.set_ui_manager_action_group(menu_view.get_action_group()); - menu_view.set_ui_manger_string(menu_model.get_ui_string()); + menu_view_.set_ui_manager_action_group(menu_view_.action_group()); + menu_view_.set_ui_manger_string(menu_model_.ui_string()); } Controller::Menu::~Menu() { } -Gtk::Box &Controller::Menu::get_view() { - return menu_view.get_view(); +Gtk::Box &Controller::Menu::view() { + return menu_view_.view(); } -void Controller::Menu::onNewEmptyfile() { - std::cout << "New file clicked"<< std::endl; +void Controller::Menu::onFileNewEmptyfile() { + std::cout << "New file clicked" << std::endl; +} +void Controller::Menu::onFileNewCCFile() { + std::cout << "New cc file clicked" << std::endl; } - - - +void Controller::Menu::onFileNewHeaderFile() { + std::cout << "New cc file clicked" << std::endl; +} +void Controller::Menu::onSystemQuit(){ + //TODO(Oyvang, Zalox, Forgie) Add everything that needs to be done before quiting + /*Quit the system*/ + Gtk::Main::quit(); //TODO(Oyvang, Zalox, Forgie) methode is depricated, find a better solution. +} +void Controller::Menu::onPluginAddSnippet() { + std::cout << "Add snipper" << std::endl; //TODO(Forgi add you snippet magic code) +} diff --git a/juci/juci.h b/juci/juci.h index fa66dbe..7df1832 100644 --- a/juci/juci.h +++ b/juci/juci.h @@ -15,7 +15,7 @@ public: virtual ~Window(); - Gtk::Box window_box; + Gtk::Box window_box_; private: Controller::Menu menu; diff --git a/juci/model.h b/juci/model.h index 04ef11d..d244cdf 100644 --- a/juci/model.h +++ b/juci/model.h @@ -16,11 +16,11 @@ public: virtual~Menu(); - std::string get_ui_string() { - return ui_string; + std::string ui_string() { + return ui_string_; }; private: - std::string ui_string; + std::string ui_string_; }; }; diff --git a/juci/models.cc b/juci/models.cc index 45bc49e..4b7f70a 100644 --- a/juci/models.cc +++ b/juci/models.cc @@ -1,15 +1,29 @@ #include "model.h" Model::Menu::Menu() { - ui_string = + ui_string_ = " " " " " " + " " " " + " " + " " + " " + // " " + //" " + " " " " " " + " " + " " + " " + " " + " " " " " "; + + // TODO(oyvang) legg til under en meny Window } Model::Menu::~Menu() { diff --git a/juci/view.h b/juci/view.h index ce52932..50316c0 100644 --- a/juci/view.h +++ b/juci/view.h @@ -18,14 +18,13 @@ public: virtual ~Menu(); - Gtk::Box &get_view(); - - Glib::RefPtr get_action_group() { - return action_group; + Gtk::Box &view(); + Glib::RefPtr action_group() { + return action_group_; }; - Glib::RefPtr get_ui_manager() { - return ui_manager; + Glib::RefPtr ui_manager() { + return ui_manager_; }; void set_ui_manger_string(std::string ui_string); @@ -33,9 +32,9 @@ public: void set_ui_manager_action_group(Glib::RefPtr action_group); protected: - Gtk::Box view; - Glib::RefPtr ui_manager; - Glib::RefPtr action_group; + Gtk::Box view_; + Glib::RefPtr ui_manager_; + Glib::RefPtr action_group_; }; diff --git a/juci/views.cc b/juci/views.cc index 8e8c112..cfb63c3 100644 --- a/juci/views.cc +++ b/juci/views.cc @@ -5,17 +5,17 @@ /* MENU */ /***********************************/ View::Menu::Menu(Gtk::Orientation orientation) : - view(orientation) { + view_(orientation) { - action_group = Gtk::ActionGroup::create(); - ui_manager = Gtk::UIManager::create(); + action_group_ = Gtk::ActionGroup::create(); + ui_manager_ = Gtk::UIManager::create(); } void View::Menu::set_ui_manger_string(std::string ui_string) { try { - ui_manager->add_ui_from_string(ui_string); + ui_manager_->add_ui_from_string(ui_string); } catch (const Glib::Error &ex) { std::cerr << "building menus failed: " << ex.what(); @@ -23,12 +23,12 @@ void View::Menu::set_ui_manger_string(std::string ui_string) { } void View::Menu::set_ui_manager_action_group(Glib::RefPtr action_group) { - ui_manager->insert_action_group(action_group); + ui_manager_->insert_action_group(action_group); } -Gtk::Box &View::Menu::get_view() { - view.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK); - return view; +Gtk::Box &View::Menu::view() { + view_.pack_start(*ui_manager_->get_widget("/MenuBar"), Gtk::PACK_SHRINK); + return view_; } diff --git a/juci/window.cc b/juci/window.cc index ddbfd76..7c25a9d 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -1,30 +1,23 @@ #include "juci.h" Window::Window() : - window_box(Gtk::ORIENTATION_HORIZONTAL), + window_box_(Gtk::ORIENTATION_HORIZONTAL), menu() { set_title("example juCi++"); set_default_size(600, 600); - add(window_box); - menu.get_action_group()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), - [this]() { - onSystemQuit(); - }); + add(window_box_); - add_accel_group(menu.get_ui_manager()->get_accel_group()); + add_accel_group(menu.ui_manager()->get_accel_group()); - window_box.pack_start(menu.get_view()); + window_box_.pack_start(menu.view()); show_all_children(); }; -void Window::onSystemQuit() { - hide(); -} Window::~Window() {