Browse Source

gtk-3.0 theme support and support for gtksourceview styles

merge-requests/365/head
Jørgen Lien Sellæg 10 years ago
parent
commit
2161c76bf4
  1. 46
      src/config.cc
  2. 8
      src/config.h
  3. 13
      src/juci.cc
  4. 5
      src/singletons.cc
  5. 7
      src/singletons.h
  6. 14
      src/theme.h
  7. 1
      src/tooltips.cc
  8. 15
      src/window.cc
  9. 8
      src/window.h

46
src/config.cc

@ -5,15 +5,25 @@
#include "files.h"
#include "sourcefile.h"
MainConfig::MainConfig(Menu &menu) : menu(menu) {
MainConfig::MainConfig() {
find_or_create_config_files();
boost::property_tree::json_parser::read_json(Singleton::config_dir() + "config.json", cfg);
Singleton::Config::window()->keybindings = cfg.get_child("keybindings");
GenerateSource();
GenerateKeybindings();
GenerateTheme();
GenerateDirectoryFilter();
GenerateTerminalCommands();
}
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<std::string>();
if (prop.first == "main") config->main = prop.second.get_value<std::string>();
}
}
void MainConfig::find_or_create_config_files() {
std::vector<std::string> files = {"config.json", "menu.xml", "plugins.py"};
boost::filesystem::create_directories(boost::filesystem::path(Singleton::config_dir()));
@ -34,23 +44,6 @@ void MainConfig::GenerateSource() {
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 visual_json = source_json.get_child("visual");
for (auto &i : visual_json) {
if (i.first == "background")
source_cfg->background = i.second.get_value<std::string>();
else if (i.first == "background_selected")
source_cfg->background_selected = i.second.get_value<std::string>();
else if (i.first == "background_tooltips")
source_cfg->background_tooltips = i.second.get_value<std::string>();
else if (i.first == "show_line_numbers")
source_cfg->show_line_numbers = i.second.get_value<std::string>() == "1";
else if (i.first == "highlight_current_line")
source_cfg->highlight_current_line = i.second.get_value<std::string>() == "1";
else if (i.first == "font")
source_cfg->font = i.second.get_value<std::string>();
else if (i.first == "theme")
source_cfg->theme = i.second.get_value<std::string>();
}
source_cfg->tab_size = source_json.get<unsigned>("tab_size");
for (unsigned c = 0; c < source_cfg->tab_size; c++)
source_cfg->tab+=" ";
@ -72,21 +65,6 @@ void MainConfig::GenerateTerminalCommands() {
terminal_cfg->run_command=(i.second.get_value<std::string>()); //TODO: run_commands array->one run_command?
}
void MainConfig::GenerateKeybindings() {
boost::filesystem::path path(Singleton::config_dir() + "menu.xml");
if (!boost::filesystem::is_regular_file(path)) {
std::cerr << "menu.xml not found" << std::endl;
throw;
}
menu.ui = juci::filesystem::read(path);
boost::property_tree::ptree keys_json = cfg.get_child("keybindings");
for (auto &i : keys_json) {
auto key=i.second.get_value<std::string>();
menu.key_map[i.first] = key;
}
DEBUG("Keybindings fetched");
}
void MainConfig::GenerateDirectoryFilter() {
auto dir_cfg=Singleton::Config::directories();
DEBUG("Fetching directory filter");

8
src/config.h

@ -6,16 +6,16 @@
class MainConfig {
public:
MainConfig(Menu &menu);
MainConfig();
void find_or_create_config_files();
void PrintMenu();
void GenerateSource();
void GenerateKeybindings();
void GenerateDirectoryFilter();
void GenerateTheme();
void GenerateTerminalCommands();
private:
boost::property_tree::ptree cfg;
boost::property_tree::ptree key_tree;
Menu &menu;
};
#endif

13
src/juci.cc

@ -1,5 +1,6 @@
#include "juci.h"
#include "singletons.h"
#include "config.h"
void init_logging() {
add_common_attributes();
@ -44,12 +45,12 @@ void app::on_activate() {
}
app::app() : Gtk::Application("no.sout.juci", Gio::APPLICATION_HANDLES_COMMAND_LINE) {
auto css_provider = Gtk::CssProvider::create();
if (css_provider->load_from_path(Singleton::style_dir() + "juci.css")) {
auto style_context = Gtk::StyleContext::create();
style_context->add_provider(css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
style_context->add_provider_for_screen(window->get_screen(), css_provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}
MainConfig(); // Read the configs here
auto css_provider = Gtk::CssProvider::get_default();
auto style_context = Gtk::StyleContext::create();
auto screen = Gdk::Screen::get_default();
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[]) {

5
src/singletons.cc

@ -3,8 +3,11 @@
std::unique_ptr<Source::Config> Singleton::Config::source_=std::unique_ptr<Source::Config>(new Source::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<Terminal> Singleton::terminal_=std::unique_ptr<Terminal>();
std::unique_ptr<Theme::Config> Singleton::Config::theme_ = std::unique_ptr<Theme::Config>(new Theme::Config());
std::unique_ptr<Window::Config> Singleton::Config::window_ = std::unique_ptr<Window::Config>(new Window::Config());
Terminal *Singleton::terminal() {
if(!terminal_)
terminal_=std::unique_ptr<Terminal>(new Terminal());

7
src/singletons.h

@ -2,9 +2,11 @@
#define JUCI_SINGLETONS_H_
#include "source.h"
#include "window.h"
#include "directories.h"
#include "terminal.h"
#include "notebook.h"
#include "theme.h"
#include "menu.h"
#include <gtkmm.h>
#include <string>
@ -16,12 +18,17 @@ public:
static Source::Config *source() {return source_.get();}
static Terminal::Config *terminal() {return terminal_.get();}
static Directories::Config *directories() {return directories_.get();}
static Theme::Config *theme() { return theme_.get(); }
static Window::Config *window() { return window_.get(); }
private:
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<Terminal::Config> terminal_;
static std::unique_ptr<Directories::Config> directories_;
};
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();

14
src/theme.h

@ -0,0 +1,14 @@
#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_

1
src/tooltips.cc

@ -54,7 +54,6 @@ void Tooltip::adjust(bool disregard_drawn) {
tooltip_widget=std::unique_ptr<Gtk::TextView>(new Gtk::TextView(create_tooltip_buffer()));
wrap_lines(tooltip_widget->get_buffer());
tooltip_widget->set_editable(false);
tooltip_widget->override_background_color(Gdk::RGBA(Singleton::Config::source()->background_tooltips));
window->add(*tooltip_widget);
auto layout=Pango::Layout::create(tooltip_widget->get_pango_context());

15
src/window.cc

@ -12,15 +12,24 @@ namespace sigc {
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE
}
void Window::generate_keybindings() {
boost::filesystem::path path(Singleton::config_dir() + "menu.xml");
menu.ui = juci::filesystem::read(path);
for (auto &i : Singleton::Config::window()->keybindings) {
auto key = i.second.get_value<std::string>();
menu.key_map[i.first] = key;
}
}
Window::Window() : box(Gtk::ORIENTATION_VERTICAL) {
INFO("Create Window");
set_title("juCi++");
set_default_size(600, 400);
set_events(Gdk::POINTER_MOTION_MASK|Gdk::FOCUS_CHANGE_MASK|Gdk::SCROLL_MASK);
add(box);
MainConfig(this->menu); //Read the configs here
PluginApi(&this->notebook, &this->menu); //Initialise plugins
generate_keybindings();
PluginApi(&this->notebook, &this->menu);
create_menu();
box.pack_start(menu.get_widget(), Gtk::PACK_SHRINK);

8
src/window.h

@ -6,12 +6,17 @@
#include "entrybox.h"
#include "notebook.h"
#include "menu.h"
#include <boost/property_tree/json_parser.hpp>
class Window : public Gtk::Window {
public:
Window();
Notebook notebook;
Directories directories;
class Config {
public:
boost::property_tree::ptree keybindings;
};
protected:
bool on_key_press_event(GdkEventKey *event);
bool on_delete_event (GdkEventAny *event);
@ -32,16 +37,15 @@ private:
void open_folder_dialog();
void open_file_dialog();
void save_file_dialog();
void search_and_replace_entry();
void goto_line_entry();
void rename_token_entry();
void generate_keybindings();
std::string last_search;
std::string last_replace;
bool case_sensitive_search=true;
bool regex_search=false;
bool search_entry_shown=false;
};
#endif // JUCI_WINDOW_H

Loading…
Cancel
Save