From 7ec25e0c4adbffd8e4ec4886f4161e6db1fdf618 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 13 Aug 2015 23:03:26 +0200 Subject: [PATCH 01/25] Theme cleanup. Will try to add more clang_types to config.json Tomorrow. Remember to remove ~/.juci to get the latest changes. --- src/config.cc | 37 ++++++++--------- src/config.h | 1 - src/files.h | 47 +++++++-------------- src/juci.cc | 6 ++- src/singletons.cc | 4 +- src/singletons.h | 4 -- src/source.cc | 104 +++++++++++++++++++++++++++++----------------- src/source.h | 11 +++-- src/theme.h | 14 ------- src/tooltips.cc | 2 + src/window.h | 2 + 11 files changed, 116 insertions(+), 116 deletions(-) delete mode 100644 src/theme.h diff --git a/src/config.cc b/src/config.cc index 7aac125..8dfda00 100644 --- a/src/config.cc +++ b/src/config.cc @@ -10,20 +10,17 @@ MainConfig::MainConfig() { boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg); Singleton::Config::window()->keybindings = cfg.get_child("keybindings"); GenerateSource(); - GenerateTheme(); GenerateDirectoryFilter(); + + Singleton::Config::window()->theme=cfg.get("visual.gtk_theme"); + Singleton::Config::window()->theme_variant=cfg.get("visual.gtk_theme_variant"); + + boost::filesystem::create_directories(boost::filesystem::path(Singleton::style_dir())); + Singleton::Config::source()->style=cfg.get("visual.gtk_sourceview_style"); + Singleton::Config::terminal()->make_command=cfg.get("project.make_command"); } -void MainConfig::GenerateTheme() { - auto config = Singleton::Config::theme(); - auto props = cfg.get_child("theme"); - for (auto &prop : props) { - if (prop.first == "theme") config->theme = prop.second.get_value(); - if (prop.first == "main") config->main = prop.second.get_value(); - } -} - void MainConfig::find_or_create_config_files() { std::vector files = {"config.json", "menu.xml", "plugins.py"}; boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir())); @@ -40,16 +37,18 @@ void MainConfig::find_or_create_config_files() { void MainConfig::GenerateSource() { auto source_cfg = Singleton::Config::source(); auto source_json = cfg.get_child("source"); - auto clang_types_json = source_json.get_child("clang_types"); - auto style_json = source_json.get_child("style"); - auto gsv_json = source_json.get_child("sourceview"); - for (auto &i : gsv_json) - source_cfg->gsv[i.first] = i.second.get_value(); - for (auto &i : style_json) - source_cfg->tags[i.first] = i.second.get_value(); - for (auto &i : clang_types_json) - source_cfg->types[i.first] = i.second.get_value(); + source_cfg->tab_size = source_json.get("tab_size"); + source_cfg->tab_char = source_json.get("tab_char"); + for(unsigned c=0;ctab_size;c++) + source_cfg->tab+=source_cfg->tab_char; + + source_cfg->highlight_current_line = source_json.get_value("highlight_current_line"); + source_cfg->show_line_numbers = source_json.get_value("show_line_numbers"); + + + for (auto &i : source_json.get_child("clang_types")) + source_cfg->clang_types[i.first] = i.second.get_value(); } void MainConfig::GenerateDirectoryFilter() { diff --git a/src/config.h b/src/config.h index 4362fb0..b0b5afd 100644 --- a/src/config.h +++ b/src/config.h @@ -11,7 +11,6 @@ public: void PrintMenu(); void GenerateSource(); void GenerateDirectoryFilter(); - void GenerateTheme(); private: boost::property_tree::ptree cfg; }; diff --git a/src/files.h b/src/files.h index 4ac51f0..bcc9a69 100644 --- a/src/files.h +++ b/src/files.h @@ -1,36 +1,23 @@ #include const std::string configjson = "{\n" +" \"visual\": {\n" +" \"gtk_theme\": \"Adwaita\", //At least these two exist on all systems: Adwaita, Raleigh\n" +" \"gtk_theme_variant\": \"\", //\"\" for default, \"dark\" for dark theme variant\n" +" \"gtk_sourceview_style\": \"classic\" //Choices on default install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\n" +" },\n" " \"source\": {\n" -" \"colors\": {\n" -" \"text_color\": \"black\",\n" -" \"string\": \"#CC0000\",\n" -" \"namespace_ref\": \"#990099\",\n" -" \"type\": \"#0066FF\",\n" -" \"keyword\": \"blue\",\n" -" \"comment\": \"grey\",\n" -" \"own\": \"pink\",\n" -" \"diagnostic_warning\": \"orange\",\n" -" \"diagnostic_error\": \"red\"\n" -" },\n" -" \"syntax\": {\n" -" \"43\": \"type\",\n" -" \"46\": \"namespace_ref\",\n" -" \"109\": \"string\",\n" -" \"702\": \"keyword\",\n" -" \"703\": \"own\",\n" -" \"705\": \"comment\"\n" -" },\n" -" \"visual\": {\n" -" \"background\": \"white\",\n" -" \"background_selected\": \"blue\",\n" -" \"background_tooltips\": \"yellow\",\n" -" \"font\": \"Monospace\",\n" -" \"show_line_numbers\": 1,\n" -" \"highlight_current_line\": 1\n" +" \"clang_types\": {\n" +" \"43\": \"def:type\",\n" +" \"46\": \"def:preprocessor\",\n" +" \"109\": \"def:constant\",\n" +" \"702\": \"def:statement\",\n" +" \"705\": \"def:comment\"\n" " },\n" " \"tab_size\": 2,\n" -" \"tab_char\": \"\"\n" +" \"tab_char\": \" \", //Use \"\\t\" for regular tab\n" +" \"highlight_current_line\": true,\n" +" \"show_line_numbers\": true\n" " },\n" " \"keybindings\": {\n" " \"new_file\": \"n\",\n" @@ -67,12 +54,10 @@ const std::string configjson = " \"#\",\n" " \"~\",\n" " \".idea\",\n" -" \".so\",\n" -" \"in-lowercase.pls\"\n" +" \".so\"\n" " ],\n" " \"exceptions\": [\n" -" \"cmakelists.txt\",\n" -" \"in-lowercase.pls\"\n" +" \"cmakelists.txt\"\n" " ]\n" " }\n" "}\n"; diff --git a/src/juci.cc b/src/juci.cc index b95da2d..4aa992f 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -3,6 +3,8 @@ #include "config.h" #include +using namespace std; //TODO: remove + void init_logging() { add_common_attributes(); add_file_log(keywords::file_name = Singleton::log_dir() + "juci.log", @@ -49,11 +51,11 @@ void app::on_activate() { app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) { MainConfig(); // Read the configs here - auto css_provider = Gtk::CssProvider::get_default(); auto style_context = Gtk::StyleContext::create(); auto screen = Gdk::Screen::get_default(); + auto css_provider = Gtk::CssProvider::get_named(Singleton::Config::window()->theme, Singleton::Config::window()->theme_variant); + //TODO: add check if theme exists, or else write error to Singleton::terminal() style_context->add_provider_for_screen(screen, css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); - css_provider->load_from_path(Singleton::theme_dir() + Singleton::Config::theme()->current_theme()); } int main(int argc, char *argv[]) { diff --git a/src/singletons.cc b/src/singletons.cc index 7039985..dd9d926 100644 --- a/src/singletons.cc +++ b/src/singletons.cc @@ -1,8 +1,8 @@ #include "singletons.h" std::unique_ptr Singleton::Config::source_=std::unique_ptr(new Source::Config()); -std::unique_ptr Singleton::Config::directories_=std::unique_ptr(new Directories::Config());std::unique_ptr Singleton::Config::terminal_=std::unique_ptr(new Terminal::Config()); -std::unique_ptr Singleton::Config::theme_ = std::unique_ptr(new Theme::Config()); +std::unique_ptr Singleton::Config::directories_=std::unique_ptr(new Directories::Config()); +std::unique_ptr Singleton::Config::terminal_=std::unique_ptr(new Terminal::Config()); std::unique_ptr Singleton::Config::window_ = std::unique_ptr(new Window::Config()); std::unique_ptr Singleton::terminal_=std::unique_ptr(); diff --git a/src/singletons.h b/src/singletons.h index f65a3d9..de07113 100644 --- a/src/singletons.h +++ b/src/singletons.h @@ -7,7 +7,6 @@ #include "directories.h" #include "terminal.h" #include "notebook.h" -#include "theme.h" #include "menu.h" #include #include @@ -18,19 +17,16 @@ public: public: static Source::Config *source() {return source_.get();} static Directories::Config *directories() {return directories_.get();} - static Theme::Config *theme() { return theme_.get(); } static Window::Config *window() { return window_.get(); } static Terminal::Config *terminal() {return terminal_.get();} private: static std::unique_ptr source_; - static std::unique_ptr theme_; static std::unique_ptr window_; static std::unique_ptr directories_; static std::unique_ptr terminal_; }; static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } - static std::string theme_dir() { return std::string(getenv("HOME")) + "/.juci/gtk-themes/"; } static std::string log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; } static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } static Terminal *terminal(); diff --git a/src/source.cc b/src/source.cc index ca6ca14..0a7dcf4 100644 --- a/src/source.cc +++ b/src/source.cc @@ -56,18 +56,19 @@ Source::View::View(const boost::filesystem::path &file_path): file_path(file_pat //TODO: (gtkmm's Gtk::Object has connect_property_changed, so subclassing this might be an idea) g_signal_connect(search_context, "notify::occurrences-count", G_CALLBACK(search_occurrences_updated), this); - // style + //TODO: Move this to notebook? Might take up too much memory doing this for every tab. auto style_scheme_manager=Gsv::StyleSchemeManager::get_default(); style_scheme_manager->prepend_search_path(Singleton::style_dir()); - auto scheme = style_scheme_manager->get_scheme(Singleton::Config::theme()->theme); + auto scheme = style_scheme_manager->get_scheme(Singleton::Config::source()->style); - if(scheme) { + if(scheme) get_source_buffer()->set_style_scheme(scheme); - } + else + Singleton::terminal()->print("Error: Could not find gtksourceview style: "+Singleton::Config::source()->style+'\n'); - property_highlight_current_line() = Singleton::Config::source()->gsv["highlight_current_line"] == "true"; - property_show_line_numbers() = Singleton::Config::source()->gsv["show_line_numbers"] == "true"; + property_highlight_current_line() = Singleton::Config::source()->highlight_current_line; + property_show_line_numbers() = Singleton::Config::source()->show_line_numbers; } void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) { @@ -388,50 +389,77 @@ clang::Index Source::ClangViewParse::clang_index(0, 0); Source::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path): Source::View(file_path), project_path(project_path) { - for (auto &item : Singleton::Config::source()->tags) { - auto scheme = get_source_buffer()->get_style_scheme(); + auto scheme = get_source_buffer()->get_style_scheme(); + for (auto &item : Singleton::Config::source()->clang_types) { auto style = scheme->get_style(item.second); - if (style) { - DEBUG("Style " + item.second + " found in style " + scheme->get_name()); - auto tag = get_source_buffer()->create_tag(item.first); - if (style->property_foreground_set()) - tag->property_foreground() = style->property_foreground(); - if (style->property_background_set()) - tag->property_background() = style->property_background(); - if (style->property_strikethrough_set()) - tag->property_strikethrough() = style->property_strikethrough(); + auto tag = get_source_buffer()->create_tag(item.second); + if (style) { + DEBUG("Style " + item.second + " found in style " + scheme->get_name()); + if (style->property_foreground_set()) + tag->property_foreground() = style->property_foreground(); + if (style->property_background_set()) + tag->property_background() = style->property_background(); + if (style->property_strikethrough_set()) + tag->property_strikethrough() = style->property_strikethrough(); // // if (style->property_bold_set()) tag->property_weight() = style->property_bold(); // // if (style->property_italic_set()) tag->property_italic() = style->property_italic(); // // if (style->property_line_background_set()) tag->property_line_background() = style->property_line_background(); // // if (style->property_underline_set()) tag->property_underline() = style->property_underline(); - } else { + } else DEBUG("Style " + item.second + " not found in " + scheme->get_name()); - get_source_buffer()->create_tag(item.first)->property_foreground() = item.second; - } } INFO("Tagtable filled"); - //Create underline color tags for diagnostic warnings and errors: - auto diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_warning"); + //Create tags for diagnostic warnings and errors: + auto style=scheme->get_style("def:warning"); + auto diagnostic_tag=get_source_buffer()->create_tag("diagnostic_warning"); auto diagnostic_tag_underline=Gtk::TextTag::create("diagnostic_warning_underline"); - get_buffer()->get_tag_table()->add(diagnostic_tag_underline); - diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR; - auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions: - auto param_spec=g_object_class_find_property(tag_class, "underline-rgba"); - if(param_spec!=NULL) { - diagnostic_tag_underline->set_property("underline-rgba", diagnostic_tag->property_foreground_rgba().get_value()); + if(style && (style->property_foreground_set() || style->property_background_set())) { + Glib::ustring warning_property; + if(style->property_foreground_set()) { + warning_property=style->property_foreground().get_value(); + diagnostic_tag->property_foreground() = warning_property; + } + else if(style->property_background_set()) + warning_property=style->property_background().get_value(); + + get_buffer()->get_tag_table()->add(diagnostic_tag_underline); + diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR; + auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions: + auto param_spec=g_object_class_find_property(tag_class, "underline-rgba"); + if(param_spec!=NULL) { + diagnostic_tag_underline->set_property("underline-rgba", Gdk::RGBA(warning_property)); + } } - diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_error"); + style=scheme->get_style("def:error"); + diagnostic_tag=get_source_buffer()->create_tag("diagnostic_error"); diagnostic_tag_underline=Gtk::TextTag::create("diagnostic_error_underline"); - get_buffer()->get_tag_table()->add(diagnostic_tag_underline); - diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR; - tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions: - param_spec=g_object_class_find_property(tag_class, "underline-rgba"); - if(param_spec!=NULL) { - diagnostic_tag_underline->set_property("underline-rgba", diagnostic_tag->property_foreground_rgba().get_value()); + if(style && (style->property_foreground_set() || style->property_background_set())) { + Glib::ustring error_property; + if(style->property_foreground_set()) { + error_property=style->property_foreground().get_value(); + diagnostic_tag->property_foreground() = error_property; + } + else if(style->property_background_set()) + error_property=style->property_background().get_value(); + + get_buffer()->get_tag_table()->add(diagnostic_tag_underline); + diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR; + auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions: + auto param_spec=g_object_class_find_property(tag_class, "underline-rgba"); + if(param_spec!=NULL) { + diagnostic_tag_underline->set_property("underline-rgba", Gdk::RGBA(error_property)); + } } //TODO: clear tag_class and param_spec? + //Add tooltip background + style = scheme->get_style("def:note"); + auto tag=get_source_buffer()->create_tag("tooltip_background"); + if(style->property_background_set()) { + tag->property_background()=style->property_background(); + } + parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path.string()); //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: @@ -604,16 +632,14 @@ void Source::ClangViewParse::update_syntax() { for (auto &range : ranges) { auto type = boost::lexical_cast(range.kind); try { - last_syntax_tags.emplace(Singleton::Config::source()->types.at(type)); + last_syntax_tags.emplace(Singleton::Config::source()->clang_types.at(type)); } catch (std::exception) { continue; } Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset); Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset); - buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type), - begin_iter, end_iter); - + buffer->apply_tag_by_name(Singleton::Config::source()->clang_types.at(type), begin_iter, end_iter); } } diff --git a/src/source.h b/src/source.h index a888fae..9211eb4 100644 --- a/src/source.h +++ b/src/source.h @@ -20,10 +20,13 @@ namespace Source { class Config { public: - unsigned tab_size = 2; - char tab_char = ' '; - std::string tab = " "; - std::unordered_map tags, types, gsv; + std::string style; + unsigned tab_size; + char tab_char; + std::string tab; + bool highlight_current_line; + bool show_line_numbers; + std::unordered_map clang_types; }; class Range { diff --git a/src/theme.h b/src/theme.h deleted file mode 100644 index 7b915ea..0000000 --- a/src/theme.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef JUCI_THEME_H_ -#define JUCI_THEME_H_ - -#include - -namespace Theme { - class Config { - public: - std::string current_theme() { return theme + "/" + main; } - std::string theme, main; - }; -} - -#endif // JUCI_THEME_H_ diff --git a/src/tooltips.cc b/src/tooltips.cc index c76e7dc..6e962e1 100644 --- a/src/tooltips.cc +++ b/src/tooltips.cc @@ -54,6 +54,8 @@ void Tooltip::adjust(bool disregard_drawn) { tooltip_widget=std::unique_ptr(new Gtk::TextView(create_tooltip_buffer())); wrap_lines(tooltip_widget->get_buffer()); tooltip_widget->set_editable(false); + auto tag=text_view.get_buffer()->get_tag_table()->lookup("tooltip_background"); + tooltip_widget->override_background_color(tag->property_background_rgba()); window->add(*tooltip_widget); auto layout=Pango::Layout::create(tooltip_widget->get_pango_context()); diff --git a/src/window.h b/src/window.h index f2b57f1..ba6cc1f 100644 --- a/src/window.h +++ b/src/window.h @@ -16,6 +16,8 @@ public: Notebook notebook; class Config { public: + std::string theme; + std::string theme_variant; boost::property_tree::ptree keybindings; }; From 22f34d61a27db97ab3133b3dcd868e781f2b80a2 Mon Sep 17 00:00:00 2001 From: eidheim Date: Thu, 13 Aug 2015 23:20:25 +0200 Subject: [PATCH 02/25] Modified comments slightly in files.h. --- src/files.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/files.h b/src/files.h index bcc9a69..a20bb82 100644 --- a/src/files.h +++ b/src/files.h @@ -2,8 +2,8 @@ const std::string configjson = "{\n" " \"visual\": {\n" -" \"gtk_theme\": \"Adwaita\", //At least these two exist on all systems: Adwaita, Raleigh\n" -" \"gtk_theme_variant\": \"\", //\"\" for default, \"dark\" for dark theme variant\n" +" \"gtk_theme\": \"Adwaita\", //Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\n" +" \"gtk_theme_variant\": \"\", //Use \"\" for default variant, and \"dark\" for dark theme variant\n" " \"gtk_sourceview_style\": \"classic\" //Choices on default install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\n" " },\n" " \"source\": {\n" From 391e799ac6df70c7983ba7d7cd4b80326d0d4348 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 14 Aug 2015 07:19:06 +0200 Subject: [PATCH 03/25] Fixed smart paste when text is selected, and now sets project_path if file opened is outside of current directory-project_path. --- src/notebook.cc | 4 ++-- src/source.cc | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index 146cc8e..3bc8f0e 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -55,7 +55,7 @@ void Notebook::open(const boost::filesystem::path &file_path) { auto language=Source::guess_language(file_path); if(language && (language->get_id()=="chdr" || language->get_id()=="c" || language->get_id()=="cpp" || language->get_id()=="objc")) { boost::filesystem::path project_path; - if(directories.cmake && directories.cmake->project_path!="") + if(directories.cmake && directories.cmake->project_path!="" && file_path.string().substr(0, directories.cmake->project_path.string().size())==directories.cmake->project_path.string()) project_path=directories.cmake->project_path; else { project_path=file_path.parent_path(); @@ -119,7 +119,7 @@ bool Notebook::save(int page) { //If CMakeLists.txt have been modified: //TODO: recreate cmake even without directories open? if(view->file_path.filename()=="CMakeLists.txt") { - if(directories.cmake && directories.cmake->project_path!="" && view->file_path>=directories.cmake->project_path && CMake::create_compile_commands(directories.cmake->project_path)) { + if(directories.cmake && directories.cmake->project_path!="" && view->file_path.string().substr(0, directories.cmake->project_path.string().size())==directories.cmake->project_path.string() && CMake::create_compile_commands(directories.cmake->project_path)) { directories.open_folder(); for(auto source_view: source_views) { if(auto source_clang_view=dynamic_cast(source_view)) { diff --git a/src/source.cc b/src/source.cc index 0a7dcf4..2cfdcfd 100644 --- a/src/source.cc +++ b/src/source.cc @@ -149,7 +149,7 @@ void Source::View::paste() { auto line=get_line_before_insert(); std::smatch sm; std::string prefix_tabs; - if(std::regex_match(line, sm, spaces_regex) && sm[2].str().size()==0) { + if(!get_buffer()->get_has_selection() && std::regex_match(line, sm, spaces_regex) && sm[2].str().size()==0) { prefix_tabs=sm[1].str(); Glib::ustring::size_type start_line=0; From 0dca04a04f5ea1c73ccfc12afe6b9380f31e345f Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 14 Aug 2015 09:44:28 +0200 Subject: [PATCH 04/25] Juci now handles UTF-8 all the way. --- src/source.cc | 62 +++++++++++++++++++++++++-------------------------- src/source.h | 14 +++++------- src/window.cc | 2 +- 3 files changed, 36 insertions(+), 42 deletions(-) diff --git a/src/source.cc b/src/source.cc index 2cfdcfd..da52d62 100644 --- a/src/source.cc +++ b/src/source.cc @@ -510,8 +510,6 @@ void Source::ClangViewParse::init_parse() { parse_thread_stop=false; - int start_offset = get_source_buffer()->begin().get_offset(); - int end_offset = get_source_buffer()->end().get_offset(); auto buffer_map=get_buffer_map(); //Remove includes for first parse for initial syntax highlighting auto& str=buffer_map[file_path.string()]; @@ -526,9 +524,7 @@ void Source::ClangViewParse::init_parse() { } pos++; } - init_syntax_highlighting(buffer_map, - start_offset, - end_offset); + init_syntax_highlighting(buffer_map); update_syntax(); set_status("parsing..."); @@ -555,11 +551,7 @@ void Source::ClangViewParse::init_parse() { }); } -void Source::ClangViewParse:: -init_syntax_highlighting(const std::map - &buffers, - int start_offset, - int end_offset) { +void Source::ClangViewParse::init_syntax_highlighting(const std::map &buffers) { std::vector arguments = get_compilation_commands(); clang_tu = std::unique_ptr(new clang::TranslationUnit(clang_index, file_path.string(), @@ -612,15 +604,15 @@ void Source::ClangViewParse::update_syntax() { std::vector ranges; for (auto &token : *clang_tokens) { if(token.get_kind()==0) // PunctuationToken - ranges.emplace_back(token.offsets.first, token.offsets.second, (int) token.get_cursor().get_kind()); + ranges.emplace_back(token.offsets, (int) token.get_cursor().get_kind()); else if(token.get_kind()==1) // KeywordToken - ranges.emplace_back(token.offsets.first, token.offsets.second, 702); + ranges.emplace_back(token.offsets, 702); else if(token.get_kind()==2) // IdentifierToken - ranges.emplace_back(token.offsets.first, token.offsets.second, (int) token.get_cursor().get_kind()); + ranges.emplace_back(token.offsets, (int) token.get_cursor().get_kind()); else if(token.get_kind()==3) // LiteralToken - ranges.emplace_back(token.offsets.first, token.offsets.second, 109); + ranges.emplace_back(token.offsets, 109); else if(token.get_kind()==4) // CommentToken - ranges.emplace_back(token.offsets.first, token.offsets.second, 705); + ranges.emplace_back(token.offsets, 705); } if (ranges.empty() || ranges.size() == 0) { return; @@ -637,8 +629,8 @@ void Source::ClangViewParse::update_syntax() { continue; } - Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset); - Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset); + Gtk::TextIter 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); buffer->apply_tag_by_name(Singleton::Config::source()->clang_types.at(type), begin_iter, end_iter); } } @@ -650,8 +642,8 @@ void Source::ClangViewParse::update_diagnostics() { auto diagnostics=clang_tu->get_diagnostics(); for(auto &diagnostic: diagnostics) { if(diagnostic.path==file_path.string()) { - auto start=get_buffer()->get_iter_at_offset(diagnostic.offsets.first); - auto end=get_buffer()->get_iter_at_offset(diagnostic.offsets.second); + auto start=get_buffer()->get_iter_at_line_index(diagnostic.offsets.first.line-1, diagnostic.offsets.first.index-1); + auto end=get_buffer()->get_iter_at_line_index(diagnostic.offsets.second.line-1, diagnostic.offsets.second.index-1); std::string diagnostic_tag_name; if(diagnostic.severity<=CXDiagnostic_Warning) diagnostic_tag_name="diagnostic_warning"; @@ -678,8 +670,8 @@ void Source::ClangViewParse::update_types() { type_tooltips.clear(); for(auto &token: *clang_tokens) { if(token.get_kind()==clang::Token_Identifier && token.has_type()) { - auto start=get_buffer()->get_iter_at_offset(token.offsets.first); - auto end=get_buffer()->get_iter_at_offset(token.offsets.second); + auto start=get_buffer()->get_iter_at_line_index(token.offsets.first.line-1, token.offsets.first.index-1); + auto end=get_buffer()->get_iter_at_line_index(token.offsets.second.line-1, token.offsets.second.index-1); auto create_tooltip_buffer=[this, &token]() { auto tooltip_buffer=Gtk::TextBuffer::create(get_buffer()->get_tag_table()); tooltip_buffer->insert_at_cursor("Type: "+token.get_type()); @@ -1095,10 +1087,12 @@ Source::ClangViewAutocomplete(file_path, project_path) { get_token=[this]() -> std::string { if(clang_readable) { + auto iter=get_buffer()->get_insert()->get_iter(); + auto line=(unsigned)iter.get_line(); + auto index=(unsigned)iter.get_line_index(); for(auto &token: *clang_tokens) { if(token.get_kind()==clang::Token_Identifier && token.has_type()) { - auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset(); - if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) { + if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { auto referenced=token.get_cursor().get_referenced(); if(referenced) return referenced.get_usr(); @@ -1111,10 +1105,12 @@ Source::ClangViewAutocomplete(file_path, project_path) { get_token_name=[this]() -> std::string { if(clang_readable) { + auto iter=get_buffer()->get_insert()->get_iter(); + auto line=(unsigned)iter.get_line(); + auto index=(unsigned)iter.get_line_index(); for(auto &token: *clang_tokens) { if(token.get_kind()==clang::Token_Identifier && token.has_type()) { - auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset(); - if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) { + if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { return token.get_spelling(); } } @@ -1129,7 +1125,7 @@ Source::ClangViewAutocomplete(file_path, project_path) { get_buffer()->remove_tag(similar_tokens_tag, get_buffer()->begin(), get_buffer()->end()); auto offsets=clang_tokens->get_similar_token_offsets(usr); for(auto &offset: offsets) { - get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_offset(offset.first), get_buffer()->get_iter_at_offset(offset.second)); + get_buffer()->apply_tag(similar_tokens_tag, get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1), get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1)); } last_similar_tokens_tagged=usr; } @@ -1146,7 +1142,7 @@ Source::ClangViewAutocomplete(file_path, project_path) { auto offsets=clang_tokens->get_similar_token_offsets(usr); std::vector, Glib::RefPtr > > marks; for(auto &offset: offsets) { - marks.emplace_back(get_buffer()->create_mark(get_buffer()->get_iter_at_offset(offset.first)), get_buffer()->create_mark(get_buffer()->get_iter_at_offset(offset.second))); + marks.emplace_back(get_buffer()->create_mark(get_buffer()->get_iter_at_line_index(offset.first.line-1, offset.first.index-1)), get_buffer()->create_mark(get_buffer()->get_iter_at_line_index(offset.second.line-1, offset.second.index-1))); number++; } get_source_buffer()->begin_user_action(); @@ -1171,12 +1167,14 @@ Source::ClangViewAutocomplete(file_path, project_path) { }); get_declaration_location=[this](){ - std::pair location; + std::pair location; if(clang_readable) { + auto iter=get_buffer()->get_insert()->get_iter(); + auto line=(unsigned)iter.get_line(); + auto index=(unsigned)iter.get_line_index(); for(auto &token: *clang_tokens) { if(token.get_kind()==clang::Token_Identifier && token.has_type()) { - auto insert_offset=(unsigned)get_buffer()->get_insert()->get_iter().get_offset(); - if(insert_offset>=token.offsets.first && insert_offset<=token.offsets.second) { + if(line==token.offsets.first.line-1 && index>=token.offsets.first.index-1 && index <=token.offsets.second.index-1) { auto referenced=token.get_cursor().get_referenced(); if(referenced) { location.first=referenced.get_source_location().get_path(); @@ -1193,7 +1191,7 @@ Source::ClangViewAutocomplete(file_path, project_path) { goto_method=[this](){ if(clang_readable) { selection_dialog=std::unique_ptr(new SelectionDialog(*this, get_buffer()->create_mark(get_buffer()->get_insert()->get_iter()))); - auto rows=std::make_shared >(); + auto rows=std::make_shared >(); auto methods=clang_tokens->get_cxx_methods(); if(methods.size()==0) return; @@ -1204,7 +1202,7 @@ Source::ClangViewAutocomplete(file_path, project_path) { //TODO see if rows gets destroyed when selection_dialog gets destroyed. selection_dialog->on_select=[this, rows](const std::string& selected, bool hide_window) { auto offset=rows->at(selected); - get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(offset)); + get_buffer()->place_cursor(get_buffer()->get_iter_at_line_index(offset.line-1, offset.index-1)); scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); delayed_tooltips_connection.disconnect(); }; diff --git a/src/source.h b/src/source.h index 9211eb4..30b67a3 100644 --- a/src/source.h +++ b/src/source.h @@ -31,10 +31,9 @@ namespace Source { class Range { public: - Range(unsigned start_offset, unsigned end_offset, int kind): - start_offset(start_offset), end_offset(end_offset), kind(kind) {} - unsigned start_offset; - unsigned end_offset; + Range(std::pair offsets, int kind): + offsets(offsets), kind(kind) {} + std::pair offsets; int kind; }; @@ -63,7 +62,7 @@ namespace Source { boost::filesystem::path file_path; - std::function()> get_declaration_location; + std::function()> get_declaration_location; std::function goto_method; std::function get_token; std::function get_token_name; @@ -112,10 +111,7 @@ namespace Source { private: std::map get_buffer_map() const; // inits the syntax highligthing on file open - void init_syntax_highlighting(const std::map - &buffers, - int start_offset, - int end_offset); + void init_syntax_highlighting(const std::map &buffers); int reparse(const std::map &buffers); void update_syntax(); std::set last_syntax_tags; diff --git a/src/window.cc b/src/window.cc index 5314f91..2985a12 100644 --- a/src/window.cc +++ b/src/window.cc @@ -194,7 +194,7 @@ void Window::create_menu() { auto location=notebook.get_current_view()->get_declaration_location(); if(location.first.size()>0) { notebook.open(location.first); - notebook.get_current_view()->get_buffer()->place_cursor(notebook.get_current_view()->get_buffer()->get_iter_at_offset(location.second)); + notebook.get_current_view()->get_buffer()->place_cursor(notebook.get_current_view()->get_buffer()->get_iter_at_line_index(location.second.line-1, location.second.index-1)); while(gtk_events_pending()) gtk_main_iteration(); notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); From 7ce2901bc4f7c3f92fc59f9cc241ecd52e8aad8e Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 14 Aug 2015 09:59:15 +0200 Subject: [PATCH 05/25] Small menu cleanup. --- src/files.h | 8 ++++++-- src/source.cc | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/files.h b/src/files.h index a20bb82..a1bb2b0 100644 --- a/src/files.h +++ b/src/files.h @@ -70,21 +70,24 @@ const std::string menuxml = " \n" " \n" " \n" +" \n" " \n" " \n" +" \n" " \n" " \n" " \n" " \n" " \n" " \n" +" \n" +" \n" +" \n" " \n" " \n" " \n" " \n" " \n" -" \n" -" \n" " \n" " \n" " \n" @@ -97,6 +100,7 @@ const std::string menuxml = " \n" " \n" " \n" +" \n" " \n" " \n" " \n" diff --git a/src/source.cc b/src/source.cc index da52d62..127205d 100644 --- a/src/source.cc +++ b/src/source.cc @@ -562,7 +562,7 @@ void Source::ClangViewParse::init_syntax_highlighting(const std::map Source::ClangViewParse::get_buffer_map() const { std::map buffer_map; - buffer_map[file_path.string()]=get_source_buffer()->get_text().raw(); + buffer_map[file_path.string()]=get_source_buffer()->get_text(); return buffer_map; } From fd4b6aef8a1213e040f541ec89dc24be70e42883 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 14 Aug 2015 11:08:23 +0200 Subject: [PATCH 06/25] Added default juci style, and option to set font (only the source font like gedit does it). --- src/config.cc | 7 ++++++- src/files.h | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++- src/source.cc | 2 ++ src/source.h | 1 + 4 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/config.cc b/src/config.cc index 8dfda00..3f3c85b 100644 --- a/src/config.cc +++ b/src/config.cc @@ -16,6 +16,10 @@ MainConfig::MainConfig() { Singleton::Config::window()->theme_variant=cfg.get("visual.gtk_theme_variant"); boost::filesystem::create_directories(boost::filesystem::path(Singleton::style_dir())); + boost::filesystem::path juci_style_path=Singleton::style_dir(); + juci_style_path+="juci.xml"; + if(!boost::filesystem::exists(juci_style_path)) + juci::filesystem::write(juci_style_path, juci_style); Singleton::Config::source()->style=cfg.get("visual.gtk_sourceview_style"); Singleton::Config::terminal()->make_command=cfg.get("project.make_command"); @@ -46,9 +50,10 @@ void MainConfig::GenerateSource() { source_cfg->highlight_current_line = source_json.get_value("highlight_current_line"); source_cfg->show_line_numbers = source_json.get_value("show_line_numbers"); - for (auto &i : source_json.get_child("clang_types")) source_cfg->clang_types[i.first] = i.second.get_value(); + + source_cfg->font=source_json.get("font"); } void MainConfig::GenerateDirectoryFilter() { diff --git a/src/files.h b/src/files.h index a1bb2b0..7a64a9e 100644 --- a/src/files.h +++ b/src/files.h @@ -4,9 +4,10 @@ const std::string configjson = " \"visual\": {\n" " \"gtk_theme\": \"Adwaita\", //Use \"\" for default theme, At least these two exist on all systems: Adwaita, Raleigh\n" " \"gtk_theme_variant\": \"\", //Use \"\" for default variant, and \"dark\" for dark theme variant\n" -" \"gtk_sourceview_style\": \"classic\" //Choices on default install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\n" +" \"gtk_sourceview_style\": \"juci\" //Choices on default install: classic, cobalt, kate, oblivion, solarized-dark, solarized-light, tango\n" " },\n" " \"source\": {\n" +" \"font\": \"Monospace\", //Use \"\" for default font, and for instance \"Monospace 12\" to also set size.\n" " \"clang_types\": {\n" " \"43\": \"def:type\",\n" " \"46\": \"def:preprocessor\",\n" @@ -117,6 +118,56 @@ const std::string menuxml = " \n" "\n"; +const std::string juci_style = +"\n" +"\n" +"\n" +" juCi++ team\n" +" <_description>Default juCi++ style\n" +"\n" +" \n" +" \n" +" \n" +" \n" +" \n" +" \n" +"\n" +" \n" +"