|
|
|
@ -1,5 +1,6 @@ |
|
|
|
#include "source_base.h" |
|
|
|
#include "source_base.h" |
|
|
|
#include "config.h" |
|
|
|
#include "config.h" |
|
|
|
|
|
|
|
#include "filesystem.h" |
|
|
|
#include "git.h" |
|
|
|
#include "git.h" |
|
|
|
#include "info.h" |
|
|
|
#include "info.h" |
|
|
|
#include "selection_dialog.h" |
|
|
|
#include "selection_dialog.h" |
|
|
|
@ -106,62 +107,27 @@ bool Source::BaseView::load(bool not_undoable_action) { |
|
|
|
disable_spellcheck = false; |
|
|
|
disable_spellcheck = false; |
|
|
|
}}; |
|
|
|
}}; |
|
|
|
|
|
|
|
|
|
|
|
if(language) { |
|
|
|
if(boost::filesystem::exists(file_path, ec)) { |
|
|
|
std::ifstream input(file_path.string(), std::ofstream::binary); |
|
|
|
try { |
|
|
|
if(input) { |
|
|
|
auto io_channel = Glib::IOChannel::create_from_file(file_path.string(), "r"); |
|
|
|
std::string str; |
|
|
|
Glib::ustring text; |
|
|
|
input.seekg(0, std::ios::end); |
|
|
|
if(get_buffer()->size() == 0) { |
|
|
|
auto size = input.tellg(); |
|
|
|
Glib::IOStatus status; |
|
|
|
input.seekg(0, std::ios::beg); |
|
|
|
do { |
|
|
|
str.reserve(size); |
|
|
|
status = io_channel->read(text, 131072); |
|
|
|
str.assign(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()); |
|
|
|
get_buffer()->insert_at_cursor(text); |
|
|
|
Glib::ustring ustr(std::move(str)); |
|
|
|
} while(status == Glib::IOStatus::IO_STATUS_NORMAL); |
|
|
|
|
|
|
|
|
|
|
|
bool valid = true; |
|
|
|
|
|
|
|
Glib::ustring::iterator iter; |
|
|
|
|
|
|
|
while(!ustr.validate(iter)) { |
|
|
|
|
|
|
|
auto next_char_iter = iter; |
|
|
|
|
|
|
|
next_char_iter++; |
|
|
|
|
|
|
|
ustr.replace(iter, next_char_iter, "?"); |
|
|
|
|
|
|
|
valid = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!valid) |
|
|
|
|
|
|
|
Terminal::get().print("Warning: " + file_path.string() + " is not a valid UTF-8 file. Saving might corrupt the file.\n"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(get_buffer()->size() == 0) |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor(ustr); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
replace_text(ustr.raw()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
std::ifstream input(file_path.string(), std::ofstream::binary); |
|
|
|
|
|
|
|
if(input) { |
|
|
|
|
|
|
|
std::string str; |
|
|
|
|
|
|
|
input.seekg(0, std::ios::end); |
|
|
|
|
|
|
|
auto size = input.tellg(); |
|
|
|
|
|
|
|
input.seekg(0, std::ios::beg); |
|
|
|
|
|
|
|
str.reserve(size); |
|
|
|
|
|
|
|
str.assign(std::istreambuf_iterator<char>(input), std::istreambuf_iterator<char>()); |
|
|
|
|
|
|
|
Glib::ustring ustr(std::move(str)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ustr.validate()) { |
|
|
|
|
|
|
|
if(get_buffer()->size() == 0) |
|
|
|
|
|
|
|
get_buffer()->insert_at_cursor(ustr); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
replace_text(ustr.raw()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
Terminal::get().print("Error: " + file_path.string() + " is not a valid UTF-8 file.\n", true); |
|
|
|
io_channel->read_to_end(text); |
|
|
|
return false; |
|
|
|
replace_text(text.raw()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
catch(const Glib::Error &error) { |
|
|
|
|
|
|
|
Terminal::get().print("Error: Could not read file " + filesystem::get_short_path(file_path).string() + ": " + error.what() + '\n', true); |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get_buffer()->set_modified(false); |
|
|
|
get_buffer()->set_modified(false); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
|