Files
PrimeWorldEditor/src/Editor/Undo/CMoveResourceCommand.h
Lioncache f577335087 Editor/Undo: Mark relevant variables as maybe unused
Prevents potential warnings on release mode.
2025-12-07 02:30:04 -05:00

50 lines
1.9 KiB
C++

#ifndef CMOVERESOURCECOMMAND_H
#define CMOVERESOURCECOMMAND_H
#include "IUndoCommand.h"
#include "Editor/CEditorApplication.h"
#include "Editor/ResourceBrowser/CResourceBrowser.h"
#include <Core/GameProject/CResourceEntry.h>
#include <QCoreApplication>
class CMoveResourceCommand : public IUndoCommand
{
CResourceEntry *mpEntry;
TString mOldDirPath;
TString mNewDirPath;
bool mOldDirAutoGenerated;
public:
CMoveResourceCommand(CResourceEntry *pEntry, CVirtualDirectory *pNewDir)
: IUndoCommand(QCoreApplication::translate("CMoveResourceCommand", "Move Resource"))
, mpEntry(pEntry)
, mOldDirPath(pEntry->DirectoryPath())
, mNewDirPath(pNewDir->FullPath())
, mOldDirAutoGenerated(pEntry->HasFlag(EResEntryFlag::AutoResDir))
{}
// note: for redo, it doesn't matter if the new directory was auto-generated, since the
// purpose of tracking that flag is to detect which resources have been auto-categorized.
// if this is being called, even if the new directory is auto-generated, it means the
// user is intentionally placing it here, so it should be treated as a custom directory
void undo() override { DoMove(mOldDirPath, mOldDirAutoGenerated); }
void redo() override { DoMove(mNewDirPath, false); }
bool AffectsCleanState() const override { return false; }
protected:
void DoMove(const TString& rkPath, bool IsAutoDir)
{
const TString ResName = mpEntry->CookedAssetPath(true).GetFileName();
gpEdApp->ResourceBrowser()->ResourceAboutToBeMoved(mpEntry, TO_QSTRING(rkPath + ResName));
CVirtualDirectory *pOldDir = mpEntry->Directory();
[[maybe_unused]] const bool Success = mpEntry->Move(rkPath, IsAutoDir);
ASSERT(Success); // todo better error handling
gpEdApp->ResourceBrowser()->ResourceMoved(mpEntry, pOldDir, mpEntry->Name());
}
};
#endif // CMOVERESOURCECOMMAND_H