|
From: andrew7 <bd...@us...> - 2007-06-09 16:21:45
|
Update of /cvsroot/smartwin/SmartWin/include/smartwin/widgets In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv7301 Modified Files: WidgetLoadFile.h Log Message: Add showDialog( SmartUtil::tstring defaultFilePath ) to allow prechoosen file as the default. Index: WidgetLoadFile.h =================================================================== RCS file: /cvsroot/smartwin/SmartWin/include/smartwin/widgets/WidgetLoadFile.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- WidgetLoadFile.h 30 Nov 2006 00:43:57 -0000 1.15 +++ WidgetLoadFile.h 9 Jun 2007 16:21:39 -0000 1.16 @@ -81,6 +81,18 @@ */ SmartUtil::tstring showDialog(); + /// Shows the dialog with a default file path preselected. + /** Returns string() or "empty string" if user press cancel. <br> + * Returns a "file path" if user presses ok. <br> + * Use the inherited functions AspectFileFilter::addFilter and + * AspectFileFilter::activeFilter <br> + * before calling this function, if you wish the dialog to show only certain + * types of files. + */ + SmartUtil::tstring showDialog( SmartUtil::tstring defaultFilePath ); + + + /// Shows the dialog /** Returns an empty vector if user press cancel. <br> * Returns a vector of "file paths" if user presses ok. <br> @@ -132,6 +144,34 @@ return retVal; } + +template< class Parent > +SmartUtil::tstring WidgetLoadFile< Parent >::showDialog( SmartUtil::tstring defaultFilePath ) +{ + TCHAR szFile[PATH_BUFFER_SIZE]; // buffer for file name +#ifndef _tcscpy_s + _tcsncpy( szFile, defaultFilePath.c_str(), PATH_BUFFER_SIZE ); +#else + _tcscpy_s( szFile, PATH_BUFFER_SIZE, defaultFilePath.c_str() ); +#endif + + + OPENFILENAME ofn; // common dialog box structure + fillOutCommonStructure( ofn, itsParent->handle(), OFN_FILEMUSTEXIST ); + ofn.lpstrFile = szFile; + ofn.Flags |= OFN_FILEMUSTEXIST; + + SmartUtil::tstring retVal; + if ( ::GetOpenFileName( & ofn ) ) + { + retVal = ofn.lpstrFile; + backslashToForwardSlashForUnix( retVal ); + } + return retVal; +} + + + template< class Parent > std::vector<SmartUtil::tstring> WidgetLoadFile<Parent>::showDialogMultiSelect() { |