diff --git a/src/dialogs.cc b/src/dialogs.cc index 9eb7ba4..be57184 100644 --- a/src/dialogs.cc +++ b/src/dialogs.cc @@ -23,7 +23,7 @@ Dialog::Message::Message(const std::string &text) : Gtk::Window(Gtk::WindowType: show_now(); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); } bool Dialog::Message::on_delete_event(GdkEventAny *event) { diff --git a/src/juci.cc b/src/juci.cc index 15f9ba7..4b50c38 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -105,7 +105,7 @@ void Application::on_activate() { } while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); for(auto view : Notebook::get().get_views()) view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); } diff --git a/src/notebook.cc b/src/notebook.cc index c9eb343..b23c3c2 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -168,7 +168,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i if(!show_tooltips) view->hide_tooltips(); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); if(get_current_view() == view) { if(center) view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5); diff --git a/src/selection_dialog.cc b/src/selection_dialog.cc index a94cd06..5ef5709 100644 --- a/src/selection_dialog.cc +++ b/src/selection_dialog.cc @@ -166,7 +166,7 @@ void SelectionDialogBase::show() { } else if(list_view_text.get_model()->children().begin() != list_view_text.get_selection()->get_selected()) { while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); if(is_visible()) list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5); } diff --git a/src/source_clang.cc b/src/source_clang.cc index 87ee1fc..6202c37 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -1793,7 +1793,7 @@ void Source::ClangViewRefactor::wait_parsing() { if(message) { for(;;) { while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); bool all_parsed = true; for(auto &clang_view : clang_views) { if(!clang_view->parsed) { @@ -1927,7 +1927,7 @@ void Source::ClangView::async_delete() { } auto before_parse_time = std::time(nullptr); - delete_thread = std::thread([this, before_parse_time, project_paths_in_use = std::move(project_paths_in_use)] { + delete_thread = std::thread([this, before_parse_time, project_paths_in_use = std::move(project_paths_in_use), buffer_modified = get_buffer()->get_modified()] { while(!parsed) std::this_thread::sleep_for(std::chrono::milliseconds(10)); @@ -1935,7 +1935,7 @@ void Source::ClangView::async_delete() { parse_state = ParseState::STOP; dispatcher.disconnect(); - if(get_buffer()->get_modified()) { + if(buffer_modified) { std::ifstream stream(file_path.string(), std::ios::binary); if(stream) { std::string buffer; @@ -1953,6 +1953,8 @@ void Source::ClangView::async_delete() { auto build = Project::Build::create(file_path); Usages::Clang::cache(build->project_path, build->get_default_path(), file_path, before_parse_time, project_paths_in_use, clang_tu.get(), clang_tokens.get()); } + else + Usages::Clang::cancel_cache_in_progress(); if(full_reparse_thread.joinable()) full_reparse_thread.join(); diff --git a/src/usages_clang.cc b/src/usages_clang.cc index 592d096..6cd86a0 100644 --- a/src/usages_clang.cc +++ b/src/usages_clang.cc @@ -165,7 +165,7 @@ std::vector Usages::Clang::get_usages(const boost::filesy message = std::make_unique(message_string); while(cache_in_progress_count != 0) { while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); } } @@ -359,8 +359,14 @@ void Usages::Clang::erase_all_caches_for_project(const boost::filesystem::path & if(project_path.empty()) return; - if(cache_in_progress_count != 0) - std::this_thread::sleep_for(std::chrono::milliseconds(10)); + if(cache_in_progress_count != 0) { + Dialog::Message message("Please wait while clearing project parse cache"); + while(cache_in_progress_count != 0) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(); + } + message.hide(); + } LockGuard lock(caches_mutex); boost::system::error_code ec; @@ -384,6 +390,10 @@ void Usages::Clang::cache_in_progress() { ++cache_in_progress_count; } +void Usages::Clang::cancel_cache_in_progress() { + --cache_in_progress_count; +} + void Usages::Clang::add_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path_, std::vector &usages, PathSet &visited, const std::string &spelling, clangmm::Cursor cursor, clangmm::TranslationUnit *translation_unit, bool store_in_cache) { diff --git a/src/usages_clang.h b/src/usages_clang.h index 7fe60db..0ecd960 100644 --- a/src/usages_clang.h +++ b/src/usages_clang.h @@ -117,6 +117,7 @@ namespace Usages { static void erase_cache(const boost::filesystem::path &path); static void erase_all_caches_for_project(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path); static void cache_in_progress(); + static void cancel_cache_in_progress(); private: static void add_usages(const boost::filesystem::path &project_path, const boost::filesystem::path &build_path, const boost::filesystem::path &path_, diff --git a/src/window.cc b/src/window.cc index a0b92f3..3bb0d07 100644 --- a/src/window.cc +++ b/src/window.cc @@ -105,13 +105,19 @@ Window::Window() { return false; }); - signal_hide().connect([] { - while(!Source::View::non_deleted_views.empty()) { - while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + signal_delete_event().connect([](GdkEventAny *) { + if(!Source::View::non_deleted_views.empty()) { + Dialog::Message message("Please wait while completing background processes"); + while(!Source::View::non_deleted_views.empty()) { + while(Gtk::Main::events_pending()) + Gtk::Main::iteration(); + } + message.hide(); } // TODO 2022 (after Debian Stretch LTS has ended, see issue #354): remove: Project::current = nullptr; + + return false; }); Gtk::Settings::get_default()->connect_property_changed("gtk-theme-name", [] { diff --git a/tests/source_clang_test.cc b/tests/source_clang_test.cc index 6fbaf38..170c4fd 100644 --- a/tests/source_clang_test.cc +++ b/tests/source_clang_test.cc @@ -16,7 +16,7 @@ std::string main_error = R"(int main() { void flush_events() { while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); } int main() { diff --git a/tests/source_key_test.cc b/tests/source_key_test.cc index a56bf4b..e0e339e 100644 --- a/tests/source_key_test.cc +++ b/tests/source_key_test.cc @@ -27,7 +27,7 @@ int main() { { buffer->set_text(" ''\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(3); assert(view.is_spellcheck_iter(iter)); @@ -36,7 +36,7 @@ int main() { { buffer->set_text(" \"\"\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(3); assert(view.is_spellcheck_iter(iter)); @@ -45,7 +45,7 @@ int main() { { buffer->set_text(" 'test\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_to_line_end(); assert(view.is_spellcheck_iter(iter)); @@ -54,7 +54,7 @@ int main() { { buffer->set_text(" \"test'\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_to_line_end(); iter.backward_char(); @@ -67,7 +67,7 @@ int main() { { buffer->set_text(" 'test'\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(2); assert(!view.is_spellcheck_iter(iter)); @@ -85,7 +85,7 @@ int main() { { buffer->set_text(" \"test\"\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(2); assert(!view.is_spellcheck_iter(iter)); @@ -103,7 +103,7 @@ int main() { { buffer->set_text(" '\\''\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(2); assert(!view.is_spellcheck_iter(iter)); @@ -124,7 +124,7 @@ int main() { { buffer->set_text(" /**/\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(2); assert(!view.is_spellcheck_iter(iter)); @@ -145,7 +145,7 @@ int main() { { buffer->set_text(" //t\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(2); assert(!view.is_spellcheck_iter(iter)); @@ -474,7 +474,7 @@ int main() { { buffer->set_text(" int main() {//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " int main() {//comment\n" " \n" @@ -511,7 +511,7 @@ int main() { iter.backward_chars(4); buffer->place_cursor(iter); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " int main() {//comment\n" " \n" @@ -578,7 +578,7 @@ int main() { iter.backward_chars(1); buffer->place_cursor(iter); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " int main()\n" " {/*comment*/\n" @@ -598,7 +598,7 @@ int main() { { buffer->set_text(" else // comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " else // comment\n" " "); @@ -614,7 +614,7 @@ int main() { { buffer->set_text(" else;//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " else;//comment\n" " "); @@ -630,7 +630,7 @@ int main() { { buffer->set_text(" else {}//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " else {}//comment\n" " "); @@ -654,7 +654,7 @@ int main() { { buffer->set_text(" } else if(true)//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " } else if(true)//comment\n" " "); @@ -673,7 +673,7 @@ int main() { buffer->set_text(" } else if(true)//comment\n" " ;//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " } else if(true)//comment\n" " ;//comment\n" @@ -694,7 +694,7 @@ int main() { buffer->set_text(" if(true) { /*comment*/\n" " ;"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " if(true) { /*comment*/\n" " ;\n" @@ -745,7 +745,7 @@ int main() { buffer->set_text(" if(true && // comment\n" " false) { // comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " if(true && // comment\n" " false) { // comment\n" @@ -771,7 +771,7 @@ int main() { " false)//comment\n" " ;//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " if(true &&\n" " false)//comment\n" @@ -828,7 +828,7 @@ int main() { buffer->set_text(" int a = 2 + // test\n" " 2;"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " int a = 2 + // test\n" " 2;\n" @@ -1085,7 +1085,7 @@ int main() { { buffer->set_text(" auto func=[] {//comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " auto func=[] {//comment\n" " \n" @@ -1193,7 +1193,7 @@ int main() { buffer->set_text(" class Class : BaseClass {\n" " public://comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " class Class : BaseClass {\n" " public://comment\n" @@ -1285,7 +1285,7 @@ int main() { { buffer->set_text(" /*"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " /*\n" " * "); @@ -1295,7 +1295,7 @@ int main() { buffer->set_text(" /*\n" " */"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " /*\n" " */\n" @@ -1305,7 +1305,7 @@ int main() { { buffer->set_text(" //comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " //comment\n" " "); @@ -1315,7 +1315,7 @@ int main() { buffer->set_text(" //comment\n" " //comment"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " //comment\n" " //comment\n" @@ -1326,7 +1326,7 @@ int main() { buffer->set_text("#test\n" " test();"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_to_line_end(); buffer->place_cursor(iter); @@ -1342,7 +1342,7 @@ int main() { buffer->set_text(" #test\n" " test();"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_to_line_end(); buffer->place_cursor(iter); @@ -1361,7 +1361,7 @@ int main() { iter.backward_char(); buffer->place_cursor(iter); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == "if('a'=='a'\n" " )"); @@ -1392,7 +1392,7 @@ int main() { buffer->set_text(" else if(true)//comment\n" " "); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " else if(true)//comment\n" " {"); @@ -1516,7 +1516,7 @@ int main() { { buffer->set_text(" {} //}"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->begin(); iter.forward_chars(3); buffer->place_cursor(iter); @@ -1624,7 +1624,7 @@ int main() { buffer->set_text(" else if(true)//comment\n" " "); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " else if(true)//comment\n" " {}"); @@ -1704,7 +1704,7 @@ int main() { buffer->set_text(" if(true) // test\n" " ;"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(11); buffer->place_cursor(iter); @@ -1719,7 +1719,7 @@ int main() { buffer->set_text(" if(true) // test\n" " ;"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(0); iter.forward_chars(11); buffer->place_cursor(iter); @@ -1847,7 +1847,7 @@ int main() { buffer->set_text(" int main() {//comment\n" " "); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == " int main() {//comment\n" " }"); @@ -2076,7 +2076,7 @@ int main() { "\n" " test"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(2); buffer->place_cursor(iter); view.on_key_press_event(&event); @@ -2110,7 +2110,7 @@ int main() { "\n" " test"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(2); buffer->place_cursor(iter); view.on_key_press_event(&event); @@ -2489,7 +2489,7 @@ int main() { buffer->set_text("\n" " * [test](https://test.org)\n"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); auto iter = buffer->get_iter_at_line(1); iter.forward_to_line_end(); buffer->place_cursor(iter); @@ -2505,7 +2505,7 @@ int main() { buffer->set_text("\n" " * [test](https://test.org)"); while(Gtk::Main::events_pending()) - Gtk::Main::iteration(false); + Gtk::Main::iteration(); view.on_key_press_event(&event); g_assert(buffer->get_text() == "\n" " * [test](https://test.org)\n" diff --git a/tests/usages_clang_test.cc b/tests/usages_clang_test.cc index d7f2301..61c7076 100644 --- a/tests/usages_clang_test.cc +++ b/tests/usages_clang_test.cc @@ -5,10 +5,17 @@ #include "usages_clang.h" #include #include +#include -#include +//Requires display server to work +//However, it is possible to use the Broadway backend if the test is run in a pure terminal environment: +//broadwayd& +//make test int main() { + auto app = Gtk::Application::create(); + Gsv::init(); + auto tests_path = boost::filesystem::canonical(JUCI_TESTS_PATH); auto project_path = boost::filesystem::canonical(tests_path / "usages_clang_test_files"); auto build_path = project_path / "build"; @@ -148,6 +155,7 @@ int main() { } Usages::Clang::erase_unused_caches({project_path}); + Usages::Clang::cache_in_progress(); Usages::Clang::cache(project_path, build_path, path, time(nullptr), {project_path}, &translation_unit, tokens.get()); assert(Usages::Clang::caches.size() == 3); assert(Usages::Clang::caches.find(project_path / "main.cpp") != Usages::Clang::caches.end()); @@ -155,6 +163,7 @@ int main() { assert(Usages::Clang::caches.find(project_path / "test2.hpp") != Usages::Clang::caches.end()); Usages::Clang::erase_unused_caches({}); + Usages::Clang::cache_in_progress(); Usages::Clang::cache(project_path, build_path, path, time(nullptr), {}, &translation_unit, tokens.get()); assert(Usages::Clang::caches.size() == 0);