Browse Source

gtksource version checks cleanup, and now using new gtksource functions if gtksource version is >=3.22

merge-requests/365/head
eidheim 9 years ago
parent
commit
a950f753ab
  1. 8
      src/notebook.cc
  2. 30
      src/source.cc

8
src/notebook.cc

@ -6,7 +6,7 @@
#include "project.h" #include "project.h"
#include "filesystem.h" #include "filesystem.h"
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 3 || (GTKSOURCEVIEWMM_MAJOR_VERSION == 3 && GTKSOURCEVIEWMM_MINOR_VERSION >= 18)
#include "gtksourceview-3.0/gtksourceview/gtksourcemap.h" #include "gtksourceview-3.0/gtksourceview/gtksourcemap.h"
#endif #endif
@ -283,7 +283,7 @@ void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_in
scrolled_windows.back()->add(*source_views.back()); scrolled_windows.back()->add(*source_views.back());
hboxes.back()->pack_start(*scrolled_windows.back()); hboxes.back()->pack_start(*scrolled_windows.back());
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 3 || (GTKSOURCEVIEWMM_MAJOR_VERSION == 3 && GTKSOURCEVIEWMM_MINOR_VERSION >= 18)
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()), source_views.back()->gobj()); gtk_source_map_set_view(GTK_SOURCE_MAP(source_maps.back()->gobj()), source_views.back()->gobj());
#endif #endif
@ -429,7 +429,7 @@ void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_in
} }
void Notebook::configure(size_t index) { void Notebook::configure(size_t index) {
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 3 || (GTKSOURCEVIEWMM_MAJOR_VERSION == 3 && GTKSOURCEVIEWMM_MINOR_VERSION >= 18)
auto source_font_description=Pango::FontDescription(Config::get().source.font); auto source_font_description=Pango::FontDescription(Config::get().source.font);
auto source_map_font_desc=Pango::FontDescription(static_cast<std::string>(source_font_description.get_family())+" "+Config::get().source.map_font_size); auto source_map_font_desc=Pango::FontDescription(static_cast<std::string>(source_font_description.get_family())+" "+Config::get().source.map_font_size);
source_maps.at(index)->override_font(source_map_font_desc); source_maps.at(index)->override_font(source_map_font_desc);
@ -513,7 +513,7 @@ bool Notebook::close(size_t index) {
auto notebook_page=get_notebook_page(index); auto notebook_page=get_notebook_page(index);
notebooks[notebook_page.first].remove_page(notebook_page.second); notebooks[notebook_page.first].remove_page(notebook_page.second);
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 17 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 3 || (GTKSOURCEVIEWMM_MAJOR_VERSION == 3 && GTKSOURCEVIEWMM_MINOR_VERSION >= 18)
source_maps.erase(source_maps.begin()+index); source_maps.erase(source_maps.begin()+index);
#endif #endif

30
src/source.cc

@ -533,7 +533,7 @@ void Source::View::configure() {
property_show_line_numbers() = Config::get().source.show_line_numbers; property_show_line_numbers() = Config::get().source.show_line_numbers;
if(Config::get().source.font.size()>0) if(Config::get().source.font.size()>0)
override_font(Pango::FontDescription(Config::get().source.font)); override_font(Pango::FontDescription(Config::get().source.font));
#if GTKSOURCEVIEWMM_MAJOR_VERSION > 2 & GTKSOURCEVIEWMM_MINOR_VERSION > 15 #if GTKSOURCEVIEWMM_MAJOR_VERSION > 3 || (GTKSOURCEVIEWMM_MAJOR_VERSION == 3 && GTKSOURCEVIEWMM_MINOR_VERSION >= 16)
if(Config::get().source.show_background_pattern) if(Config::get().source.show_background_pattern)
gtk_source_view_set_background_pattern(this->gobj(), GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID); gtk_source_view_set_background_pattern(this->gobj(), GTK_SOURCE_BACKGROUND_PATTERN_TYPE_GRID);
else else
@ -697,7 +697,12 @@ void Source::View::search_forward() {
get_buffer()->get_selection_bounds(insert, selection_bound); get_buffer()->get_selection_bounds(insert, selection_bound);
auto& start=selection_bound; auto& start=selection_bound;
Gtk::TextIter match_start, match_end; Gtk::TextIter match_start, match_end;
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22))
gboolean has_wrapped_around;
if(gtk_source_search_context_forward2(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) {
#else
if(gtk_source_search_context_forward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { if(gtk_source_search_context_forward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) {
#endif
get_buffer()->select_range(match_start, match_end); get_buffer()->select_range(match_start, match_end);
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
} }
@ -708,7 +713,12 @@ void Source::View::search_backward() {
get_buffer()->get_selection_bounds(insert, selection_bound); get_buffer()->get_selection_bounds(insert, selection_bound);
auto &start=insert; auto &start=insert;
Gtk::TextIter match_start, match_end; Gtk::TextIter match_start, match_end;
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22))
gboolean has_wrapped_around;
if(gtk_source_search_context_backward2(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) {
#else
if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) {
#endif
get_buffer()->select_range(match_start, match_end); get_buffer()->select_range(match_start, match_end);
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());
} }
@ -719,9 +729,18 @@ void Source::View::replace_forward(const std::string &replacement) {
get_buffer()->get_selection_bounds(insert, selection_bound); get_buffer()->get_selection_bounds(insert, selection_bound);
auto &start=insert; auto &start=insert;
Gtk::TextIter match_start, match_end; Gtk::TextIter match_start, match_end;
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22))
gboolean has_wrapped_around;
if(gtk_source_search_context_forward2(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) {
#else
if(gtk_source_search_context_forward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { if(gtk_source_search_context_forward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) {
#endif
auto offset=match_start.get_offset(); auto offset=match_start.get_offset();
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22))
gtk_source_search_context_replace2(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr);
#else
gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr);
#endif
Glib::ustring replacement_ustring=replacement; Glib::ustring replacement_ustring=replacement;
get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement_ustring.size())); get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement_ustring.size()));
@ -734,9 +753,18 @@ void Source::View::replace_backward(const std::string &replacement) {
get_buffer()->get_selection_bounds(insert, selection_bound); get_buffer()->get_selection_bounds(insert, selection_bound);
auto &start=selection_bound; auto &start=selection_bound;
Gtk::TextIter match_start, match_end; Gtk::TextIter match_start, match_end;
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22))
gboolean has_wrapped_around;
if(gtk_source_search_context_backward2(search_context, start.gobj(), match_start.gobj(), match_end.gobj(), &has_wrapped_around)) {
#else
if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) { if(gtk_source_search_context_backward(search_context, start.gobj(), match_start.gobj(), match_end.gobj())) {
#endif
auto offset=match_start.get_offset(); auto offset=match_start.get_offset();
#if defined(GTK_SOURCE_MAJOR_VERSION) && (GTK_SOURCE_MAJOR_VERSION > 3 || (GTK_SOURCE_MAJOR_VERSION == 3 && GTK_SOURCE_MINOR_VERSION >= 22))
gtk_source_search_context_replace2(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr);
#else
gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr); gtk_source_search_context_replace(search_context, match_start.gobj(), match_end.gobj(), replacement.c_str(), replacement.size(), nullptr);
#endif
get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement.size())); get_buffer()->select_range(get_buffer()->get_iter_at_offset(offset), get_buffer()->get_iter_at_offset(offset+replacement.size()));
scroll_to(get_buffer()->get_insert()); scroll_to(get_buffer()->get_insert());

Loading…
Cancel
Save