diff --git a/Core/Contents/Source/PolyWinCore.cpp b/Core/Contents/Source/PolyWinCore.cpp index 85713dda0..f54a8c0fd 100644 --- a/Core/Contents/Source/PolyWinCore.cpp +++ b/Core/Contents/Source/PolyWinCore.cpp @@ -1149,35 +1149,32 @@ std::vector Win32Core::openFilePicker(std::vector ext ofn.nMaxFileTitle = 0; ofn.lpstrInitialDir=NULL; - if(allowMultiple) { - ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT|OFN_EXPLORER; - } else { + if(!allowMultiple) { ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_EXPLORER; + } else { + ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT|OFN_EXPLORER; } std::vector retVec; if(GetOpenFileName(&ofn)) { if(allowMultiple) { - String path = fBuffer; - - std::string buf; - for (int i = ofn.nFileOffset; i < sizeof( fBuffer ); i++) - { - if (fBuffer[i] != NULL) - buf.push_back(fBuffer[i]); - else if (fBuffer[i-1] != NULL) - { - retVec.push_back(path + "/" + buf); - buf = ""; - } - else // 2 NULL characters = no more files + String dir = fBuffer; + size_t pos = dir.length(), last = 0; + while (true){ + if (fBuffer[pos + 1] == NULL){ + if (retVec.size() == 0){ + retVec.push_back(dir); + } break; - } - if (retVec.size() == 1) - { - retVec.clear(); - retVec.push_back(path); // If only 1 file selected, path is the full path of the file + } else { + String fileName; + for (last = pos + 1; fBuffer[pos + 1] != NULL; pos++){ + fileName.append(fBuffer[pos + 1]); + } + retVec.push_back(dir + "/" + fileName); + pos++; + } } } else { retVec.push_back(String(fBuffer)); diff --git a/IDE/Build/Windows/Polycode.rc b/IDE/Build/Windows/Polycode.rc index 68fcaf658..53513b679 100644 Binary files a/IDE/Build/Windows/Polycode.rc and b/IDE/Build/Windows/Polycode.rc differ diff --git a/IDE/Build/Windows/resource.h b/IDE/Build/Windows/resource.h index de8ce9694..570646085 100644 Binary files a/IDE/Build/Windows/resource.h and b/IDE/Build/Windows/resource.h differ diff --git a/IDE/Build/Windows2013/Polycode.rc b/IDE/Build/Windows2013/Polycode.rc index d73e4349e..8f4b134a1 100644 Binary files a/IDE/Build/Windows2013/Polycode.rc and b/IDE/Build/Windows2013/Polycode.rc differ diff --git a/IDE/Build/Windows2013/Polycode.sln b/IDE/Build/Windows2013/Polycode.sln index 77a7790d8..a07f85ac4 100644 --- a/IDE/Build/Windows2013/Polycode.sln +++ b/IDE/Build/Windows2013/Polycode.sln @@ -1,8 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2013 -VisualStudioVersion = 12.0.30501.0 -MinimumVisualStudioVersion = 10.0.40219.1 +VisualStudioVersion = 12.0.30501.0MinimumVisualStudioVersion = 10.0.40219.1 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Polycode", "Polycode.vcxproj", "{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0D5CDD59-CFF6-4143-8D1D-A92BBAB86060}" diff --git a/IDE/Build/Windows2013/resource.h b/IDE/Build/Windows2013/resource.h index de8ce9694..e1e0b7a7f 100644 Binary files a/IDE/Build/Windows2013/resource.h and b/IDE/Build/Windows2013/resource.h differ diff --git a/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp b/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp index 420a3b4f0..d40adef2e 100644 --- a/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp +++ b/IDE/Build/WindowsShared/PolycodeWinIDEView.cpp @@ -70,6 +70,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) case ID_FILE_OPEN_PROJECT: globalApp->openProject(); break; + case ID_FILE_OPEN_FILE: + globalApp->openFilePicker(); + break; case ID_FILE_CLOSE_FILE: globalApp->closeFile(); break; diff --git a/IDE/Contents/Include/PolycodeEditor.h b/IDE/Contents/Include/PolycodeEditor.h index c02b6fac8..8261c03a5 100644 --- a/IDE/Contents/Include/PolycodeEditor.h +++ b/IDE/Contents/Include/PolycodeEditor.h @@ -127,7 +127,9 @@ class PolycodeEditorFactory { bool canHandleExtension(String extension); + std::vector getExtensions(); + protected: - std::vector extensions; + std::vector extensions; }; diff --git a/IDE/Contents/Include/PolycodeEditorManager.h b/IDE/Contents/Include/PolycodeEditorManager.h index 5854b1d52..f93ec3794 100644 --- a/IDE/Contents/Include/PolycodeEditorManager.h +++ b/IDE/Contents/Include/PolycodeEditorManager.h @@ -38,6 +38,8 @@ class PolycodeEditorManager : public EventDispatcher { void registerEditorFactory(PolycodeEditorFactory *editorFactory); PolycodeEditorFactory *getEditorFactoryForExtension(String extension); + + std::vector getExtensionsWithEditor(); void handleEvent(Event *event); diff --git a/IDE/Contents/Include/PolycodeIDEApp.h b/IDE/Contents/Include/PolycodeIDEApp.h index af9c01d68..cab677485 100644 --- a/IDE/Contents/Include/PolycodeIDEApp.h +++ b/IDE/Contents/Include/PolycodeIDEApp.h @@ -70,6 +70,7 @@ class PolycodeIDEApp : public EventDispatcher { void openFileInProject(PolycodeProject *project, String filePath); void openFile(OSFileEntry file); + void openFilePicker(); void stopProject(); diff --git a/IDE/Contents/Source/PolycodeEditor.cpp b/IDE/Contents/Source/PolycodeEditor.cpp index 37e33b679..4afe3f086 100644 --- a/IDE/Contents/Source/PolycodeEditor.cpp +++ b/IDE/Contents/Source/PolycodeEditor.cpp @@ -42,6 +42,10 @@ bool PolycodeEditorFactory::canHandleExtension(String extension) { return false; } +std::vector PolycodeEditorFactory::getExtensions(){ + return extensions; +} + void PolycodeEditor::setFilePath(String newPath) { filePath = newPath; } diff --git a/IDE/Contents/Source/PolycodeEditorManager.cpp b/IDE/Contents/Source/PolycodeEditorManager.cpp index bddfc7241..066f9d197 100644 --- a/IDE/Contents/Source/PolycodeEditorManager.cpp +++ b/IDE/Contents/Source/PolycodeEditorManager.cpp @@ -45,6 +45,17 @@ PolycodeEditorFactory *PolycodeEditorManager::getEditorFactoryForExtension(Strin return NULL; } +std::vector PolycodeEditorManager::getExtensionsWithEditor(){ + std::vector extensions; + for (int i = 0; i < editorFactories.size(); i++) { + PolycodeEditorFactory *factory = editorFactories[i]; + for (int e = 0; e < factory->getExtensions().size(); e++){ + extensions.push_back(CoreFileExtension(factory->getExtensions()[e], factory->getExtensions()[e])); + } + } + return extensions; +} + PolycodeEditor *PolycodeEditorManager::createEditorForExtension(String extension) { for(int i=0;i < editorFactories.size(); i++) { PolycodeEditorFactory *factory = editorFactories[i]; diff --git a/IDE/Contents/Source/PolycodeEntityEditor.cpp b/IDE/Contents/Source/PolycodeEntityEditor.cpp index b5c7eca5b..ae64f70a0 100644 --- a/IDE/Contents/Source/PolycodeEntityEditor.cpp +++ b/IDE/Contents/Source/PolycodeEntityEditor.cpp @@ -2533,4 +2533,3 @@ void PolycodeEntityEditor::Resize(int x, int y) { mainSizer->Resize(x, y); PolycodeEditor::Resize(x,y); } - diff --git a/IDE/Contents/Source/PolycodeIDEApp.cpp b/IDE/Contents/Source/PolycodeIDEApp.cpp index 90e9a5edf..f5343b212 100644 --- a/IDE/Contents/Source/PolycodeIDEApp.cpp +++ b/IDE/Contents/Source/PolycodeIDEApp.cpp @@ -189,6 +189,7 @@ core = new POLYCODE_CORE((PolycodeView*)view, 1100, 700,false,false, 0, 0,60, -1 fileEntry->addItem("New File", "new_file", KEY_n); fileEntry->addItem("New Project", "new_project", KEY_LSHIFT, KEY_n); fileEntry->addItem("New Folder", "new_folder", KEY_LSHIFT, KEY_f); + fileEntry->addItem("Open File", "open_file", KEY_o); fileEntry->addItem("Open Project", "open_project", KEY_LSHIFT, KEY_o); fileEntry->addItem("Close Project", "close_project", KEY_LSHIFT, KEY_w); fileEntry->addItem("Close File", "close_file", KEY_w); @@ -708,6 +709,25 @@ void PolycodeIDEApp::openFile(OSFileEntry file) { } } +void PolycodeIDEApp::openFilePicker() { + std::vector extensions = editorManager->getExtensionsWithEditor(); + #ifdef USE_POLYCODEUI_FILE_DIALOGS + std::vector exts; + for(int e = 0; e < extensions.size(); e++){ + exts.push_back((extensions[e].extension)); + } + frame->showFileBrowser(CoreServices::getInstance()->getCore()->getUserHomeDirectory(), false, exts, false); + frame->fileDialog->addEventListener(this, UIEvent::OK_EVENT); + frame->fileDialog->action = "openFile"; +#else + extensions.insert(extensions.begin(), CoreFileExtension("All Types", "*")); + std::vector filePaths = core->openFilePicker(extensions, true); + for (int f = 0; f < filePaths.size(); f++){ + openFile(OSFileEntry(filePaths[f], OSFileEntry::TYPE_FILE)); + } +#endif +} + void PolycodeIDEApp::handleEvent(Event *event) { if(event->getDispatcher() == frame->assetImporterWindow) { @@ -763,6 +783,8 @@ void PolycodeIDEApp::handleEvent(Event *event) { frame->assetImporterWindow->setSourceFileAndTargetFolder(path, projectManager->activeFolder, projectManager->activeFolder.replace(projectManager->getActiveProject()->getRootFolder(), "")); frame->showModal(frame->assetImporterWindow); frame->assetImporterWindow->addEventListener(this, UIEvent::OK_EVENT); + } else if(frame->fileDialog->action == "openFile") { + openFile(OSFileEntry(path, OSFileEntry::TYPE_FILE)); } } } @@ -777,7 +799,9 @@ void PolycodeIDEApp::handleEvent(Event *event) { newProject(); } else if(action == "new_folder") { newGroup(); - } else if(action == "open_project") { + } else if (action == "open_file") { + openFilePicker(); + } else if (action == "open_project") { openProject(); } else if(action == "close_project") { closeProject();