diff options
| author | Jonas Suhr Christensen <jsc@umbraculum.org> | 2013-05-15 18:14:01 +0200 | 
|---|---|---|
| committer | Jonas Suhr Christensen <jsc@umbraculum.org> | 2013-05-15 18:14:01 +0200 | 
| commit | 976ce209938be1bfc088d5f6cdd523a4089e1dd0 (patch) | |
| tree | 8ef16aeefd3a4d9a675dc140c0daa84bdf8bb9b0 | |
| parent | b61c55a43c21a95234d79f6afd9a64964f5fffec (diff) | |
Make it possible to type a path and have browser switch accordingly.
| -rw-r--r-- | plugingui/directory.cc | 2 | ||||
| -rw-r--r-- | plugingui/filebrowser.cc | 23 | ||||
| -rw-r--r-- | plugingui/listbox.cc | 5 | ||||
| -rw-r--r-- | plugingui/listbox.h | 1 | ||||
| -rw-r--r-- | plugingui/listboxbasic.cc | 5 | ||||
| -rw-r--r-- | plugingui/listboxbasic.h | 2 | 
6 files changed, 35 insertions, 3 deletions
| diff --git a/plugingui/directory.cc b/plugingui/directory.cc index 1069856..9053f8d 100644 --- a/plugingui/directory.cc +++ b/plugingui/directory.cc @@ -61,7 +61,7 @@ Directory::~Directory()  void Directory::setPath(std::string path)  {    DEBUG(directory, "Setting path to '%s'\n", path.c_str()); -  this->_path = path; +  this->_path = cleanPath(path);    refresh();  } diff --git a/plugingui/filebrowser.cc b/plugingui/filebrowser.cc index 6eaca8a..3c8b89d 100644 --- a/plugingui/filebrowser.cc +++ b/plugingui/filebrowser.cc @@ -68,7 +68,6 @@ static void changeDir(void *ptr)    struct GUI::FileBrowser::private_data *prv =      (struct GUI::FileBrowser::private_data *) ptr; -      GUI::ListBox *lb = prv->listbox;    GUI::LineEdit *le = prv->lineedit;    std::string value = lb->selectedValue();  @@ -87,6 +86,12 @@ static void changeDir(void *ptr)    }  #endif +  if(value.empty() && !dir->isDir()) { +    DEBUG(filebrowser, "Selecting file '%s'\n", dir->path().c_str()); +    if(prv->filesel_handler) prv->filesel_handler(prv->ptr, dir->path().c_str()); +    return; +  } +    if(!value.empty() && dir->fileExists(value)) {      std::string file = dir->path() + "/" + value;      DEBUG(filebrowser, "Selecting file '%s'\n", file.c_str()); @@ -137,6 +142,19 @@ static void changeDir(void *ptr)    lb->addItems(items);  } +static void handleKeyEvent(void *ptr) { +  struct GUI::FileBrowser::private_data *prv = +    (struct GUI::FileBrowser::private_data *) ptr; + +  GUI::ListBox *lb = prv->listbox; +  lb->clearSelectedValue();   +  GUI::LineEdit *le = prv->lineedit; + +  printf("AAA: %s\n", le->text().c_str()); +  prv->dir->setPath(le->text()); +  changeDir(ptr); +} +  GUI::FileBrowser::FileBrowser(GUI::Widget *parent)    : GUI::Widget(parent),      lbl_path(this), lineedit(this), listbox(this), btn_sel(this), btn_esc(this), @@ -152,8 +170,9 @@ GUI::FileBrowser::FileBrowser(GUI::Widget *parent)    lbl_path.setText("Path:"); -  lineedit.setReadOnly(true); +//  lineedit.setReadOnly(true);    prv->lineedit = &lineedit; +  prv->lineedit->registerEnterPressedHandler(handleKeyEvent, prv);    prv->listbox = &listbox;    listbox.registerSelectHandler(changeDir, prv); diff --git a/plugingui/listbox.cc b/plugingui/listbox.cc index 3647753..ed873b2 100644 --- a/plugingui/listbox.cc +++ b/plugingui/listbox.cc @@ -82,6 +82,11 @@ std::string GUI::ListBox::selectedValue()    return basic->selectedValue();  } +void GUI::ListBox::clearSelectedValue()  +{ +  basic->clearSelectedValue(); +} +  void GUI::ListBox::registerClickHandler(void (*handler)(void *), void *ptr)  {    basic->registerClickHandler(handler, ptr); diff --git a/plugingui/listbox.h b/plugingui/listbox.h index 4a7af20..c8677e7 100644 --- a/plugingui/listbox.h +++ b/plugingui/listbox.h @@ -48,6 +48,7 @@ public:    bool selectItem(int index);    std::string selectedName();    std::string selectedValue(); +  void clearSelectedValue();    void registerSelectHandler(void (*handler)(void *), void *ptr);    void registerClickHandler(void (*handler)(void *), void *ptr); diff --git a/plugingui/listboxbasic.cc b/plugingui/listboxbasic.cc index f0699c7..df7877d 100644 --- a/plugingui/listboxbasic.cc +++ b/plugingui/listboxbasic.cc @@ -144,6 +144,11 @@ std::string GUI::ListBoxBasic::selectedValue()    return items[selected].value;  } +void GUI::ListBoxBasic::clearSelectedValue() +{ +  setSelection(-1); +} +  void GUI::ListBoxBasic::registerClickHandler(void (*handler)(void *), void *ptr)  {    this->clk_handler = handler; diff --git a/plugingui/listboxbasic.h b/plugingui/listboxbasic.h index ebb46b0..deb4a67 100644 --- a/plugingui/listboxbasic.h +++ b/plugingui/listboxbasic.h @@ -59,6 +59,8 @@ public:    std::string selectedName();    std::string selectedValue(); +  void clearSelectedValue(); +    void registerSelectHandler(void (*handler)(void *), void *ptr);    void registerClickHandler(void (*handler)(void *), void *ptr);    void registerValueChangeHandler(void (*handler)(void *), void *ptr); | 
