GUI: Add editable path in file browser dialog

This commit is contained in:
Chatziargyriou Eleftheria 2018-08-18 09:37:59 +03:00 committed by Thierry Crozat
parent 37c0342b32
commit 4188ba1252
4 changed files with 23 additions and 5 deletions

View file

@ -22,6 +22,7 @@
#include "gui/browser.h" #include "gui/browser.h"
#include "gui/gui-manager.h" #include "gui/gui-manager.h"
#include "gui/widgets/edittext.h"
#include "gui/widgets/list.h" #include "gui/widgets/list.h"
#include "common/config-manager.h" #include "common/config-manager.h"
@ -56,7 +57,7 @@ BrowserDialog::BrowserDialog(const char *title, bool dirBrowser)
new StaticTextWidget(this, "Browser.Headline", title); new StaticTextWidget(this, "Browser.Headline", title);
// Current path - TODO: handle long paths ? // Current path - TODO: handle long paths ?
_currentPath = new StaticTextWidget(this, "Browser.Path", "DUMMY"); _currentPath = new EditTextWidget(this, "Browser.Path", "DUMMY");
// Add file list // Add file list
_fileList = new ListWidget(this, "Browser.List"); _fileList = new ListWidget(this, "Browser.List");
@ -94,6 +95,12 @@ void BrowserDialog::open() {
void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) { void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data) {
switch (cmd) { switch (cmd) {
//Search for typed-in directory
case kExitTxtCmd:
_node = Common::FSNode(_currentPath->getEditString());
updateListing();
break;
//Search by text input
case kChooseCmd: case kChooseCmd:
if (_isDirBrowser) { if (_isDirBrowser) {
// If nothing is selected in the list widget, choose the current dir. // If nothing is selected in the list widget, choose the current dir.
@ -157,7 +164,7 @@ void BrowserDialog::handleCommand(CommandSender *sender, uint32 cmd, uint32 data
void BrowserDialog::updateListing() { void BrowserDialog::updateListing() {
// Update the path display // Update the path display
_currentPath->setLabel(_node.getPath()); _currentPath->setEditString(_node.getPath());
// We memorize the last visited path. // We memorize the last visited path.
ConfMan.set("browser_lastpath", _node.getPath()); ConfMan.set("browser_lastpath", _node.getPath());

View file

@ -29,7 +29,7 @@
namespace GUI { namespace GUI {
class ListWidget; class ListWidget;
class StaticTextWidget; class EditTextWidget;
class CheckboxWidget; class CheckboxWidget;
class CommandSender; class CommandSender;
@ -54,7 +54,7 @@ protected:
const void *_chooseRef; const void *_chooseRef;
#else #else
ListWidget *_fileList; ListWidget *_fileList;
StaticTextWidget *_currentPath; EditTextWidget *_currentPath;
Common::FSNode _node; Common::FSNode _node;
Common::FSList _nodeContent; Common::FSList _nodeContent;
bool _showHidden; bool _showHidden;

View file

@ -64,7 +64,6 @@ void EditTextWidget::reflowLayout() {
EditableWidget::reflowLayout(); EditableWidget::reflowLayout();
} }
void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) { void EditTextWidget::handleMouseDown(int x, int y, int button, int clickCount) {
if (!isEnabled()) if (!isEnabled())
return; return;
@ -133,13 +132,19 @@ void EditTextWidget::startEditMode() {
void EditTextWidget::endEditMode() { void EditTextWidget::endEditMode() {
releaseFocus(); releaseFocus();
sendCommand(kExitTxtCmd, 0);
sendCommand(_finishCmd, 0); sendCommand(_finishCmd, 0);
} }
void EditTextWidget::abortEditMode() { void EditTextWidget::abortEditMode() {
setEditString(_backupString); setEditString(_backupString);
sendCommand(_cmd, 0); sendCommand(_cmd, 0);
releaseFocus(); releaseFocus();
} }
Common::String EditTextWidget::getEditString() {
return _backupString;
}
} // End of namespace GUI } // End of namespace GUI

View file

@ -25,9 +25,14 @@
#include "gui/widgets/editable.h" #include "gui/widgets/editable.h"
#include "common/str.h" #include "common/str.h"
#include "gui/dialog.h"
namespace GUI { namespace GUI {
enum {
kExitTxtCmd = 'TXTE'
};
/* EditTextWidget */ /* EditTextWidget */
class EditTextWidget : public EditableWidget { class EditTextWidget : public EditableWidget {
protected: protected:
@ -43,6 +48,7 @@ public:
EditTextWidget(GuiObject *boss, const String &name, const String &text, const char *tooltp = 0, uint32 cmd = 0, uint32 finishCmd = 0); EditTextWidget(GuiObject *boss, const String &name, const String &text, const char *tooltp = 0, uint32 cmd = 0, uint32 finishCmd = 0);
void setEditString(const String &str); void setEditString(const String &str);
String getEditString();
virtual void handleMouseDown(int x, int y, int button, int clickCount); virtual void handleMouseDown(int x, int y, int button, int clickCount);