|
|
|
@ -240,7 +240,7 @@ HighlightToken(clang::Token *token, |
|
|
|
// Constructor for Controller
|
|
|
|
// Constructor for Controller
|
|
|
|
Source::Controller::Controller(const Source::Config &config, |
|
|
|
Source::Controller::Controller(const Source::Config &config, |
|
|
|
Notebook::Controller ¬ebook) : |
|
|
|
Notebook::Controller ¬ebook) : |
|
|
|
config(config), notebook(notebook) { |
|
|
|
config(config), notebook(notebook), parse_thread_go(false), parse_thread_mapped(false) { |
|
|
|
INFO("Source Controller with childs constructed"); |
|
|
|
INFO("Source Controller with childs constructed"); |
|
|
|
view.signal_key_press_event().connect(sigc::mem_fun(*this, &Source::Controller::OnKeyPress), false); |
|
|
|
view.signal_key_press_event().connect(sigc::mem_fun(*this, &Source::Controller::OnKeyPress), false); |
|
|
|
view.set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); |
|
|
|
view.set_smart_home_end(Gsv::SMART_HOME_END_BEFORE); |
|
|
|
@ -316,35 +316,50 @@ void Source::Controller::OnOpenFile(const string &filepath) { |
|
|
|
notebook.index()); |
|
|
|
notebook.index()); |
|
|
|
view.OnUpdateSyntax(parser.ExtractTokens(start_offset, end_offset), config); |
|
|
|
view.OnUpdateSyntax(parser.ExtractTokens(start_offset, end_offset), config); |
|
|
|
|
|
|
|
|
|
|
|
//OnUpdateSyntax must happen in main thread, so the parse-thread
|
|
|
|
//GTK-calls must happen in main thread, so the parse_thread
|
|
|
|
//sends a signal to the main thread that it is to call the following function:
|
|
|
|
//sends signals to the main thread that it is to call the following functions:
|
|
|
|
parsing_done.connect([this](){ |
|
|
|
parse_start.connect([this]{ |
|
|
|
|
|
|
|
if(parse_thread_buffers_mutex.try_lock()) { |
|
|
|
|
|
|
|
notebook.MapBuffers(&this->parse_thread_buffers); |
|
|
|
|
|
|
|
parse_thread_mapped=true; |
|
|
|
|
|
|
|
parse_thread_buffers_mutex.unlock(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
parse_thread_go=true; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
parse_done.connect([this](){ |
|
|
|
|
|
|
|
if(parse_thread_mapped) { |
|
|
|
INFO("Updating syntax"); |
|
|
|
INFO("Updating syntax"); |
|
|
|
view. |
|
|
|
view. |
|
|
|
OnUpdateSyntax(parser.ExtractTokens(0, buffer()->get_text().size()), config); |
|
|
|
OnUpdateSyntax(parser.ExtractTokens(0, buffer()->get_text().size()), config); |
|
|
|
INFO("Syntax updated"); |
|
|
|
INFO("Syntax updated"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
parse_thread_go=true; |
|
|
|
|
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
buffer()->signal_end_user_action().connect([this]() { |
|
|
|
std::thread parse_thread([this]() { |
|
|
|
std::thread parse([this]() { |
|
|
|
while(true) { |
|
|
|
if (parsing.try_lock()) { |
|
|
|
while(!parse_thread_go) std::this_thread::yield(); |
|
|
|
INFO("Starting parsing"); |
|
|
|
if(!parse_thread_mapped) { |
|
|
|
while (true) { |
|
|
|
parse_thread_go=false; |
|
|
|
const std::string raw = buffer()->get_text().raw(); |
|
|
|
parse_start(); |
|
|
|
std::map<std::string, std::string> buffers; |
|
|
|
|
|
|
|
notebook.MapBuffers(&buffers); |
|
|
|
|
|
|
|
buffers[parser.file_path] = raw; |
|
|
|
|
|
|
|
if (parser.ReParse(buffers) == 0 && |
|
|
|
|
|
|
|
raw == buffer()->get_text().raw()) { |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (parse_thread_mapped && parsing.try_lock() && parse_thread_buffers_mutex.try_lock()) { |
|
|
|
|
|
|
|
parser.ReParse(this->parse_thread_buffers); |
|
|
|
|
|
|
|
parse_thread_go=false; |
|
|
|
parsing.unlock(); |
|
|
|
parsing.unlock(); |
|
|
|
parsing_done(); |
|
|
|
parse_thread_buffers_mutex.unlock(); |
|
|
|
INFO("Parsing completed"); |
|
|
|
parse_done(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
parse.detach(); |
|
|
|
parse_thread.detach(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
buffer()->signal_changed().connect([this]() { |
|
|
|
|
|
|
|
parse_thread_mapped=false; |
|
|
|
|
|
|
|
parse_thread_go=true; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|