local save deletion and renaming with the right click context menu
This commit is contained in:
parent
659c3677aa
commit
323dae959a
@ -12,6 +12,8 @@
|
||||
#include "Style.h"
|
||||
#include "tasks/Task.h"
|
||||
#include "simulation/SaveRenderer.h"
|
||||
#include "dialogues/TextPrompt.h"
|
||||
#include "dialogues/ErrorMessage.h"
|
||||
|
||||
class Thumbnail;
|
||||
|
||||
@ -25,6 +27,14 @@ public:
|
||||
{
|
||||
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
|
||||
@ -164,15 +174,30 @@ void FileBrowserActivity::SelectSave(SaveFile * file)
|
||||
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)
|
||||
{
|
||||
for(int i = 0; i < components.size(); i++)
|
||||
{
|
||||
RemoveComponent(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)
|
||||
{
|
||||
@ -208,6 +233,11 @@ void FileBrowserActivity::NotifyDone(Task * task)
|
||||
progressBar->Visible = false;
|
||||
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)
|
||||
@ -253,6 +283,7 @@ void FileBrowserActivity::OnTick(float dt)
|
||||
),
|
||||
ui::Point(buttonWidth, buttonHeight),
|
||||
saveFile);
|
||||
saveButton->AddContextMenu(1);
|
||||
saveButton->Tick(dt);
|
||||
saveButton->SetActionCallback(new SaveSelectedAction(this));
|
||||
progressBar->SetStatus("Rendering thumbnails");
|
||||
|
@ -52,6 +52,8 @@ public:
|
||||
virtual void OnMouseDown(int x, int y, unsigned button);
|
||||
void loadDirectory(std::string directory, std::string search);
|
||||
void SelectSave(SaveFile * file);
|
||||
void DeleteSave(SaveFile * file);
|
||||
void RenameSave(SaveFile * file);
|
||||
void DoSearch(std::string search);
|
||||
virtual ~FileBrowserActivity();
|
||||
|
||||
|
@ -28,12 +28,6 @@ SaveButton::SaveButton(Point position, Point size, SaveInfo * save):
|
||||
isMouseInsideHistory(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)
|
||||
{
|
||||
name = save->name;
|
||||
@ -303,15 +297,34 @@ void SaveButton::OnMouseUnclick(int x, int y, unsigned int button)
|
||||
if(isButtonDown)
|
||||
{
|
||||
isButtonDown = false;
|
||||
if(isMouseInsideAuthor)
|
||||
DoAuthorAction();
|
||||
else if(isMouseInsideHistory)
|
||||
DoHistoryAction();
|
||||
if(isMouseInsideHistory)
|
||||
DoAltAction();
|
||||
else if(isMouseInsideAuthor)
|
||||
DoAltAction2();
|
||||
else
|
||||
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)
|
||||
{
|
||||
switch(item)
|
||||
@ -324,10 +337,10 @@ void SaveButton::OnContextMenuAction(int item)
|
||||
DoSelection();
|
||||
break;
|
||||
case 2:
|
||||
DoHistoryAction();
|
||||
DoAltAction();
|
||||
break;
|
||||
case 3:
|
||||
DoAuthorAction();
|
||||
DoAltAction2();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -376,16 +389,16 @@ void SaveButton::OnMouseLeave(int x, int y)
|
||||
isMouseInsideHistory = false;
|
||||
}
|
||||
|
||||
void SaveButton::DoHistoryAction()
|
||||
void SaveButton::DoAltAction()
|
||||
{
|
||||
if(actionCallback)
|
||||
actionCallback->HistoryActionCallback(this);
|
||||
actionCallback->AltActionCallback(this);
|
||||
}
|
||||
|
||||
void SaveButton::DoAuthorAction()
|
||||
void SaveButton::DoAltAction2()
|
||||
{
|
||||
if(actionCallback)
|
||||
actionCallback->AuthorActionCallback(this);
|
||||
actionCallback->AltActionCallback2(this);
|
||||
}
|
||||
|
||||
void SaveButton::DoAction()
|
||||
|
@ -18,8 +18,8 @@ class SaveButtonAction
|
||||
{
|
||||
public:
|
||||
virtual void ActionCallback(ui::SaveButton * sender) {}
|
||||
virtual void AuthorActionCallback(ui::SaveButton * sender) {}
|
||||
virtual void HistoryActionCallback(ui::SaveButton * sender) {}
|
||||
virtual void AltActionCallback(ui::SaveButton * sender) {}
|
||||
virtual void AltActionCallback2(ui::SaveButton * sender) {}
|
||||
virtual void SelectedCallback(ui::SaveButton * sender) {}
|
||||
virtual ~SaveButtonAction() {}
|
||||
};
|
||||
@ -53,6 +53,7 @@ public:
|
||||
|
||||
virtual void OnMouseMovedInside(int x, int y, int dx, int dy);
|
||||
|
||||
void AddContextMenu(int menuType);
|
||||
virtual void OnContextMenuAction(int item);
|
||||
|
||||
virtual void Draw(const Point& screenPos);
|
||||
@ -70,8 +71,8 @@ public:
|
||||
SaveFile * GetSaveFile() { return file; }
|
||||
inline bool GetState() { return state; }
|
||||
virtual void DoAction();
|
||||
virtual void DoAuthorAction();
|
||||
virtual void DoHistoryAction();
|
||||
virtual void DoAltAction();
|
||||
virtual void DoAltAction2();
|
||||
virtual void DoSelection();
|
||||
void SetActionCallback(SaveButtonAction * action);
|
||||
protected:
|
||||
|
@ -615,16 +615,16 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
||||
{
|
||||
v->c->Selected(sender->GetSave()->GetID(), sender->GetSelected());
|
||||
}
|
||||
virtual void AuthorActionCallback(ui::SaveButton * sender)
|
||||
{
|
||||
v->Search("user:"+sender->GetSave()->GetUserName());
|
||||
}
|
||||
virtual void HistoryActionCallback(ui::SaveButton * sender)
|
||||
virtual void AltActionCallback(ui::SaveButton * sender)
|
||||
{
|
||||
stringstream search;
|
||||
search << "history:" << sender->GetSave()->GetID();
|
||||
v->Search(search.str());
|
||||
}
|
||||
virtual void AltActionCallback2(ui::SaveButton * sender)
|
||||
{
|
||||
v->Search("user:"+sender->GetSave()->GetUserName());
|
||||
}
|
||||
};
|
||||
for(i = 0; i < saves.size(); i++)
|
||||
{
|
||||
@ -643,6 +643,7 @@ void SearchView::NotifySaveListChanged(SearchModel * sender)
|
||||
),
|
||||
ui::Point(buttonWidth, buttonHeight),
|
||||
saves[i]);
|
||||
saveButton->AddContextMenu(0);
|
||||
saveButton->SetActionCallback(new SaveOpenAction(this));
|
||||
if(Client::Ref().GetAuthUser().ID)
|
||||
saveButton->SetSelectable(true);
|
||||
|
Reference in New Issue
Block a user