Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge release branch into master #3653

Merged
merged 3 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/control/Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ auto Control::openFile(fs::path filepath, int scrollToPage, bool forceOpen) -> b
return loadXoptTemplate(filepath);
}

if (filepath.extension() == ".pdf") {
if (Util::hasPdfFileExt(filepath)) {
return loadPdf(filepath, scrollToPage);
}

Expand Down
4 changes: 2 additions & 2 deletions src/core/control/RecentManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void RecentManager::addRecentFileFilename(const fs::path& filepath) {
std::array<gchar*, 2> groups = {group_name.data(), nullptr};
std::string app_name = g_get_application_name();
std::string app_exec = std::string(g_get_prgname()) + " %u";
std::string mime_type = (filepath.extension() == ".pdf") ? std::string(MIME_PDF) : std::string(MIME);
std::string mime_type = Util::hasPdfFileExt(filepath) ? std::string(MIME_PDF) : std::string(MIME);

GtkRecentData recentData{};
recentData.display_name = nullptr;
Expand Down Expand Up @@ -137,7 +137,7 @@ auto RecentManager::filterRecent(GList* items, bool xoj) -> GList* {
if (xoj && Util::hasXournalFileExt(*p)) {
filteredItems = g_list_prepend(filteredItems, info);
}
if (!xoj && p->extension() == ".pdf") {
if (!xoj && Util::hasPdfFileExt(*p)) {
filteredItems = g_list_prepend(filteredItems, info);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/core/control/tools/InputHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,11 @@ void InputHandler::createStroke(Point p) {
}
} else if (h->getToolType() == TOOL_HIGHLIGHTER) {
stroke->setToolType(STROKE_TOOL_HIGHLIGHTER);
p.z = Point::NO_PRESSURE;
} else if (h->getToolType() == TOOL_ERASER) {
stroke->setToolType(STROKE_TOOL_ERASER);
stroke->setColor(Color(0xffffffU));
p.z = Point::NO_PRESSURE;
}

stroke->addPoint(p);
Expand Down
7 changes: 5 additions & 2 deletions src/core/model/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,11 @@ auto Document::createSaveFilename(DocumentType type, const std::string& defaultS
}
if (!pdfFilepath.empty()) {
fs::path p = pdfFilepath.filename();
std::string ext = this->attachPdf ? ".pdf" : "";
Util::clearExtensions(p, ext);
if (this->attachPdf) {
Util::clearExtensions(p, ".pdf");
} else {
Util::clearExtensions(p);
}
return p;
}

Expand Down
6 changes: 5 additions & 1 deletion src/util/PathUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,14 @@ auto Util::getEscapedPath(const fs::path& path) -> std::string {
}

auto Util::hasXournalFileExt(const fs::path& path) -> bool {
auto extension = path.extension();
auto extension = StringUtils::toLowerCase(path.extension().string());
return extension == ".xoj" || extension == ".xopp";
}

auto Util::hasPdfFileExt(const fs::path& path) -> bool {
return StringUtils::toLowerCase(path.extension().string()) == ".pdf";
}

auto Util::clearExtensions(fs::path& path, const std::string& ext) -> void {
auto rm_ext = [&path](const std::string ext) {
if (StringUtils::toLowerCase(path.extension().string()) == StringUtils::toLowerCase(ext)) {
Expand Down
9 changes: 7 additions & 2 deletions src/util/include/util/PathUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ namespace Util {
[[maybe_unused]] [[nodiscard]] bool hasXournalFileExt(const fs::path& path);

/**
* Clear the the last known xournal extension (last .xoj, .xopp etc.)
* @return true if this file has a pdf extension
*/
bool hasPdfFileExt(const fs::path& path);

/**
* Clear the xournal extensions ignoring case (.xoj, .xopp)
*
* @param ext An extension to clear additionally, eg .pdf (would also clear
* .pdf.xopp etc.)
* .PDF.xopp etc.)
*/
void clearExtensions(fs::path& path, const std::string& ext = "");

Expand Down