Implement stamp renaming
This commit is contained in:
parent
d84e0a0c3e
commit
7623f45e6e
@ -11,6 +11,7 @@
|
||||
#include "common/platform/Platform.h"
|
||||
#include "common/String.h"
|
||||
#include "graphics/Graphics.h"
|
||||
#include "gui/dialogues/ErrorMessage.h"
|
||||
#include "prefs/Prefs.h"
|
||||
#include "lua/CommandInterface.h"
|
||||
#include "Config.h"
|
||||
@ -287,6 +288,27 @@ void Client::DeleteStamp(ByteString stampID)
|
||||
}
|
||||
}
|
||||
|
||||
void Client::RenameStamp(ByteString stampID, ByteString newName)
|
||||
{
|
||||
auto oldPath = ByteString::Build(STAMPS_DIR, PATH_SEP_CHAR, stampID, ".stm");
|
||||
auto newPath = ByteString::Build(STAMPS_DIR, PATH_SEP_CHAR, newName, ".stm");
|
||||
|
||||
if (Platform::FileExists(newPath))
|
||||
{
|
||||
new ErrorMessage("Error renaming stamp", "A stamp with this name already exists.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Platform::RenameFile(oldPath, newPath, false))
|
||||
{
|
||||
new ErrorMessage("Error renaming stamp", "Could not rename the stamp.");
|
||||
return;
|
||||
}
|
||||
|
||||
std::replace(stampIDs.begin(), stampIDs.end(), stampID, newName);
|
||||
WriteStamps();
|
||||
}
|
||||
|
||||
ByteString Client::AddStamp(std::unique_ptr<GameSave> saveData)
|
||||
{
|
||||
auto now = (uint64_t)time(NULL);
|
||||
|
@ -91,6 +91,7 @@ public:
|
||||
|
||||
std::unique_ptr<SaveFile> GetStamp(ByteString stampID);
|
||||
void DeleteStamp(ByteString stampID);
|
||||
void RenameStamp(ByteString stampID, ByteString newName);
|
||||
ByteString AddStamp(std::unique_ptr<GameSave> saveData);
|
||||
void RescanStamps();
|
||||
const std::vector<ByteString> &GetStamps() const;
|
||||
|
@ -7,6 +7,8 @@
|
||||
#include "client/GameSave.h"
|
||||
#include "client/SaveFile.h"
|
||||
#include "gui/dialogues/ConfirmPrompt.h"
|
||||
#include "gui/dialogues/TextPrompt.h"
|
||||
#include "gui/dialogues/ErrorMessage.h"
|
||||
#include "tasks/TaskWindow.h"
|
||||
#include "tasks/Task.h"
|
||||
|
||||
@ -75,6 +77,23 @@ void LocalBrowserController::removeSelectedC()
|
||||
new TaskWindow("Removing stamps", new RemoveSavesTask(this, selected));
|
||||
}
|
||||
|
||||
void LocalBrowserController::RenameSelected()
|
||||
{
|
||||
ByteString save = browserModel->GetSelected()[0];
|
||||
|
||||
new TextPrompt("Rename stamp", "Enter a new name for the stamp:", "", "[new name]", false, { [this, save](const String &newName) {
|
||||
if (newName.length() == 0)
|
||||
{
|
||||
new ErrorMessage("Error renaming stamp", "You have to specify the filename.");
|
||||
return;
|
||||
}
|
||||
|
||||
Client::Ref().RenameStamp(save, newName.ToUtf8());
|
||||
|
||||
RefreshSavesList();
|
||||
} });
|
||||
}
|
||||
|
||||
void LocalBrowserController::RescanStamps()
|
||||
{
|
||||
browserModel->RescanStamps();
|
||||
|
@ -17,6 +17,7 @@ public:
|
||||
std::unique_ptr<SaveFile> TakeSave();
|
||||
void RemoveSelected();
|
||||
void removeSelectedC();
|
||||
void RenameSelected();
|
||||
void ClearSelection();
|
||||
void Selected(ByteString stampID, bool selected);
|
||||
void RescanStamps();
|
||||
|
@ -48,7 +48,13 @@ LocalBrowserView::LocalBrowserView():
|
||||
removeSelected = new ui::Button(ui::Point(((WINDOWW-100)/2), WINDOWH-18), ui::Point(100, 16), "Delete");
|
||||
removeSelected->Visible = false;
|
||||
removeSelected->SetActionCallback({ [this] { c->RemoveSelected(); } });
|
||||
|
||||
renameSelected = new ui::Button(ui::Point(((WINDOWW - 100) / 2 + 52), WINDOWH - 18), ui::Point(100, 16), "Rename");
|
||||
renameSelected->Visible = false;
|
||||
renameSelected->SetActionCallback({ [this] { c->RenameSelected(); } });
|
||||
|
||||
AddComponent(removeSelected);
|
||||
AddComponent(renameSelected);
|
||||
}
|
||||
|
||||
void LocalBrowserView::textChanged()
|
||||
@ -179,16 +185,18 @@ void LocalBrowserView::NotifySelectedChanged(LocalBrowserModel * sender)
|
||||
}
|
||||
}
|
||||
|
||||
if (selected.size())
|
||||
removeSelected->Visible = selected.size() > 0;
|
||||
renameSelected->Visible = selected.size() == 1;
|
||||
removeSelected->Position.X = (WINDOWW - 100) / 2;
|
||||
if (renameSelected->Visible)
|
||||
{
|
||||
removeSelected->Visible = true;
|
||||
pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = false;
|
||||
}
|
||||
else if (removeSelected->Visible)
|
||||
{
|
||||
removeSelected->Visible = false;
|
||||
pageLabel->Visible = pageCountLabel->Visible = pageTextbox->Visible = true;
|
||||
removeSelected->Position.X -= 52;
|
||||
}
|
||||
|
||||
auto showPagination = !removeSelected->Visible;
|
||||
pageLabel->Visible = showPagination;
|
||||
pageCountLabel->Visible = showPagination;
|
||||
pageTextbox->Visible = showPagination;
|
||||
}
|
||||
|
||||
void LocalBrowserView::OnMouseWheel(int x, int y, int d)
|
||||
|
@ -22,6 +22,7 @@ class LocalBrowserView: public ui::Window {
|
||||
ui::Label * pageCountLabel;
|
||||
ui::Textbox * pageTextbox;
|
||||
ui::Button * removeSelected;
|
||||
ui::Button *renameSelected;
|
||||
|
||||
void textChanged();
|
||||
bool changed;
|
||||
|
Loading…
Reference in New Issue
Block a user