Skip to content

Commit

Permalink
Fixes ivansafrin#563, adds the ability to open a file directly in the…
Browse files Browse the repository at this point in the history
… IDE (with the right editor), without adding it to the project (Windows).
  • Loading branch information
Joachim Meyer committed Sep 23, 2014
1 parent 213fd02 commit cd41c45
Show file tree
Hide file tree
Showing 12 changed files with 55 additions and 8 deletions.
20 changes: 18 additions & 2 deletions Core/Contents/Source/PolyWinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,7 +1137,7 @@ std::vector<String> Win32Core::openFilePicker(std::vector<CoreFileExtension> ext
ofn.nMaxFileTitle = 0;
ofn.lpstrInitialDir=NULL;

if(allowMultiple) {
if(!allowMultiple) {
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_EXPLORER;
} else {
ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ALLOWMULTISELECT|OFN_EXPLORER;
Expand All @@ -1147,7 +1147,23 @@ std::vector<String> Win32Core::openFilePicker(std::vector<CoreFileExtension> ext

if(GetOpenFileName(&ofn)) {
if(allowMultiple) {

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;
} 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));
}
Expand Down
Binary file modified IDE/Build/Windows2013/Polycode.rc
Binary file not shown.
8 changes: 4 additions & 4 deletions IDE/Build/Windows2013/Polycode.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Express 2013 for Windows Desktop
VisualStudioVersion = 12.0.21005.1
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Polycode", "Polycode.vcxproj", "{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}"
EndProject
Expand All @@ -18,8 +18,8 @@ Global
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.ActiveCfg = Debug|x64
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.Build.0 = Debug|x64
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.ActiveCfg = Debug|Win32
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|Win32.Build.0 = Debug|Win32
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|x64.ActiveCfg = Debug|x64
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Debug|x64.Build.0 = Debug|x64
{D6C2171B-9167-4FB6-851A-DC1CEDCFC43D}.Release|Win32.ActiveCfg = Release|Win32
Expand Down
Binary file modified IDE/Build/Windows2013/resource.h
Binary file not shown.
3 changes: 3 additions & 0 deletions IDE/Build/WindowsShared/PolycodeWinIDEView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion IDE/Contents/Include/PolycodeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,9 @@ class PolycodeEditorFactory {

bool canHandleExtension(String extension);

std::vector<String> getExtensions();

protected:
std::vector<std::string> extensions;
std::vector<String> extensions;

};
2 changes: 2 additions & 0 deletions IDE/Contents/Include/PolycodeEditorManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class PolycodeEditorManager : public EventDispatcher {
void registerEditorFactory(PolycodeEditorFactory *editorFactory);

PolycodeEditorFactory *getEditorFactoryForExtension(String extension);

std::vector<CoreFileExtension> getExtensionsWithEditor();

void handleEvent(Event *event);

Expand Down
1 change: 1 addition & 0 deletions IDE/Contents/Include/PolycodeIDEApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class PolycodeIDEApp : public EventDispatcher {
void openFileInProject(PolycodeProject *project, String filePath);

void openFile(OSFileEntry file);
void openFilePicker();

void stopProject();

Expand Down
4 changes: 4 additions & 0 deletions IDE/Contents/Source/PolycodeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ bool PolycodeEditorFactory::canHandleExtension(String extension) {
return false;
}

std::vector<String> PolycodeEditorFactory::getExtensions(){
return extensions;
}

void PolycodeEditor::setFilePath(String newPath) {
filePath = newPath;
}
Expand Down
11 changes: 11 additions & 0 deletions IDE/Contents/Source/PolycodeEditorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ PolycodeEditorFactory *PolycodeEditorManager::getEditorFactoryForExtension(Strin
return NULL;
}

std::vector<CoreFileExtension> PolycodeEditorManager::getExtensionsWithEditor(){
std::vector<CoreFileExtension> 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];
Expand Down
1 change: 0 additions & 1 deletion IDE/Contents/Source/PolycodeEntityEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2517,4 +2517,3 @@ void PolycodeEntityEditor::Resize(int x, int y) {
mainSizer->Resize(x, y);
PolycodeEditor::Resize(x,y);
}

9 changes: 9 additions & 0 deletions IDE/Contents/Source/PolycodeIDEApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,15 @@ void PolycodeIDEApp::openFile(OSFileEntry file) {
}
}

void PolycodeIDEApp::openFilePicker() {
std::vector<CoreFileExtension> extensions = editorManager->getExtensionsWithEditor();
extensions.insert(extensions.begin(), CoreFileExtension("All Types", "*"));
std::vector<String> filePaths = core->openFilePicker(extensions, true);
for (int f = 0; f < filePaths.size(); f++){
openFile(OSFileEntry(filePaths[f], OSFileEntry::TYPE_FILE));
}
}

void PolycodeIDEApp::handleEvent(Event *event) {

if(event->getDispatcher() == frame->assetImporterWindow) {
Expand Down

0 comments on commit cd41c45

Please sign in to comment.