| 358 | } |
| 359 | |
| 360 | UIFileDialog* App::openFileDialog( bool registerEvents ) { |
| 361 | UIFileDialog* dialog = UIFileDialog::New( |
| 362 | UIFileDialog::DefaultFlags | |
| 363 | ( mConfig.ui.nativeFileDialogs ? UIFileDialog::UseNativeFileDialog : 0 ), |
| 364 | "*", getDefaultFileDialogFolder() ); |
| 365 | dialog->setWindowFlags( UI_WIN_DEFAULT_FLAGS | UI_WIN_MAXIMIZE_BUTTON | UI_WIN_MODAL ); |
| 366 | dialog->setTitle( i18n( "open_file", "Open File" ) ); |
| 367 | dialog->setCloseShortcut( KEY_ESCAPE ); |
| 368 | dialog->setSingleClickNavigation( mConfig.editor.singleClickNavigation ); |
| 369 | if ( registerEvents ) { |
| 370 | dialog->setAllowsMultiFileSelect( true ); |
| 371 | dialog->on( Event::OpenFile, [this]( const Event* event ) { |
| 372 | auto files = event->getNode()->asType<UIFileDialog>()->getFullPaths(); |
| 373 | for ( const auto& file : files ) { |
| 374 | mLastFileFolder = FileSystem::fileRemoveFileName( file ); |
| 375 | loadFileFromPath( file ); |
| 376 | } |
| 377 | } ); |
| 378 | } |
| 379 | dialog->on( Event::OnWindowClose, [this]( const Event* ) { |
| 380 | if ( App::instance() && mSplitter && mSplitter->getCurWidget() && |
| 381 | !SceneManager::instance()->isShuttingDown() ) |
| 382 | mSplitter->getCurWidget()->setFocus(); |
| 383 | } ); |
| 384 | dialog->center(); |
| 385 | dialog->show(); |
| 386 | return dialog; |
| 387 | } |
| 388 | |
| 389 | std::string App::getDefaultFileDialogFolder() const { |
| 390 | return mLastFileFolder.empty() ? getLastUsedFolder() : mLastFileFolder; |
no test coverage detected