Browse Source

New singleton system without a singleton container class.

merge-requests/365/head
eidheim 10 years ago
parent
commit
1675305884
  1. 2
      src/CMakeLists.txt
  2. 5
      src/cmake.cc
  3. 4
      src/config.cc
  4. 9
      src/config.h
  5. 15
      src/dialogs.cc
  6. 2
      src/directories.cc
  7. 6
      src/directories.h
  8. 43
      src/juci.cc
  9. 5
      src/juci.h
  10. 11
      src/menu.cc
  11. 8
      src/menu.h
  12. 39
      src/notebook.cc
  13. 4
      src/notebook.h
  14. 20
      src/singletons.cc
  15. 22
      src/singletons.h
  16. 41
      src/source.cc
  17. 4
      src/source.h
  18. 27
      src/source_clang.cc
  19. 14
      src/terminal.cc
  20. 7
      src/terminal.h
  21. 224
      src/window.cc
  22. 8
      src/window.h

2
src/CMakeLists.txt

@ -69,8 +69,6 @@ set(source_files juci.h
terminal.cc terminal.cc
tooltips.h tooltips.h
tooltips.cc tooltips.cc
singletons.h
singletons.cc
cmake.h cmake.h
cmake.cc cmake.cc
dialogs.cc dialogs.cc

5
src/cmake.cc

@ -1,7 +1,8 @@
#include "cmake.h" #include "cmake.h"
#include "singletons.h"
#include "filesystem.h" #include "filesystem.h"
#include "dialogs.h" #include "dialogs.h"
#include "config.h"
#include "terminal.h"
#include <boost/regex.hpp> #include <boost/regex.hpp>
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
@ -47,7 +48,7 @@ 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) {
Dialog::Message message("Creating "+path.string()+"/compile_commands.json"); Dialog::Message message("Creating "+path.string()+"/compile_commands.json");
auto exit_status=Singleton::terminal->process(Singleton::config->terminal.cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path); auto exit_status=Terminal::get().process(Config::get().terminal.cmake_command+" . -DCMAKE_EXPORT_COMPILE_COMMANDS=ON", path);
message.hide(); message.hide();
if(exit_status==EXIT_SUCCESS) { if(exit_status==EXIT_SUCCESS) {
#ifdef _WIN32 //Temporary fix to MSYS2's libclang #ifdef _WIN32 //Temporary fix to MSYS2's libclang

4
src/config.cc

@ -1,10 +1,10 @@
#include "singletons.h"
#include "config.h" #include "config.h"
#include "logging.h" #include "logging.h"
#include <exception> #include <exception>
#include "files.h" #include "files.h"
#include <iostream> #include <iostream>
#include "filesystem.h" #include "filesystem.h"
#include "terminal.h"
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -38,7 +38,7 @@ void Config::load() {
retrieve_config(); retrieve_config();
} }
catch(const std::exception &e) { catch(const std::exception &e) {
Singleton::terminal->print("Error reading "+config_json+": "+e.what()+"\n"); ::Terminal::get().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);

9
src/config.h

@ -2,7 +2,6 @@
#define JUCI_CONFIG_H_ #define JUCI_CONFIG_H_
#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 <unordered_map> #include <unordered_map>
#include <string> #include <string>
#include <utility> #include <utility>
@ -59,8 +58,14 @@ public:
std::unordered_map<std::string, DocumentationSearch> documentation_searches; std::unordered_map<std::string, DocumentationSearch> documentation_searches;
}; };
private:
Config(); Config();
public:
static Config &get() {
static Config singleton;
return singleton;
}
void load(); void load();
Menu menu; Menu menu;

15
src/dialogs.cc

@ -1,6 +1,5 @@
#include "dialogs.h" #include "dialogs.h"
#include "juci.h" #include "window.h"
#include "singletons.h"
#include <cmath> #include <cmath>
namespace sigc { namespace sigc {
@ -18,10 +17,7 @@ namespace sigc {
} }
Dialog::Message::Message(const std::string &text): Gtk::MessageDialog(text, false, Gtk::MessageType::MESSAGE_INFO, Gtk::ButtonsType::BUTTONS_NONE, true) { Dialog::Message::Message(const std::string &text): Gtk::MessageDialog(text, false, Gtk::MessageType::MESSAGE_INFO, Gtk::ButtonsType::BUTTONS_NONE, true) {
auto g_application=g_application_get_default(); set_transient_for(::Window::get());
auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Application>::cast_static(gio_application);
set_transient_for(*application->window);
set_position(Gtk::WindowPosition::WIN_POS_CENTER_ON_PARENT); set_position(Gtk::WindowPosition::WIN_POS_CENTER_ON_PARENT);
show_now(); show_now();
@ -36,12 +32,9 @@ std::string Dialog::gtk_dialog(const std::string &title,
const std::string &file_name) { const std::string &file_name) {
Gtk::FileChooserDialog dialog(title, gtk_options); Gtk::FileChooserDialog dialog(title, gtk_options);
auto g_application=g_application_get_default(); //TODO: Post issue that Gio::Application::get_default should return pointer and not Glib::RefPtr dialog.set_transient_for(Window::get());
auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Application>::cast_static(gio_application);
dialog.set_transient_for(*application->window);
auto current_path=application->window->notebook.get_current_folder(); auto current_path=Window::get().notebook.get_current_folder();
boost::system::error_code ec; boost::system::error_code ec;
if(current_path.empty()) if(current_path.empty())
current_path=boost::filesystem::current_path(ec); current_path=boost::filesystem::current_path(ec);

2
src/directories.cc

@ -1,4 +1,4 @@
#include "singletons.h" #include "directories.h"
#include "logging.h" #include "logging.h"
#include <algorithm> #include <algorithm>
#include <unordered_set> #include <unordered_set>

6
src/directories.h

@ -26,7 +26,13 @@ public:
Gtk::TreeModelColumn<Gdk::RGBA> color; Gtk::TreeModelColumn<Gdk::RGBA> color;
}; };
private:
Directories(); Directories();
public:
static Directories &get() {
static Directories singleton;
return singleton;
}
~Directories(); ~Directories();
void open(const boost::filesystem::path& dir_path=""); void open(const boost::filesystem::path& dir_path="");
void update(); void update();

43
src/juci.cc

@ -1,16 +1,12 @@
#include "juci.h" #include "juci.h"
#include "singletons.h" #include "window.h"
#include "directories.h"
#include "menu.h"
#include "config.h"
#include "logging.h"
using namespace std; //TODO: remove using namespace std; //TODO: remove
void Application::init_logging() {
boost::log::add_common_attributes();
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::keywords::auto_flush = true);
JINFO("Logging initalized");
}
int Application::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 ...]");
@ -39,7 +35,7 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
files.emplace_back(new_p); files.emplace_back(new_p);
} }
else else
Singleton::terminal->print("Error: folder path "+parent_p.string()+" does not exist.\n", true); Terminal::get().print("Error: folder path "+parent_p.string()+" does not exist.\n", true);
} }
} }
} }
@ -48,12 +44,12 @@ int Application::on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine>
} }
void Application::on_activate() { void Application::on_activate() {
add_window(*window); add_window(Window::get());
window->show(); Window::get().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); Directories::get().open(directory);
first_directory=false; first_directory=false;
} }
else { else {
@ -67,25 +63,24 @@ void Application::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+"\n"); Terminal::get().async_print("Executing: juci "+directory.string()+files_in_directory+"\n");
Singleton::terminal->process("juci "+directory.string()+files_in_directory, "", false); Terminal::get().process("juci "+directory.string()+files_in_directory, "", false);
}); });
another_juci_app.detach(); another_juci_app.detach();
} }
} }
for(auto &file: files) for(auto &file: files)
window->notebook.open(file); Window::get().notebook.open(file);
} }
void Application::on_startup() { void Application::on_startup() {
Gtk::Application::on_startup(); Gtk::Application::on_startup();
Singleton::menu->init(); Menu::get().build();
Singleton::menu->build();
auto object = Singleton::menu->builder->get_object("juci-menu"); auto object = Menu::get().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 = Menu::get().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;
@ -97,15 +92,15 @@ void Application::on_startup() {
} }
Application::Application() : 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(); boost::log::add_common_attributes();
init_logging(); auto log_dir = Config::get().juci_home_path()/"log"/"juci.log";
boost::log::add_file_log(boost::log::keywords::file_name = log_dir, boost::log::keywords::auto_flush = true);
JINFO("Logging initalized");
Glib::set_application_name("juCi++"); Glib::set_application_name("juCi++");
//Gtk::MessageDialog without buttons caused text to be selected, this prevents that //Gtk::MessageDialog without buttons caused text to be selected, this prevents that
Gtk::Settings::get_default()->property_gtk_label_select_on_focus()=false; Gtk::Settings::get_default()->property_gtk_label_select_on_focus()=false;
window=std::unique_ptr<Window>(new Window());
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {

5
src/juci.h

@ -2,8 +2,7 @@
#define JUCI_JUCI_H_ #define JUCI_JUCI_H_
#include <gtkmm.h> #include <gtkmm.h>
#include "logging.h" #include <boost/filesystem.hpp>
#include "window.h"
class Application : public Gtk::Application { class Application : public Gtk::Application {
public: public:
@ -11,11 +10,9 @@ public:
int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) override; int on_command_line(const Glib::RefPtr<Gio::ApplicationCommandLine> &cmd) override;
void on_activate() override; void on_activate() override;
void on_startup() override; void on_startup() override;
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();
}; };
#endif // JUCI_JUCI_H_ #endif // JUCI_JUCI_H_

11
src/menu.cc

@ -1,16 +1,13 @@
#include "menu.h" #include "menu.h"
#include "singletons.h" #include "config.h"
#include <string> #include <string>
#include <iostream> #include <iostream>
using namespace std; //TODO: remove using namespace std; //TODO: remove
//TODO: if Ubuntu ever gets fixed, cleanup the Ubuntu specific code
Menu::Menu() { Menu::Menu() {
} auto accels=Config::get().menu.keys;
//TODO: if Ubuntu ever gets fixed, move to constructor, also cleanup the rest of the Ubuntu specific code
void Menu::init() {
auto accels=Singleton::config->menu.keys;
for(auto &accel: accels) { for(auto &accel: accels) {
#ifdef JUCI_UBUNTU_BUGGED_MENU #ifdef JUCI_UBUNTU_BUGGED_MENU
size_t pos=0; size_t pos=0;
@ -312,7 +309,7 @@ void Menu::set_keys() {
auto gio_application=Glib::wrap(g_application, true); auto gio_application=Glib::wrap(g_application, true);
auto application=Glib::RefPtr<Gtk::Application>::cast_static(gio_application); auto application=Glib::RefPtr<Gtk::Application>::cast_static(gio_application);
for(auto &key: Singleton::config->menu.keys) { for(auto &key: Config::get().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);

8
src/menu.h

@ -6,9 +6,13 @@
#include <gtkmm.h> #include <gtkmm.h>
class Menu { class Menu {
public: private:
Menu(); Menu();
void init(); //For Ubuntu 14... public:
static Menu &get() {
static Menu singleton;
return singleton;
}
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;

39
src/notebook.cc

@ -1,5 +1,6 @@
#include "singletons.h"
#include "notebook.h" #include "notebook.h"
#include "config.h"
#include "directories.h"
#include "logging.h" #include "logging.h"
#include <fstream> #include <fstream>
#include <regex> #include <regex>
@ -92,7 +93,7 @@ void Notebook::open(const boost::filesystem::path &file_path) {
if(boost::filesystem::exists(file_path)) { if(boost::filesystem::exists(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", true); Terminal::get().print("Error: could not open "+file_path.string()+"\n", true);
return; return;
} }
can_read.close(); can_read.close();
@ -100,15 +101,15 @@ void Notebook::open(const boost::filesystem::path &file_path) {
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=Directories::get();
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 {
project_path=file_path.parent_path(); project_path=file_path.parent_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"); Terminal::get().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")) {
@ -119,13 +120,13 @@ void Notebook::open(const boost::filesystem::path &file_path) {
else else
source_views.emplace_back(new Source::GenericView(file_path, project_path, language)); source_views.emplace_back(new Source::GenericView(file_path, project_path, language));
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_text) {
if(get_current_page()!=-1 && get_current_view()==view) if(get_current_page()!=-1 && get_current_view()==view)
Singleton::status->set_text(status+" "); status.set_text(status_text+" ");
}; };
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_text) {
if(get_current_page()!=-1 && get_current_view()==view) if(get_current_page()!=-1 && get_current_view()==view)
Singleton::info->set_text(" "+info); info.set_text(" "+info_text);
}; };
scrolled_windows.emplace_back(new Gtk::ScrolledWindow()); scrolled_windows.emplace_back(new Gtk::ScrolledWindow());
@ -186,10 +187,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(Config::get().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())+" "+Config::get().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(Config::get().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);
} }
@ -207,7 +208,7 @@ bool Notebook::save(int page) {
auto view=get_view(page); auto view=get_view(page);
if (view->file_path != "" && view->get_buffer()->get_modified()) { if (view->file_path != "" && view->get_buffer()->get_modified()) {
//Remove trailing whitespace characters on save, and add trailing newline if missing //Remove trailing whitespace characters on save, and add trailing newline if missing
if(Singleton::config->source.cleanup_whitespace_characters) { if(Config::get().source.cleanup_whitespace_characters) {
auto buffer=view->get_buffer(); auto buffer=view->get_buffer();
buffer->begin_user_action(); buffer->begin_user_action();
for(int line=0;line<buffer->get_line_count();line++) { for(int line=0;line<buffer->get_line_count();line++) {
@ -249,9 +250,9 @@ bool Notebook::save(int page) {
//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=Directories::get();
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;
} }
else { else {
CMake cmake(view->file_path.parent_path()); CMake cmake(view->file_path.parent_path());
@ -271,7 +272,7 @@ bool Notebook::save(int page) {
JDEBUG("end true"); JDEBUG("end true");
return true; return true;
} }
Singleton::terminal->print("Error: could not save file " +view->file_path.string()+"\n", true); Terminal::get().print("Error: could not save file " +view->file_path.string()+"\n", true);
} }
JDEBUG("end false"); JDEBUG("end false");
return false; return false;
@ -335,7 +336,7 @@ boost::filesystem::path Notebook::get_current_folder() {
if(get_current_page()!=-1) if(get_current_page()!=-1)
current_path=get_current_view()->project_path; current_path=get_current_view()->project_path;
else else
current_path=Singleton::directories->current_path; current_path=Directories::get().current_path;
return current_path; return current_path;
} }

4
src/notebook.h

@ -29,7 +29,9 @@ public:
bool save_current(); bool save_current();
void configure(int view_nr); void configure(int view_nr);
boost::filesystem::path get_current_folder(); boost::filesystem::path get_current_folder();
Gtk::Label info;
Gtk::Label status;
private: private:
bool save_modified_dialog(int page); bool save_modified_dialog(int page);
std::vector<Source::View*> source_views; //Is NOT freed in destructor, this is intended for quick program exit. std::vector<Source::View*> source_views; //Is NOT freed in destructor, this is intended for quick program exit.

20
src/singletons.cc

@ -1,20 +0,0 @@
#include "singletons.h"
#include <iostream> //TODO: remove
using namespace std; //TODO: remove
std::unique_ptr<Config> Singleton::config;
std::unique_ptr<Menu> Singleton::menu;
std::unique_ptr<Terminal> Singleton::terminal;
std::unique_ptr<Directories> Singleton::directories;
std::unique_ptr<Gtk::Label> Singleton::info;
std::unique_ptr<Gtk::Label> Singleton::status;
void Singleton::init() {
config=std::unique_ptr<Config>(new Config());
menu=std::unique_ptr<Menu>(new Menu());
terminal=std::unique_ptr<Terminal>(new Terminal());
directories=std::unique_ptr<Directories>(new Directories());
info=std::unique_ptr<Gtk::Label>(new Gtk::Label());
status=std::unique_ptr<Gtk::Label>(new Gtk::Label());
}

22
src/singletons.h

@ -1,22 +0,0 @@
#ifndef JUCI_SINGLETONS_H_
#define JUCI_SINGLETONS_H_
#include <gtkmm.h>
#include "directories.h"
#include "terminal.h"
#include "menu.h"
#include "config.h"
class Singleton {
public:
static std::unique_ptr<Config> config;
static std::unique_ptr<Menu> menu;
static std::unique_ptr<Terminal> terminal;
static std::unique_ptr<Directories> directories;
static std::unique_ptr<Gtk::Label> info;
static std::unique_ptr<Gtk::Label> status;
static void init();
};
#endif // JUCI_SINGLETONS_H_

41
src/source.cc

@ -1,11 +1,12 @@
#include "singletons.h"
#include "source.h" #include "source.h"
#include "config.h"
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include "logging.h" #include "logging.h"
#include <algorithm> #include <algorithm>
#include <gtksourceview/gtksource.h> #include <gtksourceview/gtksource.h>
#include <iostream> #include <iostream>
#include "filesystem.h" #include "filesystem.h"
#include "terminal.h"
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -87,11 +88,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"); Terminal::get().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", true); Terminal::get().print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n", true);
} }
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=Config::get().source.default_tab_char;
tab_size=Singleton::config->source.default_tab_size; tab_size=Config::get().source.default_tab_size;
if(Singleton::config->source.auto_tab_char_and_size) { if(Config::get().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"); Terminal::get().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->juci_home_path()/"styles").string()); style_scheme_manager->prepend_search_path((Config::get().juci_home_path()/"styles").string());
if(Singleton::config->source.style.size()>0) { if(Config::get().source.style.size()>0) {
auto scheme = style_scheme_manager->get_scheme(Singleton::config->source.style); auto scheme = style_scheme_manager->get_scheme(Config::get().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', true); Terminal::get().print("Error: Could not find gtksourceview style: "+Config::get().source.style+'\n', true);
} }
if(Singleton::config->source.wrap_lines) if(Config::get().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() = Config::get().source.highlight_current_line;
property_show_line_numbers() = Singleton::config->source.show_line_numbers; property_show_line_numbers() = Config::get().source.show_line_numbers;
if(Singleton::config->source.font.size()>0) if(Config::get().source.font.size()>0)
override_font(Pango::FontDescription(Singleton::config->source.font)); override_font(Pango::FontDescription(Config::get().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(Config::get().source.spellcheck_language.size()>0) {
aspell_config_replace(spellcheck_config, "lang", Singleton::config->source.spellcheck_language.c_str()); aspell_config_replace(spellcheck_config, "lang", Config::get().source.spellcheck_language.c_str());
aspell_config_replace(spellcheck_config, "encoding", "utf-8"); aspell_config_replace(spellcheck_config, "encoding", "utf-8");
} }
spellcheck_possible_err=new_aspell_speller(spellcheck_config); spellcheck_possible_err=new_aspell_speller(spellcheck_config);
@ -1289,7 +1290,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"); Terminal::get().print("Language for file "+file_path.string()+" set to "+language->get_name()+".\n");
} }
auto completion=get_completion(); auto completion=get_completion();
@ -1321,7 +1322,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', true); Terminal::get().print("Error: error parsing language file "+language_file.string()+": "+e.what()+'\n', true);
} }
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);

4
src/source.h

@ -88,8 +88,8 @@ namespace Source {
std::unique_ptr<SelectionDialog> selection_dialog; std::unique_ptr<SelectionDialog> selection_dialog;
sigc::connection delayed_tooltips_connection; sigc::connection delayed_tooltips_connection;
std::function<void(View* view, const std::string &status)> on_update_status; std::function<void(View* view, const std::string &status_text)> on_update_status;
std::function<void(View* view, const std::string &info)> on_update_info; std::function<void(View* view, const std::string &info_text)> on_update_info;
void set_status(const std::string &status); void set_status(const std::string &status);
void set_info(const std::string &info); void set_info(const std::string &info);
std::string status; std::string status;

27
src/source_clang.cc

@ -1,5 +1,6 @@
#include "source_clang.h" #include "source_clang.h"
#include "singletons.h" #include "config.h"
#include "terminal.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
@ -25,14 +26,14 @@ Source::View(file_path, project_path, language) {
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 : Config::get().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=Terminal::get().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_preprocess_connection=parse_preprocess.connect([this]{ parse_preprocess_connection=parse_preprocess.connect([this]{
@ -58,7 +59,7 @@ Source::View(file_path, project_path, language) {
} }
}); });
parse_error_connection=parse_error.connect([this](){ parse_error_connection=parse_error.connect([this](){
Singleton::terminal->print("Error: failed to reparse "+this->file_path.string()+".\n", true); Terminal::get().print("Error: failed to reparse "+this->file_path.string()+".\n", true);
set_status(""); set_status("");
set_info(""); set_info("");
parsing_in_progress->cancel("failed"); parsing_in_progress->cancel("failed");
@ -79,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 : Config::get().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);
@ -237,8 +238,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=Config::get().source.clang_types.find(std::to_string(range.kind));
if(type_it!=Singleton::config->source.clang_types.end()) { if(type_it!=Config::get().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);
@ -711,7 +712,7 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_state(Au
autocomplete_check(); autocomplete_check();
}); });
autocomplete_error_connection=autocomplete_error.connect([this]() { autocomplete_error_connection=autocomplete_error.connect([this]() {
Singleton::terminal->print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n", true); Terminal::get().print("Error: autocomplete failed, reparsing "+this->file_path.string()+"\n", true);
autocomplete_state=AutocompleteState::CANCELED; autocomplete_state=AutocompleteState::CANCELED;
full_reparse(); full_reparse();
}); });
@ -968,7 +969,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
}); });
auto_indent=[this]() { auto_indent=[this]() {
auto command=Singleton::config->terminal.clang_format_command; auto command=Config::get().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') {
@ -982,13 +983,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(Config::get().source.clang_format_style!="")
command+=", "+Singleton::config->source.clang_format_style; command+=", "+Config::get().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_status=Singleton::terminal->process(stdin_stream, stdout_stream, command); auto exit_status=Terminal::get().process(stdin_stream, stdout_stream, command);
if(exit_status==0) { if(exit_status==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();
@ -1224,7 +1225,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 //Terminal::get().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()+'/')

14
src/terminal.cc

@ -1,14 +1,14 @@
#include "terminal.h" #include "terminal.h"
#include <iostream> #include <iostream>
#include "logging.h" #include "logging.h"
#include "singletons.h" #include "config.h"
#include <iostream> //TODO: remove #include <iostream> //TODO: remove
using namespace std; //TODO: remove using namespace std; //TODO: remove
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, "."); Terminal::get().async_print(line_nr-1, ".");
}); });
start(start_msg); start(start_msg);
} }
@ -20,7 +20,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=Terminal::get().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) {
@ -35,14 +35,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); Terminal::get().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); Terminal::get().async_print(line_nr-1, msg);
} }
} }
@ -191,8 +191,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()>Config::get().terminal.history_size) {
int lines=get_buffer()->get_line_count()-Singleton::config->terminal.history_size; int lines=get_buffer()->get_line_count()-Config::get().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);
} }

7
src/terminal.h

@ -26,7 +26,14 @@ public:
std::thread wait_thread; std::thread wait_thread;
}; };
private:
Terminal(); Terminal();
public:
static Terminal &get() {
static Terminal singleton;
return singleton;
}
int process(const std::string &command, const boost::filesystem::path &path="", bool use_pipes=true); int process(const std::string &command, const boost::filesystem::path &path="", bool use_pipes=true);
int process(std::istream &stdin_stream, std::ostream &stdout_stream, const std::string &command, const boost::filesystem::path &path=""); int process(std::istream &stdin_stream, std::ostream &stdout_stream, const std::string &command, const boost::filesystem::path &path="");
void async_process(const std::string &command, const boost::filesystem::path &path="", std::function<void(int exit_status)> callback=nullptr); void async_process(const std::string &command, const boost::filesystem::path &path="", std::function<void(int exit_status)> callback=nullptr);

224
src/window.cc

@ -1,6 +1,8 @@
#include "window.h" #include "window.h"
#include "logging.h" #include "logging.h"
#include "singletons.h" #include "config.h"
#include "menu.h"
#include "directories.h"
//#include "api.h" //#include "api.h"
#include "dialogs.h" #include "dialogs.h"
#include "filesystem.h" #include "filesystem.h"
@ -28,40 +30,40 @@ 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(Config::get().window.default_size.first, Config::get().window.default_size.second);
//PluginApi(&this->notebook, &this->menu); //PluginApi(&this->notebook, &this->menu);
add(vpaned); add(vpaned);
directories_scrolled_window.add(*Singleton::directories); directories_scrolled_window.add(Directories::get());
directory_and_notebook_panes.pack1(directories_scrolled_window, Gtk::SHRINK); directory_and_notebook_panes.pack1(directories_scrolled_window, 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*Config::get().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*Config::get().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(Terminal::get());
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(notebook.info, Gtk::PACK_SHRINK);
info_and_status_hbox.pack_end(*Singleton::status, Gtk::PACK_SHRINK); info_and_status_hbox.pack_end(notebook.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) { Directories::get().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){ Terminal::get().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(); Terminal::get().queue_draw();
}); });
entry_box.signal_show().connect([this](){ entry_box.signal_show().connect([this](){
@ -92,11 +94,11 @@ Window::Window() : compiling(false) {
activate_menu_items(); activate_menu_items();
Singleton::directories->select(view->file_path); Directories::get().select(view->file_path);
if(view->full_reparse_needed) { if(view->full_reparse_needed) {
if(!view->full_reparse()) if(!view->full_reparse())
Singleton::terminal->async_print("Error: failed to reparse "+view->file_path.string()+". Please reopen the file manually.\n", true); Terminal::get().async_print("Error: failed to reparse "+view->file_path.string()+". Please reopen the file manually.\n", true);
} }
else if(view->soft_reparse_needed) else if(view->soft_reparse_needed)
view->soft_reparse(); view->soft_reparse();
@ -113,7 +115,7 @@ Window::Window() : compiling(false) {
about.hide(); about.hide();
}); });
about.set_version(Singleton::config->window.version); about.set_version(Config::get().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",
@ -128,65 +130,65 @@ Window::Window() : compiling(false) {
} // Window constructor } // Window constructor
void Window::configure() { void Window::configure() {
Singleton::config->load(); Config::get().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(Config::get().window.theme_name, Config::get().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 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);
Singleton::directories->update(); Directories::get().update();
Singleton::menu->set_keys(); Menu::get().set_keys();
} }
void Window::set_menu_actions() { void Window::set_menu_actions() {
auto &menu = Singleton::menu; auto &menu = Menu::get();
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->juci_home_path()/"config"/"config.json"); notebook.open(Config::get().juci_home_path()/"config"/"config.json");
}); });
menu->add_action("quit", [this]() { menu.add_action("quit", [this]() {
close(); close();
}); });
menu->add_action("new_file", [this]() { menu.add_action("new_file", [this]() {
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", true); Terminal::get().print("Error: "+path.string()+" already exists.\n", true);
} }
else { else {
if(filesystem::write(path)) { if(filesystem::write(path)) {
if(Singleton::directories->current_path!="") if(Directories::get().current_path!="")
Singleton::directories->update(); Directories::get().update();
notebook.open(path.string()); notebook.open(path.string());
Singleton::terminal->print("New file "+path.string()+" created.\n"); Terminal::get().print("New file "+path.string()+" created.\n");
} }
else else
Singleton::terminal->print("Error: could not create new file "+path.string()+".\n", true); Terminal::get().print("Error: could not create new file "+path.string()+".\n", true);
} }
} }
}); });
menu->add_action("new_folder", [this]() { menu.add_action("new_folder", [this]() {
auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); auto time_now=std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
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)) {
boost::system::error_code ec; boost::system::error_code ec;
auto last_write_time=boost::filesystem::last_write_time(path, ec); auto last_write_time=boost::filesystem::last_write_time(path, ec);
if(!ec && last_write_time>=time_now) { if(!ec && last_write_time>=time_now) {
if(Singleton::directories->current_path!="") if(Directories::get().current_path!="")
Singleton::directories->update(); Directories::get().update();
Singleton::terminal->print("New folder "+path.string()+" created.\n"); Terminal::get().print("New folder "+path.string()+" created.\n");
} }
else else
Singleton::terminal->print("Error: "+path.string()+" already exists.\n", true); Terminal::get().print("Error: "+path.string()+" already exists.\n", true);
Singleton::directories->select(path); Directories::get().select(path);
} }
}); });
menu->add_action("new_project_cpp", [this]() { menu.add_action("new_project_cpp", [this]() {
boost::filesystem::path project_path = Dialog::new_folder(); boost::filesystem::path project_path = Dialog::new_folder();
if(project_path!="") { if(project_path!="") {
auto project_name=project_path.filename().string(); auto project_name=project_path.filename().string();
@ -199,41 +201,41 @@ 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", true); Terminal::get().print("Error: "+cmakelists_path.string()+" already exists.\n", true);
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", true); Terminal::get().print("Error: "+cpp_main_path.string()+" already exists.\n", true);
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); Directories::get().open(project_path);
notebook.open(cpp_main_path); notebook.open(cpp_main_path);
Singleton::terminal->print("C++ project "+project_name+" created.\n"); Terminal::get().print("C++ project "+project_name+" created.\n");
} }
else else
Singleton::terminal->print("Error: Could not create project "+project_path.string()+"\n", true); Terminal::get().print("Error: Could not create project "+project_path.string()+"\n", true);
} }
}); });
menu->add_action("open_file", [this]() { menu.add_action("open_file", [this]() {
auto path=Dialog::open_file(); auto path=Dialog::open_file();
if(path!="") if(path!="")
notebook.open(path); notebook.open(path);
}); });
menu->add_action("open_folder", [this]() { menu.add_action("open_folder", [this]() {
auto path = Dialog::open_folder(); auto path = Dialog::open_folder();
if (path!="" && boost::filesystem::exists(path)) if (path!="" && boost::filesystem::exists(path))
Singleton::directories->open(path); Directories::get().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->juci_home_path()/"config"/"config.json") { if(notebook.get_current_view()->file_path==Config::get().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,7 +246,7 @@ 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_as(notebook.get_current_view()->file_path); auto path = Dialog::save_file_as(notebook.get_current_view()->file_path);
if(path!="") { if(path!="") {
@ -252,18 +254,18 @@ void Window::set_menu_actions() {
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(Directories::get().current_path!="")
Singleton::directories->update(); Directories::get().update();
notebook.open(path); notebook.open(path);
Singleton::terminal->print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n"); Terminal::get().print("File saved to: " + notebook.get_current_view()->file_path.string()+"\n");
} }
else else
Singleton::terminal->print("Error saving file\n"); Terminal::get().print("Error saving file\n");
} }
} }
}); });
menu->add_action("edit_undo", [this]() { menu.add_action("edit_undo", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager(); auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager();
if (undo_manager->can_undo()) { if (undo_manager->can_undo()) {
@ -272,7 +274,7 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu->add_action("edit_redo", [this]() { menu.add_action("edit_redo", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager(); auto undo_manager = notebook.get_current_view()->get_source_buffer()->get_undo_manager();
if(undo_manager->can_redo()) { if(undo_manager->can_redo()) {
@ -282,21 +284,21 @@ void Window::set_menu_actions() {
} }
}); });
menu->add_action("edit_cut", [this]() { menu.add_action("edit_cut", [this]() {
auto widget=get_focus(); auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget)) if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->cut_clipboard(); entry->cut_clipboard();
else if(notebook.get_current_page()!=-1) else if(notebook.get_current_page()!=-1)
notebook.get_current_view()->get_buffer()->cut_clipboard(Gtk::Clipboard::get()); notebook.get_current_view()->get_buffer()->cut_clipboard(Gtk::Clipboard::get());
}); });
menu->add_action("edit_copy", [this]() { menu.add_action("edit_copy", [this]() {
auto widget=get_focus(); auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget)) if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->copy_clipboard(); entry->copy_clipboard();
else if(auto text_view=dynamic_cast<Gtk::TextView*>(widget)) else if(auto text_view=dynamic_cast<Gtk::TextView*>(widget))
text_view->get_buffer()->copy_clipboard(Gtk::Clipboard::get()); text_view->get_buffer()->copy_clipboard(Gtk::Clipboard::get());
}); });
menu->add_action("edit_paste", [this]() { menu.add_action("edit_paste", [this]() {
auto widget=get_focus(); auto widget=get_focus();
if(auto entry=dynamic_cast<Gtk::Entry*>(widget)) if(auto entry=dynamic_cast<Gtk::Entry*>(widget))
entry->paste_clipboard(); entry->paste_clipboard();
@ -304,35 +306,35 @@ void Window::set_menu_actions() {
notebook.get_current_view()->paste(); notebook.get_current_view()->paste();
}); });
menu->add_action("edit_find", [this]() { menu.add_action("edit_find", [this]() {
search_and_replace_entry(); search_and_replace_entry();
}); });
menu->add_action("source_spellcheck", [this]() { menu.add_action("source_spellcheck", [this]() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->spellcheck(); notebook.get_current_view()->spellcheck();
}); });
menu->add_action("source_spellcheck_clear", [this]() { menu.add_action("source_spellcheck_clear", [this]() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->remove_spellcheck_errors(); notebook.get_current_view()->remove_spellcheck_errors();
}); });
menu->add_action("source_spellcheck_next_error", [this]() { menu.add_action("source_spellcheck_next_error", [this]() {
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
notebook.get_current_view()->goto_next_spellcheck_error(); notebook.get_current_view()->goto_next_spellcheck_error();
}); });
menu->add_action("source_indentation_set_buffer_tab", [this]() { menu.add_action("source_indentation_set_buffer_tab", [this]() {
set_tab_entry(); set_tab_entry();
}); });
menu->add_action("source_indentation_auto_indent_buffer", [this]() { menu.add_action("source_indentation_auto_indent_buffer", [this]() {
if(notebook.get_current_page()!=-1 && notebook.get_current_view()->auto_indent) if(notebook.get_current_page()!=-1 && notebook.get_current_view()->auto_indent)
notebook.get_current_view()->auto_indent(); notebook.get_current_view()->auto_indent();
}); });
menu->add_action("source_goto_line", [this]() { menu.add_action("source_goto_line", [this]() {
goto_line_entry(); goto_line_entry();
}); });
menu->add_action("source_center_cursor", [this]() { menu.add_action("source_center_cursor", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view(); auto view=notebook.get_current_view();
@ -343,13 +345,13 @@ void Window::set_menu_actions() {
} }
}); });
menu->add_action("source_find_documentation", [this]() { menu.add_action("source_find_documentation", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
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=Config::get().source.documentation_searches.find(data[0]);
if(documentation_search!=Singleton::config->source.documentation_searches.end()) { if(documentation_search!=Config::get().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) {
@ -370,7 +372,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->process("open \""+uri+"\""); Terminal::get().process("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);
@ -384,7 +386,7 @@ void Window::set_menu_actions() {
} }
}); });
menu->add_action("source_goto_declaration", [this]() { menu.add_action("source_goto_declaration", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->get_declaration_location) { if(notebook.get_current_view()->get_declaration_location) {
auto location=notebook.get_current_view()->get_declaration_location(); auto location=notebook.get_current_view()->get_declaration_location();
@ -417,7 +419,7 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu->add_action("source_goto_usage", [this]() { menu.add_action("source_goto_usage", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto current_view=notebook.get_current_view(); auto current_view=notebook.get_current_view();
if(current_view->get_token && current_view->get_usages) { if(current_view->get_token && current_view->get_usages) {
@ -479,25 +481,25 @@ void Window::set_menu_actions() {
} }
} }
}); });
menu->add_action("source_goto_method", [this]() { menu.add_action("source_goto_method", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_method) { if(notebook.get_current_view()->goto_method) {
notebook.get_current_view()->goto_method(); notebook.get_current_view()->goto_method();
} }
} }
}); });
menu->add_action("source_rename", [this]() { menu.add_action("source_rename", [this]() {
rename_token_entry(); rename_token_entry();
}); });
menu->add_action("source_goto_next_diagnostic", [this]() { menu.add_action("source_goto_next_diagnostic", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->goto_next_diagnostic) { if(notebook.get_current_view()->goto_next_diagnostic) {
notebook.get_current_view()->goto_next_diagnostic(); notebook.get_current_view()->goto_next_diagnostic();
} }
} }
}); });
menu->add_action("source_apply_fix_its", [this]() { menu.add_action("source_apply_fix_its", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
if(notebook.get_current_view()->apply_fix_its) { if(notebook.get_current_view()->apply_fix_its) {
notebook.get_current_view()->apply_fix_its(); notebook.get_current_view()->apply_fix_its();
@ -505,14 +507,14 @@ void Window::set_menu_actions() {
} }
}); });
menu->add_action("compile_and_run", [this]() { menu.add_action("compile_and_run", [this]() {
if(compiling) if(compiling)
return; return;
boost::filesystem::path cmake_path; boost::filesystem::path cmake_path;
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
cmake_path=notebook.get_current_view()->file_path.parent_path(); cmake_path=notebook.get_current_view()->file_path.parent_path();
else else
cmake_path=Singleton::directories->current_path; cmake_path=Directories::get().current_path;
if(cmake_path.empty()) if(cmake_path.empty())
return; return;
CMake cmake(cmake_path); CMake cmake(cmake_path);
@ -525,9 +527,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"); Terminal::get().print("Compiling and running "+executable_path.string()+"\n");
auto project_path=cmake.project_path; auto project_path=cmake.project_path;
Singleton::terminal->async_process(Singleton::config->terminal.make_command, cmake.project_path, [this, executable_path, project_path](int exit_status){ Terminal::get().async_process(Config::get().terminal.make_command, cmake.project_path, [this, executable_path, project_path](int exit_status){
compiling=false; compiling=false;
if(exit_status==EXIT_SUCCESS) { if(exit_status==EXIT_SUCCESS) {
auto executable_path_spaces_fixed=executable_path.string(); auto executable_path_spaces_fixed=executable_path.string();
@ -539,40 +541,40 @@ void Window::set_menu_actions() {
} }
last_char=executable_path_spaces_fixed[c]; last_char=executable_path_spaces_fixed[c];
} }
Singleton::terminal->async_process(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_status){ Terminal::get().async_process(executable_path_spaces_fixed, project_path, [this, executable_path](int exit_status){
Singleton::terminal->async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n'); Terminal::get().async_print(executable_path.string()+" returned: "+std::to_string(exit_status)+'\n');
}); });
} }
}); });
} }
else { else {
Singleton::terminal->print("Could not find add_executable in the following paths:\n"); Terminal::get().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"); Terminal::get().print(" "+path.string()+"\n");
} }
} }
}); });
menu->add_action("compile", [this]() { menu.add_action("compile", [this]() {
if(compiling) if(compiling)
return; return;
boost::filesystem::path cmake_path; boost::filesystem::path cmake_path;
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1)
cmake_path=notebook.get_current_view()->file_path.parent_path(); cmake_path=notebook.get_current_view()->file_path.parent_path();
else else
cmake_path=Singleton::directories->current_path; cmake_path=Directories::get().current_path;
if(cmake_path.empty()) if(cmake_path.empty())
return; return;
CMake cmake(cmake_path); CMake cmake(cmake_path);
if(cmake.project_path!="") { if(cmake.project_path!="") {
compiling=true; compiling=true;
Singleton::terminal->print("Compiling project "+cmake.project_path.string()+"\n"); Terminal::get().print("Compiling project "+cmake.project_path.string()+"\n");
Singleton::terminal->async_process(Singleton::config->terminal.make_command, cmake.project_path, [this](int exit_status){ Terminal::get().async_process(Config::get().terminal.make_command, cmake.project_path, [this](int exit_status){
compiling=false; compiling=false;
}); });
} }
}); });
menu->add_action("run_command", [this]() { menu.add_action("run_command", [this]() {
entry_box.clear(); entry_box.clear();
entry_box.labels.emplace_back(); entry_box.labels.emplace_back();
auto label_it=entry_box.labels.begin(); auto label_it=entry_box.labels.begin();
@ -584,10 +586,10 @@ void Window::set_menu_actions() {
if(content!="") { if(content!="") {
last_run_command=content; last_run_command=content;
auto run_path=notebook.get_current_folder(); auto run_path=notebook.get_current_folder();
Singleton::terminal->async_print("Running: "+content+'\n'); Terminal::get().async_print("Running: "+content+'\n');
Singleton::terminal->async_process(content, run_path, [this, content](int exit_status){ Terminal::get().async_process(content, run_path, [this, content](int exit_status){
Singleton::terminal->async_print(content+" returned: "+std::to_string(exit_status)+'\n'); Terminal::get().async_print(content+" returned: "+std::to_string(exit_status)+'\n');
}); });
} }
entry_box.hide(); entry_box.hide();
@ -600,19 +602,19 @@ void Window::set_menu_actions() {
entry_box.show(); entry_box.show();
}); });
menu->add_action("kill_last_running", [this]() { menu.add_action("kill_last_running", [this]() {
Singleton::terminal->kill_last_async_process(); Terminal::get().kill_last_async_process();
}); });
menu->add_action("force_kill_last_running", [this]() { menu.add_action("force_kill_last_running", [this]() {
Singleton::terminal->kill_last_async_process(true); Terminal::get().kill_last_async_process(true);
}); });
menu->add_action("next_tab", [this]() { menu.add_action("next_tab", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
notebook.open(notebook.get_view((notebook.get_current_page()+1)%notebook.size())->file_path); notebook.open(notebook.get_view((notebook.get_current_page()+1)%notebook.size())->file_path);
} }
}); });
menu->add_action("previous_tab", [this]() { menu.add_action("previous_tab", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
int previous_page=notebook.get_current_page()-1; int previous_page=notebook.get_current_page()-1;
if(previous_page<0) if(previous_page<0)
@ -620,15 +622,15 @@ void Window::set_menu_actions() {
notebook.open(notebook.get_view(previous_page)->file_path); notebook.open(notebook.get_view(previous_page)->file_path);
} }
}); });
menu->add_action("close_tab", [this]() { menu.add_action("close_tab", [this]() {
notebook.close_current_page(); notebook.close_current_page();
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
notebook.get_current_view()->set_status(notebook.get_current_view()->status); notebook.get_current_view()->set_status(notebook.get_current_view()->status);
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(""); notebook.status.set_text("");
Singleton::info->set_text(""); notebook.info.set_text("");
activate_menu_items(false); activate_menu_items(false);
} }
@ -637,15 +639,15 @@ 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 = Menu::get();
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);
menu->actions["source_goto_usage"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_usages) : false); menu.actions["source_goto_usage"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->get_usages) : false);
menu->actions["source_goto_method"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_method) : false); menu.actions["source_goto_method"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_method) : false);
menu->actions["source_rename"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->rename_similar_tokens) : false); menu.actions["source_rename"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->rename_similar_tokens) : false);
menu->actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_next_diagnostic) : false); menu.actions["source_goto_next_diagnostic"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->goto_next_diagnostic) : false);
menu->actions["source_apply_fix_its"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->apply_fix_its) : false); menu.actions["source_apply_fix_its"]->set_enabled(activate ? static_cast<bool>(notebook.get_current_view()->apply_fix_its) : false);
} }
bool Window::on_key_press_event(GdkEventKey *event) { bool Window::on_key_press_event(GdkEventKey *event) {
@ -688,7 +690,7 @@ bool Window::on_delete_event(GdkEventAny *event) {
if(!notebook.close_current_page()) if(!notebook.close_current_page())
return true; return true;
} }
Singleton::terminal->kill_async_processes(); Terminal::get().kill_async_processes();
return false; return false;
} }
@ -893,7 +895,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"); Terminal::get().print("Replaced "+std::to_string(number)+" occurrences in file "+view->file_path.string()+"\n");
notebook.save(c); notebook.save(c);
modified_pages.emplace_back(c); modified_pages.emplace_back(c);
} }

8
src/window.h

@ -7,8 +7,14 @@
#include <atomic> #include <atomic>
class Window : public Gtk::ApplicationWindow { class Window : public Gtk::ApplicationWindow {
public: private:
Window(); Window();
public:
static Window &get() {
static Window singleton;
return singleton;
}
Notebook notebook; Notebook notebook;
protected: protected:

Loading…
Cancel
Save