MCPcopy Create free account
hub / github.com/MeshInspector/MeshLib / windowsDialog

Function windowsDialog

source/MRViewer/MRFileDialog.cpp:108–245  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106
107#if defined( _WIN32 )
108std::vector<std::filesystem::path> windowsDialog( const MR::FileDialog::Parameters& params = {} )
109{
110 std::vector<std::filesystem::path> res;
111 //<SnippetRefCounts>
112 HRESULT hr = CoInitializeEx( NULL, COINIT_APARTMENTTHREADED |
113 COINIT_DISABLE_OLE1DDE );
114
115 std::vector<COMDLG_FILTERSPEC> filters;
116 std::vector<std::pair<std::wstring, std::wstring>> filtersWCopy;
117
118 if( SUCCEEDED( hr ) )
119 {
120 IFileDialog* pFileOpen;
121
122 // Create the FileOpenDialog object.
123 hr = CoCreateInstance( params.saveDialog ? CLSID_FileSaveDialog : CLSID_FileOpenDialog,
124 NULL, CLSCTX_ALL,
125 params.saveDialog ? IID_IFileSaveDialog : IID_IFileOpenDialog,
126 reinterpret_cast<void**>(&pFileOpen) );
127
128 if( SUCCEEDED( hr ) )
129 {
130 auto baseFolder = params.baseFolder;
131 if ( baseFolder.empty() )
132 baseFolder = MR::FileDialog::getLastUsedDir();
133 if( !baseFolder.empty() )
134 {
135 IShellItem* pItem;
136 hr = SHCreateItemFromParsingName( baseFolder.c_str(), NULL, IID_PPV_ARGS( &pItem ) );
137 if( SUCCEEDED( hr ) )
138 {
139 pFileOpen->SetFolder( pItem );
140 pItem->Release();
141 }
142 }
143
144 // Set the options on the dialog.
145 DWORD dwFlags;
146 // Before setting, always get the options first in order
147 // not to override existing options.
148 pFileOpen->GetOptions( &dwFlags );
149 pFileOpen->SetOptions( dwFlags | (params.multiselect ? FOS_ALLOWMULTISELECT : 0) |
150 (params.folderDialog ? FOS_PICKFOLDERS : 0) );
151
152 if( !params.filters.empty() )
153 {
154 unsigned filtersSize = unsigned( params.filters.size() );
155 filtersWCopy.resize( filtersSize );
156 filters.resize( filtersSize );
157
158 for( unsigned i = 0; i < filtersSize; ++i )
159 {
160 const auto& [nameU8, filterU8] = params.filters[i];
161 auto& [nameW, filterW] = filtersWCopy[i];
162 nameW = MR::utf8ToWide( nameU8.c_str() );
163 filterW = MR::utf8ToWide( filterU8.c_str() );
164
165 filters[i].pszName = nameW.c_str();

Callers 1

runDialogFunction · 0.85

Calls 11

getLastUsedDirFunction · 0.85
setLastUsedDirFunction · 0.85
ReleaseMethod · 0.80
ShowMethod · 0.80
push_backMethod · 0.80
utf8ToWideFunction · 0.50
emptyMethod · 0.45
sizeMethod · 0.45
resizeMethod · 0.45
dataMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected