Browse Source

Merged with master

merge-requests/365/head
oyvang 11 years ago
parent
commit
cd72ddef74
  1. 4
      juci/api.h
  2. 4
      juci/config.cc
  3. 247
      juci/notebook.cc
  4. 28
      juci/notebook.h
  5. 66
      juci/source.cc
  6. 109
      juci/source.h

4
juci/api.h

@ -55,9 +55,9 @@ namespace libjuci {
const std::string plugin_path,
const std::string menu_keybinding);
void AddMenuXml(const std::string plugin_name,
const string parent_menu);
const std::string parent_menu);
void AddSubMenuXml(const std::string plugin_name,
const string parent_menu);
const std::string parent_menu);
//////////////////////////////
//// Boost.Python methods ////
//////////////////////////////

4
juci/config.cc

@ -17,16 +17,14 @@ void MainConfig::GenerateSource() {
boost::property_tree::ptree colors_json = source_json.get_child("colors");
for ( auto &i : colors_json ) {
source_cfg_.InsertTag(i.first, i.second.get_value<std::string>());
std::cout << "inserting tag, key: " << i.first << " value: " << i.second.get_value<std::string>() << std::endl;
}
for ( auto &i : syntax_json ) {
source_cfg_.InsertType(i.first, i.second.get_value<std::string>());
std::cout << "inserting type, key: " << i.first << " value: " << i.second.get_value<std::string>() << std::endl;
}
}
void MainConfig::GenerateKeybindings() {
string line;
std::string line;
std::ifstream menu_xml("menu.xml");
if (menu_xml.is_open()) {
while (getline(menu_xml, line)) {

247
juci/notebook.cc

@ -1,6 +1,5 @@
#include "notebook.h"
#include <fstream>
#include "clangmm.h"
Notebook::Model::Model() {
cc_extension_ = ".cc";
@ -8,7 +7,7 @@ Notebook::Model::Model() {
scrollvalue_ = 50;
}
Notebook::View::View() {
Notebook::View::View() : notebook_() {
view_.pack2(notebook_);
view_.set_position(120);
}
@ -17,20 +16,14 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& k
Source::Config& source_cfg,
Directories::Config& dir_cfg) :
source_config_(source_cfg),
directories_(dir_cfg) {
std::cout << "NOTEBOOK CONTROLLER"<< std::endl;
directories_(dir_cfg),
index_(0, 1) {
window_ = window;
std::cout << "1"<< std::endl;
OnNewPage("juCi++");
std::cout << "2"<< std::endl;
refClipboard_ = Gtk::Clipboard::get();
std::cout << "3"<< std::endl;
ispopup = false;
std::cout << "4"<< std::endl;
view().pack1(directories_.widget(), true, true);
std::cout << "5"<< std::endl;
CreateKeybindings(keybindings);
std::cout << "FERDIG"<< std::endl;
} // Constructor
@ -105,7 +98,7 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
[this]() {
OnEditPaste();
});
entry_.view_.entry().signal_activate().
entry_.view_.entry().signal_activate().
connect(
[this]() {
if (is_new_file_) {
@ -138,62 +131,108 @@ void Notebook::Controller::CreateKeybindings(Keybindings::Controller
});
}
bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button){
if(button->button == 1 && ispopup){
popup_.response(Gtk::RESPONSE_DELETE_EVENT);
return true;
bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button) {
if (button->button == 1 && ispopup) {
popup_.response(Gtk::RESPONSE_DELETE_EVENT);
return true;
}
return false;
}
bool Notebook::Controller::OnKeyRelease(GdkEventKey* key){
if(key->keyval==46){
return GeneratePopup();
}
return false;
bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) {
return GeneratePopup(key->keyval);
}
bool Notebook::Controller::GeneratePopup(){
bool Notebook::Controller::GeneratePopup(int key_id) {
// Get function to fill popup with suggests item vector under is for testing
std::vector<std::string> items;
Gtk::TextIter start = CurrentTextView().get_buffer()->get_insert()->get_iter();
text_vec_.at(CurrentPage())->GetAutoCompleteSuggestions(start.get_line()+1,
start.get_line_offset()+2,
&items);
std::cout << items.size()<< std::endl;
if(items.size()>0){
// Replace over with get suggestions from zalox! OVER IS JUST FOR TESTING
Gtk::ScrolledWindow popup_scroll_;
Gtk::ListViewText listview_(1,false,Gtk::SelectionMode::SELECTION_SINGLE);
popup_scroll_.set_policy(Gtk::PolicyType::POLICY_NEVER,
Gtk::PolicyType::POLICY_NEVER);
listview_.set_enable_search(false);
listview_.set_headers_visible(false);
listview_.set_hscroll_policy(Gtk::ScrollablePolicy::SCROLL_NATURAL);
listview_.set_activate_on_single_click(true);
for (auto &i : items) listview_.append(i);
popup_scroll_.add(listview_);
popup_.get_vbox()->pack_start(popup_scroll_);
popup_.set_transient_for(*window_);
popup_.show_all();
int popup_x = popup_.get_width();
int popup_y = items.size()*20;
PopupSetSize(popup_scroll_,popup_x,popup_y);
int x,y;
FindPopupPosition(CurrentTextView(),popup_x,popup_y,x,y);
popup_.move(x, y+15);
PopupSelectHandler(popup_, listview_);
ispopup = true;
popup_.run();
popup_.hide();
ispopup = false;
return true;
Gtk::TextIter beg = CurrentTextView().get_buffer()->get_insert()->get_iter();
Gtk::TextIter end = CurrentTextView().get_buffer()->get_insert()->get_iter();
Gtk::TextIter tmp = CurrentTextView().get_buffer()->get_insert()->get_iter();
Gtk::TextIter tmp1 = CurrentTextView().get_buffer()->get_insert()->get_iter();
Gtk::TextIter line =
CurrentTextView().get_buffer()->get_iter_at_line(tmp.get_line());
if (end.backward_char() && end.backward_char()) {
bool illegal_chars =
end.backward_search("\"", Gtk::TEXT_SEARCH_VISIBLE_ONLY, tmp, tmp1, line)
||
end.backward_search("//", Gtk::TEXT_SEARCH_VISIBLE_ONLY, tmp, tmp1, line);
if (illegal_chars) {
return false;
}
std::string c = text_vec_[CurrentPage()]->buffer()->get_text(end, beg);
switch (key_id) {
case 46:
break;
case 58:
if (c != "::") return false;
break;
case 60:
if (c != "->") return false;
break;
case 62:
if (c != "->") return false;
break;
default:
return false;
}
} else {
return false;
}
return false;
std::vector<Source::AutoCompleteData> acdata;
text_vec_.at(CurrentPage())->
GetAutoCompleteSuggestions(beg.get_line()+1,
beg.get_line_offset()+2,
&acdata);
std::map<std::string, std::string> items;
for (auto &data : acdata) {
std::stringstream ss;
std::string return_value;
for (auto &chunk : data.chunks_) {
switch (chunk.kind()) {
case clang::CompletionChunk_ResultType:
return_value = chunk.chunk();
break;
case clang::CompletionChunk_Informative:
break;
default:
ss << chunk.chunk();
break;
}
}
items[ss.str() + " --> " + return_value] = ss.str();
}
// Replace over with get suggestions from zalox! OVER IS JUST FOR TESTING
Gtk::ScrolledWindow popup_scroll_;
Gtk::ListViewText listview_(1, false, Gtk::SelectionMode::SELECTION_SINGLE);
popup_scroll_.set_policy(Gtk::PolicyType::POLICY_NEVER,
Gtk::PolicyType::POLICY_NEVER);
listview_.set_enable_search(true);
listview_.set_headers_visible(false);
listview_.set_hscroll_policy(Gtk::ScrollablePolicy::SCROLL_NATURAL);
listview_.set_activate_on_single_click(true);
if (items.empty()) {
items["No suggestions found..."] = "";
}
for (auto &i : items) {
listview_.append(i.first);
}
popup_scroll_.add(listview_);
popup_.get_vbox()->pack_start(popup_scroll_);
popup_.set_transient_for(*window_);
popup_.show_all();
int popup_x = popup_.get_width();
int popup_y = items.size() * 20;
PopupSetSize(popup_scroll_, popup_x, popup_y);
int x, y;
FindPopupPosition(CurrentTextView(), popup_x, popup_y, x, y);
popup_.move(x, y+15);
PopupSelectHandler(popup_, listview_, &items);
ispopup = true;
popup_.run();
popup_.hide();
ispopup = false;
return true;
}
bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) {
@ -236,6 +275,14 @@ void Notebook::Controller::OnNewPage(std::string name) {
Notebook().set_focus_child(text_vec_.at(Pages()-1)->view());
}
void Notebook::Controller::
MapBuffers(std::map<std::string, std::string> *buffers) {
for (auto &buffer : text_vec_) {
buffers->operator[](buffer->model().file_path()) =
buffer->buffer()->get_text().raw();
}
}
void Notebook::Controller::OnOpenFile(std::string path) {
OnCreatePage();
text_vec_.back()->OnOpenFile(path);
@ -243,16 +290,14 @@ void Notebook::Controller::OnOpenFile(std::string path) {
unsigned pos = path.find_last_of("/\\");
Notebook().append_page(*editor_vec_.back(), path.substr(pos+1));
Notebook().show_all_children();
std::cout << "setting current page"<< std::endl;
Notebook().set_current_page(Pages()-1);
std::cout << "current page set" << std::endl;
Notebook().set_focus_child(text_vec_.back()->view());
OnBufferChange();
}
void Notebook::Controller::OnCreatePage() {
text_vec_.push_back(new Source::Controller(source_config()));
linenumbers_vec_.push_back(new Source::Controller(source_config()));
text_vec_.push_back(new Source::Controller(source_config(), this));
linenumbers_vec_.push_back(new Source::Controller(source_config(), this));
scrolledline_vec_.push_back(new Gtk::ScrolledWindow());
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow());
editor_vec_.push_back(new Gtk::HBox());
@ -442,37 +487,37 @@ Gtk::Notebook& Notebook::Controller::Notebook() {
void Notebook::Controller::TextViewHandlers(Gtk::TextView& textview) {
textview.get_buffer()->signal_changed().connect(
[this]() {
OnBufferChange();
});
[this]() {
OnBufferChange();
});
textview.signal_button_release_event().
connect(sigc::mem_fun(*this,&Notebook::Controller::OnMouseRelease),false);
connect(sigc::mem_fun(*this, &Notebook::Controller::OnMouseRelease), false);
textview.signal_key_release_event().
connect(sigc::mem_fun(*this,&Notebook::Controller::OnKeyRelease),false);
connect(sigc::mem_fun(*this, &Notebook::Controller::OnKeyRelease), false);
}
void Notebook::Controller::PopupSelectHandler(Gtk::Dialog &popup,
Gtk::ListViewText &listview){
Gtk::ListViewText &listview,
std::map<std::string, std::string>
*items) {
listview.signal_row_activated().
connect([this, &listview, &popup](const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn*) {
std::string selected =
listview.get_text(listview.get_selected()[0]);
CurrentTextView().get_buffer()->insert_at_cursor(selected);
popup.response(Gtk::RESPONSE_DELETE_EVENT);
});
connect([this, &listview, &popup, items](const Gtk::TreeModel::Path& path,
Gtk::TreeViewColumn*) {
std::string selected = items->
at(listview.get_text(listview.get_selected()[0]));
CurrentTextView().get_buffer()->insert_at_cursor(selected);
popup.response(Gtk::RESPONSE_DELETE_EVENT);
});
}
void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll,
int &current_x,
int &current_y) {
int &current_x,
int &current_y) {
int textview_x = CurrentTextView().get_width();
int textview_y = 150;
bool is_never_scroll_x = true;
bool is_never_scroll_y = true;
std::cout << textview_x << std::endl;
if (current_x > textview_x) {
current_x = textview_x;
is_never_scroll_x = false;
@ -481,49 +526,49 @@ void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll,
current_y = textview_y;
is_never_scroll_y = false;
}
scroll.set_size_request(current_x,current_y);
scroll.set_size_request(current_x, current_y);
if (!is_never_scroll_x && !is_never_scroll_y) {
scroll.set_policy(Gtk::PolicyType::POLICY_AUTOMATIC,
Gtk::PolicyType::POLICY_AUTOMATIC);
Gtk::PolicyType::POLICY_AUTOMATIC);
} else if (!is_never_scroll_x && is_never_scroll_y) {
scroll.set_policy(Gtk::PolicyType::POLICY_AUTOMATIC,
Gtk::PolicyType::POLICY_NEVER);
Gtk::PolicyType::POLICY_NEVER);
} else if (is_never_scroll_x && !is_never_scroll_y) {
scroll.set_policy(Gtk::PolicyType::POLICY_NEVER,
Gtk::PolicyType::POLICY_AUTOMATIC);
Gtk::PolicyType::POLICY_AUTOMATIC);
}
}
void Notebook::Controller::FindPopupPosition(Gtk::TextView& textview,
int popup_x,
int popup_y,
int &x,
int &y){
int popup_x,
int popup_y,
int &x,
int &y) {
Gdk::Rectangle temp1, temp2;
textview.get_cursor_locations(
CurrentTextView().
get_buffer()->get_insert()->
get_iter(), temp1,temp2);
CurrentTextView().
get_buffer()->get_insert()->
get_iter(), temp1, temp2);
int textview_edge_x = 0;
int textview_edge_y = 0;
textview.buffer_to_window_coords(
Gtk::TextWindowType::TEXT_WINDOW_WIDGET,
temp1.get_x(),
temp1.get_y(),
x, y);
Gtk::TextWindowType::TEXT_WINDOW_WIDGET,
temp1.get_x(),
temp1.get_y(),
x, y);
Glib::RefPtr<Gdk::Window> gdkw =
CurrentTextView().get_window(Gtk::TextWindowType::TEXT_WINDOW_WIDGET);
gdkw->get_origin(textview_edge_x, textview_edge_y);
x+=textview_edge_x;
y+=textview_edge_y;
x += textview_edge_x;
y += textview_edge_y;
if ((textview_edge_x-x)*-1 > textview.get_width()-popup_x) {
x -= popup_x;
if(x<textview_edge_x) x = textview_edge_x;
if (x < textview_edge_x) x = textview_edge_x;
}
if ((textview_edge_y-y)*-1 > textview.get_height()-popup_y) {
y -= (popup_y+14) + 15;
if(x<textview_edge_y) y = textview_edge_y +15;
if (x < textview_edge_y) y = textview_edge_y +15;
}
}
@ -540,7 +585,7 @@ void Notebook::Controller:: OnSaveFile() {
file.open (path);
file << CurrentTextView().get_buffer()->get_text();
file.close();
text_vec_.at(CurrentPage())->set_path(path);
text_vec_.at(CurrentPage())->set_file_path(path);
text_vec_.at(CurrentPage())->set_is_saved(true);
}
}

28
juci/notebook.h

@ -8,7 +8,9 @@
#include "directories.h"
#include <boost/algorithm/string/case_conv.hpp>
#include <type_traits>
#include <map>
#include <sigc++/sigc++.h>
#include "clangmm.h"
namespace Notebook {
class Model {
@ -56,10 +58,12 @@ namespace Notebook {
void OnOpenFile(std::string filename);
void OnCreatePage();
bool ScrollEventCallback(GdkEventScroll* scroll_event);
void MapBuffers(std::map<std::string, std::string> *buffers);
clang::Index* index() { return &index_; }
int Pages();
Directories::Controller& directories() { return directories_; }
Directories::Controller& directories() { return directories_; }
Gtk::Paned& view();
bool GeneratePopup();
bool GeneratePopup(int key);
void Search(bool forward);
const Source::Config& source_config() { return source_config_; }
bool OnMouseRelease(GdkEventButton* button);
@ -68,17 +72,20 @@ namespace Notebook {
protected:
void TextViewHandlers(Gtk::TextView& textview);
void PopupSelectHandler(Gtk::Dialog &popup,
Gtk::ListViewText &listview);
private:
Gtk::ListViewText &listview,
std::map<std::string, std::string>
*items);
private:
void CreateKeybindings(Keybindings::Controller& keybindings);
void FindPopupPosition(Gtk::TextView& textview,
int popup_x,
int popup_y,
int &x,
int &y);
int popup_x,
int popup_y,
int &x,
int &y);
void PopupSetSize(Gtk::ScrolledWindow& scroll,
int &current_x,
int &current_y);
int &current_x,
int &current_y);
Glib::RefPtr<Gtk::Builder> m_refBuilder;
Glib::RefPtr<Gio::SimpleActionGroup> refActionGroup;
Source::Config source_config_;
@ -97,6 +104,7 @@ namespace Notebook {
bool ispopup;
Gtk::Dialog popup_;
Gtk::Window* window_;
clang::Index index_;
}; // class controller
} // namespace Notebook
#endif // JUCI_NOTEBOOK_H_

66
juci/source.cc

@ -4,7 +4,7 @@
#include <boost/property_tree/json_parser.hpp>
#include <fstream>
#include <boost/timer/timer.hpp>
#include "notebook.h"
#define log( var ) \
std::cout << "source.cc (" << __LINE__ << ") " << #var << std::endl
@ -102,16 +102,17 @@ Source::Model::Model(const Source::Config &config) :
void Source::Model::
InitSyntaxHighlighting(const std::string &filepath,
const std::string &project_path,
const std::string &text,
const std::map<std::string, std::string>
&buffers,
int start_offset,
int end_offset) {
set_file_path(filepath);
int end_offset,
clang::Index *index) {
set_project_path(project_path);
std::vector<const char*> arguments = get_compilation_commands();
tu_ = clang::TranslationUnit(true,
tu_ = clang::TranslationUnit(index,
filepath,
arguments,
text);
buffers);
}
// Source::View::UpdateLine
@ -123,7 +124,7 @@ OnLineEdit(const std::vector<Source::Range> &locations,
// Source::Model::UpdateLine
int Source::Model::
ReParse(const std::string &buffer) {
ReParse(const std::map<std::string, std::string> &buffer) {
return tu_.ReparseTranslationUnit(file_path(), buffer);
}
@ -135,10 +136,12 @@ void Source::Controller::OnLineEdit() { }
void Source::Controller::
GetAutoCompleteSuggestions(int line_number,
int column,
std::vector<std::string> *suggestions) {
std::vector<Source::AutoCompleteData>
*suggestions) {
parsing.lock();
model().GetAutoCompleteSuggestions(view().get_buffer()
->get_text().raw(),
std::map<std::string, std::string> buffers;
notebook_->MapBuffers(&buffers);
model().GetAutoCompleteSuggestions(buffers,
line_number,
column,
suggestions);
@ -146,22 +149,23 @@ GetAutoCompleteSuggestions(int line_number,
}
void Source::Model::
GetAutoCompleteSuggestions(const std::string& buffer,
GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers,
int line_number,
int column,
std::vector<std::string> *suggestions) {
std::vector<Source::AutoCompleteData>
*suggestions) {
clang::CodeCompleteResults results(&tu_,
file_path(),
buffer,
buffers,
line_number,
column);
for (int i = 0; i < results.size(); i++) {
std::stringstream ss;
const vector<clang::CompletionChunk> c = results.get(i).get_chunks();
for (auto &stringchunk : c) {
ss << stringchunk.chunk();
const vector<clang::CompletionChunk> chunks_ = results.get(i).get_chunks();
std::vector<AutoCompleteChunk> chunks;
for (auto &chunk : chunks_) {
chunks.emplace_back(chunk);
}
suggestions->emplace_back(ss.str());
suggestions->emplace_back(chunks);
}
}
@ -261,9 +265,9 @@ HighlightToken(clang::Token *token,
// Source::Controller::Controller()
// Constructor for Controller
Source::Controller::Controller(const Source::Config &config) :
model_(config) {
}
Source::Controller::Controller(const Source::Config &config,
Notebook::Controller *notebook) :
model_(config), notebook_(notebook) { }
// Source::Controller::view()
// return shared_ptr to the view
@ -282,7 +286,6 @@ void Source::Controller::OnNewEmptyFile() {
model().set_file_path(filename);
model().set_project_path(filename);
s.save("");
//OnOpenFile(filename); //OYVANG ADDED; REMOVE IF WRONG
}
string extract_file_path(const std::string &file_path) {
@ -312,7 +315,7 @@ void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges,
Glib::RefPtr<Gtk::TextBuffer> buffer = get_buffer();
buffer->remove_all_tags(buffer->begin(), buffer->end());
for (auto &range : ranges) {
string type = std::to_string(range.kind());
std::string type = std::to_string(range.kind());
try {
config.typetable().at(type);
} catch (std::exception) {
@ -335,19 +338,22 @@ void Source::View::OnUpdateSyntax(const std::vector<Source::Range> &ranges,
}
void Source::Controller::OnOpenFile(const string &filepath) {
path_=filepath;
set_file_path(filepath);
sourcefile s(filepath);
std::map<std::string, std::string> buffers;
notebook_->MapBuffers(&buffers);
buffers[filepath] = s.get_content();
buffer()->set_text(s.get_content());
int start_offset = buffer()->begin().get_offset();
int end_offset = buffer()->end().get_offset();
if (check_extention(filepath)) {
view().ApplyConfig(model().config());
model().InitSyntaxHighlighting(filepath,
extract_file_path(filepath),
buffer()->get_text().raw(),
buffers,
start_offset,
end_offset);
end_offset,
notebook_->index());
view().OnUpdateSyntax(model().ExtractTokens(start_offset, end_offset),
model().config());
}
@ -358,7 +364,10 @@ void Source::Controller::OnOpenFile(const string &filepath) {
if (parsing.try_lock()) {
while (true) {
const std::string raw = buffer()->get_text().raw();
if (model().ReParse(raw) == 0 &&
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;
@ -373,7 +382,6 @@ void Source::Controller::OnOpenFile(const string &filepath) {
}
});
buffer()->signal_begin_user_action().connect([this]() {
if (go) {
syntax.lock();

109
juci/source.h

@ -3,31 +3,34 @@
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
#include "gtkmm.h"
#include "clangmm.h"
#include <thread>
#include <mutex>
#include <string>
using std::string;
namespace Notebook {
class Controller;
}
namespace Source {
class Config {
public:
Config(const Config &original);
Config();
const std::unordered_map<string, string>& tagtable() const;
const std::unordered_map<string, string>& typetable() const;
void SetTagTable(const std::unordered_map<string, string> &tagtable);
void InsertTag(const string &key, const string &value);
void SetTypeTable(const std::unordered_map<string, string> &tagtable);
void InsertType(const string &key, const string &value);
const std::unordered_map<std::string, std::string>& tagtable() const;
const std::unordered_map<std::string, std::string>& typetable() const;
void SetTagTable(const std::unordered_map<std::string, std::string>
&tagtable);
void InsertTag(const std::string &key, const std::string &value);
void SetTypeTable(const std::unordered_map<std::string, std::string>
&tagtable);
void InsertType(const std::string &key, const std::string &value);
private:
std::unordered_map<string, string> tagtable_;
std::unordered_map<string, string> typetable_;
string background_;
std::unordered_map<std::string, std::string> tagtable_;
std::unordered_map<std::string, std::string> typetable_;
std::string background_;
}; // class Config
class Location {
@ -48,13 +51,6 @@ namespace Source {
const Location& start() const { return start_; }
const Location& end() const { return end_; }
int kind() const { return kind_; }
void to_stream() const {
std::cout << "range: [" << start_.line_number()-1;
std::cout << ", " << end_.line_number()-1 << "] ";
std::cout << "<" << start_.column_offset()-1;
std::cout << ", " << end_.column_offset()-1 << ">";
std::cout << std::endl;
}
private:
Location start_;
Location end_;
@ -71,68 +67,91 @@ namespace Source {
const Config &config);
private:
string GetLine(const Gtk::TextIter &begin);
std::string GetLine(const Gtk::TextIter &begin);
}; // class View
class AutoCompleteChunk {
public:
explicit AutoCompleteChunk(const clang::CompletionChunk &chunk) :
chunk_(chunk.chunk()), kind_(chunk.kind()) { }
const std::string& chunk() const { return chunk_; }
const clang::CompletionChunkKind& kind() const { return kind_; }
private:
std::string chunk_;
enum clang::CompletionChunkKind kind_;
};
class AutoCompleteData {
public:
explicit AutoCompleteData(const std::vector<AutoCompleteChunk> &chunks) :
chunks_(chunks) { }
std::vector<AutoCompleteChunk> chunks_;
};
class Model{
public:
// constructor for Source::Model
explicit Model(const Source::Config &config);
// inits the syntax highligthing on file open
void InitSyntaxHighlighting(const std::string &filepath,
const std::string &project_path,
const std::string &text,
int start_offset,
int end_offset);
const std::string &project_path,
const std::map<std::string, std::string>
&buffers,
int start_offset,
int end_offset,
clang::Index *index);
// sets the filepath for this mvc
void set_file_path(const string &file_path);
void set_file_path(const std::string &file_path);
// sets the project path for this mvc
void set_project_path(const string &project_path);
void set_project_path(const std::string &project_path);
// gets the file_path member
const string& file_path() const;
const std::string& file_path() const;
// gets the project_path member
const string& project_path() const;
const std::string& project_path() const;
// gets the config member
const Config& config() const;
void GetAutoCompleteSuggestions(const std::string& buffer,
int line_number,
int column,
std::vector<std::string> *suggestions);
~Model() { }
int ReParse(const std::string &buffer);
void GetAutoCompleteSuggestions(const std::map<std::string, std::string>
&buffers,
int line_number,
int column,
std::vector<AutoCompleteData>
*suggestions);
~Model() { }
int ReParse(const std::map<std::string, std::string> &buffers);
std::vector<Range> ExtractTokens(int, int);
private:
Config config_;
string file_path_;
string project_path_;
std::string file_path_;
std::string project_path_;
clang::TranslationUnit tu_;
void HighlightToken(clang::Token *token,
std::vector<Range> *source_ranges,
int token_kind);
void HighlightCursor(clang::Token *token,
std::vector<Range> *source_ranges);
std::vector<const char*> get_compilation_commands();
};
class Controller {
public:
explicit Controller(const Source::Config &config);
Controller(const Source::Config &config,
Notebook::Controller *notebook);
Controller();
View& view();
Model& model();
void OnNewEmptyFile();
void OnOpenFile(const string &filename);
void OnOpenFile(const std::string &filename);
void GetAutoCompleteSuggestions(int line_number,
int column,
std::vector<std::string> *suggestions);
std::vector<AutoCompleteData>
*suggestions);
Glib::RefPtr<Gtk::TextBuffer> buffer();
bool is_saved(){return is_saved_;};
std::string path(){return path_;};
void set_is_saved(bool isSaved){is_saved_ = isSaved;};
void set_path(std::string path){path_ = path;};
bool is_saved() { return is_saved_; }
std::string path() { return model().file_path(); }
void set_is_saved(bool isSaved) { is_saved_ = isSaved; }
void set_file_path(std::string path) { model().set_file_path(path); }
private:
@ -140,13 +159,13 @@ namespace Source {
void OnSaveFile();
std::mutex syntax;
std::mutex parsing;
std::string path_;
bool go = false;
bool is_saved_ = false;
protected:
View view_;
Model model_;
Notebook::Controller *notebook_;
}; // class Controller
} // namespace Source
#endif // JUCI_SOURCE_H_

Loading…
Cancel
Save