|
|
@@ -26,6 +26,7 @@
|
|
|
#include "Exception.h"
|
|
|
#include "File.h"
|
|
|
#include "FileSelector.h"
|
|
|
+#include "InputEvents.h"
|
|
|
#include "LineEdit.h"
|
|
|
#include "ListView.h"
|
|
|
#include "Text.h"
|
|
|
@@ -111,6 +112,7 @@ FileSelector::FileSelector(UI* ui) :
|
|
|
subscribeToEvent(mPathEdit, EVENT_TEXTFINISHED, EVENT_HANDLER(FileSelector, handlePathChanged));
|
|
|
subscribeToEvent(mFileList, EVENT_ITEMSELECTED, EVENT_HANDLER(FileSelector, handleFileSelected));
|
|
|
subscribeToEvent(mFileList, EVENT_ITEMDOUBLECLICKED, EVENT_HANDLER(FileSelector, handleFileDoubleClicked));
|
|
|
+ subscribeToEvent(mFileList, EVENT_LISTVIEWKEY, EVENT_HANDLER(FileSelector, handleFileListKey));
|
|
|
subscribeToEvent(mOKButton, EVENT_PRESSED, EVENT_HANDLER(FileSelector, handleOKPressed));
|
|
|
subscribeToEvent(mCancelButton, EVENT_PRESSED, EVENT_HANDLER(FileSelector, handleCancelPressed));
|
|
|
|
|
|
@@ -366,10 +368,44 @@ void FileSelector::refreshFiles()
|
|
|
mLastUsedFilter = getFilter();
|
|
|
}
|
|
|
|
|
|
+bool FileSelector::enterFile()
|
|
|
+{
|
|
|
+ unsigned index = mFileList->getSelection();
|
|
|
+ if (index >= mFileEntries.size())
|
|
|
+ return false;
|
|
|
+
|
|
|
+ if (mFileEntries[index].mDirectory)
|
|
|
+ {
|
|
|
+ // If a directory doubleclicked, enter it. Recognize . and .. as a special case
|
|
|
+ const std::string& newPath = mFileEntries[index].mName;
|
|
|
+ if ((newPath != ".") && (newPath != ".."))
|
|
|
+ setPath(mPath + newPath);
|
|
|
+ else if (newPath == "..")
|
|
|
+ {
|
|
|
+ unsigned pos = unfixPath(mPath).rfind('/');
|
|
|
+ if (pos != std::string::npos)
|
|
|
+ setPath(mPath.substr(0, pos));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ // Doubleclicking a file is the same as pressing OK
|
|
|
+ using namespace FileSelected;
|
|
|
+
|
|
|
+ VariantMap eventData;
|
|
|
+ eventData[P_FILENAME] = mPath + mFileEntries[index].mName;
|
|
|
+ eventData[P_OK] = true;
|
|
|
+ sendEvent(EVENT_FILESELECTED, eventData);
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
void FileSelector::handleFilterChanged(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
if (mIgnoreEvents)
|
|
|
return;
|
|
|
+
|
|
|
if (getFilter() != mLastUsedFilter)
|
|
|
refreshFiles();
|
|
|
}
|
|
|
@@ -378,6 +414,7 @@ void FileSelector::handlePathChanged(StringHash eventType, VariantMap& eventData
|
|
|
{
|
|
|
if (mIgnoreEvents)
|
|
|
return;
|
|
|
+
|
|
|
// Attempt to set path. Restores old if does not exist
|
|
|
setPath(mPathEdit->getText());
|
|
|
}
|
|
|
@@ -386,6 +423,7 @@ void FileSelector::handleFileSelected(StringHash eventType, VariantMap& eventDat
|
|
|
{
|
|
|
if (mIgnoreEvents)
|
|
|
return;
|
|
|
+
|
|
|
unsigned index = mFileList->getSelection();
|
|
|
if (index >= mFileEntries.size())
|
|
|
return;
|
|
|
@@ -399,37 +437,30 @@ void FileSelector::handleFileDoubleClicked(StringHash eventType, VariantMap& eve
|
|
|
if (mIgnoreEvents)
|
|
|
return;
|
|
|
|
|
|
- unsigned index = mFileList->getSelection();
|
|
|
- if (index >= mFileEntries.size())
|
|
|
+ enterFile();
|
|
|
+}
|
|
|
+
|
|
|
+void FileSelector::handleFileListKey(StringHash eventType, VariantMap& eventData)
|
|
|
+{
|
|
|
+ if (mIgnoreEvents)
|
|
|
return;
|
|
|
|
|
|
- if (mFileEntries[index].mDirectory)
|
|
|
- {
|
|
|
- // If a directory doubleclicked, enter it. Recognize . and .. as a special case
|
|
|
- const std::string& newPath = mFileEntries[index].mName;
|
|
|
- if ((newPath != ".") && (newPath != ".."))
|
|
|
- setPath(mPath + newPath);
|
|
|
- else if (newPath == "..")
|
|
|
- {
|
|
|
- unsigned pos = unfixPath(mPath).rfind('/');
|
|
|
- if (pos != std::string::npos)
|
|
|
- setPath(mPath.substr(0, pos));
|
|
|
- }
|
|
|
- }
|
|
|
- else
|
|
|
+ using namespace ListViewKey;
|
|
|
+
|
|
|
+ if (eventData[P_KEY].getInt() == KEY_RETURN)
|
|
|
{
|
|
|
- // Doubleclicking a file is the same as pressing OK
|
|
|
- using namespace FileSelected;
|
|
|
-
|
|
|
- VariantMap eventData;
|
|
|
- eventData[P_FILENAME] = mPath + mFileEntries[index].mName;
|
|
|
- eventData[P_OK] = true;
|
|
|
- sendEvent(EVENT_FILESELECTED, eventData);
|
|
|
+ bool entered = enterFile();
|
|
|
+ // When a key is used to enter a directory, select the first file if no selection
|
|
|
+ if ((entered) && (!mFileList->getSelectedItem()))
|
|
|
+ mFileList->setSelection(0);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void FileSelector::handleOKPressed(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
+ if (mIgnoreEvents)
|
|
|
+ return;
|
|
|
+
|
|
|
const std::string& fileName = getFileName();
|
|
|
if (!fileName.empty())
|
|
|
{
|
|
|
@@ -444,6 +475,9 @@ void FileSelector::handleOKPressed(StringHash eventType, VariantMap& eventData)
|
|
|
|
|
|
void FileSelector::handleCancelPressed(StringHash eventType, VariantMap& eventData)
|
|
|
{
|
|
|
+ if (mIgnoreEvents)
|
|
|
+ return;
|
|
|
+
|
|
|
using namespace FileSelected;
|
|
|
|
|
|
VariantMap newEventData;
|