diff --git a/uppsrc/CtrlLib/CtrlUtil.cpp b/uppsrc/CtrlLib/CtrlUtil.cpp index 1bd06197b..5ea25ee33 100644 --- a/uppsrc/CtrlLib/CtrlUtil.cpp +++ b/uppsrc/CtrlLib/CtrlUtil.cpp @@ -289,4 +289,28 @@ void MemoryProfileInfo() { PromptOK("[C " + DeQtfLf(text)); }; +FileSelButton::FileSelButton(MODE mode, const char *title) +: title(title), mode(mode) +{ + button.NoWantFocus(); + button.SetImage(CtrlImg::right_arrow()); + button <<= THISBACK(OnAction); +} + +void FileSelButton::OnAction() +{ + Ctrl *owner = button.GetParent(); + ASSERT(owner); + String old = ~*owner; + if(mode == MODE_DIR) + ActiveDir(old); + else + Set(old); + if(mode == MODE_OPEN ? ExecuteOpen(title) : mode == MODE_SAVE ? ExecuteSaveAs(title) : ExecuteSelectDir(title)) + { + *owner <<= Get(); + owner->Action(); + } +} + END_UPP_NAMESPACE diff --git a/uppsrc/CtrlLib/CtrlUtil.h b/uppsrc/CtrlLib/CtrlUtil.h index 0c4632404..8cfe54b9a 100644 --- a/uppsrc/CtrlLib/CtrlUtil.h +++ b/uppsrc/CtrlLib/CtrlUtil.h @@ -453,6 +453,31 @@ public: void Set(const ValueMap& m); }; + +class FileSelButton : public FileSel +{ +public: + typedef FileSelButton CLASSNAME; + enum MODE { MODE_OPEN, MODE_SAVE, MODE_DIR }; + FileSelButton(MODE mode = MODE_OPEN, const char *title = NULL); + + void Attach(Ctrl& parent) { parent.AddFrame(button); } + void Title(String t) { title = t; } + String GetTitle() const { return title; } + +private: + void OnAction(); + +private: + FrameRight