Browse Source

Removed uses of deprecated override_font

merge-requests/399/head
eidheim 6 years ago
parent
commit
53eac52d9e
  1. 2
      src/config.cc
  2. 2
      src/config.h
  3. 4
      src/notebook.cc
  4. 2
      src/source.cc
  5. 2
      src/source_base.cc
  6. 17
      src/terminal.cc
  7. 71
      src/window.cc
  8. 4
      src/window.h

2
src/config.cc

@ -158,7 +158,7 @@ void Config::read(const boost::property_tree::ptree &cfg) {
if(source.smart_inserts) if(source.smart_inserts)
source.smart_brackets = true; source.smart_brackets = true;
source.show_map = source_json.get<bool>("show_map"); source.show_map = source_json.get<bool>("show_map");
source.map_font_size = source_json.get<std::string>("map_font_size"); source.map_font_size = source_json.get<unsigned>("map_font_size");
source.show_git_diff = source_json.get<bool>("show_git_diff"); source.show_git_diff = source_json.get<bool>("show_git_diff");
source.show_background_pattern = source_json.get<bool>("show_background_pattern"); source.show_background_pattern = source_json.get<bool>("show_background_pattern");
source.show_right_margin = source_json.get<bool>("show_right_margin"); source.show_right_margin = source_json.get<bool>("show_right_margin");

2
src/config.h

@ -74,7 +74,7 @@ public:
bool smart_inserts; bool smart_inserts;
bool show_map; bool show_map;
std::string map_font_size; unsigned map_font_size;
bool show_git_diff; bool show_git_diff;
bool show_background_pattern; bool show_background_pattern;
bool show_right_margin; bool show_right_margin;

4
src/notebook.cc

@ -289,6 +289,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, Position position
source_maps.emplace_back(Glib::wrap(gtk_source_map_new())); source_maps.emplace_back(Glib::wrap(gtk_source_map_new()));
gtk_source_map_set_view(GTK_SOURCE_MAP(source_maps.back()->gobj()), view->gobj()); gtk_source_map_set_view(GTK_SOURCE_MAP(source_maps.back()->gobj()), view->gobj());
source_maps.back()->get_style_context()->add_class("juci_source_map");
configure(source_views.size() - 1); configure(source_views.size() - 1);
@ -462,9 +463,6 @@ void Notebook::open_uri(const std::string &uri) {
void Notebook::configure(size_t index) { void Notebook::configure(size_t index) {
auto source_font_description = Pango::FontDescription(Config::get().source.font);
auto source_map_font_desc = Pango::FontDescription(source_font_description.get_family() + " " + Config::get().source.map_font_size);
source_maps.at(index)->override_font(source_map_font_desc);
if(Config::get().source.show_map) { if(Config::get().source.show_map) {
if(hboxes.at(index)->get_children().size() == 1) if(hboxes.at(index)->get_children().size() == 1)
hboxes.at(index)->pack_end(*source_maps.at(index), Gtk::PACK_SHRINK); hboxes.at(index)->pack_end(*source_maps.at(index), Gtk::PACK_SHRINK);

2
src/source.cc

@ -380,8 +380,6 @@ void Source::View::configure() {
set_wrap_mode(Gtk::WrapMode::WRAP_NONE); set_wrap_mode(Gtk::WrapMode::WRAP_NONE);
property_highlight_current_line() = Config::get().source.highlight_current_line; property_highlight_current_line() = Config::get().source.highlight_current_line;
line_renderer->set_visible(Config::get().source.show_line_numbers); line_renderer->set_visible(Config::get().source.show_line_numbers);
if(Config::get().source.font.size() > 0)
override_font(Pango::FontDescription(Config::get().source.font));
#if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 20) #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION >= 20)
Gdk::Rectangle rectangle; Gdk::Rectangle rectangle;

2
src/source_base.cc

@ -10,6 +10,8 @@
#include <regex> #include <regex>
Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language) : Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) { Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language) : Gsv::View(), file_path(file_path), language(language), status_diagnostics(0, 0, 0) {
get_style_context()->add_class("juci_source_view");
load(true); load(true);
get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0)); get_buffer()->place_cursor(get_buffer()->get_iter_at_offset(0));

17
src/terminal.cc

@ -9,6 +9,8 @@
#include <thread> #include <thread>
Terminal::Terminal() { Terminal::Terminal() {
get_style_context()->add_class("juci_terminal");
set_editable(false); set_editable(false);
bold_tag = get_buffer()->create_tag(); bold_tag = get_buffer()->create_tag();
@ -319,21 +321,6 @@ void Terminal::async_print(size_t line_nr, const std::string &message) {
void Terminal::configure() { void Terminal::configure() {
link_tag->property_foreground_rgba() = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_LINK); link_tag->property_foreground_rgba() = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_LINK);
if(Config::get().terminal.font.size() > 0) {
override_font(Pango::FontDescription(Config::get().terminal.font));
}
else if(Config::get().source.font.size() > 0) {
Pango::FontDescription font_description(Config::get().source.font);
auto font_description_size = font_description.get_size();
if(font_description_size == 0) {
Pango::FontDescription default_font_description(Gtk::Settings::get_default()->property_gtk_font_name());
font_description_size = default_font_description.get_size();
}
if(font_description_size > 0)
font_description.set_size(font_description_size * 0.95);
override_font(font_description);
}
} }
void Terminal::clear() { void Terminal::clear() {

71
src/window.cc

@ -147,6 +147,8 @@ Window::Window() {
void Window::configure() { void Window::configure() {
Config::get().load(); Config::get().load();
auto screen = get_screen(); auto screen = get_screen();
static Glib::RefPtr<Gtk::CssProvider> css_provider_theme;
if(css_provider_theme) if(css_provider_theme)
Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_theme); Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_theme);
if(Config::get().theme.name.empty()) { if(Config::get().theme.name.empty()) {
@ -158,36 +160,73 @@ void Window::configure() {
//TODO: add check if theme exists, or else write error to terminal //TODO: add check if theme exists, or else write error to terminal
Gtk::StyleContext::add_provider_for_screen(screen, css_provider_theme, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS); Gtk::StyleContext::add_provider_for_screen(screen, css_provider_theme, GTK_STYLE_PROVIDER_PRIORITY_SETTINGS);
if(css_provider_theme_font) static Glib::RefPtr<Gtk::CssProvider> css_provider_fonts;
Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_theme_font); if(css_provider_fonts)
if(!Config::get().theme.font.empty()) { Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_fonts);
Pango::FontDescription font_description(Config::get().theme.font); else
try { css_provider_fonts = Gtk::CssProvider::create();
css_provider_theme_font = Gtk::CssProvider::create();
auto font_description_to_style = [](const Pango::FontDescription &font_description) {
auto family = font_description.get_family();
auto size = std::to_string(font_description.get_size() / 1024);
if(size == "0")
size.clear();
if(!family.empty())
family = "font-family: " + family + ';';
if(!size.empty())
size = "font-size: " + size + "px;";
return family + size;
};
auto font_description_string_to_style = [&font_description_to_style](const std::string font_description_string) {
return font_description_to_style(Pango::FontDescription(font_description_string));
};
std::string fonts_style;
if(!Config::get().theme.font.empty())
fonts_style += "* {" + font_description_string_to_style(Config::get().theme.font) + "}";
if(!Config::get().source.font.empty()) {
auto font_description = Pango::FontDescription(Config::get().source.font);
fonts_style += ".juci_source_view {" + font_description_to_style(font_description) + "}";
font_description.set_size(Config::get().source.map_font_size * 1024);
fonts_style += ".juci_source_map {" + font_description_to_style(font_description) + "}";
}
else
fonts_style += ".juci_source_map {" + font_description_string_to_style(std::to_string(Config::get().source.map_font_size)) + "}";
if(!Config::get().terminal.font.empty())
fonts_style += ".juci_terminal {" + font_description_string_to_style(Config::get().terminal.font) + "}";
else {
Pango::FontDescription font_description(Config::get().source.font);
auto font_description_size = font_description.get_size();
if(font_description_size > 0) {
font_description.set_size(font_description_size * 0.95);
fonts_style += ".juci_terminal {" + font_description_to_style(font_description) + "}";
}
else {
auto family = font_description.get_family(); auto family = font_description.get_family();
auto size = std::to_string(font_description.get_size() / 1024);
if(size == "0")
size.clear();
if(!family.empty()) if(!family.empty())
family = "font-family: " + family + ';'; family = "font-family: " + family + ';';
if(!size.empty()) fonts_style += ".juci_terminal {" + family + "font-size: 95%;}";
size = "font-size: " + size + "px;"; }
css_provider_theme_font->load_from_data("* {" + family + size + "}"); }
get_style_context()->add_provider_for_screen(screen, css_provider_theme_font, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
if(!fonts_style.empty()) {
try {
css_provider_fonts->load_from_data(fonts_style);
get_style_context()->add_provider_for_screen(screen, css_provider_fonts, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
} }
catch(const Gtk::CssProviderError &e) { catch(const Gtk::CssProviderError &e) {
Terminal::get().print("Error: could not override theme font: " + e.what() + '\n', true); Terminal::get().print("Error: could not override fonts: " + e.what() + '\n', true);
} }
} }
auto style_scheme_manager = Source::StyleSchemeManager::get_default(); static Glib::RefPtr<Gtk::CssProvider> css_provider_tooltips;
if(css_provider_tooltips) if(css_provider_tooltips)
Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_tooltips); Gtk::StyleContext::remove_provider_for_screen(screen, css_provider_tooltips);
else else
css_provider_tooltips = Gtk::CssProvider::create(); css_provider_tooltips = Gtk::CssProvider::create();
Glib::RefPtr<Gsv::Style> style; Glib::RefPtr<Gsv::Style> style;
if(Config::get().source.style.size() > 0) { if(Config::get().source.style.size() > 0) {
auto scheme = style_scheme_manager->get_scheme(Config::get().source.style); auto scheme = Source::StyleSchemeManager::get_default()->get_scheme(Config::get().source.style);
if(scheme) if(scheme)
style = scheme->get_style("def:note"); style = scheme->get_style("def:note");
else { else {

4
src/window.h

@ -22,10 +22,6 @@ protected:
private: private:
Gtk::AboutDialog about; Gtk::AboutDialog about;
Glib::RefPtr<Gtk::CssProvider> css_provider_theme;
Glib::RefPtr<Gtk::CssProvider> css_provider_theme_font;
Glib::RefPtr<Gtk::CssProvider> css_provider_tooltips;
void configure(); void configure();
void set_menu_actions(); void set_menu_actions();
void search_and_replace_entry(); void search_and_replace_entry();

Loading…
Cancel
Save