mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-09-02 12:32:40 +02:00
local save deletion and renaming with the right click context menu
This commit is contained in:
@@ -12,6 +12,8 @@
|
|||||||
#include "Style.h"
|
#include "Style.h"
|
||||||
#include "tasks/Task.h"
|
#include "tasks/Task.h"
|
||||||
#include "simulation/SaveRenderer.h"
|
#include "simulation/SaveRenderer.h"
|
||||||
|
#include "dialogues/TextPrompt.h"
|
||||||
|
#include "dialogues/ErrorMessage.h"
|
||||||
|
|
||||||
class Thumbnail;
|
class Thumbnail;
|
||||||
|
|
||||||
@@ -25,6 +27,14 @@ public:
|
|||||||
{
|
{
|
||||||
a->SelectSave(sender->GetSaveFile());
|
a->SelectSave(sender->GetSaveFile());
|
||||||
}
|
}
|
||||||
|
virtual void AltActionCallback(ui::SaveButton * sender)
|
||||||
|
{
|
||||||
|
a->RenameSave(sender->GetSaveFile());
|
||||||
|
}
|
||||||
|
virtual void AltActionCallback2(ui::SaveButton * sender)
|
||||||
|
{
|
||||||
|
a->DeleteSave(sender->GetSaveFile());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
//Currently, reading is done on another thread, we can't render outside the main thread due to some bullshit with OpenGL
|
//Currently, reading is done on another thread, we can't render outside the main thread due to some bullshit with OpenGL
|
||||||
@@ -164,15 +174,30 @@ void FileBrowserActivity::SelectSave(SaveFile * file)
|
|||||||
Exit();
|
Exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileBrowserActivity::DeleteSave(SaveFile * file)
|
||||||
|
{
|
||||||
|
remove(file->GetName().c_str());
|
||||||
|
loadDirectory(directory, "");
|
||||||
|
}
|
||||||
|
|
||||||
|
void FileBrowserActivity::RenameSave(SaveFile * file)
|
||||||
|
{
|
||||||
|
std::string newName = TextPrompt::Blocking("Rename", "Change save name", file->GetDisplayName(), "", 0);
|
||||||
|
newName = directory + PATH_SEP + newName + ".cps";
|
||||||
|
int ret = rename(file->GetName().c_str(), newName.c_str());
|
||||||
|
if (ret)
|
||||||
|
ErrorMessage::Blocking("Error", "Could not rename file");
|
||||||
|
else
|
||||||
|
loadDirectory(directory, "");
|
||||||
|
}
|
||||||
|
|
||||||
void FileBrowserActivity::loadDirectory(std::string directory, std::string search)
|
void FileBrowserActivity::loadDirectory(std::string directory, std::string search)
|
||||||
{
|
{
|
||||||
for(int i = 0; i < components.size(); i++)
|
for(int i = 0; i < components.size(); i++)
|
||||||
{
|
{
|
||||||
RemoveComponent(components[i]);
|
RemoveComponent(components[i]);
|
||||||
itemList->RemoveChild(components[i]);
|
itemList->RemoveChild(components[i]);
|
||||||
delete components[i];
|
|
||||||
}
|
}
|
||||||
components.clear();
|
|
||||||
|
|
||||||
for(std::vector<ui::Component*>::iterator iter = componentsQueue.begin(), end = componentsQueue.end(); iter != end; ++iter)
|
for(std::vector<ui::Component*>::iterator iter = componentsQueue.begin(), end = componentsQueue.end(); iter != end; ++iter)
|
||||||
{
|
{
|
||||||
@@ -208,6 +233,11 @@ void FileBrowserActivity::NotifyDone(Task * task)
|
|||||||
progressBar->Visible = false;
|
progressBar->Visible = false;
|
||||||
infoText->Visible = true;
|
infoText->Visible = true;
|
||||||
}
|
}
|
||||||
|
for(int i = 0; i < components.size(); i++)
|
||||||
|
{
|
||||||
|
delete components[i];
|
||||||
|
}
|
||||||
|
components.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileBrowserActivity::OnMouseDown(int x, int y, unsigned button)
|
void FileBrowserActivity::OnMouseDown(int x, int y, unsigned button)
|
||||||
@@ -253,6 +283,7 @@ void FileBrowserActivity::OnTick(float dt)
|
|||||||
),
|
),
|
||||||
ui::Point(buttonWidth, buttonHeight),
|
ui::Point(buttonWidth, buttonHeight),
|
||||||
saveFile);
|
saveFile);
|
||||||
|
saveButton->AddContextMenu(1);
|
||||||
saveButton->Tick(dt);
|
saveButton->Tick(dt);
|
||||||
saveButton->SetActionCallback(new SaveSelectedAction(this));
|
saveButton->SetActionCallback(new SaveSelectedAction(this));
|
||||||
progressBar->SetStatus("Rendering thumbnails");
|
progressBar->SetStatus("Rendering thumbnails");
|
||||||
|
@@ -52,6 +52,8 @@ public:
|
|||||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||||
void loadDirectory(std::string directory, std::string search);
|
void loadDirectory(std::string directory, std::string search);
|
||||||
void SelectSave(SaveFile * file);
|
void SelectSave(SaveFile * file);
|
||||||
|
void DeleteSave(SaveFile * file);
|
||||||
|
void RenameSave(SaveFile * file);
|
||||||
void DoSearch(std::string search);
|
void DoSearch(std::string search);
|
||||||
virtual ~FileBrowserActivity();
|
virtual ~FileBrowserActivity();
|
||||||
|
|
||||||
|
@@ -28,12 +28,6 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
|||||||
isMouseInsideHistory(false),
|
isMouseInsideHistory(false),
|
||||||
showVotes(false)
|
showVotes(false)
|
||||||
{
|
{
|
||||||
menu = new ContextMenu(this);
|
|
||||||
menu->AddItem(ContextMenuItem("Open", 0, true));
|
|
||||||
menu->AddItem(ContextMenuItem("Select", 1, true));
|
|
||||||
menu->AddItem(ContextMenuItem("View History", 2, true));
|
|
||||||
menu->AddItem(ContextMenuItem("More by this user", 3, true));
|
|
||||||
|
|
||||||
if(save)
|
if(save)
|
||||||
{
|
{
|
||||||
name = save->name;
|
name = save->name;
|
||||||
@@ -303,15 +297,34 @@ void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
|
|||||||
if(isButtonDown)
|
if(isButtonDown)
|
||||||
{
|
{
|
||||||
isButtonDown = false;
|
isButtonDown = false;
|
||||||
if(isMouseInsideAuthor)
|
if(isMouseInsideHistory)
|
||||||
DoAuthorAction();
|
DoAltAction();
|
||||||
else if(isMouseInsideHistory)
|
else if(isMouseInsideAuthor)
|
||||||
DoHistoryAction();
|
DoAltAction2();
|
||||||
else
|
else
|
||||||
DoAction();
|
DoAction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SaveButton::AddContextMenu(int menuType)
|
||||||
|
{
|
||||||
|
if (menuType == 0) //Save browser
|
||||||
|
{
|
||||||
|
menu = new ContextMenu(this);
|
||||||
|
menu->AddItem(ContextMenuItem("Open", 0, true));
|
||||||
|
menu->AddItem(ContextMenuItem("Select", 1, true));
|
||||||
|
menu->AddItem(ContextMenuItem("View History", 2, true));
|
||||||
|
menu->AddItem(ContextMenuItem("More by this user", 3, true));
|
||||||
|
}
|
||||||
|
else if (menuType == 1) //Local save browser
|
||||||
|
{
|
||||||
|
menu = new ContextMenu(this);
|
||||||
|
menu->AddItem(ContextMenuItem("Open", 0, true));
|
||||||
|
menu->AddItem(ContextMenuItem("Rename", 2, true));
|
||||||
|
menu->AddItem(ContextMenuItem("Delete", 3, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SaveButton::OnContextMenuAction(int item)
|
void SaveButton::OnContextMenuAction(int item)
|
||||||
{
|
{
|
||||||
switch(item)
|
switch(item)
|
||||||
@@ -324,10 +337,10 @@ void SaveButton::OnContextMenuAction(int item)
|
|||||||
DoSelection();
|
DoSelection();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
DoHistoryAction();
|
DoAltAction();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
DoAuthorAction();
|
DoAltAction2();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -376,16 +389,16 @@ void SaveButton::OnMouseLeave(int x, int y)
|
|||||||
isMouseInsideHistory = false;
|
isMouseInsideHistory = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::DoHistoryAction()
|
void SaveButton::DoAltAction()
|
||||||
{
|
{
|
||||||
if(actionCallback)
|
if(actionCallback)
|
||||||
actionCallback->HistoryActionCallback(this);
|
actionCallback->AltActionCallback(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::DoAuthorAction()
|
void SaveButton::DoAltAction2()
|
||||||
{
|
{
|
||||||
if(actionCallback)
|
if(actionCallback)
|
||||||
actionCallback->AuthorActionCallback(this);
|
actionCallback->AltActionCallback2(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SaveButton::DoAction()
|
void SaveButton::DoAction()
|
||||||
|
@@ -18,8 +18,8 @@ class SaveButtonAction
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void ActionCallback(ui::SaveButton * sender) {}
|
virtual void ActionCallback(ui::SaveButton * sender) {}
|
||||||
virtual void AuthorActionCallback(ui::SaveButton * sender) {}
|
virtual void AltActionCallback(ui::SaveButton * sender) {}
|
||||||
virtual void HistoryActionCallback(ui::SaveButton * sender) {}
|
virtual void AltActionCallback2(ui::SaveButton * sender) {}
|
||||||
virtual void SelectedCallback(ui::SaveButton * sender) {}
|
virtual void SelectedCallback(ui::SaveButton * sender) {}
|
||||||
virtual ~SaveButtonAction() {}
|
virtual ~SaveButtonAction() {}
|
||||||
};
|
};
|
||||||
@@ -53,6 +53,7 @@ public:
|
|||||||
|
|
||||||
virtual void OnMouseMovedInside(int x, int y, int dx, int dy);
|
virtual void OnMouseMovedInside(int x, int y, int dx, int dy);
|
||||||
|
|
||||||
|
void AddContextMenu(int menuType);
|
||||||
virtual void OnContextMenuAction(int item);
|
virtual void OnContextMenuAction(int item);
|
||||||
|
|
||||||
virtual void Draw(const Point& screenPos);
|
virtual void Draw(const Point& screenPos);
|
||||||
@@ -70,8 +71,8 @@ public:
|
|||||||
SaveFile * GetSaveFile() { return file; }
|
SaveFile * GetSaveFile() { return file; }
|
||||||
inline bool GetState() { return state; }
|
inline bool GetState() { return state; }
|
||||||
virtual void DoAction();
|
virtual void DoAction();
|
||||||
virtual void DoAuthorAction();
|
virtual void DoAltAction();
|
||||||
virtual void DoHistoryAction();
|
virtual void DoAltAction2();
|
||||||
virtual void DoSelection();
|
virtual void DoSelection();
|
||||||
void SetActionCallback(SaveButtonAction * action);
|
void SetActionCallback(SaveButtonAction * action);
|
||||||
protected:
|
protected:
|
||||||
|
@@ -615,16 +615,16 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
|||||||
{
|
{
|
||||||
v->c->Selected(sender->GetSave()->GetID(), sender->GetSelected());
|
v->c->Selected(sender->GetSave()->GetID(), sender->GetSelected());
|
||||||
}
|
}
|
||||||
virtual void AuthorActionCallback(ui::SaveButton * sender)
|
virtual void AltActionCallback(ui::SaveButton * sender)
|
||||||
{
|
|
||||||
v->Search("user:"+sender->GetSave()->GetUserName());
|
|
||||||
}
|
|
||||||
virtual void HistoryActionCallback(ui::SaveButton * sender)
|
|
||||||
{
|
{
|
||||||
stringstream search;
|
stringstream search;
|
||||||
search << "history:" << sender->GetSave()->GetID();
|
search << "history:" << sender->GetSave()->GetID();
|
||||||
v->Search(search.str());
|
v->Search(search.str());
|
||||||
}
|
}
|
||||||
|
virtual void AltActionCallback2(ui::SaveButton * sender)
|
||||||
|
{
|
||||||
|
v->Search("user:"+sender->GetSave()->GetUserName());
|
||||||
|
}
|
||||||
};
|
};
|
||||||
for(i = 0; i < saves.size(); i++)
|
for(i = 0; i < saves.size(); i++)
|
||||||
{
|
{
|
||||||
@@ -643,6 +643,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
|||||||
),
|
),
|
||||||
ui::Point(buttonWidth, buttonHeight),
|
ui::Point(buttonWidth, buttonHeight),
|
||||||
saves[i]);
|
saves[i]);
|
||||||
|
saveButton->AddContextMenu(0);
|
||||||
saveButton->SetActionCallback(new SaveOpenAction(this));
|
saveButton->SetActionCallback(new SaveOpenAction(this));
|
||||||
if(Client::Ref().GetAuthUser().ID)
|
if(Client::Ref().GetAuthUser().ID)
|
||||||
saveButton->SetSelectable(true);
|
saveButton->SetSelectable(true);
|
||||||
|
Reference in New Issue
Block a user