Browse Source

Fixed crash.

merge-requests/365/head
eidheim 11 years ago
parent
commit
88a0713128
  1. 26
      juci/notebook.cc
  2. 4
      juci/notebook.h
  3. 20
      juci/source.cc
  4. 2
      juci/source.h

26
juci/notebook.cc

@ -290,7 +290,6 @@ bool Notebook::Controller::GeneratePopup(int key_id) {
Notebook::Controller::~Controller() { Notebook::Controller::~Controller() {
INFO("Notebook destructor"); INFO("Notebook destructor");
for (auto &i : text_vec_) delete i;
for (auto &i : editor_vec_) delete i; for (auto &i : editor_vec_) delete i;
for (auto &i : scrolledtext_vec_) delete i; for (auto &i : scrolledtext_vec_) delete i;
} }
@ -336,7 +335,7 @@ void Notebook::Controller::OnOpenFile(std::string path) {
void Notebook::Controller::OnCreatePage() { void Notebook::Controller::OnCreatePage() {
INFO("Notebook create page"); INFO("Notebook create page");
text_vec_.push_back(new Source::Controller(source_config(), this)); text_vec_.emplace_back(new Source::Controller(source_config(), this));
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());
scrolledtext_vec_.back()->add(text_vec_.back()->view()); scrolledtext_vec_.back()->add(text_vec_.back()->view());
@ -352,7 +351,6 @@ void Notebook::Controller::OnCloseCurrentPage() {
} }
int page = CurrentPage(); int page = CurrentPage();
Notebook().remove_page(page); Notebook().remove_page(page);
delete text_vec_.at(page);
delete scrolledtext_vec_.at(page); delete scrolledtext_vec_.at(page);
delete editor_vec_.at(page); delete editor_vec_.at(page);
text_vec_.erase(text_vec_.begin()+ page); text_vec_.erase(text_vec_.begin()+ page);
@ -371,17 +369,17 @@ void Notebook::Controller::OnFileNewHeaderFile() {
} }
void Notebook::Controller::OnEditCopy() { void Notebook::Controller::OnEditCopy() {
if (Pages() != 0) { if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_); Buffer(*text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnEditPaste() { void Notebook::Controller::OnEditPaste() {
if (Pages() != 0) { if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_); Buffer(*text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_);
} }
} }
void Notebook::Controller::OnEditCut() { void Notebook::Controller::OnEditCut() {
if (Pages() != 0) { if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->cut_clipboard(refClipboard_); Buffer(*text_vec_.at(CurrentPage()))->cut_clipboard(refClipboard_);
} }
} }
@ -390,8 +388,8 @@ std::string Notebook::Controller::GetCursorWord() {
int page = CurrentPage(); int page = CurrentPage();
std::string word; std::string word;
Gtk::TextIter start, end; Gtk::TextIter start, end;
start = Buffer(text_vec_.at(page))->get_insert()->get_iter(); start = Buffer(*text_vec_.at(page))->get_insert()->get_iter();
end = Buffer(text_vec_.at(page))->get_insert()->get_iter(); end = Buffer(*text_vec_.at(page))->get_insert()->get_iter();
if (!end.ends_line()) { if (!end.ends_line()) {
while (!end.ends_word()) { while (!end.ends_word()) {
end.forward_char(); end.forward_char();
@ -402,14 +400,14 @@ std::string Notebook::Controller::GetCursorWord() {
start.backward_char(); start.backward_char();
} }
} }
word = Buffer(text_vec_.at(page))->get_text(start, end); word = Buffer(*text_vec_.at(page))->get_text(start, end);
// TODO(Oyvang) fix selected text // TODO(Oyvang) fix selected text
return word; return word;
} }
void Notebook::Controller::OnEditSearch() { void Notebook::Controller::OnEditSearch() {
search_match_end_ = search_match_end_ =
Buffer(text_vec_.at(CurrentPage()))->get_iter_at_offset(0); Buffer(*text_vec_.at(CurrentPage()))->get_iter_at_offset(0);
entry_.OnShowSearch(GetCursorWord()); entry_.OnShowSearch(GetCursorWord());
} }
@ -423,7 +421,7 @@ void Notebook::Controller::Search(bool forward) {
if ( !forward ) { if ( !forward ) {
if ( search_match_start_ == 0 || if ( search_match_start_ == 0 ||
search_match_start_.get_line_offset() == 0) { search_match_start_.get_line_offset() == 0) {
search_match_start_ = Buffer(text_vec_.at(CurrentPage()))->end(); search_match_start_ = Buffer(*text_vec_.at(CurrentPage()))->end();
} }
search_match_start_. search_match_start_.
backward_search(search_word, backward_search(search_word,
@ -433,7 +431,7 @@ void Notebook::Controller::Search(bool forward) {
search_match_end_); search_match_end_);
} else { } else {
if ( search_match_end_ == 0 ) { if ( search_match_end_ == 0 ) {
search_match_end_ = Buffer(text_vec_.at(CurrentPage()))->begin(); search_match_end_ = Buffer(*text_vec_.at(CurrentPage()))->begin();
} }
search_match_end_. search_match_end_.
forward_search(search_word, forward_search(search_word,
@ -476,8 +474,8 @@ int Notebook::Controller::CurrentPage() {
} }
Glib::RefPtr<Gtk::TextBuffer> Glib::RefPtr<Gtk::TextBuffer>
Notebook::Controller::Buffer(Source::Controller *source) { Notebook::Controller::Buffer(Source::Controller &source) {
return source->view().get_buffer(); return source.view().get_buffer();
} }
int Notebook::Controller::Pages() { int Notebook::Controller::Pages() {

4
juci/notebook.h

@ -35,7 +35,7 @@ namespace Notebook {
Source::Config& config, Source::Config& config,
Directories::Config& dir_cfg); Directories::Config& dir_cfg);
~Controller(); ~Controller();
Glib::RefPtr<Gtk::TextBuffer> Buffer(Source::Controller *source); Glib::RefPtr<Gtk::TextBuffer> Buffer(Source::Controller &source);
Source::View& CurrentTextView(); Source::View& CurrentTextView();
int CurrentPage(); int CurrentPage();
Gtk::Box& entry_view(); Gtk::Box& entry_view();
@ -101,7 +101,7 @@ namespace Notebook {
bool is_new_file_; bool is_new_file_;
Entry::Controller entry_; Entry::Controller entry_;
std::vector<Source::Controller*> text_vec_; std::vector<std::unique_ptr<Source::Controller> > text_vec_;
std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_; std::vector<Gtk::ScrolledWindow*> scrolledtext_vec_;
std::vector<Gtk::HBox*> editor_vec_; std::vector<Gtk::HBox*> editor_vec_;
std::list<Gtk::TargetEntry> listTargets_; std::list<Gtk::TargetEntry> listTargets_;

20
juci/source.cc

@ -120,10 +120,10 @@ InitSyntaxHighlighting(const std::string &filepath,
clang::Index *index) { clang::Index *index) {
set_project_path(project_path); set_project_path(project_path);
std::vector<string> arguments = get_compilation_commands(); std::vector<string> arguments = get_compilation_commands();
tu_ = clang::TranslationUnit(index, tu_ = std::unique_ptr<clang::TranslationUnit>(new clang::TranslationUnit(index,
filepath, filepath,
arguments, arguments,
buffers); buffers));
} }
// Source::View::UpdateLine // Source::View::UpdateLine
@ -136,7 +136,7 @@ OnLineEdit(const std::vector<Source::Range> &locations,
// Source::Model::UpdateLine // Source::Model::UpdateLine
int Source::Model:: int Source::Model::
ReParse(const std::map<std::string, std::string> &buffer) { ReParse(const std::map<std::string, std::string> &buffer) {
return tu_.ReparseTranslationUnit(file_path(), buffer); return tu_->ReparseTranslationUnit(file_path(), buffer);
} }
@ -168,7 +168,7 @@ GetAutoCompleteSuggestions(const std::map<std::string, std::string> &buffers,
int column, int column,
std::vector<Source::AutoCompleteData> std::vector<Source::AutoCompleteData>
*suggestions) { *suggestions) {
clang::CodeCompleteResults results(&tu_, clang::CodeCompleteResults results(tu_.get(),
file_path(), file_path(),
buffers, buffers,
line_number, line_number,
@ -224,10 +224,10 @@ get_compilation_commands() {
std::vector<Source::Range> Source::Model:: std::vector<Source::Range> Source::Model::
ExtractTokens(int start_offset, int end_offset) { ExtractTokens(int start_offset, int end_offset) {
std::vector<Source::Range> ranges; std::vector<Source::Range> ranges;
clang::SourceLocation start(&tu_, file_path(), start_offset); clang::SourceLocation start(tu_.get(), file_path(), start_offset);
clang::SourceLocation end(&tu_, file_path(), end_offset); clang::SourceLocation end(tu_.get(), file_path(), end_offset);
clang::SourceRange range(&start, &end); clang::SourceRange range(&start, &end);
clang::Tokens tokens(&tu_, &range); clang::Tokens tokens(tu_.get(), &range);
std::vector<clang::Token> tks = tokens.tokens(); std::vector<clang::Token> tks = tokens.tokens();
for (auto &token : tks) { for (auto &token : tks) {
switch (token.kind()) { switch (token.kind()) {
@ -244,8 +244,8 @@ ExtractTokens(int start_offset, int end_offset) {
void Source::Model:: void Source::Model::
HighlightCursor(clang::Token *token, HighlightCursor(clang::Token *token,
std::vector<Source::Range> *source_ranges) { std::vector<Source::Range> *source_ranges) {
clang::SourceLocation location = token->get_source_location(&tu_); clang::SourceLocation location = token->get_source_location(tu_.get());
clang::Cursor cursor(&tu_, &location); clang::Cursor cursor(tu_.get(), &location);
clang::SourceRange range(&cursor); clang::SourceRange range(&cursor);
clang::SourceLocation begin(&range, true); clang::SourceLocation begin(&range, true);
clang::SourceLocation end(&range, false); clang::SourceLocation end(&range, false);
@ -261,7 +261,7 @@ void Source::Model::
HighlightToken(clang::Token *token, HighlightToken(clang::Token *token,
std::vector<Source::Range> *source_ranges, std::vector<Source::Range> *source_ranges,
int token_kind) { int token_kind) {
clang::SourceRange range = token->get_source_range(&tu_); clang::SourceRange range = token->get_source_range(tu_.get());
unsigned begin_line_num, begin_offset, end_line_num, end_offset; unsigned begin_line_num, begin_offset, end_line_num, end_offset;
clang::SourceLocation begin(&range, true); clang::SourceLocation begin(&range, true);
clang::SourceLocation end(&range, false); clang::SourceLocation end(&range, false);

2
juci/source.h

@ -129,7 +129,7 @@ namespace Source {
Config config_; Config config_;
std::string file_path_; std::string file_path_;
std::string project_path_; std::string project_path_;
clang::TranslationUnit tu_; std::unique_ptr<clang::TranslationUnit> tu_; //use unique_ptr since it is not initialized in constructor
void HighlightToken(clang::Token *token, void HighlightToken(clang::Token *token,
std::vector<Range> *source_ranges, std::vector<Range> *source_ranges,
int token_kind); int token_kind);

Loading…
Cancel
Save