Browse Source

Theme cleanup. Will try to add more clang_types to config.json Tomorrow. Remember to remove ~/.juci to get the latest changes.

merge-requests/365/head
eidheim 10 years ago
parent
commit
7ec25e0c4a
  1. 37
      src/config.cc
  2. 1
      src/config.h
  3. 47
      src/files.h
  4. 6
      src/juci.cc
  5. 4
      src/singletons.cc
  6. 4
      src/singletons.h
  7. 104
      src/source.cc
  8. 11
      src/source.h
  9. 14
      src/theme.h
  10. 2
      src/tooltips.cc
  11. 2
      src/window.h

37
src/config.cc

@ -10,18 +10,15 @@ MainConfig::MainConfig() {
boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg); boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg);
Singleton::Config::window()->keybindings = cfg.get_child("keybindings"); Singleton::Config::window()->keybindings = cfg.get_child("keybindings");
GenerateSource(); GenerateSource();
GenerateTheme();
GenerateDirectoryFilter(); GenerateDirectoryFilter();
Singleton::Config::terminal()->make_command=cfg.get<std::string>("project.make_command");
}
void MainConfig::GenerateTheme() { Singleton::Config::window()->theme=cfg.get<std::string>("visual.gtk_theme");
auto config = Singleton::Config::theme(); Singleton::Config::window()->theme_variant=cfg.get<std::string>("visual.gtk_theme_variant");
auto props = cfg.get_child("theme");
for (auto &prop : props) { boost::filesystem::create_directories(boost::filesystem::path(Singleton::style_dir()));
if (prop.first == "theme") config->theme = prop.second.get_value<std::string>(); Singleton::Config::source()->style=cfg.get<std::string>("visual.gtk_sourceview_style");
if (prop.first == "main") config->main = prop.second.get_value<std::string>();
} Singleton::Config::terminal()->make_command=cfg.get<std::string>("project.make_command");
} }
void MainConfig::find_or_create_config_files() { void MainConfig::find_or_create_config_files() {
@ -40,16 +37,18 @@ void MainConfig::find_or_create_config_files() {
void MainConfig::GenerateSource() { void MainConfig::GenerateSource() {
auto source_cfg = Singleton::Config::source(); auto source_cfg = Singleton::Config::source();
auto source_json = cfg.get_child("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->tab_size = source_json.get<unsigned>("tab_size");
source_cfg->gsv[i.first] = i.second.get_value<std::string>(); source_cfg->tab_char = source_json.get<char>("tab_char");
for (auto &i : style_json) for(unsigned c=0;c<source_cfg->tab_size;c++)
source_cfg->tags[i.first] = i.second.get_value<std::string>(); source_cfg->tab+=source_cfg->tab_char;
for (auto &i : clang_types_json)
source_cfg->types[i.first] = i.second.get_value<std::string>(); source_cfg->highlight_current_line = source_json.get_value<bool>("highlight_current_line");
source_cfg->show_line_numbers = source_json.get_value<bool>("show_line_numbers");
for (auto &i : source_json.get_child("clang_types"))
source_cfg->clang_types[i.first] = i.second.get_value<std::string>();
} }
void MainConfig::GenerateDirectoryFilter() { void MainConfig::GenerateDirectoryFilter() {

1
src/config.h

@ -11,7 +11,6 @@ public:
void PrintMenu(); void PrintMenu();
void GenerateSource(); void GenerateSource();
void GenerateDirectoryFilter(); void GenerateDirectoryFilter();
void GenerateTheme();
private: private:
boost::property_tree::ptree cfg; boost::property_tree::ptree cfg;
}; };

47
src/files.h

@ -1,36 +1,23 @@
#include <string> #include <string>
const std::string configjson = const std::string configjson =
"{\n" "{\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" " \"source\": {\n"
" \"colors\": {\n" " \"clang_types\": {\n"
" \"text_color\": \"black\",\n" " \"43\": \"def:type\",\n"
" \"string\": \"#CC0000\",\n" " \"46\": \"def:preprocessor\",\n"
" \"namespace_ref\": \"#990099\",\n" " \"109\": \"def:constant\",\n"
" \"type\": \"#0066FF\",\n" " \"702\": \"def:statement\",\n"
" \"keyword\": \"blue\",\n" " \"705\": \"def:comment\"\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"
" },\n" " },\n"
" \"tab_size\": 2,\n" " \"tab_size\": 2,\n"
" \"tab_char\": \"<space>\"\n" " \"tab_char\": \" \", //Use \"\\t\" for regular tab\n"
" \"highlight_current_line\": true,\n"
" \"show_line_numbers\": true\n"
" },\n" " },\n"
" \"keybindings\": {\n" " \"keybindings\": {\n"
" \"new_file\": \"<primary>n\",\n" " \"new_file\": \"<primary>n\",\n"
@ -67,12 +54,10 @@ const std::string configjson =
" \"#\",\n" " \"#\",\n"
" \"~\",\n" " \"~\",\n"
" \".idea\",\n" " \".idea\",\n"
" \".so\",\n" " \".so\"\n"
" \"in-lowercase.pls\"\n"
" ],\n" " ],\n"
" \"exceptions\": [\n" " \"exceptions\": [\n"
" \"cmakelists.txt\",\n" " \"cmakelists.txt\"\n"
" \"in-lowercase.pls\"\n"
" ]\n" " ]\n"
" }\n" " }\n"
"}\n"; "}\n";

6
src/juci.cc

@ -3,6 +3,8 @@
#include "config.h" #include "config.h"
#include <iostream> #include <iostream>
using namespace std; //TODO: remove
void init_logging() { void init_logging() {
add_common_attributes(); add_common_attributes();
add_file_log(keywords::file_name = Singleton::log_dir() + "juci.log", 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) { app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_NON_UNIQUE | Gio::APPLICATION_HANDLES_COMMAND_LINE) {
MainConfig(); // Read the configs here MainConfig(); // Read the configs here
auto css_provider = Gtk::CssProvider::get_default();
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, 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); 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[]) { int main(int argc, char *argv[]) {

4
src/singletons.cc

@ -1,8 +1,8 @@
#include "singletons.h" #include "singletons.h"
std::unique_ptr<Source::Config> Singleton::Config::source_=std::unique_ptr<Source::Config>(new Source::Config()); std::unique_ptr<Source::Config> Singleton::Config::source_=std::unique_ptr<Source::Config>(new Source::Config());
std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique_ptr<Directories::Config>(new Directories::Config());std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config()); std::unique_ptr<Directories::Config> Singleton::Config::directories_=std::unique_ptr<Directories::Config>(new Directories::Config());
std::unique_ptr<Theme::Config> Singleton::Config::theme_ = std::unique_ptr<Theme::Config>(new Theme::Config()); std::unique_ptr<Terminal::Config> Singleton::Config::terminal_=std::unique_ptr<Terminal::Config>(new Terminal::Config());
std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config()); std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config());
std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>(); std::unique_ptr<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>();

4
src/singletons.h

@ -7,7 +7,6 @@
#include "directories.h" #include "directories.h"
#include "terminal.h" #include "terminal.h"
#include "notebook.h" #include "notebook.h"
#include "theme.h"
#include "menu.h" #include "menu.h"
#include <gtkmm.h> #include <gtkmm.h>
#include <string> #include <string>
@ -18,19 +17,16 @@ public:
public: public:
static Source::Config *source() {return source_.get();} static Source::Config *source() {return source_.get();}
static Directories::Config *directories() {return directories_.get();} static Directories::Config *directories() {return directories_.get();}
static Theme::Config *theme() { return theme_.get(); }
static Window::Config *window() { return window_.get(); } static Window::Config *window() { return window_.get(); }
static Terminal::Config *terminal() {return terminal_.get();} static Terminal::Config *terminal() {return terminal_.get();}
private: private:
static std::unique_ptr<Source::Config> source_; static std::unique_ptr<Source::Config> source_;
static std::unique_ptr<Theme::Config> theme_;
static std::unique_ptr<Window::Config> window_; static std::unique_ptr<Window::Config> window_;
static std::unique_ptr<Directories::Config> directories_; static std::unique_ptr<Directories::Config> directories_;
static std::unique_ptr<Terminal::Config> terminal_; static std::unique_ptr<Terminal::Config> terminal_;
}; };
static std::string config_dir() { return std::string(getenv("HOME")) + "/.juci/config/"; } 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 log_dir() { return std::string(getenv("HOME")) + "/.juci/log/"; }
static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; } static std::string style_dir() { return std::string(getenv("HOME")) + "/.juci/styles/"; }
static Terminal *terminal(); static Terminal *terminal();

104
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) //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); 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(); auto style_scheme_manager=Gsv::StyleSchemeManager::get_default();
style_scheme_manager->prepend_search_path(Singleton::style_dir()); 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); 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_highlight_current_line() = Singleton::Config::source()->highlight_current_line;
property_show_line_numbers() = Singleton::Config::source()->gsv["show_line_numbers"] == "true"; property_show_line_numbers() = Singleton::Config::source()->show_line_numbers;
} }
void Source::View::search_occurrences_updated(GtkWidget* widget, GParamSpec* property, gpointer data) { 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::ClangViewParse::ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path):
Source::View(file_path), project_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); auto style = scheme->get_style(item.second);
if (style) { auto tag = get_source_buffer()->create_tag(item.second);
DEBUG("Style " + item.second + " found in style " + scheme->get_name()); if (style) {
auto tag = get_source_buffer()->create_tag(item.first); DEBUG("Style " + item.second + " found in style " + scheme->get_name());
if (style->property_foreground_set()) if (style->property_foreground_set())
tag->property_foreground() = style->property_foreground(); tag->property_foreground() = style->property_foreground();
if (style->property_background_set()) if (style->property_background_set())
tag->property_background() = style->property_background(); tag->property_background() = style->property_background();
if (style->property_strikethrough_set()) if (style->property_strikethrough_set())
tag->property_strikethrough() = style->property_strikethrough(); tag->property_strikethrough() = style->property_strikethrough();
// // if (style->property_bold_set()) tag->property_weight() = style->property_bold(); // // 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_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_line_background_set()) tag->property_line_background() = style->property_line_background();
// // if (style->property_underline_set()) tag->property_underline() = style->property_underline(); // // if (style->property_underline_set()) tag->property_underline() = style->property_underline();
} else { } else
DEBUG("Style " + item.second + " not found in " + scheme->get_name()); DEBUG("Style " + item.second + " not found in " + scheme->get_name());
get_source_buffer()->create_tag(item.first)->property_foreground() = item.second;
}
} }
INFO("Tagtable filled"); INFO("Tagtable filled");
//Create underline color tags for diagnostic warnings and errors: //Create tags for diagnostic warnings and errors:
auto diagnostic_tag=get_buffer()->get_tag_table()->lookup("diagnostic_warning"); 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"); auto diagnostic_tag_underline=Gtk::TextTag::create("diagnostic_warning_underline");
get_buffer()->get_tag_table()->add(diagnostic_tag_underline); if(style && (style->property_foreground_set() || style->property_background_set())) {
diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR; Glib::ustring warning_property;
auto tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions: if(style->property_foreground_set()) {
auto param_spec=g_object_class_find_property(tag_class, "underline-rgba"); warning_property=style->property_foreground().get_value();
if(param_spec!=NULL) { diagnostic_tag->property_foreground() = warning_property;
diagnostic_tag_underline->set_property("underline-rgba", diagnostic_tag->property_foreground_rgba().get_value()); }
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"); diagnostic_tag_underline=Gtk::TextTag::create("diagnostic_error_underline");
get_buffer()->get_tag_table()->add(diagnostic_tag_underline); if(style && (style->property_foreground_set() || style->property_background_set())) {
diagnostic_tag_underline->property_underline()=Pango::Underline::UNDERLINE_ERROR; Glib::ustring error_property;
tag_class=G_OBJECT_GET_CLASS(diagnostic_tag_underline->gobj()); //For older GTK+ 3 versions: if(style->property_foreground_set()) {
param_spec=g_object_class_find_property(tag_class, "underline-rgba"); error_property=style->property_foreground().get_value();
if(param_spec!=NULL) { diagnostic_tag->property_foreground() = error_property;
diagnostic_tag_underline->set_property("underline-rgba", diagnostic_tag->property_foreground_rgba().get_value()); }
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? //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()); parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path.string());
//GTK-calls must happen in main thread, so the parse_thread //GTK-calls must happen in main thread, so the parse_thread
//sends signals to the main thread that it is to call the following functions: //sends signals to the main thread that it is to call the following functions:
@ -604,16 +632,14 @@ void Source::ClangViewParse::update_syntax() {
for (auto &range : ranges) { for (auto &range : ranges) {
auto type = boost::lexical_cast<std::string>(range.kind); auto type = boost::lexical_cast<std::string>(range.kind);
try { 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) { } catch (std::exception) {
continue; continue;
} }
Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset); Gtk::TextIter begin_iter = buffer->get_iter_at_offset(range.start_offset);
Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset); Gtk::TextIter end_iter = buffer->get_iter_at_offset(range.end_offset);
buffer->apply_tag_by_name(Singleton::Config::source()->types.at(type), buffer->apply_tag_by_name(Singleton::Config::source()->clang_types.at(type), begin_iter, end_iter);
begin_iter, end_iter);
} }
} }

11
src/source.h

@ -20,10 +20,13 @@ namespace Source {
class Config { class Config {
public: public:
unsigned tab_size = 2; std::string style;
char tab_char = ' '; unsigned tab_size;
std::string tab = " "; char tab_char;
std::unordered_map<std::string, std::string> tags, types, gsv; std::string tab;
bool highlight_current_line;
bool show_line_numbers;
std::unordered_map<std::string, std::string> clang_types;
}; };
class Range { class Range {

14
src/theme.h

@ -1,14 +0,0 @@
#ifndef JUCI_THEME_H_
#define JUCI_THEME_H_
#include <string>
namespace Theme {
class Config {
public:
std::string current_theme() { return theme + "/" + main; }
std::string theme, main;
};
}
#endif // JUCI_THEME_H_

2
src/tooltips.cc

@ -54,6 +54,8 @@ void Tooltip::adjust(bool disregard_drawn) {
tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(create_tooltip_buffer())); tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(create_tooltip_buffer()));
wrap_lines(tooltip_widget->get_buffer()); wrap_lines(tooltip_widget->get_buffer());
tooltip_widget->set_editable(false); 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); window->add(*tooltip_widget);
auto layout=Pango::Layout::create(tooltip_widget->get_pango_context()); auto layout=Pango::Layout::create(tooltip_widget->get_pango_context());

2
src/window.h

@ -16,6 +16,8 @@ public:
Notebook notebook; Notebook notebook;
class Config { class Config {
public: public:
std::string theme;
std::string theme_variant;
boost::property_tree::ptree keybindings; boost::property_tree::ptree keybindings;
}; };

Loading…
Cancel
Save