diff --git a/src/source_base.cpp b/src/source_base.cpp index 97d5abb..29759c4 100644 --- a/src/source_base.cpp +++ b/src/source_base.cpp @@ -10,7 +10,7 @@ #include #include -Source::SearchView::SearchView(const Glib::RefPtr &language) : Gsv::View(), language(language) { +Source::CommonView::CommonView(const Glib::RefPtr &language) : Gsv::View(), language(language) { search_settings = gtk_source_search_settings_new(); gtk_source_search_settings_set_wrap_around(search_settings, true); search_context = gtk_source_search_context_new(get_source_buffer()->gobj(), search_settings); @@ -18,19 +18,19 @@ Source::SearchView::SearchView(const Glib::RefPtr &language) : Gs g_signal_connect(search_context, "notify::occurrences-count", G_CALLBACK(search_occurrences_updated), this); } -Source::SearchView::~SearchView() { +Source::CommonView::~CommonView() { g_clear_object(&search_context); g_clear_object(&search_settings); } -void Source::SearchView::search_highlight(const std::string &text, bool case_sensitive, bool regex) { +void Source::CommonView::search_highlight(const std::string &text, bool case_sensitive, bool regex) { gtk_source_search_settings_set_case_sensitive(search_settings, case_sensitive); gtk_source_search_settings_set_regex_enabled(search_settings, regex); gtk_source_search_settings_set_search_text(search_settings, text.c_str()); search_occurrences_updated(nullptr, nullptr, this); } -void Source::SearchView::search_forward() { +void Source::CommonView::search_forward() { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; @@ -48,7 +48,7 @@ void Source::SearchView::search_forward() { #endif } -void Source::SearchView::search_backward() { +void Source::CommonView::search_backward() { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; @@ -66,7 +66,7 @@ void Source::SearchView::search_backward() { #endif } -void Source::SearchView::replace_forward(const std::string &replacement) { +void Source::CommonView::replace_forward(const std::string &replacement) { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; @@ -90,7 +90,7 @@ void Source::SearchView::replace_forward(const std::string &replacement) { #endif } -void Source::SearchView::replace_backward(const std::string &replacement) { +void Source::CommonView::replace_backward(const std::string &replacement) { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); Gtk::TextIter match_start, match_end; @@ -112,17 +112,17 @@ void Source::SearchView::replace_backward(const std::string &replacement) { #endif } -void Source::SearchView::replace_all(const std::string &replacement) { +void Source::CommonView::replace_all(const std::string &replacement) { gtk_source_search_context_replace_all(search_context, replacement.c_str(), replacement.size(), nullptr); } -void Source::SearchView::search_occurrences_updated(GtkWidget *widget, GParamSpec *property, gpointer data) { +void Source::CommonView::search_occurrences_updated(GtkWidget *widget, GParamSpec *property, gpointer data) { auto view = static_cast(data); if(view->update_search_occurrences) view->update_search_occurrences(gtk_source_search_context_get_occurrences_count(view->search_context)); } -bool Source::SearchView::on_key_press_event(GdkEventKey *event) { +bool Source::CommonView::on_key_press_event(GdkEventKey *event) { if(event->keyval == GDK_KEY_Home && event->state & GDK_CONTROL_MASK) { auto iter = get_buffer()->begin(); scroll_to(iter); // Home key should always scroll to start, even though cursor does not move @@ -136,7 +136,7 @@ bool Source::SearchView::on_key_press_event(GdkEventKey *event) { return Gsv::View::on_key_press_event(event); } -void Source::SearchView::cut() { +void Source::CommonView::cut() { if(!get_editable()) return copy(); @@ -168,7 +168,7 @@ void Source::SearchView::cut() { keep_clipboard = true; } -void Source::SearchView::cut_lines() { +void Source::CommonView::cut_lines() { if(!get_editable()) return copy_lines(); @@ -211,7 +211,7 @@ void Source::SearchView::cut_lines() { keep_clipboard = true; } -void Source::SearchView::copy() { +void Source::CommonView::copy() { if(!get_buffer()->get_has_selection()) copy_lines(); else if(language && language->get_id() == "diff") { @@ -233,7 +233,7 @@ void Source::SearchView::copy() { get_buffer()->copy_clipboard(Gtk::Clipboard::get()); } -void Source::SearchView::copy_lines() { +void Source::CommonView::copy_lines() { Gtk::TextIter start, end; get_buffer()->get_selection_bounds(start, end); start = get_buffer()->get_iter_at_line(start.get_line()); @@ -259,7 +259,7 @@ void Source::SearchView::copy_lines() { Gtk::Clipboard::get()->set_text(get_buffer()->get_text(start, end)); } -Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : SearchView(language), file_path(file_path), status_diagnostics(0, 0, 0) { +Source::BaseView::BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr &language) : CommonView(language), file_path(file_path), status_diagnostics(0, 0, 0) { get_style_context()->add_class("juci_source_view"); load(true); @@ -1187,7 +1187,7 @@ bool Source::BaseView::on_key_press_event(GdkEventKey *event) { return true; } - return Source::SearchView::on_key_press_event(event); + return Source::CommonView::on_key_press_event(event); } bool Source::BaseView::on_key_press_event_extra_cursors(GdkEventKey *event) { diff --git a/src/source_base.hpp b/src/source_base.hpp index 0d24a03..864b93b 100644 --- a/src/source_base.hpp +++ b/src/source_base.hpp @@ -27,10 +27,11 @@ namespace Source { } }; - class SearchView : public Gsv::View { + /// Also used for terminal + class CommonView : public Gsv::View { public: - SearchView(const Glib::RefPtr &language = {}); - ~SearchView() override; + CommonView(const Glib::RefPtr &language = {}); + ~CommonView() override; void search_highlight(const std::string &text, bool case_sensitive, bool regex); void search_forward(); void search_backward(); @@ -61,7 +62,7 @@ namespace Source { static void search_occurrences_updated(GtkWidget *widget, GParamSpec *property, gpointer data); }; - class BaseView : public SearchView { + class BaseView : public CommonView { public: BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr &language); ~BaseView() override; diff --git a/src/terminal.cpp b/src/terminal.cpp index 5a99e3e..687c753 100644 --- a/src/terminal.cpp +++ b/src/terminal.cpp @@ -10,7 +10,7 @@ #include #include -Terminal::Terminal() : Source::SearchView() { +Terminal::Terminal() : Source::CommonView() { get_style_context()->add_class("juci_terminal"); set_editable(false); @@ -628,7 +628,7 @@ bool Terminal::on_key_press_event(GdkEventKey *event) { event->keyval == GDK_KEY_Page_Up || event->keyval == GDK_KEY_Page_Down || event->keyval == GDK_KEY_Up || event->keyval == GDK_KEY_Down || event->keyval == GDK_KEY_Left || event->keyval == GDK_KEY_Right) - return Source::SearchView::on_key_press_event(event); + return Source::CommonView::on_key_press_event(event); LockGuard lock(processes_mutex); bool debug_is_running = false; diff --git a/src/terminal.hpp b/src/terminal.hpp index 726ca05..100046f 100644 --- a/src/terminal.hpp +++ b/src/terminal.hpp @@ -10,7 +10,7 @@ #include #include -class Terminal : public Source::SearchView { +class Terminal : public Source::CommonView { Terminal(); public: diff --git a/src/window.cpp b/src/window.cpp index f805405..562e0be 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -632,7 +632,7 @@ void Window::set_menu_actions() { else entry->cut_clipboard(); } - else if(auto view = dynamic_cast(widget)) + else if(auto view = dynamic_cast(widget)) view->cut(); }); menu.add_action("edit_cut_lines", [this]() { @@ -648,7 +648,7 @@ void Window::set_menu_actions() { Gtk::Clipboard::get()->set_text(entry->get_text()); entry->set_text(""); } - else if(auto view = dynamic_cast(widget)) + else if(auto view = dynamic_cast(widget)) view->cut_lines(); }); menu.add_action("edit_copy", [this]() { @@ -669,7 +669,7 @@ void Window::set_menu_actions() { else entry->copy_clipboard(); } - else if(auto view = dynamic_cast(widget)) + else if(auto view = dynamic_cast(widget)) view->copy(); }); menu.add_action("edit_copy_lines", [this]() { @@ -691,7 +691,7 @@ void Window::set_menu_actions() { auto widget = get_focus(); if(auto entry = dynamic_cast(widget)) Gtk::Clipboard::get()->set_text(entry->get_text()); - else if(auto view = dynamic_cast(widget)) + else if(auto view = dynamic_cast(widget)) view->copy_lines(); }); menu.add_action("edit_paste", [this]() { diff --git a/src/window.hpp b/src/window.hpp index dea21bd..7a58199 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -40,7 +40,7 @@ private: bool regex_search = false; bool search_entry_shown = false; /// Last source view focused - Source::SearchView *focused_view = nullptr; + Source::CommonView *focused_view = nullptr; bool find_pattern_case_sensitive = true; bool find_pattern_extended_regex = false; };