fix no autoloading journal for "filename.xopp" and "filename.xoj" problem (#3217)

* fix an autoloading journal problem

By default, if suppose we were to save a file "filename.pdf" as an xopp/xoj
file, it would save to "filename.xopp". But enabling Autloading journals
feature in Edit->Preferences->Load/Save doesn't detect "filename.xopp" or
"filename.xoj", while loading the pdf file and doesn't load the xopp/xoj
file. But it instead autoloads if the file were named as
"filename.pdf.xopp" or "filename.pdf.xoj". This is because Util::ClearExtensions
doesn't explicitly remove ".pdf" extension from the file path, but rather removes
".xoj" and ".xopp". Utils::ClearExtensions can be forced to remove ".pdf" extension by
passing the extension as the second argument to the function.
This commit implements that second argument and loads
"filename.xoj"/"filename.xopp" if autoloading is enabled.

* remove duplicated code with a loop

* resolve merge conflict

* apply clang format

* apply suggested changes
upstream-master
Vivek Thazhathattil 5 years ago committed by GitHub
parent 1a60605e7c
commit 923689147b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      src/control/Control.cpp

@ -2079,18 +2079,16 @@ auto Control::loadPdf(const fs::path& filepath, int scrollToPage) -> bool {
LoadHandler loadHandler;
if (settings->isAutoloadPdfXoj()) {
fs::path f = filepath;
Util::clearExtensions(f);
f += ".xopp";
Document* tmp = loadHandler.loadDocument(f);
if (tmp == nullptr) {
f = filepath;
Util::clearExtensions(f);
f += ".xoj";
Document* tmp;
const std::vector<std::string> exts = {".xopp", ".xoj", ".pdf.xopp", ".pdf.xoj"};
for (const std::string& ext: exts) {
fs::path f = filepath;
Util::clearExtensions(f, ".pdf");
f += ext;
tmp = loadHandler.loadDocument(f);
if (tmp)
break;
}
if (tmp) {
this->doc->lock();
this->doc->clearDocument();

Loading…
Cancel
Save