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() {
INFO("Notebook destructor");
for (auto &i : text_vec_) delete i;
for (auto &i : editor_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() {
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());
editor_vec_.push_back(new Gtk::HBox());
scrolledtext_vec_.back()->add(text_vec_.back()->view());
@ -352,7 +351,6 @@ void Notebook::Controller::OnCloseCurrentPage() {
}
int page = CurrentPage();
Notebook().remove_page(page);
delete text_vec_.at(page);
delete scrolledtext_vec_.at(page);
delete editor_vec_.at(page);
text_vec_.erase(text_vec_.begin()+ page);
@ -371,17 +369,17 @@ void Notebook::Controller::OnFileNewHeaderFile() {
}
void Notebook::Controller::OnEditCopy() {
if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_);
Buffer(*text_vec_.at(CurrentPage()))->copy_clipboard(refClipboard_);
}
}
void Notebook::Controller::OnEditPaste() {
if (Pages() != 0) {
Buffer(text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_);
Buffer(*text_vec_.at(CurrentPage()))->paste_clipboard(refClipboard_);
}
}
void Notebook::Controller::OnEditCut() {
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();
std::string word;
Gtk::TextIter start, end;
start = Buffer(text_vec_.at(page))->get_insert()->get_iter();
end = 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();
if (!end.ends_line()) {
while (!end.ends_word()) {
end.forward_char();
@ -402,14 +400,14 @@ std::string Notebook::Controller::GetCursorWord() {
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
return word;
}
void Notebook::Controller::OnEditSearch() {
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());
}
@ -423,7 +421,7 @@ void Notebook::Controller::Search(bool forward) {
if ( !forward ) {
if ( search_match_start_ == 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_.
backward_search(search_word,
@ -433,7 +431,7 @@ void Notebook::Controller::Search(bool forward) {
search_match_end_);
} else {
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_.
forward_search(search_word,
@ -476,8 +474,8 @@ int Notebook::Controller::CurrentPage() {
}
Glib::RefPtr<Gtk::TextBuffer>
Notebook::Controller::Buffer(Source::Controller *source) {
return source->view().get_buffer();
Notebook::Controller::Buffer(Source::Controller &source) {
return source.view().get_buffer();
}
int Notebook::Controller::Pages() {

4
juci/notebook.h

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

20
juci/source.cc

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

2
juci/source.h

@ -129,7 +129,7 @@ namespace Source {
Config config_;
std::string file_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,
std::vector<Range> *source_ranges,
int token_kind);

Loading…
Cancel
Save