|
|
|
@ -1,15 +1,11 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include "api.h" |
|
|
|
#include "api.h" |
|
|
|
|
|
|
|
|
|
|
|
Menu::Controller* PluginApi::menu_; |
|
|
|
Menu::Controller* PluginApi::menu_; |
|
|
|
Notebook::Controller* PluginApi::notebook_; |
|
|
|
Notebook::Controller* PluginApi::notebook_; |
|
|
|
|
|
|
|
|
|
|
|
/////////////////////////////
|
|
|
|
/////////////////////////////
|
|
|
|
//// API ServiceProvider ////
|
|
|
|
//// API ServiceProvider ////
|
|
|
|
/////////////////////////////
|
|
|
|
/////////////////////////////
|
|
|
|
|
|
|
|
std::string PluginApi::ProjectPath() { |
|
|
|
std::string PluginApi::ProjectPath() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
int MAXPATHLEN = 50; |
|
|
|
int MAXPATHLEN = 50; |
|
|
|
char temp[MAXPATHLEN]; |
|
|
|
char temp[MAXPATHLEN]; |
|
|
|
return ( getcwd(temp, MAXPATHLEN) ? std::string( temp ) : std::string("") ); |
|
|
|
return ( getcwd(temp, MAXPATHLEN) ? std::string( temp ) : std::string("") ); |
|
|
|
@ -19,7 +15,6 @@ 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(); |
|
|
|
|
|
|
|
|
|
|
|
libjuci::IterToWordStart(word_start); |
|
|
|
libjuci::IterToWordStart(word_start); |
|
|
|
libjuci::IterToWordEnd(word_end); |
|
|
|
libjuci::IterToWordEnd(word_end); |
|
|
|
if (word_start != word_end) { |
|
|
|
if (word_start != word_end) { |
|
|
|
@ -34,7 +29,6 @@ void PluginApi::ReplaceLine(std::string line) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::string PluginApi::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(); |
|
|
|
@ -49,16 +43,13 @@ std::string PluginApi::GetWord() { |
|
|
|
return ""; |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//runs the pythonscript that initiates every plugin within plugins/
|
|
|
|
|
|
|
|
void PluginApi::InitPlugins() { |
|
|
|
void PluginApi::InitPlugins() { |
|
|
|
//libjuci::LoadPlugin(g_project_root+"plugins.py");
|
|
|
|
|
|
|
|
libjuci::LoadPlugin(ProjectPath()+"/plugins.py"); |
|
|
|
libjuci::LoadPlugin(ProjectPath()+"/plugins.py"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PluginApi::AddMenuElement(std::string plugin_name) { |
|
|
|
void PluginApi::AddMenuElement(std::string plugin_name) { |
|
|
|
AddMenuXml(plugin_name, "PluginMenu"); |
|
|
|
AddMenuXml(plugin_name, "PluginMenu"); |
|
|
|
std::string plugin_action_name = plugin_name+"Menu"; |
|
|
|
std::string plugin_action_name = plugin_name+"Menu"; |
|
|
|
|
|
|
|
|
|
|
|
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)); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -68,9 +59,7 @@ void PluginApi::AddSubMenuElement(std::string parent_menu, |
|
|
|
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) { |
|
|
|
|
|
|
|
|
|
|
|
AddSubMenuXml(menu_func_name, parent_menu); |
|
|
|
AddSubMenuXml(menu_func_name, parent_menu); |
|
|
|
|
|
|
|
|
|
|
|
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), |
|
|
|
@ -81,15 +70,12 @@ void PluginApi::AddSubMenuElement(std::string parent_menu, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) { |
|
|
|
void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) { |
|
|
|
|
|
|
|
|
|
|
|
std::string temp_menu = menu_->keybindings_.model_.menu_ui_string(); |
|
|
|
std::string temp_menu = menu_->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
|
|
|
|
plugin_menu_pos+=parent_menu.size() +2; |
|
|
|
plugin_menu_pos+=parent_menu.size() +2; |
|
|
|
std::string menu_prefix = temp_menu.substr(0, plugin_menu_pos); |
|
|
|
std::string menu_prefix = temp_menu.substr(0, plugin_menu_pos); |
|
|
|
std::string menu_suffix = temp_menu.substr(plugin_menu_pos); |
|
|
|
std::string menu_suffix = temp_menu.substr(plugin_menu_pos); |
|
|
|
|
|
|
|
|
|
|
|
std::string menu_input = |
|
|
|
std::string menu_input = |
|
|
|
" <menu action='"+plugin_name+"Menu'> " |
|
|
|
" <menu action='"+plugin_name+"Menu'> " |
|
|
|
" </menu> "; |
|
|
|
" </menu> "; |
|
|
|
@ -98,7 +84,8 @@ void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) { |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void PluginApi::AddSubMenuXml(std::string plugin_name, std::string parent_menu){ |
|
|
|
void PluginApi::AddSubMenuXml(std::string plugin_name, |
|
|
|
|
|
|
|
std::string parent_menu) { |
|
|
|
std::string temp_menu = menu_->keybindings_.model_.menu_ui_string(); |
|
|
|
std::string temp_menu = menu_->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); |
|
|
|
@ -108,7 +95,6 @@ void PluginApi::AddSubMenuXml(std::string plugin_name, std::string parent_menu){ |
|
|
|
std::string menu_suffix = temp_menu.substr(parent_menu_pos); |
|
|
|
std::string menu_suffix = temp_menu.substr(parent_menu_pos); |
|
|
|
|
|
|
|
|
|
|
|
std::string menu_input ="<menuitem action='"+plugin_name+"'/>"; |
|
|
|
std::string menu_input ="<menuitem action='"+plugin_name+"'/>"; |
|
|
|
|
|
|
|
|
|
|
|
menu_->keybindings_.model_.menu_ui_string_ = |
|
|
|
menu_->keybindings_.model_.menu_ui_string_ = |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
menu_prefix + menu_input + menu_suffix; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -137,7 +123,6 @@ void libjuci::AddSubMenuElement(std::string parent_menu, |
|
|
|
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) { |
|
|
|
|
|
|
|
|
|
|
|
PluginApi::AddSubMenuElement(parent_menu, |
|
|
|
PluginApi::AddSubMenuElement(parent_menu, |
|
|
|
menu_name, |
|
|
|
menu_name, |
|
|
|
menu_func_name, |
|
|
|
menu_func_name, |
|
|
|
@ -164,7 +149,6 @@ void libjuci::LoadPlugin(const std::string& plugin_name) { |
|
|
|
main_module.attr("__dict__"); |
|
|
|
main_module.attr("__dict__"); |
|
|
|
bp::api::object ignored2 = |
|
|
|
bp::api::object ignored2 = |
|
|
|
OpenPythonScript(plugin_name, main_namespace); |
|
|
|
OpenPythonScript(plugin_name, main_namespace); |
|
|
|
|
|
|
|
|
|
|
|
}catch (bp::error_already_set const&) { |
|
|
|
}catch (bp::error_already_set const&) { |
|
|
|
PyErr_Print(); |
|
|
|
PyErr_Print(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -191,7 +175,6 @@ void libjuci::InitPlugin(const std::string& plugin_path) { |
|
|
|
bp::api::object main_namespace = main_module.attr("__dict__"); |
|
|
|
bp::api::object main_namespace = main_module.attr("__dict__"); |
|
|
|
bp::api::object ignored2 = OpenPythonScript(plugin_path, main_namespace); |
|
|
|
bp::api::object ignored2 = OpenPythonScript(plugin_path, main_namespace); |
|
|
|
bp::object returnValue = bp::eval("initPlugin()", main_namespace); |
|
|
|
bp::object returnValue = bp::eval("initPlugin()", main_namespace); |
|
|
|
//std::string return_value = bp::extract<std::string>(pySnippet);
|
|
|
|
|
|
|
|
// do something with return_value
|
|
|
|
// do something with return_value
|
|
|
|
}catch (bp::error_already_set const&) { |
|
|
|
}catch (bp::error_already_set const&) { |
|
|
|
PyErr_Print(); |
|
|
|
PyErr_Print(); |
|
|
|
|