Browse Source

progress

master
tedjk 11 years ago
parent
commit
3cd445fbcc
  1. 2
      juci/CMakeLists.txt
  2. 111
      juci/api.cc
  3. 59
      juci/api.h
  4. 5
      juci/api_ext.cc
  5. 4
      juci/cmake/Modules/FindTestlcl.cmake
  6. 2
      juci/juci.cc
  7. 8
      juci/menu.cc
  8. 3
      juci/menu.h
  9. 4
      juci/source.cc
  10. 10
      juci/window.cc
  11. 7
      juci/window.h

2
juci/CMakeLists.txt

@ -104,7 +104,7 @@ include_directories(
${Boost_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS}
${PYTHON_INCLUDE_DIRS} ${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS} ${GTKMM_INCLUDE_DIRS}
"/home/zalox/bachelor/libclang++/headers/" ${LCL_INCLUDE_DIRS}
) )
link_directories( link_directories(
${GTKMM_LIBRARY_DIRS} ${GTKMM_LIBRARY_DIRS}

111
juci/api.cc

@ -1,47 +1,80 @@
#include "api.h" #include "api.h"
namespace juci_api{
void cpp::ReplaceWord(const std::string word) { std::shared_ptr<Menu::Controller> libjuci::ApiServiceProvider::menu_;
//TODO implement api::ReplaceWord / change string to iter? std::shared_ptr<Notebook::Controller> libjuci::ApiServiceProvider::notebook_;
//some_namespace::controller::replaceWord(word_*);
std::cout << "unimplemented function: 'api::ReplaceWord()' called"
<< std::endl;
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) { void libjuci::ApiServiceProvider::AddKeybinding() {
//TODO implement api::ReplaceLine / change string to iter?
//some_namespace::controller::replaceLine(line_);
std::cout << "unimplemented function: 'api::ReplaceLine()' called"
<< std::endl;
}
//helpers libjuci::ApiServiceProvider::menu_->keybindings_.action_group_menu()
boost::python::api::object py::openPythonScript(const std::string path, ->add(Gtk::Action::create("PluginAddSnippet",
boost::python::api::object python_name_space) { "Add snippet"),
std::string temp = g_project_root + path + ".py"; Gtk::AccelKey("<control><alt>space"),
boost::python::str the_path(temp); []() {
return boost::python::exec_file(the_path, python_name_space);//, python_name_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) { std::cout << "The string: " << word_ << std::endl;
try{ }
/* initialize python interpreter */
Py_Initialize(); void libjuci::ReplaceLine(const std::string line) {
boost::python::api::object main_module = boost::python::import("__main__"); //TODO implement libjuci::ReplaceLine / change string to iter?
boost::python::api::object main_namespace = main_module.attr("__dict__"); //some_namespace::controller::replaceLine(line_);
std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called"
/* runs script from python */ << std::endl;
//boost::python::object ignored1 = setPythonVar("word", word, main_namespace); }
boost::python::api::object ignored2 = openPythonScript(plugin_name, main_namespace); //////////////////////////////
/* extracts desired values */ //// Boost.Python methods ////
//boost::python::object pySnippet = boost::python::eval("getSnippet()", main_namespace); //////////////////////////////
//word = boost::python::extract<std::string>(pySnippet);
/* add snippet to textView */ boost::python::api::object libjuci::openPythonScript(const std::string path,
//TODO add snippet boost::python::api::object python_name_space) {
}catch(boost::python::error_already_set const&) { std::string temp = g_project_root + path + ".py";
PyErr_Print(); 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<std::string>(pySnippet);
/* add snippet to textView */
//TODO add snippet
}catch(boost::python::error_already_set const&) {
PyErr_Print();
} }
} }

59
juci/api.h

@ -4,44 +4,43 @@
#include <boost/python.hpp> #include <boost/python.hpp>
#include <Python.h> #include <Python.h>
#include <string> #include <string>
#include "notebook.h"
// Plugin API #include "menu.h"
//
const std::string g_project_root("/home/forgie/bachelor/app/juci/"); const std::string g_project_root("/home/forgie/app/juci/");
static std::string g_test_string("test");
namespace juci_api { namespace libjuci {
//
// calls from python to C++ /////////////////////////////
// //// API ServiceProvider ////
namespace cpp { /////////////////////////////
struct ApiServiceProvider {
public:
// Replaceword: static std::shared_ptr<Menu::Controller> menu_;
// replaces a word in the editor with a string static std::shared_ptr<Notebook::Controller> 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_); void ReplaceWord(const std::string word_);
//
// ReplaceLine:
// Replaces a line in the editor with a string
//
void ReplaceLine(const std::string line_); void ReplaceLine(const std::string line_);
}//namespace cpp //////////////////////////////
//// Boost.Python methods ////
// //////////////////////////////
// calls from C++ to Python
//
namespace py {
//helpers
boost::python::api::object openPythonScript(const std::string path, boost::python::api::object openPythonScript(const std::string path,
boost::python::api::object python_name_space); boost::python::api::object python_name_space);
//void snippet(std::string& word); //void snippet(std::string& word);
void LoadPlugin(const std::string& plugin_name); void LoadPlugin(const std::string& plugin_name);
}// py
}//juci_api }//api
#endif // JUCI_API_H #endif // JUCI_API_H

5
juci/api_ext.cc

@ -1,7 +1,8 @@
#include "api.h" #include "api.h"
BOOST_PYTHON_MODULE(juci_to_python_api) { BOOST_PYTHON_MODULE(juci_to_python_api) {
using namespace boost::python; using namespace boost::python;
// text editing // text editing
def("replaceLine", &juci_api::cpp::ReplaceLine); def("replaceLine", &libjuci::ReplaceLine);
def("replaceWord", &juci_api::cpp::ReplaceWord); def("replaceWord", &libjuci::ReplaceWord);
}// module::juci }// module::juci

4
juci/cmake/Modules/FindTestlcl.cmake

@ -10,11 +10,11 @@
find_package(PkgConfig) find_package(PkgConfig)
find_path(LCL_INCLUDE_DIR headers/TranslationUnit.h find_path(LCL_INCLUDE_DIR headers/TranslationUnit.h
HINTS "/home/zalox/bachelor/libclang++/" HINTS "/home/forgie/code/libclangpp/"
) )
find_library(LCL_LIBRARY NAMES testlcl 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_LIBRARIES ${LCL_LIBRARY} )
set(LCL_INCLUDE_DIRS ${LCL_INCLUDE_DIR} ) set(LCL_INCLUDE_DIRS ${LCL_INCLUDE_DIR} )

2
juci/juci.cc

@ -7,5 +7,7 @@ int main(int argc, char *argv[]) {
argv, argv,
"no.sout.juci"); "no.sout.juci");
Window window; Window window;
//api::LoadPlugin("juci_api_test");
return app->run(window); return app->run(window);
} }

8
juci/menu.cc

@ -36,12 +36,12 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
"_Plugins")); "_Plugins"));
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet", keybindings_.action_group_menu()->add(Gtk::Action::create("PluginSnippet",
"Snippet")); "Snippet"));
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet", /*keybindings_.action_group_menu()->add(Gtk::Action::create("PluginAddSnippet",
"Add snippet"), "Add snippet"),
Gtk::AccelKey("<alt>space"), Gtk::AccelKey("<alt>space"),
[this]() { [this]() {
OnPluginAddSnippet(); OnPluginAddSnippet();
}); });*/
keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu", keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu",
Gtk::Stock::HELP)); Gtk::Stock::HELP));
keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout", keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout",
@ -62,8 +62,8 @@ Gtk::Box &Menu::Controller::view() {
} }
void Menu::Controller::OnPluginAddSnippet() { void Menu::Controller::OnPluginAddSnippet() {
//TODO(Forgi add you snippet magic code) //TODO(Forgi add you snippet magic code)
std::cout << "Add snipper" << std::endl; std::cout << "Add snippet" << std::endl;
juci_api::py::LoadPlugin("snippet"); //juci_api::py::LoadPlugin("snippet");
} }
void Menu::Controller::OnFileOpenFile() { void Menu::Controller::OnFileOpenFile() {
std::cout << "Open file clicked" << std::endl; std::cout << "Open file clicked" << std::endl;

3
juci/menu.h

@ -4,7 +4,6 @@
#include <iostream> #include <iostream>
#include "gtkmm.h" #include "gtkmm.h"
#include "keybindings.h" #include "keybindings.h"
#include "api.h"
namespace Menu { namespace Menu {
class View { class View {
@ -18,7 +17,7 @@ namespace Menu {
public: public:
explicit Controller(Keybindings::Controller& keybindings); explicit Controller(Keybindings::Controller& keybindings);
Gtk::Box &view(); Gtk::Box &view();
private:
Keybindings::Controller &keybindings_; Keybindings::Controller &keybindings_;
View menu_view_; View menu_view_;
void OnFileNewEmptyfile(); void OnFileNewEmptyfile();

4
juci/source.cc

@ -92,7 +92,7 @@ void Source::Theme::SetTagTable(
//// Model //// //// Model ////
/////////////// ///////////////
Source::Model::Model() : Source::Model::Model() :
theme_() { theme_() {/*
std::cout << "Model constructor run" << std::endl; std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree pt; boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json("config.json", 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::string>() << std::endl; // std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
} }
} }
} }*/
} }
Source::Theme& Source::Model::theme() { Source::Theme& Source::Model::theme() {

10
juci/window.cc

@ -17,6 +17,11 @@ Window::Window() :
[this]() { [this]() {
OnOpenFile(); OnOpenFile();
}); });
libjuci::ApiServiceProvider::menu_ = std::shared_ptr<Menu::Controller>(&menu_);
libjuci::ApiServiceProvider::notebook_ = std::shared_ptr<Notebook::Controller>(&notebook_);
libjuci::ApiServiceProvider::AddKeybinding();
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings_.ui_manager_menu()->get_accel_group());
add_accel_group(keybindings_.ui_manager_hidden()->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()); window_box_.pack_start(notebook_.view());
show_all_children(); show_all_children();
} // Window constructor } // Window constructor
void Window::OnWindowHide() { void Window::OnWindowHide(){
//TODO forgie: find out how to 'remove' the pointers
libjuci::ApiServiceProvider::notebook_ = std::shared_ptr<Notebook::Controller>(nullptr);
libjuci::ApiServiceProvider::menu_ = std::shared_ptr<Menu::Controller>(nullptr);
hide(); hide();
} }

7
juci/window.h

@ -3,14 +3,14 @@
#include <iostream> #include <iostream>
#include "gtkmm.h" #include "gtkmm.h"
#include "menu.h" #include "api.h"
#include "notebook.h" #include <cstddef>
class Window : public Gtk::Window { class Window : public Gtk::Window {
public: public:
Window(); Window();
Gtk::Box window_box_; Gtk::Box window_box_;
private: //private:
Keybindings::Controller keybindings_; Keybindings::Controller keybindings_;
Menu::Controller menu_; Menu::Controller menu_;
Notebook::Controller notebook_; Notebook::Controller notebook_;
@ -21,3 +21,4 @@ private:
}; };
#endif // JUCI_WINDOW_H_ #endif // JUCI_WINDOW_H_

Loading…
Cancel
Save