From f2acfd51ee5c241606df4258c0946367c3f99387 Mon Sep 17 00:00:00 2001 From: forgie Date: Wed, 11 Feb 2015 10:11:08 +0100 Subject: [PATCH 01/13] yay --- juci/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 9d13438..fc2a948 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -79,8 +79,8 @@ add_executable(${project_name} add_library(${module} SHARED - api.h - api_ext.cc + api + api_ext ) # dependencies From bc40ad6721d628ce9379c1b524aa4bfe1ce9492e Mon Sep 17 00:00:00 2001 From: forgie Date: Wed, 11 Feb 2015 13:24:05 +0100 Subject: [PATCH 02/13] BPP21 #comment got it working #time 3h --- juci/CMakeLists.txt | 9 ++---- juci/api.cc | 47 +++++++++++++++++++++++++++++++ juci/api.h | 68 +++++++++++++-------------------------------- juci/api_ext.cc | 3 +- juci/menu.cc | 6 ++++ juci/menu.h | 2 ++ 6 files changed, 77 insertions(+), 58 deletions(-) create mode 100644 juci/api.cc diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index fc2a948..4e4b80d 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -4,7 +4,6 @@ set(module juci_to_python_api) project (${project_name}) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") INCLUDE(FindPkgConfig) @@ -61,24 +60,20 @@ else() message(FATAL_ERROR "The gtkmm libraries are required. Quitting.") endif() - - - # name of the executable on Windows will be example.exe add_executable(${project_name} - #list of every needed file to create the executable + #list of every needed file to create the executable keybindings menu source window juci api + #there is no need for extentions ) - add_library(${module} SHARED - api api_ext ) diff --git a/juci/api.cc b/juci/api.cc new file mode 100644 index 0000000..42149d0 --- /dev/null +++ b/juci/api.cc @@ -0,0 +1,47 @@ +#include "api.h" +namespace juci_api{ + + void cpp::ReplaceWord(const std::string word) { + //TODO implement api::ReplaceWord / change string to iter? + //some_namespace::controller::replaceWord(word_*); + std::cout << "unimplemented function: 'api::ReplaceWord()' called" + << std::endl; + + std::cout << "The string: " << g_test_string << std::endl; + } + + void cpp::ReplaceLine(const std::string line) { + //TODO implement api::ReplaceLine / change string to iter? + //some_namespace::controller::replaceLine(line_); + std::cout << "unimplemented function: 'api::ReplaceLine()' called" + << std::endl; + } + + //helpers + boost::python::api::object py::openPythonScript(const std::string path, + boost::python::api::object python_name_space) { + std::string temp = g_project_root + path + ".py"; + boost::python::str the_path(temp); + return boost::python::exec_file(the_path, python_name_space);//, python_name_space); + } + + void py::LoadPlugin(const std::string& plugin_name) { + try{ + /* initialize python interpreter */ + Py_Initialize(); + boost::python::api::object main_module = boost::python::import("__main__"); + boost::python::api::object main_namespace = main_module.attr("__dict__"); + + /* runs script from python */ + //boost::python::object ignored1 = setPythonVar("word", word, main_namespace); + boost::python::api::object ignored2 = openPythonScript(plugin_name, main_namespace); + /* extracts desired values */ + //boost::python::object pySnippet = boost::python::eval("getSnippet()", main_namespace); + //word = boost::python::extract(pySnippet); + /* add snippet to textView */ + //TODO add snippet + }catch(boost::python::error_already_set const&) { + PyErr_Print(); + } + } +} diff --git a/juci/api.h b/juci/api.h index ef84968..9bd42c4 100644 --- a/juci/api.h +++ b/juci/api.h @@ -1,77 +1,47 @@ +#ifndef JUCI_API_H_ +#define JUCI_API_H_ + #include #include #include -// + // Plugin API // -namespace juci_api{ +const std::string g_project_root("/home/forgie/bachelor/app/juci/"); +static std::string g_test_string("test"); +namespace juci_api { // // calls from python to C++ // - namespace cpp{ + namespace cpp { - // + // Replaceword: // replaces a word in the editor with a string - // - void ReplaceWord(const std::string word_){ - //TODO implement api::ReplaceWord / change string to iter? - //some_namespace::controller::replaceWord(word_*); - std::cout << "unimplemented function: 'api::ReplaceWord()' called" - << std::endl; - } + + void ReplaceWord(const std::string word_); // // ReplaceLine: // Replaces a line in the editor with a string // - void ReplaceLine(const std::string line_){ - //TODO implement api::ReplaceLine / change string to iter? - //some_namespace::controller::replaceLine(line_); - std::cout << "unimplemented function: 'api::ReplaceLine()' called" - << std::endl; - } + void ReplaceLine(const std::string line_); }//namespace cpp // // calls from C++ to Python // - namespace py{ - const std::string g_project_root("~/bachelor/app/juci/"); + namespace py { + + //helpers boost::python::api::object openPythonScript(const std::string path, - boost::python::api::object python_name_space) { - std::string temp = g_project_root + path + ".py"; - boost::python::str the_path(temp); - return boost::python::exec_file(the_path, python_name_space);//, python_name_space); - } + boost::python::api::object python_name_space); //void snippet(std::string& word); - void plugin(const std::string& plugin_name){ - try{ - /* initialize python interpreter */ - Py_Initialize(); - boost::python::api::object main_module = boost::python::import("__main__"); - boost::python::api::object main_namespace = main_module.attr("__dict__"); - - /* runs script from python */ - //boost::python::object ignored1 = setPythonVar("word", word, main_namespace); - boost::python::api::object ignored2 = openPythonScript(plugin_name, main_namespace); - /* extracts desired values */ - //boost::python::object pySnippet = boost::python::eval("getSnippet()", main_namespace); - //word = boost::python::extract(pySnippet); - /* add snippet to textView */ - //TODO add snippet - }catch(boost::python::error_already_set const&){ - PyErr_Print(); - } - } - - }// py - + void LoadPlugin(const std::string& plugin_name); + }// py }//juci_api - - - +#endif // JUCI_API_H diff --git a/juci/api_ext.cc b/juci/api_ext.cc index 922b86b..8ea43b2 100644 --- a/juci/api_ext.cc +++ b/juci/api_ext.cc @@ -1,6 +1,5 @@ #include "api.h" - -BOOST_PYTHON_MODULE(jucy_to_python_api) { +BOOST_PYTHON_MODULE(juci_to_python_api) { using namespace boost::python; // text editing def("replaceLine", &juci_api::cpp::ReplaceLine); diff --git a/juci/menu.cc b/juci/menu.cc index 9d028f2..3d01629 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -196,8 +196,14 @@ void Menu::Controller::OnSystemQuit() { void Menu::Controller::OnPluginAddSnippet() { std::cout << "Add snipper" << std::endl; //TODO(Forgi add you snippet magic code) + 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 diff --git a/juci/menu.h b/juci/menu.h index caa9e98..6fce909 100644 --- a/juci/menu.h +++ b/juci/menu.h @@ -4,6 +4,8 @@ #include #include "gtkmm.h" #include "keybindings.h" +#include "api.h" + namespace Menu { class Model { From 012754cfe29bf1811270178290f6d8bb393066d5 Mon Sep 17 00:00:00 2001 From: oyvang Date: Wed, 11 Feb 2015 15:33:45 +0100 Subject: [PATCH 03/13] dunno what i have done --- juci/juci.cc | 1 - juci/keybindings.cc | 3 +++ juci/menu.cc | 17 ++++++++++++----- juci/menu.h | 2 ++ juci/window.cc | 5 ++++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/juci/juci.cc b/juci/juci.cc index 5b206f6..6284f51 100644 --- a/juci/juci.cc +++ b/juci/juci.cc @@ -7,7 +7,6 @@ int main(int argc, char *argv[]) { argc, argv, "no.sout.juci"); - // app->set_flags(Gio::APPLICATION_NON_UNIQUE); Window window; return app->run(window); diff --git a/juci/keybindings.cc b/juci/keybindings.cc index c112c0a..438da61 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -4,11 +4,14 @@ Keybindings::Controller::Controller() { action_group_ = Gtk::ActionGroup::create(); ui_manager_ = Gtk::UIManager::create(); + } + Keybindings::Controller::~Controller(){ } void Keybindings::Controller::set_ui_manager_action_group(Glib::RefPtr action_group) { + ui_manager_->insert_action_group(action_group); } void Keybindings::Controller::set_ui_manger_string(std::string ui_string) { diff --git a/juci/menu.cc b/juci/menu.cc index 2fcd916..7fdeb9c 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -38,6 +38,7 @@ Menu::Model::Model() { " " " " " " + " " " " " " " "; @@ -81,14 +82,12 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : [this]() { OnFileNewEmptyfile(); }); - keybindings_.action_group()->add(Gtk::Action::create("FileNewCC", - Gtk::Stock::NEW, "New cc file", "Create a new cc file"), + keybindings_.action_group()->add(Gtk::Action::create("FileNewCC", "New cc file"), Gtk::AccelKey("c"), [this]() { - OnFileNewCCFile(); + OnFileNewCCFile(); }); - keybindings_.action_group()->add(Gtk::Action::create("FileNewH", - Gtk::Stock::NEW, "New h file", "Create a new h file"), + keybindings_.action_group()->add(Gtk::Action::create("FileNewH","New h file" ), Gtk::AccelKey("h"), [this]() { OnFileNewHeaderFile(); @@ -152,6 +151,12 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : [this]() { OnHelpAbout(); }); + keybindings_.action_group()->add(Gtk::Action::create("HelpHide"), + Gtk::AccelKey("K"), + [this]() { + OnHelpAbout(); + }); + /* END help menu */ @@ -159,6 +164,8 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : keybindings_.ui_manager()->add_ui_from_string(menu_model_.ui_string()); keybindings_.ui_manager()->insert_action_group(keybindings_.action_group()); + + } Menu::Controller::~Controller() { diff --git a/juci/menu.h b/juci/menu.h index 1eea96e..b8db48a 100644 --- a/juci/menu.h +++ b/juci/menu.h @@ -31,6 +31,8 @@ namespace Menu { protected: Gtk::Box view_; }; // class View + + // controller class Controller { public: diff --git a/juci/window.cc b/juci/window.cc index b16c80a..d602a74 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -2,7 +2,7 @@ Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), - menu_(keybindings_) { + menu_(keybindings_){ set_title("juCi++"); set_default_size(600, 600); add(window_box_); @@ -16,6 +16,9 @@ Window::Window() : window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(source().view()); show_all_children(); + //TODO(Oyvang, Forgi, Zalox) Find a better solution to hide menu items and still have the keybinding + keybindings_.action_group()->get_action("HelpHide")->set_visible(false); + show(); } Source::Controller& Window::source() { From 38d2fef54a6d3e1fad0318099b10459500d4dcd9 Mon Sep 17 00:00:00 2001 From: oyvang Date: Thu, 12 Feb 2015 10:23:04 +0100 Subject: [PATCH 04/13] BAB-11 #time 3h #comment moved ui_string from menu to keybinding --- juci/keybindings.cc | 76 ++++++++++++++++++++++++++++++++++---- juci/keybindings.h | 40 ++++++++++++++++---- juci/menu.cc | 89 ++++++++++++++------------------------------- juci/window.cc | 10 ++--- 4 files changed, 134 insertions(+), 81 deletions(-) diff --git a/juci/keybindings.cc b/juci/keybindings.cc index 438da61..040f1bd 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -1,24 +1,86 @@ #include "keybindings.h" +Keybindings::Model::Model() { + std::cout<<"Keybindings: Model constructor run"< " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " "; + + hidden_ui_string_ = + " " + " " + " " + " " + " "; +}; + +Keybindings::Model::~Model() { +} Keybindings::Controller::Controller() { - action_group_ = Gtk::ActionGroup::create(); - ui_manager_ = Gtk::UIManager::create(); + std::cout<<"Keybindings: Controller constructor run"< action_group) { - ui_manager_->insert_action_group(action_group); +void Keybindings::Controller::BuildMenu() { + try { + ui_manager_menu_->add_ui_from_string(model_.menu_ui_string()); + } + catch (const Glib::Error &ex) { + std::cerr << "building menu failed" << ex.what(); + } + ui_manager_menu_->insert_action_group(action_group_menu_); } -void Keybindings::Controller::set_ui_manger_string(std::string ui_string) { + + +void Keybindings::Controller::BuildHiddenMenu() { try { - ui_manager_->add_ui_from_string(ui_string); + ui_manager_hidden_->add_ui_from_string(model_.hidden_ui_string()); } catch (const Glib::Error &ex) { - std::cerr << "building menus failed: " << ex.what(); + std::cerr << "building hidden menu failed" << ex.what(); } + ui_manager_hidden_->insert_action_group(action_group_hidden_); } + diff --git a/juci/keybindings.h b/juci/keybindings.h index c15a50c..02099f2 100644 --- a/juci/keybindings.h +++ b/juci/keybindings.h @@ -2,27 +2,51 @@ #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 Controller { public: Controller(); virtual ~Controller(); - Glib::RefPtr action_group() { - return action_group_; + 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() { - return ui_manager_; + Glib::RefPtr ui_manager_hidden() { + return ui_manager_hidden_; }; - void set_ui_manger_string(std::string ui_string); + void BuildMenu(); + void BuildHiddenMenu(); - void set_ui_manager_action_group(Glib::RefPtr action_group); protected: - Glib::RefPtr ui_manager_; - Glib::RefPtr action_group_; + Glib::RefPtr ui_manager_menu_; + Glib::RefPtr action_group_menu_; + Glib::RefPtr ui_manager_hidden_; + Glib::RefPtr action_group_hidden_; + private: + Keybindings::Model model_; }; } \ No newline at end of file diff --git a/juci/menu.cc b/juci/menu.cc index ba22027..c8fb794 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -6,42 +6,7 @@ Menu::Model::Model() { - ui_string_ = - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " " - " "; + } @@ -74,71 +39,71 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : keybindings_(keybindings) { /* Add action to menues */ /* START file menu */ - keybindings_.action_group()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE)); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE)); /* File->New files */ - keybindings_.action_group()->add(Gtk::Action::create("FileNew", "New")); - keybindings_.action_group()->add(Gtk::Action::create("FileNewStandard", + 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(); }); - keybindings_.action_group()->add(Gtk::Action::create("FileNewCC", "New cc file"), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewCC", "New cc file"), Gtk::AccelKey("c"), [this]() { OnFileNewCCFile(); }); - keybindings_.action_group()->add(Gtk::Action::create("FileNewH","New h file" ), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewH","New h file" ), Gtk::AccelKey("h"), [this]() { OnFileNewHeaderFile(); }); /* File-> New files end */ - keybindings_.action_group()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN), [this]() { OnFileOpenFile(); }); - keybindings_.action_group()->add(Gtk::Action::create("FileOpenFolder", "Open folder"), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", "Open folder"), [this]() { OnFileOpenFolder(); }); /* END file menu */ /* START edit menu */ - keybindings_.action_group()->add(Gtk::Action::create("EditMenu", Gtk::Stock::EDIT)); - keybindings_.action_group()->add(Gtk::Action::create("EditCopy", Gtk::Stock::COPY), + 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()->add(Gtk::Action::create("EditCut", Gtk::Stock::CUT), + keybindings_.action_group_menu()->add(Gtk::Action::create("EditCut", Gtk::Stock::CUT), [this]() { OnEditCut(); }); - keybindings_.action_group()->add(Gtk::Action::create("EditPaste", Gtk::Stock::PASTE), + keybindings_.action_group_menu()->add(Gtk::Action::create("EditPaste", Gtk::Stock::PASTE), [this]() { OnEditPaste(); }); - keybindings_.action_group()->add(Gtk::Action::create("EditFind", Gtk::Stock::FIND), + keybindings_.action_group_menu()->add(Gtk::Action::create("EditFind", Gtk::Stock::FIND), [this]() { OnEditFind(); }); /* END edit menu */ /* START window menu */ - keybindings_.action_group()->add(Gtk::Action::create("WindowMenu", "_Window")); - keybindings_.action_group()->add(Gtk::Action::create("WindowCloseTab", "Close tab"), + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", "_Window")); + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", "Close tab"), Gtk::AccelKey("w"), [this]() { OnWindowCloseTab(); }); - keybindings_.action_group()->add(Gtk::Action::create("WindowSplitWindow", "Split window"), + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", "Split window"), Gtk::AccelKey("S"), [this]() { OnWindowSplitWindow(); }); /* END window menu */ /* START Plugin menu */ - keybindings_.action_group()->add(Gtk::Action::create("PluginMenu", "_Plugins")); + keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", "_Plugins")); /*Plugin->snippet*/ - keybindings_.action_group()->add(Gtk::Action::create("PluginSnippet", "Snippet")); - keybindings_.action_group()->add(Gtk::Action::create("PluginAddSnippet", "Add snippet"), + keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", "Snippet")); + keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", "Add snippet"), Gtk::AccelKey("space"), [this]() { OnPluginAddSnippet(); @@ -146,24 +111,26 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : /* End snippet */ /* END plugin menu */ /* START help menu */ - keybindings_.action_group()->add(Gtk::Action::create("HelpMenu", Gtk::Stock::HELP)); - keybindings_.action_group()->add(Gtk::Action::create("HelpAbout", Gtk::Stock::ABOUT), + keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", Gtk::Stock::HELP)); + keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", Gtk::Stock::ABOUT), [this]() { OnHelpAbout(); }); - keybindings_.action_group()->add(Gtk::Action::create("HelpHide"), + +// Hidden actions + keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"), Gtk::AccelKey("K"), [this]() { OnHelpAbout(); }); + keybindings_.BuildMenu(); + keybindings_.BuildHiddenMenu(); -/* END help menu */ +/* END help menu */ - keybindings_.ui_manager()->add_ui_from_string(menu_model_.ui_string()); - keybindings_.ui_manager()->insert_action_group(keybindings_.action_group()); } @@ -172,7 +139,7 @@ Menu::Controller::~Controller() { } Gtk::Box &Menu::Controller::view() { - return menu_view_.view(keybindings_.ui_manager()); + return menu_view_.view(keybindings_.ui_manager_menu()); } void Menu::Controller::OnFileNewEmptyfile() { diff --git a/juci/window.cc b/juci/window.cc index d602a74..f1b5d3c 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -6,19 +6,19 @@ Window::Window() : set_title("juCi++"); set_default_size(600, 600); add(window_box_); - keybindings_.action_group()->add(Gtk::Action::create("FileQuit", + keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), [this]() { OnSystemQuit(); }); - add_accel_group(keybindings_.ui_manager()->get_accel_group()); + 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(source().view()); show_all_children(); - //TODO(Oyvang, Forgi, Zalox) Find a better solution to hide menu items and still have the keybinding - keybindings_.action_group()->get_action("HelpHide")->set_visible(false); - show(); + } Source::Controller& Window::source() { From b789965da5c37d26116ea5941d97bad1d83c2537 Mon Sep 17 00:00:00 2001 From: oyvang Date: Thu, 12 Feb 2015 10:50:28 +0100 Subject: [PATCH 05/13] fixed some google style issues --- juci/CMakeLists.txt | 1 - juci/juci.cc | 2 +- juci/keybindings.h | 8 +++- juci/menu.cc | 87 ++++++++++++++++++--------------------- juci/menu.h | 23 +---------- juci/notebook.cc | 0 juci/notebook.h | 0 juci/window.cc | 4 +- juci/{juci.h => window.h} | 3 +- 9 files changed, 53 insertions(+), 75 deletions(-) create mode 100644 juci/notebook.cc create mode 100644 juci/notebook.h rename juci/{juci.h => window.h} (89%) diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index ac95554..0374908 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -63,7 +63,6 @@ endif() # name of the executable on Windows will be example.exe add_executable(${project_name} #list of every needed file to create the executable - juci.h juci.cc keybindings menu diff --git a/juci/juci.cc b/juci/juci.cc index 6284f51..1cbdc8b 100644 --- a/juci/juci.cc +++ b/juci/juci.cc @@ -1,4 +1,4 @@ -#include "juci.h" +#include "window.h" diff --git a/juci/keybindings.h b/juci/keybindings.h index 02099f2..bac39b8 100644 --- a/juci/keybindings.h +++ b/juci/keybindings.h @@ -1,3 +1,7 @@ +//juCi++ class that holds every keybinding. +#ifndef JUCI_KEYBINDINGS_H_ +#define JUCI_KEYBINDINGS_H_ + #include "iostream" #include "gtkmm.h" @@ -49,4 +53,6 @@ namespace Keybindings { Keybindings::Model model_; }; -} \ No newline at end of file +} + +#endif // JUCI_KEYBINDINGS_H_ \ No newline at end of file diff --git a/juci/menu.cc b/juci/menu.cc index c8fb794..6736aea 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -1,25 +1,10 @@ #include "menu.h" -/***********************************/ -/* MODEL */ -/***********************************/ - - -Menu::Model::Model() { - - -} - -Menu::Model::~Model() { -} - - // VIEW - Menu::View::View(Gtk::Orientation orientation) : view_(orientation) { -} +}// view controller Gtk::Box &Menu::View::view( Glib::RefPtr ui_manager) { @@ -27,19 +12,15 @@ Gtk::Box &Menu::View::view( return view_; } -Menu::View::~View() { -} -/***********************************/ -/* CONTROLLER */ -/***********************************/ +// CONTROLLER Menu::Controller::Controller(Keybindings::Controller keybindings) : menu_view_(Gtk::ORIENTATION_VERTICAL), - menu_model_(), keybindings_(keybindings) { /* Add action to menues */ /* START file menu */ - keybindings_.action_group_menu()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE)); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileMenu", + 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", @@ -47,63 +28,78 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : [this]() { OnFileNewEmptyfile(); }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewCC", "New cc file"), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewCC", + "New cc file"), Gtk::AccelKey("c"), [this]() { - OnFileNewCCFile(); + OnFileNewCCFile(); }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewH","New h file" ), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewH", + "New h file"), Gtk::AccelKey("h"), [this]() { OnFileNewHeaderFile(); }); /* File-> New files end */ - keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", + Gtk::Stock::OPEN), [this]() { OnFileOpenFile(); }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", "Open folder"), + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", + "Open folder"), [this]() { OnFileOpenFolder(); }); /* END file menu */ /* START edit menu */ - keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", Gtk::Stock::EDIT)); - keybindings_.action_group_menu()->add(Gtk::Action::create("EditCopy", Gtk::Stock::COPY), + 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), + 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), + keybindings_.action_group_menu()->add(Gtk::Action::create("EditPaste", + Gtk::Stock::PASTE), [this]() { OnEditPaste(); }); - keybindings_.action_group_menu()->add(Gtk::Action::create("EditFind", Gtk::Stock::FIND), + keybindings_.action_group_menu()->add(Gtk::Action::create("EditFind", + Gtk::Stock::FIND), [this]() { OnEditFind(); }); /* END edit menu */ /* START window menu */ - keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", "_Window")); - keybindings_.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", "Close tab"), + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", + "_Window")); + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", + "Close tab"), Gtk::AccelKey("w"), [this]() { OnWindowCloseTab(); }); - keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", "Split window"), + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", + "Split window"), Gtk::AccelKey("S"), [this]() { OnWindowSplitWindow(); }); /* END window menu */ /* START Plugin menu */ - keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", "_Plugins")); + keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", + "_Plugins")); /*Plugin->snippet*/ - keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", "Snippet")); - keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", "Add snippet"), + keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", + "Snippet")); + keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", + "Add snippet"), Gtk::AccelKey("space"), [this]() { OnPluginAddSnippet(); @@ -111,8 +107,10 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : /* End snippet */ /* END plugin menu */ /* START help menu */ - keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", Gtk::Stock::HELP)); - keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", Gtk::Stock::ABOUT), + keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", + Gtk::Stock::HELP)); + keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", + Gtk::Stock::ABOUT), [this]() { OnHelpAbout(); }); @@ -123,8 +121,6 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : [this]() { OnHelpAbout(); }); - - keybindings_.BuildMenu(); keybindings_.BuildHiddenMenu(); @@ -135,8 +131,6 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : } -Menu::Controller::~Controller() { -} Gtk::Box &Menu::Controller::view() { return menu_view_.view(keybindings_.ui_manager_menu()); @@ -158,7 +152,8 @@ void Menu::Controller::OnFileNewHeaderFile() { } void Menu::Controller::OnPluginAddSnippet() { - std::cout << "Add snipper" << std::endl; //TODO(Forgi add you snippet magic code) + //TODO(Forgi add you snippet magic code) + std::cout << "Add snipper" << std::endl; juci_api::py::LoadPlugin("snippet"); } diff --git a/juci/menu.h b/juci/menu.h index 22745bd..8641bca 100644 --- a/juci/menu.h +++ b/juci/menu.h @@ -8,50 +8,29 @@ namespace Menu { - class Model { - public: - Model(); - - virtual ~Model(); - - std::string ui_string() { - return ui_string_; - } - - private: - std::string ui_string_; - }; // class Model - class View { public: explicit View(Gtk::Orientation orient); - virtual ~View(); - Gtk::Box &view(Glib::RefPtr ui_manager); protected: Gtk::Box view_; }; // class View - - // controller class Controller { public: explicit Controller(Keybindings::Controller keybindings); - virtual ~Controller(); - Gtk::Box &view(); private: Keybindings::Controller keybindings_; View menu_view_; - Model menu_model_; void OnFileNewEmptyfile(); - /*Signal handlers*/ + // Signal handlers void OnFileNewCCFile(); void OnFileNewHeaderFile(); diff --git a/juci/notebook.cc b/juci/notebook.cc new file mode 100644 index 0000000..e69de29 diff --git a/juci/notebook.h b/juci/notebook.h new file mode 100644 index 0000000..e69de29 diff --git a/juci/window.cc b/juci/window.cc index f1b5d3c..5a7ee49 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -1,4 +1,4 @@ -#include "juci.h" +#include "window.h" Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), @@ -19,7 +19,7 @@ Window::Window() : window_box_.pack_start(source().view()); show_all_children(); -} +} // Window constructor Source::Controller& Window::source() { return source_; diff --git a/juci/juci.h b/juci/window.h similarity index 89% rename from juci/juci.h rename to juci/window.h index f7c1efb..c9f6a69 100644 --- a/juci/juci.h +++ b/juci/window.h @@ -1,4 +1,3 @@ -//juCi++ main header file #ifndef JUCI_JUCI_H_ #define JUCI_JUCI_H_ @@ -19,7 +18,7 @@ private: Source::Controller source_; Gtk::Box window_box_; - /*signal handler*/ + //signal handlers void OnSystemQuit(); }; From c4089d9a574b5f9466136d30f8248ee63229ea7c Mon Sep 17 00:00:00 2001 From: oyvang Date: Mon, 16 Feb 2015 11:11:50 +0100 Subject: [PATCH 06/13] BAB-17 #time 8h #comment Need to implement Entry for text name and extension to complete this notebook. --- juci/CMakeLists.txt | 1 + juci/keybindings.cc | 2 - juci/menu.cc | 47 +----------------------- juci/notebook.cc | 89 +++++++++++++++++++++++++++++++++++++++++++++ juci/notebook.h | 36 ++++++++++++++++++ juci/window.cc | 10 ++--- juci/window.h | 20 +++++----- 7 files changed, 143 insertions(+), 62 deletions(-) diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 0374908..a18463f 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -69,6 +69,7 @@ add_executable(${project_name} source window api + notebook #there is no need for extentions ) diff --git a/juci/keybindings.cc b/juci/keybindings.cc index 040f1bd..5aba847 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -1,7 +1,6 @@ #include "keybindings.h" Keybindings::Model::Model() { - std::cout<<"Keybindings: Model constructor run"< " @@ -50,7 +49,6 @@ Keybindings::Model::~Model() { } Keybindings::Controller::Controller() { - std::cout<<"Keybindings: Controller constructor run"<add(Gtk::Action::create("FileMenu", - 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(); - }); - keybindings_.action_group_menu()->add(Gtk::Action::create("FileNewCC", - "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(); - }); + /* File-> New files end */ keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", Gtk::Stock::OPEN), @@ -79,12 +59,7 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : /* START window menu */ keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", "_Window")); - keybindings_.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", - "Close tab"), - Gtk::AccelKey("w"), - [this]() { - OnWindowCloseTab(); - }); + keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", "Split window"), Gtk::AccelKey("S"), @@ -136,20 +111,6 @@ Gtk::Box &Menu::Controller::view() { return menu_view_.view(keybindings_.ui_manager_menu()); } -void Menu::Controller::OnFileNewEmptyfile() { - std::cout << "New file clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} - -void Menu::Controller::OnFileNewCCFile() { - std::cout << "New cc file clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} - -void Menu::Controller::OnFileNewHeaderFile() { - std::cout << "New header file clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} void Menu::Controller::OnPluginAddSnippet() { //TODO(Forgi add you snippet magic code) @@ -172,10 +133,6 @@ void Menu::Controller::OnFileOpenFolder() { //TODO(Oyvang) Legg til funksjon } -void Menu::Controller::OnWindowCloseTab() { - std::cout << "Closing tab clicked" << std::endl; - //TODO(Oyvang) Legg til funksjon -} void Menu::Controller::OnEditCopy() { std::cout << "Clicked copy" << std::endl; diff --git a/juci/notebook.cc b/juci/notebook.cc index e69de29..2a309d5 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -0,0 +1,89 @@ +#include "notebook.h" + + +Notebook::View::View() : + view_(Gtk::ORIENTATION_VERTICAL){ + +} +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++"); + + + keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", + 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(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC", + "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(); + }); + keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", + "Close tab"), + Gtk::AccelKey("w"), + [this]() { + OnCloseCurrentPage(); + }); + +} + +Gtk::Box& Notebook::Controller::view() { + return view_.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(); +} + +void Notebook::Controller::OnCloseCurrentPage() { + int page = view_.notebook().get_current_page(); + view_.notebook().remove_page(page); + delete source_vec_.at(page); + delete scrolledwindow_vec_.at(page); + source_vec_.erase(source_vec_.begin()+ page); + scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page); +} + +void Notebook::Controller::OnFileNewEmptyfile() { + OnNewPage("New Page"); + //TODO(Oyvang) Legg til funksjon for Entry file name.extension +} + +void Notebook::Controller::OnFileNewCCFile() { + OnNewPage("New Page"); + //TODO(Oyvang) Legg til funksjon for Entry file name.extension +} + +void Notebook::Controller::OnFileNewHeaderFile() { + OnNewPage("New Page"); + //TODO(Oyvang) Legg til funksjon for Entry file name.extension +} + + + + diff --git a/juci/notebook.h b/juci/notebook.h index e69de29..35adb9a 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -0,0 +1,36 @@ +#ifndef JUCI_NOTEBOOK_H_ +#define JUCI_NOTEBOOK_H_ + +#include +#include "gtkmm.h" +#include "keybindings.h" +#include "source.h" + +namespace Notebook { + class View : public Gtk::Box { + 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(); + void OnNewPage(std::string name); + void OnCloseCurrentPage(); + private: + View view_; + std::vector source_vec_; + std::vector scrolledwindow_vec_; + void OnFileNewEmptyfile(); + void OnFileNewCCFile(); + void OnFileNewHeaderFile(); + };// class controller +} // namespace notebook + + +#endif // JUCI_NOTEBOOK_H_ diff --git a/juci/window.cc b/juci/window.cc index 5a7ee49..6cda23c 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -2,6 +2,7 @@ Window::Window() : window_box_(Gtk::ORIENTATION_VERTICAL), + notebook_(keybindings_), menu_(keybindings_){ set_title("juCi++"); set_default_size(600, 600); @@ -9,22 +10,19 @@ Window::Window() : keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), [this]() { - OnSystemQuit(); + 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(source().view()); + window_box_.pack_start(notebook_.view()); show_all_children(); } // Window constructor -Source::Controller& Window::source() { - return source_; -} -void Window::OnSystemQuit() { +void Window::OnWindowHide() { hide(); } diff --git a/juci/window.h b/juci/window.h index c9f6a69..36b76a2 100644 --- a/juci/window.h +++ b/juci/window.h @@ -1,25 +1,27 @@ -#ifndef JUCI_JUCI_H_ -#define JUCI_JUCI_H_ +#ifndef JUCI_WINDOW_H_ +#define JUCI_WINDOW_H_ #include #include "gtkmm.h" #include "menu.h" -#include "source.h" +#include "notebook.h" class Window : public Gtk::Window { public: Window(); - virtual ~Window() {} + Gtk::Box window_box_; + private: Keybindings::Controller keybindings_; Menu::Controller menu_; - Source::Controller& source(); - Source::Controller source_; - Gtk::Box window_box_; + Notebook::Controller notebook_; //signal handlers - void OnSystemQuit(); + void OnWindowHide(); + }; -#endif // JUCI_JUCI_H_ + + +#endif // JUCI_WINDOW_H_ From 16e98a9c852808d2a49702762075b7624a5ab84d Mon Sep 17 00:00:00 2001 From: oyvang Date: Tue, 17 Feb 2015 15:19:20 +0100 Subject: [PATCH 07/13] BAB-23 #time 6h #close #comment fixed entry, focus entry and notbook focus --- juci/CMakeLists.txt | 1 + juci/entry.cc | 55 +++++++++++++++++++++++++++++++++++++++++++++ juci/entry.h | 43 +++++++++++++++++++++++++++++++++++ juci/menu.cc | 8 ++----- juci/menu.h | 2 +- juci/notebook.cc | 29 +++++++++++++++++++----- juci/notebook.h | 8 ++++--- juci/window.cc | 3 ++- 8 files changed, 133 insertions(+), 16 deletions(-) create mode 100644 juci/entry.cc create mode 100644 juci/entry.h diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index a18463f..d955509 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -70,6 +70,7 @@ add_executable(${project_name} window api notebook + entry #there is no need for extentions ) diff --git a/juci/entry.cc b/juci/entry.cc new file mode 100644 index 0000000..3aac46d --- /dev/null +++ b/juci/entry.cc @@ -0,0 +1,55 @@ +#include "entry.h" + +Entry::Model::Model() : + next_("Next"), + prev_("Prev"){ +std::cout<<"Model Entry"< +#include "gtkmm.h" +#include "keybindings.h" + +namespace Entry { + class View { + public: + View(); + Gtk::Box& view(); + Gtk::Entry& entry(){return entry_;} + Gtk::Button& button_apply(){return button_apply_;}; + Gtk::Button& button_cancel(){return button_cancel_;}; + void OnShowSetFilenName(std::string exstension); + void OnHideEntry(); + protected: + Gtk::Box view_; + Gtk::Entry entry_; + Gtk::Button button_apply_, button_cancel_; + }; + class Model { + public: + Model(); + std::string next(){return next_;}; + std::string prev(){return prev_;}; + private: + std::string next_, prev_; + }; + class Controller { + public: + Controller(); + Gtk::Box& view(); + Gtk::Button& button_apply(); + void OnShowSetFilenName(std::string exstension); + void OnHideEntries(); + View view_; + };// class controller +} // namespace notebook + + +#endif // JUCI_ENTRY_H_ diff --git a/juci/menu.cc b/juci/menu.cc index 020cf58..a634fe4 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -14,7 +14,7 @@ Gtk::Box &Menu::View::view( // CONTROLLER -Menu::Controller::Controller(Keybindings::Controller keybindings) : +Menu::Controller::Controller(Keybindings::Controller& keybindings) : menu_view_(Gtk::ORIENTATION_VERTICAL), keybindings_(keybindings) { /* Add action to menues */ @@ -50,11 +50,7 @@ Menu::Controller::Controller(Keybindings::Controller keybindings) : [this]() { OnEditPaste(); }); - keybindings_.action_group_menu()->add(Gtk::Action::create("EditFind", - Gtk::Stock::FIND), - [this]() { - OnEditFind(); - }); + /* END edit menu */ /* START window menu */ keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", diff --git a/juci/menu.h b/juci/menu.h index 8641bca..702858a 100644 --- a/juci/menu.h +++ b/juci/menu.h @@ -20,7 +20,7 @@ namespace Menu { class Controller { public: - explicit Controller(Keybindings::Controller keybindings); + explicit Controller(Keybindings::Controller& keybindings); Gtk::Box &view(); diff --git a/juci/notebook.cc b/juci/notebook.cc index 2a309d5..23a15d4 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -10,7 +10,7 @@ Gtk::Box& Notebook::View::view() { return view_; } -Notebook::Controller::Controller(Keybindings::Controller keybindings) { +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()); @@ -44,13 +44,28 @@ Notebook::Controller::Controller(Keybindings::Controller keybindings) { [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::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()); @@ -58,9 +73,13 @@ void Notebook::Controller::OnNewPage(std::string name) { 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(); view_.notebook().remove_page(page); delete source_vec_.at(page); @@ -70,17 +89,17 @@ void Notebook::Controller::OnCloseCurrentPage() { } void Notebook::Controller::OnFileNewEmptyfile() { - OnNewPage("New Page"); + entry_.OnShowSetFilenName(""); //TODO(Oyvang) Legg til funksjon for Entry file name.extension } void Notebook::Controller::OnFileNewCCFile() { - OnNewPage("New Page"); + entry_.OnShowSetFilenName(".cc"); //TODO(Oyvang) Legg til funksjon for Entry file name.extension } void Notebook::Controller::OnFileNewHeaderFile() { - OnNewPage("New Page"); + entry_.OnShowSetFilenName(".h"); //TODO(Oyvang) Legg til funksjon for Entry file name.extension } diff --git a/juci/notebook.h b/juci/notebook.h index 35adb9a..eee4892 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -3,11 +3,11 @@ #include #include "gtkmm.h" -#include "keybindings.h" +#include "entry.h" #include "source.h" namespace Notebook { - class View : public Gtk::Box { + class View { public: View(); Gtk::Box& view(); @@ -18,12 +18,14 @@ namespace Notebook { }; class Controller { public: - Controller(Keybindings::Controller keybindings); + 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(); diff --git a/juci/window.cc b/juci/window.cc index 6cda23c..fd9295f 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -5,7 +5,7 @@ Window::Window() : notebook_(keybindings_), menu_(keybindings_){ set_title("juCi++"); - set_default_size(600, 600); + set_default_size(600, 00); add(window_box_); keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", Gtk::Stock::QUIT), @@ -17,6 +17,7 @@ Window::Window() : 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(); From 54ca8f5f148063fb5724dc27a80c303ad9c25f8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 19 Feb 2015 11:00:24 +0100 Subject: [PATCH 08/13] Add json configfile --- juci/config.json | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 juci/config.json diff --git a/juci/config.json b/juci/config.json new file mode 100644 index 0000000..39d397a --- /dev/null +++ b/juci/config.json @@ -0,0 +1,192 @@ +{ + "colors": { + "text_color": ["black", "standard text color"], + "string": ["green", "string text color"] + }, + "syntax": { + "1": ["text_color","CXCursor_UnexposedDecl"], + "2": ["text_color","CXCursor_StructDecl"], + "3": ["text_color","CXCursor_UnionDecl"], + "4": ["text_color","CXCursor_ClassDecl"], + "5": ["text_color","CXCursor_EnumDecl"], + "6": ["text_color","CXCursor_FieldDecl"], + "7": ["text_color","CXCursor_EnumConstantDecl"], + "8": ["text_color","CXCursor_FunctionDecl"], + "9": ["text_color","CXCursor_VarDecl"], + "10": ["text_color","CXCursor_ParmDecl"], + "11": ["text_color","CXCursor_ObjCInterfaceDecl"], + "12": ["text_color","CXCursor_ObjCCategoryDecl"], + "13": ["text_color","CXCursor_ObjCProtocolDecl"], + "14": ["text_color","CXCursor_ObjCPropertyDecl"], + "15": ["text_color","CXCursor_ObjCIvarDecl"], + "16": ["text_color","CXCursor_ObjCInstanceMethodDecl"], + "17": ["text_color","CXCursor_ObjCClassMethodDecl"], + "18": ["text_color","CXCursor_ObjCImplementationDecl"], + "19": ["text_color","CXCursor_ObjCCategoryImplDecl"], + "20": ["text_color","CXCursor_TypedefDecl"], + "21": ["text_color","CXCursor_CXXMethod"], + "22": ["text_color","CXCursor_Namespace"], + "23": ["text_color","CXCursor_LinkageSpec"], + "24": ["text_color","CXCursor_Constructor"], + "25": ["text_color","CXCursor_Destructor"], + "26": ["text_color","CXCursor_ConversionFunction"], + "27": ["text_color","CXCursor_TemplateTypeParameter"], + "28": ["text_color","CXCursor_NonTypeTemplateParameter"], + "29": ["text_color","CXCursor_TemplateTemplateParameter"], + "30": ["text_color","CXCursor_FunctionTemplate"], + "31": ["text_color","CXCursor_ClassTemplate"], + "32": ["text_color","CXCursor_ClassTemplatePartialSpecialization"], + "33": ["text_color","CXCursor_NamespaceAlias"], + "34": ["text_color","CXCursor_UsingDirective"], + "35": ["text_color","CXCursor_UsingDeclaration"], + "36": ["text_color","CXCursor_TypeAliasDecl"], + "37": ["text_color","CXCursor_ObjCSynthesizeDecl"], + "38": ["text_color","CXCursor_ObjCDynamicDecl"], + "39": ["text_color","CXCursor_CXXAccessSpecifier"], + "40": ["text_color","CXCursor_FirstRef"], + "41": ["text_color","CXCursor_ObjCSuperClassRef"], + "42": ["text_color","CXCursor_ObjCProtocolRef"], + "43": ["text_color","CXCursor_ObjCClassRef"], + "44": ["text_color","CXCursor_TypeRef"], + "45": ["text_color","CXCursor_CXXBaseSpecifier"], + "46": ["text_color","CXCursor_TemplateRef"], + "47": ["text_color","CXCursor_NamespaceRef"], + "48": ["text_color","CXCursor_MemberRef"], + "49": ["text_color","CXCursor_LabelRef"], + "50": ["text_color","CXCursor_OverloadedDeclRef"], + "51": ["text_color","CXCursor_VariableRef"], + "70": ["text_color","CXCursor_FirstInvalid"], + "70": ["text_color","CXCursor_InvalidFile"], + "71": ["text_color","CXCursor_NoDeclFound"], + "72": ["text_color","CXCursor_NotImplemented"], + "73": ["text_color","CXCursor_InvalidCode"], + "100": ["text_color","CXCursor_FirstExpr"], + "100": ["text_color","CXCursor_UnexposedExpr"], + "101": ["text_color","CXCursor_DeclRefExpr"], + "102": ["text_color","CXCursor_MemberRefExpr"], + "103": ["text_color","CXCursor_CallExpr"], + "104": ["text_color","CXCursor_ObjCMessageExpr"], + "105": ["text_color","CXCursor_BlockExpr"], + "106": ["text_color","CXCursor_IntegerLiteral"], + "107": ["text_color","CXCursor_FloatingLiteral"], + "108": ["text_color","CXCursor_ImaginaryLiteral"], + "109": ["string","CXCursor_StringLiteral"], + "110": ["text_color","CXCursor_CharacterLiteral"], + "111": ["text_color","CXCursor_ParenExpr"], + "112": ["text_color","CXCursor_UnaryOperator"], + "113": ["text_color","CXCursor_ArraySubscriptExpr"], + "114": ["text_color","CXCursor_BinaryOperator"], + "115": ["text_color","CXCursor_CompoundAssignOperator"], + "116": ["text_color","CXCursor_ConditionalOperator"], + "117": ["text_color","CXCursor_CStyleCastExpr"], + "118": ["text_color","CXCursor_CompoundLiteralExpr"], + "119": ["text_color","CXCursor_InitListExpr"], + "120": ["text_color","CXCursor_AddrLabelExpr"], + "121": ["text_color","CXCursor_StmtExpr"], + "122": ["text_color","CXCursor_GenericSelectionExpr"], + "123": ["text_color","CXCursor_GNUNullExpr"], + "124": ["text_color","CXCursor_CXXStaticCastExpr"], + "125": ["text_color","CXCursor_CXXDynamicCastExpr"], + "126": ["text_color","CXCursor_CXXReinterpretCastExpr"], + "127": ["text_color","CXCursor_CXXConstCastExpr"], + "128": ["text_color","CXCursor_CXXFunctionalCastExpr"], + "129": ["text_color","CXCursor_CXXTypeidExpr"], + "130": ["text_color","CXCursor_CXXBoolLiteralExpr"], + "131": ["text_color","CXCursor_CXXNullPtrLiteralExpr"], + "132": ["text_color","CXCursor_CXXThisExpr"], + "133": ["text_color","CXCursor_CXXThrowExpr"], + "134": ["text_color","CXCursor_CXXNewExpr"], + "135": ["text_color","CXCursor_CXXDeleteExpr"], + "136": ["text_color","CXCursor_UnaryExpr"], + "137": ["text_color","CXCursor_ObjCStringLiteral"], + "138": ["text_color","CXCursor_ObjCEncodeExpr"], + "139": ["text_color","CXCursor_ObjCSelectorExpr"], + "140": ["text_color","CXCursor_ObjCProtocolExpr"], + "141": ["text_color","CXCursor_ObjCBridgedCastExpr"], + "142": ["text_color","CXCursor_PackExpansionExpr"], + "143": ["text_color","CXCursor_SizeOfPackExpr"], + "144": ["text_color","CXCursor_LambdaExpr"], + "145": ["text_color","CXCursor_ObjCBoolLiteralExpr"], + "146": ["text_color","CXCursor_ObjCSelfExpr"], + "200": ["text_color","CXCursor_FirstStmt"], + "200": ["text_color","CXCursor_UnexposedStmt"], + "201": ["text_color","CXCursor_LabelStmt"], + "202": ["text_color","CXCursor_CompoundStmt"], + "203": ["text_color","CXCursor_CaseStmt"], + "204": ["text_color","CXCursor_DefaultStmt"], + "205": ["text_color","CXCursor_IfStmt"], + "206": ["text_color","CXCursor_SwitchStmt"], + "207": ["text_color","CXCursor_WhileStmt"], + "208": ["text_color","CXCursor_DoStmt"], + "209": ["text_color","CXCursor_ForStmt"], + "210": ["text_color","CXCursor_GotoStmt"], + "211": ["text_color","CXCursor_IndirectGotoStmt"], + "212": ["text_color","CXCursor_ContinueStmt"], + "213": ["text_color","CXCursor_BreakStmt"], + "214": ["text_color","CXCursor_ReturnStmt"], + "215": ["text_color","CXCursor_GCCAsmStmt"], + "216": ["text_color","CXCursor_ObjCAtTryStmt"], + "217": ["text_color","CXCursor_ObjCAtCatchStmt"], + "218": ["text_color","CXCursor_ObjCAtFinallyStmt"], + "219": ["text_color","CXCursor_ObjCAtThrowStmt"], + "220": ["text_color","CXCursor_ObjCAtSynchronizedStmt"], + "221": ["text_color","CXCursor_ObjCAutoreleasePoolStmt"], + "222": ["text_color","CXCursor_ObjCForCollectionStmt"], + "223": ["text_color","CXCursor_CXXCatchStmt"], + "224": ["text_color","CXCursor_CXXTryStmt"], + "225": ["text_color","CXCursor_CXXForRangeStmt"], + "226": ["text_color","CXCursor_SEHTryStmt"], + "227": ["text_color","CXCursor_SEHExceptStmt"], + "228": ["text_color","CXCursor_SEHFinallyStmt"], + "229": ["text_color","CXCursor_MSAsmStmt"], + "230": ["text_color","CXCursor_NullStmt"], + "231": ["text_color","CXCursor_DeclStmt"], + "232": ["text_color","CXCursor_OMPParallelDirective"], + "233": ["text_color","CXCursor_OMPSimdDirective"], + "234": ["text_color","CXCursor_OMPForDirective"], + "235": ["text_color","CXCursor_OMPSectionsDirective"], + "236": ["text_color","CXCursor_OMPSectionDirective"], + "237": ["text_color","CXCursor_OMPSingleDirective"], + "238": ["text_color","CXCursor_OMPParallelForDirective"], + "239": ["text_color","CXCursor_OMPParallelSectionsDirective"], + "240": ["text_color","CXCursor_OMPTaskDirective"], + "241": ["text_color","CXCursor_OMPMasterDirective"], + "242": ["text_color","CXCursor_OMPCriticalDirective"], + "243": ["text_color","CXCursor_OMPTaskyieldDirective"], + "244": ["text_color","CXCursor_OMPBarrierDirective"], + "245": ["text_color","CXCursor_OMPTaskwaitDirective"], + "246": ["text_color","CXCursor_OMPFlushDirective"], + "247": ["text_color","CXCursor_SEHLeaveStmt"], + "248": ["text_color","CXCursor_OMPOrderedDirective"], + "249": ["text_color","CXCursor_OMPAtomicDirective"], + "250": ["text_color","CXCursor_OMPForSimdDirective"], + "251": ["text_color","CXCursor_OMPParallelForSimdDirective"], + "252": ["text_color","CXCursor_OMPTargetDirective"], + "253": ["text_color","CXCursor_OMPTeamsDirective"], + "300": ["text_color","CXCursor_TranslationUnit"], + "400": ["text_color","CXCursor_FirstAttr"], + "400": ["text_color","CXCursor_UnexposedAttr"], + "401": ["text_color","CXCursor_IBActionAttr"], + "402": ["text_color","CXCursor_IBOutletAttr"], + "403": ["text_color","CXCursor_IBOutletCollectionAttr"], + "404": ["text_color","CXCursor_CXXFinalAttr"], + "405": ["text_color","CXCursor_CXXOverrideAttr"], + "406": ["text_color","CXCursor_AnnotateAttr"], + "407": ["text_color","CXCursor_AsmLabelAttr"], + "408": ["text_color","CXCursor_PackedAttr"], + "409": ["text_color","CXCursor_PureAttr"], + "410": ["text_color","CXCursor_ConstAttr"], + "411": ["text_color","CXCursor_NoDuplicateAttr"], + "412": ["text_color","CXCursor_CUDAConstantAttr"], + "413": ["text_color","CXCursor_CUDADeviceAttr"], + "414": ["text_color","CXCursor_CUDAGlobalAttr"], + "415": ["text_color","CXCursor_CUDAHostAttr"], + "416": ["text_color","CXCursor_CUDASharedAttr"], + "500": ["text_color","CXCursor_PreprocessingDirective"], + "501": ["text_color","CXCursor_MacroDefinition"], + "502": ["text_color","CXCursor_MacroExpansion"], + "503": ["text_color","CXCursor_InclusionDirective"], + "600": ["text_color","CXCursor_ModuleImportDecl"], + "700": ["text_color","CXCursor_OverloadCandidate"] + } +} From 86ec615d9668542ff47bceb001526ae0c485467c Mon Sep 17 00:00:00 2001 From: oyvang Date: Thu, 19 Feb 2015 12:39:53 +0100 Subject: [PATCH 09/13] Optimilised code, added copy,paste and cut function --- juci/entry.cc | 16 +---- juci/juci.cc | 2 - juci/keybindings.cc | 99 ++++++++++++++---------------- juci/keybindings.h | 81 +++++++++++-------------- juci/menu.cc | 145 ++++++++++++-------------------------------- juci/menu.h | 74 ++++++++-------------- juci/notebook.cc | 116 +++++++++++++++++++---------------- juci/notebook.h | 56 +++++++++-------- juci/window.cc | 18 +++--- juci/window.h | 5 -- 10 files changed, 252 insertions(+), 360 deletions(-) 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_ From 07b6fb71dc86e3841d4ba615d2ff08bb65effd12 Mon Sep 17 00:00:00 2001 From: oyvang Date: Thu, 19 Feb 2015 12:51:11 +0100 Subject: [PATCH 10/13] fixed copy, paste, cut bug when no buffer up --- juci/notebook.cc | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 7d88609..5fc223f 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -100,20 +100,28 @@ void Notebook::Controller::OnFileNewHeaderFile() { entry_.OnShowSetFilenName(".h"); } 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); + if(view_.notebook().get_n_pages()!=0){ + 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); -}; + if(view_.notebook().get_n_pages()!=0){ + 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); + if(view_.notebook().get_n_pages()!=0){ + int source_pos = view_.notebook().get_current_page(); + Glib::RefPtr buffer = source_vec_.at(source_pos) + ->view().get_buffer(); + buffer->cut_clipboard(refClipboard); + } } From b2f2ccb38868aa209b66b771dd61610eb3770949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 19 Feb 2015 14:16:39 +0100 Subject: [PATCH 11/13] Add syntax highlighting --- .gitignore | 1 + juci/CMakeLists.txt | 38 ++++- juci/config.json | 375 ++++++++++++++++++++++---------------------- juci/notebook.cc | 2 + juci/source.cc | 64 +++++++- juci/source.h | 18 ++- juci/sourcefile.cc | 92 +++++++++++ juci/sourcefile.h | 23 +++ 8 files changed, 415 insertions(+), 198 deletions(-) create mode 100644 juci/sourcefile.cc create mode 100644 juci/sourcefile.h diff --git a/.gitignore b/.gitignore index 36c3170..c37aa89 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ !*.cc !*.h !CMakeLists.txt +!config.json \ No newline at end of file diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index ad2d5e2..57c6030 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -5,9 +5,19 @@ set(module juci_to_python_api) project (${project_name}) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/") INCLUDE(FindPkgConfig) +message("Searcing for libclang") +#LIBCLANG_FOUND System has libclang. +#LIBCLANG_INCLUDE_DIRS The libclang include directories. +#LIBCLANG_LIBRARIES The libraries needed to use libclang. +#LIBCLANG_LIBRARY_DIR The path to the directory containing libclang. +#LIBCLANG_KNOWN_LLVM_VERSIONS Known LLVM release numbers. +find_package(Testlcl) + + #### Finding boost, the variables below is set ##### #PYTHONLIBS_FOUND - True if headers and requested libraries were found #PYTHON_INCLUDE_DIRS - Boost include directories @@ -59,7 +69,6 @@ else() message("Gtkmm link dirs ${GTKMM_LIBRARIES}") message(FATAL_ERROR "The gtkmm libraries are required. Quitting.") endif() - # name of the executable on Windows will be example.exe add_executable(${project_name} #list of every needed file to create the executable @@ -67,6 +76,8 @@ add_executable(${project_name} keybindings menu source + sourcefile.h + sourcefile.cc window api notebook @@ -81,11 +92,30 @@ add_library(${module} SHARED ) # dependencies -include_directories(${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} "/home/zalox/bachelor/libclang++/") -link_directories(${GTKMM_LIBRARY_DIRS} ${Boost_LIBRARY_DIRS} ${PYTHON_INCLUDE_DIRS} "/home/zalox/bachelor/libclang++/") + + +if(${lcl_NOTFOUND}) + message("FATAL_ERROR ohh lord!") +else() + message("Found libs!") +endif() + +include_directories( + ${Boost_INCLUDE_DIRS} + ${PYTHON_INCLUDE_DIRS} + ${GTKMM_INCLUDE_DIRS} + "/home/zalox/bachelor/libclang++/headers/" + ) +link_directories( + ${GTKMM_LIBRARY_DIRS} + ${Boost_LIBRARY_DIRS} + ${PYTHON_INCLUDE_DIRS} + ${LCL_LIBRARY_DIRS} + ) #module: set_target_properties(${module} PROPERTIES PREFIX "") target_link_libraries(${module} ${PYTHON_LIBRARIES} ${Boost_LIBRARIES}) #executable: -target_link_libraries(${project_name} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} "/home/zalox/bachelor/libclang++/") +target_link_libraries(${project_name} ${LCL_LIBRARIES} ${GTKMM_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) + diff --git a/juci/config.json b/juci/config.json index 39d397a..c9814a5 100644 --- a/juci/config.json +++ b/juci/config.json @@ -1,192 +1,193 @@ { "colors": { - "text_color": ["black", "standard text color"], - "string": ["green", "string text color"] + "text_color": "black", + "string" : "green" }, "syntax": { - "1": ["text_color","CXCursor_UnexposedDecl"], - "2": ["text_color","CXCursor_StructDecl"], - "3": ["text_color","CXCursor_UnionDecl"], - "4": ["text_color","CXCursor_ClassDecl"], - "5": ["text_color","CXCursor_EnumDecl"], - "6": ["text_color","CXCursor_FieldDecl"], - "7": ["text_color","CXCursor_EnumConstantDecl"], - "8": ["text_color","CXCursor_FunctionDecl"], - "9": ["text_color","CXCursor_VarDecl"], - "10": ["text_color","CXCursor_ParmDecl"], - "11": ["text_color","CXCursor_ObjCInterfaceDecl"], - "12": ["text_color","CXCursor_ObjCCategoryDecl"], - "13": ["text_color","CXCursor_ObjCProtocolDecl"], - "14": ["text_color","CXCursor_ObjCPropertyDecl"], - "15": ["text_color","CXCursor_ObjCIvarDecl"], - "16": ["text_color","CXCursor_ObjCInstanceMethodDecl"], - "17": ["text_color","CXCursor_ObjCClassMethodDecl"], - "18": ["text_color","CXCursor_ObjCImplementationDecl"], - "19": ["text_color","CXCursor_ObjCCategoryImplDecl"], - "20": ["text_color","CXCursor_TypedefDecl"], - "21": ["text_color","CXCursor_CXXMethod"], - "22": ["text_color","CXCursor_Namespace"], - "23": ["text_color","CXCursor_LinkageSpec"], - "24": ["text_color","CXCursor_Constructor"], - "25": ["text_color","CXCursor_Destructor"], - "26": ["text_color","CXCursor_ConversionFunction"], - "27": ["text_color","CXCursor_TemplateTypeParameter"], - "28": ["text_color","CXCursor_NonTypeTemplateParameter"], - "29": ["text_color","CXCursor_TemplateTemplateParameter"], - "30": ["text_color","CXCursor_FunctionTemplate"], - "31": ["text_color","CXCursor_ClassTemplate"], - "32": ["text_color","CXCursor_ClassTemplatePartialSpecialization"], - "33": ["text_color","CXCursor_NamespaceAlias"], - "34": ["text_color","CXCursor_UsingDirective"], - "35": ["text_color","CXCursor_UsingDeclaration"], - "36": ["text_color","CXCursor_TypeAliasDecl"], - "37": ["text_color","CXCursor_ObjCSynthesizeDecl"], - "38": ["text_color","CXCursor_ObjCDynamicDecl"], - "39": ["text_color","CXCursor_CXXAccessSpecifier"], - "40": ["text_color","CXCursor_FirstRef"], - "41": ["text_color","CXCursor_ObjCSuperClassRef"], - "42": ["text_color","CXCursor_ObjCProtocolRef"], - "43": ["text_color","CXCursor_ObjCClassRef"], - "44": ["text_color","CXCursor_TypeRef"], - "45": ["text_color","CXCursor_CXXBaseSpecifier"], - "46": ["text_color","CXCursor_TemplateRef"], - "47": ["text_color","CXCursor_NamespaceRef"], - "48": ["text_color","CXCursor_MemberRef"], - "49": ["text_color","CXCursor_LabelRef"], - "50": ["text_color","CXCursor_OverloadedDeclRef"], - "51": ["text_color","CXCursor_VariableRef"], - "70": ["text_color","CXCursor_FirstInvalid"], - "70": ["text_color","CXCursor_InvalidFile"], - "71": ["text_color","CXCursor_NoDeclFound"], - "72": ["text_color","CXCursor_NotImplemented"], - "73": ["text_color","CXCursor_InvalidCode"], - "100": ["text_color","CXCursor_FirstExpr"], - "100": ["text_color","CXCursor_UnexposedExpr"], - "101": ["text_color","CXCursor_DeclRefExpr"], - "102": ["text_color","CXCursor_MemberRefExpr"], - "103": ["text_color","CXCursor_CallExpr"], - "104": ["text_color","CXCursor_ObjCMessageExpr"], - "105": ["text_color","CXCursor_BlockExpr"], - "106": ["text_color","CXCursor_IntegerLiteral"], - "107": ["text_color","CXCursor_FloatingLiteral"], - "108": ["text_color","CXCursor_ImaginaryLiteral"], - "109": ["string","CXCursor_StringLiteral"], - "110": ["text_color","CXCursor_CharacterLiteral"], - "111": ["text_color","CXCursor_ParenExpr"], - "112": ["text_color","CXCursor_UnaryOperator"], - "113": ["text_color","CXCursor_ArraySubscriptExpr"], - "114": ["text_color","CXCursor_BinaryOperator"], - "115": ["text_color","CXCursor_CompoundAssignOperator"], - "116": ["text_color","CXCursor_ConditionalOperator"], - "117": ["text_color","CXCursor_CStyleCastExpr"], - "118": ["text_color","CXCursor_CompoundLiteralExpr"], - "119": ["text_color","CXCursor_InitListExpr"], - "120": ["text_color","CXCursor_AddrLabelExpr"], - "121": ["text_color","CXCursor_StmtExpr"], - "122": ["text_color","CXCursor_GenericSelectionExpr"], - "123": ["text_color","CXCursor_GNUNullExpr"], - "124": ["text_color","CXCursor_CXXStaticCastExpr"], - "125": ["text_color","CXCursor_CXXDynamicCastExpr"], - "126": ["text_color","CXCursor_CXXReinterpretCastExpr"], - "127": ["text_color","CXCursor_CXXConstCastExpr"], - "128": ["text_color","CXCursor_CXXFunctionalCastExpr"], - "129": ["text_color","CXCursor_CXXTypeidExpr"], - "130": ["text_color","CXCursor_CXXBoolLiteralExpr"], - "131": ["text_color","CXCursor_CXXNullPtrLiteralExpr"], - "132": ["text_color","CXCursor_CXXThisExpr"], - "133": ["text_color","CXCursor_CXXThrowExpr"], - "134": ["text_color","CXCursor_CXXNewExpr"], - "135": ["text_color","CXCursor_CXXDeleteExpr"], - "136": ["text_color","CXCursor_UnaryExpr"], - "137": ["text_color","CXCursor_ObjCStringLiteral"], - "138": ["text_color","CXCursor_ObjCEncodeExpr"], - "139": ["text_color","CXCursor_ObjCSelectorExpr"], - "140": ["text_color","CXCursor_ObjCProtocolExpr"], - "141": ["text_color","CXCursor_ObjCBridgedCastExpr"], - "142": ["text_color","CXCursor_PackExpansionExpr"], - "143": ["text_color","CXCursor_SizeOfPackExpr"], - "144": ["text_color","CXCursor_LambdaExpr"], - "145": ["text_color","CXCursor_ObjCBoolLiteralExpr"], - "146": ["text_color","CXCursor_ObjCSelfExpr"], - "200": ["text_color","CXCursor_FirstStmt"], - "200": ["text_color","CXCursor_UnexposedStmt"], - "201": ["text_color","CXCursor_LabelStmt"], - "202": ["text_color","CXCursor_CompoundStmt"], - "203": ["text_color","CXCursor_CaseStmt"], - "204": ["text_color","CXCursor_DefaultStmt"], - "205": ["text_color","CXCursor_IfStmt"], - "206": ["text_color","CXCursor_SwitchStmt"], - "207": ["text_color","CXCursor_WhileStmt"], - "208": ["text_color","CXCursor_DoStmt"], - "209": ["text_color","CXCursor_ForStmt"], - "210": ["text_color","CXCursor_GotoStmt"], - "211": ["text_color","CXCursor_IndirectGotoStmt"], - "212": ["text_color","CXCursor_ContinueStmt"], - "213": ["text_color","CXCursor_BreakStmt"], - "214": ["text_color","CXCursor_ReturnStmt"], - "215": ["text_color","CXCursor_GCCAsmStmt"], - "216": ["text_color","CXCursor_ObjCAtTryStmt"], - "217": ["text_color","CXCursor_ObjCAtCatchStmt"], - "218": ["text_color","CXCursor_ObjCAtFinallyStmt"], - "219": ["text_color","CXCursor_ObjCAtThrowStmt"], - "220": ["text_color","CXCursor_ObjCAtSynchronizedStmt"], - "221": ["text_color","CXCursor_ObjCAutoreleasePoolStmt"], - "222": ["text_color","CXCursor_ObjCForCollectionStmt"], - "223": ["text_color","CXCursor_CXXCatchStmt"], - "224": ["text_color","CXCursor_CXXTryStmt"], - "225": ["text_color","CXCursor_CXXForRangeStmt"], - "226": ["text_color","CXCursor_SEHTryStmt"], - "227": ["text_color","CXCursor_SEHExceptStmt"], - "228": ["text_color","CXCursor_SEHFinallyStmt"], - "229": ["text_color","CXCursor_MSAsmStmt"], - "230": ["text_color","CXCursor_NullStmt"], - "231": ["text_color","CXCursor_DeclStmt"], - "232": ["text_color","CXCursor_OMPParallelDirective"], - "233": ["text_color","CXCursor_OMPSimdDirective"], - "234": ["text_color","CXCursor_OMPForDirective"], - "235": ["text_color","CXCursor_OMPSectionsDirective"], - "236": ["text_color","CXCursor_OMPSectionDirective"], - "237": ["text_color","CXCursor_OMPSingleDirective"], - "238": ["text_color","CXCursor_OMPParallelForDirective"], - "239": ["text_color","CXCursor_OMPParallelSectionsDirective"], - "240": ["text_color","CXCursor_OMPTaskDirective"], - "241": ["text_color","CXCursor_OMPMasterDirective"], - "242": ["text_color","CXCursor_OMPCriticalDirective"], - "243": ["text_color","CXCursor_OMPTaskyieldDirective"], - "244": ["text_color","CXCursor_OMPBarrierDirective"], - "245": ["text_color","CXCursor_OMPTaskwaitDirective"], - "246": ["text_color","CXCursor_OMPFlushDirective"], - "247": ["text_color","CXCursor_SEHLeaveStmt"], - "248": ["text_color","CXCursor_OMPOrderedDirective"], - "249": ["text_color","CXCursor_OMPAtomicDirective"], - "250": ["text_color","CXCursor_OMPForSimdDirective"], - "251": ["text_color","CXCursor_OMPParallelForSimdDirective"], - "252": ["text_color","CXCursor_OMPTargetDirective"], - "253": ["text_color","CXCursor_OMPTeamsDirective"], - "300": ["text_color","CXCursor_TranslationUnit"], - "400": ["text_color","CXCursor_FirstAttr"], - "400": ["text_color","CXCursor_UnexposedAttr"], - "401": ["text_color","CXCursor_IBActionAttr"], - "402": ["text_color","CXCursor_IBOutletAttr"], - "403": ["text_color","CXCursor_IBOutletCollectionAttr"], - "404": ["text_color","CXCursor_CXXFinalAttr"], - "405": ["text_color","CXCursor_CXXOverrideAttr"], - "406": ["text_color","CXCursor_AnnotateAttr"], - "407": ["text_color","CXCursor_AsmLabelAttr"], - "408": ["text_color","CXCursor_PackedAttr"], - "409": ["text_color","CXCursor_PureAttr"], - "410": ["text_color","CXCursor_ConstAttr"], - "411": ["text_color","CXCursor_NoDuplicateAttr"], - "412": ["text_color","CXCursor_CUDAConstantAttr"], - "413": ["text_color","CXCursor_CUDADeviceAttr"], - "414": ["text_color","CXCursor_CUDAGlobalAttr"], - "415": ["text_color","CXCursor_CUDAHostAttr"], - "416": ["text_color","CXCursor_CUDASharedAttr"], - "500": ["text_color","CXCursor_PreprocessingDirective"], - "501": ["text_color","CXCursor_MacroDefinition"], - "502": ["text_color","CXCursor_MacroExpansion"], - "503": ["text_color","CXCursor_InclusionDirective"], - "600": ["text_color","CXCursor_ModuleImportDecl"], - "700": ["text_color","CXCursor_OverloadCandidate"] - } + "1": "text_color", + "2": "text_color", + "2": "text_color", + "3": "text_color", + "4": "text_color", + "5": "text_color", + "6": "text_color", + "7": "text_color", + "8": "text_color", + "9": "text_color", + "10": "text_color", + "11": "text_color", + "12": "text_color", + "13": "text_color", + "14": "text_color", + "15": "text_color", + "16": "text_color", + "17": "text_color", + "18": "text_color", + "19": "text_color", + "20": "text_color", + "21": "text_color", + "22": "text_color", + "23": "text_color", + "24": "text_color", + "25": "text_color", + "26": "text_color", + "27": "text_color", + "28": "text_color", + "29": "text_color", + "30": "text_color", + "31": "text_color", + "32": "text_color", + "33": "text_color", + "34": "text_color", + "35": "text_color", + "36": "text_color", + "37": "text_color", + "38": "text_color", + "39": "text_color", + "40": "text_color", + "41": "text_color", + "42": "text_color", + "43": "text_color", + "44": "text_color", + "45": "text_color", + "46": "text_color", + "47": "text_color", + "48": "text_color", + "49": "text_color", + "50": "text_color", + "51": "text_color", + "70": "text_color", + "70": "text_color", + "71": "text_color", + "72": "text_color", + "73": "text_color", + "100": "text_color", + "100": "text_color", + "101": "text_color", + "102": "text_color", + "103": "text_color", + "104": "text_color", + "105": "text_color", + "106": "text_color", + "107": "text_color", + "108": "text_color", + "109": "string", + "110": "text_color", + "111": "text_color", + "112": "text_color", + "113": "text_color", + "114": "text_color", + "115": "text_color", + "116": "text_color", + "117": "text_color", + "118": "text_color", + "119": "text_color", + "120": "text_color", + "121": "text_color", + "122": "text_color", + "123": "text_color", + "124": "text_color", + "125": "text_color", + "126": "text_color", + "127": "text_color", + "128": "text_color", + "129": "text_color", + "130": "text_color", + "131": "text_color", + "132": "text_color", + "133": "text_color", + "134": "text_color", + "135": "text_color", + "136": "text_color", + "137": "text_color", + "138": "text_color", + "139": "text_color", + "140": "text_color", + "141": "text_color", + "142": "text_color", + "143": "text_color", + "144": "text_color", + "145": "text_color", + "146": "text_color", + "200": "text_color", + "200": "text_color", + "201": "text_color", + "202": "text_color", + "203": "text_color", + "204": "text_color", + "205": "text_color", + "206": "text_color", + "207": "text_color", + "208": "text_color", + "209": "text_color", + "210": "text_color", + "211": "text_color", + "212": "text_color", + "213": "text_color", + "214": "text_color", + "215": "text_color", + "216": "text_color", + "217": "text_color", + "218": "text_color", + "219": "text_color", + "220": "text_color", + "221": "text_color", + "222": "text_color", + "223": "text_color", + "224": "text_color", + "225": "text_color", + "226": "text_color", + "227": "text_color", + "228": "text_color", + "229": "text_color", + "230": "text_color", + "231": "text_color", + "232": "text_color", + "233": "text_color", + "234": "text_color", + "235": "text_color", + "236": "text_color", + "237": "text_color", + "238": "text_color", + "239": "text_color", + "240": "text_color", + "241": "text_color", + "242": "text_color", + "243": "text_color", + "244": "text_color", + "245": "text_color", + "246": "text_color", + "247": "text_color", + "248": "text_color", + "249": "text_color", + "250": "text_color", + "251": "text_color", + "252": "text_color", + "253": "text_color", + "300": "text_color", + "400": "text_color", + "400": "text_color", + "401": "text_color", + "402": "text_color", + "403": "text_color", + "404": "text_color", + "405": "text_color", + "406": "text_color", + "407": "text_color", + "408": "text_color", + "409": "text_color", + "410": "text_color", + "411": "text_color", + "412": "text_color", + "413": "text_color", + "414": "text_color", + "415": "text_color", + "416": "text_color", + "500": "text_color", + "501": "text_color", + "502": "text_color", + "503": "text_color", + "600": "text_color", + "700": "text_color" + } } diff --git a/juci/notebook.cc b/juci/notebook.cc index 23a15d4..b003b18 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -14,6 +14,7 @@ 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()); + source_vec_.back()->OnNewEmptyFile(); view_.notebook().append_page(*scrolledwindow_vec_.back(), "juCi++"); @@ -71,6 +72,7 @@ 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()); + source_vec_.back()->OnNewEmptyFile(); view_.notebook().append_page(*scrolledwindow_vec_.back(), name); view_.notebook().show_all_children(); view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); diff --git a/juci/source.cc b/juci/source.cc index 735e8d4..e813fd9 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -1,5 +1,8 @@ #include "source.h" #include +#include "sourcefile.h" +#include +#include ////////////// //// View //// @@ -12,11 +15,10 @@ Source::View::View() { string Source::View::UpdateLine() { Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); // for each word --> check what it is --> apply appropriate tag - - // retUrn ""; + return ""; } -String Source::View::Getline(const Gtk::TextIter &begin) { +string Source::View::GetLine(const Gtk::TextIter &begin) { Gtk::TextIter end(begin); while (!end.ends_line()) end++; @@ -31,12 +33,28 @@ void Source::View::ApplyTheme(const Source::Theme &theme) { } } +void Source::View::OnOpenFile(std::vector &locations, + const Source::Theme &theme) { + Glib::RefPtr buffer = get_buffer(); + for (auto &loc : locations) { + string type = std::to_string(loc.kind()); + int linum = loc.line_number(); + int begin = loc.begin(); + int end = loc.end(); + buffer->apply_tag_by_name(theme.tagtable().at(type), + buffer->get_iter_at_line_offset(linum, begin), + buffer->get_iter_at_line_offset(linum, end)); + } +} // Source::View::Theme::tagtable() // returns a const refrence to the tagtable const std::unordered_map& Source::Theme::tagtable() const { return tagtable_; } +void Source::Theme::InsertTag(const string &key, const string &value) { + tagtable_[key] = value; +} // Source::View::Theme::SetTagTable() // sets the tagtable for the view void Source::Theme::SetTagTable( @@ -47,14 +65,37 @@ void Source::Theme::SetTagTable( /////////////// //// Model //// /////////////// -Source::Model::Model() { +Source::Model::Model() : + theme_() { std::cout << "Model constructor run" << std::endl; + boost::property_tree::ptree pt; + boost::property_tree::json_parser::read_json("config.json", pt); + for ( auto &i : pt ) { + boost::property_tree::ptree props = pt.get_child(i.first); + for (auto &pi : props) { + if (i.first.compare("syntax")) { // checks the config-file + theme_.InsertTag(pi.first, pi.second.get_value()); + } + } + } +} + +Source::Theme& Source::Model::theme() { + return theme_; } const string Source::Model::filepath() { return filepath_; } +void Source::Model::SetFilePath(const string &filepath) { + filepath_ = filepath; +} + +void Source::Model:: +SetSourceLocations(const std::vector &locations) { + locations_ = locations; +} //////////////////// //// Controller //// //////////////////// @@ -82,3 +123,18 @@ Source::Model& Source::Controller::model() { void Source::Controller::OnLineEdit() { view().UpdateLine(); } + +void Source::Controller::OnNewEmptyFile() { + string filename("/tmp/juci_t"); + sourcefile s(filename); + model().SetFilePath(filename); + s.save(""); +} + +void Source::Controller::OnOpenFile(const string &filename) { + sourcefile s(filename); + view().get_buffer()->set_text(s.get_content()); + Clang::TranslationUnit tu(filename.c_str()); + model().SetSourceLocations(tu.getSourceLocations()); + view().OnOpenFile(model().getSourceLocations(), model().theme()); +} diff --git a/juci/source.h b/juci/source.h index 2e06a40..888db11 100644 --- a/juci/source.h +++ b/juci/source.h @@ -5,6 +5,7 @@ #include #include #include "gtkmm.h" +#include using std::string; @@ -13,6 +14,7 @@ namespace Source { public: const std::unordered_map& tagtable() const; void SetTagTable(const std::unordered_map &tagtable); + void InsertTag(const string &key, const string &value); private: std::unordered_map tagtable_; string background_; @@ -23,6 +25,8 @@ namespace Source { View(); string UpdateLine(); void ApplyTheme(const Theme &theme); + void OnOpenFile(std::vector &locations, + const Theme &theme); private: string GetLine(const Gtk::TextIter &begin); }; // class View @@ -30,11 +34,18 @@ namespace Source { class Model{ public: Model(); - Theme theme(); + Theme& theme(); const string filepath(); + void SetFilePath(const string &filepath); + void SetSourceLocations(const std::vector &locations); + std::vector& getSourceLocations() { + return locations_; + } + private: Theme theme_; string filepath_; + std::vector locations_; }; class Controller { @@ -42,12 +53,13 @@ namespace Source { Controller(); View& view(); Model& model(); + void OnNewEmptyFile(); + void OnOpenFile(const string &filename); private: void OnLineEdit(); - void OnOpenFile(); void OnSaveFile(); - + protected: View view_; Model model_; diff --git a/juci/sourcefile.cc b/juci/sourcefile.cc new file mode 100644 index 0000000..0374584 --- /dev/null +++ b/juci/sourcefile.cc @@ -0,0 +1,92 @@ +#include "sourcefile.h" +#include +#include +#include +#include + +using namespace std; + +sourcefile::sourcefile(const string &input_filename) + : lines(), filename(input_filename) { + open(input_filename); +} + +/** + * + */ +void sourcefile::open(const string &filename) { + Gio::init(); + + // Creates/Opens a file specified by the input string. + Glib::RefPtr file = Gio::File::create_for_path(filename); + + if (!file) // Gio::File has overloaded operator + cerr << "Was not able to open file: " << filename << endl; + + // Creates pointer for filestream + + if (!file->query_exists()) { + file->create_file()->close(); + } + + Glib::RefPtr stream = file->read(); + + if (!stream) // error message on stream failure + cerr << filename << " returned an empty stream" << endl; + + Glib::RefPtr + datainput = Gio::DataInputStream::create(stream); + + string line; + while (datainput->read_line(line)) { + lines.push_back(line); + } + + datainput->close(); + stream->close(); +} + +vector sourcefile::get_lines() { + return lines; +} + +string sourcefile::get_line(int line_number) { + return lines[line_number]; +} + +int sourcefile::save(const string &text) { + Gio::init(); + + // Creates/Opens a file specified by the input string. + Glib::RefPtr file = Gio::File::create_for_path(filename); + + if (!file) // Gio::File has overloaded operator + cerr << "Was not able to open file: " << filename << endl; + + // Creates + Glib::RefPtr stream = + file->query_exists() ? file->replace() : file->create_file(); + + if (!stream) // error message on stream failure + cerr << filename << " returned an empty stream" << endl; + + Glib::RefPtr + output = Gio::DataOutputStream::create(stream); + + output->put_string(text); + + output->close(); + stream->close(); + + + return 0; +} + +string sourcefile::get_content() { + string res; + for (auto line : lines) { + res.append(line).append("\n"); + } + return res; +} + diff --git a/juci/sourcefile.h b/juci/sourcefile.h new file mode 100644 index 0000000..608ea05 --- /dev/null +++ b/juci/sourcefile.h @@ -0,0 +1,23 @@ +#ifndef JUCI_SOURCEFILE_H_ +#define JUCI_SOURCEFILE_H_ + +#include +#include + +using namespace std; + +class sourcefile { +public: + explicit sourcefile(const string &filename); + vector get_lines(); + string get_content(); + string get_line(int line_number); + int save(const string &text); + +private: + void open(const string &filename); + vector lines; + string filename; +}; + +#endif // JUCI_SOURCEFILE_H_ From 3ed83dde8cca84871fab5464362590f97692a6a6 Mon Sep 17 00:00:00 2001 From: oyvang Date: Thu, 19 Feb 2015 14:55:53 +0100 Subject: [PATCH 12/13] Open file test for zalox --- juci/notebook.cc | 17 +++++++++------ juci/notebook.h | 2 +- juci/window.cc | 57 ++++++++++++++++++++++++++++++++++++++++++++++++ juci/window.h | 1 + 4 files changed, 69 insertions(+), 8 deletions(-) diff --git a/juci/notebook.cc b/juci/notebook.cc index 2179d26..93cf561 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -21,11 +21,7 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){ keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", Gtk::Stock::FILE)); /* File->New files */ - keybindings.action_group_menu()->add(Gtk::Action::create("FileOpenFile", - Gtk::Stock::OPEN), - [this]() { - OnOpenFile(); - }); + keybindings.action_group_menu()->add(Gtk::Action::create("FileNewStandard", Gtk::Stock::NEW, "New empty file", @@ -136,8 +132,15 @@ void Notebook::Controller::OnEditCut() { } } -void Notebook::Controller::OnOpenFile() { - std::cout << "fired" << std::endl; +void Notebook::Controller::OnOpenFile(std::string name, std::string content){ + scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); + source_vec_.push_back(new Source::Controller); + scrolledwindow_vec_.back()->add(source_vec_.back()->view()); + source_vec_.back()->view().get_buffer()->set_text(content); + view_.notebook().append_page(*scrolledwindow_vec_.back(), name); + view_.notebook().show_all_children(); + view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); + view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); } diff --git a/juci/notebook.h b/juci/notebook.h index 2e15b57..7afb31f 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -36,7 +36,7 @@ namespace Notebook { void OnEditCopy(); void OnEditPaste(); void OnEditCut(); - void OnOpenFile(); + void OnOpenFile(std::string name, std::string content); }; // class controller } // namespace Notebook diff --git a/juci/window.cc b/juci/window.cc index 38b5da6..2e3942d 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -12,6 +12,11 @@ Window::Window() : [this]() { OnWindowHide(); }); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", + Gtk::Stock::OPEN), + [this]() { + OnOpenFile(); + }); add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); @@ -23,3 +28,55 @@ Window::Window() : void Window::OnWindowHide() { hide(); } + +void Window::OnOpenFile() { + Gtk::FileChooserDialog dialog("Please choose a file", + Gtk::FILE_CHOOSER_ACTION_OPEN); + dialog.set_transient_for(*this); + dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); + + //Add response buttons the the dialog: + dialog.add_button("_Cancel", Gtk::RESPONSE_CANCEL); + dialog.add_button("_Open", Gtk::RESPONSE_OK); + + //Add filters, so that only certain file types can be selected: + Glib::RefPtr filter_text = Gtk::FileFilter::create(); + filter_text->set_name("Text files"); + filter_text->add_mime_type("text/plain"); + dialog.add_filter(filter_text); + + Glib::RefPtr filter_cpp = Gtk::FileFilter::create(); + filter_cpp->set_name("C/C++ files"); + filter_cpp->add_mime_type("text/x-c"); + filter_cpp->add_mime_type("text/x-c++"); + filter_cpp->add_mime_type("text/x-c-header"); + dialog.add_filter(filter_cpp); + + Glib::RefPtr filter_any = Gtk::FileFilter::create(); + filter_any->set_name("Any files"); + filter_any->add_pattern("*"); + dialog.add_filter(filter_any); + + int result = dialog.run(); + + switch (result) { + case(Gtk::RESPONSE_OK): { + std::cout << "Open clicked." << std::endl; + + std::string path = dialog.get_filename(); + std::cout << "File selected: " << path << std::endl; + Source::Controller sourcefile; + notebook_.OnOpenFile(path, sourcefile.OnOpenFile(path)); + break; + } + case(Gtk::RESPONSE_CANCEL): { + std::cout << "Cancel clicked." << std::endl; + break; + } + default: { + std::cout << "Unexpected button clicked." << std::endl; + break; + } + } + +} diff --git a/juci/window.h b/juci/window.h index ba275a7..d002781 100644 --- a/juci/window.h +++ b/juci/window.h @@ -17,6 +17,7 @@ private: //signal handlers void OnWindowHide(); + void OnOpenFile(); }; #endif // JUCI_WINDOW_H_ From 11755ae716bf5769302f57776e38047ef89040db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 20 Feb 2015 10:57:32 +0100 Subject: [PATCH 13/13] Commit --- juci/keybindings.cc | 2 +- juci/menu.cc | 65 +++++++++++++++++++++------------------------ juci/notebook.cc | 12 ++++----- juci/notebook.h | 4 +-- juci/source.cc | 33 ++++++++++++++++++++++- juci/source.h | 5 ++++ juci/window.cc | 4 +-- 7 files changed, 78 insertions(+), 47 deletions(-) diff --git a/juci/keybindings.cc b/juci/keybindings.cc index dd5b45d..d24bf47 100644 --- a/juci/keybindings.cc +++ b/juci/keybindings.cc @@ -54,7 +54,7 @@ Keybindings::Controller::Controller() { action_group_hidden_ = Gtk::ActionGroup::create(); ui_manager_hidden_ = Gtk::UIManager::create(); } -Keybindings::Controller::~Controller(){ +Keybindings::Controller::~Controller() { } void Keybindings::Controller::BuildMenu() { try { diff --git a/juci/menu.cc b/juci/menu.cc index be004ca..8f7bd15 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -4,10 +4,9 @@ Menu::View::View(Gtk::Orientation orientation) : 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_; } @@ -15,48 +14,46 @@ Gtk::Box &Menu::View::view( Menu::Controller::Controller(Keybindings::Controller& keybindings) : menu_view_(Gtk::ORIENTATION_VERTICAL), keybindings_(keybindings) { - keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", - Gtk::Stock::OPEN), - [this]() { - OnFileOpenFile(); - }); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew", + Gtk::Stock::FILE)); + keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", - "Open folder"), - [this]() { - OnFileOpenFolder(); - }); + "Open folder"), + [this]() { + OnFileOpenFolder(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", - Gtk::Stock::EDIT)); + 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(); - }); + "Split window"), + Gtk::AccelKey("S"), + [this]() { + OnWindowSplitWindow(); + }); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", - "_Plugins")); + "_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(); - }); + "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(); - }); + 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(); } // Controller diff --git a/juci/notebook.cc b/juci/notebook.cc index 93cf561..cad945d 100644 --- a/juci/notebook.cc +++ b/juci/notebook.cc @@ -108,7 +108,7 @@ void Notebook::Controller::OnFileNewHeaderFile() { entry_.OnShowSetFilenName(".h"); } void Notebook::Controller::OnEditCopy() { - if(view_.notebook().get_n_pages()!=0){ + if (view_.notebook().get_n_pages() != 0) { int source_pos = view_.notebook().get_current_page(); Glib::RefPtr buffer = source_vec_.at(source_pos) ->view().get_buffer(); @@ -116,7 +116,7 @@ void Notebook::Controller::OnEditCopy() { } } void Notebook::Controller::OnEditPaste() { - if(view_.notebook().get_n_pages()!=0){ + if (view_.notebook().get_n_pages() != 0) { int source_pos = view_.notebook().get_current_page(); Glib::RefPtr buffer = source_vec_.at(source_pos) ->view().get_buffer(); @@ -124,7 +124,7 @@ void Notebook::Controller::OnEditPaste() { } } void Notebook::Controller::OnEditCut() { - if(view_.notebook().get_n_pages()!=0){ + if (view_.notebook().get_n_pages() != 0) { int source_pos = view_.notebook().get_current_page(); Glib::RefPtr buffer = source_vec_.at(source_pos) ->view().get_buffer(); @@ -132,12 +132,12 @@ void Notebook::Controller::OnEditCut() { } } -void Notebook::Controller::OnOpenFile(std::string name, std::string content){ +void Notebook::Controller::OnOpenFile(std::string filename) { scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); source_vec_.push_back(new Source::Controller); scrolledwindow_vec_.back()->add(source_vec_.back()->view()); - source_vec_.back()->view().get_buffer()->set_text(content); - view_.notebook().append_page(*scrolledwindow_vec_.back(), name); + source_vec_.back()->OnOpenFile(filename); + view_.notebook().append_page(*scrolledwindow_vec_.back(), filename); view_.notebook().show_all_children(); view_.notebook().set_focus_child(*scrolledwindow_vec_.back()); view_.notebook().set_current_page(view_.notebook().get_n_pages()-1); diff --git a/juci/notebook.h b/juci/notebook.h index 7afb31f..7dfe02f 100644 --- a/juci/notebook.h +++ b/juci/notebook.h @@ -11,7 +11,7 @@ namespace Notebook { public: View(); Gtk::Box& view(); - Gtk::Notebook& notebook(){return notebook_;} + Gtk::Notebook& notebook() { return notebook_; } protected: Gtk::Box view_; Gtk::Notebook notebook_; @@ -23,6 +23,7 @@ namespace Notebook { Gtk::Box& entry_view(); void OnNewPage(std::string name); void OnCloseCurrentPage(); + void OnOpenFile(std::string filename); private: View view_; Entry::Controller entry_; @@ -36,7 +37,6 @@ namespace Notebook { void OnEditCopy(); void OnEditPaste(); void OnEditCut(); - void OnOpenFile(std::string name, std::string content); }; // class controller } // namespace Notebook diff --git a/juci/source.cc b/juci/source.cc index e813fd9..7b12dc1 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -14,6 +14,7 @@ Source::View::View() { // returns the new line string Source::View::UpdateLine() { Gtk::TextIter line(get_buffer()->get_insert()->get_iter()); + // std::cout << line.get_line() << std::endl; // for each word --> check what it is --> apply appropriate tag return ""; } @@ -41,9 +42,18 @@ void Source::View::OnOpenFile(std::vector &locations, int linum = loc.line_number(); int begin = loc.begin(); int end = loc.end(); - buffer->apply_tag_by_name(theme.tagtable().at(type), + if(end < 0) end = 0; + if(begin < 0) begin = 0; + + // for (auto &i : theme.tagtable()) { + // std::cout << "first: "<< i.first << " second: "<< i.second << std::endl; + // } + + // std::cout << "type: " << type << std::endl; + buffer->apply_tag_by_name(theme.typetable().at(type), buffer->get_iter_at_line_offset(linum, begin), buffer->get_iter_at_line_offset(linum, end)); + // std::cout << "This is a ans" << std::endl; } } // Source::View::Theme::tagtable() @@ -52,11 +62,27 @@ const std::unordered_map& Source::Theme::tagtable() const { return tagtable_; } +// Source::View::Theme::tagtable() +// returns a const refrence to the tagtable +const std::unordered_map& Source::Theme::typetable() const { + return typetable_; +} + void Source::Theme::InsertTag(const string &key, const string &value) { tagtable_[key] = value; } // Source::View::Theme::SetTagTable() // sets the tagtable for the view +void Source::Theme::SetTypeTable( + const std::unordered_map &typetable) { + typetable_ = typetable; +} + +void Source::Theme::InsertType(const string &key, const string &value) { + typetable_[key] = value; +} +// Source::View::Theme::SetTagTable() +// sets the tagtable for the view void Source::Theme::SetTagTable( const std::unordered_map &tagtable) { tagtable_ = tagtable; @@ -75,6 +101,11 @@ Source::Model::Model() : for (auto &pi : props) { if (i.first.compare("syntax")) { // checks the config-file theme_.InsertTag(pi.first, pi.second.get_value()); + // std::cout << "inserting tag. " << pi.first << pi.second.get_value() << std::endl; + } + if (i.first.compare("colors")) { // checks the config-file + theme_.InsertType(pi.first, pi.second.get_value()); + // std::cout << "inserting type. " << pi.first << pi.second.get_value() << std::endl; } } } diff --git a/juci/source.h b/juci/source.h index 888db11..8b7011f 100644 --- a/juci/source.h +++ b/juci/source.h @@ -13,10 +13,15 @@ namespace Source { class Theme { public: const std::unordered_map& tagtable() const; + const std::unordered_map& typetable() const; void SetTagTable(const std::unordered_map &tagtable); void InsertTag(const string &key, const string &value); + void SetTypeTable(const std::unordered_map &tagtable); + void InsertType(const string &key, const string &value); + private: std::unordered_map tagtable_; + std::unordered_map typetable_; string background_; }; // class Theme diff --git a/juci/window.cc b/juci/window.cc index 2e3942d..5db176e 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -62,11 +62,9 @@ void Window::OnOpenFile() { switch (result) { case(Gtk::RESPONSE_OK): { std::cout << "Open clicked." << std::endl; - std::string path = dialog.get_filename(); std::cout << "File selected: " << path << std::endl; - Source::Controller sourcefile; - notebook_.OnOpenFile(path, sourcefile.OnOpenFile(path)); + notebook_.OnOpenFile(path); break; } case(Gtk::RESPONSE_CANCEL): {