|
|
|
@ -1,16 +1,13 @@ |
|
|
|
#include "api.h" |
|
|
|
#include "api.h" |
|
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<Menu::Controller> libjuci::ApiServiceProvider::menu_; |
|
|
|
std::shared_ptr<Menu::Controller> PluginApi::menu_; |
|
|
|
std::shared_ptr<Notebook::Controller> libjuci::ApiServiceProvider::notebook_; |
|
|
|
std::shared_ptr<Notebook::Controller> PluginApi::notebook_; |
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
/////////////////////////////
|
|
|
|
//// API ServiceProvider ////
|
|
|
|
//// API ServiceProvider ////
|
|
|
|
/////////////////////////////
|
|
|
|
/////////////////////////////
|
|
|
|
libjuci::ApiServiceProvider::ApiServiceProvider( ) { |
|
|
|
|
|
|
|
std::cout << "Apiservice std.ctor" << std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void libjuci::ApiServiceProvider::ReplaceWord(std::string word) { |
|
|
|
void PluginApi::ReplaceWord(std::string word) { |
|
|
|
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook(); |
|
|
|
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook(); |
|
|
|
Gtk::TextIter word_start = libjuci::IterFromNotebook(); |
|
|
|
Gtk::TextIter word_start = libjuci::IterFromNotebook(); |
|
|
|
Gtk::TextIter word_end = libjuci::IterFromNotebook(); |
|
|
|
Gtk::TextIter word_end = libjuci::IterFromNotebook(); |
|
|
|
@ -24,12 +21,12 @@ void libjuci::ApiServiceProvider::ReplaceWord(std::string word) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::ApiServiceProvider::ReplaceLine(std::string line) { |
|
|
|
void PluginApi::ReplaceLine(std::string line) { |
|
|
|
std::cout << "Unimplemented function: ApiServiceProvider::ReplaceLine(string)" |
|
|
|
std::cout << "unimplemented: " << __func__ << std::endl; |
|
|
|
<< std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string libjuci::ApiServiceProvider::GetWord() { |
|
|
|
std::string PluginApi::GetWord() { |
|
|
|
|
|
|
|
// TODO forgie: use notebook's functions
|
|
|
|
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook();
|
|
|
|
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook();
|
|
|
|
Gtk::TextIter word_start = libjuci::IterFromNotebook(); |
|
|
|
Gtk::TextIter word_start = libjuci::IterFromNotebook(); |
|
|
|
Gtk::TextIter word_end = libjuci::IterFromNotebook(); |
|
|
|
Gtk::TextIter word_end = libjuci::IterFromNotebook(); |
|
|
|
@ -44,49 +41,28 @@ std::string libjuci::ApiServiceProvider::GetWord() { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::ApiServiceProvider::AddKeybinding() { |
|
|
|
//runs the pythonscript that initiates every plugin within plugins/
|
|
|
|
|
|
|
|
void PluginApi::InitPlugins() { |
|
|
|
libjuci::LoadPlugin(g_project_root+"plugins.py"); |
|
|
|
libjuci::LoadPlugin(g_project_root+"plugins.py"); |
|
|
|
|
|
|
|
|
|
|
|
// libjuci::AddMenuElement("Snippet");
|
|
|
|
|
|
|
|
// libjuci::AddMenuElement("Bobby");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO forgie: update views
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
//// Api to python ////
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
void libjuci::ReplaceWord(const std::string word) { |
|
|
|
|
|
|
|
libjuci::ApiServiceProvider::ReplaceWord(word); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void libjuci::ReplaceLine(const std::string line) { |
|
|
|
|
|
|
|
//TODO forgie: implement libjuci::ReplaceLine / change string to iter?
|
|
|
|
|
|
|
|
//some_namespace::controller::replaceLine(line_);
|
|
|
|
|
|
|
|
std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called" |
|
|
|
|
|
|
|
<< std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::string libjuci::GetWord() { |
|
|
|
|
|
|
|
return libjuci::ApiServiceProvider::GetWord(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::AddMenuElement(std::string plugin_name){ |
|
|
|
void PluginApi::AddMenuElement(std::string plugin_name){ |
|
|
|
libjuci::AddMenuXml(plugin_name, "PluginMenu"); |
|
|
|
AddMenuXml(plugin_name, "PluginMenu"); |
|
|
|
std::string plugin_action_name = plugin_name+"Menu"; |
|
|
|
std::string plugin_action_name = plugin_name+"Menu"; |
|
|
|
|
|
|
|
|
|
|
|
libjuci::ApiServiceProvider::menu_->keybindings_.action_group_menu() |
|
|
|
menu_->keybindings_.action_group_menu() |
|
|
|
->add(Gtk::Action::create(plugin_action_name, plugin_name)); |
|
|
|
->add(Gtk::Action::create(plugin_action_name, plugin_name)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::AddSubMenuElement(std::string parent_menu, |
|
|
|
void PluginApi::AddSubMenuElement(std::string parent_menu, |
|
|
|
std::string menu_name, |
|
|
|
std::string menu_name, |
|
|
|
std::string menu_func_name, |
|
|
|
std::string menu_func_name, |
|
|
|
std::string plugin_path, |
|
|
|
std::string plugin_path, |
|
|
|
std::string menu_keybinding) { |
|
|
|
std::string menu_keybinding) { |
|
|
|
|
|
|
|
|
|
|
|
libjuci::AddSubMenuXml(menu_func_name, parent_menu); |
|
|
|
AddSubMenuXml(menu_func_name, parent_menu); |
|
|
|
|
|
|
|
|
|
|
|
libjuci::ApiServiceProvider::menu_->keybindings_.action_group_menu() |
|
|
|
menu_->keybindings_.action_group_menu() |
|
|
|
->add(Gtk::Action::create(menu_func_name, |
|
|
|
->add(Gtk::Action::create(menu_func_name, |
|
|
|
menu_name), |
|
|
|
menu_name), |
|
|
|
Gtk::AccelKey(menu_keybinding), |
|
|
|
Gtk::AccelKey(menu_keybinding), |
|
|
|
@ -95,10 +71,9 @@ void libjuci::AddSubMenuElement(std::string parent_menu, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::AddMenuXml(std::string plugin_name, std::string parent_menu) { |
|
|
|
void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) { |
|
|
|
|
|
|
|
|
|
|
|
std::string temp_menu = libjuci::ApiServiceProvider::menu_ |
|
|
|
std::string temp_menu = menu_->keybindings_.model_.menu_ui_string(); |
|
|
|
->keybindings_.model_.menu_ui_string(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t plugin_menu_pos = temp_menu.find(parent_menu); |
|
|
|
std::size_t plugin_menu_pos = temp_menu.find(parent_menu); |
|
|
|
// +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc
|
|
|
|
// +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc
|
|
|
|
@ -108,16 +83,14 @@ void libjuci::AddMenuXml(std::string plugin_name, std::string parent_menu) { |
|
|
|
|
|
|
|
|
|
|
|
std::string menu_input = |
|
|
|
std::string menu_input = |
|
|
|
" <menu action='"+plugin_name+"Menu'> " |
|
|
|
" <menu action='"+plugin_name+"Menu'> " |
|
|
|
// " <menuitem action='PluginAdd"+plugin_name+"'/> "
|
|
|
|
" </menu> "; |
|
|
|
" </menu> "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libjuci::ApiServiceProvider::menu_->keybindings_.model_.menu_ui_string_ = |
|
|
|
menu_->keybindings_.model_.menu_ui_string_ = |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::AddSubMenuXml(std::string plugin_name, std::string parent_menu){ |
|
|
|
void PluginApi::AddSubMenuXml(std::string plugin_name, std::string parent_menu){ |
|
|
|
std::string temp_menu = libjuci::ApiServiceProvider::menu_ |
|
|
|
std::string temp_menu = menu_->keybindings_.model_.menu_ui_string(); |
|
|
|
->keybindings_.model_.menu_ui_string(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
std::size_t parent_menu_pos = temp_menu.find(parent_menu); |
|
|
|
std::size_t parent_menu_pos = temp_menu.find(parent_menu); |
|
|
|
// +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc
|
|
|
|
// +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc
|
|
|
|
@ -125,78 +98,95 @@ void libjuci::AddSubMenuXml(std::string plugin_name, std::string parent_menu){ |
|
|
|
std::string menu_prefix = temp_menu.substr(0, parent_menu_pos); |
|
|
|
std::string menu_prefix = temp_menu.substr(0, parent_menu_pos); |
|
|
|
std::string menu_suffix = temp_menu.substr(parent_menu_pos); |
|
|
|
std::string menu_suffix = temp_menu.substr(parent_menu_pos); |
|
|
|
|
|
|
|
|
|
|
|
std::string menu_input = |
|
|
|
std::string menu_input ="<menuitem action='"+plugin_name+"'/>"; |
|
|
|
" <menuitem action='"+plugin_name+"'/> "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
libjuci::ApiServiceProvider::menu_->keybindings_.model_.menu_ui_string_ = |
|
|
|
menu_->keybindings_.model_.menu_ui_string_ = |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::cout << libjuci::ApiServiceProvider::menu_ |
|
|
|
///////////////////////
|
|
|
|
->keybindings_.model_.menu_ui_string_ << std::endl; |
|
|
|
//// Api to python ////
|
|
|
|
|
|
|
|
///////////////////////
|
|
|
|
|
|
|
|
void libjuci::ReplaceWord(const std::string word) { |
|
|
|
|
|
|
|
PluginApi::ReplaceWord(word); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void libjuci::ReplaceLine(const std::string line) { |
|
|
|
|
|
|
|
std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called" |
|
|
|
|
|
|
|
<< std::endl; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
std::string libjuci::GetWord() { |
|
|
|
|
|
|
|
return PluginApi::GetWord(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void libjuci::AddMenuElement(std::string plugin_name){ |
|
|
|
|
|
|
|
PluginApi::AddMenuElement(plugin_name); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void libjuci::AddSubMenuElement(std::string parent_menu, |
|
|
|
|
|
|
|
std::string menu_name, |
|
|
|
|
|
|
|
std::string menu_func_name, |
|
|
|
|
|
|
|
std::string plugin_path, |
|
|
|
|
|
|
|
std::string menu_keybinding) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PluginApi::AddSubMenuElement(parent_menu, |
|
|
|
|
|
|
|
menu_name, |
|
|
|
|
|
|
|
menu_func_name, |
|
|
|
|
|
|
|
plugin_path, |
|
|
|
|
|
|
|
menu_keybinding); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////
|
|
|
|
//////////////////////////////
|
|
|
|
//// Boost.Python methods ////
|
|
|
|
//// Boost.Python methods ////
|
|
|
|
//////////////////////////////
|
|
|
|
//////////////////////////////
|
|
|
|
|
|
|
|
namespace bp = boost::python; |
|
|
|
|
|
|
|
|
|
|
|
boost::python::api::object libjuci::OpenPythonScript(const std::string path, |
|
|
|
bp::api::object libjuci::OpenPythonScript(const std::string path, |
|
|
|
boost::python::api::object python_name_space) { |
|
|
|
bp::api::object python_name_space) { |
|
|
|
boost::python::str str_path(path); |
|
|
|
bp::str str_path(path); |
|
|
|
return boost::python::exec_file(str_path, python_name_space);//, python_name_space);
|
|
|
|
return bp::exec_file(str_path, python_name_space); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::LoadPlugin(const std::string& plugin_name) { |
|
|
|
void libjuci::LoadPlugin(const std::string& plugin_name) { |
|
|
|
std::cout << "libjuci::LoadPlugin " << plugin_name << std::endl;
|
|
|
|
std::cout << "libjuci::LoadPlugin " << plugin_name << std::endl;
|
|
|
|
try{ |
|
|
|
try{ |
|
|
|
Py_Initialize(); |
|
|
|
Py_Initialize(); |
|
|
|
boost::python::api::object main_module = boost::python::import("__main__"); |
|
|
|
bp::api::object main_module = bp::import("__main__"); |
|
|
|
boost::python::api::object main_namespace = |
|
|
|
bp::api::object main_namespace = |
|
|
|
main_module.attr("__dict__"); |
|
|
|
main_module.attr("__dict__"); |
|
|
|
boost::python::api::object ignored2 = |
|
|
|
bp::api::object ignored2 = |
|
|
|
OpenPythonScript(plugin_name, main_namespace); |
|
|
|
OpenPythonScript(plugin_name, main_namespace); |
|
|
|
|
|
|
|
|
|
|
|
}catch(boost::python::error_already_set const&) { |
|
|
|
}catch(bp::error_already_set const&) { |
|
|
|
PyErr_Print(); |
|
|
|
PyErr_Print(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::LoadPluginFunction(const std::string &function_name, |
|
|
|
void libjuci::LoadPluginFunction(const std::string &function_name, |
|
|
|
const std::string &plugin_path){ |
|
|
|
const std::string &plugin_path){ |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
Py_Initialize(); |
|
|
|
Py_Initialize(); |
|
|
|
boost::python::api::object main_module = boost::python::import("__main__"); |
|
|
|
bp::api::object main_module = bp::import("__main__"); |
|
|
|
boost::python::api::object main_namespace = main_module.attr("__dict__"); |
|
|
|
bp::api::object main_namespace = main_module.attr("__dict__"); |
|
|
|
boost::python::api::object ignored2 = OpenPythonScript(plugin_path, |
|
|
|
bp::api::object ignored2 = OpenPythonScript(plugin_path, main_namespace); |
|
|
|
main_namespace); |
|
|
|
bp::str func_name(function_name); |
|
|
|
|
|
|
|
bp::api::object returnValue = bp::eval(func_name, main_namespace); |
|
|
|
boost::python::str func_name(function_name); |
|
|
|
}catch(bp::error_already_set const&) { |
|
|
|
// for extracting return value from python:
|
|
|
|
|
|
|
|
boost::python::object returnValue = boost::python::eval(func_name, |
|
|
|
|
|
|
|
main_namespace); |
|
|
|
|
|
|
|
//std::string return_value = boost::python::extract<std::string>(pySnippet);
|
|
|
|
|
|
|
|
//do something with return_value
|
|
|
|
|
|
|
|
}catch(boost::python::error_already_set const&) { |
|
|
|
|
|
|
|
PyErr_Print(); |
|
|
|
PyErr_Print(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//std::cout << __func__ << " - " << function_name << std::endl;
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void libjuci::InitPlugin(const std::string& plugin_path) { |
|
|
|
void libjuci::InitPlugin(const std::string& plugin_path) { |
|
|
|
std::cout << "libjuci::InitPlugin " << plugin_path << std::endl;
|
|
|
|
std::cout << "libjuci::InitPlugin " << plugin_path << std::endl;
|
|
|
|
try{ |
|
|
|
try{ |
|
|
|
Py_Initialize(); |
|
|
|
Py_Initialize(); |
|
|
|
boost::python::api::object main_module = boost::python::import("__main__"); |
|
|
|
bp::api::object main_module = bp::import("__main__"); |
|
|
|
boost::python::api::object main_namespace = main_module.attr("__dict__"); |
|
|
|
bp::api::object main_namespace = main_module.attr("__dict__"); |
|
|
|
boost::python::api::object ignored2 = OpenPythonScript(plugin_path, |
|
|
|
bp::api::object ignored2 = OpenPythonScript(plugin_path, main_namespace); |
|
|
|
main_namespace); |
|
|
|
bp::object returnValue = bp::eval("initPlugin()", main_namespace); |
|
|
|
|
|
|
|
//std::string return_value = bp::extract<std::string>(pySnippet);
|
|
|
|
/* for extracting return value from python: */ |
|
|
|
|
|
|
|
boost::python::object returnValue = boost::python::eval("initPlugin()", |
|
|
|
|
|
|
|
main_namespace); |
|
|
|
|
|
|
|
//std::string return_value = boost::python::extract<std::string>(pySnippet);
|
|
|
|
|
|
|
|
//do something with return_value
|
|
|
|
//do something with return_value
|
|
|
|
}catch(boost::python::error_already_set const&) { |
|
|
|
}catch(bp::error_already_set const&) { |
|
|
|
PyErr_Print(); |
|
|
|
PyErr_Print(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -223,11 +213,11 @@ void libjuci::IterToWordEnd(Gtk::TextIter &iter) { |
|
|
|
Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() { |
|
|
|
Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() { |
|
|
|
//finding focused view
|
|
|
|
//finding focused view
|
|
|
|
int i = 0; |
|
|
|
int i = 0; |
|
|
|
while(!libjuci::ApiServiceProvider::notebook_->source_vec_.at(i) |
|
|
|
while(!PluginApi::notebook_->source_vec_.at(i) |
|
|
|
->view().has_focus()) { |
|
|
|
->view().has_focus()) { |
|
|
|
i++; |
|
|
|
i++; |
|
|
|
} |
|
|
|
} |
|
|
|
return Glib::RefPtr<Gtk::TextBuffer>(libjuci::ApiServiceProvider::notebook_ |
|
|
|
return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_ |
|
|
|
->source_vec_.at(i) |
|
|
|
->source_vec_.at(i) |
|
|
|
->view().get_buffer()); |
|
|
|
->view().get_buffer()); |
|
|
|
} |
|
|
|
} |
|
|
|
|