Browse Source

More cleanup: mainly, OnUpdateSyntax->update_syntax moved to Source::Controller.

merge-requests/365/head
eidheim 11 years ago
parent
commit
6647377ab5
  1. 8
      juci/notebook.cc
  2. 26
      juci/source.cc
  3. 18
      juci/source.h

8
juci/notebook.cc

@ -236,13 +236,13 @@ bool Notebook::Controller::GeneratePopup(int key_id) {
for (auto &data : acdata) { for (auto &data : acdata) {
std::stringstream ss; std::stringstream ss;
std::string return_value; std::string return_value;
for (auto &chunk : data.chunks_) { for (auto &chunk : data.chunks) {
switch (chunk.kind()) { switch (chunk.kind) {
case clang::CompletionChunk_ResultType: case clang::CompletionChunk_ResultType:
return_value = chunk.chunk(); return_value = chunk.chunk;
break; break;
case clang::CompletionChunk_Informative: break; case clang::CompletionChunk_Informative: break;
default: ss << chunk.chunk(); break; default: ss << chunk.chunk; break;
} }
} }
if (ss.str().length() > 0) { // if length is 0 the result is empty if (ss.str().length() > 0) { // if length is 0 the result is empty

26
juci/source.cc

@ -260,20 +260,11 @@ Source::Controller::~Controller() {
parse_thread.join(); parse_thread.join();
} }
void Source::Controller::OnNewEmptyFile() { void Source::Controller::update_syntax(const std::vector<Source::Range> &ranges) {
string filename("/tmp/juci_t");
sourcefile s(filename);
parser.file_path=filename;
parser.project_path=filename;
s.save("");
}
void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges,
const Source::Config &config) {
if (ranges.empty() || ranges.size() == 0) { if (ranges.empty() || ranges.size() == 0) {
return; return;
} }
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer(); auto buffer = view.get_buffer();
buffer->remove_all_tags(buffer->begin(), buffer->end()); buffer->remove_all_tags(buffer->begin(), buffer->end());
for (auto &range : ranges) { for (auto &range : ranges) {
std::string type = std::to_string(range.kind()); std::string type = std::to_string(range.kind());
@ -298,6 +289,14 @@ void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges,
} }
} }
void Source::Controller::OnNewEmptyFile() {
string filename("/tmp/juci_t");
sourcefile s(filename);
parser.file_path=filename;
parser.project_path=filename;
s.save("");
}
void Source::Controller::OnOpenFile(const string &filepath) { void Source::Controller::OnOpenFile(const string &filepath) {
parser.file_path=filepath; parser.file_path=filepath;
sourcefile s(filepath); sourcefile s(filepath);
@ -315,7 +314,7 @@ void Source::Controller::OnOpenFile(const string &filepath) {
start_offset, start_offset,
end_offset, end_offset,
&Parser::clang_index); &Parser::clang_index);
view.OnUpdateSyntax(parser.ExtractTokens(start_offset, end_offset), config); update_syntax(parser.ExtractTokens(start_offset, end_offset));
//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:
@ -331,8 +330,7 @@ void Source::Controller::OnOpenFile(const string &filepath) {
parse_done.connect([this](){ parse_done.connect([this](){
if(parse_thread_mapped) { if(parse_thread_mapped) {
INFO("Updating syntax"); INFO("Updating syntax");
view. update_syntax(parser.ExtractTokens(0, buffer()->get_text().size()));
OnUpdateSyntax(parser.ExtractTokens(0, buffer()->get_text().size()), config);
INFO("Syntax updated"); INFO("Syntax updated");
} }
else { else {

18
juci/source.h

@ -66,28 +66,23 @@ namespace Source {
public: public:
View(); View();
virtual ~View() { } virtual ~View() { }
void OnUpdateSyntax(const std::vector<Range> &locations,
const Config &config);
std::string GetLine(size_t line_number); std::string GetLine(size_t line_number);
std::string GetLineBeforeInsert(); std::string GetLineBeforeInsert();
}; // class View }; // class View
class AutoCompleteChunk { class AutoCompleteChunk {
public: public:
explicit AutoCompleteChunk(const clang::CompletionChunk &chunk) : explicit AutoCompleteChunk(const clang::CompletionChunk &clang_chunk) :
chunk_(chunk.chunk()), kind_(chunk.kind()) { } chunk(clang_chunk.chunk()), kind(clang_chunk.kind()) { }
const std::string& chunk() const { return chunk_; } std::string chunk;
const clang::CompletionChunkKind& kind() const { return kind_; } enum clang::CompletionChunkKind kind;
private:
std::string chunk_;
enum clang::CompletionChunkKind kind_;
}; };
class AutoCompleteData { class AutoCompleteData {
public: public:
explicit AutoCompleteData(const std::vector<AutoCompleteChunk> &chunks) : explicit AutoCompleteData(const std::vector<AutoCompleteChunk> &chunks) :
chunks_(chunks) { } chunks(chunks) { }
std::vector<AutoCompleteChunk> chunks_; std::vector<AutoCompleteChunk> chunks;
}; };
class Controller; class Controller;
@ -131,6 +126,7 @@ namespace Source {
Controller(const Source::Config &config, Controller(const Source::Config &config,
const std::vector<std::unique_ptr<Source::Controller> > &controllers); const std::vector<std::unique_ptr<Source::Controller> > &controllers);
~Controller(); ~Controller();
void update_syntax(const std::vector<Range> &locations);
void OnNewEmptyFile(); void OnNewEmptyFile();
void OnOpenFile(const std::string &filename); void OnOpenFile(const std::string &filename);
Glib::RefPtr<Gsv::Buffer> buffer(); Glib::RefPtr<Gsv::Buffer> buffer();

Loading…
Cancel
Save