diff --git a/include/nana/gui/filebox.hpp b/include/nana/gui/filebox.hpp index b9c5bc84..3df2abb0 100644 --- a/include/nana/gui/filebox.hpp +++ b/include/nana/gui/filebox.hpp @@ -28,10 +28,8 @@ namespace nana filebox(filebox&&) = delete; filebox& operator=(filebox&&) = delete; public: - using filters = std::vector>; using path_type = std::filesystem::path; - explicit filebox(bool is_open_mode); filebox(window owner, bool is_open_mode); filebox(const filebox&); ~filebox(); @@ -39,20 +37,35 @@ namespace nana filebox& operator=(const filebox&); /// Change owner window - void owner(window); - - /// Set a new title for the dialog - /// @param string a text for title - /// @return the old title. - ::std::string title( ::std::string new_title); - - /** @brief Suggest initial path used to locate a directory when the filebox starts. - * @param string initial_directory a path of initial directory - * @note the behavior of init_path is different between Win7 and Win2K/XP/Vista, but its behavior under Linux is conformed with Win7. + /** + * Changes the owner window for the filebox. When #show()/operator()# are invoked, the dialog of filebox will be created with the specified owner. + * @param handle A handle to a window which will be used for the owner of filebox */ - filebox& init_path(const ::std::string& initial_directory); + void owner(window handle); - filebox& init_file(const ::std::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file. + /// Changes new title + /** + * Changes the title. When #show()/operator()# are invoked, the dialog of filebox will be created with the specified title. + * @param text Text of title + */ + void title( ::std::string text); + + /// Sets a initial path + /** + * Suggest initial path used to locate a directory when the filebox starts. + * @note the behavior of init_path is different between Win7 and Win2K/XP/Vista, but its behavior under Linux is conformed with Win7. + * @param path a path of initial directory + * @return reference of *this. + */ + filebox& init_path(const path_type& path); + + /// Sets a initial filename + /** + * Suggest a filename when filebox starts. If the filename contains a path, the initial path will be replaced with the path presents in initial filename. + * @param filename a filename used for a initial filename when filebox starts. + * @return reference of *this. + */ + filebox& init_file(const ::std::string& filename); ///< Init file, if it contains a path, the init path is replaced by the path of init file. /// \brief Add a filetype filter. /// To specify multiple filter in a single description, use a semicolon to separate the patterns(for example,"*.TXT;*.DOC;*.BAK"). @@ -60,17 +73,11 @@ namespace nana const ::std::string& filetype ///< filter pattern(for example: "*.TXT") ); - filebox& add_filter(const filters &ftres) - { - for (auto &f : ftres) - add_filter(f.first, f.second); - return *this; - }; + filebox& add_filter(const std::vector> &filters); - - const ::std::string& path() const; + const path_type& path() const; - void allow_multi_select(bool allow); + filebox& allow_multi_select(bool allow); /// Display the filebox dialog std::vector show() const; @@ -99,7 +106,7 @@ namespace nana ~folderbox(); /// Enables/disables multi select - void allow_multi_select(bool allow); + folderbox& allow_multi_select(bool allow); std::vector show() const; @@ -108,10 +115,11 @@ namespace nana return show(); } - /// Set a new title for the dialog - /// @param string a text for title - /// @return the old title. - ::std::string title( ::std::string new_title); + /// Changes title + /** + * @param text Text of title + */ + folderbox& title(std::string text); private: implement* impl_; }; diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index 239f9971..35fc8ca4 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -1339,15 +1339,10 @@ namespace nana std::string init_file; std::string title; - std::string path; + path_type path; std::vector filters; }; - filebox::filebox(bool is_openmode) - : filebox(nullptr, is_openmode) - { - } - filebox::filebox(window owner, bool open) : impl_(new implement) { @@ -1389,23 +1384,17 @@ namespace nana impl_->owner = wd; } - std::string filebox::title(std::string s) + void filebox::title(std::string s) { impl_->title.swap(s); - return s; } - filebox& filebox::init_path(const std::string& ipstr) + filebox& filebox::init_path(const path_type& p) { - if(ipstr.empty()) - { - impl_->path.clear(); - } - else - { - if (fs::is_directory(ipstr)) - impl_->path = ipstr; - } + std::error_code err; + if (p.empty() || is_directory(p, err)) + impl_->path = p; + return *this; } @@ -1422,7 +1411,14 @@ namespace nana return *this; } - const std::string& filebox::path() const + filebox& filebox::add_filter(const std::vector> &filters) + { + for (auto &f : filters) + add_filter(f.first, f.second); + return *this; + } + + const filebox::path_type& filebox::path() const { return impl_->path; } @@ -1574,9 +1570,10 @@ namespace nana } - void filebox::allow_multi_select(bool allow) + filebox& filebox::allow_multi_select(bool allow) { impl_->allow_multi_select = allow; + return *this; } //end class filebox @@ -1600,10 +1597,10 @@ namespace nana } - std::string folderbox::title(std::string s) + folderbox& folderbox::title(std::string s) { impl_->title.swap(s); - return s; + return *this; } @@ -1626,9 +1623,10 @@ namespace nana } #endif - void folderbox::allow_multi_select(bool allow) + folderbox& folderbox::allow_multi_select(bool allow) { impl_->allow_multi_select = allow; + return *this; } std::vector folderbox::show() const