mirror of https://gitlab.com/cppit/jucipp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
6.0 KiB
160 lines
6.0 KiB
|
8 years ago
|
#pragma once
|
||
|
|
|
||
|
6 years ago
|
#include "mutex.hpp"
|
||
|
|
#include "snippets.hpp"
|
||
|
8 years ago
|
#include <boost/filesystem.hpp>
|
||
|
8 years ago
|
#include <gtksourceviewmm.h>
|
||
|
7 years ago
|
#include <list>
|
||
|
|
#include <regex>
|
||
|
8 years ago
|
#include <set>
|
||
|
7 years ago
|
#include <vector>
|
||
|
8 years ago
|
|
||
|
|
namespace Source {
|
||
|
6 years ago
|
class SearchView : public Gsv::View {
|
||
|
|
public:
|
||
|
|
SearchView();
|
||
|
|
~SearchView() override;
|
||
|
|
void search_highlight(const std::string &text, bool case_sensitive, bool regex);
|
||
|
|
void search_forward();
|
||
|
|
void search_backward();
|
||
|
|
void replace_forward(const std::string &replacement);
|
||
|
|
void replace_backward(const std::string &replacement);
|
||
|
|
void replace_all(const std::string &replacement);
|
||
|
|
|
||
|
|
std::function<void(int number)> update_search_occurrences;
|
||
|
|
|
||
|
|
private:
|
||
|
|
GtkSourceSearchContext *search_context;
|
||
|
|
GtkSourceSearchSettings *search_settings;
|
||
|
|
static void search_occurrences_updated(GtkWidget *widget, GParamSpec *property, gpointer data);
|
||
|
|
};
|
||
|
|
|
||
|
|
class BaseView : public SearchView {
|
||
|
8 years ago
|
public:
|
||
|
8 years ago
|
BaseView(const boost::filesystem::path &file_path, const Glib::RefPtr<Gsv::Language> &language);
|
||
|
8 years ago
|
~BaseView() override;
|
||
|
8 years ago
|
boost::filesystem::path file_path;
|
||
|
8 years ago
|
|
||
|
8 years ago
|
Glib::RefPtr<Gsv::Language> language;
|
||
|
8 years ago
|
|
||
|
|
bool load(bool not_undoable_action = false);
|
||
|
8 years ago
|
/// Set new text more optimally and without unnecessary scrolling
|
||
|
|
void replace_text(const std::string &new_text);
|
||
|
8 years ago
|
virtual void rename(const boost::filesystem::path &path);
|
||
|
8 years ago
|
virtual bool save() = 0;
|
||
|
8 years ago
|
|
||
|
8 years ago
|
Glib::RefPtr<Gio::FileMonitor> monitor;
|
||
|
|
sigc::connection monitor_changed_connection;
|
||
|
|
sigc::connection delayed_monitor_changed_connection;
|
||
|
8 years ago
|
|
||
|
8 years ago
|
virtual void configure() = 0;
|
||
|
|
virtual void hide_tooltips() = 0;
|
||
|
|
virtual void hide_dialogs() = 0;
|
||
|
8 years ago
|
|
||
|
7 years ago
|
void set_tab_char_and_size(char tab_char, unsigned tab_size);
|
||
|
|
std::pair<char, unsigned> get_tab_char_and_size() { return {tab_char, tab_size}; }
|
||
|
8 years ago
|
|
||
|
8 years ago
|
/// Safely returns iter given line and an offset using either byte index or character offset. Defaults to using byte index.
|
||
|
|
virtual Gtk::TextIter get_iter_at_line_pos(int line, int pos);
|
||
|
|
/// Safely returns iter given line and character offset
|
||
|
|
Gtk::TextIter get_iter_at_line_offset(int line, int offset);
|
||
|
|
/// Safely returns iter given line and byte index
|
||
|
|
Gtk::TextIter get_iter_at_line_index(int line, int index);
|
||
|
8 years ago
|
|
||
|
8 years ago
|
Gtk::TextIter get_iter_at_line_end(int line_nr);
|
||
|
8 years ago
|
|
||
|
8 years ago
|
/// Safely places cursor at line using get_iter_at_line_pos.
|
||
|
|
void place_cursor_at_line_pos(int line, int pos);
|
||
|
|
/// Safely places cursor at line offset
|
||
|
|
void place_cursor_at_line_offset(int line, int offset);
|
||
|
|
/// Safely places cursor at line index
|
||
|
|
void place_cursor_at_line_index(int line, int index);
|
||
|
8 years ago
|
|
||
|
6 years ago
|
virtual void scroll_to_cursor_delayed(bool center, bool show_tooltips) {}
|
||
|
7 years ago
|
|
||
|
|
std::function<void(BaseView *view)> update_tab_label;
|
||
|
|
std::function<void(BaseView *view)> update_status_location;
|
||
|
|
std::function<void(BaseView *view)> update_status_file_path;
|
||
|
|
std::function<void(BaseView *view)> update_status_diagnostics;
|
||
|
|
std::function<void(BaseView *view)> update_status_state;
|
||
|
|
std::tuple<size_t, size_t, size_t> status_diagnostics;
|
||
|
|
std::string status_state;
|
||
|
|
std::function<void(BaseView *view)> update_status_branch;
|
||
|
|
std::string status_branch;
|
||
|
|
|
||
|
6 years ago
|
void cut();
|
||
|
|
void cut_line();
|
||
|
7 years ago
|
void paste();
|
||
|
|
|
||
|
7 years ago
|
std::string get_selected_text();
|
||
|
|
|
||
|
7 years ago
|
bool disable_spellcheck = false;
|
||
|
|
|
||
|
7 years ago
|
void set_snippets();
|
||
|
|
|
||
|
7 years ago
|
private:
|
||
|
6 years ago
|
bool keep_clipboard = false;
|
||
|
|
|
||
|
8 years ago
|
protected:
|
||
|
|
std::time_t last_write_time;
|
||
|
|
void monitor_file();
|
||
|
8 years ago
|
void check_last_write_time(std::time_t last_write_time_ = static_cast<std::time_t>(-1));
|
||
|
|
|
||
|
7 years ago
|
bool is_bracket_language = false;
|
||
|
|
|
||
|
7 years ago
|
unsigned tab_size;
|
||
|
|
char tab_char;
|
||
|
|
std::string tab;
|
||
|
|
std::pair<char, unsigned> find_tab_char_and_size();
|
||
|
|
|
||
|
7 years ago
|
/// Apple key for MacOS, and control key otherwise
|
||
|
|
GdkModifierType primary_modifier_mask;
|
||
|
|
|
||
|
8 years ago
|
/// Move iter to line start. Depending on iter position, before or after indentation.
|
||
|
8 years ago
|
/// Works with wrapped lines.
|
||
|
8 years ago
|
Gtk::TextIter get_smart_home_iter(const Gtk::TextIter &iter);
|
||
|
|
/// Move iter to line end. Depending on iter position, before or after indentation.
|
||
|
8 years ago
|
/// Works with wrapped lines.
|
||
|
8 years ago
|
/// Note that smart end goes FIRST to end of line to avoid hiding empty chars after expressions.
|
||
|
|
Gtk::TextIter get_smart_end_iter(const Gtk::TextIter &iter);
|
||
|
8 years ago
|
|
||
|
6 years ago
|
public:
|
||
|
8 years ago
|
std::string get_line(const Gtk::TextIter &iter);
|
||
|
8 years ago
|
std::string get_line(const Glib::RefPtr<Gtk::TextBuffer::Mark> &mark);
|
||
|
8 years ago
|
std::string get_line(int line_nr);
|
||
|
|
std::string get_line();
|
||
|
6 years ago
|
|
||
|
|
protected:
|
||
|
8 years ago
|
std::string get_line_before(const Gtk::TextIter &iter);
|
||
|
8 years ago
|
std::string get_line_before(const Glib::RefPtr<Gtk::TextBuffer::Mark> &mark);
|
||
|
8 years ago
|
std::string get_line_before();
|
||
|
|
Gtk::TextIter get_tabs_end_iter(const Gtk::TextIter &iter);
|
||
|
8 years ago
|
Gtk::TextIter get_tabs_end_iter(const Glib::RefPtr<Gtk::TextBuffer::Mark> &mark);
|
||
|
8 years ago
|
Gtk::TextIter get_tabs_end_iter(int line_nr);
|
||
|
|
Gtk::TextIter get_tabs_end_iter();
|
||
|
8 years ago
|
|
||
|
7 years ago
|
bool is_token_char(gunichar chr);
|
||
|
7 years ago
|
std::pair<Gtk::TextIter, Gtk::TextIter> get_token_iters(Gtk::TextIter iter);
|
||
|
|
std::string get_token(const Gtk::TextIter &iter);
|
||
|
7 years ago
|
void cleanup_whitespace_characters();
|
||
|
|
void cleanup_whitespace_characters(const Gtk::TextIter &iter);
|
||
|
8 years ago
|
|
||
|
7 years ago
|
bool enable_multiple_cursors = false;
|
||
|
7 years ago
|
|
||
|
|
std::vector<std::pair<Glib::RefPtr<Gtk::TextBuffer::Mark>, int>> extra_cursors;
|
||
|
|
std::vector<Glib::RefPtr<Gtk::TextBuffer::Mark>> extra_snippet_cursors;
|
||
|
|
void setup_extra_cursor_signals();
|
||
|
|
bool extra_cursors_signals_set = false;
|
||
|
|
|
||
|
|
/// After inserting a snippet, one can use tab to select the next argument
|
||
|
|
bool keep_snippet_marks = false;
|
||
|
7 years ago
|
Mutex snippets_mutex;
|
||
|
|
std::vector<Snippets::Snippet> *snippets GUARDED_BY(snippets_mutex) = nullptr;
|
||
|
7 years ago
|
std::list<std::vector<std::pair<Glib::RefPtr<Gtk::TextBuffer::Mark>, Glib::RefPtr<Gtk::TextBuffer::Mark>>>> snippets_marks;
|
||
|
|
Glib::RefPtr<Gtk::TextTag> snippet_argument_tag;
|
||
|
6 years ago
|
void insert_snippet(Gtk::TextIter iter, const Glib::ustring &snippet);
|
||
|
7 years ago
|
bool select_snippet_argument();
|
||
|
|
bool clear_snippet_marks();
|
||
|
8 years ago
|
};
|
||
|
8 years ago
|
} // namespace Source
|