Browse Source

reformatted code

merge-requests/365/head
tedjk 11 years ago
parent
commit
d99ae48cbf
  1. 23
      juci/api.cc
  2. 25
      juci/api.h
  3. 16
      juci/config.h
  4. 2
      juci/window.cc

23
juci/api.cc

@ -1,15 +1,11 @@
#include "api.h"
Menu::Controller* PluginApi::menu_;
Notebook::Controller* PluginApi::notebook_;
/////////////////////////////
//// API ServiceProvider ////
/////////////////////////////
std::string PluginApi::ProjectPath()
{
std::string PluginApi::ProjectPath() {
int MAXPATHLEN = 50;
char temp[MAXPATHLEN];
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();
Gtk::TextIter word_start = libjuci::IterFromNotebook();
Gtk::TextIter word_end = libjuci::IterFromNotebook();
libjuci::IterToWordStart(word_start);
libjuci::IterToWordEnd(word_end);
if (word_start != word_end) {
@ -34,7 +29,6 @@ void PluginApi::ReplaceLine(std::string line) {
}
std::string PluginApi::GetWord() {
// TODO forgie: use notebook's functions
Glib::RefPtr<Gtk::TextBuffer> buffer = libjuci::BufferFromNotebook();
Gtk::TextIter word_start = libjuci::IterFromNotebook();
Gtk::TextIter word_end = libjuci::IterFromNotebook();
@ -49,16 +43,13 @@ std::string PluginApi::GetWord() {
return "";
}
//runs the pythonscript that initiates every plugin within plugins/
void PluginApi::InitPlugins() {
//libjuci::LoadPlugin(g_project_root+"plugins.py");
libjuci::LoadPlugin(ProjectPath()+"/plugins.py");
}
void PluginApi::AddMenuElement(std::string plugin_name) {
AddMenuXml(plugin_name, "PluginMenu");
std::string plugin_action_name = plugin_name+"Menu";
menu_->keybindings_.action_group_menu()
->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 plugin_path,
std::string menu_keybinding) {
AddSubMenuXml(menu_func_name, parent_menu);
menu_->keybindings_.action_group_menu()
->add(Gtk::Action::create(menu_func_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) {
std::string temp_menu = menu_->keybindings_.model_.menu_ui_string();
std::size_t plugin_menu_pos = temp_menu.find(parent_menu);
// +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc
plugin_menu_pos+=parent_menu.size() +2;
std::string menu_prefix = temp_menu.substr(0, plugin_menu_pos);
std::string menu_suffix = temp_menu.substr(plugin_menu_pos);
std::string menu_input =
" <menu action='"+plugin_name+"Menu'> "
" </menu> ";
@ -98,7 +84,8 @@ void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) {
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::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_input ="<menuitem action='"+plugin_name+"'/>";
menu_->keybindings_.model_.menu_ui_string_ =
menu_prefix + menu_input + menu_suffix;
}
@ -137,7 +123,6 @@ void libjuci::AddSubMenuElement(std::string parent_menu,
std::string menu_func_name,
std::string plugin_path,
std::string menu_keybinding) {
PluginApi::AddSubMenuElement(parent_menu,
menu_name,
menu_func_name,
@ -164,7 +149,6 @@ void libjuci::LoadPlugin(const std::string& plugin_name) {
main_module.attr("__dict__");
bp::api::object ignored2 =
OpenPythonScript(plugin_name, main_namespace);
}catch (bp::error_already_set const&) {
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 ignored2 = OpenPythonScript(plugin_path, main_namespace);
bp::object returnValue = bp::eval("initPlugin()", main_namespace);
//std::string return_value = bp::extract<std::string>(pySnippet);
// do something with return_value
}catch (bp::error_already_set const&) {
PyErr_Print();

25
juci/api.h

@ -14,10 +14,8 @@
public:
static Menu::Controller* menu_;
static Notebook::Controller* notebook_;
static void InitPlugins();
static std::string ProjectPath();
// for Python module:
static std::string GetWord();
// menu management
@ -30,23 +28,18 @@
// text-buffer functions
static void ReplaceWord(const std::string word);
static void ReplaceLine(const std::string line);
protected:
static void AddMenuXml(std::string plugin_name, std::string parent_menu);
static void AddSubMenuXml(std::string plugin_name, std::string parent_menu);
};
}; // PluginApi
namespace libjuci {
///////////////////////
//// Glib wrappers ////
///////////////////////
void IterToWordStart(Gtk::TextIter &iter);
void IterToWordEnd(Gtk::TextIter &iter);
Gtk::TextIter IterFromNotebook();
//TODO forgie: make sure it does not get the buffer to the last created textview.
Glib::RefPtr<Gtk::TextBuffer> BufferFromNotebook();
///////////////////////
//// Api to python ////
///////////////////////
@ -61,23 +54,21 @@ namespace libjuci {
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
void AddMenuXml(const std::string plugin_name,
const string parent_menu);
void AddSubMenuXml(const std::string plugin_name,
const string parent_menu);
//TODO forgie: Make more functions targeting the python module
//////////////////////////////
//// Boost.Python methods ////
//////////////////////////////
boost::python::api::object OpenPythonScript(const std::string path,
boost::python::api::object python_name_space);
void LoadPlugin(const std::string& plugin_name);
namespace bp = boost::python;
bp::api::object OpenPythonScript(const std::string path,
bp::api::object python_name_space);
void LoadPluginFunction(const std::string &function_name, const std::string &plugin_path);
void LoadPlugin(const std::string& plugin_name);
void LoadPluginFunction(const std::string &function_name,
const std::string &plugin_path);
void InitPlugin(const std::string& plugin_path);
} // libjuci
#endif // JUCI_API_H
#endif // JUCI_API_H_

16
juci/config.h

@ -10,22 +10,12 @@
MainConfig();
const Source::Config& source_cfg();
Keybindings::Config& keybindings_cfg();
void PrintMenu();
//boost::property_tree::ptree& source_cfg();
//boost::property_tree::ptree& keybindings_cfg();
//boost::property_tree::ptree& notebookk_cfg();
//boost::property_tree::ptree& menu_cfg();
void GenerateSource();
void GenerateKeybindings();
private:
boost::property_tree::ptree cfg_;
// boost::property_tree::ptree sourcecfg_;
boost::property_tree::ptree key_tree_;
// boost::property_tree::ptree notebook_cfg_;
// boost::property_tree::ptree menu_cfg_;
Source::Config source_cfg_;
Keybindings::Config keybindings_cfg_;
void GenerateSource();
void GenerateKeybindings();
};

2
juci/window.cc

@ -26,8 +26,6 @@ Window::Window() :
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group());
add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group());
//moved here from menu.cc by forgie
keybindings_.BuildMenu();
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK);

Loading…
Cancel
Save