Browse Source

Cleanup of SelectionDialog::on_change and on_select

pipelines/235045657
eidheim 6 years ago
parent
commit
a26ae56aae
  1. 17
      src/autocomplete.cpp
  2. 5
      src/autocomplete.hpp
  3. 12
      src/project.cpp
  4. 12
      src/selection_dialog.cpp
  5. 2
      src/selection_dialog.hpp
  6. 4
      src/source_clang.cpp
  7. 2
      src/source_language_protocol.cpp
  8. 2
      src/tooltips.cpp
  9. 2
      src/tooltips.hpp
  10. 10
      src/window.cpp

17
src/autocomplete.cpp

@ -148,15 +148,16 @@ void Autocomplete::setup_dialog() {
reparse(); reparse();
}; };
CompletionDialog::get()->on_changed = [this](unsigned int index, const std::string &text) { CompletionDialog::get()->on_change = [this](boost::optional<unsigned int> index, const std::string &text) {
if(index >= rows.size()) { if(on_change)
on_change(index, text);
if(!index) {
tooltips.hide(); tooltips.hide();
return; return;
} }
on_changed(index, text); auto set_buffer = set_tooltip_buffer(*index);
auto set_buffer = set_tooltip_buffer(index);
if(!set_buffer) if(!set_buffer)
tooltips.hide(); tooltips.hide();
else { else {
@ -170,9 +171,7 @@ void Autocomplete::setup_dialog() {
}; };
CompletionDialog::get()->on_select = [this](unsigned int index, const std::string &text, bool hide_window) { CompletionDialog::get()->on_select = [this](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size()) if(on_select)
return; on_select(index, text, hide_window);
on_select(index, text, hide_window);
}; };
} }

5
src/autocomplete.hpp

@ -3,6 +3,7 @@
#include "mutex.hpp" #include "mutex.hpp"
#include "tooltips.hpp" #include "tooltips.hpp"
#include <atomic> #include <atomic>
#include <boost/optional.hpp>
#include <thread> #include <thread>
class Autocomplete { class Autocomplete {
@ -46,8 +47,8 @@ public:
std::function<void()> on_show = [] {}; std::function<void()> on_show = [] {};
std::function<void()> on_hide = [] {}; std::function<void()> on_hide = [] {};
std::function<void(unsigned int, const std::string &)> on_changed = [](unsigned int index, const std::string &text) {}; std::function<void(boost::optional<unsigned int>, const std::string &)> on_change;
std::function<void(unsigned int, const std::string &, bool)> on_select = [](unsigned int index, const std::string &text, bool hide_window) {}; std::function<void(unsigned int, const std::string &, bool)> on_select;
std::function<std::function<void(Tooltip &tooltip)>(unsigned int)> set_tooltip_buffer = [](unsigned int index) { return nullptr; }; std::function<std::function<void(Tooltip &tooltip)>(unsigned int)> set_tooltip_buffer = [](unsigned int index) { return nullptr; };

12
src/project.cpp

@ -245,8 +245,6 @@ void Project::Base::show_symbols() {
if(rows.size() == 0) if(rows.size() == 0)
return; return;
SelectionDialog::get()->on_select = [rows = std::move(rows), project_path = std::move(ctags.project_path)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [rows = std::move(rows), project_path = std::move(ctags.project_path)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size())
return;
auto offset = rows[index]; auto offset = rows[index];
auto full_path = project_path / offset.file_path; auto full_path = project_path / offset.file_path;
boost::system::error_code ec; boost::system::error_code ec;
@ -556,8 +554,6 @@ void Project::LLDB::debug_backtrace() {
} }
SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size())
return;
auto frame = rows[index]; auto frame = rows[index];
if(!frame.file_path.empty()) { if(!frame.file_path.empty()) {
if(Notebook::get().open(frame.file_path)) { if(Notebook::get().open(frame.file_path)) {
@ -597,8 +593,6 @@ void Project::LLDB::debug_show_variables() {
} }
SelectionDialog::get()->on_select = [rows](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [rows](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows->size())
return;
auto variable = (*rows)[index]; auto variable = (*rows)[index];
Debug::LLDB::get().select_frame(variable.frame_index, variable.thread_index_id); Debug::LLDB::get().select_frame(variable.frame_index, variable.thread_index_id);
if(!variable.file_path.empty()) { if(!variable.file_path.empty()) {
@ -617,15 +611,15 @@ void Project::LLDB::debug_show_variables() {
self->debug_variable_tooltips.clear(); self->debug_variable_tooltips.clear();
}; };
SelectionDialog::get()->on_changed = [self = this->shared_from_this(), rows, view](unsigned int index, const std::string &text) { SelectionDialog::get()->on_change = [self = this->shared_from_this(), rows, view](boost::optional<unsigned int> index, const std::string &text) {
if(index >= rows->size()) { if(!index) {
self->debug_variable_tooltips.hide(); self->debug_variable_tooltips.hide();
return; return;
} }
self->debug_variable_tooltips.clear(); self->debug_variable_tooltips.clear();
auto set_tooltip_buffer = [rows, index](Tooltip &tooltip) { auto set_tooltip_buffer = [rows, index](Tooltip &tooltip) {
auto variable = (*rows)[index]; auto variable = (*rows)[*index];
Glib::ustring value = variable.value; Glib::ustring value = variable.value;
if(!value.empty()) { if(!value.empty()) {

12
src/selection_dialog.cpp

@ -155,11 +155,11 @@ void SelectionDialogBase::cursor_changed() {
index = it->get_value(list_view_text.column_record.index); index = it->get_value(list_view_text.column_record.index);
if(last_index == index) if(last_index == index)
return; return;
if(on_changed) { if(on_change) {
std::string text; std::string text;
if(it) if(it)
text = it->get_value(list_view_text.column_record.text); text = it->get_value(list_view_text.column_record.text);
on_changed(index.value_or(-1), text); on_change(index, text);
} }
last_index = index; last_index = index;
} }
@ -288,8 +288,12 @@ bool SelectionDialog::on_key_press(GdkEventKey *key) {
} }
else if(key->keyval == GDK_KEY_Return || key->keyval == GDK_KEY_KP_Enter || key->keyval == GDK_KEY_ISO_Left_Tab || key->keyval == GDK_KEY_Tab) { else if(key->keyval == GDK_KEY_Return || key->keyval == GDK_KEY_KP_Enter || key->keyval == GDK_KEY_ISO_Left_Tab || key->keyval == GDK_KEY_Tab) {
auto it = list_view_text.get_selection()->get_selected(); auto it = list_view_text.get_selection()->get_selected();
auto column = list_view_text.get_column(0); if(it) {
list_view_text.row_activated(list_view_text.get_model()->get_path(it), *column); auto column = list_view_text.get_column(0);
list_view_text.row_activated(list_view_text.get_model()->get_path(it), *column);
}
else
hide();
return true; return true;
} }
else if(key->keyval == GDK_KEY_Escape) { else if(key->keyval == GDK_KEY_Escape) {

2
src/selection_dialog.hpp

@ -50,8 +50,8 @@ public:
std::function<void()> on_show; std::function<void()> on_show;
std::function<void()> on_hide; std::function<void()> on_hide;
std::function<void(boost::optional<unsigned int> index, const std::string &text)> on_change;
std::function<void(unsigned int index, const std::string &text, bool hide_window)> on_select; std::function<void(unsigned int index, const std::string &text, bool hide_window)> on_select;
std::function<void(unsigned int index, const std::string &text)> on_changed;
std::function<void(const std::string &text)> on_search_entry_changed; std::function<void(const std::string &text)> on_search_entry_changed;
Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark; Glib::RefPtr<Gtk::TextBuffer::Mark> start_mark;

4
src/source_clang.cpp

@ -923,8 +923,8 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa
code_complete_results = nullptr; code_complete_results = nullptr;
}; };
autocomplete.on_changed = [this](unsigned int index, const std::string &text) { autocomplete.on_change = [this](boost::optional<unsigned int> index, const std::string &text) {
selected_completion_string = completion_strings[index]; selected_completion_string = index ? completion_strings[*index] : nullptr;
}; };
autocomplete.on_select = [this](unsigned int index, const std::string &text, bool hide_window) { autocomplete.on_select = [this](unsigned int index, const std::string &text, bool hide_window) {

2
src/source_language_protocol.cpp

@ -211,8 +211,8 @@ void LanguageProtocol::Client::parse_server_message() {
if(header_read) { if(header_read) {
server_message_stream.seekg(0, std::ios::end); server_message_stream.seekg(0, std::ios::end);
size_t read_size = server_message_stream.tellg(); size_t read_size = server_message_stream.tellg();
std::stringstream tmp;
if(read_size >= *server_message_size) { if(read_size >= *server_message_size) {
std::stringstream tmp;
if(read_size > *server_message_size) { if(read_size > *server_message_size) {
server_message_stream.seekg(*server_message_size, std::ios::beg); server_message_stream.seekg(*server_message_size, std::ios::beg);
server_message_stream.seekp(*server_message_size, std::ios::beg); server_message_stream.seekp(*server_message_size, std::ios::beg);

2
src/tooltips.cpp

@ -803,7 +803,7 @@ void Tooltips::show(bool disregard_drawn) {
} }
} }
void Tooltips::hide(boost::optional<std::pair<int, int>> last_mouse_pos, boost::optional<std::pair<int, int>> mouse_pos) { void Tooltips::hide(const boost::optional<std::pair<int, int>> &last_mouse_pos, const boost::optional<std::pair<int, int>> &mouse_pos) {
for(auto &tooltip : tooltip_list) for(auto &tooltip : tooltip_list)
tooltip.hide(last_mouse_pos, mouse_pos); tooltip.hide(last_mouse_pos, mouse_pos);
} }

2
src/tooltips.hpp

@ -62,7 +62,7 @@ public:
void show(const Gdk::Rectangle &rectangle, bool disregard_drawn = false); void show(const Gdk::Rectangle &rectangle, bool disregard_drawn = false);
void show(bool disregard_drawn = false); void show(bool disregard_drawn = false);
void hide(boost::optional<std::pair<int, int>> last_mouse_pos = {}, boost::optional<std::pair<int, int>> mouse_pos = {}); void hide(const boost::optional<std::pair<int, int>> &last_mouse_pos = {}, const boost::optional<std::pair<int, int>> &mouse_pos = {});
void clear() { tooltip_list.clear(); }; void clear() { tooltip_list.clear(); };
template <typename... Ts> template <typename... Ts>

10
src/window.cpp

@ -963,8 +963,6 @@ void Window::set_menu_actions() {
} }
SelectionDialog::get()->on_select = [paths = std::move(paths)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [paths = std::move(paths)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= paths.size())
return;
if(Notebook::get().open(paths[index])) { if(Notebook::get().open(paths[index])) {
auto view = Notebook::get().get_current_view(); auto view = Notebook::get().get_current_view();
view->hide_tooltips(); view->hide_tooltips();
@ -1117,8 +1115,6 @@ void Window::set_menu_actions() {
return; return;
} }
SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size())
return;
auto location = rows[index]; auto location = rows[index];
boost::system::error_code ec; boost::system::error_code ec;
if(!boost::filesystem::is_regular_file(location.file_path, ec)) if(!boost::filesystem::is_regular_file(location.file_path, ec))
@ -1177,8 +1173,6 @@ void Window::set_menu_actions() {
if(rows.size() == 0) if(rows.size() == 0)
return; return;
SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size())
return;
auto offset = rows[index]; auto offset = rows[index];
boost::system::error_code ec; boost::system::error_code ec;
if(!boost::filesystem::is_regular_file(offset.file_path, ec)) if(!boost::filesystem::is_regular_file(offset.file_path, ec))
@ -1210,8 +1204,6 @@ void Window::set_menu_actions() {
SelectionDialog::get()->set_cursor_at_last_row(); SelectionDialog::get()->set_cursor_at_last_row();
} }
SelectionDialog::get()->on_select = [view, rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [view, rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size())
return;
auto offset = rows[index]; auto offset = rows[index];
view->get_buffer()->place_cursor(view->get_iter_at_line_pos(offset.line, offset.index)); view->get_buffer()->place_cursor(view->get_iter_at_line_pos(offset.line, offset.index));
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
@ -1572,8 +1564,6 @@ void Window::set_menu_actions() {
} }
SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) { SelectionDialog::get()->on_select = [rows = std::move(rows)](unsigned int index, const std::string &text, bool hide_window) {
if(index >= rows.size())
return;
if(Notebook::get().open(rows[index].file_path)) { if(Notebook::get().open(rows[index].file_path)) {
auto view = Notebook::get().get_current_view(); auto view = Notebook::get().get_current_view();
view->place_cursor_at_line_pos(rows[index].line, rows[index].index); view->place_cursor_at_line_pos(rows[index].line, rows[index].index);

Loading…
Cancel
Save