diff --git a/juci/CMakeLists.txt b/juci/CMakeLists.txt index 57c6030..9f93102 100644 --- a/juci/CMakeLists.txt +++ b/juci/CMakeLists.txt @@ -104,7 +104,7 @@ include_directories( ${Boost_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS} - "/home/zalox/bachelor/libclang++/headers/" + ${LCL_INCLUDE_DIRS} ) link_directories( ${GTKMM_LIBRARY_DIRS} diff --git a/juci/api.cc b/juci/api.cc index 42149d0..196b1f8 100644 --- a/juci/api.cc +++ b/juci/api.cc @@ -1,47 +1,80 @@ #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::shared_ptr libjuci::ApiServiceProvider::menu_; +std::shared_ptr libjuci::ApiServiceProvider::notebook_; - std::cout << "The string: " << g_test_string << std::endl; - } +///////////////////////////// +//// API ServiceProvider //// +///////////////////////////// +libjuci::ApiServiceProvider::ApiServiceProvider( ){ + std::cout << "Apiservice std.ctor" << std::endl; +} +void libjuci::ApiServiceProvider::ReplaceWord(std::string word){ + std::cout << word << std::endl; +} +void libjuci::ApiServiceProvider::ReplaceLine(std::string line){} - 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 libjuci::ApiServiceProvider::AddKeybinding() { + + libjuci::ApiServiceProvider::menu_->keybindings_.action_group_menu() + ->add(Gtk::Action::create("PluginAddSnippet", + "Add snippet"), + Gtk::AccelKey("space"), + []() { + std::cout << "ctrl alt space" << std::endl; + libjuci::LoadPlugin("juci_api_test"); + }); + std::cout << "addkeybinding" << std::endl; +} + +/////////////////////// +//// Api to python //// +/////////////////////// +void libjuci::ReplaceWord(const std::string word_) { + //TODO implement libjuci::ReplaceWord / change string to iter? + //some_namespace::controller::replaceWord(word_*); + //std::cout << "unimplemented function: 'libjuci::ReplaceWord()' called" + // << std::endl; + + //libjuci::ApiServiceProvider::ReplaceWord(word); - 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(); - } + std::cout << "The string: " << word_ << std::endl; +} + +void libjuci::ReplaceLine(const std::string line) { + //TODO implement libjuci::ReplaceLine / change string to iter? + //some_namespace::controller::replaceLine(line_); + std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called" + << std::endl; +} +////////////////////////////// +//// Boost.Python methods //// +////////////////////////////// + +boost::python::api::object libjuci::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 libjuci::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 9bd42c4..9f096a2 100644 --- a/juci/api.h +++ b/juci/api.h @@ -4,44 +4,43 @@ #include #include #include +#include "notebook.h" +#include "menu.h" -// Plugin 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 { +const std::string g_project_root("/home/forgie/app/juci/"); - - // Replaceword: - // replaces a word in the editor with a string - +namespace libjuci { + +///////////////////////////// +//// API ServiceProvider //// +///////////////////////////// + struct ApiServiceProvider { + public: + static std::shared_ptr menu_; + static std::shared_ptr notebook_; + + ApiServiceProvider(); + static void ReplaceWord(const std::string word); + void ReplaceLine(const std::string line); + static void AddKeybinding(); + }; + +/////////////////////// +//// Api to python //// +/////////////////////// void ReplaceWord(const std::string word_); - - // - // ReplaceLine: - // Replaces a line in the editor with a string - // - void ReplaceLine(const std::string line_); - - }//namespace cpp - // - // calls from C++ to Python - // - namespace py { - + void ReplaceLine(const std::string line_); - //helpers +////////////////////////////// +//// Boost.Python methods //// +////////////////////////////// boost::python::api::object openPythonScript(const std::string path, boost::python::api::object python_name_space); //void snippet(std::string& word); void LoadPlugin(const std::string& plugin_name); - }// py -}//juci_api + +}//api #endif // JUCI_API_H diff --git a/juci/api_ext.cc b/juci/api_ext.cc index 8ea43b2..2104278 100644 --- a/juci/api_ext.cc +++ b/juci/api_ext.cc @@ -1,7 +1,8 @@ #include "api.h" + BOOST_PYTHON_MODULE(juci_to_python_api) { using namespace boost::python; // text editing - def("replaceLine", &juci_api::cpp::ReplaceLine); - def("replaceWord", &juci_api::cpp::ReplaceWord); - }// module::juci + def("replaceLine", &libjuci::ReplaceLine); + def("replaceWord", &libjuci::ReplaceWord); + }// module::juci \ No newline at end of file diff --git a/juci/cmake/Modules/FindTestlcl.cmake b/juci/cmake/Modules/FindTestlcl.cmake index 526cdfe..c28720f 100644 --- a/juci/cmake/Modules/FindTestlcl.cmake +++ b/juci/cmake/Modules/FindTestlcl.cmake @@ -10,11 +10,11 @@ find_package(PkgConfig) find_path(LCL_INCLUDE_DIR headers/TranslationUnit.h - HINTS "/home/zalox/bachelor/libclang++/" + HINTS "/home/forgie/code/libclangpp/" ) find_library(LCL_LIBRARY NAMES testlcl - HINTS "/home/zalox/bachelor/libclang++/lib") + HINTS "/home/forgie/code/libclangpp/lib") set(LCL_LIBRARIES ${LCL_LIBRARY} ) set(LCL_INCLUDE_DIRS ${LCL_INCLUDE_DIR} ) diff --git a/juci/juci.cc b/juci/juci.cc index 68a06ad..84b1e6f 100644 --- a/juci/juci.cc +++ b/juci/juci.cc @@ -7,5 +7,7 @@ int main(int argc, char *argv[]) { argv, "no.sout.juci"); Window window; + + //api::LoadPlugin("juci_api_test"); return app->run(window); } diff --git a/juci/menu.cc b/juci/menu.cc index 8f7bd15..1121674 100644 --- a/juci/menu.cc +++ b/juci/menu.cc @@ -36,12 +36,12 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) : "_Plugins")); keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", "Snippet")); - keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", + /*keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", "Add snippet"), Gtk::AccelKey("space"), [this]() { OnPluginAddSnippet(); - }); + });*/ keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", Gtk::Stock::HELP)); keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", @@ -62,8 +62,8 @@ Gtk::Box &Menu::Controller::view() { } void Menu::Controller::OnPluginAddSnippet() { //TODO(Forgi add you snippet magic code) - std::cout << "Add snipper" << std::endl; - juci_api::py::LoadPlugin("snippet"); + std::cout << "Add snippet" << std::endl; + //juci_api::py::LoadPlugin("snippet"); } void Menu::Controller::OnFileOpenFile() { std::cout << "Open file clicked" << std::endl; diff --git a/juci/menu.h b/juci/menu.h index 8e00bad..f743999 100644 --- a/juci/menu.h +++ b/juci/menu.h @@ -4,7 +4,6 @@ #include #include "gtkmm.h" #include "keybindings.h" -#include "api.h" namespace Menu { class View { @@ -18,7 +17,7 @@ namespace Menu { public: explicit Controller(Keybindings::Controller& keybindings); Gtk::Box &view(); - private: + Keybindings::Controller &keybindings_; View menu_view_; void OnFileNewEmptyfile(); diff --git a/juci/source.cc b/juci/source.cc index 7b12dc1..b93bf4a 100644 --- a/juci/source.cc +++ b/juci/source.cc @@ -92,7 +92,7 @@ void Source::Theme::SetTagTable( //// Model //// /////////////// Source::Model::Model() : - theme_() { + theme_() {/* std::cout << "Model constructor run" << std::endl; boost::property_tree::ptree pt; boost::property_tree::json_parser::read_json("config.json", pt); @@ -108,7 +108,7 @@ Source::Model::Model() : // std::cout << "inserting type. " << pi.first << pi.second.get_value() << std::endl; } } - } + }*/ } Source::Theme& Source::Model::theme() { diff --git a/juci/window.cc b/juci/window.cc index 5db176e..3919c47 100644 --- a/juci/window.cc +++ b/juci/window.cc @@ -17,6 +17,11 @@ Window::Window() : [this]() { OnOpenFile(); }); + + libjuci::ApiServiceProvider::menu_ = std::shared_ptr(&menu_); + libjuci::ApiServiceProvider::notebook_ = std::shared_ptr(¬ebook_); + libjuci::ApiServiceProvider::AddKeybinding(); + add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); @@ -25,7 +30,10 @@ Window::Window() : window_box_.pack_start(notebook_.view()); show_all_children(); } // Window constructor -void Window::OnWindowHide() { +void Window::OnWindowHide(){ + //TODO forgie: find out how to 'remove' the pointers + libjuci::ApiServiceProvider::notebook_ = std::shared_ptr(nullptr); + libjuci::ApiServiceProvider::menu_ = std::shared_ptr(nullptr); hide(); } diff --git a/juci/window.h b/juci/window.h index d002781..eac2412 100644 --- a/juci/window.h +++ b/juci/window.h @@ -3,14 +3,14 @@ #include #include "gtkmm.h" -#include "menu.h" -#include "notebook.h" +#include "api.h" +#include class Window : public Gtk::Window { public: Window(); Gtk::Box window_box_; -private: +//private: Keybindings::Controller keybindings_; Menu::Controller menu_; Notebook::Controller notebook_; @@ -21,3 +21,4 @@ private: }; #endif // JUCI_WINDOW_H_ +