Browse Source

Singletong and config cleanup. Got rid of most if not all circular includes.

merge-requests/365/head
eidheim 10 years ago
parent
commit
626d347387
  1. 5
      src/cmake.cc
  2. 79
      src/config.cc
  3. 72
      src/config.h
  4. 15
      src/dialogs.cc
  5. 13
      src/dialogs.h
  6. 5
      src/dialogs_win.cc
  7. 6
      src/directories.cc
  8. 6
      src/directories.h
  9. 40
      src/juci.cc
  10. 13
      src/juci.h
  11. 8
      src/menu.cc
  12. 6
      src/menu.h
  13. 25
      src/notebook.cc
  14. 1
      src/notebook.h
  15. 66
      src/singletons.cc
  16. 43
      src/singletons.h
  17. 39
      src/source.cc
  18. 28
      src/source.h
  19. 24
      src/source_clang.cc
  20. 1
      src/source_clang.h
  21. 12
      src/terminal.cc
  22. 8
      src/terminal.h
  23. 12
      src/terminal_win.cc
  24. 1
      src/tooltips.cc
  25. 130
      src/window.cc
  26. 8
      src/window.h

5
src/cmake.cc

@ -1,5 +1,6 @@
#include "cmake.h" #include "cmake.h"
#include "singletons.h" #include "singletons.h"
#include "filesystem.h"
#include <regex> #include <regex>
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
@ -44,8 +45,8 @@ CMake::CMake(const boost::filesystem::path &path) {
} }
bool CMake::create_compile_commands(const boost::filesystem::path &path) { bool CMake::create_compile_commands(const boost::filesystem::path &path) {
Singleton::terminal()->print("Creating "+path.string()+"/compile_commands.json\n"); Singleton::terminal->print("Creating "+path.string()+"/compile_commands.json\n");
if(Singleton::terminal()->execute(Singleton::Config::terminal()->cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path)==EXIT_SUCCESS) { if(Singleton::terminal->execute(Singleton::config->terminal.cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path)==EXIT_SUCCESS) {
#ifdef _WIN32 //Temporary fix to MSYS2's libclang #ifdef _WIN32 //Temporary fix to MSYS2's libclang
auto compile_commands_path=path; auto compile_commands_path=path;
compile_commands_path/="compile_commands.json"; compile_commands_path/="compile_commands.json";

79
src/config.cc

@ -4,14 +4,15 @@
#include <exception> #include <exception>
#include "files.h" #include "files.h"
#include <iostream> #include <iostream>
#include "filesystem.h"
using namespace std; //TODO: remove using namespace std; //TODO: remove
MainConfig::MainConfig() { Config::Config() {
init_home_path(); init_home_path();
} }
void MainConfig::read() { void Config::load() {
auto config_json = (home/"config"/"config.json").string(); // This causes some redundant copies, but assures windows support auto config_json = (home/"config"/"config.json").string(); // This causes some redundant copies, but assures windows support
try { try {
find_or_create_config_files(); find_or_create_config_files();
@ -20,7 +21,7 @@ void MainConfig::read() {
retrieve_config(); retrieve_config();
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Singleton::terminal()->print("Error reading "+config_json+": "+e.what()+"\n"); Singleton::terminal->print("Error reading "+config_json+": "+e.what()+"\n");
std::stringstream ss; std::stringstream ss;
ss << configjson; ss << configjson;
boost::property_tree::read_json(ss, cfg); boost::property_tree::read_json(ss, cfg);
@ -29,7 +30,7 @@ void MainConfig::read() {
cfg.clear(); cfg.clear();
} }
void MainConfig::find_or_create_config_files() { void Config::find_or_create_config_files() {
auto config_dir = home/"config"; auto config_dir = home/"config";
auto config_json = config_dir/"config.json"; auto config_json = config_dir/"config.json";
auto plugins_py = config_dir/"plugins.py"; auto plugins_py = config_dir/"plugins.py";
@ -57,25 +58,25 @@ void MainConfig::find_or_create_config_files() {
filesystem::write(juci_style_path, juci_dark_blue_style); filesystem::write(juci_style_path, juci_dark_blue_style);
} }
void MainConfig::retrieve_config() { void Config::retrieve_config() {
auto keybindings_pt = cfg.get_child("keybindings"); auto keybindings_pt = cfg.get_child("keybindings");
for (auto &i : keybindings_pt) { for (auto &i : keybindings_pt) {
Singleton::Config::menu()->keys[i.first] = i.second.get_value<std::string>(); menu.keys[i.first] = i.second.get_value<std::string>();
} }
GenerateSource(); GenerateSource();
GenerateDirectoryFilter(); GenerateDirectoryFilter();
Singleton::Config::window()->theme_name=cfg.get<std::string>("gtk_theme.name"); window.theme_name=cfg.get<std::string>("gtk_theme.name");
Singleton::Config::window()->theme_variant=cfg.get<std::string>("gtk_theme.variant"); window.theme_variant=cfg.get<std::string>("gtk_theme.variant");
Singleton::Config::window()->version = cfg.get<std::string>("version"); window.version = cfg.get<std::string>("version");
Singleton::Config::window()->default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")}; window.default_size = {cfg.get<int>("default_window_size.width"), cfg.get<int>("default_window_size.height")};
Singleton::Config::terminal()->make_command=cfg.get<std::string>("project.make_command"); terminal.make_command=cfg.get<std::string>("project.make_command");
Singleton::Config::terminal()->cmake_command=cfg.get<std::string>("project.cmake_command"); terminal.cmake_command=cfg.get<std::string>("project.cmake_command");
Singleton::Config::terminal()->clang_format_command=cfg.get<std::string>("project.clang_format_command", "clang-format"); terminal.clang_format_command=cfg.get<std::string>("project.clang_format_command", "clang-format");
Singleton::Config::terminal()->history_size=cfg.get<int>("terminal_history_size"); terminal.history_size=cfg.get<int>("terminal_history_size");
} }
bool MainConfig::check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path) { bool Config::check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path) {
if(parent_path.size()>0) if(parent_path.size()>0)
parent_path+="."; parent_path+=".";
bool exists=true; bool exists=true;
@ -97,7 +98,7 @@ bool MainConfig::check_config_file(const boost::property_tree::ptree &default_cf
return exists; return exists;
} }
void MainConfig::update_config_file() { void Config::update_config_file() {
boost::property_tree::ptree default_cfg; boost::property_tree::ptree default_cfg;
bool cfg_ok=true; bool cfg_ok=true;
try { try {
@ -122,56 +123,54 @@ void MainConfig::update_config_file() {
} }
} }
void MainConfig::GenerateSource() { void Config::GenerateSource() {
auto source_cfg = Singleton::Config::source();
auto source_json = cfg.get_child("source"); auto source_json = cfg.get_child("source");
Singleton::Config::source()->style=source_json.get<std::string>("style"); source.style=source_json.get<std::string>("style");
source_cfg->font=source_json.get<std::string>("font"); source.font=source_json.get<std::string>("font");
source_cfg->show_map = source_json.get<bool>("show_map"); source.show_map = source_json.get<bool>("show_map");
source_cfg->map_font_size = source_json.get<std::string>("map_font_size"); source.map_font_size = source_json.get<std::string>("map_font_size");
source_cfg->spellcheck_language = source_json.get<std::string>("spellcheck_language"); source.spellcheck_language = source_json.get<std::string>("spellcheck_language");
source_cfg->default_tab_char = source_json.get<char>("default_tab_char"); source.default_tab_char = source_json.get<char>("default_tab_char");
source_cfg->default_tab_size = source_json.get<unsigned>("default_tab_size"); source.default_tab_size = source_json.get<unsigned>("default_tab_size");
source_cfg->auto_tab_char_and_size = source_json.get<bool>("auto_tab_char_and_size"); source.auto_tab_char_and_size = source_json.get<bool>("auto_tab_char_and_size");
source_cfg->wrap_lines = source_json.get<bool>("wrap_lines"); source.wrap_lines = source_json.get<bool>("wrap_lines");
source_cfg->highlight_current_line = source_json.get<bool>("highlight_current_line"); source.highlight_current_line = source_json.get<bool>("highlight_current_line");
source_cfg->show_line_numbers = source_json.get<bool>("show_line_numbers"); source.show_line_numbers = source_json.get<bool>("show_line_numbers");
for (auto &i : source_json.get_child("clang_types")) for (auto &i : source_json.get_child("clang_types"))
source_cfg->clang_types[i.first] = i.second.get_value<std::string>(); source.clang_types[i.first] = i.second.get_value<std::string>();
source_cfg->clang_format_style = source_json.get<std::string>("clang_format_style"); source.clang_format_style = source_json.get<std::string>("clang_format_style");
auto pt_doc_search=cfg.get_child("documentation_searches"); auto pt_doc_search=cfg.get_child("documentation_searches");
for(auto &pt_doc_search_lang: pt_doc_search) { for(auto &pt_doc_search_lang: pt_doc_search) {
source_cfg->documentation_searches[pt_doc_search_lang.first].separator=pt_doc_search_lang.second.get<std::string>("separator"); source.documentation_searches[pt_doc_search_lang.first].separator=pt_doc_search_lang.second.get<std::string>("separator");
auto &queries=source_cfg->documentation_searches.find(pt_doc_search_lang.first)->second.queries; auto &queries=source.documentation_searches.find(pt_doc_search_lang.first)->second.queries;
for(auto &i: pt_doc_search_lang.second.get_child("queries")) { for(auto &i: pt_doc_search_lang.second.get_child("queries")) {
queries[i.first]=i.second.get_value<std::string>(); queries[i.first]=i.second.get_value<std::string>();
} }
} }
} }
void MainConfig::GenerateDirectoryFilter() { void Config::GenerateDirectoryFilter() {
auto dir_cfg=Singleton::Config::directories();
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");
dir_cfg->exceptions.clear(); directories.exceptions.clear();
dir_cfg->ignored.clear(); directories.ignored.clear();
for ( auto &i : except_json ) for ( auto &i : except_json )
dir_cfg->exceptions.emplace_back(i.second.get_value<std::string>()); directories.exceptions.emplace_back(i.second.get_value<std::string>());
for ( auto &i : ignore_json ) for ( auto &i : ignore_json )
dir_cfg->ignored.emplace_back(i.second.get_value<std::string>()); directories.ignored.emplace_back(i.second.get_value<std::string>());
} }
void MainConfig::init_home_path(){ void Config::init_home_path(){
std::vector<std::string> locations = JUCI_ENV_SEARCH_LOCATIONS; std::vector<std::string> locations = JUCI_ENV_SEARCH_LOCATIONS;
char *ptr = nullptr; char *ptr = nullptr;
for (auto &env : locations) { for (auto &env : locations) {

72
src/config.h

@ -3,11 +3,76 @@
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include "menu.h" #include "menu.h"
#include <unordered_map>
#include <string>
#include <utility>
#include <vector>
class MainConfig { class Config {
public: public:
MainConfig(); class Menu {
void read(); public:
std::unordered_map<std::string, std::string> keys;
};
class Window {
public:
std::string theme_name;
std::string theme_variant;
std::string version;
std::pair<int, int> default_size;
};
class Terminal {
public:
std::string cmake_command;
std::string make_command;
std::string clang_format_command;
int history_size;
};
class Directories {
public:
std::vector<std::string> ignored;
std::vector<std::string> exceptions;
};
class Source {
public:
class DocumentationSearch {
public:
std::string separator;
std::unordered_map<std::string, std::string> queries;
};
std::string style;
std::string font;
std::string spellcheck_language;
bool show_map;
std::string map_font_size;
bool auto_tab_char_and_size;
char default_tab_char;
unsigned default_tab_size;
bool wrap_lines;
bool highlight_current_line;
bool show_line_numbers;
std::unordered_map<std::string, std::string> clang_types;
std::string clang_format_style;
std::unordered_map<std::string, DocumentationSearch> documentation_searches;
};
Config();
void load();
Menu menu;
Window window;
Terminal terminal;
Directories directories;
Source source;
const boost::filesystem::path& juci_home_path() const { return home; } const boost::filesystem::path& juci_home_path() const { return home; }
private: private:
@ -15,7 +80,6 @@ private:
void retrieve_config(); void retrieve_config();
bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path=""); bool check_config_file(const boost::property_tree::ptree &default_cfg, std::string parent_path="");
void update_config_file(); void update_config_file();
void PrintMenu();
void GenerateSource(); void GenerateSource();
void GenerateDirectoryFilter(); void GenerateDirectoryFilter();

15
src/dialogs.cc

@ -2,20 +2,24 @@
#include "singletons.h" #include "singletons.h"
#include <gtkmm.h> #include <gtkmm.h>
#include <vector> #include <vector>
#include "juci.h"
std::string open_dialog(const std::string &title, std::string open_dialog(const std::string &title,
const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons, const std::vector<std::pair<std::string, Gtk::ResponseType>> &buttons,
Gtk::FileChooserAction gtk_options, Gtk::FileChooserAction gtk_options,
const std::string &file_name = "") { const std::string &file_name = "") {
Gtk::FileChooserDialog dialog(title, gtk_options); Gtk::FileChooserDialog dialog(title, gtk_options);
if(!Singleton::directories()->current_path.empty()) if(!Singleton::directories->current_path.empty())
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), Singleton::directories()->current_path.c_str()); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), Singleton::directories->current_path.c_str());
else else
gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().c_str()); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), boost::filesystem::current_path().c_str());
if (!file_name.empty()) if (!file_name.empty())
gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), file_name.c_str()); gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), file_name.c_str());
dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS);
dialog.set_transient_for(*Singleton::window());
auto application=Glib::RefPtr<Application>::cast_static(Gio::Application::get_default()).release();
dialog.set_transient_for(*application->window);
for (auto &button : buttons) for (auto &button : buttons)
dialog.add_button(button.first, button.second); dialog.add_button(button.first, button.second);
return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : "";
@ -45,10 +49,9 @@ std::string Dialog::select_file() {
Gtk::FILE_CHOOSER_ACTION_OPEN); Gtk::FILE_CHOOSER_ACTION_OPEN);
} }
std::string Dialog::save_file() { std::string Dialog::save_file(const boost::filesystem::path file_path) {
return open_dialog("Please choose a file", return open_dialog("Please choose a file",
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, {std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)},
Gtk::FILE_CHOOSER_ACTION_SAVE, Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string());
Singleton::window()->notebook.get_current_view()->file_path.string());
} }

13
src/dialogs.h

@ -1,14 +1,15 @@
#ifndef JUCI_DIALOG_H_ #ifndef JUCI_DIALOG_H_
#define JUCI_DIALOG_H_ #define JUCI_DIALOG_H_
#include <string> #include <string>
#include <boost/filesystem.hpp>
class Dialog { class Dialog {
public: public:
static std::string select_folder(); static std::string select_folder();
static std::string select_file(); static std::string select_file();
static std::string new_file(); static std::string new_file();
static std::string new_folder(); static std::string new_folder();
static std::string save_file(); static std::string save_file(const boost::filesystem::path file_path);
}; // Dialog }; // Dialog
#ifdef _WIN32 #ifdef _WIN32

5
src/dialogs_win.cc

@ -7,7 +7,7 @@ HRESULT __hr__;
#define check(__fun__, error_message) \ #define check(__fun__, error_message) \
__hr__ = __fun__; \ __hr__ = __fun__; \
if (FAILED(__hr__)) { \ if (FAILED(__hr__)) { \
Singleton::terminal()->print(error_message); \ Singleton::terminal->print(error_message); \
throw std::runtime_error(error_message); \ throw std::runtime_error(error_message); \
} }
#endif // CHECK #endif // CHECK
@ -90,7 +90,8 @@ std::string Dialog::select_file() {
return (OpenDialog("Open file", 0)).show(); return (OpenDialog("Open file", 0)).show();
} }
std::string Dialog::save_file() { std::string Dialog::save_file(const boost::filesystem::path file_path) {
//TODO: use file_path
return (SaveDialog("Please choose your destination", 0)).show(); return (SaveDialog("Please choose your destination", 0)).show();
} }
#endif #endif

6
src/directories.cc

@ -1,8 +1,8 @@
#include "singletons.h" #include "singletons.h"
#include "directories.h"
#include "logging.h" #include "logging.h"
#include <algorithm> #include <algorithm>
#include <unordered_set> #include <unordered_set>
#include "source.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -201,11 +201,11 @@ void Directories::select(const boost::filesystem::path &path) {
bool Directories::ignored(std::string path) { bool Directories::ignored(std::string path) {
std::transform(path.begin(), path.end(), path.begin(), ::tolower); std::transform(path.begin(), path.end(), path.begin(), ::tolower);
for(std::string &i : Singleton::Config::directories()->exceptions) { for(std::string &i : Singleton::config->directories.exceptions) {
if(i == path) if(i == path)
return false; return false;
} }
for(auto &i : Singleton::Config::directories()->ignored) { for(auto &i : Singleton::config->directories.ignored) {
if(path.find(i, 0) != std::string::npos) if(path.find(i, 0) != std::string::npos)
return true; return true;
} }

6
src/directories.h

@ -12,12 +12,6 @@
class Directories : public Gtk::ScrolledWindow { class Directories : public Gtk::ScrolledWindow {
public: public:
class Config {
public:
std::vector<std::string> ignored;
std::vector<std::string> exceptions;
};
class ColumnRecord : public Gtk::TreeModel::ColumnRecord { class ColumnRecord : public Gtk::TreeModel::ColumnRecord {
public: public:
ColumnRecord() { ColumnRecord() {

40
src/juci.cc

@ -3,15 +3,15 @@
using namespace std; //TODO: remove using namespace std; //TODO: remove
void app::init_logging() { void Application::init_logging() {
boost::log::add_common_attributes(); boost::log::add_common_attributes();
auto log_dir = Singleton::Config::main()->juci_home_path()/"log"/"juci.log"; auto log_dir = Singleton::config->juci_home_path()/"log"/"juci.log";
boost::log::add_file_log(boost::log::keywords::file_name = log_dir, boost::log::add_file_log(boost::log::keywords::file_name = log_dir,
boost::log::keywords::auto_flush = true); boost::log::keywords::auto_flush = true);
JINFO("Logging initalized"); JINFO("Logging initalized");
} }
int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) { int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
Glib::set_prgname("juci"); Glib::set_prgname("juci");
Glib::OptionContext ctx("[PATH ...]"); Glib::OptionContext ctx("[PATH ...]");
Glib::OptionGroup gtk_group(gtk_get_option_group(true)); Glib::OptionGroup gtk_group(gtk_get_option_group(true));
@ -37,13 +37,13 @@ int app::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) {
return 0; return 0;
} }
void app::on_activate() { void Application::on_activate() {
add_window(*Singleton::window()); add_window(*window);
Singleton::window()->show(); window->show();
bool first_directory=true; bool first_directory=true;
for(auto &directory: directories) { for(auto &directory: directories) {
if(first_directory) { if(first_directory) {
Singleton::directories()->open(directory); Singleton::directories->open(directory);
first_directory=false; first_directory=false;
} }
else { else {
@ -57,25 +57,25 @@ void app::on_activate() {
it++; it++;
} }
std::thread another_juci_app([this, directory, files_in_directory](){ std::thread another_juci_app([this, directory, files_in_directory](){
Singleton::terminal()->async_print("Executing: juci "+directory.string()+files_in_directory); Singleton::terminal->async_print("Executing: juci "+directory.string()+files_in_directory);
Singleton::terminal()->execute("juci "+directory.string()+files_in_directory, "", false); Singleton::terminal->execute("juci "+directory.string()+files_in_directory, "", false);
}); });
another_juci_app.detach(); another_juci_app.detach();
} }
} }
for(auto &file: files) for(auto &file: files)
Singleton::window()->notebook.open(file); window->notebook.open(file);
} }
void app::on_startup() { void Application::on_startup() {
Gtk::Application::on_startup(); Gtk::Application::on_startup();
Singleton::menu()->init(); Singleton::menu->init();
Singleton::menu()->build(); Singleton::menu->build();
auto object = Singleton::menu()->builder->get_object("juci-menu"); auto object = Singleton::menu->builder->get_object("juci-menu");
auto juci_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object); auto juci_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
object = Singleton::menu()->builder->get_object("window-menu"); object = Singleton::menu->builder->get_object("window-menu");
auto window_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object); auto window_menu = Glib::RefPtr<Gio::Menu>::cast_dynamic(object);
if (!juci_menu || !window_menu) { if (!juci_menu || !window_menu) {
std::cerr << "Menu not found." << std::endl; std::cerr << "Menu not found." << std::endl;
@ -86,13 +86,15 @@ void app::on_startup() {
} }
} }
app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { Application::Application() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) {
Singleton::init();
init_logging(); init_logging();
Glib::set_application_name("juCi++"); Glib::set_application_name("juCi++");
Singleton::menu()->application=static_cast<Gtk::Application*>(this); //For Ubuntu 14...
Singleton::window(); window=std::unique_ptr<Window>(new Window());
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
return app().run(argc, argv); return Application().run(argc, argv);
} }

13
src/juci.h

@ -1,17 +1,18 @@
#ifndef JUCI_JUCI_H_ #ifndef JUCI_JUCI_H_
#define JUCI_JUCI_H_ #define JUCI_JUCI_H_
#include "window.h" #include <gtkmm.h>
#include "logging.h" #include "logging.h"
#include "window.h"
class app : public Gtk::Application { class Application : public Gtk::Application {
public: public:
app(); Application();
int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd); int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd);
void on_activate(); void on_activate();
void on_startup(); void on_startup();
std::unique_ptr<Window> window;
private: private:
std::vector<boost::filesystem::path> directories; std::vector<boost::filesystem::path> directories;
std::vector<boost::filesystem::path> files; std::vector<boost::filesystem::path> files;
void init_logging(); void init_logging();

8
src/menu.cc

@ -10,7 +10,7 @@ Menu::Menu() {
//TODO: if Ubuntu ever gets fixed, move to constructor, also cleanup the rest of the Ubuntu specific code //TODO: if Ubuntu ever gets fixed, move to constructor, also cleanup the rest of the Ubuntu specific code
void Menu::init() { void Menu::init() {
auto accels=Singleton::Config::menu()->keys; auto accels=Singleton::config->menu.keys;
for(auto &accel: accels) { for(auto &accel: accels) {
#ifdef UBUNTU_BUGGED_MENU #ifdef UBUNTU_BUGGED_MENU
size_t pos=0; size_t pos=0;
@ -295,11 +295,15 @@ void Menu::init() {
} }
void Menu::add_action(const std::string &name, std::function<void()> action) { void Menu::add_action(const std::string &name, std::function<void()> action) {
auto application=Glib::RefPtr<Gtk::Application>::cast_static(Gio::Application::get_default()).release();
actions[name]=application->add_action(name, action); actions[name]=application->add_action(name, action);
} }
void Menu::set_keys() { void Menu::set_keys() {
for(auto &key: Singleton::Config::menu()->keys) { auto application=Glib::RefPtr<Gtk::Application>::cast_static(Gio::Application::get_default()).release();
for(auto &key: Singleton::config->menu.keys) {
if(key.second.size()>0 && actions.find(key.first)!=actions.end()) { if(key.second.size()>0 && actions.find(key.first)!=actions.end()) {
#if GTK_VERSION_GE(3, 12) #if GTK_VERSION_GE(3, 12)
application->set_accel_for_action("app."+key.first, key.second); application->set_accel_for_action("app."+key.first, key.second);

6
src/menu.h

@ -7,14 +7,8 @@
class Menu { class Menu {
public: public:
class Config {
public:
std::unordered_map<std::string, std::string> keys;
};
Menu(); Menu();
void init(); //For Ubuntu 14... void init(); //For Ubuntu 14...
Gtk::Application* application; //For Ubuntu 14...
void add_action(const std::string &name, std::function<void()> action); void add_action(const std::string &name, std::function<void()> action);
std::unordered_map<std::string, Glib::RefPtr<Gio::SimpleAction> > actions; std::unordered_map<std::string, Glib::RefPtr<Gio::SimpleAction> > actions;

25
src/notebook.cc

@ -4,6 +4,7 @@
#include <fstream> #include <fstream>
#include <regex> #include <regex>
#include "cmake.h" #include "cmake.h"
#include "filesystem.h"
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17
#include "gtksourceview-3.0/gtksourceview/gtksourcemap.h" #include "gtksourceview-3.0/gtksourceview/gtksourcemap.h"
@ -66,14 +67,14 @@ void Notebook::open(const boost::filesystem::path &file_path) {
std::ifstream can_read(file_path.string()); std::ifstream can_read(file_path.string());
if(!can_read) { if(!can_read) {
Singleton::terminal()->print("Error: could not open "+file_path.string()+"\n"); Singleton::terminal->print("Error: could not open "+file_path.string()+"\n");
return; return;
} }
can_read.close(); can_read.close();
auto language=Source::guess_language(file_path); auto language=Source::guess_language(file_path);
boost::filesystem::path project_path; boost::filesystem::path project_path;
auto directories=Singleton::directories(); auto &directories=Singleton::directories;
if(directories->cmake && directories->cmake->project_path!="" && file_path.generic_string().substr(0, directories->cmake->project_path.generic_string().size()+1)==directories->cmake->project_path.generic_string()+'/') if(directories->cmake && directories->cmake->project_path!="" && file_path.generic_string().substr(0, directories->cmake->project_path.generic_string().size()+1)==directories->cmake->project_path.generic_string()+'/')
project_path=directories->cmake->project_path; project_path=directories->cmake->project_path;
else { else {
@ -81,7 +82,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
CMake cmake(project_path); CMake cmake(project_path);
if(cmake.project_path!="") { if(cmake.project_path!="") {
project_path=cmake.project_path; project_path=cmake.project_path;
Singleton::terminal()->print("Project path for "+file_path.string()+" set to "+project_path.string()+"\n"); Singleton::terminal->print("Project path for "+file_path.string()+" set to "+project_path.string()+"\n");
} }
} }
if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { if(language && (language->get_id()=="chdr" || language->get_id()=="cpphdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) {
@ -94,11 +95,11 @@ void Notebook::open(const boost::filesystem::path &file_path) {
source_views.back()->on_update_status=[this](Source::View* view, const std::string &status) { source_views.back()->on_update_status=[this](Source::View* view, const std::string &status) {
if(get_current_page()!=-1 && get_current_view()==view) if(get_current_page()!=-1 && get_current_view()==view)
Singleton::status()->set_text(status+" "); Singleton::status->set_text(status+" ");
}; };
source_views.back()->on_update_info=[this](Source::View* view, const std::string &info) { source_views.back()->on_update_info=[this](Source::View* view, const std::string &info) {
if(get_current_page()!=-1 && get_current_view()==view) if(get_current_page()!=-1 && get_current_view()==view)
Singleton::info()->set_text(" "+info); Singleton::info->set_text(" "+info);
}; };
scrolled_windows.emplace_back(new Gtk::ScrolledWindow()); scrolled_windows.emplace_back(new Gtk::ScrolledWindow());
@ -149,10 +150,10 @@ void Notebook::open(const boost::filesystem::path &file_path) {
void Notebook::configure(int view_nr) { void Notebook::configure(int view_nr) {
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17
auto source_font_description=Pango::FontDescription(Singleton::Config::source()->font); auto source_font_description=Pango::FontDescription(Singleton::config->source.font);
auto source_map_font_desc=Pango::FontDescription(static_cast<std::string>(source_font_description.get_family())+" "+Singleton::Config::source()->map_font_size); auto source_map_font_desc=Pango::FontDescription(static_cast<std::string>(source_font_description.get_family())+" "+Singleton::config->source.map_font_size);
source_maps.at(view_nr)->override_font(source_map_font_desc); source_maps.at(view_nr)->override_font(source_map_font_desc);
if(Singleton::Config::source()->show_map) { if(Singleton::config->source.show_map) {
if(hboxes.at(view_nr)->get_children().size()==1) if(hboxes.at(view_nr)->get_children().size()==1)
hboxes.at(view_nr)->pack_end(*source_maps.at(view_nr), Gtk::PACK_SHRINK); hboxes.at(view_nr)->pack_end(*source_maps.at(view_nr), Gtk::PACK_SHRINK);
} }
@ -188,7 +189,7 @@ bool Notebook::save(int page, bool reparse_needed) {
//If CMakeLists.txt have been modified: //If CMakeLists.txt have been modified:
boost::filesystem::path project_path; boost::filesystem::path project_path;
if(view->file_path.filename()=="CMakeLists.txt") { if(view->file_path.filename()=="CMakeLists.txt") {
auto directories=Singleton::directories(); auto &directories=Singleton::directories;
if(directories->cmake && directories->cmake->project_path!="" && view->file_path.generic_string().substr(0, directories->cmake->project_path.generic_string().size()+1)==directories->cmake->project_path.generic_string()+'/' && CMake::create_compile_commands(directories->cmake->project_path)) { if(directories->cmake && directories->cmake->project_path!="" && view->file_path.generic_string().substr(0, directories->cmake->project_path.generic_string().size()+1)==directories->cmake->project_path.generic_string()+'/' && CMake::create_compile_commands(directories->cmake->project_path)) {
project_path=directories->cmake->project_path; project_path=directories->cmake->project_path;
} }
@ -203,9 +204,9 @@ bool Notebook::save(int page, bool reparse_needed) {
if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) { if(auto source_clang_view=dynamic_cast<Source::ClangView*>(source_view)) {
if(project_path==source_clang_view->project_path) { if(project_path==source_clang_view->project_path) {
if(source_clang_view->restart_parse()) if(source_clang_view->restart_parse())
Singleton::terminal()->async_print("Reparsing "+source_clang_view->file_path.string()+"\n"); Singleton::terminal->async_print("Reparsing "+source_clang_view->file_path.string()+"\n");
else else
Singleton::terminal()->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n"); Singleton::terminal->async_print("Error: failed to reparse "+source_clang_view->file_path.string()+". Please reopen the file manually.\n");
} }
} }
} }
@ -214,7 +215,7 @@ bool Notebook::save(int page, bool reparse_needed) {
JDEBUG("end true"); JDEBUG("end true");
return true; return true;
} }
Singleton::terminal()->print("Error: could not save file " +view->file_path.string()+"\n"); Singleton::terminal->print("Error: could not save file " +view->file_path.string()+"\n");
} }
JDEBUG("end false"); JDEBUG("end false");
return false; return false;

1
src/notebook.h

@ -8,7 +8,6 @@
#include <type_traits> #include <type_traits>
#include <map> #include <map>
#include <sigc++/sigc++.h> #include <sigc++/sigc++.h>
#include "directories.h"
class Notebook : public Gtk::Notebook { class Notebook : public Gtk::Notebook {
public: public:

66
src/singletons.cc

@ -1,52 +1,20 @@
#include "singletons.h" #include "singletons.h"
std::unique_ptr<Source::Config> Singleton::Config::source_=std::unique_ptr<Source::Config>(new Source::Config()); #include <iostream> //TODO: remove
std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique_ptr<Directories::Config>(new Directories::Config()); using namespace std; //TODO: remove
std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config());
std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config()); std::unique_ptr<Config> Singleton::config;
std::unique_ptr<MainConfig> Singleton::Config::main_=std::unique_ptr<MainConfig>(new MainConfig()); std::unique_ptr<Menu> Singleton::menu;
std::unique_ptr<Terminal> Singleton::terminal;
std::unique_ptr<Menu::Config> Singleton::Config::menu_ = std::unique_ptr<Menu::Config>(new Menu::Config()); std::unique_ptr<Directories> Singleton::directories;
std::unique_ptr<Gtk::Label> Singleton::info;
std::unique_ptr<Gtk::Label> Singleton::status;
std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>();
Terminal *Singleton::terminal() { void Singleton::init() {
if(!terminal_) config=std::unique_ptr<Config>(new Config());
terminal_=std::unique_ptr<Terminal>(new Terminal()); menu=std::unique_ptr<Menu>(new Menu());
return terminal_.get(); terminal=std::unique_ptr<Terminal>(new Terminal());
} directories=std::unique_ptr<Directories>(new Directories());
info=std::unique_ptr<Gtk::Label>(new Gtk::Label());
std::unique_ptr<Directories> Singleton::directories_=std::unique_ptr<Directories>(); status=std::unique_ptr<Gtk::Label>(new Gtk::Label());
Directories *Singleton::directories() {
if(!directories_)
directories_=std::unique_ptr<Directories>(new Directories());
return directories_.get();
}
std::unique_ptr<Window> Singleton::window_=std::unique_ptr<Window>();
Window *Singleton::window() {
if(!window_)
window_=std::unique_ptr<Window>(new Window());
return window_.get();
}
std::unique_ptr<Gtk::Label> Singleton::status_=std::unique_ptr<Gtk::Label>();
Gtk::Label *Singleton::status() {
if(!status_)
status_=std::unique_ptr<Gtk::Label>(new Gtk::Label());
return status_.get();
}
std::unique_ptr<Gtk::Label> Singleton::info_=std::unique_ptr<Gtk::Label>();
Gtk::Label *Singleton::info() {
if(!info_)
info_=std::unique_ptr<Gtk::Label>(new Gtk::Label());
return info_.get();
}
std::unique_ptr<Menu> Singleton::menu_=std::unique_ptr<Menu>();
Menu *Singleton::menu() {
if(!menu_)
menu_=std::unique_ptr<Menu>(new Menu());
return menu_.get();
} }

43
src/singletons.h

@ -2,50 +2,21 @@
#define JUCI_SINGLETONS_H_ #define JUCI_SINGLETONS_H_
#include <gtkmm.h> #include <gtkmm.h>
#include "filesystem.h"
#include "source.h"
#include "window.h"
#include "directories.h" #include "directories.h"
#include "terminal.h" #include "terminal.h"
#include "notebook.h"
#include "menu.h" #include "menu.h"
#include "window.h"
#include "config.h" #include "config.h"
class Singleton { class Singleton {
public: public:
class Config { static std::unique_ptr<Config> config;
public: static std::unique_ptr<Menu> menu;
static Source::Config *source() {return source_.get();} static std::unique_ptr<Terminal> terminal;
static Directories::Config *directories() {return directories_.get();} static std::unique_ptr<Directories> directories;
static Window::Config *window() { return window_.get(); } static std::unique_ptr<Gtk::Label> info;
static Terminal::Config *terminal() {return terminal_.get();} static std::unique_ptr<Gtk::Label> status;
static Menu::Config *menu() {return menu_.get();}
static MainConfig *main() { return main_.get(); }
private:
static std::unique_ptr<Source::Config> source_;
static std::unique_ptr<Window::Config> window_;
static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Terminal::Config> terminal_;
static std::unique_ptr<Menu::Config> menu_;
static std::unique_ptr<MainConfig> main_;
};
static Terminal *terminal();
static Directories *directories();
static Gtk::Label *status();
static Gtk::Label *info();
static Menu *menu();
static Window *window();
private: static void init();
static std::unique_ptr<Terminal> terminal_;
static std::unique_ptr<Gtk::Label> status_;
static std::unique_ptr<Gtk::Label> info_;
static std::unique_ptr<Directories> directories_;
static std::unique_ptr<Menu> menu_;
static std::unique_ptr<Window> window_;
}; };
#endif // JUCI_SINGLETONS_H_ #endif // JUCI_SINGLETONS_H_

39
src/source.cc

@ -5,6 +5,7 @@
#include <algorithm> #include <algorithm>
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <iostream> #include <iostream>
#include "filesystem.h"
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -86,11 +87,11 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
get_source_buffer()->begin_not_undoable_action(); get_source_buffer()->begin_not_undoable_action();
if(language) { if(language) {
if(filesystem::read_non_utf8(file_path, get_buffer())==-1) if(filesystem::read_non_utf8(file_path, get_buffer())==-1)
Singleton::terminal()->print("Warning: "+file_path.string()+" is not a valid UTF-8 file. Saving might corrupt the file.\n"); Singleton::terminal->print("Warning: "+file_path.string()+" is not a valid UTF-8 file. Saving might corrupt the file.\n");
} }
else { else {
if(filesystem::read(file_path, get_buffer())==-1) if(filesystem::read(file_path, get_buffer())==-1)
Singleton::terminal()->print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n"); Singleton::terminal->print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n");
} }
get_source_buffer()->end_not_undoable_action(); get_source_buffer()->end_not_undoable_action();
@ -262,9 +263,9 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
set_tooltip_events(); set_tooltip_events();
tab_char=Singleton::Config::source()->default_tab_char; tab_char=Singleton::config->source.default_tab_char;
tab_size=Singleton::Config::source()->default_tab_size; tab_size=Singleton::config->source.default_tab_size;
if(Singleton::Config::source()->auto_tab_char_and_size) { if(Singleton::config->source.auto_tab_char_and_size) {
auto tab_char_and_size=find_tab_char_and_size(); auto tab_char_and_size=find_tab_char_and_size();
if(tab_char_and_size.first!=0) { if(tab_char_and_size.first!=0) {
if(tab_char!=tab_char_and_size.first || tab_size!=tab_char_and_size.second) { if(tab_char!=tab_char_and_size.first || tab_size!=tab_char_and_size.second) {
@ -273,7 +274,7 @@ Source::View::View(const boost::filesystem::path &file_path, const boost::filesy
tab_str="<space>"; tab_str="<space>";
else else
tab_str="<tab>"; tab_str="<tab>";
Singleton::terminal()->print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+std::to_string(tab_char_and_size.second)+".\n"); Singleton::terminal->print("Tab char and size for file "+file_path.string()+" set to: "+tab_str+", "+std::to_string(tab_char_and_size.second)+".\n");
} }
tab_char=tab_char_and_size.first; tab_char=tab_char_and_size.first;
@ -295,25 +296,25 @@ void Source::View::set_tab_char_and_size(char tab_char, unsigned tab_size) {
void Source::View::configure() { void Source::View::configure() {
//TODO: Move this to notebook? Might take up too much memory doing this for every tab. //TODO: Move this to notebook? Might take up too much memory doing this for every tab.
auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); auto style_scheme_manager=Gsv::StyleSchemeManager::get_default();
style_scheme_manager->prepend_search_path((Singleton::Config::main()->juci_home_path()/"styles").string()); style_scheme_manager->prepend_search_path((Singleton::config->juci_home_path()/"styles").string());
if(Singleton::Config::source()->style.size()>0) { if(Singleton::config->source.style.size()>0) {
auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->style); auto scheme = style_scheme_manager->get_scheme(Singleton::config->source.style);
if(scheme) if(scheme)
get_source_buffer()->set_style_scheme(scheme); get_source_buffer()->set_style_scheme(scheme);
else else
Singleton::terminal()->print("Error: Could not find gtksourceview style: "+Singleton::Config::source()->style+'\n'); Singleton::terminal->print("Error: Could not find gtksourceview style: "+Singleton::config->source.style+'\n');
} }
if(Singleton::Config::source()->wrap_lines) if(Singleton::config->source.wrap_lines)
set_wrap_mode(Gtk::WrapMode::WRAP_CHAR); set_wrap_mode(Gtk::WrapMode::WRAP_CHAR);
else else
set_wrap_mode(Gtk::WrapMode::WRAP_NONE); set_wrap_mode(Gtk::WrapMode::WRAP_NONE);
property_highlight_current_line() = Singleton::Config::source()->highlight_current_line; property_highlight_current_line() = Singleton::config->source.highlight_current_line;
property_show_line_numbers() = Singleton::Config::source()->show_line_numbers; property_show_line_numbers() = Singleton::config->source.show_line_numbers;
if(Singleton::Config::source()->font.size()>0) if(Singleton::config->source.font.size()>0)
override_font(Pango::FontDescription(Singleton::Config::source()->font)); override_font(Pango::FontDescription(Singleton::config->source.font));
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 15 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 15
gtk_source_view_set_background_pattern(this->gobj(), GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID); gtk_source_view_set_background_pattern(this->gobj(), GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID);
#endif #endif
@ -370,8 +371,8 @@ void Source::View::configure() {
note_tag->property_foreground()=style->property_foreground(); note_tag->property_foreground()=style->property_foreground();
} }
if(Singleton::Config::source()->spellcheck_language.size()>0) if(Singleton::config->source.spellcheck_language.size()>0)
aspell_config_replace(spellcheck_config, "lang", Singleton::Config::source()->spellcheck_language.c_str()); aspell_config_replace(spellcheck_config, "lang", Singleton::config->source.spellcheck_language.c_str());
spellcheck_possible_err=new_aspell_speller(spellcheck_config); spellcheck_possible_err=new_aspell_speller(spellcheck_config);
if(spellcheck_checker!=NULL) if(spellcheck_checker!=NULL)
delete_aspell_speller(spellcheck_checker); delete_aspell_speller(spellcheck_checker);
@ -1273,7 +1274,7 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const
if(language) { if(language) {
get_source_buffer()->set_language(language); get_source_buffer()->set_language(language);
Singleton::terminal()->print("Language for file "+file_path.string()+" set to "+language->get_name()+".\n"); Singleton::terminal->print("Language for file "+file_path.string()+" set to "+language->get_name()+".\n");
} }
auto completion=get_completion(); auto completion=get_completion();
@ -1305,7 +1306,7 @@ Source::GenericView::GenericView(const boost::filesystem::path &file_path, const
boost::property_tree::xml_parser::read_xml(language_file.string(), pt); boost::property_tree::xml_parser::read_xml(language_file.string(), pt);
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Singleton::terminal()->print("Error: error parsing language file "+language_file.string()+": "+e.what()+'\n'); Singleton::terminal->print("Error: error parsing language file "+language_file.string()+": "+e.what()+'\n');
} }
bool has_context_class=false; bool has_context_class=false;
parse_language_file(completion_buffer_keywords, has_context_class, pt); parse_language_file(completion_buffer_keywords, has_context_class, pt);

28
src/source.h

@ -8,39 +8,11 @@
#include <vector> #include <vector>
#include "selectiondialog.h" #include "selectiondialog.h"
#include "terminal.h"
#include "tooltips.h" #include "tooltips.h"
namespace Source { namespace Source {
Glib::RefPtr<Gsv::Language> guess_language(const boost::filesystem::path &file_path); Glib::RefPtr<Gsv::Language> guess_language(const boost::filesystem::path &file_path);
class Config {
public:
class DocumentationSearch {
public:
std::string separator;
std::unordered_map<std::string, std::string> queries;
};
std::string style;
std::string font;
std::string spellcheck_language;
bool show_map;
std::string map_font_size;
bool auto_tab_char_and_size;
char default_tab_char;
unsigned default_tab_size;
bool wrap_lines;
bool highlight_current_line;
bool show_line_numbers;
std::unordered_map<std::string, std::string> clang_types;
std::string clang_format_style;
std::unordered_map<std::string, DocumentationSearch> documentation_searches;
};
class Token { class Token {
public: public:
Token(): type(-1) {} Token(): type(-1) {}

24
src/source_clang.cc

@ -25,14 +25,14 @@ Source::View(file_path, project_path, language), parse_error(false) {
JDEBUG("start"); JDEBUG("start");
auto tag_table=get_buffer()->get_tag_table(); auto tag_table=get_buffer()->get_tag_table();
for (auto &item : Singleton::Config::source()->clang_types) { for (auto &item : Singleton::config->source.clang_types) {
if(!tag_table->lookup(item.second)) { if(!tag_table->lookup(item.second)) {
get_buffer()->create_tag(item.second); get_buffer()->create_tag(item.second);
} }
} }
configure(); configure();
parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path.string()); parsing_in_progress=Singleton::terminal->print_in_progress("Parsing "+file_path.string());
//GTK-calls must happen in main thread, so the parse_thread //GTK-calls must happen in main thread, so the parse_thread
//sends signals to the main thread that it is to call the following functions: //sends signals to the main thread that it is to call the following functions:
parse_start_connection=parse_start.connect([this]{ parse_start_connection=parse_start.connect([this]{
@ -59,7 +59,7 @@ Source::View(file_path, project_path, language), parse_error(false) {
} }
}); });
parse_fail_connection=parse_fail.connect([this](){ parse_fail_connection=parse_fail.connect([this](){
Singleton::terminal()->print("Error: failed to reparse "+this->file_path.string()+".\n"); Singleton::terminal->print("Error: failed to reparse "+this->file_path.string()+".\n");
set_status(""); set_status("");
set_info(""); set_info("");
parsing_in_progress->cancel("failed"); parsing_in_progress->cancel("failed");
@ -80,7 +80,7 @@ void Source::ClangViewParse::configure() {
auto scheme = get_source_buffer()->get_style_scheme(); auto scheme = get_source_buffer()->get_style_scheme();
auto tag_table=get_buffer()->get_tag_table(); auto tag_table=get_buffer()->get_tag_table();
for (auto &item : Singleton::Config::source()->clang_types) { for (auto &item : Singleton::config->source.clang_types) {
auto tag = get_buffer()->get_tag_table()->lookup(item.second); auto tag = get_buffer()->get_tag_table()->lookup(item.second);
if(tag) { if(tag) {
auto style = scheme->get_style(item.second); auto style = scheme->get_style(item.second);
@ -240,8 +240,8 @@ void Source::ClangViewParse::update_syntax() {
buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end()); buffer->remove_tag_by_name(tag, buffer->begin(), buffer->end());
last_syntax_tags.clear(); last_syntax_tags.clear();
for (auto &range : ranges) { for (auto &range : ranges) {
auto type_it=Singleton::Config::source()->clang_types.find(std::to_string(range.kind)); auto type_it=Singleton::config->source.clang_types.find(std::to_string(range.kind));
if(type_it!=Singleton::Config::source()->clang_types.end()) { if(type_it!=Singleton::config->source.clang_types.end()) {
last_syntax_tags.emplace(type_it->second); last_syntax_tags.emplace(type_it->second);
Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1); Gtk::TextIter begin_iter = buffer->get_iter_at_line_index(range.offsets.first.line-1, range.offsets.first.index-1);
Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1); Gtk::TextIter end_iter = buffer->get_iter_at_line_index(range.offsets.second.line-1, range.offsets.second.index-1);
@ -649,7 +649,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_cancel_s
}); });
autocomplete_fail_connection=autocomplete_fail.connect([this]() { autocomplete_fail_connection=autocomplete_fail.connect([this]() {
Singleton::terminal()->print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n"); Singleton::terminal->print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n");
restart_parse(); restart_parse();
autocomplete_starting=false; autocomplete_starting=false;
autocomplete_cancel_starting=false; autocomplete_cancel_starting=false;
@ -924,7 +924,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
}); });
auto_indent=[this]() { auto_indent=[this]() {
auto command=Singleton::Config::terminal()->clang_format_command; auto command=Singleton::config->terminal.clang_format_command;
unsigned indent_width; unsigned indent_width;
std::string tab_style; std::string tab_style;
if(tab_char=='\t') { if(tab_char=='\t') {
@ -938,13 +938,13 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
command+=" -style=\"{IndentWidth: "+std::to_string(indent_width); command+=" -style=\"{IndentWidth: "+std::to_string(indent_width);
command+=", "+tab_style; command+=", "+tab_style;
command+=", "+std::string("AccessModifierOffset: -")+std::to_string(indent_width); command+=", "+std::string("AccessModifierOffset: -")+std::to_string(indent_width);
if(Singleton::Config::source()->clang_format_style!="") if(Singleton::config->source.clang_format_style!="")
command+=", "+Singleton::Config::source()->clang_format_style; command+=", "+Singleton::config->source.clang_format_style;
command+="}\""; command+="}\"";
std::stringstream stdin_stream(get_buffer()->get_text()), stdout_stream; std::stringstream stdin_stream(get_buffer()->get_text()), stdout_stream;
auto exit_code=Singleton::terminal()->execute(stdin_stream, stdout_stream, command); auto exit_code=Singleton::terminal->execute(stdin_stream, stdout_stream, command);
if(exit_code==0) { if(exit_code==0) {
get_source_buffer()->begin_user_action(); get_source_buffer()->begin_user_action();
auto iter=get_buffer()->get_insert()->get_iter(); auto iter=get_buffer()->get_insert()->get_iter();
@ -1107,7 +1107,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
auto usr=referenced.get_usr(); auto usr=referenced.get_usr();
boost::filesystem::path referenced_path=referenced.get_source_location().get_path(); boost::filesystem::path referenced_path=referenced.get_source_location().get_path();
//Singleton::terminal()->print(usr+'\n', true); //TODO: remove //Singleton::terminal->print(usr+'\n', true); //TODO: remove
//Return empty if referenced is within project //Return empty if referenced is within project
if(referenced_path.generic_string().substr(0, this->project_path.generic_string().size()+1)==this->project_path.generic_string()+'/') if(referenced_path.generic_string().substr(0, this->project_path.generic_string().size()+1)==this->project_path.generic_string()+'/')

1
src/source_clang.h

@ -8,6 +8,7 @@
#include <regex> #include <regex>
#include "clangmm.h" #include "clangmm.h"
#include "source.h" #include "source.h"
#include "terminal.h"
namespace Source { namespace Source {
class ClangViewParse : public View { class ClangViewParse : public View {

12
src/terminal.cc

@ -84,7 +84,7 @@ pid_t popen3(const std::string &command, const std::string &path, int *stdin_fd,
Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) { Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
waiting_print.connect([this](){ waiting_print.connect([this](){
Singleton::terminal()->async_print(line_nr-1, "."); Singleton::terminal->async_print(line_nr-1, ".");
}); });
start(start_msg); start(start_msg);
} }
@ -96,7 +96,7 @@ Terminal::InProgress::~InProgress() {
} }
void Terminal::InProgress::start(const std::string& msg) { void Terminal::InProgress::start(const std::string& msg) {
line_nr=Singleton::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) {
@ -111,14 +111,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;
Singleton::terminal()->async_print(line_nr-1, msg); Singleton::terminal->async_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;
Singleton::terminal()->async_print(line_nr-1, msg); Singleton::terminal->async_print(line_nr-1, msg);
} }
} }
@ -357,8 +357,8 @@ size_t Terminal::print(const std::string &message, bool bold){
else else
get_buffer()->insert(get_buffer()->end(), umessage); get_buffer()->insert(get_buffer()->end(), umessage);
if(get_buffer()->get_line_count()>Singleton::Config::terminal()->history_size) { if(get_buffer()->get_line_count()>Singleton::config->terminal.history_size) {
int lines=get_buffer()->get_line_count()-Singleton::Config::terminal()->history_size; int lines=get_buffer()->get_line_count()-Singleton::config->terminal.history_size;
get_buffer()->erase(get_buffer()->begin(), get_buffer()->get_iter_at_line(lines)); get_buffer()->erase(get_buffer()->begin(), get_buffer()->get_iter_at_line(lines));
deleted_lines+=static_cast<size_t>(lines); deleted_lines+=static_cast<size_t>(lines);
} }

8
src/terminal.h

@ -12,14 +12,6 @@
class Terminal : public Gtk::TextView { class Terminal : public Gtk::TextView {
public: public:
class Config {
public:
std::string cmake_command;
std::string make_command;
std::string clang_format_command;
int history_size;
};
class InProgress { class InProgress {
public: public:
InProgress(const std::string& start_msg); InProgress(const std::string& start_msg);

12
src/terminal_win.cc

@ -129,7 +129,7 @@ HANDLE popen3(const std::string &command, const std::string &path, HANDLE *stdin
Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) { Terminal::InProgress::InProgress(const std::string& start_msg): stop(false) {
waiting_print.connect([this](){ waiting_print.connect([this](){
Singleton::terminal()->async_print(line_nr-1, "."); Singleton::terminal->async_print(line_nr-1, ".");
}); });
start(start_msg); start(start_msg);
} }
@ -141,7 +141,7 @@ Terminal::InProgress::~InProgress() {
} }
void Terminal::InProgress::start(const std::string& msg) { void Terminal::InProgress::start(const std::string& msg) {
line_nr=Singleton::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) {
@ -156,14 +156,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;
Singleton::terminal()->async_print(line_nr-1, msg); Singleton::terminal->async_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;
Singleton::terminal()->async_print(line_nr-1, msg); Singleton::terminal->async_print(line_nr-1, msg);
} }
} }
@ -427,8 +427,8 @@ size_t Terminal::print(const std::string &message, bool bold){
else else
get_buffer()->insert(get_buffer()->end(), umessage); get_buffer()->insert(get_buffer()->end(), umessage);
if(get_buffer()->get_line_count()>Singleton::Config::terminal()->history_size) { if(get_buffer()->get_line_count()>Singleton::config->terminal.history_size) {
int lines=get_buffer()->get_line_count()-Singleton::Config::terminal()->history_size; int lines=get_buffer()->get_line_count()-Singleton::config->terminal.history_size;
get_buffer()->erase(get_buffer()->begin(), get_buffer()->get_iter_at_line(lines)); get_buffer()->erase(get_buffer()->begin(), get_buffer()->get_iter_at_line(lines));
deleted_lines+=static_cast<size_t>(lines); deleted_lines+=static_cast<size_t>(lines);
} }

1
src/tooltips.cc

@ -1,5 +1,4 @@
#include "tooltips.h" #include "tooltips.h"
#include "singletons.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove

130
src/window.cc

@ -1,9 +1,9 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
#include "singletons.h" #include "singletons.h"
#include "config.h"
//#include "api.h" //#include "api.h"
#include "dialogs.h" #include "dialogs.h"
#include "filesystem.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -28,39 +28,39 @@ Window::Window() : compiling(false) {
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);
set_menu_actions(); set_menu_actions();
configure(); configure();
set_default_size(Singleton::Config::window()->default_size.first, Singleton::Config::window()->default_size.second); set_default_size(Singleton::config->window.default_size.first, Singleton::config->window.default_size.second);
//PluginApi(&this->notebook, &this->menu); //PluginApi(&this->notebook, &this->menu);
add(vpaned); add(vpaned);
directory_and_notebook_panes.pack1(*Singleton::directories(), Gtk::SHRINK); directory_and_notebook_panes.pack1(*Singleton::directories, Gtk::SHRINK);
notebook_vbox.pack_start(notebook); notebook_vbox.pack_start(notebook);
notebook_vbox.pack_end(entry_box, Gtk::PACK_SHRINK); notebook_vbox.pack_end(entry_box, Gtk::PACK_SHRINK);
directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK); directory_and_notebook_panes.pack2(notebook_vbox, Gtk::SHRINK);
directory_and_notebook_panes.set_position(static_cast<int>(0.2*Singleton::Config::window()->default_size.first)); directory_and_notebook_panes.set_position(static_cast<int>(0.2*Singleton::config->window.default_size.first));
vpaned.set_position(static_cast<int>(0.75*Singleton::Config::window()->default_size.second)); vpaned.set_position(static_cast<int>(0.75*Singleton::config->window.default_size.second));
vpaned.pack1(directory_and_notebook_panes, true, false); vpaned.pack1(directory_and_notebook_panes, true, false);
terminal_scrolled_window.add(*Singleton::terminal()); terminal_scrolled_window.add(*Singleton::terminal);
terminal_vbox.pack_start(terminal_scrolled_window); terminal_vbox.pack_start(terminal_scrolled_window);
info_and_status_hbox.pack_start(*Singleton::info(), Gtk::PACK_SHRINK); info_and_status_hbox.pack_start(*Singleton::info, Gtk::PACK_SHRINK);
info_and_status_hbox.pack_end(*Singleton::status(), Gtk::PACK_SHRINK); info_and_status_hbox.pack_end(*Singleton::status, Gtk::PACK_SHRINK);
terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK); terminal_vbox.pack_end(info_and_status_hbox, Gtk::PACK_SHRINK);
vpaned.pack2(terminal_vbox, true, true); vpaned.pack2(terminal_vbox, true, true);
show_all_children(); show_all_children();
Singleton::directories()->on_row_activated=[this](const std::string &file) { Singleton::directories->on_row_activated=[this](const std::string &file) {
notebook.open(file); notebook.open(file);
}; };
//Scroll to end of terminal whenever info is printed //Scroll to end of terminal whenever info is printed
Singleton::terminal()->signal_size_allocate().connect([this](Gtk::Allocation& allocation){ Singleton::terminal->signal_size_allocate().connect([this](Gtk::Allocation& allocation){
auto adjustment=terminal_scrolled_window.get_vadjustment(); auto adjustment=terminal_scrolled_window.get_vadjustment();
adjustment->set_value(adjustment->get_upper()-adjustment->get_page_size()); adjustment->set_value(adjustment->get_upper()-adjustment->get_page_size());
Singleton::terminal()->queue_draw(); Singleton::terminal->queue_draw();
}); });
entry_box.signal_show().connect([this](){ entry_box.signal_show().connect([this](){
@ -90,7 +90,7 @@ Window::Window() : compiling(false) {
activate_menu_items(); activate_menu_items();
Singleton::directories()->select(notebook.get_current_view()->file_path); Singleton::directories->select(notebook.get_current_view()->file_path);
if(auto source_view=dynamic_cast<Source::ClangView*>(notebook.get_current_view())) { if(auto source_view=dynamic_cast<Source::ClangView*>(notebook.get_current_view())) {
if(source_view->reparse_needed) { if(source_view->reparse_needed) {
@ -111,7 +111,7 @@ Window::Window() : compiling(false) {
about.hide(); about.hide();
}); });
about.set_version(Singleton::Config::window()->version); about.set_version(Singleton::config->window.version);
about.set_authors({"(in order of appearance)", about.set_authors({"(in order of appearance)",
"Ted Johan Kristoffersen", "Ted Johan Kristoffersen",
"Jørgen Lien Sellæg", "Jørgen Lien Sellæg",
@ -126,27 +126,25 @@ Window::Window() : compiling(false) {
} // Window constructor } // Window constructor
void Window::configure() { void Window::configure() {
Singleton::Config::main()->read(); Singleton::config->load();
auto style_context = Gtk::StyleContext::create(); auto style_context = Gtk::StyleContext::create();
auto screen = Gdk::Screen::get_default(); auto screen = Gdk::Screen::get_default();
auto css_provider = Gtk::CssProvider::get_named(Singleton::Config::window()->theme_name, Singleton::Config::window()->theme_variant); auto css_provider = Gtk::CssProvider::get_named(Singleton::config->window.theme_name, Singleton::config->window.theme_variant);
//TODO: add check if theme exists, or else write error to Singleton::terminal() //TODO: add check if theme exists, or else write error to Singleton::terminal
style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS); style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
if(Singleton::directories() != nullptr) { Singleton::directories->update();
Singleton::directories()->update(); Singleton::menu->set_keys();
}
Singleton::menu()->set_keys();
} }
void Window::set_menu_actions() { void Window::set_menu_actions() {
auto menu = Singleton::menu(); auto &menu = Singleton::menu;
menu->add_action("about", [this]() { menu->add_action("about", [this]() {
about.show(); about.show();
about.present(); about.present();
}); });
menu->add_action("preferences", [this]() { menu->add_action("preferences", [this]() {
notebook.open(Singleton::Config::main()->juci_home_path()/"config"/"config.json"); notebook.open(Singleton::config->juci_home_path()/"config"/"config.json");
}); });
menu->add_action("quit", [this]() { menu->add_action("quit", [this]() {
hide(); hide();
@ -156,17 +154,17 @@ void Window::set_menu_actions() {
boost::filesystem::path path = Dialog::new_file(); boost::filesystem::path path = Dialog::new_file();
if(path!="") { if(path!="") {
if(boost::filesystem::exists(path)) { if(boost::filesystem::exists(path)) {
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); Singleton::terminal->print("Error: "+path.string()+" already exists.\n");
} }
else { else {
if(filesystem::write(path)) { if(filesystem::write(path)) {
if(Singleton::directories()->current_path!="") if(Singleton::directories->current_path!="")
Singleton::directories()->update(); Singleton::directories->update();
notebook.open(path.string()); notebook.open(path.string());
Singleton::terminal()->print("New file "+path.string()+" created.\n"); Singleton::terminal->print("New file "+path.string()+" created.\n");
} }
else else
Singleton::terminal()->print("Error: could not create new file "+path.string()+".\n"); Singleton::terminal->print("Error: could not create new file "+path.string()+".\n");
} }
} }
}); });
@ -175,13 +173,13 @@ void Window::set_menu_actions() {
boost::filesystem::path path = Dialog::new_folder(); boost::filesystem::path path = Dialog::new_folder();
if(path!="" && boost::filesystem::exists(path)) { if(path!="" && boost::filesystem::exists(path)) {
if(boost::filesystem::last_write_time(path)>=time_now) { if(boost::filesystem::last_write_time(path)>=time_now) {
if(Singleton::directories()->current_path!="") if(Singleton::directories->current_path!="")
Singleton::directories()->update(); Singleton::directories->update();
Singleton::terminal()->print("New folder "+path.string()+" created.\n"); Singleton::terminal->print("New folder "+path.string()+" created.\n");
} }
else else
Singleton::terminal()->print("Error: "+path.string()+" already exists.\n"); Singleton::terminal->print("Error: "+path.string()+" already exists.\n");
Singleton::directories()->select(path); Singleton::directories->select(path);
} }
}); });
menu->add_action("new_project_cpp", [this]() { menu->add_action("new_project_cpp", [this]() {
@ -197,22 +195,22 @@ void Window::set_menu_actions() {
auto cpp_main_path=project_path; auto cpp_main_path=project_path;
cpp_main_path+="/main.cpp"; cpp_main_path+="/main.cpp";
if(boost::filesystem::exists(cmakelists_path)) { if(boost::filesystem::exists(cmakelists_path)) {
Singleton::terminal()->print("Error: "+cmakelists_path.string()+" already exists.\n"); Singleton::terminal->print("Error: "+cmakelists_path.string()+" already exists.\n");
return; return;
} }
if(boost::filesystem::exists(cpp_main_path)) { if(boost::filesystem::exists(cpp_main_path)) {
Singleton::terminal()->print("Error: "+cpp_main_path.string()+" already exists.\n"); Singleton::terminal->print("Error: "+cpp_main_path.string()+" already exists.\n");
return; return;
} }
std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n"; std::string cmakelists="cmake_minimum_required(VERSION 2.8)\n\nproject("+project_name+")\n\nset(CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -std=c++1y -Wall\")\n\nadd_executable("+project_name+" main.cpp)\n";
std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n"; std::string cpp_main="#include <iostream>\n\nusing namespace std;\n\nint main() {\n cout << \"Hello World!\" << endl;\n\n return 0;\n}\n";
if(filesystem::write(cmakelists_path, cmakelists) && filesystem::write(cpp_main_path, cpp_main)) { if(filesystem::write(cmakelists_path, cmakelists) && filesystem::write(cpp_main_path, cpp_main)) {
Singleton::directories()->open(project_path); Singleton::directories->open(project_path);
notebook.open(cpp_main_path); notebook.open(cpp_main_path);
Singleton::terminal()->print("C++ project "+project_name+" created.\n"); Singleton::terminal->print("C++ project "+project_name+" created.\n");
} }
else else
Singleton::terminal()->print("Error: Could not create project "+project_path.string()+"\n"); Singleton::terminal->print("Error: Could not create project "+project_path.string()+"\n");
} }
}); });
@ -224,14 +222,14 @@ void Window::set_menu_actions() {
menu->add_action("open_folder", [this]() { menu->add_action("open_folder", [this]() {
auto path = Dialog::select_folder(); auto path = Dialog::select_folder();
if (path!="" && boost::filesystem::exists(path)) if (path!="" && boost::filesystem::exists(path))
Singleton::directories()->open(path); Singleton::directories->open(path);
}); });
menu->add_action("save", [this]() { menu->add_action("save", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.save_current()) { if(notebook.save_current()) {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->file_path==Singleton::Config::main()->juci_home_path()/"config"/"config.json") { if(notebook.get_current_view()->file_path==Singleton::config->juci_home_path()/"config"/"config.json") {
configure(); configure();
for(int c=0;c<notebook.size();c++) { for(int c=0;c<notebook.size();c++) {
notebook.get_view(c)->configure(); notebook.get_view(c)->configure();
@ -244,19 +242,19 @@ void Window::set_menu_actions() {
}); });
menu->add_action("save_as", [this]() { menu->add_action("save_as", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto path = Dialog::save_file(); auto path = Dialog::save_file(notebook.get_current_view()->file_path);
if(path!="") { if(path!="") {
std::ofstream file(path); std::ofstream file(path);
if(file) { if(file) {
file << notebook.get_current_view()->get_buffer()->get_text(); file << notebook.get_current_view()->get_buffer()->get_text();
file.close(); file.close();
if(Singleton::directories()->current_path!="") if(Singleton::directories->current_path!="")
Singleton::directories()->update(); Singleton::directories->update();
notebook.open(path); notebook.open(path);
Singleton::terminal()->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n"); Singleton::terminal->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n");
} }
else else
Singleton::terminal()->print("Error saving file\n"); Singleton::terminal->print("Error saving file\n");
} }
} }
}); });
@ -344,8 +342,8 @@ void Window::set_menu_actions() {
if(notebook.get_current_view()->get_token_data) { if(notebook.get_current_view()->get_token_data) {
auto data=notebook.get_current_view()->get_token_data(); auto data=notebook.get_current_view()->get_token_data();
if(data.size()>0) { if(data.size()>0) {
auto documentation_search=Singleton::Config::source()->documentation_searches.find(data[0]); auto documentation_search=Singleton::config->source.documentation_searches.find(data[0]);
if(documentation_search!=Singleton::Config::source()->documentation_searches.end()) { if(documentation_search!=Singleton::config->source.documentation_searches.end()) {
std::string token_query; std::string token_query;
for(size_t c=1;c<data.size();c++) { for(size_t c=1;c<data.size();c++) {
if(data[c].size()>0) { if(data[c].size()>0) {
@ -366,7 +364,7 @@ void Window::set_menu_actions() {
if(query!=documentation_search->second.queries.end()) { if(query!=documentation_search->second.queries.end()) {
std::string uri=query->second+token_query; std::string uri=query->second+token_query;
#ifdef __APPLE__ #ifdef __APPLE__
Singleton::terminal()->execute("open \""+uri+"\""); Singleton::terminal->execute("open \""+uri+"\"");
#else #else
GError* error=NULL; GError* error=NULL;
gtk_show_uri(NULL, uri.c_str(), GDK_CURRENT_TIME, &error); gtk_show_uri(NULL, uri.c_str(), GDK_CURRENT_TIME, &error);
@ -446,9 +444,9 @@ void Window::set_menu_actions() {
if(cmake.project_path!="") { if(cmake.project_path!="") {
if(executable_path!="") { if(executable_path!="") {
compiling=true; compiling=true;
Singleton::terminal()->print("Compiling and running "+executable_path.string()+"\n"); Singleton::terminal->print("Compiling and running "+executable_path.string()+"\n");
auto project_path=cmake.project_path; auto project_path=cmake.project_path;
Singleton::terminal()->async_execute(Singleton::Config::terminal()->make_command, cmake.project_path, [this, executable_path, project_path](int exit_code){ Singleton::terminal->async_execute(Singleton::config->terminal.make_command, cmake.project_path, [this, executable_path, project_path](int exit_code){
compiling=false; compiling=false;
if(exit_code==EXIT_SUCCESS) { if(exit_code==EXIT_SUCCESS) {
auto executable_path_spaces_fixed=executable_path.string(); auto executable_path_spaces_fixed=executable_path.string();
@ -460,16 +458,16 @@ void Window::set_menu_actions() {
} }
last_char=executable_path_spaces_fixed[c]; last_char=executable_path_spaces_fixed[c];
} }
Singleton::terminal()->async_execute(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_code){ Singleton::terminal->async_execute(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_code){
Singleton::terminal()->async_print(executable_path.string()+" returned: "+std::to_string(exit_code)+'\n'); Singleton::terminal->async_print(executable_path.string()+" returned: "+std::to_string(exit_code)+'\n');
}); });
} }
}); });
} }
else { else {
Singleton::terminal()->print("Could not find add_executable in the following paths:\n"); Singleton::terminal->print("Could not find add_executable in the following paths:\n");
for(auto &path: cmake.paths) for(auto &path: cmake.paths)
Singleton::terminal()->print(" "+path.string()+"\n"); Singleton::terminal->print(" "+path.string()+"\n");
} }
} }
}); });
@ -479,8 +477,8 @@ void Window::set_menu_actions() {
CMake cmake(notebook.get_current_view()->file_path); CMake cmake(notebook.get_current_view()->file_path);
if(cmake.project_path!="") { if(cmake.project_path!="") {
compiling=true; compiling=true;
Singleton::terminal()->print("Compiling project "+cmake.project_path.string()+"\n"); Singleton::terminal->print("Compiling project "+cmake.project_path.string()+"\n");
Singleton::terminal()->async_execute(Singleton::Config::terminal()->make_command, cmake.project_path, [this](int exit_code){ Singleton::terminal->async_execute(Singleton::config->terminal.make_command, cmake.project_path, [this](int exit_code){
compiling=false; compiling=false;
}); });
} }
@ -505,11 +503,11 @@ void Window::set_menu_actions() {
run_path=notebook.get_current_view()->file_path.parent_path(); run_path=notebook.get_current_view()->file_path.parent_path();
} }
else else
run_path=Singleton::directories()->current_path; run_path=Singleton::directories->current_path;
Singleton::terminal()->async_print("Running: "+content+'\n'); Singleton::terminal->async_print("Running: "+content+'\n');
Singleton::terminal()->async_execute(content, run_path, [this, content](int exit_code){ Singleton::terminal->async_execute(content, run_path, [this, content](int exit_code){
Singleton::terminal()->async_print(content+" returned: "+std::to_string(exit_code)+'\n'); Singleton::terminal->async_print(content+" returned: "+std::to_string(exit_code)+'\n');
}); });
} }
entry_box.hide(); entry_box.hide();
@ -523,10 +521,10 @@ void Window::set_menu_actions() {
}); });
menu->add_action("kill_last_running", [this]() { menu->add_action("kill_last_running", [this]() {
Singleton::terminal()->kill_last_async_execute(); Singleton::terminal->kill_last_async_execute();
}); });
menu->add_action("force_kill_last_running", [this]() { menu->add_action("force_kill_last_running", [this]() {
Singleton::terminal()->kill_last_async_execute(true); Singleton::terminal->kill_last_async_execute(true);
}); });
menu->add_action("next_tab", [this]() { menu->add_action("next_tab", [this]() {
@ -549,8 +547,8 @@ void Window::set_menu_actions() {
notebook.get_current_view()->set_info(notebook.get_current_view()->info); notebook.get_current_view()->set_info(notebook.get_current_view()->info);
} }
else { else {
Singleton::status()->set_text(""); Singleton::status->set_text("");
Singleton::info()->set_text(""); Singleton::info->set_text("");
activate_menu_items(false); activate_menu_items(false);
} }
@ -559,7 +557,7 @@ void Window::set_menu_actions() {
} }
void Window::activate_menu_items(bool activate) { void Window::activate_menu_items(bool activate) {
auto menu = Singleton::menu(); auto &menu = Singleton::menu;
menu->actions["source_indentation_auto_indent_buffer"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->auto_indent) : false); menu->actions["source_indentation_auto_indent_buffer"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->auto_indent) : false);
menu->actions["source_find_documentation"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_token_data) : false); menu->actions["source_find_documentation"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_token_data) : false);
menu->actions["source_goto_declaration"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_declaration_location) : false); menu->actions["source_goto_declaration"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_declaration_location) : false);
@ -614,7 +612,7 @@ void Window::hide() {
if(!notebook.close_current_page()) if(!notebook.close_current_page())
return; return;
} }
Singleton::terminal()->kill_async_executes(); Singleton::terminal->kill_async_executes();
Gtk::Window::hide(); Gtk::Window::hide();
} }
@ -816,7 +814,7 @@ void Window::rename_token_entry() {
if(view->rename_similar_tokens) { if(view->rename_similar_tokens) {
auto number=view->rename_similar_tokens(*token, content); auto number=view->rename_similar_tokens(*token, content);
if(number>0) { if(number>0) {
Singleton::terminal()->print("Replaced "+std::to_string(number)+" occurrences in file "+view->file_path.string()+"\n"); Singleton::terminal->print("Replaced "+std::to_string(number)+" occurrences in file "+view->file_path.string()+"\n");
notebook.save(c); notebook.save(c);
} }
} }

8
src/window.h

@ -2,7 +2,6 @@
#define JUCI_WINDOW_H_ #define JUCI_WINDOW_H_
#include "gtkmm.h" #include "gtkmm.h"
#include "directories.h"
#include "entrybox.h" #include "entrybox.h"
#include "notebook.h" #include "notebook.h"
#include <atomic> #include <atomic>
@ -11,13 +10,6 @@ class Window : public Gtk::ApplicationWindow {
public: public:
Window(); Window();
Notebook notebook; Notebook notebook;
class Config {
public:
std::string theme_name;
std::string theme_variant;
std::string version;
std::pair<int, int> default_size;
};
protected: protected:
bool on_key_press_event(GdkEventKey *event); bool on_key_press_event(GdkEventKey *event);

Loading…
Cancel
Save