mirror of
https://github.com/elasota/Aerofoil.git
synced 2025-09-23 14:53:52 +00:00
Add delete option to File browser
This commit is contained in:
@@ -40,13 +40,15 @@ static const int kCancelButton = 2;
|
||||
static const int kFileList = 3;
|
||||
static const int kFileListScrollBar = 4;
|
||||
static const int kFileNameEditBox = 5;
|
||||
static const int kDeleteButton = 5;
|
||||
static const int kOpenDeleteButton = 5;
|
||||
static const int kSaveDeleteButton = 7;
|
||||
static const int kFileBrowserUIOpenDialogTemplateID = 2001;
|
||||
static const int kFileBrowserUISaveDialogTemplateID = 2002;
|
||||
static const int kFileBrowserUIOverwriteDialogTemplateID = 2003;
|
||||
static const int kFileBrowserUIBadNameDialogTemplateID = 2004;
|
||||
static const int kFileBrowserUISaveDialogUnobstructiveTemplateID = 2007;
|
||||
static const int kFileBrowserUIDeleteDialogTemplateID = 2008;
|
||||
static const int kFileBrowserUISaveDialogWithDeleteButtonTemplateID = 2009;
|
||||
|
||||
|
||||
static const int kOverwriteNoButton = 1;
|
||||
@@ -57,7 +59,7 @@ namespace PortabilityLayer
|
||||
class FileBrowserUIImpl
|
||||
{
|
||||
public:
|
||||
explicit FileBrowserUIImpl(const FileBrowserUI_DetailsCallbackAPI &callbackAPI);
|
||||
FileBrowserUIImpl(VirtualDirectory_t dir, const FileBrowserUI_DetailsCallbackAPI &callbackAPI);
|
||||
~FileBrowserUIImpl();
|
||||
|
||||
static void PubScrollBarCallback(void *captureContext, Widget *control, int part);
|
||||
@@ -111,6 +113,8 @@ namespace PortabilityLayer
|
||||
uint32_t m_doubleClickTime;
|
||||
bool m_haveFirstClick;
|
||||
|
||||
VirtualDirectory_t m_dir;
|
||||
|
||||
const FileBrowserUI_DetailsCallbackAPI m_api;
|
||||
};
|
||||
}
|
||||
@@ -128,7 +132,7 @@ static int16_t FileBrowserUIImpl_PopUpAlertUIFilter(void *context, Dialog *dialo
|
||||
|
||||
namespace PortabilityLayer
|
||||
{
|
||||
FileBrowserUIImpl::FileBrowserUIImpl(const FileBrowserUI_DetailsCallbackAPI &callbackAPI)
|
||||
FileBrowserUIImpl::FileBrowserUIImpl(VirtualDirectory_t dir, const FileBrowserUI_DetailsCallbackAPI &callbackAPI)
|
||||
: m_offset(0)
|
||||
, m_surface(nullptr)
|
||||
, m_window(nullptr)
|
||||
@@ -142,6 +146,7 @@ namespace PortabilityLayer
|
||||
, m_doubleClickTime(0)
|
||||
, m_haveFirstClick(false)
|
||||
, m_api(callbackAPI)
|
||||
, m_dir(dir)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -439,8 +444,19 @@ namespace PortabilityLayer
|
||||
|
||||
dialog->GetItems()[kOkayButton - 1].GetWidget()->SetEnabled(selection >= 0);
|
||||
|
||||
bool isDeleteValid = (selection >= 0);
|
||||
|
||||
if (isDeleteValid)
|
||||
{
|
||||
const FileBrowserUIImpl::FileEntry &entry = (*m_entries)[selection];
|
||||
isDeleteValid = m_api.m_isDeleteValidCallback(m_dir, entry.m_nameStr.ToShortStr());
|
||||
}
|
||||
|
||||
if (gs_currentFileBrowserUIMode == FileBrowserUI::Mode_Open)
|
||||
dialog->GetItems()[kDeleteButton - 1].GetWidget()->SetEnabled(selection >= 0);
|
||||
dialog->GetItems()[kOpenDeleteButton - 1].GetWidget()->SetEnabled(isDeleteValid);
|
||||
else if (gs_currentFileBrowserUIMode == FileBrowserUI::Mode_SaveWithDelete)
|
||||
dialog->GetItems()[kSaveDeleteButton - 1].GetWidget()->SetEnabled(isDeleteValid);
|
||||
|
||||
|
||||
DrawFileList();
|
||||
}
|
||||
@@ -585,16 +601,22 @@ namespace PortabilityLayer
|
||||
int windowHeight = 272;
|
||||
if (mode == Mode_Open)
|
||||
dialogID = kFileBrowserUIOpenDialogTemplateID;
|
||||
else if (mode == Mode_Save)
|
||||
else if (mode == Mode_SaveWithDelete || mode == Mode_SaveNoDelete)
|
||||
{
|
||||
if (PLDrivers::GetSystemServices()->IsTextInputObstructive())
|
||||
{
|
||||
dialogID = kFileBrowserUISaveDialogUnobstructiveTemplateID;
|
||||
windowHeight = 208;
|
||||
isObstructive = true;
|
||||
mode = Mode_SaveNoDelete; // HACK HACK HACK
|
||||
}
|
||||
else
|
||||
dialogID = kFileBrowserUISaveDialogTemplateID;
|
||||
{
|
||||
if (mode == Mode_SaveWithDelete)
|
||||
dialogID = kFileBrowserUISaveDialogWithDeleteButtonTemplateID;
|
||||
else
|
||||
dialogID = kFileBrowserUISaveDialogTemplateID;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -602,7 +624,7 @@ namespace PortabilityLayer
|
||||
return false;
|
||||
}
|
||||
|
||||
FileBrowserUIImpl uiImpl(callbackAPI);
|
||||
FileBrowserUIImpl uiImpl(dirID, callbackAPI);
|
||||
|
||||
// Enumerate files
|
||||
IGpFileSystem *fs = PLDrivers::GetFileSystem();
|
||||
@@ -674,7 +696,7 @@ namespace PortabilityLayer
|
||||
const Rect scrollBarRect = dialog->GetItems()[kFileListScrollBar - 1].GetWidget()->GetRect();
|
||||
|
||||
EditboxWidget *editbox = nullptr;
|
||||
if (mode == Mode_Save)
|
||||
if (mode == Mode_SaveWithDelete || mode == Mode_SaveNoDelete)
|
||||
{
|
||||
editbox = static_cast<EditboxWidget*>(dialog->GetItems()[kFileNameEditBox - 1].GetWidget());
|
||||
editbox->SetCharacterFilter(&uiImpl, FileBrowserUIImpl::PubEditBoxCharFilter);
|
||||
@@ -725,7 +747,7 @@ namespace PortabilityLayer
|
||||
if (hit == kFileListScrollBar)
|
||||
uiImpl.SetScrollOffset(scrollBar->GetState());
|
||||
|
||||
if (hit == kOkayButton && mode == Mode_Save)
|
||||
if (hit == kOkayButton && (mode == Mode_SaveWithDelete || mode == Mode_SaveNoDelete))
|
||||
{
|
||||
IGpFileSystem *fs = PLDrivers::GetFileSystem();
|
||||
|
||||
@@ -759,7 +781,7 @@ namespace PortabilityLayer
|
||||
}
|
||||
}
|
||||
|
||||
if (mode == Mode_Open && hit == kDeleteButton)
|
||||
if ((mode == Mode_Open && hit == kOpenDeleteButton) || (mode == Mode_SaveWithDelete && hit == kSaveDeleteButton))
|
||||
{
|
||||
PLDrivers::GetSystemServices()->Beep();
|
||||
int16_t subHit = FileBrowserUIImpl::PopUpAlert(Rect::Create(0, 0, 135, 327), kFileBrowserUIDeleteDialogTemplateID, &substitutions);
|
||||
@@ -768,14 +790,18 @@ namespace PortabilityLayer
|
||||
{
|
||||
PLPasStr uiFileName = uiImpl.GetSelectedFileName();
|
||||
|
||||
bool deleted = false;
|
||||
if (composites)
|
||||
PortabilityLayer::FileManager::GetInstance()->DeleteCompositeFile(dirID, uiFileName);
|
||||
deleted = PortabilityLayer::FileManager::GetInstance()->DeleteCompositeFile(dirID, uiFileName);
|
||||
else
|
||||
PortabilityLayer::FileManager::GetInstance()->DeleteNonCompositeFile(dirID, uiFileName, extension);
|
||||
deleted = PortabilityLayer::FileManager::GetInstance()->DeleteNonCompositeFile(dirID, uiFileName, extension);
|
||||
|
||||
uiImpl.RemoveSelectedFile();
|
||||
dialog->GetItems()[kOkayButton - 1].GetWidget()->SetEnabled(false);
|
||||
dialog->GetItems()[kDeleteButton - 1].GetWidget()->SetEnabled(false);
|
||||
if (mode == Mode_Open)
|
||||
dialog->GetItems()[kOpenDeleteButton - 1].GetWidget()->SetEnabled(false);
|
||||
else if (mode == Mode_SaveWithDelete)
|
||||
dialog->GetItems()[kSaveDeleteButton - 1].GetWidget()->SetEnabled(false);
|
||||
}
|
||||
hit = -1;
|
||||
}
|
||||
@@ -793,7 +819,7 @@ namespace PortabilityLayer
|
||||
uiFileName = uiImpl.GetSelectedFileName();
|
||||
confirmed = true;
|
||||
}
|
||||
else if (mode == Mode_Save)
|
||||
else if (mode == Mode_SaveWithDelete || mode == Mode_SaveNoDelete)
|
||||
{
|
||||
uiFileName = editbox->GetString();
|
||||
confirmed = true;
|
||||
|
@@ -20,8 +20,9 @@ namespace PortabilityLayer
|
||||
void(*m_drawFileDetailsCallback)(DrawSurface *surface, const Point &basePoint, const Rect &constraintRect, void *fileDetails);
|
||||
|
||||
void *(*m_loadFileDetailsCallback)(VirtualDirectory_t dirID, const PLPasStr &filename);
|
||||
void(*m_freeFileDetailsCallback)(void *fileDetails);
|
||||
bool(*m_filterFileCallback)(VirtualDirectory_t dirID, const PLPasStr &filename);
|
||||
void (*m_freeFileDetailsCallback)(void *fileDetails);
|
||||
bool (*m_filterFileCallback)(VirtualDirectory_t dirID, const PLPasStr &filename);
|
||||
bool (*m_isDeleteValidCallback)(VirtualDirectory_t dirID, const PLPasStr &filename);
|
||||
};
|
||||
|
||||
class FileBrowserUI
|
||||
@@ -30,7 +31,8 @@ namespace PortabilityLayer
|
||||
|
||||
enum Mode
|
||||
{
|
||||
Mode_Save,
|
||||
Mode_SaveNoDelete,
|
||||
Mode_SaveWithDelete,
|
||||
Mode_Open,
|
||||
};
|
||||
|
||||
|
@@ -282,7 +282,11 @@ namespace PortabilityLayer
|
||||
if (!FileManagerTools::ConstructFilename(extFN, initialFileName, ""))
|
||||
return false;
|
||||
|
||||
return FileBrowserUI::Prompt(FileBrowserUI::Mode_Save, dirID, extension, path, outPathLength, pathCapacity, initialFileName, promptText, composites, detailsAPI);
|
||||
FileBrowserUI::Mode mode = FileBrowserUI::Mode_SaveNoDelete;
|
||||
if (!PLDrivers::GetSystemServices()->HasNativeFileManager())
|
||||
mode = FileBrowserUI::Mode_SaveWithDelete;
|
||||
|
||||
return FileBrowserUI::Prompt(mode, dirID, extension, path, outPathLength, pathCapacity, initialFileName, promptText, composites, detailsAPI);
|
||||
}
|
||||
|
||||
bool FileManagerImpl::PromptOpenFile(VirtualDirectory_t dirID, const char *extension, char *path, size_t &outPathLength, size_t pathCapacity, const PLPasStr &promptText, bool composites, const FileBrowserUI_DetailsCallbackAPI &detailsAPI)
|
||||
|
Reference in New Issue
Block a user