autosave_restore moved out of welcome in case of loading from file
This commit is contained in:
+4
-2
@@ -126,13 +126,15 @@ namespace anm2ed
|
|||||||
return directory_get() / path::from_utf8(autosaveNameUtf8);
|
return directory_get() / path::from_utf8(autosaveNameUtf8);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::filesystem::path Document::path_from_autosave_get(std::filesystem::path& path)
|
std::filesystem::path Document::path_from_autosave_get(const std::filesystem::path& path)
|
||||||
{
|
{
|
||||||
auto fileName = path::to_utf8(path.filename());
|
auto fileName = path::to_utf8(path.filename());
|
||||||
if (!fileName.empty() && fileName.front() == '.') fileName.erase(fileName.begin());
|
if (!fileName.empty() && fileName.front() == '.') fileName.erase(fileName.begin());
|
||||||
|
constexpr std::string_view autosaveExtension = ".autosave";
|
||||||
|
if (fileName.ends_with(autosaveExtension))
|
||||||
|
fileName.erase(fileName.size() - autosaveExtension.size());
|
||||||
|
|
||||||
auto restorePath = path.parent_path() / std::filesystem::path(std::u8string(fileName.begin(), fileName.end()));
|
auto restorePath = path.parent_path() / std::filesystem::path(std::u8string(fileName.begin(), fileName.end()));
|
||||||
restorePath.replace_extension("");
|
|
||||||
|
|
||||||
return restorePath;
|
return restorePath;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -105,7 +105,7 @@ namespace anm2ed
|
|||||||
bool autosave(std::string* = nullptr, anm2::Compatibility = anm2::ANM2ED, bool = false, bool = true,
|
bool autosave(std::string* = nullptr, anm2::Compatibility = anm2::ANM2ED, bool = false, bool = true,
|
||||||
bool = true);
|
bool = true);
|
||||||
std::filesystem::path autosave_path_get();
|
std::filesystem::path autosave_path_get();
|
||||||
std::filesystem::path path_from_autosave_get(std::filesystem::path&);
|
std::filesystem::path path_from_autosave_get(const std::filesystem::path&);
|
||||||
|
|
||||||
void snapshot(const std::string& message);
|
void snapshot(const std::string& message);
|
||||||
void undo();
|
void undo();
|
||||||
|
|||||||
@@ -0,0 +1,54 @@
|
|||||||
|
#include "autosave_restore.hpp"
|
||||||
|
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
#include "path_.hpp"
|
||||||
|
|
||||||
|
using namespace anm2ed::resource;
|
||||||
|
using namespace anm2ed::util;
|
||||||
|
|
||||||
|
namespace anm2ed::imgui
|
||||||
|
{
|
||||||
|
void AutosaveRestore::update(Manager& manager)
|
||||||
|
{
|
||||||
|
if (!manager.autosaveFiles.empty() && !popup.is_open()) popup.open();
|
||||||
|
|
||||||
|
popup.trigger();
|
||||||
|
|
||||||
|
if (ImGui::BeginPopupModal(popup.label(), &popup.isOpen, ImGuiWindowFlags_NoResize))
|
||||||
|
{
|
||||||
|
ImGui::TextUnformatted(localize.get(LABEL_RESTORE_AUTOSAVES_PROMPT));
|
||||||
|
|
||||||
|
auto childSize = child_size_get(5);
|
||||||
|
|
||||||
|
if (ImGui::BeginChild("##Restore Files Child", childSize, ImGuiChildFlags_Borders,
|
||||||
|
ImGuiWindowFlags_HorizontalScrollbar))
|
||||||
|
{
|
||||||
|
for (auto& file : manager.autosaveFiles)
|
||||||
|
{
|
||||||
|
auto label = std::format(FILE_LABEL_FORMAT, path::to_utf8(file.filename()), path::to_utf8(file));
|
||||||
|
ImGui::TextUnformatted(label.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui::EndChild();
|
||||||
|
|
||||||
|
auto widgetSize = widget_size_with_row_get(2);
|
||||||
|
|
||||||
|
if (ImGui::Button(localize.get(BASIC_YES), widgetSize))
|
||||||
|
{
|
||||||
|
manager.autosave_files_open();
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::SameLine();
|
||||||
|
|
||||||
|
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
|
||||||
|
{
|
||||||
|
manager.autosave_files_clear();
|
||||||
|
popup.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::EndPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "manager.hpp"
|
||||||
|
#include "strings.hpp"
|
||||||
|
|
||||||
|
namespace anm2ed::imgui
|
||||||
|
{
|
||||||
|
class AutosaveRestore
|
||||||
|
{
|
||||||
|
PopupHelper popup{PopupHelper(LABEL_WELCOME_RESTORE_POPUP, imgui::POPUP_SMALL_NO_HEIGHT)};
|
||||||
|
|
||||||
|
public:
|
||||||
|
void update(Manager&);
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -46,6 +46,8 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
welcome.update(manager, resources, dialog, taskbar, documents);
|
welcome.update(manager, resources, dialog, taskbar, documents);
|
||||||
|
|
||||||
|
autosaveRestore.update(manager);
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "autosave_restore.hpp"
|
||||||
#include "documents.hpp"
|
#include "documents.hpp"
|
||||||
#include "taskbar.hpp"
|
#include "taskbar.hpp"
|
||||||
#include "window/animation_preview.hpp"
|
#include "window/animation_preview.hpp"
|
||||||
@@ -35,6 +36,7 @@ namespace anm2ed::imgui
|
|||||||
Timeline timeline;
|
Timeline timeline;
|
||||||
Tools tools;
|
Tools tools;
|
||||||
Welcome welcome;
|
Welcome welcome;
|
||||||
|
AutosaveRestore autosaveRestore;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void tick(Manager&, Settings&, float);
|
void tick(Manager&, Settings&, float);
|
||||||
|
|||||||
@@ -65,46 +65,6 @@ namespace anm2ed::imgui
|
|||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
if (!manager.autosaveFiles.empty() && !restorePopup.is_open()) restorePopup.open();
|
|
||||||
|
|
||||||
restorePopup.trigger();
|
|
||||||
|
|
||||||
if (ImGui::BeginPopupModal(restorePopup.label(), &restorePopup.isOpen, ImGuiWindowFlags_NoResize))
|
|
||||||
{
|
|
||||||
ImGui::TextUnformatted(localize.get(LABEL_RESTORE_AUTOSAVES_PROMPT));
|
|
||||||
|
|
||||||
auto childSize = child_size_get(5);
|
|
||||||
|
|
||||||
if (ImGui::BeginChild("##Restore Files Child", childSize, ImGuiChildFlags_Borders,
|
|
||||||
ImGuiWindowFlags_HorizontalScrollbar))
|
|
||||||
{
|
|
||||||
for (auto& file : manager.autosaveFiles)
|
|
||||||
{
|
|
||||||
auto label = std::format(FILE_LABEL_FORMAT, path::to_utf8(file.filename()), path::to_utf8(file));
|
|
||||||
ImGui::TextUnformatted(label.c_str());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ImGui::EndChild();
|
|
||||||
|
|
||||||
auto widgetSize = widget_size_with_row_get(2);
|
|
||||||
|
|
||||||
if (ImGui::Button(localize.get(BASIC_YES), widgetSize))
|
|
||||||
{
|
|
||||||
manager.autosave_files_open();
|
|
||||||
restorePopup.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
|
||||||
|
|
||||||
if (ImGui::Button(localize.get(BASIC_NO), widgetSize))
|
|
||||||
{
|
|
||||||
manager.autosave_files_clear();
|
|
||||||
restorePopup.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndPopup();
|
|
||||||
}
|
|
||||||
|
|
||||||
selectable_input_text_id() = {};
|
selectable_input_text_id() = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "documents.hpp"
|
#include "documents.hpp"
|
||||||
#include "manager.hpp"
|
|
||||||
#include "strings.hpp"
|
|
||||||
#include "taskbar.hpp"
|
#include "taskbar.hpp"
|
||||||
|
|
||||||
namespace anm2ed::imgui
|
namespace anm2ed::imgui
|
||||||
{
|
{
|
||||||
class Welcome
|
class Welcome
|
||||||
{
|
{
|
||||||
PopupHelper restorePopup{PopupHelper(LABEL_WELCOME_RESTORE_POPUP, imgui::POPUP_SMALL_NO_HEIGHT)};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void update(Manager&, Resources&, Dialog&, Taskbar&, Documents&);
|
void update(Manager&, Resources&, Dialog&, Taskbar&, Documents&);
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-9
@@ -353,18 +353,10 @@ namespace anm2ed
|
|||||||
{
|
{
|
||||||
for (auto& path : autosaveFiles)
|
for (auto& path : autosaveFiles)
|
||||||
{
|
{
|
||||||
auto fileNamePath = path.filename();
|
|
||||||
auto fileNameUtf8 = path::to_utf8(fileNamePath);
|
|
||||||
if (!fileNameUtf8.empty() && fileNameUtf8.front() == '.') fileNameUtf8.erase(fileNameUtf8.begin());
|
|
||||||
fileNamePath = path::from_utf8(fileNameUtf8);
|
|
||||||
|
|
||||||
auto restorePath = path.parent_path() / fileNamePath;
|
|
||||||
restorePath.replace_extension("");
|
|
||||||
|
|
||||||
if (auto document = open(path, false, false))
|
if (auto document = open(path, false, false))
|
||||||
{
|
{
|
||||||
document->isForceDirty = true;
|
document->isForceDirty = true;
|
||||||
document->path = restorePath;
|
document->path = document->path_from_autosave_get(path);
|
||||||
document->change(Document::ALL);
|
document->change(Document::ALL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user