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. 31
      juci/source.cc
  4. 4
      juci/source.h

9
juci/CMakeLists.txt

@ -1,12 +1,17 @@
cmake_minimum_required (VERSION 2.8.4)
set(project_name juci)
set(module juci_to_python_api)
project (${project_name})
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/")
#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)
message("Searcing for libclang")

4
juci/api.cc

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

31
juci/source.cc

@ -5,6 +5,7 @@
#include <boost/timer/timer.hpp>
#include "notebook.h"
#include "logging.h"
#include <algorithm>
Source::Location::
Location(int line_number, int column_offset) :
@ -353,43 +354,37 @@ void Source::Controller::OnOpenFile(const string &filepath) {
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset),
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]() {
if (!go) {
std::thread parse([this]() {
if (parsing.try_lock()) {
INFO("Starting parsing");
while (true) {
const std::string raw = buffer()->get_text().raw();
raw_size=raw.size();
std::map<std::string, std::string> buffers;
notebook_->MapBuffers(&buffers);
buffers[model().file_path()] = raw;
if (model().ReParse(buffers) == 0 &&
raw == buffer()->get_text().raw()) {
syntax.lock();
go = true;
syntax.unlock();
break;
}
}
parsing.unlock();
parsing_done();
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();
}
});
}
}

4
juci/source.h

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

Loading…
Cancel
Save