Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open file in ide #602

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 18 additions & 21 deletions Core/Contents/Source/PolyWinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,35 +1149,32 @@ std::vector<String> Win32Core::openFilePicker(std::vector<CoreFileExtension> 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<String> 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));
Expand Down
Binary file modified IDE/Build/Windows/Polycode.rc
Binary file not shown.
Binary file modified IDE/Build/Windows/resource.h
Binary file not shown.
Binary file modified IDE/Build/Windows2013/Polycode.rc
Binary file not shown.
3 changes: 1 addition & 2 deletions IDE/Build/Windows2013/Polycode.sln
Original file line number Diff line number Diff line change
@@ -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}"
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 @@ -70,6 +70,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 @@ -2533,4 +2533,3 @@ void PolycodeEntityEditor::Resize(int x, int y) {
mainSizer->Resize(x, y);
PolycodeEditor::Resize(x,y);
}

26 changes: 25 additions & 1 deletion IDE/Contents/Source/PolycodeIDEApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -708,6 +709,25 @@ void PolycodeIDEApp::openFile(OSFileEntry file) {
}
}

void PolycodeIDEApp::openFilePicker() {
std::vector<CoreFileExtension> extensions = editorManager->getExtensionsWithEditor();
#ifdef USE_POLYCODEUI_FILE_DIALOGS
std::vector<String> 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<String> 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) {
Expand Down Expand Up @@ -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));
}
}
}
Expand All @@ -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();
Expand Down