|
|
|
@ -1,6 +1,5 @@ |
|
|
|
#include "notebook.h" |
|
|
|
#include "notebook.h" |
|
|
|
#include <fstream> |
|
|
|
#include <fstream> |
|
|
|
#include "clangmm.h" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Notebook::Model::Model() { |
|
|
|
Notebook::Model::Model() { |
|
|
|
cc_extension_ = ".cc"; |
|
|
|
cc_extension_ = ".cc"; |
|
|
|
@ -8,7 +7,7 @@ Notebook::Model::Model() { |
|
|
|
scrollvalue_ = 50; |
|
|
|
scrollvalue_ = 50; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Notebook::View::View() { |
|
|
|
Notebook::View::View() : notebook_() { |
|
|
|
view_.pack2(notebook_); |
|
|
|
view_.pack2(notebook_); |
|
|
|
view_.set_position(120); |
|
|
|
view_.set_position(120); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -17,20 +16,14 @@ Notebook::Controller::Controller(Gtk::Window* window, Keybindings::Controller& k |
|
|
|
Source::Config& source_cfg, |
|
|
|
Source::Config& source_cfg, |
|
|
|
Directories::Config& dir_cfg) : |
|
|
|
Directories::Config& dir_cfg) : |
|
|
|
source_config_(source_cfg), |
|
|
|
source_config_(source_cfg), |
|
|
|
directories_(dir_cfg) { |
|
|
|
directories_(dir_cfg), |
|
|
|
std::cout << "NOTEBOOK CONTROLLER"<< std::endl; |
|
|
|
index_(0, 1) { |
|
|
|
window_ = window; |
|
|
|
window_ = window; |
|
|
|
std::cout << "1"<< std::endl; |
|
|
|
|
|
|
|
OnNewPage("juCi++"); |
|
|
|
OnNewPage("juCi++"); |
|
|
|
std::cout << "2"<< std::endl; |
|
|
|
|
|
|
|
refClipboard_ = Gtk::Clipboard::get(); |
|
|
|
refClipboard_ = Gtk::Clipboard::get(); |
|
|
|
std::cout << "3"<< std::endl; |
|
|
|
|
|
|
|
ispopup = false; |
|
|
|
ispopup = false; |
|
|
|
std::cout << "4"<< std::endl; |
|
|
|
|
|
|
|
view().pack1(directories_.widget(), true, true); |
|
|
|
view().pack1(directories_.widget(), true, true); |
|
|
|
std::cout << "5"<< std::endl; |
|
|
|
|
|
|
|
CreateKeybindings(keybindings); |
|
|
|
CreateKeybindings(keybindings); |
|
|
|
std::cout << "FERDIG"<< std::endl; |
|
|
|
|
|
|
|
} // Constructor
|
|
|
|
} // Constructor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -147,34 +140,82 @@ bool Notebook::Controller:: OnMouseRelease(GdkEventButton* button){ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) { |
|
|
|
bool Notebook::Controller::OnKeyRelease(GdkEventKey* key) { |
|
|
|
if(key->keyval==46){ |
|
|
|
return GeneratePopup(key->keyval); |
|
|
|
return GeneratePopup(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Notebook::Controller::GeneratePopup(){ |
|
|
|
bool Notebook::Controller::GeneratePopup(int key_id) { |
|
|
|
// Get function to fill popup with suggests item vector under is for testing
|
|
|
|
// Get function to fill popup with suggests item vector under is for testing
|
|
|
|
std::vector<std::string> items; |
|
|
|
Gtk::TextIter beg = CurrentTextView().get_buffer()->get_insert()->get_iter(); |
|
|
|
Gtk::TextIter start = CurrentTextView().get_buffer()->get_insert()->get_iter(); |
|
|
|
Gtk::TextIter end = CurrentTextView().get_buffer()->get_insert()->get_iter(); |
|
|
|
text_vec_.at(CurrentPage())->GetAutoCompleteSuggestions(start.get_line()+1, |
|
|
|
Gtk::TextIter tmp = CurrentTextView().get_buffer()->get_insert()->get_iter(); |
|
|
|
start.get_line_offset()+2, |
|
|
|
Gtk::TextIter tmp1 = CurrentTextView().get_buffer()->get_insert()->get_iter(); |
|
|
|
&items); |
|
|
|
Gtk::TextIter line = |
|
|
|
std::cout << items.size()<< std::endl; |
|
|
|
CurrentTextView().get_buffer()->get_iter_at_line(tmp.get_line()); |
|
|
|
if(items.size()>0){ |
|
|
|
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; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
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
|
|
|
|
// Replace over with get suggestions from zalox! OVER IS JUST FOR TESTING
|
|
|
|
|
|
|
|
|
|
|
|
Gtk::ScrolledWindow popup_scroll_; |
|
|
|
Gtk::ScrolledWindow popup_scroll_; |
|
|
|
Gtk::ListViewText listview_(1, false, Gtk::SelectionMode::SELECTION_SINGLE); |
|
|
|
Gtk::ListViewText listview_(1, false, Gtk::SelectionMode::SELECTION_SINGLE); |
|
|
|
|
|
|
|
|
|
|
|
popup_scroll_.set_policy(Gtk::PolicyType::POLICY_NEVER, |
|
|
|
popup_scroll_.set_policy(Gtk::PolicyType::POLICY_NEVER, |
|
|
|
Gtk::PolicyType::POLICY_NEVER); |
|
|
|
Gtk::PolicyType::POLICY_NEVER); |
|
|
|
listview_.set_enable_search(false); |
|
|
|
listview_.set_enable_search(true); |
|
|
|
listview_.set_headers_visible(false); |
|
|
|
listview_.set_headers_visible(false); |
|
|
|
listview_.set_hscroll_policy(Gtk::ScrollablePolicy::SCROLL_NATURAL); |
|
|
|
listview_.set_hscroll_policy(Gtk::ScrollablePolicy::SCROLL_NATURAL); |
|
|
|
listview_.set_activate_on_single_click(true); |
|
|
|
listview_.set_activate_on_single_click(true); |
|
|
|
for (auto &i : items) listview_.append(i); |
|
|
|
if (items.empty()) { |
|
|
|
|
|
|
|
items["No suggestions found..."] = ""; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (auto &i : items) { |
|
|
|
|
|
|
|
listview_.append(i.first); |
|
|
|
|
|
|
|
} |
|
|
|
popup_scroll_.add(listview_); |
|
|
|
popup_scroll_.add(listview_); |
|
|
|
popup_.get_vbox()->pack_start(popup_scroll_); |
|
|
|
popup_.get_vbox()->pack_start(popup_scroll_); |
|
|
|
popup_.set_transient_for(*window_); |
|
|
|
popup_.set_transient_for(*window_); |
|
|
|
@ -186,15 +227,13 @@ bool Notebook::Controller::GeneratePopup(){ |
|
|
|
int x, y; |
|
|
|
int x, y; |
|
|
|
FindPopupPosition(CurrentTextView(), popup_x, popup_y, x, y); |
|
|
|
FindPopupPosition(CurrentTextView(), popup_x, popup_y, x, y); |
|
|
|
popup_.move(x, y+15); |
|
|
|
popup_.move(x, y+15); |
|
|
|
PopupSelectHandler(popup_, listview_); |
|
|
|
PopupSelectHandler(popup_, listview_, &items); |
|
|
|
ispopup = true; |
|
|
|
ispopup = true; |
|
|
|
popup_.run(); |
|
|
|
popup_.run(); |
|
|
|
popup_.hide(); |
|
|
|
popup_.hide(); |
|
|
|
ispopup = false; |
|
|
|
ispopup = false; |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { |
|
|
|
bool Notebook::Controller::ScrollEventCallback(GdkEventScroll* scroll_event) { |
|
|
|
int page = CurrentPage(); |
|
|
|
int page = CurrentPage(); |
|
|
|
@ -236,6 +275,14 @@ void Notebook::Controller::OnNewPage(std::string name) { |
|
|
|
Notebook().set_focus_child(text_vec_.at(Pages()-1)->view()); |
|
|
|
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) { |
|
|
|
void Notebook::Controller::OnOpenFile(std::string path) { |
|
|
|
OnCreatePage(); |
|
|
|
OnCreatePage(); |
|
|
|
text_vec_.back()->OnOpenFile(path); |
|
|
|
text_vec_.back()->OnOpenFile(path); |
|
|
|
@ -243,16 +290,14 @@ void Notebook::Controller::OnOpenFile(std::string path) { |
|
|
|
unsigned pos = path.find_last_of("/\\"); |
|
|
|
unsigned pos = path.find_last_of("/\\"); |
|
|
|
Notebook().append_page(*editor_vec_.back(), path.substr(pos+1)); |
|
|
|
Notebook().append_page(*editor_vec_.back(), path.substr(pos+1)); |
|
|
|
Notebook().show_all_children(); |
|
|
|
Notebook().show_all_children(); |
|
|
|
std::cout << "setting current page"<< std::endl; |
|
|
|
|
|
|
|
Notebook().set_current_page(Pages()-1); |
|
|
|
Notebook().set_current_page(Pages()-1); |
|
|
|
std::cout << "current page set" << std::endl; |
|
|
|
|
|
|
|
Notebook().set_focus_child(text_vec_.back()->view()); |
|
|
|
Notebook().set_focus_child(text_vec_.back()->view()); |
|
|
|
OnBufferChange(); |
|
|
|
OnBufferChange(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Notebook::Controller::OnCreatePage() { |
|
|
|
void Notebook::Controller::OnCreatePage() { |
|
|
|
text_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())); |
|
|
|
linenumbers_vec_.push_back(new Source::Controller(source_config(), this)); |
|
|
|
scrolledline_vec_.push_back(new Gtk::ScrolledWindow()); |
|
|
|
scrolledline_vec_.push_back(new Gtk::ScrolledWindow()); |
|
|
|
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow()); |
|
|
|
scrolledtext_vec_.push_back(new Gtk::ScrolledWindow()); |
|
|
|
editor_vec_.push_back(new Gtk::HBox()); |
|
|
|
editor_vec_.push_back(new Gtk::HBox()); |
|
|
|
@ -451,16 +496,17 @@ void Notebook::Controller::TextViewHandlers(Gtk::TextView& textview) { |
|
|
|
|
|
|
|
|
|
|
|
textview.signal_key_release_event(). |
|
|
|
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, |
|
|
|
void Notebook::Controller::PopupSelectHandler(Gtk::Dialog &popup, |
|
|
|
Gtk::ListViewText &listview){ |
|
|
|
Gtk::ListViewText &listview, |
|
|
|
|
|
|
|
std::map<std::string, std::string> |
|
|
|
|
|
|
|
*items) { |
|
|
|
listview.signal_row_activated(). |
|
|
|
listview.signal_row_activated(). |
|
|
|
connect([this, &listview, &popup](const Gtk::TreeModel::Path& path, |
|
|
|
connect([this, &listview, &popup, items](const Gtk::TreeModel::Path& path, |
|
|
|
Gtk::TreeViewColumn*) { |
|
|
|
Gtk::TreeViewColumn*) { |
|
|
|
std::string selected = |
|
|
|
std::string selected = items-> |
|
|
|
listview.get_text(listview.get_selected()[0]); |
|
|
|
at(listview.get_text(listview.get_selected()[0])); |
|
|
|
CurrentTextView().get_buffer()->insert_at_cursor(selected); |
|
|
|
CurrentTextView().get_buffer()->insert_at_cursor(selected); |
|
|
|
popup.response(Gtk::RESPONSE_DELETE_EVENT); |
|
|
|
popup.response(Gtk::RESPONSE_DELETE_EVENT); |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -472,7 +518,6 @@ void Notebook::Controller::PopupSetSize(Gtk::ScrolledWindow &scroll, |
|
|
|
int textview_y = 150; |
|
|
|
int textview_y = 150; |
|
|
|
bool is_never_scroll_x = true; |
|
|
|
bool is_never_scroll_x = true; |
|
|
|
bool is_never_scroll_y = true; |
|
|
|
bool is_never_scroll_y = true; |
|
|
|
std::cout << textview_x << std::endl; |
|
|
|
|
|
|
|
if (current_x > textview_x) { |
|
|
|
if (current_x > textview_x) { |
|
|
|
current_x = textview_x; |
|
|
|
current_x = textview_x; |
|
|
|
is_never_scroll_x = false; |
|
|
|
is_never_scroll_x = false; |
|
|
|
@ -540,7 +585,7 @@ void Notebook::Controller:: OnSaveFile() { |
|
|
|
file.open (path); |
|
|
|
file.open (path); |
|
|
|
file << CurrentTextView().get_buffer()->get_text(); |
|
|
|
file << CurrentTextView().get_buffer()->get_text(); |
|
|
|
file.close(); |
|
|
|
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); |
|
|
|
text_vec_.at(CurrentPage())->set_is_saved(true); |
|
|
|
} |
|
|
|
} |
|
|
|
}
|
|
|
|
}
|
|
|
|
|