diff --git a/juci/api.cc b/juci/api.cc
index cf1099d..eefe937 100644
--- a/juci/api.cc
+++ b/juci/api.cc
@@ -1,16 +1,16 @@
#include "api.h"
#include "logging.h"
+#include "singletons.h"
Menu::Controller* PluginApi::menu_;
Notebook::Controller* PluginApi::notebook_;
/////////////////////////////
//// API ServiceProvider ////
/////////////////////////////
-PluginApi::PluginApi(Menu::Controller& menu_ctl_,
- Notebook::Controller& notebook_ctl_) {
+PluginApi::PluginApi() {
DEBUG("Adding pointers for the API");
- menu_ = &menu_ctl_;
- notebook_ = ¬ebook_ctl_;
+ notebook_ = Singleton::notebook();
+ menu_ = Singleton::menu();
DEBUG("Initiating plugins(from plugins.py)..");
#ifndef __APPLE__
InitPlugins(); //TODO: fix this
@@ -18,11 +18,6 @@ PluginApi::PluginApi(Menu::Controller& menu_ctl_,
DEBUG("Plugins initiated..");
}
-PluginApi::~PluginApi() {
- menu_ = NULL;
- notebook_ = NULL;
-}
-
std::string PluginApi::ProjectPath() {
int MAXPATHLEN = 50;
char temp[MAXPATHLEN];
@@ -69,7 +64,7 @@ void PluginApi::AddMenuElement(std::string plugin_name) {
DEBUG("Adding menu element for "+plugin_name);
AddMenuXml(plugin_name, "PluginMenu");
std::string plugin_action_name = plugin_name+"Menu";
- menu_->keybindings_.action_group_menu()
+ Singleton::keybindings()->action_group_menu
->add(Gtk::Action::create(plugin_action_name, plugin_name));
}
@@ -79,7 +74,7 @@ void PluginApi::AddSubMenuElement(std::string parent_menu,
std::string plugin_path,
std::string menu_keybinding) {
AddSubMenuXml(menu_func_name, parent_menu);
- menu_->keybindings_.action_group_menu()
+ Singleton::keybindings()->action_group_menu
->add(Gtk::Action::create(menu_func_name,
menu_name),
Gtk::AccelKey(menu_keybinding),
@@ -89,7 +84,7 @@ void PluginApi::AddSubMenuElement(std::string parent_menu,
}
void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) {
- std::string temp_menu = menu_->keybindings_.model_.menu_ui_string();
+ std::string temp_menu = Singleton::keybindings()->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;
@@ -99,13 +94,13 @@ void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) {
"
";
- menu_->keybindings_.model_.menu_ui_string_ =
+ Singleton::keybindings()->menu_ui_string =
menu_prefix + menu_input + menu_suffix;
}
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 = Singleton::keybindings()->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
@@ -114,7 +109,7 @@ void PluginApi::AddSubMenuXml(std::string plugin_name,
std::string menu_suffix = temp_menu.substr(parent_menu_pos);
std::string menu_input ="";
- menu_->keybindings_.model_.menu_ui_string_ =
+ Singleton::keybindings()->menu_ui_string =
menu_prefix + menu_input + menu_suffix;
}
@@ -221,7 +216,7 @@ void libjuci::IterToWordEnd(Gtk::TextIter &iter) {
Glib::RefPtr libjuci::BufferFromNotebook() {
return Glib::RefPtr(PluginApi::notebook_
- ->CurrentTextView().get_buffer());
+ ->CurrentSourceView()->get_buffer());
}
Gtk::TextIter libjuci::IterFromNotebook() {
diff --git a/juci/api.h b/juci/api.h
index 900d206..64e72c1 100644
--- a/juci/api.h
+++ b/juci/api.h
@@ -12,8 +12,7 @@
////////////////////
class PluginApi {
public:
- PluginApi(Menu::Controller&, Notebook::Controller&);
- ~PluginApi();
+ PluginApi();
static Menu::Controller* menu_;
static Notebook::Controller* notebook_;
static void InitPlugins();
diff --git a/juci/config.cc b/juci/config.cc
index 9fa2a69..6096a9e 100644
--- a/juci/config.cc
+++ b/juci/config.cc
@@ -1,8 +1,8 @@
+#include "singletons.h"
#include "config.h"
#include "logging.h"
-MainConfig::MainConfig() :
- keybindings_cfg() {
+MainConfig::MainConfig() {
INFO("Reading config file");
boost::property_tree::json_parser::read_json("config.json", cfg_);
INFO("Config file read");
@@ -13,7 +13,7 @@ MainConfig::MainConfig() :
}
void MainConfig::GenerateSource() {
- auto source_cfg=Singletons::Config::source();
+ auto source_cfg=Singleton::Config::source();
DEBUG("Fetching source cfg");
// boost::property_tree::ptree
auto source_json = cfg_.get_child("source");
@@ -58,39 +58,42 @@ void MainConfig::GenerateSource() {
}
void MainConfig::GenerateTerminalCommands() {
+ auto terminal_cfg=Singleton::Config::terminal();
boost::property_tree::ptree source_json = cfg_.get_child("project");
boost::property_tree::ptree compile_commands_json = source_json.get_child("compile_commands");
boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands");
for (auto &i : compile_commands_json) {
- terminal_cfg.compile_commands.emplace_back(i.second.get_value());
+ terminal_cfg->compile_commands.emplace_back(i.second.get_value());
}
for (auto &i : run_commands_json) {
- terminal_cfg.run_command=(i.second.get_value()); //TODO: run_commands array->one run_command?
+ terminal_cfg->run_command=(i.second.get_value()); //TODO: run_commands array->one run_command?
}
}
void MainConfig::GenerateKeybindings() {
+ auto keybindings_cfg=Singleton::Config::keybindings();
DEBUG("Fetching keybindings");
std::string line;
std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) {
while (getline(menu_xml, line))
- keybindings_cfg.AppendXml(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();
+ keybindings_cfg->key_map[i.first] = i.second.get_value();
DEBUG("Keybindings fetched");
}
void MainConfig::GenerateDirectoryFilter() {
+ auto dir_cfg=Singleton::Config::directories();
DEBUG("Fetching directory filter");
boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter");
boost::property_tree::ptree ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions");
for ( auto &i : except_json )
- dir_cfg.AddException(i.second.get_value());
+ dir_cfg->AddException(i.second.get_value());
for ( auto &i : ignore_json )
- dir_cfg.AddIgnore(i.second.get_value());
+ dir_cfg->AddIgnore(i.second.get_value());
DEBUG("Directory filter fetched");
}
diff --git a/juci/config.h b/juci/config.h
index c6913fc..e08c17b 100644
--- a/juci/config.h
+++ b/juci/config.h
@@ -4,17 +4,9 @@
#include
#include
#include
-#include "singletons.h"
-#include "keybindings.h"
-#include "source.h"
-#include "directories.h"
-#include "terminal.h"
class MainConfig {
public:
- Terminal::Config terminal_cfg;
- Keybindings::Config keybindings_cfg;
- Directories::Config dir_cfg;
MainConfig();
void PrintMenu();
void GenerateSource();
diff --git a/juci/directories.cc b/juci/directories.cc
index 6e8ca9e..65a28dd 100644
--- a/juci/directories.cc
+++ b/juci/directories.cc
@@ -1,8 +1,8 @@
#include "directories.h"
#include "logging.h"
+#include "singletons.h"
-Directories::Controller::Controller(Directories::Config& cfg) :
- config_(cfg) {
+Directories::Controller::Controller() {
DEBUG("adding treeview to scrolledwindow");
m_ScrolledWindow.add(m_TreeView);
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
@@ -29,10 +29,10 @@ open_folder(const boost::filesystem::path& dir_path) {
bool Directories::Controller::IsIgnored(std::string path) {
DEBUG("Checking if file-/directory is filtered");
std::transform(path.begin(), path.end(), path.begin(), ::tolower);
- if (config().IsException(path)) {
+ if (Singleton::Config::directories()->IsException(path)) {
return false;
}
- if (config().IsIgnored(path)) {
+ if (Singleton::Config::directories()->IsIgnored(path)) {
return true;
}
return false;
@@ -156,12 +156,6 @@ GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_na
return "no project name";
}
-Directories::Config::Config() {
-}
-Directories::Config::Config(Directories::Config& cfg) :
- ignore_list_(cfg.ignore_list()), exception_list_(cfg.exception_list()) {
-}
-
void Directories::Config::AddIgnore(std::string filter) {
ignore_list_.push_back(filter);
}
diff --git a/juci/directories.h b/juci/directories.h
index ff7d195..c6363c5 100644
--- a/juci/directories.h
+++ b/juci/directories.h
@@ -14,8 +14,6 @@ namespace Directories {
class Config {
public:
- Config(Config &original);
- Config();
std::vector ignore_list() { return ignore_list_; }
std::vector exception_list() { return exception_list_; }
void AddIgnore(std::string filter);
@@ -43,10 +41,8 @@ namespace Directories {
class Controller {
public:
Controller();
- Controller(Directories::Config& cfg);
View& view() { return view_;}
Model& model() { return model_;}
- Directories::Config& config() { return config_;}
Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;}
void open_folder(const boost::filesystem::path& dir_path);
void list_dirs(const boost::filesystem::path& dir_path,
@@ -64,7 +60,6 @@ namespace Directories {
private:
View view_;
Model model_;
- Directories::Config config_;
protected:
void on_treeview_row_activated(const Gtk::TreeModel::Path& path,
diff --git a/juci/juci.cc b/juci/juci.cc
index f19e7da..0785b9a 100644
--- a/juci/juci.cc
+++ b/juci/juci.cc
@@ -1,4 +1,5 @@
#include "juci.h"
+#include "singletons.h"
void init_logging() {
add_common_attributes();
@@ -36,11 +37,11 @@ void Juci::on_activate() {
window->show();
if(directory!="") {
//TODO: use the following instead, window->notebook.open_directory(directory);
- window->notebook.project_path=directory;
- window->notebook.directories.open_folder(directory);
+ Singleton::notebook()->project_path=directory;
+ Singleton::notebook()->directories.open_folder(directory);
}
for(auto &f: files)
- window->notebook.OnOpenFile(f);
+ Singleton::notebook()->OnOpenFile(f);
}
int main(int argc, char *argv[]) {
diff --git a/juci/keybindings.cc b/juci/keybindings.cc
index 2408155..afd2821 100644
--- a/juci/keybindings.cc
+++ b/juci/keybindings.cc
@@ -1,65 +1,41 @@
#include "keybindings.h"
+#include "singletons.h"
-Keybindings::Model::Model(Keybindings::Config &config) :
- menu_ui_string_(config.menu_xml()) {
- /* hidden_ui_string_ =
- " "
- " "
- " "
- " "
- " ";*/
+Keybindings::Keybindings() {
+ menu_ui_string=Singleton::Config::keybindings()->menu_xml;
+ 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::Model::~Model() {
-}
-
-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() {
+void Keybindings::BuildMenu() {
try {
- ui_manager_menu_->add_ui_from_string(model_.menu_ui_string());
+ ui_manager_menu->add_ui_from_string(menu_ui_string);
}
catch (const Glib::Error &ex) {
std::cerr << "building menu failed" << ex.what();
}
- ui_manager_menu_->insert_action_group(action_group_menu_);
+ ui_manager_menu->insert_action_group(action_group_menu);
}
-void Keybindings::Controller::BuildHiddenMenu() {
+void Keybindings::BuildHiddenMenu() {
try {
- ui_manager_hidden_->add_ui_from_string(model_.hidden_ui_string());
+ ui_manager_hidden->add_ui_from_string(hidden_ui_string);
}
catch (const Glib::Error &ex) {
std::cerr << "building hidden menu failed" << ex.what();
}
- ui_manager_hidden_->insert_action_group(action_group_hidden_);
-}
-
-Keybindings::Config::Config(Keybindings::Config &original) {
- SetMenu(original.menu_xml());
- SetKeyMap(original.key_map());
+ ui_manager_hidden->insert_action_group(action_group_hidden);
}
-Keybindings::Config::Config() {
- menu_xml_ = "";
- }
-
void Keybindings::Config::AppendXml(std::string &child) {
- menu_xml_ += child;
+ menu_xml += child;
}
void Keybindings::Config::SetMenu(std::string &menu_xml) {
- menu_xml_ = menu_xml;
+ menu_xml = menu_xml;
}
void Keybindings::Config::SetKeyMap(std::unordered_map &key_map) {
- key_map_ = key_map;
+ key_map = key_map;
}
diff --git a/juci/keybindings.h b/juci/keybindings.h
index eafccd5..deba952 100644
--- a/juci/keybindings.h
+++ b/juci/keybindings.h
@@ -2,65 +2,31 @@
#ifndef JUCI_KEYBINDINGS_H_
#define JUCI_KEYBINDINGS_H_
+#include
#include
-#include "gtkmm.h"
#include
-//#include "config.h" //TODO :: remove?
-
-namespace Keybindings {
+class Keybindings {
+public:
class Config {
public:
- Config(Config &original);
- Config();
- std::string& menu_xml() { return menu_xml_; }
- std::unordered_map& key_map() { return key_map_; }
void AppendXml(std::string &child);
void SetMenu(std::string &menu_xml);
void SetKeyMap(std::unordered_map &key_map);
- private:
- std::unordered_map key_map_;
- std::string menu_xml_;
- std::string hidden_ui_string_;
+ std::unordered_map key_map;
+ std::string menu_xml;
};//Config
-
- class Model {
- public:
- Model(Keybindings::Config &config);
- virtual ~Model();
- 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:
- explicit Controller(Keybindings::Config &config);
- virtual ~Controller();
- Glib::RefPtr action_group_menu() {
- return action_group_menu_;
- };
- Glib::RefPtr ui_manager_menu() {
- return ui_manager_menu_;
- };
- Glib::RefPtr action_group_hidden() {
- return action_group_hidden_;
- };
- Glib::RefPtr ui_manager_hidden() {
- return ui_manager_hidden_;
- };
- void BuildMenu();
- void BuildHiddenMenu();
- // protected:
- Glib::RefPtr ui_manager_menu_;
- Glib::RefPtr action_group_menu_;
- Glib::RefPtr ui_manager_hidden_;
- Glib::RefPtr action_group_hidden_;
- // private:
- Keybindings::Config config_;
- Keybindings::Model model_;
- };//Controller
-}
+ Keybindings();
+ void BuildMenu();
+ void BuildHiddenMenu();
+
+ std::string menu_ui_string;
+ std::string hidden_ui_string;
+
+ Glib::RefPtr ui_manager_menu;
+ Glib::RefPtr action_group_menu;
+ Glib::RefPtr ui_manager_hidden;
+ Glib::RefPtr action_group_hidden;
+};
#endif // JUCI_KEYBINDINGS_H_
diff --git a/juci/menu.cc b/juci/menu.cc
index 0f09906..774ba00 100644
--- a/juci/menu.cc
+++ b/juci/menu.cc
@@ -1,4 +1,5 @@
#include "menu.h"
+#include "singletons.h"
Menu::View::View(Gtk::Orientation orientation) :
view_(orientation) {
@@ -11,43 +12,42 @@ Gtk::Box &Menu::View::view(
return view_;
}
-Menu::Controller::Controller(Keybindings::Controller& keybindings) :
- menu_view_(Gtk::ORIENTATION_VERTICAL),
- keybindings_(keybindings) {
- keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew",
+Menu::Controller::Controller() : menu_view_(Gtk::ORIENTATION_VERTICAL) {
+ auto keybindings=Singleton::keybindings();
+ keybindings->action_group_menu->add(Gtk::Action::create("FileNew",
"New File"));
- keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu",
+ keybindings->action_group_menu->add(Gtk::Action::create("EditMenu",
Gtk::Stock::EDIT));
- keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu",
+ keybindings->action_group_menu->add(Gtk::Action::create("WindowMenu",
"_Window"));
- keybindings_.action_group_menu()->add(Gtk::Action::create("WindowSplitWindow",
+ keybindings->action_group_menu->add(Gtk::Action::create("WindowSplitWindow",
"Split window"),
- Gtk::AccelKey(keybindings_.config_
- .key_map()["split_window"]),//"S"),
+ Gtk::AccelKey(Singleton::Config::keybindings()
+ ->key_map["split_window"]),//"S"),
[this]() {
OnWindowSplitWindow();
});
- keybindings_.action_group_menu()->add(Gtk::Action::create("ProjectMenu",
+ keybindings->action_group_menu->add(Gtk::Action::create("ProjectMenu",
"P_roject"));
- keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu",
+ keybindings->action_group_menu->add(Gtk::Action::create("PluginMenu",
"_Plugins"));
- keybindings_.action_group_menu()->add(Gtk::Action::create("HelpMenu",
+ keybindings->action_group_menu->add(Gtk::Action::create("HelpMenu",
Gtk::Stock::HELP));
- keybindings_.action_group_menu()->add(Gtk::Action::create("HelpAbout",
+ keybindings->action_group_menu->add(Gtk::Action::create("HelpAbout",
Gtk::Stock::ABOUT),
[this]() {
OnHelpAbout();
});
- keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"),
+ keybindings->action_group_hidden->add(Gtk::Action::create("Test"),
Gtk::AccelKey("K"),
[this]() {
OnHelpAbout();
});
- //keybindings_.BuildMenu(); // moved to window.cc
- keybindings_.BuildHiddenMenu();
+ //keybindings->BuildMenu(); // moved to window.cc
+ keybindings->BuildHiddenMenu();
} // Controller
Gtk::Box &Menu::Controller::view() {
- return menu_view_.view(keybindings_.ui_manager_menu());
+ return menu_view_.view(Singleton::keybindings()->ui_manager_menu);
}
void Menu::Controller::OnPluginAddSnippet() {
//TODO(Forgi add you snippet magic code)
diff --git a/juci/menu.h b/juci/menu.h
index f743999..0396e96 100644
--- a/juci/menu.h
+++ b/juci/menu.h
@@ -2,8 +2,7 @@
#define JUCI_MENU_H_
#include
-#include "gtkmm.h"
-#include "keybindings.h"
+#include
namespace Menu {
class View {
@@ -15,10 +14,9 @@ namespace Menu {
}; // class View
class Controller {
public:
- explicit Controller(Keybindings::Controller& keybindings);
+ Controller();
Gtk::Box &view();
- Keybindings::Controller &keybindings_;
View menu_view_;
void OnFileNewEmptyfile();
void OnFileNewCCFile();
diff --git a/juci/notebook.cc b/juci/notebook.cc
index 1398225..ac149d8 100644
--- a/juci/notebook.cc
+++ b/juci/notebook.cc
@@ -1,6 +1,7 @@
#include
#include "notebook.h"
#include "logging.h"
+#include "singletons.h"
#include // c-library
@@ -9,95 +10,86 @@ Notebook::View::View() {
set_position(120);
}
-Notebook::Controller::Controller(Keybindings::Controller& keybindings,
- Terminal::Controller& terminal,
- Directories::Config& dir_cfg) :
- terminal(terminal),
- directories(dir_cfg) {
+Notebook::Controller::Controller() :
+ directories() {
INFO("Create notebook");
- refClipboard_ = Gtk::Clipboard::get();
+ clipboard = Gtk::Clipboard::get();
view.pack1(directories.widget(), true, true);
- CreateKeybindings(keybindings);
+ CreateKeybindings();
INFO("Notebook Controller Success");
} // Constructor
-void Notebook::Controller::CreateKeybindings(Keybindings::Controller
- &keybindings) {
+void Notebook::Controller::CreateKeybindings() {
+ auto keybindings=Singleton::keybindings();
+ auto keybindings_cfg=Singleton::Config::keybindings();
INFO("Notebook create signal handlers");
directories.m_TreeView.signal_row_activated()
.connect(sigc::mem_fun(*this,
&Notebook::Controller::OnDirectoryNavigation));
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("FileMenu",
Gtk::Stock::FILE));
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("FileNewFile",
"New file"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["new_file"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["new_file"]),
[this]() {
OnFileNewFile();
});
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("WindowCloseTab",
"Close tab"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["close_tab"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["close_tab"]),
[this]() {
OnCloseCurrentPage();
});
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("EditFind",
"Find"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["edit_find"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["edit_find"]),
[this]() {
entry.show_search("");
});
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("EditCopy",
"Copy"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["edit_copy"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["edit_copy"]),
[this]() {
if (Pages() != 0) {
- CurrentTextView().get_buffer()->copy_clipboard(refClipboard_);
+ CurrentSourceView()->get_buffer()->copy_clipboard(clipboard);
}
});
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("EditCut",
"Cut"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["edit_cut"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["edit_cut"]),
[this]() {
if (Pages() != 0) {
- CurrentTextView().get_buffer()->cut_clipboard(refClipboard_);
+ CurrentSourceView()->get_buffer()->cut_clipboard(clipboard);
}
});
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("EditPaste",
"Paste"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["edit_paste"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["edit_paste"]),
[this]() {
if (Pages() != 0) {
- CurrentTextView().get_buffer()->paste_clipboard(refClipboard_);
+ CurrentSourceView()->get_buffer()->paste_clipboard(clipboard);
}
});
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("EditUndo",
"Undo"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["edit_undo"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["edit_undo"]),
[this]() {
INFO("On undo");
Glib::RefPtr undo_manager =
- CurrentTextView().get_source_buffer()->get_undo_manager();
+ CurrentSourceView()->get_source_buffer()->get_undo_manager();
if (Pages() != 0 && undo_manager->can_undo()) {
undo_manager->undo();
}
@@ -105,15 +97,14 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
}
);
- keybindings.action_group_menu()->
+ keybindings->action_group_menu->
add(Gtk::Action::create("EditRedo",
"Redo"),
- Gtk::AccelKey(keybindings.config_
- .key_map()["edit_redo"]),
+ Gtk::AccelKey(keybindings_cfg->key_map["edit_redo"]),
[this]() {
INFO("On Redo");
Glib::RefPtr undo_manager =
- CurrentTextView().get_source_buffer()->get_undo_manager();
+ CurrentSourceView()->get_source_buffer()->get_undo_manager();
if (Pages() != 0 && undo_manager->can_redo()) {
undo_manager->redo();
}
@@ -162,56 +153,42 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
INFO("Notebook signal handlers sucsess");
}
-Notebook::Controller::~Controller() {
- INFO("Notebook destructor");
- for (auto &i : editor_vec_) delete i;
- for (auto &i : scrolledtext_vec_) delete i;
-}
-
void Notebook::Controller::OnOpenFile(std::string path) {
INFO("Notebook open file");
INFO("Notebook create page");
- text_vec_.emplace_back(new Source::Controller(path, project_path, terminal));
- scrolledtext_vec_.push_back(new Gtk::ScrolledWindow());
- editor_vec_.push_back(new Gtk::HBox());
- scrolledtext_vec_.back()->add(*text_vec_.back()->view);
- editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true);
- size_t pos = path.find_last_of("/\\"); // TODO #windows
- std::string filename=path;
- if(pos!=std::string::npos)
- filename=path.substr(pos+1);
- Notebook().append_page(*editor_vec_.back(), filename);
- Notebook().show_all_children();
- Notebook().set_current_page(Pages()-1);
- Notebook().set_focus_child(*text_vec_.back()->view);
+ source_views.emplace_back(new Source(path, project_path));
+ scrolled_windows.emplace_back(new Gtk::ScrolledWindow());
+ hboxes.emplace_back(new Gtk::HBox());
+ scrolled_windows.back()->add(*source_views.back()->view);
+ hboxes.back()->pack_start(*scrolled_windows.back(), true, true);
+ boost::filesystem::path file_path(source_views.back()->view->file_path);
+ std::string title=file_path.filename().string();
+ view.notebook.append_page(*hboxes.back(), title);
+ view.notebook.show_all_children();
+ view.notebook.set_current_page(Pages()-1);
+ view.notebook.set_focus_child(*source_views.back()->view);
+ CurrentSourceView()->get_buffer()->set_modified(false);
//Add star on tab label when the page is not saved:
- //TODO: instead use Gtk::TextBuffer::set_modified and Gtk::TextBuffer::get_modified
- text_vec_.back()->buffer()->signal_changed().connect([this]() {
- if(text_vec_.at(CurrentPage())->is_saved) {
- std::string path=CurrentTextView().file_path;
- size_t pos = path.find_last_of("/\\");
- std::string filename=path;
- if(pos!=std::string::npos)
- filename=path.substr(pos+1);
- Notebook().set_tab_label_text(*(Notebook().get_nth_page(CurrentPage())), filename+"*");
- }
- text_vec_.at(CurrentPage())->is_saved=false;
+ CurrentSourceView()->get_buffer()->signal_modified_changed().connect([this]() {
+ boost::filesystem::path file_path(CurrentSourceView()->file_path);
+ std::string title=file_path.filename().string();
+ if(CurrentSourceView()->get_buffer()->get_modified())
+ title+="*";
+ view.notebook.set_tab_label_text(*(view.notebook.get_nth_page(CurrentPage())), title);
});
}
void Notebook::Controller::OnCloseCurrentPage() {
INFO("Notebook close page");
if (Pages() != 0) {
- if(!text_vec_.at(CurrentPage())->is_saved){
+ if(CurrentSourceView()->get_buffer()->get_modified()){
AskToSaveDialog();
}
int page = CurrentPage();
- Notebook().remove_page(page);
- delete scrolledtext_vec_.at(page);
- delete editor_vec_.at(page);
- text_vec_.erase(text_vec_.begin()+ page);
- scrolledtext_vec_.erase(scrolledtext_vec_.begin()+page);
- editor_vec_.erase(editor_vec_.begin()+page);
+ view.notebook.remove_page(page);
+ source_views.erase(source_views.begin()+ page);
+ scrolled_windows.erase(scrolled_windows.begin()+page);
+ hboxes.erase(hboxes.begin()+page);
}
}
void Notebook::Controller::OnFileNewFile() {
@@ -220,10 +197,10 @@ void Notebook::Controller::OnFileNewFile() {
void Notebook::Controller::search(bool forward) {
INFO("Notebook search");
- auto start = CurrentTextView().search_start;
- auto end = CurrentTextView().search_end;
+ auto start = CurrentSourceView()->search_start;
+ auto end = CurrentSourceView()->search_end;
// fetch buffer and greate settings
- auto buffer = CurrentTextView().get_source_buffer();
+ auto buffer = CurrentSourceView()->get_source_buffer();
auto settings = gtk_source_search_settings_new();
// get search text from entry
gtk_source_search_settings_set_search_text(settings, entry().c_str());
@@ -247,9 +224,9 @@ void Notebook::Controller::search(bool forward) {
end.gobj());
}
buffer->apply_tag_by_name("search", start, end);
- CurrentTextView().scroll_to(end);
- CurrentTextView().search_start = start;
- CurrentTextView().search_end = end;
+ CurrentSourceView()->scroll_to(end);
+ CurrentSourceView()->search_start = start;
+ CurrentSourceView()->search_end = end;
}
void Notebook::Controller
@@ -274,40 +251,34 @@ void Notebook::Controller
}
}
-Source::View& Notebook::Controller::CurrentTextView() {
+Source::View* Notebook::Controller::CurrentSourceView() {
INFO("Getting sourceview");
- return *text_vec_.at(CurrentPage())->view;
+ return source_views.at(CurrentPage())->view.get();
}
int Notebook::Controller::CurrentPage() {
- return Notebook().get_current_page();
+ return view.notebook.get_current_page();
}
int Notebook::Controller::Pages() {
- return Notebook().get_n_pages();
-}
-Gtk::Notebook& Notebook::Controller::Notebook() {
- return view.notebook;
+ return view.notebook.get_n_pages();
}
bool Notebook::Controller:: OnSaveFile() {
- std::string path=CurrentTextView().file_path;
+ std::string path=CurrentSourceView()->file_path;
return OnSaveFile(path);
}
bool Notebook::Controller:: OnSaveFile(std::string path) {
INFO("Notebook save file with path");
- if (path != "") {
+ if (path != "" && CurrentSourceView()->get_buffer()->get_modified()) {
std::ofstream file;
file.open (path);
- file << CurrentTextView().get_buffer()->get_text();
+ file << CurrentSourceView()->get_buffer()->get_text();
file.close();
- CurrentTextView().file_path=path;
- size_t pos = path.find_last_of("/\\");
- std::string filename=path;
- if(pos!=std::string::npos)
- filename=path.substr(pos+1);
- Notebook().set_tab_label_text(*Notebook().get_nth_page(CurrentPage()), filename);
- text_vec_.at(CurrentPage())->is_saved=true;
+ boost::filesystem::path path(CurrentSourceView()->file_path);
+ std::string title=path.filename().string();
+ view.notebook.set_tab_label_text(*view.notebook.get_nth_page(CurrentPage()), title);
+ CurrentSourceView()->get_buffer()->set_modified(false);
return true;
}
return false;
@@ -350,7 +321,7 @@ void Notebook::Controller::AskToSaveDialog() {
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text(
"Do you want to save: " +
- CurrentTextView().file_path+" ?");
+ CurrentSourceView()->file_path+" ?");
DEBUG("AskToSaveDialog: run dialog");
int result = dialog.run();
diff --git a/juci/notebook.h b/juci/notebook.h
index 8ff76b1..13808c2 100644
--- a/juci/notebook.h
+++ b/juci/notebook.h
@@ -11,8 +11,6 @@
#include