diff --git a/juci/entry.cc b/juci/entry.cc index 3aac46d..147dd5a 100644 --- a/juci/entry.cc +++ b/juci/entry.cc @@ -3,20 +3,16 @@ Entry::Model::Model() : next_("Next"), prev_("Prev"){ -std::cout<<"Model Entry"< app = Gtk::Application::create( argc, argv, "no.sout.juci"); - Window window; return app->run(window); } diff --git a/juci/keybindings.cc b/juci/keybindings.cc index 5aba847..dd5b45d 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -2,65 +2,60 @@ Keybindings::Model::Model() { menu_ui_string_ = - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " "; - + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "; + hidden_ui_string_ = - " " - " " - " " - " " - " "; + " " + " " + " " + " " + " "; }; Keybindings::Model::~Model() { } - Keybindings::Controller::Controller() { - action_group_menu_ = Gtk::ActionGroup::create(); - ui_manager_menu_ = Gtk::UIManager::create(); - - action_group_hidden_ = Gtk::ActionGroup::create(); - ui_manager_hidden_ = Gtk::UIManager::create(); - - } - +Keybindings::Controller::Controller() { + action_group_menu_ = Gtk::ActionGroup::create(); + ui_manager_menu_ = Gtk::UIManager::create(); + action_group_hidden_ = Gtk::ActionGroup::create(); + ui_manager_hidden_ = Gtk::UIManager::create(); +} Keybindings::Controller::~Controller(){ - } - void Keybindings::Controller::BuildMenu() { try { ui_manager_menu_->add_ui_from_string(model_.menu_ui_string()); @@ -70,8 +65,6 @@ void Keybindings::Controller::BuildMenu() { } ui_manager_menu_->insert_action_group(action_group_menu_); } - - void Keybindings::Controller::BuildHiddenMenu() { try { ui_manager_hidden_->add_ui_from_string(model_.hidden_ui_string()); diff --git a/juci/keybindings.h b/juci/keybindings.h index bac39b8..f117028 100644 --- a/juci/keybindings.h +++ b/juci/keybindings.h @@ -6,53 +6,42 @@ #include "gtkmm.h" namespace Keybindings { - - class Model { - public: - Model(); - virtual ~Model(); - std::string menu_ui_string(){return menu_ui_string_;} - std::string hidden_ui_string(){return hidden_ui_string_;} - private: - std::string menu_ui_string_; - std::string hidden_ui_string_; + class Model { + public: + Model(); + virtual ~Model(); + std::string menu_ui_string(){return menu_ui_string_;} + std::string hidden_ui_string(){return hidden_ui_string_;} + private: + std::string menu_ui_string_; + std::string hidden_ui_string_; + }; // Model + class Controller { + public: + Controller(); + virtual ~Controller(); + Glib::RefPtr action_group_menu() { + return action_group_menu_; }; - - class Controller { - public: - Controller(); - - virtual ~Controller(); - - Glib::RefPtr action_group_menu() { - return action_group_menu_; - }; - - Glib::RefPtr ui_manager_menu() { - return ui_manager_menu_; - }; - - Glib::RefPtr action_group_hidden() { - return action_group_hidden_; - }; - - Glib::RefPtr ui_manager_hidden() { - return ui_manager_hidden_; - }; - - void BuildMenu(); - void BuildHiddenMenu(); - - - protected: - Glib::RefPtr ui_manager_menu_; - Glib::RefPtr action_group_menu_; - Glib::RefPtr ui_manager_hidden_; - Glib::RefPtr action_group_hidden_; - private: - Keybindings::Model model_; + Glib::RefPtr ui_manager_menu() { + return ui_manager_menu_; }; - + Glib::RefPtr action_group_hidden() { + return action_group_hidden_; + }; + Glib::RefPtr ui_manager_hidden() { + return ui_manager_hidden_; + }; + void BuildMenu(); + void BuildHiddenMenu(); + protected: + Glib::RefPtr ui_manager_menu_; + Glib::RefPtr action_group_menu_; + Glib::RefPtr ui_manager_hidden_; + Glib::RefPtr action_group_hidden_; + private: + Keybindings::Model model_; + };//Controller } -#endif // JUCI_KEYBINDINGS_H_ \ No newline at end of file +#endif // JUCI_KEYBINDINGS_H_ diff --git a/juci/menu.cc b/juci/menu.cc index a634fe4..e407615 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -1,160 +1,93 @@ #include "menu.h" -// VIEW Menu::View::View(Gtk::Orientation orientation) : - view_(orientation) { - -}// view controller + view_(orientation) { + Gtk::MenuBar menutest; + view_.pack_end(menutest); +} Gtk::Box &Menu::View::view( - Glib::RefPtr ui_manager) { + Glib::RefPtr ui_manager) { view_.pack_start(*ui_manager->get_widget("/MenuBar"), Gtk::PACK_SHRINK); return view_; } - -// CONTROLLER Menu::Controller::Controller(Keybindings::Controller& keybindings) : - menu_view_(Gtk::ORIENTATION_VERTICAL), - keybindings_(keybindings) { -/* Add action to menues */ -/* START file menu */ - - /* File-> New files end */ + menu_view_(Gtk::ORIENTATION_VERTICAL), + keybindings_(keybindings) { keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", - Gtk::Stock::OPEN), - [this]() { - OnFileOpenFile(); - }); + Gtk::Stock::OPEN), + [this]() { + OnFileOpenFile(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", - "Open folder"), - [this]() { - OnFileOpenFolder(); - }); -/* END file menu */ -/* START edit menu */ + "Open folder"), + [this]() { + OnFileOpenFolder(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", - Gtk::Stock::EDIT)); - keybindings_.action_group_menu()->add(Gtk::Action::create("EditCopy", - Gtk::Stock::COPY), - [this]() { - OnEditCopy(); - }); - keybindings_.action_group_menu()->add(Gtk::Action::create("EditCut", - Gtk::Stock::CUT), - [this]() { - OnEditCut(); - }); - keybindings_.action_group_menu()->add(Gtk::Action::create("EditPaste", - Gtk::Stock::PASTE), - [this]() { - OnEditPaste(); - }); - -/* END edit menu */ -/* START window menu */ + Gtk::Stock::EDIT)); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", - "_Window")); - + "_Window")); keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", - "Split window"), - Gtk::AccelKey("S"), - [this]() { - OnWindowSplitWindow(); - }); -/* END window menu */ -/* START Plugin menu */ + "Split window"), + Gtk::AccelKey("S"), + [this]() { + OnWindowSplitWindow(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", - "_Plugins")); - /*Plugin->snippet*/ + "_Plugins")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", - "Snippet")); + "Snippet")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", - "Add snippet"), - Gtk::AccelKey("space"), - [this]() { - OnPluginAddSnippet(); - }); - /* End snippet */ -/* END plugin menu */ -/* START help menu */ + "Add snippet"), + Gtk::AccelKey("space"), + [this]() { + OnPluginAddSnippet(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", - Gtk::Stock::HELP)); + Gtk::Stock::HELP)); keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", - Gtk::Stock::ABOUT), - [this]() { - OnHelpAbout(); - }); - -// Hidden actions + Gtk::Stock::ABOUT), + [this]() { + OnHelpAbout(); + }); keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"), - Gtk::AccelKey("K"), - [this]() { - OnHelpAbout(); - }); + Gtk::AccelKey("K"), + [this]() { + OnHelpAbout(); + }); keybindings_.BuildMenu(); keybindings_.BuildHiddenMenu(); - - -/* END help menu */ - - - -} - - + }//Controller Gtk::Box &Menu::Controller::view() { return menu_view_.view(keybindings_.ui_manager_menu()); } - - void Menu::Controller::OnPluginAddSnippet() { //TODO(Forgi add you snippet magic code) std::cout << "Add snipper" << std::endl; juci_api::py::LoadPlugin("snippet"); } - - -// void Menu::Controller::LoadPlugin() { -// juci_api::py::LoadPlugin("plugin_name"); -// } - void Menu::Controller::OnFileOpenFile() { std::cout << "Open file clicked" << std::endl; //TODO(Oyvang) Legg til funksjon } - void Menu::Controller::OnFileOpenFolder() { std::cout << "Open folder clicked" << std::endl; //TODO(Oyvang) Legg til funksjon } - - -void Menu::Controller::OnEditCopy() { - std::cout << "Clicked copy" << std::endl; - //TODO(Oyvang) Legg til funksjon -} - void Menu::Controller::OnEditCut() { std::cout << "Clicked cut" << std::endl; //TODO(Oyvang) Legg til funksjon } - -void Menu::Controller::OnEditPaste() { - std::cout << "Clicked paste" << std::endl; - //TODO(Oyvang) Legg til funksjon -} - void Menu::Controller::OnEditFind() { std::cout << "Clicked find" << std::endl; //TODO(Oyvang) Legg til funksjon } - void Menu::Controller::OnWindowSplitWindow() { std::cout << "Clicked split window" << std::endl; //TODO(Oyvang) Legg til funksjon } - void Menu::Controller::OnHelpAbout() { std::cout << "Clicked about" << std::endl; //TODO(Oyvang) Legg til funksjon diff --git a/juci/menu.h b/juci/menu.h index 702858a..8e00bad 100644 --- a/juci/menu.h +++ b/juci/menu.h @@ -6,54 +6,32 @@ #include "keybindings.h" #include "api.h" - namespace Menu { - class View { - public: - explicit View(Gtk::Orientation orient); - - Gtk::Box &view(Glib::RefPtr ui_manager); - - protected: - Gtk::Box view_; - }; // class View - - class Controller { - public: - explicit Controller(Keybindings::Controller& keybindings); - - Gtk::Box &view(); - - private: - Keybindings::Controller keybindings_; - View menu_view_; - - void OnFileNewEmptyfile(); - - // Signal handlers - void OnFileNewCCFile(); - - void OnFileNewHeaderFile(); - - void OnFileOpenFile(); - - void OnFileOpenFolder(); - - void OnPluginAddSnippet(); - - void OnWindowCloseTab(); - - void OnEditCopy(); - - void OnEditCut(); - - void OnEditPaste(); - - void OnEditFind(); - - void OnWindowSplitWindow(); - - void OnHelpAbout(); - }; // class Controller + class View { + public: + explicit View(Gtk::Orientation orient); + Gtk::Box &view(Glib::RefPtr ui_manager); + protected: + Gtk::Box view_; + }; // class View + class Controller { + public: + explicit Controller(Keybindings::Controller& keybindings); + Gtk::Box &view(); + private: + Keybindings::Controller &keybindings_; + View menu_view_; + void OnFileNewEmptyfile(); + void OnFileNewCCFile(); + void OnFileNewHeaderFile(); + void OnFileOpenFile(); + void OnFileOpenFolder(); + void OnPluginAddSnippet(); + void OnWindowCloseTab(); + void OnEditCut(); + void OnEditFind(); + void OnWindowSplitWindow(); + void OnHelpAbout(); + }; // class Controller } // namespace Menu #endif // JUCI_MENU_H_ diff --git a/juci/notebook.cc b/juci/notebook.cc index 23a15d4..7d88609 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -9,75 +9,78 @@ Gtk::Box& Notebook::View::view() { view_.pack_start(notebook_); return view_; } - Notebook::Controller::Controller(Keybindings::Controller& keybindings){ - scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); - source_vec_.push_back(new Source::Controller); - scrolledwindow_vec_.back()->add(source_vec_.back()->view()); - view_.notebook().append_page(*scrolledwindow_vec_.back(), "juCi++"); - - + refClipboard = Gtk::Clipboard::get(); keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", - Gtk::Stock::FILE)); + Gtk::Stock::FILE)); /* File->New files */ keybindings.action_group_menu()->add(Gtk::Action::create("FileNew", "New")); keybindings.action_group_menu()->add(Gtk::Action::create("FileNewStandard", - Gtk::Stock::NEW, "New empty file", "Create a new file"), - [this]() { - OnFileNewEmptyfile(); - }); + Gtk::Stock::NEW, + "New empty file", + "Create a new file"), + [this]() { + OnFileNewEmptyfile(); + }); keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC", - "New cc file"), - Gtk::AccelKey("c"), - [this]() { - OnFileNewCCFile(); - }); + "New cc file"), + Gtk::AccelKey("c"), + [this]() { + OnFileNewCCFile(); + }); keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH", - "New h file"), - Gtk::AccelKey("h"), - [this]() { - OnFileNewHeaderFile(); - }); + "New h file"), + Gtk::AccelKey("h"), + [this]() { + OnFileNewHeaderFile(); + }); keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", - "Close tab"), - Gtk::AccelKey("w"), - [this]() { - OnCloseCurrentPage(); - }); + "Close tab"), + Gtk::AccelKey("w"), + [this]() { + OnCloseCurrentPage(); + }); keybindings.action_group_menu()->add(Gtk::Action::create("EditFind", - Gtk::Stock::FIND), - [this]() { - // OnEditFind(); - }); - - entry_.view_.entry().signal_activate().connect( - [this]() { - OnNewPage(entry_.view_.entry().get_text()); - entry_.OnHideEntries(); - }); -} - - + Gtk::Stock::FIND), + [this]() { + //TODO(Oyvang, Zalox, Forgi)Create function OnEditFind(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy", + Gtk::Stock::COPY), + [this]() { + OnEditCopy(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("EditCut", + Gtk::Stock::CUT), + [this]() { + OnEditCut(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("EditPaste", + Gtk::Stock::PASTE), + [this]() { + OnEditPaste(); + }); + entry_.view_.entry().signal_activate().connect( + [this]() { + OnNewPage(entry_.view_.entry().get_text()); + entry_.OnHideEntries(); + }); +}//Constructor Gtk::Box& Notebook::Controller::view() { return view_.view(); } - Gtk::Box& Notebook::Controller::entry_view(){ return entry_.view(); } - void Notebook::Controller::OnNewPage(std::string name) { - scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); source_vec_.push_back(new Source::Controller); scrolledwindow_vec_.back()->add(source_vec_.back()->view()); view_.notebook().append_page(*scrolledwindow_vec_.back(), name); view_.notebook().show_all_children(); view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); - view().show_all_children(); view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); } - void Notebook::Controller::OnCloseCurrentPage() { //TODO (oyvang, zalox, forgi) Save a temp file, in case you close one you dont want to close? int page = view_.notebook().get_current_page(); @@ -87,21 +90,32 @@ void Notebook::Controller::OnCloseCurrentPage() { source_vec_.erase(source_vec_.begin()+ page); scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page); } - void Notebook::Controller::OnFileNewEmptyfile() { entry_.OnShowSetFilenName(""); - //TODO(Oyvang) Legg til funksjon for Entry file name.extension } - void Notebook::Controller::OnFileNewCCFile() { entry_.OnShowSetFilenName(".cc"); - //TODO(Oyvang) Legg til funksjon for Entry file name.extension } - void Notebook::Controller::OnFileNewHeaderFile() { entry_.OnShowSetFilenName(".h"); - //TODO(Oyvang) Legg til funksjon for Entry file name.extension } +void Notebook::Controller::OnEditCopy() { + std::cout << "Clicked copy" << std::endl; + int source_pos = view_.notebook().get_current_page(); + Glib::RefPtr buffer = source_vec_.at(source_pos)->view().get_buffer(); + buffer->copy_clipboard(refClipboard); +} +void Notebook::Controller::OnEditPaste() { + int source_pos = view_.notebook().get_current_page(); + Glib::RefPtr buffer = source_vec_.at(source_pos)->view().get_buffer(); + buffer->paste_clipboard(refClipboard); +}; +void Notebook::Controller::OnEditCut() { + int source_pos = view_.notebook().get_current_page(); + Glib::RefPtr buffer = source_vec_.at(source_pos)->view().get_buffer(); + buffer->cut_clipboard(refClipboard); +} + diff --git a/juci/notebook.h b/juci/notebook.h index eee4892..e80b4d8 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -7,31 +7,37 @@ #include "source.h" namespace Notebook { - class View { - public: - View(); - Gtk::Box& view(); - Gtk::Notebook& notebook(){return notebook_;} - protected: - Gtk::Box view_; - Gtk::Notebook notebook_; - }; - class Controller { - public: - Controller(Keybindings::Controller& keybindings); - Gtk::Box& view(); - Gtk::Box& entry_view(); - void OnNewPage(std::string name); - void OnCloseCurrentPage(); - private: - View view_; - Entry::Controller entry_; - std::vector source_vec_; - std::vector scrolledwindow_vec_; - void OnFileNewEmptyfile(); - void OnFileNewCCFile(); - void OnFileNewHeaderFile(); - };// class controller + class View { + public: + View(); + Gtk::Box& view(); + Gtk::Notebook& notebook(){return notebook_;} + protected: + Gtk::Box view_; + Gtk::Notebook notebook_; + }; + class Controller { + public: + Controller(Keybindings::Controller& keybindings); + Gtk::Box& view(); + Gtk::Box& entry_view(); + void OnNewPage(std::string name); + void OnCloseCurrentPage(); + private: + View view_; + Entry::Controller entry_; + std::vector source_vec_; + std::vector scrolledwindow_vec_; + Glib::RefPtr refClipboard; + std::list listTargets; + void OnFileNewEmptyfile(); + void OnFileNewCCFile(); + void OnFileNewHeaderFile(); + void OnEditCopy(); + void OnEditPaste(); + void OnEditCut(); + + };// class controller } // namespace notebook diff --git a/juci/window.cc b/juci/window.cc index fd9295f..38b5da6 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -5,25 +5,21 @@ Window::Window() : notebook_(keybindings_), menu_(keybindings_){ set_title("juCi++"); - set_default_size(600, 00); + set_default_size(600, 400); add(window_box_); keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", - Gtk::Stock::QUIT), - [this]() { - OnWindowHide(); - }); - + Gtk::Stock::QUIT), + [this]() { + OnWindowHide(); + }); add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); - + window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.entry_view(), Gtk::PACK_SHRINK); window_box_.pack_start(notebook_.view()); show_all_children(); - -} // Window constructor - - + } // Window constructor void Window::OnWindowHide() { hide(); } diff --git a/juci/window.h b/juci/window.h index 36b76a2..ba275a7 100644 --- a/juci/window.h +++ b/juci/window.h @@ -10,8 +10,6 @@ class Window : public Gtk::Window { public: Window(); Gtk::Box window_box_; - - private: Keybindings::Controller keybindings_; Menu::Controller menu_; @@ -19,9 +17,6 @@ private: //signal handlers void OnWindowHide(); - }; - - #endif // JUCI_WINDOW_H_