|
|
|
@ -128,38 +128,6 @@ std::vector<Source::View*> &Notebook::get_views() { |
|
|
|
return source_views; |
|
|
|
return source_views; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Notebook::reload(const boost::filesystem::path &file_path, size_t notebook_index) { |
|
|
|
|
|
|
|
if(boost::filesystem::exists(file_path)) { |
|
|
|
|
|
|
|
std::ifstream can_read(file_path.string()); |
|
|
|
|
|
|
|
if(!can_read) { |
|
|
|
|
|
|
|
Terminal::get().print("Error: could not open "+file_path.string()+"\n", true); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
can_read.close(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto last_view=get_current_view(); |
|
|
|
|
|
|
|
int offset = last_view->get_buffer()->get_insert()->get_iter().get_offset(); |
|
|
|
|
|
|
|
int line = last_view->get_buffer()->get_insert()->get_iter().get_line(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto language=Source::guess_language(file_path); |
|
|
|
|
|
|
|
last_view->get_buffer()->erase(last_view->get_buffer()->begin(), last_view->get_buffer()->end()); |
|
|
|
|
|
|
|
last_view->get_source_buffer()->begin_not_undoable_action(); |
|
|
|
|
|
|
|
if(language) { |
|
|
|
|
|
|
|
if(filesystem::read_non_utf8(file_path, last_view->get_buffer())==-1) |
|
|
|
|
|
|
|
Terminal::get().print("Warning: "+file_path.string()+" is not a valid UTF-8 file. Saving might corrupt the file.\n"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
if(filesystem::read(file_path, last_view->get_buffer())==-1) |
|
|
|
|
|
|
|
Terminal::get().print("Error: "+file_path.string()+" is not a valid UTF-8 file.\n", true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_view->get_source_buffer()->end_not_undoable_action(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
last_view->place_cursor_at_line_offset(line, offset); |
|
|
|
|
|
|
|
last_view->get_buffer()->set_modified(true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_index) { |
|
|
|
void Notebook::open(const boost::filesystem::path &file_path, size_t notebook_index) { |
|
|
|
if(notebook_index==1 && !split) |
|
|
|
if(notebook_index==1 && !split) |
|
|
|
toggle_split(); |
|
|
|
toggle_split(); |
|
|
|
@ -552,20 +520,7 @@ bool Notebook::close(size_t index) { |
|
|
|
if(on_close_page) |
|
|
|
if(on_close_page) |
|
|
|
on_close_page(view); |
|
|
|
on_close_page(view); |
|
|
|
|
|
|
|
|
|
|
|
size_t cursor_locations_index=0; |
|
|
|
delete_cursor_locations(view); |
|
|
|
for(auto it=cursor_locations.begin();it!=cursor_locations.end();) { |
|
|
|
|
|
|
|
if(it->view==view) { |
|
|
|
|
|
|
|
it=cursor_locations.erase(it); |
|
|
|
|
|
|
|
if(current_cursor_location!=static_cast<size_t>(-1) && current_cursor_location>cursor_locations_index) |
|
|
|
|
|
|
|
--current_cursor_location; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
++it; |
|
|
|
|
|
|
|
++cursor_locations_index; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(current_cursor_location>=cursor_locations.size()) |
|
|
|
|
|
|
|
current_cursor_location=cursor_locations.size()-1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(auto clang_view=dynamic_cast<Source::ClangView*>(view)) |
|
|
|
if(auto clang_view=dynamic_cast<Source::ClangView*>(view)) |
|
|
|
clang_view->async_delete(); |
|
|
|
clang_view->async_delete(); |
|
|
|
@ -579,6 +534,24 @@ bool Notebook::close(size_t index) { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Notebook::delete_cursor_locations(Source::View *view) { |
|
|
|
|
|
|
|
size_t cursor_locations_index=0; |
|
|
|
|
|
|
|
for(auto it=cursor_locations.begin();it!=cursor_locations.end();) { |
|
|
|
|
|
|
|
if(it->view==view) { |
|
|
|
|
|
|
|
view->get_buffer()->delete_mark(it->mark); |
|
|
|
|
|
|
|
it=cursor_locations.erase(it); |
|
|
|
|
|
|
|
if(current_cursor_location!=static_cast<size_t>(-1) && current_cursor_location>cursor_locations_index) |
|
|
|
|
|
|
|
--current_cursor_location; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
++it; |
|
|
|
|
|
|
|
++cursor_locations_index; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if(current_cursor_location>=cursor_locations.size()) |
|
|
|
|
|
|
|
current_cursor_location=cursor_locations.size()-1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool Notebook::close_current() { |
|
|
|
bool Notebook::close_current() { |
|
|
|
return close(get_index(get_current_view())); |
|
|
|
return close(get_index(get_current_view())); |
|
|
|
} |
|
|
|
} |
|
|
|
|