Browse Source

Merged

master
Jørgen Lien Sellæg 11 years ago
parent
commit
ab74950106
  1. 3
      juci/CMakeLists.txt
  2. 124
      juci/api.cc
  3. 87
      juci/api.h
  4. 42
      juci/config.cc
  5. 21
      juci/config.h
  6. 49
      juci/config.json
  7. 71
      juci/keybindings.cc
  8. 33
      juci/keybindings.h
  9. 12
      juci/menu.cc
  10. 314
      juci/notebook.cc
  11. 65
      juci/notebook.h
  12. 100
      juci/source.cc
  13. 28
      juci/source.h
  14. 18
      juci/window.cc
  15. 11
      juci/window.h

3
juci/CMakeLists.txt

@ -92,6 +92,8 @@ add_executable(${project_name}
menu.cc menu.cc
source.h source.h
source.cc source.cc
config.h
config.cc
sourcefile.h sourcefile.h
sourcefile.cc sourcefile.cc
window.cc window.cc
@ -102,7 +104,6 @@ add_executable(${project_name}
notebook.h notebook.h
entry.h entry.h
entry.cc entry.cc
#there is no need for extentions
) )
add_library(${module} SHARED add_library(${module} SHARED

124
juci/api.cc

@ -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,10 +15,9 @@ 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) {
buffer->erase(word_start, word_end); buffer->erase(word_start, word_end);
Gtk::TextIter current = libjuci::IterFromNotebook(); Gtk::TextIter current = libjuci::IterFromNotebook();
buffer->insert(current, word); buffer->insert(current, word);
@ -34,62 +29,53 @@ 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();
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) {
std::string word = buffer->get_text(word_start, word_end); std::string word = buffer->get_text(word_start, word_end);
return word; return word;
} }
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));
} }
void PluginApi::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) {
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),
Gtk::AccelKey(menu_keybinding), Gtk::AccelKey(menu_keybinding),
[=]() { [=]() {
libjuci::LoadPluginFunction(menu_func_name, plugin_path); libjuci::LoadPluginFunction(menu_func_name, plugin_path);
}); });
} }
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,17 +84,17 @@ 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);
// +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc // +2 gets you outside of the tag:<'menu_name'> ref: keybindings.cc
parent_menu_pos+=parent_menu.size() +2; parent_menu_pos+=parent_menu.size() +2;
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 ="<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;
} }
@ -122,27 +108,26 @@ void libjuci::ReplaceWord(const std::string word) {
void libjuci::ReplaceLine(const std::string line) { void libjuci::ReplaceLine(const std::string line) {
std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called" std::cout << "unimplemented function: 'libjuci::ReplaceLine()' called"
<< std::endl; << std::endl;
} }
std::string libjuci::GetWord() { std::string libjuci::GetWord() {
return PluginApi::GetWord(); return PluginApi::GetWord();
} }
void libjuci::AddMenuElement(std::string plugin_name){ void libjuci::AddMenuElement(std::string plugin_name) {
PluginApi::AddMenuElement(plugin_name); PluginApi::AddMenuElement(plugin_name);
} }
void libjuci::AddSubMenuElement(std::string parent_menu, void libjuci::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) {
PluginApi::AddSubMenuElement(parent_menu, PluginApi::AddSubMenuElement(parent_menu,
menu_name, menu_name,
menu_func_name, menu_func_name,
plugin_path, plugin_path,
menu_keybinding); menu_keybinding);
} }
////////////////////////////// //////////////////////////////
@ -151,49 +136,47 @@ void libjuci::AddSubMenuElement(std::string parent_menu,
namespace bp = boost::python; namespace bp = boost::python;
bp::api::object libjuci::OpenPythonScript(const std::string path, bp::api::object libjuci::OpenPythonScript(const std::string path,
bp::api::object python_name_space) { bp::api::object python_name_space) {
bp::str str_path(path); bp::str str_path(path);
return bp::exec_file(str_path, 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) {
try{ try {
Py_Initialize(); Py_Initialize();
bp::api::object main_module = bp::import("__main__"); bp::api::object main_module = bp::import("__main__");
bp::api::object main_namespace = bp::api::object main_namespace =
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();
} }
} }
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();
bp::api::object main_module = bp::import("__main__"); bp::api::object main_module = bp::import("__main__");
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::str func_name(function_name); bp::str func_name(function_name);
bp::api::object returnValue = bp::eval(func_name, main_namespace); bp::api::object returnValue = bp::eval(func_name, main_namespace);
}catch(bp::error_already_set const&) { }catch (bp::error_already_set const&) {
PyErr_Print(); PyErr_Print();
} }
} }
void libjuci::InitPlugin(const std::string& plugin_path) { void libjuci::InitPlugin(const std::string& plugin_path) {
try{ try {
Py_Initialize(); Py_Initialize();
bp::api::object main_module = bp::import("__main__"); bp::api::object main_module = bp::import("__main__");
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();
} }
} }
@ -202,30 +185,33 @@ void libjuci::InitPlugin(const std::string& plugin_path) {
//// Glib wrappers //// //// Glib wrappers ////
/////////////////////// ///////////////////////
void libjuci::IterToWordStart(Gtk::TextIter &iter) { void libjuci::IterToWordStart(Gtk::TextIter &iter) {
if(!iter.starts_line()) { if (!iter.starts_line()) {
while(!iter.starts_word()) { while (!iter.starts_word()) {
iter.backward_char(); iter.backward_char();
} }
} }
} }
void libjuci::IterToWordEnd(Gtk::TextIter &iter) { void libjuci::IterToWordEnd(Gtk::TextIter &iter) {
if(!iter.ends_line()) { if (!iter.ends_line()) {
while(!iter.ends_word()) { while (!iter.ends_word()) {
iter.forward_char(); iter.forward_char();
} }
} }
} }
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(!PluginApi::notebook_->source_vec_.at(i)->view().has_focus()) { // while (!PluginApi::notebook_->source_vec_.at(i)->view().has_focus()) {
i++; // i++;
} //while(!PluginApi::notebook_->CurrentTextView().has_focus()) {
// i++;
// }
return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_ return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_
->source_vec_.at(i) // ->source_vec_.at(i)
->view().get_buffer()); // ->view().get_buffer());
->CurrentTextView().get_buffer());
} }
Gtk::TextIter libjuci::IterFromNotebook() { Gtk::TextIter libjuci::IterFromNotebook() {

87
juci/api.h

@ -7,46 +7,39 @@
#include "notebook.h" #include "notebook.h"
#include "menu.h" #include "menu.h"
//////////////////// ////////////////////
//// Plugin Api //// //// Plugin Api ////
//////////////////// ////////////////////
class PluginApi { class PluginApi {
public: public:
static Menu::Controller* menu_; static Menu::Controller* menu_;
static Notebook::Controller* notebook_; static Notebook::Controller* notebook_;
static void InitPlugins();
static void InitPlugins(); static std::string ProjectPath();
static std::string ProjectPath(); // for Python module:
static std::string GetWord();
//for Python module: // menu management
static std::string GetWord(); static void AddMenuElement(const std::string plugin_name);
//menu management static void AddSubMenuElement(const std::string parent_menu,
static void AddMenuElement(const std::string plugin_name); const std::string menu_name,
static void AddSubMenuElement(const std::string parent_menu, const std::string menu_func_name,
const std::string menu_name, const std::string plugin_path,
const std::string menu_func_name, const std::string menu_keybinding);
const std::string plugin_path, // text-buffer functions
const std::string menu_keybinding); static void ReplaceWord(const std::string word);
//text-buffer functions static void ReplaceLine(const std::string line);
static void ReplaceWord(const std::string word); protected:
static void ReplaceLine(const std::string line); static void AddMenuXml(std::string plugin_name, std::string parent_menu);
static void AddSubMenuXml(std::string plugin_name, std::string parent_menu);
protected: }; // PluginApi
static void AddMenuXml(std::string plugin_name, std::string parent_menu);
static void AddSubMenuXml(std::string plugin_name, std::string parent_menu);
};
namespace libjuci { namespace libjuci {
/////////////////////// ///////////////////////
//// Glib wrappers //// //// Glib wrappers ////
/////////////////////// ///////////////////////
void IterToWordStart(Gtk::TextIter &iter); void IterToWordStart(Gtk::TextIter &iter);
void IterToWordEnd(Gtk::TextIter &iter); void IterToWordEnd(Gtk::TextIter &iter);
Gtk::TextIter IterFromNotebook(); Gtk::TextIter IterFromNotebook();
//TODO forgie: make sure it does not get the buffer to the last created textview.
Glib::RefPtr<Gtk::TextBuffer> BufferFromNotebook(); Glib::RefPtr<Gtk::TextBuffer> BufferFromNotebook();
/////////////////////// ///////////////////////
//// Api to python //// //// Api to python ////
/////////////////////// ///////////////////////
@ -57,27 +50,25 @@ namespace libjuci {
void AddMenuElement(const std::string plugin_name); void AddMenuElement(const std::string plugin_name);
void AddSubMenuElement(const std::string parent_menu, void AddSubMenuElement(const std::string parent_menu,
const std::string menu_name, const std::string menu_name,
const std::string menu_func_name, const std::string menu_func_name,
const std::string plugin_path, const std::string plugin_path,
const std::string menu_keybinding); const std::string menu_keybinding);
void AddMenuXml(const std::string plugin_name, void AddMenuXml(const std::string plugin_name,
const string parent_menu); const string parent_menu);
void AddSubMenuXml(const std::string plugin_name, void AddSubMenuXml(const std::string plugin_name,
const string parent_menu); const string parent_menu);
//TODO forgie: Make more functions targeting the python module
////////////////////////////// //////////////////////////////
//// Boost.Python methods //// //// Boost.Python methods ////
////////////////////////////// //////////////////////////////
boost::python::api::object OpenPythonScript(const std::string path, namespace bp = boost::python;
boost::python::api::object python_name_space); bp::api::object OpenPythonScript(const std::string path,
void LoadPlugin(const std::string& plugin_name); 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); void InitPlugin(const std::string& plugin_path);
} // libjuci
}//libjuci #endif // JUCI_API_H_
#endif // JUCI_API_H

42
juci/config.cc

@ -0,0 +1,42 @@
#include "config.h"
MainConfig::MainConfig() :
keybindings_cfg_(), source_cfg_() {
boost::property_tree::json_parser::read_json("config.json", cfg_);
GenerateSource();
GenerateKeybindings();
// keybindings_cfg_ = cfg_.get_child("keybindings");
// notebook_cfg_ = cfg_.get_child("notebook");
// menu_cfg_ = cfg_.get_child("menu");
}
void MainConfig::GenerateSource() {
boost::property_tree::ptree source_json = cfg_.get_child("source");
boost::property_tree::ptree syntax_json = source_json.get_child("syntax");
boost::property_tree::ptree colors_json = source_json.get_child("colors");
for ( auto &i : syntax_json )
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>());
for ( auto &i : colors_json )
source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
}
void MainConfig::GenerateKeybindings() {
string line;
std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) {
while (getline(menu_xml, line)) {
keybindings_cfg_.AppendXml(line);
}
}
boost::property_tree::ptree keys_json = cfg_.get_child("keybindings");
for (auto &i : keys_json)
keybindings_cfg_.key_map()[i.first] = i.second.get_value<std::string>();
}
Keybindings::Config& MainConfig::keybindings_cfg() {
return keybindings_cfg_;
}
Source::Config& MainConfig::source_cfg() {
return source_cfg_;
}

21
juci/config.h

@ -0,0 +1,21 @@
#include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <fstream>
#include <string>
#include "keybindings.h"
#include "source.h"
class MainConfig {
public:
MainConfig();
Source::Config& source_cfg();
Keybindings::Config& keybindings_cfg();
void PrintMenu();
void GenerateSource();
void GenerateKeybindings();
private:
boost::property_tree::ptree cfg_;
boost::property_tree::ptree key_tree_;
Source::Config source_cfg_;
Keybindings::Config keybindings_cfg_;
};

49
juci/config.json

@ -1,19 +1,36 @@
{ {
"colors": { "source": {
"text_color": "#333333", "colors": {
"string" : "#CC0000", "text_color": "#333333",
"namespace_ref" : "#990099", "string": "#CC0000",
"type" : "#0066FF", "namespace_ref": "#990099",
"keyword": "blue", "type": "#0066FF",
"comment": "grey", "keyword": "blue",
"own": "pink" "comment": "grey",
}, "own": "pink"
"syntax": { },
"43": "type", "syntax": {
"46": "namespace_ref", "43": "type",
"109": "string", "46": "namespace_ref",
"702": "keyword", "109": "string",
"703": "own", "702": "keyword",
"705": "comment" "703": "own",
"705": "comment"
} }
},
"keybindings": {
"split_window": "<control><alt>s",
"new_h_file": "<control><alt>h",
"new_cc_file": "<alt>c",
"close_tab": "<control>w"
},
"example": {
"key": "value",
"key2": [
"val1",
"val2",
3
],
"key3": "value"
}
} }

71
juci/keybindings.cc

@ -1,61 +1,29 @@
#include "keybindings.h" #include "keybindings.h"
Keybindings::Model::Model() { Keybindings::Model::Model(Keybindings::Config &config) :
menu_ui_string_ = menu_ui_string_(config.menu_xml()) {
"<ui> " /* hidden_ui_string_ =
" <menubar name='MenuBar'> "
" <menu action='FileMenu'> "
" <menu action='FileNew'> "
" <menuitem action='FileNewStandard'/> "
" <menuitem action='FileNewCC'/> "
" <menuitem action='FileNewH'/> "
" </menu> "
" <menuitem action='FileOpenFile'/> "
" <menuitem action='FileOpenFolder'/> "
" <separator/> "
" <menuitem action='FileQuit'/> "
" </menu> "
" <menu action='EditMenu'> "
" <menuitem action='EditCopy'/> "
" <menuitem action='EditCut'/> "
" <menuitem action='EditPaste'/> "
" <separator/> "
" <menuitem action='EditFind'/> "
" </menu> "
" <menu action='WindowMenu'> "
" <menuitem action='WindowCloseTab'/> "
" <menuitem action='WindowSplitWindow'/> "
" </menu> "
" <menu action='PluginMenu'> "
// " <menu action='PluginSnippet'> "
// " <menuitem action='PluginAddSnippet'/> "
// " </menu> "
" </menu> "
" <menu action='HelpMenu'> "
" <menuitem action='HelpAbout'/> "
" </menu> "
" </menubar> "
"</ui> ";
hidden_ui_string_ =
"<ui> " "<ui> "
" <menubar name='MenuBar'> " " <menubar name='MenuBar'> "
" <menuitem action='Test'/> " " <menuitem action='Test'/> "
" </menubar> " " </menubar> "
"</ui> "; "</ui> ";*/
}; }
Keybindings::Model::~Model() { Keybindings::Model::~Model() {
} }
Keybindings::Controller::Controller() { Keybindings::Controller::Controller(Keybindings::Config &config) :
config_(config), model_(config) {
action_group_menu_ = Gtk::ActionGroup::create(); action_group_menu_ = Gtk::ActionGroup::create();
ui_manager_menu_ = Gtk::UIManager::create(); ui_manager_menu_ = Gtk::UIManager::create();
action_group_hidden_ = Gtk::ActionGroup::create(); action_group_hidden_ = Gtk::ActionGroup::create();
ui_manager_hidden_ = Gtk::UIManager::create(); ui_manager_hidden_ = Gtk::UIManager::create();
} }
Keybindings::Controller::~Controller() { Keybindings::Controller::~Controller() {
} }
void Keybindings::Controller::BuildMenu() { void Keybindings::Controller::BuildMenu() {
try { try {
ui_manager_menu_->add_ui_from_string(model_.menu_ui_string()); ui_manager_menu_->add_ui_from_string(model_.menu_ui_string());
@ -75,3 +43,24 @@ void Keybindings::Controller::BuildHiddenMenu() {
ui_manager_hidden_->insert_action_group(action_group_hidden_); ui_manager_hidden_->insert_action_group(action_group_hidden_);
} }
Keybindings::Config::Config(Keybindings::Config &original) {
SetMenu(original.menu_xml());
SetKeyMap(original.key_map());
}
Keybindings::Config::Config() {
menu_xml_ = "";
std::unordered_map<std::string, std::string> key_map();
}
void Keybindings::Config::AppendXml(std::string &child) {
menu_xml_ += child;
}
void Keybindings::Config::SetMenu(std::string &menu_xml) {
menu_xml_ = menu_xml;
}
void Keybindings::Config::SetKeyMap(std::unordered_map<std::string, std::string> &key_map) {
key_map_ = key_map;
}

33
juci/keybindings.h

@ -2,23 +2,42 @@
#ifndef JUCI_KEYBINDINGS_H_ #ifndef JUCI_KEYBINDINGS_H_
#define JUCI_KEYBINDINGS_H_ #define JUCI_KEYBINDINGS_H_
#include "iostream" #include <iostream>
#include "gtkmm.h" #include "gtkmm.h"
#include <unordered_map>
//#include "config.h" //TODO :: remove?
namespace Keybindings { namespace Keybindings {
class Config {
public:
Config(Config &original);
Config();
std::string& menu_xml() { return menu_xml_; }
std::unordered_map<std::string, std::string>& key_map() { return key_map_; }
void AppendXml(std::string &child);
void SetMenu(std::string &menu_xml);
void SetKeyMap(std::unordered_map<std::string, std::string> &key_map);
private:
std::unordered_map<std::string, std::string> key_map_;
std::string menu_xml_;
std::string hidden_ui_string_;
};//Config
class Model { class Model {
public: public:
Model(); Model(Keybindings::Config &config);
virtual ~Model(); virtual ~Model();
std::string menu_ui_string(){return menu_ui_string_;} std::string menu_ui_string() { return menu_ui_string_; }
std::string hidden_ui_string(){return hidden_ui_string_;} std::string hidden_ui_string() { return hidden_ui_string_; }
//private: //private:
std::string menu_ui_string_; std::string menu_ui_string_;
std::string hidden_ui_string_; std::string hidden_ui_string_;
}; // Model }; // Model
class Controller { class Controller {
public: public:
Controller(); explicit Controller(Keybindings::Config &config);
virtual ~Controller(); virtual ~Controller();
Glib::RefPtr<Gtk::ActionGroup> action_group_menu() { Glib::RefPtr<Gtk::ActionGroup> action_group_menu() {
return action_group_menu_; return action_group_menu_;
@ -40,8 +59,8 @@ namespace Keybindings {
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden_; Glib::RefPtr<Gtk::UIManager> ui_manager_hidden_;
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_; Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_;
// private: // private:
Keybindings::Model model_; Keybindings::Config config_;
Keybindings::Model model_;
};//Controller };//Controller
} }
#endif // JUCI_KEYBINDINGS_H_ #endif // JUCI_KEYBINDINGS_H_

12
juci/menu.cc

@ -28,21 +28,13 @@ Menu::Controller::Controller(Keybindings::Controller& keybindings) :
"_Window")); "_Window"));
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow", keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow",
"Split window"), "Split window"),
Gtk::AccelKey("<control><alt>S"), Gtk::AccelKey(keybindings_.config_
.key_map()["split_window"]),//"<control><alt>S"),
[this]() { [this]() {
OnWindowSplitWindow(); OnWindowSplitWindow();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu",
"_Plugins")); "_Plugins"));
//Moved to ApiServiceProvider
/*keybindings_.action_group_menu()
->add(Gtk::Action::create("PluginSnippet", "Snippet"));
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", 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",

314
juci/notebook.cc

@ -1,27 +1,20 @@
#include "notebook.h" #include "notebook.h"
Notebook::Model::Model() { Notebook::Model::Model() {
cc_extension = ".cc"; cc_extension_ = ".cc";
h_extension = ".h"; h_extension_ = ".h";
}; scrollvalue_ = 20;
Notebook::View::View() :
view_(Gtk::ORIENTATION_VERTICAL){
} }
Gtk::Box& Notebook::View::view() { Notebook::View::View(){
view_.pack_start(notebook_); view_.pack_start(notebook_);
return view_;
} }
Notebook::Controller::Controller(Keybindings::Controller& keybindings){
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller);
scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->OnNewEmptyFile();
notebook().append_page(*scrolledwindow_vec_.back(), "juCi++");
notebook().set_focus_child(*scrolledwindow_vec_.back());
refClipboard = Gtk::Clipboard::get();
Notebook::Controller::Controller(Keybindings::Controller& keybindings,
Source::Config& source_cfg) :
source_config_(source_cfg) {
OnNewPage("juCi++");
refClipboard_ = Gtk::Clipboard::get();
keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu", keybindings.action_group_menu()->add(Gtk::Action::create("FileMenu",
Gtk::Stock::FILE)); Gtk::Stock::FILE));
/* File->New files */ /* File->New files */
@ -31,35 +24,38 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
"New empty file", "New empty file",
"Create a new file"), "Create a new file"),
[this]() { [this]() {
is_new_file = true; is_new_file_ = true;
OnFileNewEmptyfile(); OnFileNewEmptyfile();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC", keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC",
"New cc file"), "New cc file"),
Gtk::AccelKey("<control><alt>c"), Gtk::AccelKey(keybindings.config_
.key_map()["new_cc_file"]),
[this]() { [this]() {
is_new_file = true; is_new_file_ = true;
OnFileNewCCFile(); OnFileNewCCFile();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH", keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH",
"New h file"), "New h file"),
Gtk::AccelKey("<control><alt>h"), Gtk::AccelKey(keybindings.config_
.key_map()["new_h_file"]),
[this]() { [this]() {
is_new_file = true; is_new_file_ = true;
OnFileNewHeaderFile(); OnFileNewHeaderFile();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab", keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab",
"Close tab"), "Close tab"),
Gtk::AccelKey("<control>w"), Gtk::AccelKey(keybindings.config_
.key_map()["close_tab"]),
[this]() { [this]() {
OnCloseCurrentPage(); OnCloseCurrentPage();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("EditFind", keybindings.action_group_menu()->add(Gtk::Action::create("EditFind",
Gtk::Stock::FIND), Gtk::Stock::FIND),
[this]() { [this]() {
is_new_file = false; is_new_file_ = false;
OnEditSearch(); OnEditSearch();
//TODO(Oyvang, Zalox, Forgi)Create function OnEditFind(); //TODO(Oyvang, Zalox, Forgi)Create function OnEditFind();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy", keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy",
Gtk::Stock::COPY), Gtk::Stock::COPY),
@ -78,9 +74,9 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
}); });
entry_.view_.entry().signal_activate().connect( entry_.view_.entry().signal_activate().connect(
[this]() { [this]() {
if(is_new_file){ if(is_new_file_){
OnNewPage(entry_.text()); OnNewPage(entry_.text());
entry_.OnHideEntries(is_new_file); entry_.OnHideEntries(is_new_file_);
}else{ }else{
Search(true); Search(true);
} }
@ -88,11 +84,11 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
entry_.button_apply().signal_clicked().connect( entry_.button_apply().signal_clicked().connect(
[this]() { [this]() {
OnNewPage(entry_.text()); OnNewPage(entry_.text());
entry_.OnHideEntries(is_new_file); entry_.OnHideEntries(is_new_file_);
}); });
entry_.button_close().signal_clicked().connect( entry_.button_close().signal_clicked().connect(
[this]() { [this]() {
entry_.OnHideEntries(is_new_file); entry_.OnHideEntries(is_new_file_);
}); });
entry_.button_next().signal_clicked().connect( entry_.button_next().signal_clicked().connect(
[this]() { [this]() {
@ -103,76 +99,146 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
Search(false); Search(false);
}); });
text_vec_.back()->view().
signal_scroll_event().connect(sigc::mem_fun(
this,
&Notebook::Controller::
scroll_event_callback));
}//Constructor }//Constructor
Gtk::Box& Notebook::Controller::view() {
bool Notebook::Controller::scroll_event_callback(GdkEventScroll* scroll_event) {
int page = CurrentPage();
int direction_y = scroll_event->delta_y;
int direction_x = scroll_event->delta_x;
Glib::RefPtr<Gtk::Adjustment> adj =
scrolledtext_vec_.at(page)->
get_vscrollbar()->get_adjustment();
if ( direction_y != 0 ) {
int dir_val = direction_y==-1?-model_.scrollvalue_:+model_.scrollvalue_;
adj->set_value(adj->get_value()+dir_val);
text_vec_.at(page)->view().set_vadjustment(adj);
linenumbers_vec_.at(page)->view().set_vadjustment(adj);
}
if ( direction_x != 0 ) {
int dir_val = direction_x==-1?-model_.scrollvalue_:+model_.scrollvalue_;
adj->set_value(adj->get_value()+dir_val);
text_vec_.at(page)->view().set_hadjustment(adj);
}
return true;
}
Notebook::Controller::~Controller() {
for (auto &i : text_vec_) delete i;
for (auto &i : linenumbers_vec_) delete i;
for (auto &i : editor_vec_) delete i;
for (auto &i : scrolledtext_vec_) delete i;
for (auto &i : scrolledline_vec_) delete i;
}
Gtk::HBox& Notebook::Controller::view() {
return view_.view(); return view_.view();
} }
Gtk::Box& Notebook::Controller::entry_view(){ Gtk::Box& Notebook::Controller::entry_view() {
return entry_.view(); return entry_.view();
} }
void Notebook::Controller::OnNewPage(std::string name) { void Notebook::Controller::OnNewPage(std::string name) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow()); OnCreatePage();
source_vec_.push_back(new Source::Controller); std::cout << "oppretta pages" << std::endl;
scrolledwindow_vec_.back()->add(source_vec_.back()->view()); text_vec_.back()->OnNewEmptyFile();
source_vec_.back()->OnNewEmptyFile(); Notebook().append_page(*editor_vec_.back(), name);
notebook().append_page(*scrolledwindow_vec_.back(), name); Notebook().show_all_children();
notebook().show_all_children(); Notebook().set_current_page(Pages()-1);
notebook().set_focus_child(*scrolledwindow_vec_.back()); Notebook().set_focus_child(text_vec_.at(Pages()-1)->view());
notebook().set_current_page(pages()-1);
} }
void Notebook::Controller::OnOpenFile(std::string path) {
OnCreatePage();
text_vec_.back()->OnOpenFile(path);
unsigned pos = path.find_last_of("/\\");
Notebook().append_page(*editor_vec_.back(), path.substr(pos+1));
Notebook().show_all_children();
Notebook().set_current_page(Pages()-1);
Notebook().set_focus_child(text_vec_.back()->view());
OnBufferChange();
}
void Notebook::Controller::OnCreatePage(){
text_vec_.push_back(new Source::Controller(source_config())); // add arguments
linenumbers_vec_.push_back(new Source::Controller(source_config())); // add arguments
scrolledline_vec_.push_back(new Gtk::ScrolledWindow());
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow());
editor_vec_.push_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(text_vec_.back()->view());
scrolledline_vec_.back()->add(linenumbers_vec_.back()->view());
linenumbers_vec_.back()->view().get_buffer()->set_text("1 \n");
linenumbers_vec_.back()->view().override_color(Gdk::RGBA("Black"));
linenumbers_vec_.back()->
view().set_justification(Gtk::Justification::JUSTIFY_RIGHT);
scrolledline_vec_.back()->get_vscrollbar()->hide();
linenumbers_vec_.back()->view().set_editable(false);
linenumbers_vec_.back()->view().set_sensitive(false);
editor_vec_.back()->pack_start(*scrolledline_vec_.back(),false,false);
editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true);
BufferChangeHandler(text_vec_.back()->view().get_buffer());
}
void Notebook::Controller::OnCloseCurrentPage() { void Notebook::Controller::OnCloseCurrentPage() {
//TODO (oyvang, zalox, forgi) Save a temp file, in case you close one you dont want to close? //TODO (oyvang, zalox, forgi) Save a temp file, in case you close one you dont want to close?
int page = currentPage(); if(Pages()!=0){
notebook().remove_page(page); int page = CurrentPage();
delete source_vec_.at(page); Notebook().remove_page(page);
delete scrolledwindow_vec_.at(page); delete text_vec_.at(page);
source_vec_.erase(source_vec_.begin()+ page); delete linenumbers_vec_.at(page);
scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page); delete scrolledtext_vec_.at(page);
delete scrolledline_vec_.at(page);
delete editor_vec_.at(page);
text_vec_.erase(text_vec_.begin()+ page);
linenumbers_vec_.erase(linenumbers_vec_.begin()+page);
scrolledtext_vec_.erase(scrolledtext_vec_.begin()+page);
scrolledline_vec_.erase(scrolledline_vec_.begin()+page);
editor_vec_.erase(editor_vec_.begin()+page);
}
} }
void Notebook::Controller::OnFileNewEmptyfile() { void Notebook::Controller::OnFileNewEmptyfile() {
entry_.OnShowSetFilenName(""); entry_.OnShowSetFilenName("");
} }
void Notebook::Controller::OnFileNewCCFile() { void Notebook::Controller::OnFileNewCCFile() {
entry_.OnShowSetFilenName(model_.cc_extension); entry_.OnShowSetFilenName(model_.cc_extension_);
} }
void Notebook::Controller::OnFileNewHeaderFile() { void Notebook::Controller::OnFileNewHeaderFile() {
entry_.OnShowSetFilenName(model_.h_extension); entry_.OnShowSetFilenName(model_.h_extension_);
} }
void Notebook::Controller::OnEditCopy() { void Notebook::Controller::OnEditCopy() {
if (pages() != 0) { if (Pages() != 0) {
buffer()->copy_clipboard(refClipboard); Buffer(text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnEditPaste() { void Notebook::Controller::OnEditPaste() {
if (pages() != 0) { if (Pages() != 0) {
buffer()->paste_clipboard(refClipboard); Buffer(text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnEditCut() { void Notebook::Controller::OnEditCut() {
if (pages() != 0) { if (Pages() != 0) {
buffer()->cut_clipboard(refClipboard); Buffer(text_vec_.at(CurrentPage()))->cut_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnOpenFile(std::string path) {
scrolledwindow_vec_.push_back(new Gtk::ScrolledWindow());
source_vec_.push_back(new Source::Controller);
scrolledwindow_vec_.back()->add(source_vec_.back()->view());
source_vec_.back()->OnOpenFile(path);
unsigned pos = path.find_last_of("/\\");
notebook().append_page(*scrolledwindow_vec_.back(), path.substr(pos+1));
notebook().show_all_children();
notebook().set_focus_child(*scrolledwindow_vec_.back());
notebook().set_current_page(pages()-1);
}
std::string Notebook::Controller::GetCursorWord(){ std::string Notebook::Controller::GetCursorWord(){
int page = CurrentPage();
std::string word; std::string word;
Gtk::TextIter start,end; Gtk::TextIter start,end;
start = buffer()->get_insert()->get_iter(); start = Buffer(text_vec_.at(page))->get_insert()->get_iter();
end = buffer()->get_insert()->get_iter(); end = Buffer(text_vec_.at(page))->get_insert()->get_iter();
if(!end.ends_line()) { if(!end.ends_line()) {
while(!end.ends_word()){ while(!end.ends_word()){
end.forward_char(); end.forward_char();
@ -183,63 +249,109 @@ std::string Notebook::Controller::GetCursorWord(){
start.backward_char(); start.backward_char();
} }
} }
word = buffer()->get_text(start,end); word = Buffer(text_vec_.at(page))->get_text(start,end);
//TODO(Oyvang)fix selected text //TODO(Oyvang)fix selected text
return word; return word;
} }
void Notebook::Controller::OnEditSearch(){ void Notebook::Controller::OnEditSearch() {
search_match_end_ = buffer()->get_iter_at_offset(0); search_match_end_ =
entry_.OnShowSearch(GetCursorWord()); Buffer(text_vec_.at(CurrentPage()))->get_iter_at_offset(0);
entry_.OnShowSearch(GetCursorWord());
} }
void Notebook::Controller::Search(bool forward){ void Notebook::Controller::Search(bool forward){
int page = CurrentPage();
std::string search_word; std::string search_word;
search_word = entry_.text(); search_word = entry_.text();
Gtk::TextIter test; Gtk::TextIter test;
if(!forward){ if ( !forward ) {
if(search_match_start_ == 0 || search_match_start_.get_line_offset() == 0) { if ( search_match_start_ == 0 ||
search_match_start_= buffer()->end(); search_match_start_.get_line_offset() == 0) {
search_match_start_= Buffer(text_vec_.at(CurrentPage()))->end();
} }
search_match_start_.backward_search(search_word, search_match_start_.
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY| backward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY, Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
search_match_start_, search_match_end_); Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
}else{ search_match_start_,
if(search_match_end_ == 0) { search_match_end_);
search_match_end_= buffer()->begin(); } else {
if ( search_match_end_ == 0 ) {
search_match_end_= Buffer(text_vec_.at(CurrentPage()))->begin();
} }
search_match_end_.forward_search(search_word, search_match_end_.
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY | forward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY, Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
search_match_start_, search_match_end_); Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
search_match_start_,
search_match_end_);
} }
}
void Notebook::Controller::OnBufferChange() {
int page = CurrentPage();
int line_nr = Buffer(text_vec_.at(page))->get_line_count();
// std::cout << "matc_start - " Glib::RefPtr
// << search_match_start_.get_line_offset() <Gtk::TextBuffer::Mark> mark = Gtk::TextBuffer::Mark::create();
// //<< test.get_line_offset() Glib::RefPtr
// << " || match_end - " <Gtk::TextBuffer::Mark> mark_lines = Gtk::TextBuffer::Mark::create();
// << search_match_end_.get_line_offset()
// << std::endl;
if(Buffer(text_vec_.at(page))->get_insert()->get_iter().starts_line() &&
Buffer(text_vec_.at(page))->get_insert()->get_iter().get_line() ==
Buffer(text_vec_.at(page))->end().get_line()) {
std::string lines ="1 ";
for ( int it = 2; it <= line_nr; ++it ) {
lines.append("\n"+ std::to_string(it)+" ");
}
Buffer(linenumbers_vec_.at(page))->set_text(lines);
Buffer(text_vec_.at(page))->
add_mark(
mark,
Buffer(text_vec_.at(page))->end());
Buffer(linenumbers_vec_.at(page))->
add_mark(
mark_lines,
Buffer(linenumbers_vec_.at(page))->end());
text_vec_.at(page)->view().scroll_to(mark);
linenumbers_vec_.at(page)->view().scroll_to(mark_lines);
}else{
Buffer(text_vec_.at(page))->
add_mark(
mark,
Buffer(text_vec_.at(page))->
get_insert()->get_iter());
}
} }
int Notebook::Controller::currentPage(){ Gtk::TextView& Notebook::Controller::CurrentTextView() {
return notebook().get_current_page(); return text_vec_.at(CurrentPage())->view();
} }
Glib::RefPtr<Gtk::TextBuffer> Notebook::Controller::buffer(){ int Notebook::Controller::CurrentPage() {
return source_vec_.at(currentPage())->view().get_buffer(); return Notebook().get_current_page();
} }
int Notebook::Controller::pages(){ Glib::RefPtr<Gtk::TextBuffer>
return notebook().get_n_pages(); Notebook::Controller::Buffer( Source::Controller *source ) {
return source->view().get_buffer();
} }
Gtk::Notebook& Notebook::Controller::notebook(){
int Notebook::Controller::Pages() {
return Notebook().get_n_pages();
}
Gtk::Notebook& Notebook::Controller::Notebook() {
return view_.notebook(); return view_.notebook();
} }
void Notebook::Controller::BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer>
buffer) {
buffer->signal_changed().connect(
[this]() {
OnBufferChange();
});
}

65
juci/notebook.h

@ -10,52 +10,63 @@ namespace Notebook {
class Model { class Model {
public: public:
Model(); Model();
std::string cc_extension; std::string cc_extension_;
std::string h_extension; std::string h_extension_;
int scrollvalue_;
}; };
class View { class View {
public: public:
View(); View();
Gtk::Box& view(); Gtk::HBox& view() {return view_;}
Gtk::Notebook& notebook() { return notebook_; } Gtk::Notebook& notebook() {return notebook_; }
protected: protected:
Gtk::Box view_; Gtk::HBox view_;
Gtk::Notebook notebook_; Gtk::Notebook notebook_;
}; };
class Controller { class Controller {
public: public:
Controller(Keybindings::Controller& keybindings);
Gtk::Box& view(); Controller(Keybindings::Controller& keybindings,
Source::Config& config);
~Controller();
Glib::RefPtr<Gtk::TextBuffer> Buffer( Source::Controller *source);
Gtk::TextView& CurrentTextView();
int CurrentPage();
Gtk::Box& entry_view(); Gtk::Box& entry_view();
void OnNewPage(std::string name); Gtk::Notebook& Notebook();
void OnBufferChange();
void OnCloseCurrentPage(); void OnCloseCurrentPage();
void OnOpenFile(std::string filename);
View view_;
Model model_;
Entry::Controller entry_;
std::vector<Source::Controller*> source_vec_;
std::vector<Gtk::ScrolledWindow*> scrolledwindow_vec_;
Glib::RefPtr<Gtk::Clipboard> refClipboard;
std::list<Gtk::TargetEntry> listTargets;
std::string GetCursorWord(); std::string GetCursorWord();
Glib::RefPtr<Gtk::TextBuffer> buffer();
Gtk::Notebook& notebook();
int currentPage();
int pages();
void OnFileNewEmptyfile();
void OnFileNewCCFile();
void OnFileNewHeaderFile();
void OnEditCopy(); void OnEditCopy();
void OnEditPaste();
void OnEditCut(); void OnEditCut();
void OnEditPaste();
void OnEditSearch(); void OnEditSearch();
void OnFileNewCCFile();
void OnFileNewEmptyfile();
void OnFileNewHeaderFile();
void OnNewPage(std::string name);
void OnOpenFile(std::string filename);
void OnCreatePage();
bool scroll_event_callback(GdkEventScroll* scroll_event);
int Pages();
Gtk::HBox& view();
void Search(bool forward); void Search(bool forward);
const Source::Config& source_config() { return source_config_; }
protected:
void BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer> buffer);
private: private:
bool is_new_file; Source::Config source_config_;
View view_;
Model model_;
bool is_new_file_;
Entry::Controller entry_;
std::vector<Source::Controller*> text_vec_, linenumbers_vec_;
std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_, scrolledline_vec_;
std::vector<Gtk::HBox*> editor_vec_;
std::list<Gtk::TargetEntry> listTargets_;
Gtk::TextIter search_match_end_; Gtk::TextIter search_match_end_;
Gtk::TextIter search_match_start_; Gtk::TextIter search_match_start_;
Glib::RefPtr<Gtk::Clipboard> refClipboard_;
}; // class controller }; // class controller
} // namespace Notebook } // namespace Notebook
#endif // JUCI_NOTEBOOK_H_ #endif // JUCI_NOTEBOOK_H_

100
juci/source.cc

@ -30,22 +30,22 @@ string Source::View::GetLine(const Gtk::TextIter &begin) {
// Source::View::ApplyTheme() // Source::View::ApplyTheme()
// Applies theme in textview // Applies theme in textview
void Source::View::ApplyTheme(const Source::Theme &theme) { void Source::View::ApplyConfig(const Source::Config &config) {
for (auto &item : theme.tagtable()) { for (auto &item : config.tagtable()) {
std::cout << "Apply: f: " << item.first << ", s: " << // std::cout << "Apply: f: " << item.first << ", s: " <<
item.second << std::endl; // item.second << std::endl;
get_buffer()->create_tag(item.first)->property_foreground() = item.second; get_buffer()->create_tag(item.first)->property_foreground() = item.second;
} }
} }
void Source::View::OnOpenFile(std::vector<clang::SourceLocation> &locations, void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Source::Theme &theme) { const Source::Config &config) {
/* ApplyTheme(theme); ApplyConfig(config);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer(); Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) { for (auto &loc : locations) {
string type = std::to_string(loc.kind()); string type = std::to_string(loc.kind());
try { try {
theme.typetable().at(type); config.typetable().at(type);
} catch (std::exception) { } catch (std::exception) {
continue; continue;
} }
@ -57,80 +57,74 @@ void Source::View::OnOpenFile(std::vector<clang::SourceLocation> &locations,
if (end < 0) end = 0; if (end < 0) end = 0;
if (begin < 0) begin = 0; if (begin < 0) begin = 0;
std::cout << "Libc: "; // std::cout << "Libc: ";
std::cout << "type: " << type; // std::cout << "type: " << type;
std::cout << " linum_s: " << linum_start+1 << " linum_e: " << linum_end+1; // std::cout << " linum_s: " << linum_start+1 << " linum_e: " << linum_end+1;
std::cout << ", begin: " << begin << ", end: " << end << std::endl; // std::cout << ", begin: " << begin << ", end: " << end << std::endl;
Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start, Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start,
begin); begin);
Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end); Gtk::TextIter end_iter = buffer->get_iter_at_line_offset(linum_end, end);
std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl; // std::cout << get_buffer()->get_text(begin_iter, end_iter) << std::endl;
if (begin_iter.get_line() == end_iter.get_line()) { if (begin_iter.get_line() == end_iter.get_line()) {
buffer->apply_tag_by_name(theme.typetable().at(type), buffer->apply_tag_by_name(config.typetable().at(type),
begin_iter, end_iter); begin_iter, end_iter);
} }
}*/ }
}
// Source::View::Config::Config(Config &config)
// copy-constructor
Source::Config::Config(const Source::Config &original) {
SetTagTable(original.tagtable());
SetTypeTable(original.typetable());
} }
// Source::View::Theme::tagtable()
Source::Config::Config(){}
// Source::View::Config::tagtable()
// returns a const refrence to the tagtable // returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::tagtable() const { const std::unordered_map<string, string>& Source::Config::tagtable() const {
return tagtable_; return tagtable_;
} }
// Source::View::Theme::tagtable() // Source::View::Config::tagtable()
// returns a const refrence to the tagtable // returns a const refrence to the tagtable
const std::unordered_map<string, string>& Source::Theme::typetable() const { const std::unordered_map<string, string>& Source::Config::typetable() const {
return typetable_; return typetable_;
} }
void Source::Theme::InsertTag(const string &key, const string &value) { void Source::Config::InsertTag(const string &key, const string &value) {
tagtable_[key] = value; tagtable_[key] = value;
} }
// Source::View::Theme::SetTagTable() // Source::View::Config::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Theme::SetTypeTable( void Source::Config::SetTypeTable(
const std::unordered_map<string, string> &typetable) { const std::unordered_map<string, string> &typetable) {
typetable_ = typetable; typetable_ = typetable;
} }
void Source::Theme::InsertType(const string &key, const string &value) { void Source::Config::InsertType(const string &key, const string &value) {
typetable_[key] = value; typetable_[key] = value;
} }
// Source::View::Theme::SetTagTable() // Source::View::Config::SetTagTable()
// sets the tagtable for the view // sets the tagtable for the view
void Source::Theme::SetTagTable( void Source::Config::SetTagTable(
const std::unordered_map<string, string> &tagtable) { const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable; tagtable_ = tagtable;
} }
/////////////// ///////////////
//// Model //// //// Model ////
/////////////// ///////////////
Source::Model::Model() : Source::Model::Model(const Source::Config &config) :
theme_() { config_(config) {
/*
std::cout << "Model constructor run" << std::endl;
boost::property_tree::ptree pt;
boost::property_tree::json_parser::read_json("config.json", pt);
for ( auto &i : pt ) {
boost::property_tree::ptree props = pt.get_child(i.first);
for (auto &pi : props) {
if (i.first.compare("syntax")) { // checks the config-file
theme_.InsertTag(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting tag. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
if (i.first.compare("colors")) { // checks the config-file
theme_.InsertType(pi.first, pi.second.get_value<std::string>());
// std::cout << "inserting type. " << pi.first << pi.second.get_value<std::string>() << std::endl;
}
}
}*/
} }
Source::Theme& Source::Model::theme() { Source::Config& Source::Model::config() {
return theme_; return config_;
} }
const string Source::Model::filepath() { const string Source::Model::filepath() {
@ -151,12 +145,13 @@ SetSourceLocations(const std::vector<clang::SourceLocation> &locations) {
// Source::Controller::Controller() // Source::Controller::Controller()
// Constructor for Controller // Constructor for Controller
Source::Controller::Controller() { Source::Controller::Controller(const Source::Config &config) :
// std::cout << "Controller constructor run" << std::endl; model_(config) {
view().get_buffer()->signal_changed().connect([this](){ view().get_buffer()->signal_changed().connect([this](){
this->OnLineEdit(); this->OnLineEdit();
}); });
} }
// Source::Controller::view() // Source::Controller::view()
// return shared_ptr to the view // return shared_ptr to the view
Source::View& Source::Controller::view() { Source::View& Source::Controller::view() {
@ -186,12 +181,9 @@ void Source::Controller::OnOpenFile(const string &filepath) {
int start_offset = buffer()->begin().get_offset(); int start_offset = buffer()->begin().get_offset();
int end_offset = buffer()->end().get_offset(); int end_offset = buffer()->end().get_offset();
std::string project_path = std::string project_path =
filepath.substr(0, filepath.find_last_of('/')); filepath.substr(0, filepath.find_last_of('/'));
clang::CompilationDatabase db(project_path); clang::CompilationDatabase db(project_path);
clang::CompileCommands commands(filepath, &db); clang::CompileCommands commands(filepath, &db);
std::vector<clang::CompileCommand> cmds = commands.get_commands(); std::vector<clang::CompileCommand> cmds = commands.get_commands();

28
juci/source.h

@ -10,8 +10,11 @@
using std::string; using std::string;
namespace Source { namespace Source {
class Theme {
class Config {
public: public:
Config(const Config &original);
Config();
const std::unordered_map<string, string>& tagtable() const; const std::unordered_map<string, string>& tagtable() const;
const std::unordered_map<string, string>& typetable() const; const std::unordered_map<string, string>& typetable() const;
void SetTagTable(const std::unordered_map<string, string> &tagtable); void SetTagTable(const std::unordered_map<string, string> &tagtable);
@ -23,7 +26,7 @@ namespace Source {
std::unordered_map<string, string> tagtable_; std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_; std::unordered_map<string, string> typetable_;
string background_; string background_;
}; // class Theme }; // class Config
/* /*
class BufferLocation { class BufferLocation {
BufferLocation(const BufferLocation &location); BufferLocation(const BufferLocation &location);
@ -43,37 +46,39 @@ namespace Source {
BufferLocation end_; BufferLocation end_;
};*/ };*/
class View : public Gtk::TextView { class View : public Gtk::TextView {
public: public:
View(); View();
string UpdateLine(); string UpdateLine();
void ApplyTheme(const Theme &theme); void ApplyConfig(const Config &config);
void OnOpenFile(std::vector<clang::SourceLocation> &locations, void OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Theme &theme); const Config &config);
private: private:
string GetLine(const Gtk::TextIter &begin); string GetLine(const Gtk::TextIter &begin);
}; // class View }; // class View
class Model{ class Model{
public: public:
Model(); Model(const Source::Config &config);
Theme& theme(); //Model();
Config& config();
const string filepath(); const string filepath();
void SetFilePath(const string &filepath); void SetFilePath(const string &filepath);
void SetSourceLocations( void SetSourceLocations( const std::vector<Clang::SourceLocation> &locations);
const std::vector<clang::SourceLocation> &locations); std::vector<Clang::SourceLocation>& getSourceLocations() {
std::vector<clang::SourceLocation>& getSourceLocations() {
return locations_; return locations_;
} }
private: private:
Theme theme_; Source::Config config_;
string filepath_; string filepath_;
std::vector<clang::SourceLocation> locations_; std::vector<clang::SourceLocation> locations_;
}; };
class Controller { class Controller {
public: public:
Controller(const Source::Config &config);
Controller(); Controller();
View& view(); View& view();
Model& model(); Model& model();
@ -84,7 +89,6 @@ namespace Source {
private: private:
void OnLineEdit(); void OnLineEdit();
void OnSaveFile(); void OnSaveFile();
protected: protected:
View view_; View view_;
Model model_; Model model_;

18
juci/window.cc

@ -2,11 +2,14 @@
Window::Window() : Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL), window_box_(Gtk::ORIENTATION_VERTICAL),
notebook_(keybindings_), main_config_(),
menu_(keybindings_){ keybindings_(main_config_.keybindings_cfg()),
notebook_(keybindings(), main_config_.source_cfg()),
menu_(keybindings()) {
set_title("juCi++"); set_title("juCi++");
set_default_size(600, 400); set_default_size(600, 400);
add(window_box_); add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT), Gtk::Stock::QUIT),
[this]() { [this]() {
@ -23,8 +26,6 @@ Window::Window() :
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());
//moved here from menu.cc by forgie
keybindings_.BuildMenu(); keybindings_.BuildMenu();
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK);
@ -33,13 +34,7 @@ Window::Window() :
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
//TODO forgie: Make shared_ptr
//libjuci::PluginApi::notebook_ =
// std::shared_ptr<Notebook::Controller>(nullptr);
// libjuci::PluginApi::menu_ =
// std::shared_ptr<Menu::Controller>(nullptr);
hide(); hide();
} }
@ -90,5 +85,4 @@ void Window::OnOpenFile() {
break; break;
} }
} }
} }

11
juci/window.h

@ -1,24 +1,27 @@
#ifndef JUCI_WINDOW_H_ #ifndef JUCI_WINDOW_H_
#define JUCI_WINDOW_H_ #define JUCI_WINDOW_H_
#include <iostream>
#include "gtkmm.h"
#include "api.h" #include "api.h"
#include "config.h"
#include <cstddef> #include <cstddef>
class Window : public Gtk::Window { class Window : public Gtk::Window {
public: public:
Window(); Window();
MainConfig& main_config() { return main_config_; }
Gtk::Box window_box_; Gtk::Box window_box_;
//private: //private:
MainConfig main_config_;
Keybindings::Controller keybindings_; Keybindings::Controller keybindings_;
Menu::Controller menu_; Menu::Controller menu_;
Notebook::Controller notebook_; Notebook::Controller notebook_;
Keybindings::Controller& keybindings() { return keybindings_; }
private:
//signal handlers //signal handlers
void OnWindowHide(); void OnWindowHide();
void OnOpenFile(); void OnOpenFile();
}; };
#endif // JUCI_WINDOW_H_ #endif // JUCI_WINDOW_H

Loading…
Cancel
Save