Browse Source

Now getting rid of all dispatchers on source_clang delete.

merge-requests/365/head
eidheim 10 years ago
parent
commit
f20823c477
  1. 32
      src/source_clang.cc
  2. 24
      src/source_clang.h

32
src/source_clang.cc

@ -36,7 +36,7 @@ Source::View(file_path, project_path, language), parse_error(false) {
parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path.string()); parsing_in_progress=Singleton::terminal()->print_in_progress("Parsing "+file_path.string());
//GTK-calls must happen in main thread, so the parse_thread //GTK-calls must happen in main thread, so the parse_thread
//sends signals to the main thread that it is to call the following functions: //sends signals to the main thread that it is to call the following functions:
parse_start.connect([this]{ parse_start_connection=parse_start.connect([this]{
if(parse_thread_buffer_map_mutex.try_lock()) { if(parse_thread_buffer_map_mutex.try_lock()) {
parse_thread_buffer_map=get_buffer_map(); parse_thread_buffer_map=get_buffer_map();
parse_thread_mapped=true; parse_thread_mapped=true;
@ -44,7 +44,7 @@ Source::View(file_path, project_path, language), parse_error(false) {
} }
parse_thread_go=true; parse_thread_go=true;
}); });
parse_done.connect([this](){ parse_done_connection=parse_done.connect([this](){
if(parse_thread_mapped) { if(parse_thread_mapped) {
if(parsing_mutex.try_lock()) { if(parsing_mutex.try_lock()) {
update_syntax(); update_syntax();
@ -59,7 +59,7 @@ Source::View(file_path, project_path, language), parse_error(false) {
parse_thread_go=true; parse_thread_go=true;
} }
}); });
parse_fail.connect([this](){ parse_fail_connection=parse_fail.connect([this](){
Singleton::terminal()->print("Error: failed to reparse "+this->file_path.string()+".\n"); Singleton::terminal()->print("Error: failed to reparse "+this->file_path.string()+".\n");
set_status(""); set_status("");
set_info(""); set_info("");
@ -106,10 +106,6 @@ void Source::ClangViewParse::configure() {
no_bracket_no_para_statement_regex=std::regex("^([ \\t]*)(else|try|do) *$"); no_bracket_no_para_statement_regex=std::regex("^([ \\t]*)(else|try|do) *$");
} }
Source::ClangViewParse::~ClangViewParse() {
delayed_reparse_connection.disconnect();
}
void Source::ClangViewParse::init_parse() { void Source::ClangViewParse::init_parse() {
type_tooltips.hide(); type_tooltips.hide();
diagnostic_tooltips.hide(); diagnostic_tooltips.hide();
@ -660,9 +656,10 @@ Source::ClangViewParse(file_path, project_path, language), autocomplete_cancel_s
autocomplete_cancel_starting=false; autocomplete_cancel_starting=false;
}); });
do_delete_object.connect([this](){ do_delete_object_connection=do_delete_object.connect([this](){
if(delete_thread.joinable()) if(delete_thread.joinable())
delete_thread.join(); delete_thread.join();
do_delete_object_connection.disconnect();
delete this; delete this;
}); });
do_restart_parse.connect([this](){ do_restart_parse.connect([this](){
@ -875,8 +872,6 @@ std::vector<Source::ClangViewAutocomplete::AutoCompleteData> Source::ClangViewAu
void Source::ClangViewAutocomplete::async_delete() { void Source::ClangViewAutocomplete::async_delete() {
parsing_in_progress->cancel("canceled, freeing resources in the background"); parsing_in_progress->cancel("canceled, freeing resources in the background");
autocomplete_done_connection.disconnect();
autocomplete_fail_connection.disconnect();
parse_thread_stop=true; parse_thread_stop=true;
delete_thread=std::thread([this](){ delete_thread=std::thread([this](){
//TODO: Is it possible to stop the clang-process in progress? //TODO: Is it possible to stop the clang-process in progress?
@ -1262,13 +1257,22 @@ void Source::ClangViewRefactor::tag_similar_tokens(const Token &token) {
} }
} }
Source::ClangViewRefactor::~ClangViewRefactor() {
delayed_tag_similar_tokens_connection.disconnect();
}
Source::ClangView::ClangView(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language): ClangViewRefactor(file_path, project_path, language) { Source::ClangView::ClangView(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language): ClangViewRefactor(file_path, project_path, language) {
if(language) { if(language) {
get_source_buffer()->set_highlight_syntax(true); get_source_buffer()->set_highlight_syntax(true);
get_source_buffer()->set_language(language); get_source_buffer()->set_language(language);
} }
} }
void Source::ClangView::async_delete() {
delayed_reparse_connection.disconnect();
parse_done_connection.disconnect();
parse_start_connection.disconnect();
parse_fail_connection.disconnect();
autocomplete_done_connection.disconnect();
autocomplete_fail_connection.disconnect();
do_restart_parse_connection.disconnect();
delayed_tag_similar_tokens_connection.disconnect();
ClangViewAutocomplete::async_delete();
}

24
src/source_clang.h

@ -21,8 +21,7 @@ namespace Source {
}; };
ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language); ClangViewParse(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language);
~ClangViewParse(); virtual void configure();
void configure();
void start_reparse(); void start_reparse();
bool reparse_needed=false; bool reparse_needed=false;
@ -39,8 +38,8 @@ namespace Source {
std::atomic<bool> parse_thread_stop; std::atomic<bool> parse_thread_stop;
std::atomic<bool> parse_error; std::atomic<bool> parse_error;
void show_diagnostic_tooltips(const Gdk::Rectangle &rectangle); virtual void show_diagnostic_tooltips(const Gdk::Rectangle &rectangle);
void show_type_tooltips(const Gdk::Rectangle &rectangle); virtual void show_type_tooltips(const Gdk::Rectangle &rectangle);
std::regex bracket_regex; std::regex bracket_regex;
std::regex no_bracket_statement_regex; std::regex no_bracket_statement_regex;
@ -48,6 +47,10 @@ namespace Source {
std::set<int> diagnostic_offsets; std::set<int> diagnostic_offsets;
std::vector<FixIt> fix_its; std::vector<FixIt> fix_its;
sigc::connection parse_done_connection;
sigc::connection parse_start_connection;
sigc::connection parse_fail_connection;
private: private:
std::map<std::string, std::string> get_buffer_map() const; std::map<std::string, std::string> get_buffer_map() const;
void update_syntax(); void update_syntax();
@ -77,11 +80,15 @@ namespace Source {
}; };
ClangViewAutocomplete(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language); ClangViewAutocomplete(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language);
void async_delete(); virtual void async_delete();
bool restart_parse(); bool restart_parse();
protected: protected:
bool on_key_press_event(GdkEventKey* key); bool on_key_press_event(GdkEventKey* key);
std::thread autocomplete_thread; std::thread autocomplete_thread;
sigc::connection autocomplete_done_connection;
sigc::connection autocomplete_fail_connection;
sigc::connection do_delete_object_connection;
sigc::connection do_restart_parse_connection;
private: private:
void start_autocomplete(); void start_autocomplete();
void autocomplete(); void autocomplete();
@ -89,9 +96,7 @@ namespace Source {
bool completion_dialog_shown=false; bool completion_dialog_shown=false;
std::vector<AutoCompleteData> get_autocomplete_suggestions(int line_number, int column, std::map<std::string, std::string>& buffer_map); std::vector<AutoCompleteData> get_autocomplete_suggestions(int line_number, int column, std::map<std::string, std::string>& buffer_map);
Glib::Dispatcher autocomplete_done; Glib::Dispatcher autocomplete_done;
sigc::connection autocomplete_done_connection;
Glib::Dispatcher autocomplete_fail; Glib::Dispatcher autocomplete_fail;
sigc::connection autocomplete_fail_connection;
bool autocomplete_starting=false; bool autocomplete_starting=false;
std::atomic<bool> autocomplete_cancel_starting; std::atomic<bool> autocomplete_cancel_starting;
guint last_keyval=0; guint last_keyval=0;
@ -108,13 +113,13 @@ namespace Source {
class ClangViewRefactor : public ClangViewAutocomplete { class ClangViewRefactor : public ClangViewAutocomplete {
public: public:
ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language); ClangViewRefactor(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language);
~ClangViewRefactor(); protected:
sigc::connection delayed_tag_similar_tokens_connection;
private: private:
std::list<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > similar_token_marks; std::list<std::pair<Glib::RefPtr<Gtk::TextMark>, Glib::RefPtr<Gtk::TextMark> > > similar_token_marks;
void tag_similar_tokens(const Token &token); void tag_similar_tokens(const Token &token);
Glib::RefPtr<Gtk::TextTag> similar_tokens_tag; Glib::RefPtr<Gtk::TextTag> similar_tokens_tag;
Token last_tagged_token; Token last_tagged_token;
sigc::connection delayed_tag_similar_tokens_connection;
std::unique_ptr<SelectionDialog> selection_dialog; std::unique_ptr<SelectionDialog> selection_dialog;
bool renaming=false; bool renaming=false;
}; };
@ -122,6 +127,7 @@ namespace Source {
class ClangView : public ClangViewRefactor { class ClangView : public ClangViewRefactor {
public: public:
ClangView(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language); ClangView(const boost::filesystem::path &file_path, const boost::filesystem::path& project_path, Glib::RefPtr<Gsv::Language> language);
virtual void async_delete();
}; };
} }

Loading…
Cancel
Save