Browse Source

Merged

merge-requests/365/head
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
source.h
source.cc
config.h
config.cc
sourcefile.h
sourcefile.cc
window.cc
@ -102,7 +104,6 @@ add_executable(${project_name}
notebook.h
entry.h
entry.cc
#there is no need for extentions
)
add_library(${module} SHARED

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

87
juci/api.h

@ -7,46 +7,39 @@
#include "notebook.h"
#include "menu.h"
////////////////////
//// Plugin Api ////
////////////////////
class PluginApi {
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
static void AddMenuElement(const std::string plugin_name);
static void AddSubMenuElement(const std::string parent_menu,
const std::string menu_name,
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
//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);
};
////////////////////
//// Plugin Api ////
////////////////////
class PluginApi {
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
static void AddMenuElement(const std::string plugin_name);
static void AddSubMenuElement(const std::string parent_menu,
const std::string menu_name,
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
// 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 ////
///////////////////////
@ -57,27 +50,25 @@ namespace libjuci {
void AddMenuElement(const std::string plugin_name);
void AddSubMenuElement(const std::string parent_menu,
const std::string menu_name,
const std::string menu_func_name,
const std::string plugin_path,
const std::string menu_keybinding);
const std::string menu_name,
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);
const string parent_menu);
void AddSubMenuXml(const std::string plugin_name,
const string parent_menu);
//TODO forgie: Make more functions targeting the python module
const string parent_menu);
//////////////////////////////
//// 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
} // libjuci
#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": {
"text_color": "#333333",
"string" : "#CC0000",
"namespace_ref" : "#990099",
"type" : "#0066FF",
"keyword": "blue",
"comment": "grey",
"own": "pink"
},
"syntax": {
"43": "type",
"46": "namespace_ref",
"109": "string",
"702": "keyword",
"703": "own",
"705": "comment"
"source": {
"colors": {
"text_color": "#333333",
"string": "#CC0000",
"namespace_ref": "#990099",
"type": "#0066FF",
"keyword": "blue",
"comment": "grey",
"own": "pink"
},
"syntax": {
"43": "type",
"46": "namespace_ref",
"109": "string",
"702": "keyword",
"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"
Keybindings::Model::Model() {
menu_ui_string_ =
"<ui> "
" <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_ =
Keybindings::Model::Model(Keybindings::Config &config) :
menu_ui_string_(config.menu_xml()) {
/* hidden_ui_string_ =
"<ui> "
" <menubar name='MenuBar'> "
" <menuitem action='Test'/> "
" </menubar> "
"</ui> ";
};
"</ui> ";*/
}
Keybindings::Model::~Model() {
}
Keybindings::Controller::Controller() {
Keybindings::Controller::Controller(Keybindings::Config &config) :
config_(config), model_(config) {
action_group_menu_ = Gtk::ActionGroup::create();
ui_manager_menu_ = Gtk::UIManager::create();
action_group_hidden_ = Gtk::ActionGroup::create();
ui_manager_hidden_ = Gtk::UIManager::create();
}
Keybindings::Controller::~Controller() {
}
void Keybindings::Controller::BuildMenu() {
try {
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_);
}
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_
#define JUCI_KEYBINDINGS_H_
#include "iostream"
#include <iostream>
#include "gtkmm.h"
#include <unordered_map>
//#include "config.h" //TODO :: remove?
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 {
public:
Model();
Model(Keybindings::Config &config);
virtual ~Model();
std::string menu_ui_string(){return menu_ui_string_;}
std::string hidden_ui_string(){return hidden_ui_string_;}
std::string menu_ui_string() { return menu_ui_string_; }
std::string hidden_ui_string() { return hidden_ui_string_; }
//private:
std::string menu_ui_string_;
std::string hidden_ui_string_;
}; // Model
class Controller {
public:
Controller();
explicit Controller(Keybindings::Config &config);
virtual ~Controller();
Glib::RefPtr<Gtk::ActionGroup> action_group_menu() {
return action_group_menu_;
@ -40,8 +59,8 @@ namespace Keybindings {
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden_;
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_;
// private:
Keybindings::Model model_;
Keybindings::Config config_;
Keybindings::Model model_;
};//Controller
}
#endif // JUCI_KEYBINDINGS_H_

12
juci/menu.cc

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

314
juci/notebook.cc

@ -1,27 +1,20 @@
#include "notebook.h"
Notebook::Model::Model() {
cc_extension = ".cc";
h_extension = ".h";
};
Notebook::View::View() :
view_(Gtk::ORIENTATION_VERTICAL){
cc_extension_ = ".cc";
h_extension_ = ".h";
scrollvalue_ = 20;
}
Gtk::Box& Notebook::View::view() {
view_.pack_start(notebook_);
return view_;
Notebook::View::View(){
view_.pack_start(notebook_);
}
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",
Gtk::Stock::FILE));
/* File->New files */
@ -31,35 +24,38 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
"New empty file",
"Create a new file"),
[this]() {
is_new_file = true;
is_new_file_ = true;
OnFileNewEmptyfile();
});
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewCC",
"New cc file"),
Gtk::AccelKey("<control><alt>c"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_cc_file"]),
[this]() {
is_new_file = true;
is_new_file_ = true;
OnFileNewCCFile();
});
keybindings.action_group_menu()->add(Gtk::Action::create("FileNewH",
"New h file"),
Gtk::AccelKey("<control><alt>h"),
Gtk::AccelKey(keybindings.config_
.key_map()["new_h_file"]),
[this]() {
is_new_file = true;
is_new_file_ = true;
OnFileNewHeaderFile();
});
keybindings.action_group_menu()->add(Gtk::Action::create("WindowCloseTab",
"Close tab"),
Gtk::AccelKey("<control>w"),
Gtk::AccelKey(keybindings.config_
.key_map()["close_tab"]),
[this]() {
OnCloseCurrentPage();
});
keybindings.action_group_menu()->add(Gtk::Action::create("EditFind",
Gtk::Stock::FIND),
[this]() {
is_new_file = false;
is_new_file_ = false;
OnEditSearch();
//TODO(Oyvang, Zalox, Forgi)Create function OnEditFind();
//TODO(Oyvang, Zalox, Forgi)Create function OnEditFind();
});
keybindings.action_group_menu()->add(Gtk::Action::create("EditCopy",
Gtk::Stock::COPY),
@ -78,9 +74,9 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
});
entry_.view_.entry().signal_activate().connect(
[this]() {
if(is_new_file){
if(is_new_file_){
OnNewPage(entry_.text());
entry_.OnHideEntries(is_new_file);
entry_.OnHideEntries(is_new_file_);
}else{
Search(true);
}
@ -88,11 +84,11 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
entry_.button_apply().signal_clicked().connect(
[this]() {
OnNewPage(entry_.text());
entry_.OnHideEntries(is_new_file);
entry_.OnHideEntries(is_new_file_);
});
entry_.button_close().signal_clicked().connect(
[this]() {
entry_.OnHideEntries(is_new_file);
entry_.OnHideEntries(is_new_file_);
});
entry_.button_next().signal_clicked().connect(
[this]() {
@ -103,76 +99,146 @@ Notebook::Controller::Controller(Keybindings::Controller& keybindings){
Search(false);
});
text_vec_.back()->view().
signal_scroll_event().connect(sigc::mem_fun(
this,
&Notebook::Controller::
scroll_event_callback));
}//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();
}
Gtk::Box& Notebook::Controller::entry_view(){
Gtk::Box& Notebook::Controller::entry_view() {
return entry_.view();
}
void Notebook::Controller::OnNewPage(std::string name) {
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(), name);
notebook().show_all_children();
notebook().set_focus_child(*scrolledwindow_vec_.back());
notebook().set_current_page(pages()-1);
OnCreatePage();
std::cout << "oppretta pages" << std::endl;
text_vec_.back()->OnNewEmptyFile();
Notebook().append_page(*editor_vec_.back(), name);
Notebook().show_all_children();
Notebook().set_current_page(Pages()-1);
Notebook().set_focus_child(text_vec_.at(Pages()-1)->view());
}
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() {
//TODO (oyvang, zalox, forgi) Save a temp file, in case you close one you dont want to close?
int page = currentPage();
notebook().remove_page(page);
delete source_vec_.at(page);
delete scrolledwindow_vec_.at(page);
source_vec_.erase(source_vec_.begin()+ page);
scrolledwindow_vec_.erase(scrolledwindow_vec_.begin()+page);
if(Pages()!=0){
int page = CurrentPage();
Notebook().remove_page(page);
delete text_vec_.at(page);
delete linenumbers_vec_.at(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() {
entry_.OnShowSetFilenName("");
}
void Notebook::Controller::OnFileNewCCFile() {
entry_.OnShowSetFilenName(model_.cc_extension);
entry_.OnShowSetFilenName(model_.cc_extension_);
}
void Notebook::Controller::OnFileNewHeaderFile() {
entry_.OnShowSetFilenName(model_.h_extension);
entry_.OnShowSetFilenName(model_.h_extension_);
}
void Notebook::Controller::OnEditCopy() {
if (pages() != 0) {
buffer()->copy_clipboard(refClipboard);
if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_);
}
}
void Notebook::Controller::OnEditPaste() {
if (pages() != 0) {
buffer()->paste_clipboard(refClipboard);
if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_);
}
}
void Notebook::Controller::OnEditCut() {
if (pages() != 0) {
buffer()->cut_clipboard(refClipboard);
if (Pages() != 0) {
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(){
int page = CurrentPage();
std::string word;
Gtk::TextIter start,end;
start = buffer()->get_insert()->get_iter();
end = buffer()->get_insert()->get_iter();
start = Buffer(text_vec_.at(page))->get_insert()->get_iter();
end = Buffer(text_vec_.at(page))->get_insert()->get_iter();
if(!end.ends_line()) {
while(!end.ends_word()){
end.forward_char();
@ -183,63 +249,109 @@ std::string Notebook::Controller::GetCursorWord(){
start.backward_char();
}
}
word = buffer()->get_text(start,end);
word = Buffer(text_vec_.at(page))->get_text(start,end);
//TODO(Oyvang)fix selected text
return word;
}
void Notebook::Controller::OnEditSearch(){
search_match_end_ = buffer()->get_iter_at_offset(0);
entry_.OnShowSearch(GetCursorWord());
void Notebook::Controller::OnEditSearch() {
search_match_end_ =
Buffer(text_vec_.at(CurrentPage()))->get_iter_at_offset(0);
entry_.OnShowSearch(GetCursorWord());
}
void Notebook::Controller::Search(bool forward){
int page = CurrentPage();
std::string search_word;
search_word = entry_.text();
Gtk::TextIter test;
if(!forward){
if(search_match_start_ == 0 || search_match_start_.get_line_offset() == 0) {
search_match_start_= buffer()->end();
if ( !forward ) {
if ( search_match_start_ == 0 ||
search_match_start_.get_line_offset() == 0) {
search_match_start_= Buffer(text_vec_.at(CurrentPage()))->end();
}
search_match_start_.backward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY|
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
search_match_start_, search_match_end_);
}else{
if(search_match_end_ == 0) {
search_match_end_= buffer()->begin();
search_match_start_.
backward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
search_match_start_,
search_match_end_);
} else {
if ( search_match_end_ == 0 ) {
search_match_end_= Buffer(text_vec_.at(CurrentPage()))->begin();
}
search_match_end_.forward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
Gtk::TextSearchFlags::TEXT_SEARCH_VISIBLE_ONLY,
search_match_start_, search_match_end_);
search_match_end_.
forward_search(search_word,
Gtk::TextSearchFlags::TEXT_SEARCH_TEXT_ONLY |
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 - "
// << search_match_start_.get_line_offset()
// //<< test.get_line_offset()
// << " || match_end - "
// << search_match_end_.get_line_offset()
// << std::endl;
Glib::RefPtr
<Gtk::TextBuffer::Mark> mark = Gtk::TextBuffer::Mark::create();
Glib::RefPtr
<Gtk::TextBuffer::Mark> mark_lines = Gtk::TextBuffer::Mark::create();
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(){
return notebook().get_current_page();
Gtk::TextView& Notebook::Controller::CurrentTextView() {
return text_vec_.at(CurrentPage())->view();
}
Glib::RefPtr<Gtk::TextBuffer> Notebook::Controller::buffer(){
return source_vec_.at(currentPage())->view().get_buffer();
int Notebook::Controller::CurrentPage() {
return Notebook().get_current_page();
}
int Notebook::Controller::pages(){
return notebook().get_n_pages();
Glib::RefPtr<Gtk::TextBuffer>
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();
}
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 {
public:
Model();
std::string cc_extension;
std::string h_extension;
std::string cc_extension_;
std::string h_extension_;
int scrollvalue_;
};
class View {
public:
View();
Gtk::Box& view();
Gtk::Notebook& notebook() { return notebook_; }
Gtk::HBox& view() {return view_;}
Gtk::Notebook& notebook() {return notebook_; }
protected:
Gtk::Box view_;
Gtk::HBox view_;
Gtk::Notebook notebook_;
};
class Controller {
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();
void OnNewPage(std::string name);
Gtk::Notebook& Notebook();
void OnBufferChange();
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();
Glib::RefPtr<Gtk::TextBuffer> buffer();
Gtk::Notebook& notebook();
int currentPage();
int pages();
void OnFileNewEmptyfile();
void OnFileNewCCFile();
void OnFileNewHeaderFile();
void OnEditCopy();
void OnEditPaste();
void OnEditCut();
void OnEditPaste();
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);
const Source::Config& source_config() { return source_config_; }
protected:
void BufferChangeHandler(Glib::RefPtr<Gtk::TextBuffer> buffer);
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_start_;
Glib::RefPtr<Gtk::Clipboard> refClipboard_;
}; // class controller
} // namespace Notebook
#endif // JUCI_NOTEBOOK_H_

100
juci/source.cc

@ -30,22 +30,22 @@ string Source::View::GetLine(const Gtk::TextIter &begin) {
// Source::View::ApplyTheme()
// Applies theme in textview
void Source::View::ApplyTheme(const Source::Theme &theme) {
for (auto &item : theme.tagtable()) {
std::cout << "Apply: f: " << item.first << ", s: " <<
item.second << std::endl;
void Source::View::ApplyConfig(const Source::Config &config) {
for (auto &item : config.tagtable()) {
// std::cout << "Apply: f: " << item.first << ", s: " <<
// item.second << std::endl;
get_buffer()->create_tag(item.first)->property_foreground() = item.second;
}
}
void Source::View::OnOpenFile(std::vector<clang::SourceLocation> &locations,
const Source::Theme &theme) {
/* ApplyTheme(theme);
void Source::View::OnOpenFile(std::vector<Clang::SourceLocation> &locations,
const Source::Config &config) {
ApplyConfig(config);
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
for (auto &loc : locations) {
string type = std::to_string(loc.kind());
try {
theme.typetable().at(type);
config.typetable().at(type);
} catch (std::exception) {
continue;
}
@ -57,80 +57,74 @@ void Source::View::OnOpenFile(std::vector<clang::SourceLocation> &locations,
if (end < 0) end = 0;
if (begin < 0) begin = 0;
std::cout << "Libc: ";
std::cout << "type: " << type;
std::cout << " linum_s: " << linum_start+1 << " linum_e: " << linum_end+1;
std::cout << ", begin: " << begin << ", end: " << end << std::endl;
// std::cout << "Libc: ";
// std::cout << "type: " << type;
// std::cout << " linum_s: " << linum_start+1 << " linum_e: " << linum_end+1;
// std::cout << ", begin: " << begin << ", end: " << end << std::endl;
Gtk::TextIter begin_iter = buffer->get_iter_at_line_offset(linum_start,
begin);
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()) {
buffer->apply_tag_by_name(theme.typetable().at(type),
begin_iter, end_iter);
buffer->apply_tag_by_name(config.typetable().at(type),
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
const std::unordered_map<string, string>& Source::Theme::tagtable() const {
const std::unordered_map<string, string>& Source::Config::tagtable() const {
return tagtable_;
}
// Source::View::Theme::tagtable()
// Source::View::Config::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_;
}
void Source::Theme::InsertTag(const string &key, const string &value) {
void Source::Config::InsertTag(const string &key, const string &value) {
tagtable_[key] = value;
}
// Source::View::Theme::SetTagTable()
// Source::View::Config::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTypeTable(
const std::unordered_map<string, string> &typetable) {
void Source::Config::SetTypeTable(
const std::unordered_map<string, string> &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;
}
// Source::View::Theme::SetTagTable()
// Source::View::Config::SetTagTable()
// sets the tagtable for the view
void Source::Theme::SetTagTable(
const std::unordered_map<string, string> &tagtable) {
void Source::Config::SetTagTable(
const std::unordered_map<string, string> &tagtable) {
tagtable_ = tagtable;
}
///////////////
//// Model ////
///////////////
Source::Model::Model() :
theme_() {
/*
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::Model::Model(const Source::Config &config) :
config_(config) {
}
Source::Theme& Source::Model::theme() {
return theme_;
Source::Config& Source::Model::config() {
return config_;
}
const string Source::Model::filepath() {
@ -151,12 +145,13 @@ SetSourceLocations(const std::vector<clang::SourceLocation> &locations) {
// Source::Controller::Controller()
// Constructor for Controller
Source::Controller::Controller() {
// std::cout << "Controller constructor run" << std::endl;
Source::Controller::Controller(const Source::Config &config) :
model_(config) {
view().get_buffer()->signal_changed().connect([this](){
this->OnLineEdit();
});
}
// Source::Controller::view()
// return shared_ptr to the 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 end_offset = buffer()->end().get_offset();
std::string project_path =
filepath.substr(0, filepath.find_last_of('/'));
clang::CompilationDatabase db(project_path);
clang::CompileCommands commands(filepath, &db);
std::vector<clang::CompileCommand> cmds = commands.get_commands();

28
juci/source.h

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

18
juci/window.cc

@ -2,11 +2,14 @@
Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL),
notebook_(keybindings_),
menu_(keybindings_){
main_config_(),
keybindings_(main_config_.keybindings_cfg()),
notebook_(keybindings(), main_config_.source_cfg()),
menu_(keybindings()) {
set_title("juCi++");
set_default_size(600, 400);
add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit",
Gtk::Stock::QUIT),
[this]() {
@ -23,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);
@ -33,13 +34,7 @@ Window::Window() :
show_all_children();
} // Window constructor
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);
void Window::OnWindowHide() {
hide();
}
@ -90,5 +85,4 @@ void Window::OnOpenFile() {
break;
}
}
}

11
juci/window.h

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

Loading…
Cancel
Save