Merge remote-tracking branch 'origin/cmake-dev' into cmake-dev
This commit is contained in:
commit
af0e40da3f
@ -23,7 +23,7 @@
|
|||||||
<ProjectGuid>{42D0520F-EFA5-4831-84FE-2B9085301C5D}</ProjectGuid>
|
<ProjectGuid>{42D0520F-EFA5-4831-84FE-2B9085301C5D}</ProjectGuid>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
<RootNamespace>nana</RootNamespace>
|
<RootNamespace>nana</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
|||||||
@ -9,7 +9,7 @@
|
|||||||
*
|
*
|
||||||
* @file nana/gui/filebox.hpp
|
* @file nana/gui/filebox.hpp
|
||||||
* @author Jinhao
|
* @author Jinhao
|
||||||
* @brief a dialog to chose file(s), implemented "native" in windows but using nana for X11
|
* @brief dialogs to chose file(s) or a directory, implemented "native" in windows but using nana for X11
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef NANA_GUI_FILEBOX_HPP
|
#ifndef NANA_GUI_FILEBOX_HPP
|
||||||
@ -31,7 +31,7 @@ namespace nana
|
|||||||
public:
|
public:
|
||||||
using filters = std::vector<std::pair< ::std::string, ::std::string>>;
|
using filters = std::vector<std::pair< ::std::string, ::std::string>>;
|
||||||
|
|
||||||
filebox(bool is_open_mode);
|
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();
|
||||||
@ -56,8 +56,8 @@ namespace nana
|
|||||||
|
|
||||||
/// \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").
|
||||||
filebox& add_filter(const ::std::string& description, ///< for example. "Text File"
|
filebox& add_filter(const ::std::string& description, ///< for example: "Text File"
|
||||||
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 filters &ftres)
|
||||||
@ -94,7 +94,7 @@ namespace nana
|
|||||||
public:
|
public:
|
||||||
using path_type = std::experimental::filesystem::path;
|
using path_type = std::experimental::filesystem::path;
|
||||||
|
|
||||||
folderbox(window owner = nullptr, const path_type& init_path = {});
|
explicit folderbox(window owner = nullptr, const path_type& init_path = {}, std::string title={});
|
||||||
~folderbox();
|
~folderbox();
|
||||||
|
|
||||||
std::optional<path_type> show() const;
|
std::optional<path_type> show() const;
|
||||||
@ -103,6 +103,11 @@ namespace nana
|
|||||||
{
|
{
|
||||||
return show();
|
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);
|
||||||
private:
|
private:
|
||||||
implement* impl_;
|
implement* impl_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -10,6 +10,8 @@
|
|||||||
* @file: nana/gui/filebox.cpp
|
* @file: nana/gui/filebox.cpp
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui.hpp>
|
||||||
#include <nana/gui/filebox.hpp>
|
#include <nana/gui/filebox.hpp>
|
||||||
#include <nana/filesystem/filesystem_ext.hpp>
|
#include <nana/filesystem/filesystem_ext.hpp>
|
||||||
@ -1114,29 +1116,29 @@ namespace nana
|
|||||||
for(auto & f : impl_->filters)
|
for(auto & f : impl_->filters)
|
||||||
{
|
{
|
||||||
filter_holder += to_wstring(f.des);
|
filter_holder += to_wstring(f.des);
|
||||||
filter_holder += static_cast<std::wstring::value_type>('\0');
|
filter_holder += static_cast<std::wstring::value_type>('\0'); // separator
|
||||||
std::wstring fs = to_wstring(f.type);
|
std::wstring ff = to_wstring(f.type);
|
||||||
std::size_t pos = 0;
|
std::size_t pos = 0;
|
||||||
while(true)
|
while(true) // eliminate spaces
|
||||||
{
|
{
|
||||||
pos = fs.find(L" ", pos);
|
pos = ff.find(L" ", pos);
|
||||||
if(pos == fs.npos)
|
if(pos == ff.npos)
|
||||||
break;
|
break;
|
||||||
fs.erase(pos);
|
ff.erase(pos);
|
||||||
}
|
}
|
||||||
filter_holder += fs;
|
filter_holder += ff;
|
||||||
filter_holder += static_cast<std::wstring::value_type>('\0');
|
filter_holder += static_cast<std::wstring::value_type>('\0'); // separator
|
||||||
|
|
||||||
//Get the default file extentsion
|
//Get the default file extension
|
||||||
if (default_extension.empty())
|
if (default_extension.empty())
|
||||||
{
|
{
|
||||||
pos = fs.find_last_of('.');
|
pos = ff.find_last_of('.');
|
||||||
if (pos != fs.npos)
|
if (pos != ff.npos)
|
||||||
{
|
{
|
||||||
fs = fs.substr(pos + 1);
|
ff = ff.substr(pos + 1);
|
||||||
if (fs != L"*")
|
if (ff != L"*")
|
||||||
{
|
{
|
||||||
default_extension = fs;
|
default_extension = ff;
|
||||||
ofn.lpstrDefExt = default_extension.data();
|
ofn.lpstrDefExt = default_extension.data();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1207,25 +1209,33 @@ namespace nana
|
|||||||
}//end class filebox
|
}//end class filebox
|
||||||
|
|
||||||
|
|
||||||
//class directory_picker
|
//class directory picker
|
||||||
struct folderbox::implement
|
struct folderbox::implement
|
||||||
{
|
{
|
||||||
window owner;
|
window owner;
|
||||||
path_type init_path;
|
path_type init_path;
|
||||||
|
std::string title;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
folderbox::folderbox(window owner, const path_type& init_path)
|
folderbox::folderbox(window owner, const path_type& init_path, std::string title)
|
||||||
: impl_(new implement)
|
: impl_(new implement{ owner, fs::canonical(init_path).make_preferred(), title })
|
||||||
{
|
{}
|
||||||
impl_->owner = owner;
|
|
||||||
impl_->init_path = init_path;
|
|
||||||
}
|
|
||||||
|
|
||||||
folderbox::~folderbox()
|
folderbox::~folderbox()
|
||||||
{
|
{
|
||||||
delete impl_;
|
delete impl_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string folderbox::title(std::string s)
|
||||||
|
{
|
||||||
|
impl_->title.swap(s);
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef NANA_MINGW
|
#ifdef NANA_MINGW
|
||||||
static int CALLBACK browse_folder_callback(HWND hwnd, UINT msg, LPARAM lparam, LPARAM data)
|
static int CALLBACK browse_folder_callback(HWND hwnd, UINT msg, LPARAM lparam, LPARAM data)
|
||||||
{
|
{
|
||||||
@ -1235,7 +1245,9 @@ namespace nana
|
|||||||
{
|
{
|
||||||
case BFFM_INITIALIZED:
|
case BFFM_INITIALIZED:
|
||||||
if (data)
|
if (data)
|
||||||
|
{
|
||||||
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, data);
|
SendMessage(hwnd, BFFM_SETSELECTION, TRUE, data);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1278,17 +1290,22 @@ namespace nana
|
|||||||
fd->Release();
|
fd->Release();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
BROWSEINFO brw = { 0 };
|
|
||||||
wchar_t display_text[MAX_PATH];
|
wchar_t display_text[MAX_PATH];
|
||||||
brw.hwndOwner = reinterpret_cast<HWND>(API::root(impl_->owner));
|
auto title = to_wstring( impl_->title ) ;
|
||||||
brw.pszDisplayName = display_text;
|
|
||||||
brw.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
|
||||||
brw.lpfn = browse_folder_callback;
|
|
||||||
|
|
||||||
std::wstring init_path = impl_->init_path.wstring();
|
std::wstring init_path = impl_->init_path.wstring();
|
||||||
brw.lParam = reinterpret_cast<LPARAM>(init_path.c_str());
|
|
||||||
auto pidl = ::SHBrowseForFolder(&brw);
|
|
||||||
|
|
||||||
|
// https://docs.microsoft.com/en-us/windows/desktop/api/shlobj_core/ns-shlobj_core-_browseinfoa
|
||||||
|
BROWSEINFO brw = { 0 };
|
||||||
|
brw.hwndOwner = reinterpret_cast<HWND>(API::root(impl_->owner));
|
||||||
|
//brw.pidlRoot; // specifies the location of the root folder from which to start browsing.
|
||||||
|
brw.pszDisplayName = display_text; // buffer to receive the display name of the folder selected by the user.
|
||||||
|
brw.lpszTitle = title.data();
|
||||||
|
brw.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE; // | BIF_EDITBOX;
|
||||||
|
brw.lpfn = browse_folder_callback;
|
||||||
|
brw.lParam = reinterpret_cast<LPARAM>(init_path.c_str());
|
||||||
|
//brw.iImage; //
|
||||||
|
|
||||||
|
auto pidl = ::SHBrowseForFolder(&brw);
|
||||||
if (pidl)
|
if (pidl)
|
||||||
{
|
{
|
||||||
wchar_t folder_path[MAX_PATH];
|
wchar_t folder_path[MAX_PATH];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user