Commit d52d84e1 authored by Ole Christian Eidheim's avatar Ole Christian Eidheim

Fixed usage cache count, simplified Gtk::Main::iteration calls, and added info...

Fixed usage cache count, simplified Gtk::Main::iteration calls, and added info message about background processes if any when quitting juCi++
parent 463cf1f9
......@@ -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) {
......
......@@ -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);
}
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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();
......
......@@ -165,7 +165,7 @@ std::vector<Usages::Clang::Usages> Usages::Clang::get_usages(const boost::filesy
message = std::make_unique<Dialog::Message>(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> &usages, PathSet &visited, const std::string &spelling, clangmm::Cursor cursor,
clangmm::TranslationUnit *translation_unit, bool store_in_cache) {
......
......@@ -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_,
......
......@@ -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", [] {
......
......@@ -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() {
......
This diff is collapsed.
......@@ -5,10 +5,17 @@
#include "usages_clang.h"
#include <cassert>
#include <fstream>
#include <gtksourceviewmm.h>
#include <iostream>
//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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment