refactor filebox and folderbox
This commit is contained in:
parent
29cee29f5f
commit
71f57bbf92
@ -28,10 +28,8 @@ namespace nana
|
|||||||
filebox(filebox&&) = delete;
|
filebox(filebox&&) = delete;
|
||||||
filebox& operator=(filebox&&) = delete;
|
filebox& operator=(filebox&&) = delete;
|
||||||
public:
|
public:
|
||||||
using filters = std::vector<std::pair< ::std::string, ::std::string>>;
|
|
||||||
using path_type = std::filesystem::path;
|
using path_type = std::filesystem::path;
|
||||||
|
|
||||||
explicit filebox(bool is_open_mode);
|
|
||||||
filebox(window owner, bool is_open_mode);
|
filebox(window owner, bool is_open_mode);
|
||||||
filebox(const filebox&);
|
filebox(const filebox&);
|
||||||
~filebox();
|
~filebox();
|
||||||
@ -39,20 +37,35 @@ namespace nana
|
|||||||
filebox& operator=(const filebox&);
|
filebox& operator=(const filebox&);
|
||||||
|
|
||||||
/// Change owner window
|
/// Change owner window
|
||||||
void owner(window);
|
/**
|
||||||
|
* Changes the owner window for the filebox. When #show()/operator()# are invoked, the dialog of filebox will be created with the specified owner.
|
||||||
/// Set a new title for the dialog
|
* @param handle A handle to a window which will be used for the owner of filebox
|
||||||
/// @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.
|
|
||||||
*/
|
*/
|
||||||
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.
|
/// \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").
|
/// 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")
|
const ::std::string& filetype ///< filter pattern(for example: "*.TXT")
|
||||||
);
|
);
|
||||||
|
|
||||||
filebox& add_filter(const filters &ftres)
|
filebox& add_filter(const std::vector<std::pair<std::string, std::string>> &filters);
|
||||||
{
|
|
||||||
for (auto &f : ftres)
|
|
||||||
add_filter(f.first, f.second);
|
|
||||||
return *this;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
const path_type& path() const;
|
||||||
|
|
||||||
const ::std::string& path() const;
|
filebox& allow_multi_select(bool allow);
|
||||||
|
|
||||||
void allow_multi_select(bool allow);
|
|
||||||
|
|
||||||
/// Display the filebox dialog
|
/// Display the filebox dialog
|
||||||
std::vector<path_type> show() const;
|
std::vector<path_type> show() const;
|
||||||
@ -99,7 +106,7 @@ namespace nana
|
|||||||
~folderbox();
|
~folderbox();
|
||||||
|
|
||||||
/// Enables/disables multi select
|
/// Enables/disables multi select
|
||||||
void allow_multi_select(bool allow);
|
folderbox& allow_multi_select(bool allow);
|
||||||
|
|
||||||
std::vector<path_type> show() const;
|
std::vector<path_type> show() const;
|
||||||
|
|
||||||
@ -108,10 +115,11 @@ namespace nana
|
|||||||
return show();
|
return show();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set a new title for the dialog
|
/// Changes title
|
||||||
/// @param string a text for title
|
/**
|
||||||
/// @return the old title.
|
* @param text Text of title
|
||||||
::std::string title( ::std::string new_title);
|
*/
|
||||||
|
folderbox& title(std::string text);
|
||||||
private:
|
private:
|
||||||
implement* impl_;
|
implement* impl_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1339,15 +1339,10 @@ namespace nana
|
|||||||
std::string init_file;
|
std::string init_file;
|
||||||
|
|
||||||
std::string title;
|
std::string title;
|
||||||
std::string path;
|
path_type path;
|
||||||
std::vector<filter> filters;
|
std::vector<filter> filters;
|
||||||
};
|
};
|
||||||
|
|
||||||
filebox::filebox(bool is_openmode)
|
|
||||||
: filebox(nullptr, is_openmode)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
filebox::filebox(window owner, bool open)
|
filebox::filebox(window owner, bool open)
|
||||||
: impl_(new implement)
|
: impl_(new implement)
|
||||||
{
|
{
|
||||||
@ -1389,23 +1384,17 @@ namespace nana
|
|||||||
impl_->owner = wd;
|
impl_->owner = wd;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string filebox::title(std::string s)
|
void filebox::title(std::string s)
|
||||||
{
|
{
|
||||||
impl_->title.swap(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())
|
std::error_code err;
|
||||||
{
|
if (p.empty() || is_directory(p, err))
|
||||||
impl_->path.clear();
|
impl_->path = p;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (fs::is_directory(ipstr))
|
|
||||||
impl_->path = ipstr;
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1422,7 +1411,14 @@ namespace nana
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string& filebox::path() const
|
filebox& filebox::add_filter(const std::vector<std::pair<std::string, std::string>> &filters)
|
||||||
|
{
|
||||||
|
for (auto &f : filters)
|
||||||
|
add_filter(f.first, f.second);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
const filebox::path_type& filebox::path() const
|
||||||
{
|
{
|
||||||
return impl_->path;
|
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;
|
impl_->allow_multi_select = allow;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
//end class filebox
|
//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);
|
impl_->title.swap(s);
|
||||||
return s;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1626,9 +1623,10 @@ namespace nana
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void folderbox::allow_multi_select(bool allow)
|
folderbox& folderbox::allow_multi_select(bool allow)
|
||||||
{
|
{
|
||||||
impl_->allow_multi_select = allow;
|
impl_->allow_multi_select = allow;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<folderbox::path_type> folderbox::show() const
|
std::vector<folderbox::path_type> folderbox::show() const
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user