Skip to content

Commit

Permalink
GUI: Add editable path in file browser dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Sedictious authored and criezy committed Aug 21, 2018
1 parent 37c0342 commit 4188ba1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
11 changes: 9 additions & 2 deletions gui/browser.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions gui/browser.h
Expand Up @@ -29,7 +29,7 @@
namespace GUI { namespace GUI {


class ListWidget; class ListWidget;
class StaticTextWidget; class EditTextWidget;
class CheckboxWidget; class CheckboxWidget;
class CommandSender; class CommandSender;


Expand All @@ -54,7 +54,7 @@ class BrowserDialog : public Dialog {
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;
Expand Down
7 changes: 6 additions & 1 deletion gui/widgets/edittext.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions gui/widgets/edittext.h
Expand Up @@ -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:
Expand All @@ -43,6 +48,7 @@ class EditTextWidget : public EditableWidget {
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);


Expand Down

0 comments on commit 4188ba1

Please sign in to comment.