Browse Source

Added singleton.*, at the moment only Source::Config made singleton. Tooltips now have yellow background. Also some cleanup.

merge-requests/365/head
eidheim 11 years ago
parent
commit
f4c1a2481c
  1. 2
      juci/CMakeLists.txt
  2. 26
      juci/config.cc
  3. 2
      juci/config.h
  4. 1
      juci/config.json
  5. 6
      juci/notebook.cc
  6. 2
      juci/notebook.h
  7. 3
      juci/singletons.cc
  8. 20
      juci/singletons.h
  9. 78
      juci/source.cc
  10. 14
      juci/source.h
  11. 4
      juci/tooltips.cc
  12. 51
      juci/window.cc
  13. 10
      juci/window.h

2
juci/CMakeLists.txt

@ -127,6 +127,8 @@ add_executable(${project_name}
terminal.cc terminal.cc
tooltips.h tooltips.h
tooltips.cc tooltips.cc
singletons.h
singletons.cc
) )
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin) set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

26
juci/config.cc

@ -2,7 +2,7 @@
#include "logging.h" #include "logging.h"
MainConfig::MainConfig() : MainConfig::MainConfig() :
keybindings_cfg(), source_cfg() { keybindings_cfg() {
INFO("Reading config file"); INFO("Reading config file");
boost::property_tree::json_parser::read_json("config.json", cfg_); boost::property_tree::json_parser::read_json("config.json", cfg_);
INFO("Config file read"); INFO("Config file read");
@ -13,6 +13,7 @@ MainConfig::MainConfig() :
} }
void MainConfig::GenerateSource() { void MainConfig::GenerateSource() {
auto source_cfg=Singletons::Config::source();
DEBUG("Fetching source cfg"); DEBUG("Fetching source cfg");
// boost::property_tree::ptree // boost::property_tree::ptree
auto source_json = cfg_.get_child("source"); auto source_json = cfg_.get_child("source");
@ -22,30 +23,33 @@ void MainConfig::GenerateSource() {
auto visual_json = source_json.get_child("visual"); auto visual_json = source_json.get_child("visual");
for (auto &i : visual_json) { for (auto &i : visual_json) {
if (i.first == "background") { if (i.first == "background") {
source_cfg.background = i.second.get_value<std::string>(); source_cfg->background = i.second.get_value<std::string>();
}
if (i.first == "background_tooltips") {
source_cfg->background_tooltips = i.second.get_value<std::string>();
} }
if (i.first == "show_line_numbers") { if (i.first == "show_line_numbers") {
source_cfg.show_line_numbers = i.second.get_value<std::string>() == "1" ? true : false; source_cfg->show_line_numbers = i.second.get_value<std::string>() == "1" ? true : false;
} }
if (i.first == "highlight_current_line") { if (i.first == "highlight_current_line") {
source_cfg.highlight_current_line = i.second.get_value<std::string>() == "1" ? true : false; source_cfg->highlight_current_line = i.second.get_value<std::string>() == "1" ? true : false;
} }
if (i.first == "font") { if (i.first == "font") {
source_cfg.font = i.second.get_value<std::string>(); source_cfg->font = i.second.get_value<std::string>();
} }
} }
source_cfg.tab_size = source_json.get<unsigned>("tab_size"); source_cfg->tab_size = source_json.get<unsigned>("tab_size");
for (unsigned c = 0; c < source_cfg.tab_size; c++) { for (unsigned c = 0; c < source_cfg->tab_size; c++) {
source_cfg.tab+=" "; source_cfg->tab+=" ";
} }
for (auto &i : colors_json) { for (auto &i : colors_json) {
source_cfg.tags[i.first]=i.second.get_value<std::string>(); source_cfg->tags[i.first]=i.second.get_value<std::string>();
} }
for (auto &i : syntax_json) { for (auto &i : syntax_json) {
source_cfg.types[i.first]=i.second.get_value<std::string>(); source_cfg->types[i.first]=i.second.get_value<std::string>();
} }
for (auto &i : extensions_json) { for (auto &i : extensions_json) {
source_cfg.extensions.emplace_back(i.second.get_value<std::string>()); source_cfg->extensions.emplace_back(i.second.get_value<std::string>());
} }
DEBUG("Source cfg fetched"); DEBUG("Source cfg fetched");
} }

2
juci/config.h

@ -4,6 +4,7 @@
#include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/xml_parser.hpp>
#include <fstream> #include <fstream>
#include <string> #include <string>
#include "singletons.h"
#include "keybindings.h" #include "keybindings.h"
#include "source.h" #include "source.h"
#include "directories.h" #include "directories.h"
@ -11,7 +12,6 @@
class MainConfig { class MainConfig {
public: public:
Source::Config source_cfg;
Terminal::Config terminal_cfg; Terminal::Config terminal_cfg;
Keybindings::Config keybindings_cfg; Keybindings::Config keybindings_cfg;
Directories::Config dir_cfg; Directories::Config dir_cfg;

1
juci/config.json

@ -34,6 +34,7 @@
], ],
"visual": { "visual": {
"background": "white", "background": "white",
"background_tooltips": "yellow",
"font": "Monospace", "font": "Monospace",
"show_line_numbers": 1, "show_line_numbers": 1,
"highlight_current_line": 1 "highlight_current_line": 1

6
juci/notebook.cc

@ -11,11 +11,9 @@ Notebook::View::View() {
Notebook::Controller::Controller(Keybindings::Controller& keybindings, Notebook::Controller::Controller(Keybindings::Controller& keybindings,
Terminal::Controller& terminal, Terminal::Controller& terminal,
Source::Config& source_cfg,
Directories::Config& dir_cfg) : Directories::Config& dir_cfg) :
terminal(terminal), terminal(terminal),
directories(dir_cfg), directories(dir_cfg) {
source_config(source_cfg) {
INFO("Create notebook"); INFO("Create notebook");
refClipboard_ = Gtk::Clipboard::get(); refClipboard_ = Gtk::Clipboard::get();
view.pack1(directories.widget(), true, true); view.pack1(directories.widget(), true, true);
@ -173,7 +171,7 @@ Notebook::Controller::~Controller() {
void Notebook::Controller::OnOpenFile(std::string path) { void Notebook::Controller::OnOpenFile(std::string path) {
INFO("Notebook open file"); INFO("Notebook open file");
INFO("Notebook create page"); INFO("Notebook create page");
text_vec_.emplace_back(new Source::Controller(source_config, path, project_path, terminal)); text_vec_.emplace_back(new Source::Controller(path, project_path, terminal));
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow()); scrolledtext_vec_.push_back(new Gtk::ScrolledWindow());
editor_vec_.push_back(new Gtk::HBox()); editor_vec_.push_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(*text_vec_.back()->view); scrolledtext_vec_.back()->add(*text_vec_.back()->view);

2
juci/notebook.h

@ -24,7 +24,6 @@ namespace Notebook {
public: public:
Controller(Keybindings::Controller& keybindings, Controller(Keybindings::Controller& keybindings,
Terminal::Controller& terminal, Terminal::Controller& terminal,
Source::Config& config,
Directories::Config& dir_cfg); Directories::Config& dir_cfg);
~Controller(); ~Controller();
Source::View& CurrentTextView(); Source::View& CurrentTextView();
@ -51,7 +50,6 @@ namespace Notebook {
Glib::RefPtr<Gtk::Builder> m_refBuilder; Glib::RefPtr<Gtk::Builder> m_refBuilder;
Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup; Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup;
Terminal::Controller& terminal; Terminal::Controller& terminal;
Source::Config& source_config;
std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_; std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_;
std::vector<Gtk::HBox*> editor_vec_; std::vector<Gtk::HBox*> editor_vec_;

3
juci/singletons.cc

@ -0,0 +1,3 @@
#include "singletons.h"
std::unique_ptr<Source::Config> Singletons::Config::source_=std::unique_ptr<Source::Config>(new Source::Config());

20
juci/singletons.h

@ -0,0 +1,20 @@
#ifndef JUCI_SINGLETONS_H_
#define JUCI_SINGLETONS_H_
#include "keybindings.h"
#include "source.h"
#include "directories.h"
#include "terminal.h"
namespace Singletons {
class Config {
public:
static Source::Config *source() {
return source_.get();
}
private:
static std::unique_ptr<Source::Config> source_;
};
}
#endif // JUCI_SINGLETONS_H_

78
juci/source.cc

@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include <regex> #include <regex>
#include "selectiondialog.h" #include "selectiondialog.h"
#include "singletons.h"
bool Source::Config::legal_extension(std::string e) const { bool Source::Config::legal_extension(std::string e) const {
std::transform(e.begin(), e.end(),e.begin(), ::tolower); std::transform(e.begin(), e.end(),e.begin(), ::tolower);
@ -21,17 +22,23 @@ bool Source::Config::legal_extension(std::string e) const {
////////////// //////////////
//// View //// //// View ////
////////////// //////////////
Source::View::View(const Source::Config& config, const std::string& file_path, const std::string& project_path): Source::View::View(const std::string& file_path, const std::string& project_path):
config(config), file_path(file_path), project_path(project_path) { file_path(file_path), project_path(project_path) {
Gsv::init(); Gsv::init();
set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); set_smart_home_end(Gsv::SMART_HOME_END_BEFORE);
set_show_line_numbers(config.show_line_numbers); set_show_line_numbers(Singletons::Config::source()->show_line_numbers);
set_highlight_current_line(config.highlight_current_line); set_highlight_current_line(Singletons::Config::source()->highlight_current_line);
sourcefile s(file_path); sourcefile s(file_path);
get_source_buffer()->get_undo_manager()->begin_not_undoable_action(); get_source_buffer()->get_undo_manager()->begin_not_undoable_action();
get_source_buffer()->set_text(s.get_content()); get_source_buffer()->set_text(s.get_content());
get_source_buffer()->get_undo_manager()->end_not_undoable_action(); get_source_buffer()->get_undo_manager()->end_not_undoable_action();
search_start = search_end = this->get_buffer()->end(); search_start = search_end = this->get_buffer()->end();
override_font(Pango::FontDescription(Singletons::Config::source()->font));
override_background_color(Gdk::RGBA(Singletons::Config::source()->background));
for (auto &item : Singletons::Config::source()->tags) {
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second;
}
} }
string Source::View::get_line(size_t line_number) { string Source::View::get_line(size_t line_number) {
@ -52,7 +59,8 @@ string Source::View::get_line_before_insert() {
//Basic indentation //Basic indentation
bool Source::View::on_key_press(GdkEventKey* key) { bool Source::View::on_key_press(GdkEventKey* key) {
const std::regex spaces_regex(std::string("^(")+config.tab_char+"*).*$"); auto config=Singletons::Config::source();
const std::regex spaces_regex(std::string("^(")+config->tab_char+"*).*$");
//Indent as in next or previous line //Indent as in next or previous line
if(key->keyval==GDK_KEY_Return && key->state==0) { if(key->keyval==GDK_KEY_Return && key->state==0) {
int line_nr=get_source_buffer()->get_insert()->get_iter().get_line(); int line_nr=get_source_buffer()->get_insert()->get_iter().get_line();
@ -83,7 +91,7 @@ bool Source::View::on_key_press(GdkEventKey* key) {
int line_end=selection_end.get_line(); int line_end=selection_end.get_line();
for(int line=line_start;line<=line_end;line++) { for(int line=line_start;line<=line_end;line++) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line); Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line);
get_source_buffer()->insert(line_it, config.tab); get_source_buffer()->insert(line_it, config->tab);
} }
return true; return true;
} }
@ -96,7 +104,7 @@ bool Source::View::on_key_press(GdkEventKey* key) {
for(int line_nr=line_start;line_nr<=line_end;line_nr++) { for(int line_nr=line_start;line_nr<=line_end;line_nr++) {
string line=get_line(line_nr); string line=get_line(line_nr);
if(!(line.size()>=config.tab_size && line.substr(0, config.tab_size)==config.tab)) if(!(line.size()>=config->tab_size && line.substr(0, config->tab_size)==config->tab))
return true; return true;
} }
@ -104,7 +112,7 @@ bool Source::View::on_key_press(GdkEventKey* key) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_nr); Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_nr);
Gtk::TextIter line_plus_it=line_it; Gtk::TextIter line_plus_it=line_it;
for(unsigned c=0;c<config.tab_size;c++) for(unsigned c=0;c<config->tab_size;c++)
line_plus_it++; line_plus_it++;
get_source_buffer()->erase(line_it, line_plus_it); get_source_buffer()->erase(line_it, line_plus_it);
} }
@ -119,7 +127,7 @@ bool Source::View::on_key_press(GdkEventKey* key) {
string previous_line=get_line(line_nr-1); string previous_line=get_line(line_nr-1);
smatch sm; smatch sm;
if(std::regex_match(previous_line, sm, spaces_regex)) { if(std::regex_match(previous_line, sm, spaces_regex)) {
if(line==sm[1] || line==(std::string(sm[1])+config.tab) || (line+config.tab==sm[1])) { if(line==sm[1] || line==(std::string(sm[1])+config->tab) || (line+config->tab==sm[1])) {
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_nr); Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(line_nr);
get_source_buffer()->erase(line_it, insert_it); get_source_buffer()->erase(line_it, insert_it);
} }
@ -134,15 +142,9 @@ bool Source::View::on_key_press(GdkEventKey* key) {
////////////////// //////////////////
clang::Index Source::ClangView::clang_index(0, 0); clang::Index Source::ClangView::clang_index(0, 0);
Source::ClangView::ClangView(const Source::Config& config, const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal): Source::ClangView::ClangView(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal):
Source::View(config, file_path, project_path), terminal(terminal), Source::View(file_path, project_path), terminal(terminal),
parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) { parse_thread_go(true), parse_thread_mapped(false), parse_thread_stop(false) {
override_font(Pango::FontDescription(config.font));
override_background_color(Gdk::RGBA(config.background));
for (auto &item : config.tags) {
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second;
}
int start_offset = get_source_buffer()->begin().get_offset(); int start_offset = get_source_buffer()->begin().get_offset();
int end_offset = get_source_buffer()->end().get_offset(); int end_offset = get_source_buffer()->end().get_offset();
auto buffer_map=get_buffer_map(); auto buffer_map=get_buffer_map();
@ -332,7 +334,7 @@ void Source::ClangView::update_syntax(const std::vector<Source::Range> &ranges)
for (auto &range : ranges) { for (auto &range : ranges) {
std::string type = std::to_string(range.kind); std::string type = std::to_string(range.kind);
try { try {
config.types.at(type); Singletons::Config::source()->types.at(type);
} catch (std::exception) { } catch (std::exception) {
continue; continue;
} }
@ -347,7 +349,7 @@ void Source::ClangView::update_syntax(const std::vector<Source::Range> &ranges)
buffer->get_iter_at_line_offset(linum_start, begin); buffer->get_iter_at_line_offset(linum_start, begin);
Gtk::TextIter end_iter = Gtk::TextIter end_iter =
buffer->get_iter_at_line_offset(linum_end, end); buffer->get_iter_at_line_offset(linum_end, end);
buffer->apply_tag_by_name(config.types.at(type), buffer->apply_tag_by_name(Singletons::Config::source()->types.at(type),
begin_iter, end_iter); begin_iter, end_iter);
} }
} }
@ -550,10 +552,11 @@ bool Source::ClangView::on_key_release(GdkEventKey* key) {
//Clang indentation //Clang indentation
//TODO: replace indentation methods with a better implementation or maybe use libclang //TODO: replace indentation methods with a better implementation or maybe use libclang
bool Source::ClangView::on_key_press(GdkEventKey* key) { bool Source::ClangView::on_key_press(GdkEventKey* key) {
const std::regex bracket_regex(std::string("^(")+config.tab_char+"*).*\\{ *$"); auto config=Singletons::Config::source();
const std::regex no_bracket_statement_regex(std::string("^(")+config.tab_char+"*)(if|for|else if|catch|while) *\\(.*[^;}] *$"); const std::regex bracket_regex(std::string("^(")+config->tab_char+"*).*\\{ *$");
const std::regex no_bracket_no_para_statement_regex(std::string("^(")+config.tab_char+"*)(else|try|do) *$"); const std::regex no_bracket_statement_regex(std::string("^(")+config->tab_char+"*)(if|for|else if|catch|while) *\\(.*[^;}] *$");
const std::regex spaces_regex(std::string("^(")+config.tab_char+"*).*$"); const std::regex no_bracket_no_para_statement_regex(std::string("^(")+config->tab_char+"*)(else|try|do) *$");
const std::regex spaces_regex(std::string("^(")+config->tab_char+"*).*$");
//Indent depending on if/else/etc and brackets //Indent depending on if/else/etc and brackets
if(key->keyval==GDK_KEY_Return && key->state==0) { if(key->keyval==GDK_KEY_Return && key->state==0) {
@ -565,35 +568,35 @@ bool Source::ClangView::on_key_press(GdkEventKey* key) {
string next_line=get_line(line_nr+1); string next_line=get_line(line_nr+1);
std::smatch sm2; std::smatch sm2;
if(std::regex_match(next_line, sm2, spaces_regex)) { if(std::regex_match(next_line, sm2, spaces_regex)) {
if(sm2[1].str()==sm[1].str()+config.tab) { if(sm2[1].str()==sm[1].str()+config->tab) {
get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab); get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config->tab);
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
return true; return true;
} }
} }
} }
get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab+"\n"+sm[1].str()+"}"); get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config->tab+"\n"+sm[1].str()+"}");
auto insert_it = get_source_buffer()->get_insert()->get_iter(); auto insert_it = get_source_buffer()->get_insert()->get_iter();
for(size_t c=0;c<config.tab_size+sm[1].str().size();c++) for(size_t c=0;c<config->tab_size+sm[1].str().size();c++)
insert_it--; insert_it--;
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
get_source_buffer()->place_cursor(insert_it); get_source_buffer()->place_cursor(insert_it);
return true; return true;
} }
else if(std::regex_match(line, sm, no_bracket_statement_regex)) { else if(std::regex_match(line, sm, no_bracket_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab); get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config->tab);
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
return true; return true;
} }
else if(std::regex_match(line, sm, no_bracket_no_para_statement_regex)) { else if(std::regex_match(line, sm, no_bracket_no_para_statement_regex)) {
get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config.tab); get_source_buffer()->insert_at_cursor("\n"+sm[1].str()+config->tab);
scroll_to(get_source_buffer()->get_insert()); scroll_to(get_source_buffer()->get_insert());
return true; return true;
} }
else if(std::regex_match(line, sm, spaces_regex)) { else if(std::regex_match(line, sm, spaces_regex)) {
std::smatch sm2; std::smatch sm2;
size_t line_nr=get_source_buffer()->get_insert()->get_iter().get_line(); size_t line_nr=get_source_buffer()->get_insert()->get_iter().get_line();
if(line_nr>0 && sm[1].str().size()>=config.tab_size) { if(line_nr>0 && sm[1].str().size()>=config->tab_size) {
string previous_line=get_line(line_nr-1); string previous_line=get_line(line_nr-1);
if(!std::regex_match(previous_line, sm2, bracket_regex)) { if(!std::regex_match(previous_line, sm2, bracket_regex)) {
if(std::regex_match(previous_line, sm2, no_bracket_statement_regex)) { if(std::regex_match(previous_line, sm2, no_bracket_statement_regex)) {
@ -613,15 +616,15 @@ bool Source::ClangView::on_key_press(GdkEventKey* key) {
//Indent left when writing } on a new line //Indent left when writing } on a new line
else if(key->keyval==GDK_KEY_braceright) { else if(key->keyval==GDK_KEY_braceright) {
string line=get_line_before_insert(); string line=get_line_before_insert();
if(line.size()>=config.tab_size) { if(line.size()>=config->tab_size) {
for(auto c: line) { for(auto c: line) {
if(c!=config.tab_char) if(c!=config->tab_char)
return false; return false;
} }
Gtk::TextIter insert_it = get_source_buffer()->get_insert()->get_iter(); Gtk::TextIter insert_it = get_source_buffer()->get_insert()->get_iter();
Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(insert_it.get_line()); Gtk::TextIter line_it = get_source_buffer()->get_iter_at_line(insert_it.get_line());
Gtk::TextIter line_plus_it=line_it; Gtk::TextIter line_plus_it=line_it;
for(unsigned c=0;c<config.tab_size;c++) for(unsigned c=0;c<config->tab_size;c++)
line_plus_it++; line_plus_it++;
get_source_buffer()->erase(line_it, line_plus_it); get_source_buffer()->erase(line_it, line_plus_it);
@ -638,15 +641,14 @@ bool Source::ClangView::on_key_press(GdkEventKey* key) {
// Source::Controller::Controller() // Source::Controller::Controller()
// Constructor for Controller // Constructor for Controller
Source::Controller::Controller(const Source::Config &config, Source::Controller::Controller(const std::string& file_path, std::string project_path, Terminal::Controller& terminal) {
const std::string& file_path, std::string project_path, Terminal::Controller& terminal) {
if(project_path=="") { if(project_path=="") {
project_path=boost::filesystem::path(file_path).parent_path().string(); project_path=boost::filesystem::path(file_path).parent_path().string();
} }
if (config.legal_extension(file_path.substr(file_path.find_last_of(".") + 1))) if (Singletons::Config::source()->legal_extension(file_path.substr(file_path.find_last_of(".") + 1)))
view=std::unique_ptr<View>(new ClangView(config, file_path, project_path, terminal)); view=std::unique_ptr<View>(new ClangView(file_path, project_path, terminal));
else else
view=std::unique_ptr<View>(new GenericView(config, file_path, project_path)); view=std::unique_ptr<View>(new GenericView(file_path, project_path));
INFO("Source Controller with childs constructed"); INFO("Source Controller with childs constructed");
} }

14
juci/source.h

@ -19,7 +19,7 @@ namespace Source {
bool legal_extension(std::string e) const ; bool legal_extension(std::string e) const ;
unsigned tab_size; unsigned tab_size;
bool show_line_numbers, highlight_current_line; bool show_line_numbers, highlight_current_line;
std::string tab, background, font; std::string tab, background, background_tooltips, font;
char tab_char=' '; char tab_char=' ';
std::vector<std::string> extensions; std::vector<std::string> extensions;
std::unordered_map<std::string, std::string> tags, types; std::unordered_map<std::string, std::string> tags, types;
@ -59,21 +59,20 @@ namespace Source {
class View : public Gsv::View { class View : public Gsv::View {
public: public:
View(const Source::Config& config, const std::string& file_path, const std::string& project_path); View(const std::string& file_path, const std::string& project_path);
std::string get_line(size_t line_number); std::string get_line(size_t line_number);
std::string get_line_before_insert(); std::string get_line_before_insert();
std::string file_path; std::string file_path;
std::string project_path; std::string project_path;
Gtk::TextIter search_start, search_end; Gtk::TextIter search_start, search_end;
protected: protected:
const Source::Config& config;
bool on_key_press(GdkEventKey* key); bool on_key_press(GdkEventKey* key);
}; // class View }; // class View
class GenericView : public View { class GenericView : public View {
public: public:
GenericView(const Source::Config& config, const std::string& file_path, const std::string& project_path): GenericView(const std::string& file_path, const std::string& project_path):
View(config, file_path, project_path) { View(file_path, project_path) {
signal_key_press_event().connect(sigc::mem_fun(*this, &Source::GenericView::on_key_press), false); signal_key_press_event().connect(sigc::mem_fun(*this, &Source::GenericView::on_key_press), false);
} }
private: private:
@ -84,7 +83,7 @@ namespace Source {
class ClangView : public View { class ClangView : public View {
public: public:
ClangView(const Source::Config& config, const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal); ClangView(const std::string& file_path, const std::string& project_path, Terminal::Controller& terminal);
~ClangView(); ~ClangView();
// inits the syntax highligthing on file open // inits the syntax highligthing on file open
void init_syntax_highlighting(const std::map<std::string, std::string> void init_syntax_highlighting(const std::map<std::string, std::string>
@ -132,8 +131,7 @@ namespace Source {
class Controller { class Controller {
public: public:
Controller(const Source::Config &config, Controller(const std::string& file_path, std::string project_path, Terminal::Controller& terminal);
const std::string& file_path, std::string project_path, Terminal::Controller& terminal);
Glib::RefPtr<Gsv::Buffer> buffer(); Glib::RefPtr<Gsv::Buffer> buffer();
bool is_saved = true; bool is_saved = true;

4
juci/tooltips.cc

@ -1,5 +1,5 @@
#include "tooltips.h" #include "tooltips.h"
#include <thread> #include "singletons.h"
Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle(); Gdk::Rectangle Tooltips::drawn_tooltips_rectangle=Gdk::Rectangle();
@ -46,11 +46,13 @@ void Tooltip::adjust() {
tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(this->get_buffer())); tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(this->get_buffer()));
tooltip_widget->set_editable(false); tooltip_widget->set_editable(false);
tooltip_widget->override_background_color(Gdk::RGBA(Singletons::Config::source()->background_tooltips));
window->add(*tooltip_widget); window->add(*tooltip_widget);
auto layout=Pango::Layout::create(tooltip_widget->get_pango_context()); auto layout=Pango::Layout::create(tooltip_widget->get_pango_context());
layout->set_text(tooltip_widget->get_buffer()->get_text()); layout->set_text(tooltip_widget->get_buffer()->get_text());
layout->get_pixel_size(tooltip_width, tooltip_height); layout->get_pixel_size(tooltip_width, tooltip_height);
tooltip_height+=2;
} }
int root_x, root_y; int root_x, root_y;

51
juci/window.cc

@ -3,65 +3,64 @@
Window::Window() : Window::Window() :
window_box_(Gtk::ORIENTATION_VERTICAL), window_box_(Gtk::ORIENTATION_VERTICAL),
main_config_(), main_config(),
keybindings_(main_config_.keybindings_cfg), keybindings(main_config.keybindings_cfg),
terminal(main_config_.terminal_cfg), terminal(main_config.terminal_cfg),
notebook(keybindings(), terminal, notebook(keybindings, terminal,
main_config_.source_cfg, main_config.dir_cfg),
main_config_.dir_cfg), menu(keybindings),
menu_(keybindings()), api(menu, notebook) {
api_(menu_, notebook) {
INFO("Create Window"); INFO("Create Window");
set_title("juCi++"); set_title("juCi++");
set_default_size(600, 400); set_default_size(600, 400);
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK); set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK);
add(window_box_); add(window_box_);
keybindings_.action_group_menu()->add(Gtk::Action::create("FileQuit", keybindings.action_group_menu()->add(Gtk::Action::create("FileQuit",
"Quit juCi++"), "Quit juCi++"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["quit"]), .key_map()["quit"]),
[this]() { [this]() {
OnWindowHide(); OnWindowHide();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFile", keybindings.action_group_menu()->add(Gtk::Action::create("FileOpenFile",
"Open file"), "Open file"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["open_file"]), .key_map()["open_file"]),
[this]() { [this]() {
OnOpenFile(); OnOpenFile();
}); });
keybindings_.action_group_menu()->add(Gtk::Action::create("FileOpenFolder", keybindings.action_group_menu()->add(Gtk::Action::create("FileOpenFolder",
"Open folder"), "Open folder"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["open_folder"]), .key_map()["open_folder"]),
[this]() { [this]() {
OnFileOpenFolder(); OnFileOpenFolder();
}); });
keybindings_. keybindings.
action_group_menu()-> action_group_menu()->
add(Gtk::Action::create("FileSaveAs", add(Gtk::Action::create("FileSaveAs",
"Save as"), "Save as"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["save_as"]), .key_map()["save_as"]),
[this]() { [this]() {
SaveFileAs(); SaveFileAs();
}); });
keybindings_. keybindings.
action_group_menu()-> action_group_menu()->
add(Gtk::Action::create("FileSave", add(Gtk::Action::create("FileSave",
"Save"), "Save"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["save"]), .key_map()["save"]),
[this]() { [this]() {
SaveFile(); SaveFile();
}); });
keybindings_. keybindings.
action_group_menu()-> action_group_menu()->
add(Gtk::Action::create("ProjectCompileAndRun", add(Gtk::Action::create("ProjectCompileAndRun",
"Compile And Run"), "Compile And Run"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["compile_and_run"]), .key_map()["compile_and_run"]),
[this]() { [this]() {
SaveFile(); SaveFile();
@ -83,11 +82,11 @@ Window::Window() :
} }
}); });
keybindings_. keybindings.
action_group_menu()-> action_group_menu()->
add(Gtk::Action::create("ProjectCompile", add(Gtk::Action::create("ProjectCompile",
"Compile"), "Compile"),
Gtk::AccelKey(keybindings_.config_ Gtk::AccelKey(keybindings.config_
.key_map()["compile"]), .key_map()["compile"]),
[this]() { [this]() {
SaveFile(); SaveFile();
@ -106,11 +105,11 @@ Window::Window() :
} }
}); });
add_accel_group(keybindings_.ui_manager_menu()->get_accel_group()); add_accel_group(keybindings.ui_manager_menu()->get_accel_group());
add_accel_group(keybindings_.ui_manager_hidden()->get_accel_group()); add_accel_group(keybindings.ui_manager_hidden()->get_accel_group());
keybindings_.BuildMenu(); keybindings.BuildMenu();
window_box_.pack_start(menu_.view(), Gtk::PACK_SHRINK); window_box_.pack_start(menu.view(), Gtk::PACK_SHRINK);
window_box_.pack_start(notebook.entry, Gtk::PACK_SHRINK); window_box_.pack_start(notebook.entry, Gtk::PACK_SHRINK);
paned_.set_position(300); paned_.set_position(300);

10
juci/window.h

@ -10,19 +10,17 @@
class Window : public Gtk::Window { class Window : public Gtk::Window {
public: public:
Window(); Window();
MainConfig& main_config() { return main_config_; }
// std::string OnSaveFileAs(); // std::string OnSaveFileAs();
Gtk::Box window_box_; Gtk::Box window_box_;
virtual ~Window() { } virtual ~Window() { }
MainConfig main_config_; MainConfig main_config;
Keybindings::Controller keybindings_; Keybindings::Controller keybindings;
Menu::Controller menu_; Menu::Controller menu;
Notebook::Controller notebook; Notebook::Controller notebook;
Terminal::Controller terminal; Terminal::Controller terminal;
PluginApi api_; PluginApi api;
Keybindings::Controller& keybindings() { return keybindings_; }
private: private:
std::mutex running; std::mutex running;
Gtk::VPaned paned_; Gtk::VPaned paned_;

Loading…
Cancel
Save