Browse Source

progress

master
tedjk 11 years ago
parent
commit
3cd445fbcc
  1. 2
      juci/CMakeLists.txt
  2. 113
      juci/api.cc
  3. 57
      juci/api.h
  4. 7
      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}
${PYTHON_INCLUDE_DIRS}
${GTKMM_INCLUDE_DIRS}
"/home/zalox/bachelor/libclang++/headers/"
${LCL_INCLUDE_DIRS}
)
link_directories(
${GTKMM_LIBRARY_DIRS}

113
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<Menu::Controller> libjuci::ApiServiceProvider::menu_;
std::shared_ptr<Notebook::Controller> 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("<control><alt>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<std::string>(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<std::string>(pySnippet);
/* add snippet to textView */
//TODO add snippet
}catch(boost::python::error_already_set const&) {
PyErr_Print();
}
}

57
juci/api.h

@ -4,44 +4,43 @@
#include <boost/python.hpp>
#include <Python.h>
#include <string>
#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::Controller> menu_;
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_);
//
// 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

7
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

4
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} )

2
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);
}

8
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("<alt>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;

3
juci/menu.h

@ -4,7 +4,6 @@
#include <iostream>
#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();

4
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::string>() << std::endl;
}
}
}
}*/
}
Source::Theme& Source::Model::theme() {

10
juci/window.cc

@ -17,6 +17,11 @@ Window::Window() :
[this]() {
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_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<Notebook::Controller>(nullptr);
libjuci::ApiServiceProvider::menu_ = std::shared_ptr<Menu::Controller>(nullptr);
hide();
}

7
juci/window.h

@ -3,14 +3,14 @@
#include <iostream>
#include "gtkmm.h"
#include "menu.h"
#include "notebook.h"
#include "api.h"
#include <cstddef>
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_

Loading…
Cancel
Save