Advertisement
Khalibloo

UE4 Windows Show Open File Dialog (.cpp)

Jul 22nd, 2018
1,126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "FileOpsBPLibrary.h"
  2. #include <algorithm>
  3. #include <string>
  4. #include "FileOps.h"
  5. #include "FileDialog.h"
  6.  
  7. bool UFileOpsBPLibrary::ShowOpenFileDialog(FString InitialDir, FString Title, bool UseFilter, FString& Filepath) {
  8.     FileDialog* dialog = new FileDialog();
  9.     dialog->FilterIndex = 1;
  10.     InitialDir = InitialDir.Replace(TEXT("/"), TEXT("\\"));
  11.     dialog->InitialDir = InitialDir.GetCharArray().GetData(); //cast FString to *TCHAR (not const *TCHAR)
  12.     dialog->Title = Title.GetCharArray().GetData();
  13.  
  14.     if (UseFilter) {
  15.         dialog->Filter = TEXT("Samurai Files (*.sam)\0*.sam\0All Files\0*.*\0\0");
  16.     }
  17.  
  18.     if (dialog->ShowOpenFileDialog()) {
  19.         Filepath = dialog->FileName;
  20.         Filepath = Filepath.Replace(_T("\\"), _T("/"));
  21.         return true;
  22.     }
  23.     return false;
  24. }
Advertisement
RAW Paste Data Copied
Advertisement