Browse Source

OS X support almost done. Fixed a crash using Glib::Dispatcher, also resulted in simpler code in source.cc.

merge-requests/365/head
eidheim 11 years ago
parent
commit
e64fe65e09
  1. 9
      juci/CMakeLists.txt
  2. 4
      juci/api.cc
  3. 65
      juci/source.cc
  4. 4
      juci/source.h

9
juci/CMakeLists.txt

@ -1,12 +1,17 @@
cmake_minimum_required (VERSION 2.8.4) cmake_minimum_required (VERSION 2.8.4)
set(project_name juci) set(project_name juci)
set(module juci_to_python_api) set(module juci_to_python_api)
project (${project_name}) project (${project_name})
add_definitions(-DBOOST_LOG_DYN_LINK) add_definitions(-DBOOST_LOG_DYN_LINK)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++11 -pthread")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/cmake/Modules/")
#You are of course using Homebrew:
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -L/usr/local/opt/gettext/lib -I/usr/local/opt/gettext/include -undefined dynamic_lookup") #TODO: fix this
set(CMAKE_MACOSX_RPATH 1)
set(ENV{PKG_CONFIG_PATH} "$ENV{PKG_CONFIG_PATH}:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig")
endif()
INCLUDE(FindPkgConfig) INCLUDE(FindPkgConfig)
message("Searcing for libclang") message("Searcing for libclang")

4
juci/api.cc

@ -12,7 +12,9 @@ PluginApi::PluginApi(Menu::Controller& menu_ctl_,
menu_ = &menu_ctl_; menu_ = &menu_ctl_;
notebook_ = &notebook_ctl_; notebook_ = &notebook_ctl_;
DEBUG("Initiating plugins(from plugins.py).."); DEBUG("Initiating plugins(from plugins.py)..");
InitPlugins(); #ifndef __APPLE__
InitPlugins(); //TODO: fix this
#endif
DEBUG("Plugins initiated.."); DEBUG("Plugins initiated..");
} }

65
juci/source.cc

@ -5,6 +5,7 @@
#include <boost/timer/timer.hpp> #include <boost/timer/timer.hpp>
#include "notebook.h" #include "notebook.h"
#include "logging.h" #include "logging.h"
#include <algorithm>
Source::Location:: Source::Location::
Location(int line_number, int column_offset) : Location(int line_number, int column_offset) :
@ -353,44 +354,38 @@ void Source::Controller::OnOpenFile(const string &filepath) {
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset), view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset),
model().config()); model().config());
//OnUpdateSyntax must happen in main thread, so the parse-thread
//sends a signal to the main thread that it is to call the following function:
parsing_done.connect([this](){
INFO("Updating syntax");
view().
OnUpdateSyntax(model().ExtractTokens(0, std::min(buffer()->get_text().size(), raw_size)),
model().config());
INFO("Syntax updated");
});
buffer()->signal_end_user_action().connect([this]() { buffer()->signal_end_user_action().connect([this]() {
if (!go) { std::thread parse([this]() {
std::thread parse([this]() { if (parsing.try_lock()) {
if (parsing.try_lock()) { INFO("Starting parsing");
INFO("Starting parsing"); while (true) {
while (true) { const std::string raw = buffer()->get_text().raw();
const std::string raw = buffer()->get_text().raw(); raw_size=raw.size();
std::map<std::string, std::string> buffers; std::map<std::string, std::string> buffers;
notebook_->MapBuffers(&buffers); notebook_->MapBuffers(&buffers);
buffers[model().file_path()] = raw; buffers[model().file_path()] = raw;
if (model().ReParse(buffers) == 0 && if (model().ReParse(buffers) == 0 &&
raw == buffer()->get_text().raw()) { raw == buffer()->get_text().raw()) {
syntax.lock(); break;
go = true; }
syntax.unlock(); }
break; parsing.unlock();
} parsing_done();
} INFO("Parsing completed");
parsing.unlock();
INFO("Parsing completed");
}
});
parse.detach();
}
});
buffer()->signal_begin_user_action().connect([this]() {
if (go) {
syntax.lock();
INFO("Updating syntax");
view().
OnUpdateSyntax(model().ExtractTokens(0, buffer()->get_text().size()),
model().config());
go = false;
INFO("Syntax updated");
syntax.unlock();
} }
}); });
parse.detach();
});
} }
} }
Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() { Glib::RefPtr<Gtk::TextBuffer> Source::Controller::buffer() {

4
juci/source.h

@ -162,9 +162,9 @@ namespace Source {
private: private:
void OnLineEdit(); void OnLineEdit();
void OnSaveFile(); void OnSaveFile();
std::mutex syntax;
std::mutex parsing; std::mutex parsing;
bool go = false; Glib::Dispatcher parsing_done;
size_t raw_size=0;
bool is_saved_ = false; bool is_saved_ = false;
bool is_changed_ = false; bool is_changed_ = false;

Loading…
Cancel
Save