Browse Source

Largeer cleanup in preparation to refactoring implementation. Also some smaller fixes.

merge-requests/365/head
eidheim 11 years ago
parent
commit
931dc12425
  1. 27
      juci/api.cc
  2. 3
      juci/api.h
  3. 21
      juci/config.cc
  4. 8
      juci/config.h
  5. 14
      juci/directories.cc
  6. 5
      juci/directories.h
  7. 7
      juci/juci.cc
  8. 56
      juci/keybindings.cc
  9. 64
      juci/keybindings.h
  10. 34
      juci/menu.cc
  11. 6
      juci/menu.h
  12. 171
      juci/notebook.cc
  13. 24
      juci/notebook.h
  14. 30
      juci/singletons.cc
  15. 27
      juci/singletons.h
  16. 186
      juci/source.cc
  17. 46
      juci/source.h
  18. 20
      juci/terminal.cc
  19. 6
      juci/terminal.h
  20. 2
      juci/tooltips.cc
  21. 121
      juci/window.cc
  22. 5
      juci/window.h

27
juci/api.cc

@ -1,16 +1,16 @@
#include "api.h" #include "api.h"
#include "logging.h" #include "logging.h"
#include "singletons.h"
Menu::Controller* PluginApi::menu_; Menu::Controller* PluginApi::menu_;
Notebook::Controller* PluginApi::notebook_; Notebook::Controller* PluginApi::notebook_;
///////////////////////////// /////////////////////////////
//// API ServiceProvider //// //// API ServiceProvider ////
///////////////////////////// /////////////////////////////
PluginApi::PluginApi(Menu::Controller& menu_ctl_, PluginApi::PluginApi() {
Notebook::Controller& notebook_ctl_) {
DEBUG("Adding pointers for the API"); DEBUG("Adding pointers for the API");
menu_ = &menu_ctl_; notebook_ = Singleton::notebook();
notebook_ = &notebook_ctl_; menu_ = Singleton::menu();
DEBUG("Initiating plugins(from plugins.py).."); DEBUG("Initiating plugins(from plugins.py)..");
#ifndef __APPLE__ #ifndef __APPLE__
InitPlugins(); //TODO: fix this InitPlugins(); //TODO: fix this
@ -18,11 +18,6 @@ PluginApi::PluginApi(Menu::Controller& menu_ctl_,
DEBUG("Plugins initiated.."); DEBUG("Plugins initiated..");
} }
PluginApi::~PluginApi() {
menu_ = NULL;
notebook_ = NULL;
}
std::string PluginApi::ProjectPath() { std::string PluginApi::ProjectPath() {
int MAXPATHLEN = 50; int MAXPATHLEN = 50;
char temp[MAXPATHLEN]; char temp[MAXPATHLEN];
@ -69,7 +64,7 @@ void PluginApi::AddMenuElement(std::string plugin_name) {
DEBUG("Adding menu element for "+plugin_name); DEBUG("Adding menu element for "+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() Singleton::keybindings()->action_group_menu
->add(Gtk::Action::create(plugin_action_name, plugin_name)); ->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 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() Singleton::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),
@ -89,7 +84,7 @@ void PluginApi::AddSubMenuElement(std::string parent_menu,
} }
void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) { void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) {
std::string temp_menu = menu_->keybindings_.model_.menu_ui_string(); std::string temp_menu = Singleton::keybindings()->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;
@ -99,13 +94,13 @@ void PluginApi::AddMenuXml(std::string plugin_name, std::string parent_menu) {
" <menu action='"+plugin_name+"Menu'> " " <menu action='"+plugin_name+"Menu'> "
" </menu> "; " </menu> ";
menu_->keybindings_.model_.menu_ui_string_ = Singleton::keybindings()->menu_ui_string =
menu_prefix + menu_input + menu_suffix; menu_prefix + menu_input + menu_suffix;
} }
void PluginApi::AddSubMenuXml(std::string plugin_name, void PluginApi::AddSubMenuXml(std::string plugin_name,
std::string parent_menu) { 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); 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
@ -114,7 +109,7 @@ void PluginApi::AddSubMenuXml(std::string plugin_name,
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_ = Singleton::keybindings()->menu_ui_string =
menu_prefix + menu_input + menu_suffix; menu_prefix + menu_input + menu_suffix;
} }
@ -221,7 +216,7 @@ void libjuci::IterToWordEnd(Gtk::TextIter &iter) {
Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() { Glib::RefPtr<Gtk::TextBuffer> libjuci::BufferFromNotebook() {
return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_ return Glib::RefPtr<Gtk::TextBuffer>(PluginApi::notebook_
->CurrentTextView().get_buffer()); ->CurrentSourceView()->get_buffer());
} }
Gtk::TextIter libjuci::IterFromNotebook() { Gtk::TextIter libjuci::IterFromNotebook() {

3
juci/api.h

@ -12,8 +12,7 @@
//////////////////// ////////////////////
class PluginApi { class PluginApi {
public: public:
PluginApi(Menu::Controller&, Notebook::Controller&); PluginApi();
~PluginApi();
static Menu::Controller* menu_; static Menu::Controller* menu_;
static Notebook::Controller* notebook_; static Notebook::Controller* notebook_;
static void InitPlugins(); static void InitPlugins();

21
juci/config.cc

@ -1,8 +1,8 @@
#include "singletons.h"
#include "config.h" #include "config.h"
#include "logging.h" #include "logging.h"
MainConfig::MainConfig() : MainConfig::MainConfig() {
keybindings_cfg() {
INFO("Reading config file"); INFO("Reading config file");
boost::property_tree::json_parser::read_json("config.json", cfg_); boost::property_tree::json_parser::read_json("config.json", cfg_);
INFO("Config file read"); INFO("Config file read");
@ -13,7 +13,7 @@ MainConfig::MainConfig() :
} }
void MainConfig::GenerateSource() { void MainConfig::GenerateSource() {
auto source_cfg=Singletons::Config::source(); auto source_cfg=Singleton::Config::source();
DEBUG("Fetching source cfg"); DEBUG("Fetching source cfg");
// boost::property_tree::ptree // boost::property_tree::ptree
auto source_json = cfg_.get_child("source"); auto source_json = cfg_.get_child("source");
@ -58,39 +58,42 @@ void MainConfig::GenerateSource() {
} }
void MainConfig::GenerateTerminalCommands() { void MainConfig::GenerateTerminalCommands() {
auto terminal_cfg=Singleton::Config::terminal();
boost::property_tree::ptree source_json = cfg_.get_child("project"); 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 compile_commands_json = source_json.get_child("compile_commands");
boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands"); boost::property_tree::ptree run_commands_json = source_json.get_child("run_commands");
for (auto &i : compile_commands_json) { for (auto &i : compile_commands_json) {
terminal_cfg.compile_commands.emplace_back(i.second.get_value<std::string>()); terminal_cfg->compile_commands.emplace_back(i.second.get_value<std::string>());
} }
for (auto &i : run_commands_json) { for (auto &i : run_commands_json) {
terminal_cfg.run_command=(i.second.get_value<std::string>()); //TODO: run_commands array->one run_command? terminal_cfg->run_command=(i.second.get_value<std::string>()); //TODO: run_commands array->one run_command?
} }
} }
void MainConfig::GenerateKeybindings() { void MainConfig::GenerateKeybindings() {
auto keybindings_cfg=Singleton::Config::keybindings();
DEBUG("Fetching keybindings"); DEBUG("Fetching keybindings");
std::string line; std::string line;
std::ifstream menu_xml("menu.xml"); std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) { if (menu_xml.is_open()) {
while (getline(menu_xml, line)) while (getline(menu_xml, line))
keybindings_cfg.AppendXml(line); keybindings_cfg->AppendXml(line);
} }
boost::property_tree::ptree keys_json = cfg_.get_child("keybindings"); boost::property_tree::ptree keys_json = cfg_.get_child("keybindings");
for (auto &i : keys_json) for (auto &i : keys_json)
keybindings_cfg.key_map()[i.first] = i.second.get_value<std::string>(); keybindings_cfg->key_map[i.first] = i.second.get_value<std::string>();
DEBUG("Keybindings fetched"); DEBUG("Keybindings fetched");
} }
void MainConfig::GenerateDirectoryFilter() { void MainConfig::GenerateDirectoryFilter() {
auto dir_cfg=Singleton::Config::directories();
DEBUG("Fetching directory filter"); DEBUG("Fetching directory filter");
boost::property_tree::ptree dir_json = cfg_.get_child("directoryfilter"); 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 ignore_json = dir_json.get_child("ignore");
boost::property_tree::ptree except_json = dir_json.get_child("exceptions"); boost::property_tree::ptree except_json = dir_json.get_child("exceptions");
for ( auto &i : except_json ) for ( auto &i : except_json )
dir_cfg.AddException(i.second.get_value<std::string>()); dir_cfg->AddException(i.second.get_value<std::string>());
for ( auto &i : ignore_json ) for ( auto &i : ignore_json )
dir_cfg.AddIgnore(i.second.get_value<std::string>()); dir_cfg->AddIgnore(i.second.get_value<std::string>());
DEBUG("Directory filter fetched"); DEBUG("Directory filter fetched");
} }

8
juci/config.h

@ -4,17 +4,9 @@
#include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/xml_parser.hpp>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include "singletons.h"
#include "keybindings.h"
#include "source.h"
#include "directories.h"
#include "terminal.h"
class MainConfig { class MainConfig {
public: public:
Terminal::Config terminal_cfg;
Keybindings::Config keybindings_cfg;
Directories::Config dir_cfg;
MainConfig(); MainConfig();
void PrintMenu(); void PrintMenu();
void GenerateSource(); void GenerateSource();

14
juci/directories.cc

@ -1,8 +1,8 @@
#include "directories.h" #include "directories.h"
#include "logging.h" #include "logging.h"
#include "singletons.h"
Directories::Controller::Controller(Directories::Config& cfg) : Directories::Controller::Controller() {
config_(cfg) {
DEBUG("adding treeview to scrolledwindow"); DEBUG("adding treeview to scrolledwindow");
m_ScrolledWindow.add(m_TreeView); m_ScrolledWindow.add(m_TreeView);
m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); 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) { bool Directories::Controller::IsIgnored(std::string path) {
DEBUG("Checking if file-/directory is filtered"); DEBUG("Checking if file-/directory is filtered");
std::transform(path.begin(), path.end(), path.begin(), ::tolower); std::transform(path.begin(), path.end(), path.begin(), ::tolower);
if (config().IsException(path)) { if (Singleton::Config::directories()->IsException(path)) {
return false; return false;
} }
if (config().IsIgnored(path)) { if (Singleton::Config::directories()->IsIgnored(path)) {
return true; return true;
} }
return false; return false;
@ -156,12 +156,6 @@ GetCmakeVarValue(const boost::filesystem::path& dir_path, std::string command_na
return "no project name"; 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) { void Directories::Config::AddIgnore(std::string filter) {
ignore_list_.push_back(filter); ignore_list_.push_back(filter);
} }

5
juci/directories.h

@ -14,8 +14,6 @@ namespace Directories {
class Config { class Config {
public: public:
Config(Config &original);
Config();
std::vector<std::string> ignore_list() { return ignore_list_; } std::vector<std::string> ignore_list() { return ignore_list_; }
std::vector<std::string> exception_list() { return exception_list_; } std::vector<std::string> exception_list() { return exception_list_; }
void AddIgnore(std::string filter); void AddIgnore(std::string filter);
@ -43,10 +41,8 @@ namespace Directories {
class Controller { class Controller {
public: public:
Controller(); Controller();
Controller(Directories::Config& cfg);
View& view() { return view_;} View& view() { return view_;}
Model& model() { return model_;} Model& model() { return model_;}
Directories::Config& config() { return config_;}
Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;} Gtk::ScrolledWindow& widget() {return m_ScrolledWindow;}
void open_folder(const boost::filesystem::path& dir_path); void open_folder(const boost::filesystem::path& dir_path);
void list_dirs(const boost::filesystem::path& dir_path, void list_dirs(const boost::filesystem::path& dir_path,
@ -64,7 +60,6 @@ namespace Directories {
private: private:
View view_; View view_;
Model model_; Model model_;
Directories::Config config_;
protected: protected:
void on_treeview_row_activated(const Gtk::TreeModel::Path& path, void on_treeview_row_activated(const Gtk::TreeModel::Path& path,

7
juci/juci.cc

@ -1,4 +1,5 @@
#include "juci.h" #include "juci.h"
#include "singletons.h"
void init_logging() { void init_logging() {
add_common_attributes(); add_common_attributes();
@ -36,11 +37,11 @@ void Juci::on_activate() {
window->show(); window->show();
if(directory!="") { if(directory!="") {
//TODO: use the following instead, window->notebook.open_directory(directory); //TODO: use the following instead, window->notebook.open_directory(directory);
window->notebook.project_path=directory; Singleton::notebook()->project_path=directory;
window->notebook.directories.open_folder(directory); Singleton::notebook()->directories.open_folder(directory);
} }
for(auto &f: files) for(auto &f: files)
window->notebook.OnOpenFile(f); Singleton::notebook()->OnOpenFile(f);
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

56
juci/keybindings.cc

@ -1,65 +1,41 @@
#include "keybindings.h" #include "keybindings.h"
#include "singletons.h"
Keybindings::Model::Model(Keybindings::Config &config) : Keybindings::Keybindings() {
menu_ui_string_(config.menu_xml()) { menu_ui_string=Singleton::Config::keybindings()->menu_xml;
/* hidden_ui_string_ = action_group_menu = Gtk::ActionGroup::create();
"<ui> " ui_manager_menu = Gtk::UIManager::create();
" <menubar name='MenuBar'> " action_group_hidden = Gtk::ActionGroup::create();
" <menuitem action='Test'/> " ui_manager_hidden = Gtk::UIManager::create();
" </menubar> "
"</ui> ";*/
} }
Keybindings::Model::~Model() { void Keybindings::BuildMenu() {
}
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 { 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) { catch (const Glib::Error &ex) {
std::cerr << "building menu failed" << ex.what(); 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 { 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) { catch (const Glib::Error &ex) {
std::cerr << "building hidden menu failed" << ex.what(); std::cerr << "building hidden menu failed" << ex.what();
} }
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_ = "";
}
void Keybindings::Config::AppendXml(std::string &child) { void Keybindings::Config::AppendXml(std::string &child) {
menu_xml_ += child; menu_xml += child;
} }
void Keybindings::Config::SetMenu(std::string &menu_xml) { void Keybindings::Config::SetMenu(std::string &menu_xml) {
menu_xml_ = menu_xml; menu_xml = menu_xml;
} }
void Keybindings::Config::SetKeyMap(std::unordered_map<std::string, std::string> &key_map) { void Keybindings::Config::SetKeyMap(std::unordered_map<std::string, std::string> &key_map) {
key_map_ = key_map; key_map = key_map;
} }

64
juci/keybindings.h

@ -2,65 +2,31 @@
#ifndef JUCI_KEYBINDINGS_H_ #ifndef JUCI_KEYBINDINGS_H_
#define JUCI_KEYBINDINGS_H_ #define JUCI_KEYBINDINGS_H_
#include <gtkmm.h>
#include <iostream> #include <iostream>
#include "gtkmm.h"
#include <unordered_map> #include <unordered_map>
//#include "config.h" //TODO :: remove?
namespace Keybindings {
class Keybindings {
public:
class Config { class Config {
public: 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 AppendXml(std::string &child);
void SetMenu(std::string &menu_xml); void SetMenu(std::string &menu_xml);
void SetKeyMap(std::unordered_map<std::string, std::string> &key_map); void SetKeyMap(std::unordered_map<std::string, std::string> &key_map);
private: std::unordered_map<std::string, std::string> key_map;
std::unordered_map<std::string, std::string> key_map_; std::string menu_xml;
std::string menu_xml_;
std::string hidden_ui_string_;
};//Config };//Config
class Model { Keybindings();
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<Gtk::ActionGroup> action_group_menu() {
return action_group_menu_;
};
Glib::RefPtr<Gtk::UIManager> ui_manager_menu() {
return ui_manager_menu_;
};
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden() {
return action_group_hidden_;
};
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden() {
return ui_manager_hidden_;
};
void BuildMenu(); void BuildMenu();
void BuildHiddenMenu(); void BuildHiddenMenu();
// protected:
Glib::RefPtr<Gtk::UIManager> ui_manager_menu_; std::string menu_ui_string;
Glib::RefPtr<Gtk::ActionGroup> action_group_menu_; std::string hidden_ui_string;
Glib::RefPtr<Gtk::UIManager> ui_manager_hidden_;
Glib::RefPtr<Gtk::ActionGroup> action_group_hidden_; Glib::RefPtr<Gtk::UIManager> ui_manager_menu;
// private: Glib::RefPtr<Gtk::ActionGroup> action_group_menu;
Keybindings::Config config_; Glib::RefPtr<Gtk::UIManager> ui_manager_hidden;
Keybindings::Model model_; Glib::RefPtr<Gtk::ActionGroup> action_group_hidden;
};//Controller };
}
#endif // JUCI_KEYBINDINGS_H_ #endif // JUCI_KEYBINDINGS_H_

34
juci/menu.cc

@ -1,4 +1,5 @@
#include "menu.h" #include "menu.h"
#include "singletons.h"
Menu::View::View(Gtk::Orientation orientation) : Menu::View::View(Gtk::Orientation orientation) :
view_(orientation) { view_(orientation) {
@ -11,43 +12,42 @@ Gtk::Box &Menu::View::view(
return view_; return view_;
} }
Menu::Controller::Controller(Keybindings::Controller& keybindings) : Menu::Controller::Controller() : menu_view_(Gtk::ORIENTATION_VERTICAL) {
menu_view_(Gtk::ORIENTATION_VERTICAL), auto keybindings=Singleton::keybindings();
keybindings_(keybindings) { keybindings->action_group_menu->add(Gtk::Action::create("FileNew",
keybindings_.action_group_menu()->add(Gtk::Action::create("FileNew",
"New File")); "New File"));
keybindings_.action_group_menu()->add(Gtk::Action::create("EditMenu", keybindings->action_group_menu->add(Gtk::Action::create("EditMenu",
Gtk::Stock::EDIT)); Gtk::Stock::EDIT));
keybindings_.action_group_menu()->add(Gtk::Action::create("WindowMenu", keybindings->action_group_menu->add(Gtk::Action::create("WindowMenu",
"_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(keybindings_.config_ Gtk::AccelKey(Singleton::Config::keybindings()
.key_map()["split_window"]),//"<control><alt>S"), ->key_map["split_window"]),//"<control><alt>S"),
[this]() { [this]() {
OnWindowSplitWindow(); OnWindowSplitWindow();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("ProjectMenu", keybindings->action_group_menu->add(Gtk::Action::create("ProjectMenu",
"P_roject")); "P_roject"));
keybindings_.action_group_menu()->add(Gtk::Action::create("PluginMenu", keybindings->action_group_menu->add(Gtk::Action::create("PluginMenu",
"_Plugins")); "_Plugins"));
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",
Gtk::Stock::ABOUT), Gtk::Stock::ABOUT),
[this]() { [this]() {
OnHelpAbout(); OnHelpAbout();
}); });
keybindings_.action_group_hidden()->add(Gtk::Action::create("Test"), keybindings->action_group_hidden->add(Gtk::Action::create("Test"),
Gtk::AccelKey("<control><alt>K"), Gtk::AccelKey("<control><alt>K"),
[this]() { [this]() {
OnHelpAbout(); OnHelpAbout();
}); });
//keybindings_.BuildMenu(); // moved to window.cc //keybindings->BuildMenu(); // moved to window.cc
keybindings_.BuildHiddenMenu(); keybindings->BuildHiddenMenu();
} // Controller } // Controller
Gtk::Box &Menu::Controller::view() { 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() { void Menu::Controller::OnPluginAddSnippet() {
//TODO(Forgi add you snippet magic code) //TODO(Forgi add you snippet magic code)

6
juci/menu.h

@ -2,8 +2,7 @@
#define JUCI_MENU_H_ #define JUCI_MENU_H_
#include <iostream> #include <iostream>
#include "gtkmm.h" #include <gtkmm.h>
#include "keybindings.h"
namespace Menu { namespace Menu {
class View { class View {
@ -15,10 +14,9 @@ namespace Menu {
}; // class View }; // class View
class Controller { class Controller {
public: public:
explicit Controller(Keybindings::Controller& keybindings); Controller();
Gtk::Box &view(); Gtk::Box &view();
Keybindings::Controller &keybindings_;
View menu_view_; View menu_view_;
void OnFileNewEmptyfile(); void OnFileNewEmptyfile();
void OnFileNewCCFile(); void OnFileNewCCFile();

171
juci/notebook.cc

@ -1,6 +1,7 @@
#include <fstream> #include <fstream>
#include "notebook.h" #include "notebook.h"
#include "logging.h" #include "logging.h"
#include "singletons.h"
#include <gtksourceview/gtksource.h> // c-library #include <gtksourceview/gtksource.h> // c-library
@ -9,95 +10,86 @@ Notebook::View::View() {
set_position(120); set_position(120);
} }
Notebook::Controller::Controller(Keybindings::Controller& keybindings, Notebook::Controller::Controller() :
Terminal::Controller& terminal, directories() {
Directories::Config& dir_cfg) :
terminal(terminal),
directories(dir_cfg) {
INFO("Create notebook"); INFO("Create notebook");
refClipboard_ = Gtk::Clipboard::get(); clipboard = Gtk::Clipboard::get();
view.pack1(directories.widget(), true, true); view.pack1(directories.widget(), true, true);
CreateKeybindings(keybindings); CreateKeybindings();
INFO("Notebook Controller Success"); INFO("Notebook Controller Success");
} // Constructor } // Constructor
void Notebook::Controller::CreateKeybindings(Keybindings::Controller void Notebook::Controller::CreateKeybindings() {
&keybindings) { auto keybindings=Singleton::keybindings();
auto keybindings_cfg=Singleton::Config::keybindings();
INFO("Notebook create signal handlers"); INFO("Notebook create signal handlers");
directories.m_TreeView.signal_row_activated() directories.m_TreeView.signal_row_activated()
.connect(sigc::mem_fun(*this, .connect(sigc::mem_fun(*this,
&Notebook::Controller::OnDirectoryNavigation)); &Notebook::Controller::OnDirectoryNavigation));
keybindings.action_group_menu()-> keybindings->action_group_menu->
add(Gtk::Action::create("FileMenu", add(Gtk::Action::create("FileMenu",
Gtk::Stock::FILE)); Gtk::Stock::FILE));
keybindings.action_group_menu()-> keybindings->action_group_menu->
add(Gtk::Action::create("FileNewFile", add(Gtk::Action::create("FileNewFile",
"New file"), "New file"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["new_file"]),
.key_map()["new_file"]),
[this]() { [this]() {
OnFileNewFile(); OnFileNewFile();
}); });
keybindings.action_group_menu()-> keybindings->action_group_menu->
add(Gtk::Action::create("WindowCloseTab", add(Gtk::Action::create("WindowCloseTab",
"Close tab"), "Close tab"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["close_tab"]),
.key_map()["close_tab"]),
[this]() { [this]() {
OnCloseCurrentPage(); OnCloseCurrentPage();
}); });
keybindings.action_group_menu()-> keybindings->action_group_menu->
add(Gtk::Action::create("EditFind", add(Gtk::Action::create("EditFind",
"Find"), "Find"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["edit_find"]),
.key_map()["edit_find"]),
[this]() { [this]() {
entry.show_search(""); entry.show_search("");
}); });
keybindings.action_group_menu()-> keybindings->action_group_menu->
add(Gtk::Action::create("EditCopy", add(Gtk::Action::create("EditCopy",
"Copy"), "Copy"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["edit_copy"]),
.key_map()["edit_copy"]),
[this]() { [this]() {
if (Pages() != 0) { 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", add(Gtk::Action::create("EditCut",
"Cut"), "Cut"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["edit_cut"]),
.key_map()["edit_cut"]),
[this]() { [this]() {
if (Pages() != 0) { 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", add(Gtk::Action::create("EditPaste",
"Paste"), "Paste"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["edit_paste"]),
.key_map()["edit_paste"]),
[this]() { [this]() {
if (Pages() != 0) { 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", add(Gtk::Action::create("EditUndo",
"Undo"), "Undo"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["edit_undo"]),
.key_map()["edit_undo"]),
[this]() { [this]() {
INFO("On undo"); INFO("On undo");
Glib::RefPtr<Gsv::UndoManager> undo_manager = Glib::RefPtr<Gsv::UndoManager> undo_manager =
CurrentTextView().get_source_buffer()->get_undo_manager(); CurrentSourceView()->get_source_buffer()->get_undo_manager();
if (Pages() != 0 && undo_manager->can_undo()) { if (Pages() != 0 && undo_manager->can_undo()) {
undo_manager->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", add(Gtk::Action::create("EditRedo",
"Redo"), "Redo"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg->key_map["edit_redo"]),
.key_map()["edit_redo"]),
[this]() { [this]() {
INFO("On Redo"); INFO("On Redo");
Glib::RefPtr<Gsv::UndoManager> undo_manager = Glib::RefPtr<Gsv::UndoManager> undo_manager =
CurrentTextView().get_source_buffer()->get_undo_manager(); CurrentSourceView()->get_source_buffer()->get_undo_manager();
if (Pages() != 0 && undo_manager->can_redo()) { if (Pages() != 0 && undo_manager->can_redo()) {
undo_manager->redo(); undo_manager->redo();
} }
@ -162,56 +153,42 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
INFO("Notebook signal handlers sucsess"); 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) { void Notebook::Controller::OnOpenFile(std::string path) {
INFO("Notebook open file"); INFO("Notebook open file");
INFO("Notebook create page"); INFO("Notebook create page");
text_vec_.emplace_back(new Source::Controller(path, project_path, terminal)); source_views.emplace_back(new Source(path, project_path));
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow()); scrolled_windows.emplace_back(new Gtk::ScrolledWindow());
editor_vec_.push_back(new Gtk::HBox()); hboxes.emplace_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(*text_vec_.back()->view); scrolled_windows.back()->add(*source_views.back()->view);
editor_vec_.back()->pack_start(*scrolledtext_vec_.back(), true, true); hboxes.back()->pack_start(*scrolled_windows.back(), true, true);
size_t pos = path.find_last_of("/\\"); // TODO #windows boost::filesystem::path file_path(source_views.back()->view->file_path);
std::string filename=path; std::string title=file_path.filename().string();
if(pos!=std::string::npos) view.notebook.append_page(*hboxes.back(), title);
filename=path.substr(pos+1); view.notebook.show_all_children();
Notebook().append_page(*editor_vec_.back(), filename); view.notebook.set_current_page(Pages()-1);
Notebook().show_all_children(); view.notebook.set_focus_child(*source_views.back()->view);
Notebook().set_current_page(Pages()-1); CurrentSourceView()->get_buffer()->set_modified(false);
Notebook().set_focus_child(*text_vec_.back()->view);
//Add star on tab label when the page is not saved: //Add star on tab label when the page is not saved:
//TODO: instead use Gtk::TextBuffer::set_modified and Gtk::TextBuffer::get_modified CurrentSourceView()->get_buffer()->signal_modified_changed().connect([this]() {
text_vec_.back()->buffer()->signal_changed().connect([this]() { boost::filesystem::path file_path(CurrentSourceView()->file_path);
if(text_vec_.at(CurrentPage())->is_saved) { std::string title=file_path.filename().string();
std::string path=CurrentTextView().file_path; if(CurrentSourceView()->get_buffer()->get_modified())
size_t pos = path.find_last_of("/\\"); title+="*";
std::string filename=path; view.notebook.set_tab_label_text(*(view.notebook.get_nth_page(CurrentPage())), title);
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;
}); });
} }
void Notebook::Controller::OnCloseCurrentPage() { void Notebook::Controller::OnCloseCurrentPage() {
INFO("Notebook close page"); INFO("Notebook close page");
if (Pages() != 0) { if (Pages() != 0) {
if(!text_vec_.at(CurrentPage())->is_saved){ if(CurrentSourceView()->get_buffer()->get_modified()){
AskToSaveDialog(); AskToSaveDialog();
} }
int page = CurrentPage(); int page = CurrentPage();
Notebook().remove_page(page); view.notebook.remove_page(page);
delete scrolledtext_vec_.at(page); source_views.erase(source_views.begin()+ page);
delete editor_vec_.at(page); scrolled_windows.erase(scrolled_windows.begin()+page);
text_vec_.erase(text_vec_.begin()+ page); hboxes.erase(hboxes.begin()+page);
scrolledtext_vec_.erase(scrolledtext_vec_.begin()+page);
editor_vec_.erase(editor_vec_.begin()+page);
} }
} }
void Notebook::Controller::OnFileNewFile() { void Notebook::Controller::OnFileNewFile() {
@ -220,10 +197,10 @@ void Notebook::Controller::OnFileNewFile() {
void Notebook::Controller::search(bool forward) { void Notebook::Controller::search(bool forward) {
INFO("Notebook search"); INFO("Notebook search");
auto start = CurrentTextView().search_start; auto start = CurrentSourceView()->search_start;
auto end = CurrentTextView().search_end; auto end = CurrentSourceView()->search_end;
// fetch buffer and greate settings // fetch buffer and greate settings
auto buffer = CurrentTextView().get_source_buffer(); auto buffer = CurrentSourceView()->get_source_buffer();
auto settings = gtk_source_search_settings_new(); auto settings = gtk_source_search_settings_new();
// get search text from entry // get search text from entry
gtk_source_search_settings_set_search_text(settings, entry().c_str()); gtk_source_search_settings_set_search_text(settings, entry().c_str());
@ -247,9 +224,9 @@ void Notebook::Controller::search(bool forward) {
end.gobj()); end.gobj());
} }
buffer->apply_tag_by_name("search", start, end); buffer->apply_tag_by_name("search", start, end);
CurrentTextView().scroll_to(end); CurrentSourceView()->scroll_to(end);
CurrentTextView().search_start = start; CurrentSourceView()->search_start = start;
CurrentTextView().search_end = end; CurrentSourceView()->search_end = end;
} }
void Notebook::Controller void Notebook::Controller
@ -274,40 +251,34 @@ void Notebook::Controller
} }
} }
Source::View& Notebook::Controller::CurrentTextView() { Source::View* Notebook::Controller::CurrentSourceView() {
INFO("Getting sourceview"); INFO("Getting sourceview");
return *text_vec_.at(CurrentPage())->view; return source_views.at(CurrentPage())->view.get();
} }
int Notebook::Controller::CurrentPage() { int Notebook::Controller::CurrentPage() {
return Notebook().get_current_page(); return view.notebook.get_current_page();
} }
int Notebook::Controller::Pages() { int Notebook::Controller::Pages() {
return Notebook().get_n_pages(); return view.notebook.get_n_pages();
}
Gtk::Notebook& Notebook::Controller::Notebook() {
return view.notebook;
} }
bool Notebook::Controller:: OnSaveFile() { bool Notebook::Controller:: OnSaveFile() {
std::string path=CurrentTextView().file_path; std::string path=CurrentSourceView()->file_path;
return OnSaveFile(path); return OnSaveFile(path);
} }
bool Notebook::Controller:: OnSaveFile(std::string path) { bool Notebook::Controller:: OnSaveFile(std::string path) {
INFO("Notebook save file with path"); INFO("Notebook save file with path");
if (path != "") { if (path != "" && CurrentSourceView()->get_buffer()->get_modified()) {
std::ofstream file; std::ofstream file;
file.open (path); file.open (path);
file << CurrentTextView().get_buffer()->get_text(); file << CurrentSourceView()->get_buffer()->get_text();
file.close(); file.close();
CurrentTextView().file_path=path; boost::filesystem::path path(CurrentSourceView()->file_path);
size_t pos = path.find_last_of("/\\"); std::string title=path.filename().string();
std::string filename=path; view.notebook.set_tab_label_text(*view.notebook.get_nth_page(CurrentPage()), title);
if(pos!=std::string::npos) CurrentSourceView()->get_buffer()->set_modified(false);
filename=path.substr(pos+1);
Notebook().set_tab_label_text(*Notebook().get_nth_page(CurrentPage()), filename);
text_vec_.at(CurrentPage())->is_saved=true;
return true; return true;
} }
return false; return false;
@ -350,7 +321,7 @@ void Notebook::Controller::AskToSaveDialog() {
false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
dialog.set_secondary_text( dialog.set_secondary_text(
"Do you want to save: " + "Do you want to save: " +
CurrentTextView().file_path+" ?"); CurrentSourceView()->file_path+" ?");
DEBUG("AskToSaveDialog: run dialog"); DEBUG("AskToSaveDialog: run dialog");
int result = dialog.run(); int result = dialog.run();

24
juci/notebook.h

@ -11,8 +11,6 @@
#include <map> #include <map>
#include <sigc++/sigc++.h> #include <sigc++/sigc++.h>
#include "clangmm.h" #include "clangmm.h"
#include "keybindings.h"
#include "terminal.h"
namespace Notebook { namespace Notebook {
class View : public Gtk::Paned { class View : public Gtk::Paned {
@ -22,13 +20,9 @@ namespace Notebook {
}; };
class Controller { class Controller {
public: public:
Controller(Keybindings::Controller& keybindings, Controller();
Terminal::Controller& terminal, Source::View* CurrentSourceView();
Directories::Config& dir_cfg);
~Controller();
Source::View& CurrentTextView();
int CurrentPage(); int CurrentPage();
Gtk::Notebook& Notebook();
void OnCloseCurrentPage(); void OnCloseCurrentPage();
void OnFileNewFile(); void OnFileNewFile();
bool OnSaveFile(); bool OnSaveFile();
@ -43,18 +37,14 @@ namespace Notebook {
std::string project_path; std::string project_path;
Directories::Controller directories; //Todo: make private after creating open_directory() Directories::Controller directories; //Todo: make private after creating open_directory()
Entry entry; Entry entry;
std::vector<std::unique_ptr<Source::Controller> > text_vec_; std::vector<std::unique_ptr<Source> > source_views;
private: private:
void CreateKeybindings(Keybindings::Controller& keybindings); void CreateKeybindings();
void AskToSaveDialog(); void AskToSaveDialog();
Glib::RefPtr<Gtk::Builder> m_refBuilder;
Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup;
Terminal::Controller& terminal;
std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_; std::vector<std::unique_ptr<Gtk::ScrolledWindow> > scrolled_windows;
std::vector<Gtk::HBox*> editor_vec_; std::vector<std::unique_ptr<Gtk::HBox> > hboxes;
std::list<Gtk::TargetEntry> listTargets_; Glib::RefPtr<Gtk::Clipboard> clipboard;
Glib::RefPtr<Gtk::Clipboard> refClipboard_;
}; // class controller }; // class controller
} // namespace Notebook } // namespace Notebook
#endif // JUCI_NOTEBOOK_H_ #endif // JUCI_NOTEBOOK_H_

30
juci/singletons.cc

@ -1,3 +1,31 @@
#include "singletons.h" #include "singletons.h"
std::unique_ptr<Source::Config> Singletons::Config::source_=std::unique_ptr<Source::Config>(new Source::Config()); std::unique_ptr<Source::Config> Singleton::Config::source_=std::unique_ptr<Source::Config>(new Source::Config());
std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config());
std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique_ptr<Directories::Config>(new Directories::Config());
std::unique_ptr<Keybindings::Config> Singleton::Config::keybindings_=std::unique_ptr<Keybindings::Config>(new Keybindings::Config());
std::unique_ptr<Terminal::Controller> Singleton::terminal_=std::unique_ptr<Terminal::Controller>();
std::unique_ptr<Keybindings> Singleton::keybindings_=std::unique_ptr<Keybindings>();
std::unique_ptr<Notebook::Controller> Singleton::notebook_=std::unique_ptr<Notebook::Controller>();
std::unique_ptr<Menu::Controller> Singleton::menu_=std::unique_ptr<Menu::Controller>();
Terminal::Controller *Singleton::terminal() {
if(!terminal_)
terminal_=std::unique_ptr<Terminal::Controller>(new Terminal::Controller());
return terminal_.get();
}
Keybindings *Singleton::keybindings() {
if(!keybindings_)
keybindings_=std::unique_ptr<Keybindings>(new Keybindings());
return keybindings_.get();
}
Notebook::Controller *Singleton::notebook() {
if(!notebook_)
notebook_=std::unique_ptr<Notebook::Controller>(new Notebook::Controller());
return notebook_.get();
}
Menu::Controller *Singleton::menu() {
if(!menu_)
menu_=std::unique_ptr<Menu::Controller>(new Menu::Controller());
return menu_.get();
}

27
juci/singletons.h

@ -5,16 +5,33 @@
#include "source.h" #include "source.h"
#include "directories.h" #include "directories.h"
#include "terminal.h" #include "terminal.h"
#include "notebook.h"
#include "menu.h"
namespace Singletons { class Singleton {
public:
class Config { class Config {
public: public:
static Source::Config *source() { static Source::Config *source() {return source_.get();}
return source_.get(); static Terminal::Config *terminal() {return terminal_.get();}
} static Directories::Config *directories() {return directories_.get();}
static Keybindings::Config *keybindings() {return keybindings_.get();}
private: private:
static std::unique_ptr<Source::Config> source_; static std::unique_ptr<Source::Config> source_;
static std::unique_ptr<Terminal::Config> terminal_;
static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Keybindings::Config> keybindings_;
}; };
}
static Terminal::Controller *terminal();
static Keybindings *keybindings();
static Notebook::Controller *notebook();
static Menu::Controller *menu();
private:
static std::unique_ptr<Terminal::Controller> terminal_;
static std::unique_ptr<Keybindings> keybindings_;
static std::unique_ptr<Notebook::Controller> notebook_;
static std::unique_ptr<Menu::Controller> menu_;
};
#endif // JUCI_SINGLETONS_H_ #endif // JUCI_SINGLETONS_H_

186
juci/source.cc

@ -29,19 +29,19 @@ Source::View::View(const std::string& file_path, const std::string& project_path
file_path(file_path), project_path(project_path) { file_path(file_path), project_path(project_path) {
Gsv::init(); Gsv::init();
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
set_show_line_numbers(Singletons::Config::source()->show_line_numbers); set_show_line_numbers(Singleton::Config::source()->show_line_numbers);
set_highlight_current_line(Singletons::Config::source()->highlight_current_line); set_highlight_current_line(Singleton::Config::source()->highlight_current_line);
sourcefile s(file_path); sourcefile s(file_path);
get_source_buffer()->get_undo_manager()->begin_not_undoable_action(); get_source_buffer()->get_undo_manager()->begin_not_undoable_action();
get_source_buffer()->set_text(s.get_content()); get_source_buffer()->set_text(s.get_content());
get_source_buffer()->get_undo_manager()->end_not_undoable_action(); get_source_buffer()->get_undo_manager()->end_not_undoable_action();
search_start = search_end = this->get_buffer()->end(); search_start = search_end = this->get_buffer()->end();
override_font(Pango::FontDescription(Singletons::Config::source()->font)); override_font(Pango::FontDescription(Singleton::Config::source()->font));
override_background_color(Gdk::RGBA(Singletons::Config::source()->background)); override_background_color(Gdk::RGBA(Singleton::Config::source()->background));
override_background_color(Gdk::RGBA(Singletons::Config::source()->background_selected), Gtk::StateFlags::STATE_FLAG_SELECTED); override_background_color(Gdk::RGBA(Singleton::Config::source()->background_selected), Gtk::StateFlags::STATE_FLAG_SELECTED);
for (auto &item : Singletons::Config::source()->tags) { for (auto &item : Singleton::Config::source()->tags) {
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; get_source_buffer()->create_tag(item.first)->property_foreground() = item.second;
} }
} }
@ -64,7 +64,7 @@ string Source::View::get_line_before_insert() {
//Basic indentation //Basic indentation
bool Source::View::on_key_press_event(GdkEventKey* key) { bool Source::View::on_key_press_event(GdkEventKey* key) {
auto config=Singletons::Config::source(); auto config=Singleton::Config::source();
const std::regex spaces_regex(std::string("^(")+config->tab_char+"*).*$"); const std::regex spaces_regex(std::string("^(")+config->tab_char+"*).*$");
//Indent as in next or previous line //Indent as in next or previous line
if(key->keyval==GDK_KEY_Return && key->state==0) { if(key->keyval==GDK_KEY_Return && key->state==0) {
@ -142,17 +142,14 @@ bool Source::View::on_key_press_event(GdkEventKey* key) {
return Gsv::View::on_key_press_event(key); return Gsv::View::on_key_press_event(key);
} }
////////////////// /////////////////////////
//// ClangView /// //// ClangViewParse ///
////////////////// /////////////////////////
clang::Index Source::ClangView::clang_index(0, 0); clang::Index Source::ClangViewParse::clang_index(0, 0);
Source::ClangView::ClangView(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal): Source::ClangViewParse::ClangViewParse(const std::string& file_path, const std::string& project_path):
Source::View(file_path, project_path), terminal(terminal), Source::View(file_path, project_path),
parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) { parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
similar_tokens_tag=get_buffer()->create_tag();
similar_tokens_tag->property_weight()=Pango::WEIGHT_BOLD;
int start_offset = get_source_buffer()->begin().get_offset(); int start_offset = get_source_buffer()->begin().get_offset();
int end_offset = get_source_buffer()->end().get_offset(); int end_offset = get_source_buffer()->end().get_offset();
auto buffer_map=get_buffer_map(); auto buffer_map=get_buffer_map();
@ -185,7 +182,7 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
parse_thread_go=true; parse_thread_go=true;
}); });
parsing_in_progress=this->terminal.print_in_progress("Parsing "+file_path); parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path);
parse_done.connect([this](){ parse_done.connect([this](){
if(parse_thread_mapped) { if(parse_thread_mapped) {
if(parsing_mutex.try_lock()) { if(parsing_mutex.try_lock()) {
@ -228,16 +225,12 @@ parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
start_reparse(); start_reparse();
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
if(last_similar_tokens_tagged!="") {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
last_similar_tokens_tagged="";
}
}); });
get_buffer()->signal_mark_set().connect(sigc::mem_fun(*this, &Source::ClangView::on_mark_set), false); get_buffer()->signal_mark_set().connect(sigc::mem_fun(*this, &Source::ClangViewParse::on_mark_set), false);
} }
Source::ClangView::~ClangView() { Source::ClangViewParse::~ClangViewParse() {
//TODO: Is it possible to stop the clang-process in progress? //TODO: Is it possible to stop the clang-process in progress?
parsing_in_progress->cancel("canceled"); parsing_in_progress->cancel("canceled");
parse_thread_stop=true; parse_thread_stop=true;
@ -247,7 +240,7 @@ Source::ClangView::~ClangView() {
parsing_mutex.unlock(); parsing_mutex.unlock();
} }
void Source::ClangView:: void Source::ClangViewParse::
init_syntax_highlighting(const std::map<std::string, std::string> init_syntax_highlighting(const std::map<std::string, std::string>
&buffers, &buffers,
int start_offset, int start_offset,
@ -260,13 +253,13 @@ init_syntax_highlighting(const std::map<std::string, std::string>
clang_tokens=clang_tu->get_tokens(0, buffers.find(file_path)->second.size()-1); clang_tokens=clang_tu->get_tokens(0, buffers.find(file_path)->second.size()-1);
} }
std::map<std::string, std::string> Source::ClangView::get_buffer_map() const { std::map<std::string, std::string> Source::ClangViewParse::get_buffer_map() const {
std::map<std::string, std::string> buffer_map; std::map<std::string, std::string> buffer_map;
buffer_map[file_path]=get_source_buffer()->get_text().raw(); buffer_map[file_path]=get_source_buffer()->get_text().raw();
return buffer_map; return buffer_map;
} }
void Source::ClangView::start_reparse() { void Source::ClangViewParse::start_reparse() {
parse_thread_mapped=false; parse_thread_mapped=false;
clang_readable=false; clang_readable=false;
delayed_reparse_connection.disconnect(); delayed_reparse_connection.disconnect();
@ -276,14 +269,13 @@ void Source::ClangView::start_reparse() {
}, 1000); }, 1000);
} }
int Source::ClangView::reparse(const std::map<std::string, std::string> &buffer) { int Source::ClangViewParse::reparse(const std::map<std::string, std::string> &buffer) {
int status = clang_tu->ReparseTranslationUnit(buffer); int status = clang_tu->ReparseTranslationUnit(buffer);
clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path)->second.size()-1); clang_tokens=clang_tu->get_tokens(0, parse_thread_buffer_map.find(file_path)->second.size()-1);
return status; return status;
} }
std::vector<std::string> Source::ClangView:: std::vector<std::string> Source::ClangViewParse::get_compilation_commands() {
get_compilation_commands() {
clang::CompilationDatabase db(project_path); clang::CompilationDatabase db(project_path);
clang::CompileCommands commands(file_path, db); clang::CompileCommands commands(file_path, db);
std::vector<clang::CompileCommand> cmds = commands.get_commands(); std::vector<clang::CompileCommand> cmds = commands.get_commands();
@ -299,7 +291,7 @@ get_compilation_commands() {
return arguments; return arguments;
} }
void Source::ClangView::update_syntax() { void Source::ClangViewParse::update_syntax() {
std::vector<Source::Range> ranges; std::vector<Source::Range> ranges;
for (auto &token : *clang_tokens) { for (auto &token : *clang_tokens) {
if(token.get_kind()==0) // PunctuationToken if(token.get_kind()==0) // PunctuationToken
@ -321,19 +313,19 @@ void Source::ClangView::update_syntax() {
for (auto &range : ranges) { for (auto &range : ranges) {
std::string type = std::to_string(range.kind); std::string type = std::to_string(range.kind);
try { try {
Singletons::Config::source()->types.at(type); Singleton::Config::source()->types.at(type);
} catch (std::exception) { } catch (std::exception) {
continue; continue;
} }
Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset); Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset);
Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset); Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset);
buffer->apply_tag_by_name(Singletons::Config::source()->types.at(type), buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type),
begin_iter, end_iter); begin_iter, end_iter);
} }
} }
void Source::ClangView::update_diagnostics() { void Source::ClangViewParse::update_diagnostics() {
diagnostic_tooltips.clear(); diagnostic_tooltips.clear();
auto diagnostics=clang_tu->get_diagnostics(); auto diagnostics=clang_tu->get_diagnostics();
for(auto &diagnostic: diagnostics) { for(auto &diagnostic: diagnostics) {
@ -371,7 +363,7 @@ void Source::ClangView::update_diagnostics() {
} }
} }
void Source::ClangView::update_types() { void Source::ClangViewParse::update_types() {
type_tooltips.clear(); type_tooltips.clear();
for(auto &token: *clang_tokens) { for(auto &token: *clang_tokens) {
if(token.has_type()) { if(token.has_type()) {
@ -391,7 +383,7 @@ void Source::ClangView::update_types() {
} }
} }
bool Source::ClangView::on_motion_notify_event(GdkEventMotion* event) { bool Source::ClangViewParse::on_motion_notify_event(GdkEventMotion* event) {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
if(clang_readable) { if(clang_readable) {
Gdk::Rectangle rectangle(event->x, event->y, 1, 1); Gdk::Rectangle rectangle(event->x, event->y, 1, 1);
@ -407,7 +399,7 @@ bool Source::ClangView::on_motion_notify_event(GdkEventMotion* event) {
return Source::View::on_motion_notify_event(event); return Source::View::on_motion_notify_event(event);
} }
void Source::ClangView::on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark) { void Source::ClangViewParse::on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark) {
if(get_buffer()->get_has_selection() && mark->get_name()=="selection_bound") if(get_buffer()->get_has_selection() && mark->get_name()=="selection_bound")
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
@ -430,46 +422,17 @@ void Source::ClangView::on_mark_set(const Gtk::TextBuffer::iterator& iterator, c
}, 500); }, 500);
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
bool found=false;
if(clang_readable) {
for(auto &token: *clang_tokens) {
if(token.has_type()) {
auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset();
if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) {
found=true;
auto referenced=token.get_cursor().get_referenced();
if(referenced) {
auto usr_and_spelling=referenced.get_usr()+token.get_spelling();
if(last_similar_tokens_tagged!=usr_and_spelling) {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
auto offsets=clang_tokens->get_similar_token_offsets(token);
for(auto &offset: offsets) {
get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_offset(offset.first), get_buffer()->get_iter_at_offset(offset.second));
}
last_similar_tokens_tagged=usr_and_spelling;
break;
}
}
}
}
}
}
if(!found && last_similar_tokens_tagged!="") {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
last_similar_tokens_tagged="";
}
} }
} }
bool Source::ClangView::on_focus_out_event(GdkEventFocus* event) { bool Source::ClangViewParse::on_focus_out_event(GdkEventFocus* event) {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
return Source::View::on_focus_out_event(event); return Source::View::on_focus_out_event(event);
} }
bool Source::ClangView::on_scroll_event(GdkEventScroll* event) { bool Source::ClangViewParse::on_scroll_event(GdkEventScroll* event) {
delayed_tooltips_connection.disconnect(); delayed_tooltips_connection.disconnect();
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
@ -478,8 +441,8 @@ bool Source::ClangView::on_scroll_event(GdkEventScroll* event) {
//Clang indentation //Clang indentation
//TODO: replace indentation methods with a better implementation or maybe use libclang //TODO: replace indentation methods with a better implementation or maybe use libclang
bool Source::ClangView::on_key_press_event(GdkEventKey* key) { bool Source::ClangViewParse::on_key_press_event(GdkEventKey* key) {
auto config=Singletons::Config::source(); auto config=Singleton::Config::source();
const std::regex bracket_regex(std::string("^(")+config->tab_char+"*).*\\{ *$"); const std::regex bracket_regex(std::string("^(")+config->tab_char+"*).*\\{ *$");
const std::regex no_bracket_statement_regex(std::string("^(")+config->tab_char+"*)(if|for|else if|catch|while) *\\(.*[^;}] *$"); const std::regex no_bracket_statement_regex(std::string("^(")+config->tab_char+"*)(if|for|else if|catch|while) *\\(.*[^;}] *$");
const std::regex no_bracket_no_para_statement_regex(std::string("^(")+config->tab_char+"*)(else|try|do) *$"); const std::regex no_bracket_no_para_statement_regex(std::string("^(")+config->tab_char+"*)(else|try|do) *$");
@ -566,8 +529,8 @@ bool Source::ClangView::on_key_press_event(GdkEventKey* key) {
////////////////////////////// //////////////////////////////
//// ClangViewAutocomplete /// //// ClangViewAutocomplete ///
////////////////////////////// //////////////////////////////
Source::ClangViewAutocomplete::ClangViewAutocomplete(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal): Source::ClangViewAutocomplete::ClangViewAutocomplete(const std::string& file_path, const std::string& project_path):
Source::ClangView(file_path, project_path, terminal), selection_dialog(*this), autocomplete_cancel_starting(false) { Source::ClangViewParse(file_path, project_path), selection_dialog(*this), autocomplete_cancel_starting(false) {
selection_dialog.on_hide=[this](){ selection_dialog.on_hide=[this](){
start_reparse(); start_reparse();
}; };
@ -606,7 +569,7 @@ bool Source::ClangViewAutocomplete::on_key_press_event(GdkEventKey *key) {
if(selection_dialog.on_key_press(key)) if(selection_dialog.on_key_press(key))
return true; return true;
} }
return ClangView::on_key_press_event(key); return ClangViewParse::on_key_press_event(key);
} }
bool Source::ClangViewAutocomplete::on_focus_out_event(GdkEventFocus* event) { bool Source::ClangViewAutocomplete::on_focus_out_event(GdkEventFocus* event) {
@ -614,13 +577,13 @@ bool Source::ClangViewAutocomplete::on_focus_out_event(GdkEventFocus* event) {
selection_dialog.hide(); selection_dialog.hide();
} }
return Source::ClangView::on_focus_out_event(event); return Source::ClangViewParse::on_focus_out_event(event);
} }
void Source::ClangViewAutocomplete::start_autocomplete() { void Source::ClangViewAutocomplete::start_autocomplete() {
const std::regex autocomplete_keys("[a-zA-Z0-9_>\\.:]"); if(!((last_keyval>='0' && last_keyval<='9') ||
std::smatch sm; (last_keyval>='a' && last_keyval<='z') || (last_keyval>='A' && last_keyval<='Z') ||
if(!std::regex_match(std::string()+(char)last_keyval, sm, autocomplete_keys)) { last_keyval=='_' || last_keyval=='>' || last_keyval=='.' || last_keyval==':')) {
autocomplete_cancel_starting=true; autocomplete_cancel_starting=true;
return; return;
} }
@ -628,6 +591,7 @@ void Source::ClangViewAutocomplete::start_autocomplete() {
if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) { if((std::count(line.begin(), line.end(), '\"')%2)!=1 && line.find("//")==std::string::npos) {
const std::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)])(->|\\.|::)([a-zA-Z0-9_]*)$"); const std::regex in_specified_namespace("^(.*[a-zA-Z0-9_\\)])(->|\\.|::)([a-zA-Z0-9_]*)$");
const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$"); const std::regex within_namespace("^(.*)([^a-zA-Z0-9_]+)([a-zA-Z0-9_]{3,})$");
std::smatch sm;
if(std::regex_match(line, sm, in_specified_namespace)) { if(std::regex_match(line, sm, in_specified_namespace)) {
prefix_mutex.lock(); prefix_mutex.lock();
prefix=sm[3].str(); prefix=sm[3].str();
@ -730,7 +694,7 @@ get_autocomplete_suggestions(int line_number, int column, std::map<std::string,
prefix_mutex.lock(); prefix_mutex.lock();
auto prefix_copy=prefix; auto prefix_copy=prefix;
prefix_mutex.unlock(); prefix_mutex.unlock();
for (int i = 0; i < results.size(); i++) { for (unsigned i = 0; i < results.size(); i++) {
auto result=results.get(i); auto result=results.get(i);
if(result.available()) { if(result.available()) {
auto chunks=result.get_chunks(); auto chunks=result.get_chunks();
@ -754,23 +718,67 @@ get_autocomplete_suggestions(int line_number, int column, std::map<std::string,
return suggestions; return suggestions;
} }
//////////////////// ////////////////////////////
//// Controller //// //// ClangViewRefactor /////
//////////////////// ////////////////////////////
// Source::Controller::Controller() Source::ClangViewRefactor::ClangViewRefactor(const std::string& file_path, const std::string& project_path):
// Constructor for Controller Source::ClangViewAutocomplete(file_path, project_path) {
Source::Controller::Controller(const std::string& file_path, std::string project_path, Terminal::Controller& terminal) { similar_tokens_tag=get_buffer()->create_tag();
similar_tokens_tag->property_weight()=Pango::WEIGHT_BOLD;
get_buffer()->signal_changed().connect([this]() {
if(last_similar_tokens_tagged!="") {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
last_similar_tokens_tagged="";
}
});
get_buffer()->signal_mark_set().connect([this](const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark){
if(mark->get_name()=="insert") {
bool found=false;
if(clang_readable) {
for(auto &token: *clang_tokens) {
if(token.has_type()) {
auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset();
if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) {
found=true;
auto referenced=token.get_cursor().get_referenced();
if(referenced) {
auto usr_and_spelling=referenced.get_usr()+token.get_spelling();
if(last_similar_tokens_tagged!=usr_and_spelling) {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
auto offsets=clang_tokens->get_similar_token_offsets(token);
for(auto &offset: offsets) {
get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_offset(offset.first), get_buffer()->get_iter_at_offset(offset.second));
}
last_similar_tokens_tagged=usr_and_spelling;
break;
}
}
}
}
}
}
if(!found && last_similar_tokens_tagged!="") {
get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end());
last_similar_tokens_tagged="";
}
}
});
}
////////////////
//// Source ////
////////////////
Source::Source(const std::string& file_path, std::string project_path) {
if(project_path=="") { if(project_path=="") {
project_path=boost::filesystem::path(file_path).parent_path().string(); project_path=boost::filesystem::path(file_path).parent_path().string();
} }
if (Singletons::Config::source()->legal_extension(file_path.substr(file_path.find_last_of(".") + 1))) if (Singleton::Config::source()->legal_extension(file_path.substr(file_path.find_last_of(".") + 1)))
view=std::unique_ptr<View>(new ClangViewAutocomplete(file_path, project_path, terminal)); view=std::unique_ptr<View>(new ClangView(file_path, project_path));
else else
view=std::unique_ptr<View>(new GenericView(file_path, project_path)); view=std::unique_ptr<View>(new GenericView(file_path, project_path));
INFO("Source Controller with childs constructed"); INFO("Source Controller with childs constructed");
} }
Glib::RefPtr<Gsv::Buffer> Source::Controller::buffer() {
return view->get_source_buffer();
}

46
juci/source.h

@ -14,7 +14,8 @@
#include "tooltips.h" #include "tooltips.h"
#include "selectiondialog.h" #include "selectiondialog.h"
namespace Source { class Source {
public:
class Config { class Config {
public: public:
bool legal_extension(std::string e) const ; bool legal_extension(std::string e) const ;
@ -59,25 +60,23 @@ namespace Source {
public: public:
GenericView(const std::string& file_path, const std::string& project_path): GenericView(const std::string& file_path, const std::string& project_path):
View(file_path, project_path) {} View(file_path, project_path) {}
protected:
bool on_key_press_event(GdkEventKey* key) {
return Source::View::on_key_press_event(key);
}
}; };
class ClangView : public View { class ClangViewParse : public View {
public: public:
ClangView(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal); ClangViewParse(const std::string& file_path, const std::string& project_path);
~ClangView(); ~ClangViewParse();
protected: protected:
void start_reparse(); void start_reparse();
bool on_key_press_event(GdkEventKey* key); bool on_key_press_event(GdkEventKey* key);
bool on_focus_out_event(GdkEventFocus* event); bool on_focus_out_event(GdkEventFocus* event);
std::unique_ptr<clang::TranslationUnit> clang_tu; std::unique_ptr<clang::TranslationUnit> clang_tu;
std::map<std::string, std::string> get_buffer_map() const;
std::mutex parsing_mutex; std::mutex parsing_mutex;
std::unique_ptr<clang::Tokens> clang_tokens;
bool clang_readable=false;
sigc::connection delayed_reparse_connection; sigc::connection delayed_reparse_connection;
private: private:
std::map<std::string, std::string> get_buffer_map() const;
// inits the syntax highligthing on file open // inits the syntax highligthing on file open
void init_syntax_highlighting(const std::map<std::string, std::string> void init_syntax_highlighting(const std::map<std::string, std::string>
&buffers, &buffers,
@ -92,15 +91,10 @@ namespace Source {
bool on_motion_notify_event(GdkEventMotion* event); bool on_motion_notify_event(GdkEventMotion* event);
void on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark); void on_mark_set(const Gtk::TextBuffer::iterator& iterator, const Glib::RefPtr<Gtk::TextBuffer::Mark>& mark);
sigc::connection delayed_tooltips_connection; sigc::connection delayed_tooltips_connection;
Glib::RefPtr<Gtk::TextTag> similar_tokens_tag;
std::string last_similar_tokens_tagged;
bool on_scroll_event(GdkEventScroll* event); bool on_scroll_event(GdkEventScroll* event);
static clang::Index clang_index; static clang::Index clang_index;
std::unique_ptr<clang::Tokens> clang_tokens;
bool clang_readable=false;
std::vector<std::string> get_compilation_commands(); std::vector<std::string> get_compilation_commands();
Terminal::Controller& terminal;
std::shared_ptr<Terminal::InProgress> parsing_in_progress; std::shared_ptr<Terminal::InProgress> parsing_in_progress;
Glib::Dispatcher parse_done; Glib::Dispatcher parse_done;
@ -113,9 +107,9 @@ namespace Source {
std::atomic<bool> parse_thread_stop; std::atomic<bool> parse_thread_stop;
}; };
class ClangViewAutocomplete : public ClangView { class ClangViewAutocomplete : public ClangViewParse {
public: public:
ClangViewAutocomplete(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal); ClangViewAutocomplete(const std::string& file_path, const std::string& project_path);
protected: protected:
bool on_key_press_event(GdkEventKey* key); bool on_key_press_event(GdkEventKey* key);
bool on_focus_out_event(GdkEventFocus* event); bool on_focus_out_event(GdkEventFocus* event);
@ -133,14 +127,22 @@ namespace Source {
std::mutex prefix_mutex; std::mutex prefix_mutex;
}; };
class Controller { class ClangViewRefactor : public ClangViewAutocomplete {
public:
ClangViewRefactor(const std::string& file_path, const std::string& project_path);
private:
Glib::RefPtr<Gtk::TextTag> similar_tokens_tag;
std::string last_similar_tokens_tagged;
};
class ClangView : public ClangViewRefactor {
public: public:
Controller(const std::string& file_path, std::string project_path, Terminal::Controller& terminal); ClangView(const std::string& file_path, const std::string& project_path):
Glib::RefPtr<Gsv::Buffer> buffer(); ClangViewRefactor(file_path, project_path) {}
};
bool is_saved = true; Source(const std::string& file_path, std::string project_path);
std::unique_ptr<Source::View> view; std::unique_ptr<Source::View> view;
}; // class Controller }; // class Source
} // namespace Source
#endif // JUCI_SOURCE_H_ #endif // JUCI_SOURCE_H_

20
juci/terminal.cc

@ -1,10 +1,11 @@
#include "terminal.h" #include "terminal.h"
#include <iostream> #include <iostream>
#include "logging.h" #include "logging.h"
#include "singletons.h"
Terminal::InProgress::InProgress(Controller& terminal, const std::string& start_msg): terminal(terminal), stop(false) { Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
waiting_print.connect([this](){ waiting_print.connect([this](){
this->terminal.print(line_nr-1, "."); Singleton::terminal()->print(line_nr-1, ".");
}); });
start(start_msg); start(start_msg);
} }
@ -16,7 +17,7 @@ Terminal::InProgress::~InProgress() {
} }
void Terminal::InProgress::start(const std::string& msg) { void Terminal::InProgress::start(const std::string& msg) {
line_nr=this->terminal.print(msg+"...\n"); line_nr=Singleton::terminal()->print(msg+"...\n");
wait_thread=std::thread([this](){ wait_thread=std::thread([this](){
size_t c=0; size_t c=0;
while(!stop) { while(!stop) {
@ -31,14 +32,14 @@ void Terminal::InProgress::start(const std::string& msg) {
void Terminal::InProgress::done(const std::string& msg) { void Terminal::InProgress::done(const std::string& msg) {
if(!stop) { if(!stop) {
stop=true; stop=true;
this->terminal.print(line_nr-1, msg); Singleton::terminal()->print(line_nr-1, msg);
} }
} }
void Terminal::InProgress::cancel(const std::string& msg) { void Terminal::InProgress::cancel(const std::string& msg) {
if(!stop) { if(!stop) {
stop=true; stop=true;
this->terminal.print(line_nr-1, msg); Singleton::terminal()->print(line_nr-1, msg);
} }
} }
@ -48,8 +49,7 @@ Terminal::View::View(){
add(scrolled_window); add(scrolled_window);
} }
Terminal::Controller::Controller(Terminal::Config& cfg) : Terminal::Controller::Controller() {
config(cfg) {
folder_command_ = ""; folder_command_ = "";
} }
@ -65,7 +65,7 @@ void Terminal::Controller::Compile(){
view.text_view.get_buffer()->set_text(""); view.text_view.get_buffer()->set_text("");
DEBUG("Terminal: Compile: running cmake command"); DEBUG("Terminal: Compile: running cmake command");
std::vector<std::string> commands = config.compile_commands; std::vector<std::string> commands = Singleton::Config::terminal()->compile_commands;
for (size_t it = 0; it < commands.size(); ++it) { for (size_t it = 0; it < commands.size(); ++it) {
ExecuteCommand(commands.at(it), "r"); ExecuteCommand(commands.at(it), "r");
@ -79,7 +79,7 @@ void Terminal::Controller::Run(std::string executable) {
print("juCi++ execute: " + executable + "\n"); print("juCi++ execute: " + executable + "\n");
DEBUG("Terminal: Compile: running run command: "); DEBUG("Terminal: Compile: running run command: ");
DEBUG_VAR(executable); DEBUG_VAR(executable);
ExecuteCommand("cd "+config.run_command + "; ./"+executable, "r"); ExecuteCommand("cd "+Singleton::Config::terminal()->run_command + "; ./"+executable, "r");
print("\n"); print("\n");
} }
@ -100,7 +100,7 @@ void Terminal::Controller::print(int line_nr, std::string message){
} }
std::shared_ptr<Terminal::InProgress> Terminal::Controller::print_in_progress(std::string start_msg) { std::shared_ptr<Terminal::InProgress> Terminal::Controller::print_in_progress(std::string start_msg) {
std::shared_ptr<Terminal::InProgress> in_progress=std::shared_ptr<Terminal::InProgress>(new Terminal::InProgress(*this, start_msg)); std::shared_ptr<Terminal::InProgress> in_progress=std::shared_ptr<Terminal::InProgress>(new Terminal::InProgress(start_msg));
return in_progress; return in_progress;
} }

6
juci/terminal.h

@ -27,13 +27,12 @@ namespace Terminal {
//Temporary solution for displaying functions in progress, and when they are done. //Temporary solution for displaying functions in progress, and when they are done.
class InProgress { class InProgress {
public: public:
InProgress(Controller& terminal, const std::string& start_msg); InProgress(const std::string& start_msg);
~InProgress(); ~InProgress();
void done(const std::string& msg); void done(const std::string& msg);
void cancel(const std::string& msg); void cancel(const std::string& msg);
private: private:
void start(const std::string& msg); void start(const std::string& msg);
Controller& terminal;
int line_nr; int line_nr;
std::atomic<bool> stop; std::atomic<bool> stop;
Glib::Dispatcher waiting_print; Glib::Dispatcher waiting_print;
@ -42,7 +41,7 @@ namespace Terminal {
class Controller { class Controller {
public: public:
Controller(Terminal::Config& cfg); Controller();
void SetFolderCommand(boost::filesystem::path CMake_path); void SetFolderCommand(boost::filesystem::path CMake_path);
void Run(std::string executable); void Run(std::string executable);
void Compile(); void Compile();
@ -51,7 +50,6 @@ namespace Terminal {
std::shared_ptr<InProgress> print_in_progress(std::string start_msg); std::shared_ptr<InProgress> print_in_progress(std::string start_msg);
Terminal::View view; Terminal::View view;
private: private:
Terminal::Config& config;
void ExecuteCommand(std::string command, std::string mode); void ExecuteCommand(std::string command, std::string mode);
bool OnButtonRealeaseEvent(GdkEventKey* key); bool OnButtonRealeaseEvent(GdkEventKey* key);
bool ExistInConsole(std::string string); bool ExistInConsole(std::string string);

2
juci/tooltips.cc

@ -46,7 +46,7 @@ void Tooltip::adjust(bool disregard_drawn) {
tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(this->get_buffer())); tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(this->get_buffer()));
tooltip_widget->set_editable(false); tooltip_widget->set_editable(false);
tooltip_widget->override_background_color(Gdk::RGBA(Singletons::Config::source()->background_tooltips)); tooltip_widget->override_background_color(Gdk::RGBA(Singleton::Config::source()->background_tooltips));
window->add(*tooltip_widget); window->add(*tooltip_widget);
auto layout=Pango::Layout::create(tooltip_widget->get_pango_context()); auto layout=Pango::Layout::create(tooltip_widget->get_pango_context());

121
juci/window.cc

@ -1,128 +1,124 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
#include "singletons.h"
Window::Window() : Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL), window_box_(Gtk::ORIENTATION_VERTICAL) {
main_config(),
keybindings(main_config.keybindings_cfg),
terminal(main_config.terminal_cfg),
notebook(keybindings, terminal,
main_config.dir_cfg),
menu(keybindings),
api(menu, notebook) {
INFO("Create Window"); INFO("Create Window");
set_title("juCi++"); set_title("juCi++");
set_default_size(600, 400); set_default_size(600, 400);
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
add(window_box_); add(window_box_);
keybindings.action_group_menu()->add(Gtk::Action::create("FileQuit", auto keybindings=Singleton::keybindings();
auto keybindings_cfg=Singleton::Config::keybindings();
keybindings->action_group_menu->add(Gtk::Action::create("FileQuit",
"Quit juCi++"), "Quit juCi++"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["quit"]), ->key_map["quit"]),
[this]() { [this]() {
OnWindowHide(); OnWindowHide();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("FileOpenFile", keybindings->action_group_menu->add(Gtk::Action::create("FileOpenFile",
"Open file"), "Open file"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["open_file"]), ->key_map["open_file"]),
[this]() { [this]() {
OnOpenFile(); OnOpenFile();
}); });
keybindings.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", keybindings->action_group_menu->add(Gtk::Action::create("FileOpenFolder",
"Open folder"), "Open folder"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["open_folder"]), ->key_map["open_folder"]),
[this]() { [this]() {
OnFileOpenFolder(); OnFileOpenFolder();
}); });
keybindings. keybindings->
action_group_menu()-> action_group_menu->
add(Gtk::Action::create("FileSaveAs", add(Gtk::Action::create("FileSaveAs",
"Save as"), "Save as"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["save_as"]), ->key_map["save_as"]),
[this]() { [this]() {
SaveFileAs(); SaveFileAs();
}); });
keybindings. keybindings->
action_group_menu()-> action_group_menu->
add(Gtk::Action::create("FileSave", add(Gtk::Action::create("FileSave",
"Save"), "Save"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["save"]), ->key_map["save"]),
[this]() { [this]() {
SaveFile(); SaveFile();
}); });
keybindings. keybindings->
action_group_menu()-> action_group_menu->
add(Gtk::Action::create("ProjectCompileAndRun", add(Gtk::Action::create("ProjectCompileAndRun",
"Compile And Run"), "Compile And Run"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["compile_and_run"]), ->key_map["compile_and_run"]),
[this]() { [this]() {
SaveFile(); SaveFile();
if (running.try_lock()) { if (running.try_lock()) {
std::thread execute([=]() { std::thread execute([this]() {
std::string path = notebook.CurrentTextView().file_path; std::string path = Singleton::notebook()->CurrentSourceView()->file_path;
size_t pos = path.find_last_of("/\\"); size_t pos = path.find_last_of("/\\");
if(pos != std::string::npos) { if(pos != std::string::npos) {
path.erase(path.begin()+pos,path.end()); path.erase(path.begin()+pos,path.end());
terminal.SetFolderCommand(path); Singleton::terminal()->SetFolderCommand(path);
} }
terminal.Compile(); Singleton::terminal()->Compile();
std::string executable = notebook.directories. std::string executable = Singleton::notebook()->directories.
GetCmakeVarValue(path,"add_executable"); GetCmakeVarValue(path,"add_executable");
terminal.Run(executable); Singleton::terminal()->Run(executable);
running.unlock(); running.unlock();
}); });
execute.detach(); execute.detach();
} }
}); });
keybindings. keybindings->
action_group_menu()-> action_group_menu->
add(Gtk::Action::create("ProjectCompile", add(Gtk::Action::create("ProjectCompile",
"Compile"), "Compile"),
Gtk::AccelKey(keybindings.config_ Gtk::AccelKey(keybindings_cfg
.key_map()["compile"]), ->key_map["compile"]),
[this]() { [this]() {
SaveFile(); SaveFile();
if (running.try_lock()) { if (running.try_lock()) {
std::thread execute([=]() { std::thread execute([this]() {
std::string path = notebook.CurrentTextView().file_path; std::string path = Singleton::notebook()->CurrentSourceView()->file_path;
size_t pos = path.find_last_of("/\\"); size_t pos = path.find_last_of("/\\");
if(pos != std::string::npos){ if(pos != std::string::npos){
path.erase(path.begin()+pos,path.end()); path.erase(path.begin()+pos,path.end());
terminal.SetFolderCommand(path); Singleton::terminal()->SetFolderCommand(path);
} }
terminal.Compile(); Singleton::terminal()->Compile();
running.unlock(); running.unlock();
}); });
execute.detach(); execute.detach();
} }
}); });
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());
keybindings.BuildMenu(); keybindings->BuildMenu();
window_box_.pack_start(menu.view(), Gtk::PACK_SHRINK); window_box_.pack_start(Singleton::menu()->view(), Gtk::PACK_SHRINK);
window_box_.pack_start(notebook.entry, Gtk::PACK_SHRINK); window_box_.pack_start(Singleton::notebook()->entry, Gtk::PACK_SHRINK);
paned_.set_position(300); paned_.set_position(300);
paned_.pack1(notebook.view, true, false); paned_.pack1(Singleton::notebook()->view, true, false);
paned_.pack2(terminal.view, true, true); paned_.pack2(Singleton::terminal()->view, true, true);
window_box_.pack_end(paned_); window_box_.pack_end(paned_);
show_all_children(); show_all_children();
INFO("Window created"); INFO("Window created");
} // Window constructor } // Window constructor
void Window::OnWindowHide() { void Window::OnWindowHide() {
for(size_t c=0;c<notebook.text_vec_.size();c++) for(size_t c=0;c<Singleton::notebook()->source_views.size();c++)
notebook.OnCloseCurrentPage(); //TODO: This only works on one page at the momemt. Change to notebook.close_page(page_nr); Singleton::notebook()->OnCloseCurrentPage(); //TODO: This only works on one page at the momemt. Change to Singleton::notebook()->close_page(page_nr);
hide(); hide();
} }
void Window::OnFileOpenFolder() { void Window::OnFileOpenFolder() {
@ -141,8 +137,8 @@ void Window::OnFileOpenFolder() {
case(Gtk::RESPONSE_OK): case(Gtk::RESPONSE_OK):
{ {
std::string project_path=dialog.get_filename(); std::string project_path=dialog.get_filename();
notebook.project_path=project_path; Singleton::notebook()->project_path=project_path;
notebook.directories.open_folder(project_path); Singleton::notebook()->directories.open_folder(project_path);
break; break;
} }
case(Gtk::RESPONSE_CANCEL): case(Gtk::RESPONSE_CANCEL):
@ -190,7 +186,7 @@ void Window::OnOpenFile() {
switch (result) { switch (result) {
case(Gtk::RESPONSE_OK): { case(Gtk::RESPONSE_OK): {
std::string path = dialog.get_filename(); std::string path = dialog.get_filename();
notebook.OnOpenFile(path); Singleton::notebook()->OnOpenFile(path);
break; break;
} }
case(Gtk::RESPONSE_CANCEL): { case(Gtk::RESPONSE_CANCEL): {
@ -203,20 +199,19 @@ void Window::OnOpenFile() {
} }
bool Window::SaveFile() { bool Window::SaveFile() {
if(notebook.OnSaveFile()) { if(Singleton::notebook()->OnSaveFile()) {
terminal.print("File saved to: " + Singleton::terminal()->print("File saved to: " +
notebook.CurrentTextView().file_path+"\n"); Singleton::notebook()->CurrentSourceView()->file_path+"\n");
return true; return true;
} }
terminal.print("File not saved");
return false; return false;
} }
bool Window::SaveFileAs() { bool Window::SaveFileAs() {
if(notebook.OnSaveFile(notebook.OnSaveFileAs())){ if(Singleton::notebook()->OnSaveFile(Singleton::notebook()->OnSaveFileAs())){
terminal.print("File saved to: " + Singleton::terminal()->print("File saved to: " +
notebook.CurrentTextView().file_path+"\n"); Singleton::notebook()->CurrentSourceView()->file_path+"\n");
return true; return true;
} }
terminal.print("File not saved"); Singleton::terminal()->print("File not saved");
return false; return false;
} }

5
juci/window.h

@ -3,7 +3,6 @@
#include "api.h" #include "api.h"
#include "config.h" #include "config.h"
#include "terminal.h"
#include <cstddef> #include <cstddef>
@ -15,10 +14,6 @@ public:
virtual ~Window() { } virtual ~Window() { }
MainConfig main_config; MainConfig main_config;
Keybindings::Controller keybindings;
Menu::Controller menu;
Notebook::Controller notebook;
Terminal::Controller terminal;
PluginApi api; PluginApi api;
private: private:

Loading…
Cancel
Save