コード例 #1
0
ファイル: PolycodeIDEApp.cpp プロジェクト: bigjko/Polycode
void PolycodeIDEApp::loadConfigFile() {
	Object configFile;
	// TODO: Make a crossplatform core method to get application data path
#if defined(__APPLE__) && defined(__MACH__)
	configFile.loadFromXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");
#else
	configFile.loadFromXML(core->getUserHomeDirectory()+"/.polycode/config.xml");
#endif	
	globalSyntaxTheme = new SyntaxHighlightTheme();
	String themeName = "default";
	ObjectEntry *syntaxTheme = configFile.root["syntax_theme"];
	if(syntaxTheme) {
		themeName = syntaxTheme->stringVal;
	}
	themeName = "monokai";	
	globalSyntaxTheme->loadFromFile(themeName);
	
	if(configFile.root["open_projects"]) {
		ObjectEntry *projects = configFile.root["open_projects"];
		if(projects) {
		for(int i=0; i < projects->length; i++) {
			ObjectEntry *entry = (*(*projects)[i])["path"];
			if(entry) {
				PolycodeProject* project = projectManager->openProject(entry->stringVal);
				if(project) {
					OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
					projectManager->setActiveProject(project);
					openFile(projectEntry);
				}
			}
		}
		}
	}
}
コード例 #2
0
void PolycodeIDEApp::saveConfigFile() {
	Config *config = CoreServices::getInstance()->getConfig();
	Object configFile;
	configFile.root.name = "config";
	configFile.root.addChild("open_projects");
	configFile.root.addChild("syntax_theme", globalSyntaxTheme->name);
	for(int i=0; i < projectManager->getProjectCount(); i++) {
		PolycodeProject *project = projectManager->getProjectByIndex(i);		
		ObjectEntry *projectEntry = configFile.root["open_projects"]->addChild("project");
		projectEntry->addChild("name", project->getProjectName());
		projectEntry->addChild("path", project->getProjectFile());
	}

	configFile.root.addChild("settings");
	ObjectEntry *textEditorEntry = configFile.root["settings"]->addChild("text_editor");
	textEditorEntry->addChild("use_external", config->getStringValue("Polycode", "useExternalTextEditor"));
	textEditorEntry->addChild("command", config->getStringValue("Polycode", "externalTextEditorCommand"));

#if defined(__APPLE__) && defined(__MACH__)
	core->createFolder(core->getUserHomeDirectory()+"/Library/Application Support/Polycode");
	configFile.saveToXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");	
#else
	core->createFolder(core->getUserHomeDirectory()+"/.polycode");
	configFile.saveToXML(core->getUserHomeDirectory()+"/.polycode/config.xml");	

#endif
}
コード例 #3
0
ファイル: PolycodeIDEApp.cpp プロジェクト: bigjko/Polycode
void PolycodeIDEApp::openProject() {
	
#ifdef USE_POLYCODEUI_FILE_DIALOGS
	std::vector<String> exts;
	exts.push_back("polyproject");
	frame->showFileBrowser(CoreServices::getInstance()->getCore()->getUserHomeDirectory(),  false, exts, false);
	frame->fileDialog->addEventListener(this, UIEvent::OK_EVENT);
#else
	vector<CoreFileExtension> extensions;
	CoreFileExtension ext;
	ext.extension = "polyproject";
	ext.description = "Polycode Project File";
	extensions.push_back(ext);

	std::vector<String> paths = core->openFilePicker(extensions, false);
	if(paths.size() == 0) 
		return;

	if(paths[0] != "") {
		PolycodeProject *project = projectManager->openProject(paths[0]);
		if(project) {
			projectManager->setActiveProject(project);
			OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
			openFile(projectEntry);			
		}
	}
#endif
}
コード例 #4
0
void PolycodeIDEApp::loadConfigFile() {
	Object configFile;
	// TODO: Make a crossplatform core method to get application data path
#if defined(__APPLE__) && defined(__MACH__)
	configFile.loadFromXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");
#else
	configFile.loadFromXML(core->getUserHomeDirectory()+"/.polycode/config.xml");
#endif	
	globalSyntaxTheme = new SyntaxHighlightTheme();
	String themeName = "monokai";
	ObjectEntry *syntaxTheme = configFile.root["syntax_theme"];
	if(syntaxTheme) {
		themeName = syntaxTheme->stringVal;
	}
	globalSyntaxTheme->loadFromFile(themeName);
	
	if(configFile.root["open_projects"]) {
		ObjectEntry *projects = configFile.root["open_projects"];
		if(projects) {
			for(int i=0; i < projects->length; i++) {
				ObjectEntry *entry = (*(*projects)[i])["path"];
				if(entry) {
					PolycodeProject* project = projectManager->openProject(entry->stringVal);
					if(project) {
						OSFileEntry projectEntry =	OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
						projectManager->setActiveProject(project);
						openFile(projectEntry);
					}
				}
			}
		}
	}
	
	Config *config = CoreServices::getInstance()->getConfig();

	if(configFile.root["settings"]) {
		ObjectEntry *settings = configFile.root["settings"];
		ObjectEntry *textEditor = (*settings)["text_editor"];
		if(textEditor) {
			if((*textEditor)["use_external"]) {
				config->setStringValue("Polycode", "useExternalTextEditor", (*textEditor)["use_external"]->stringVal);
			} else {
				config->setStringValue("Polycode", "useExternalTextEditor", "false");
			}

			if((*textEditor)["command"]) {
				config->setStringValue("Polycode", "externalTextEditorCommand", (*textEditor)["command"]->stringVal);
			} else {
				config->setStringValue("Polycode", "externalTextEditorCommand", "");
			}
		}
	} else {
		config->setStringValue("Polycode","useExternalTextEditor", "false");
		config->setStringValue("Polycode", "externalTextEditorCommand", "");
	}
	frame->settingsWindow->updateUI();
}
コード例 #5
0
ファイル: PolycodeIDEApp.cpp プロジェクト: RobLach/Polycode
void PolycodeIDEApp::saveConfigFile() {
	Object configFile;
	configFile.root.name = "config";
	configFile.root.addChild("open_projects");
	for(int i=0; i < projectManager->getProjectCount(); i++) {
		PolycodeProject *project = projectManager->getProjectByIndex(i);		
		ObjectEntry *projectEntry = configFile.root["open_projects"]->addChild("project");
		projectEntry->addChild("name", project->getProjectName());
		projectEntry->addChild("path", project->getProjectFile());
	}
	core->createFolder("/Users/ivansafrin/Library/Application Support/Polycode");
	configFile.saveToXML("/Users/ivansafrin/Library/Application Support/Polycode/config.xml");		
}
コード例 #6
0
ファイル: PolycodeIDEApp.cpp プロジェクト: baumicon/Polycode
void PolycodeIDEApp::openProject() {
	
	vector<CoreFileExtension> extensions;
	CoreFileExtension ext;
	ext.extension = "polyproject";
	ext.description = "Polycode Project File";
	extensions.push_back(ext);
	std::vector<String> paths = core->openFilePicker(extensions, false);
	if(paths[0] != "") {
		PolycodeProject *project = projectManager->openProject(paths[0]);
		if(project) {
			projectManager->setActiveProject(project);
			OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
			openFile(projectEntry);			
		}
	}		
}
コード例 #7
0
ファイル: PolycodeIDEApp.cpp プロジェクト: Mr-Nil/Polycode
void PolycodeIDEApp::saveConfigFile() {
	Config *config = CoreServices::getInstance()->getConfig();
	Object configFile;
	configFile.root.name = "config";
	configFile.root.addChild("open_projects");
	configFile.root.addChild("syntax_theme", globalSyntaxTheme->name);
	configFile.root.addChild("ui_theme", config->getStringValue("Polycode", "uiTheme"));
	configFile.root.addChild("texture_filtering_mode", config->getStringValue("Polycode", "textureFilteringMode"));
	
	configFile.root.addChild("app_width", String::IntToString(core->getXRes()));
	configFile.root.addChild("app_height", String::IntToString(core->getYRes()));
	
	ObjectEntry *consoleEntry = configFile.root.addChild("console");
	consoleEntry->addChild("size", frame->getConsoleSize());
	consoleEntry->addChild("showing", frame->isShowingConsole());
	
	for(int i=0; i < projectManager->getProjectCount(); i++) {
		PolycodeProject *project = projectManager->getProjectByIndex(i);		
		ObjectEntry *projectEntry = configFile.root["open_projects"]->addChild("project");

		projectEntry->addChild("is_active", (project == projectManager->getActiveProject()));
		
		projectEntry->addChild("name", project->getProjectName());
		projectEntry->addChild("path", project->getProjectFile());
		
		ObjectEntry *projectFrameConfig = frame->getFrameConfigForProject(project);
		if(projectFrameConfig) {
			projectEntry->addChild(projectFrameConfig);
		}
	}

	configFile.root.addChild("settings");
	ObjectEntry *textEditorEntry = configFile.root["settings"]->addChild("text_editor");
	textEditorEntry->addChild("use_external", config->getStringValue("Polycode", "useExternalTextEditor"));
	textEditorEntry->addChild("command", config->getStringValue("Polycode", "externalTextEditorCommand"));

#if defined(__APPLE__) && defined(__MACH__)
	core->createFolder(core->getUserHomeDirectory()+"/Library/Application Support/Polycode");
	configFile.saveToXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");	
#else
	core->createFolder(core->getUserHomeDirectory()+"/.polycode");
	configFile.saveToXML(core->getUserHomeDirectory()+"/.polycode/config.xml");	

#endif
}
コード例 #8
0
ファイル: PolycodeIDEApp.cpp プロジェクト: baumicon/Polycode
void PolycodeIDEApp::loadConfigFile() {

	Object configFile;
	configFile.loadFromXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");		
	if(configFile.root["open_projects"]) {
		ObjectEntry *projects = configFile.root["open_projects"];
		if(projects) {
		for(int i=0; i < projects->length; i++) {
			ObjectEntry *entry = (*(*projects)[i])["path"];
			if(entry) {
				PolycodeProject* project = projectManager->openProject(entry->stringVal);
				OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
				projectManager->setActiveProject(project);
				openFile(projectEntry);
			}
		}
		}
	}
}
コード例 #9
0
ファイル: PolycodeIDEApp.cpp プロジェクト: bigjko/Polycode
void PolycodeIDEApp::saveConfigFile() {
	Object configFile;
	configFile.root.name = "config";
	configFile.root.addChild("open_projects");
	configFile.root.addChild("syntax_theme", globalSyntaxTheme->name);
	for(int i=0; i < projectManager->getProjectCount(); i++) {
		PolycodeProject *project = projectManager->getProjectByIndex(i);		
		ObjectEntry *projectEntry = configFile.root["open_projects"]->addChild("project");
		projectEntry->addChild("name", project->getProjectName());
		projectEntry->addChild("path", project->getProjectFile());
	}

#if defined(__APPLE__) && defined(__MACH__)
	core->createFolder(core->getUserHomeDirectory()+"/Library/Application Support/Polycode");
	configFile.saveToXML(core->getUserHomeDirectory()+"/Library/Application Support/Polycode/config.xml");	
#else
	core->createFolder(core->getUserHomeDirectory()+"/.polycode");
	configFile.saveToXML(core->getUserHomeDirectory()+"/.polycode/config.xml");	

#endif
}
コード例 #10
0
ファイル: PolycodeIDEApp.cpp プロジェクト: bigjko/Polycode
void PolycodeIDEApp::handleEvent(Event *event) {

	if(event->getDispatcher() == frame->fileDialog) {
		if(event->getEventCode() == UIEvent::OK_EVENT && event->getEventType() == "UIEvent") {
			String path = frame->fileDialog->getSelection();
			if(path != "") {
				PolycodeProject *project = projectManager->openProject(path);
				if(project) {
					projectManager->setActiveProject(project);
					OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
					openFile(projectEntry);			
				}
				
			}
		}
	}

	if(event->getDispatcher() == menuBar) {
		String action = menuBar->getSelectedItem();
	
		if(action == "new_file") {
			newFile();
		} else if(action == "new_project") {
			newProject();
		} else if(action == "new_folder") {
			newGroup();
		} else if(action == "open_project") {
			openProject();
		} else if(action == "close_project") {
			closeProject();
		} else if(action == "remove_file") {
			removeFile();
		} else if(action == "refresh_project") {
			refreshProject();
		} else if(action == "save_file") {
			saveFile();
		} else if(action == "browse_examples") {
			browseExamples();
		} else if(action == "quit") {
			core->Shutdown();
		} else if(action == "run_project") {
			runProject();
		} else if(action == "export_project") {
			exportProject();
		} else if(action == "show_api") {
			openDocs();
		} else if(action == "show_about") {
			showAbout();
		}
	}

	if(event->getDispatcher() == frame->console->backtraceWindow) {
		if(event->getEventType() == "BackTraceEvent" && event->getEventCode() == BackTraceEvent::EVENT_BACKTRACE_SELECTED) {
			BackTraceEvent *btEvent = (BackTraceEvent*) event;
			openFileInProject(btEvent->project, btEvent->fileName);
			
			PolycodeEditor *editor = editorManager->getCurrentEditor();
			if(editor) {
				if(editor->getEditorType() == "PolycodeTextEditor") {
					PolycodeTextEditor *textEditor = (PolycodeTextEditor*) editor;
					textEditor->highlightLine(btEvent->lineNumber);
				}
				
			}	
		}
	}

	if(event->getDispatcher() == core) {
		switch(event->getEventCode()) {
			case Core::EVENT_LOST_FOCUS:
				core->setFramerate(3);
			break;		
			case Core::EVENT_GAINED_FOCUS:
				core->setFramerate(30);			
			break;					
			case Core::EVENT_CORE_RESIZE:
				if(menuBar) {
					frame->Resize(core->getXRes(), core->getYRes()-25);
					menuBar->Resize(core->getXRes(), 25);
				} else {
					frame->Resize(core->getXRes(), core->getYRes());
				}
			break;
		}
	}
	
	if(event->getDispatcher()  == frame->getProjectBrowser()) {
		
		if(event->getEventType() == "PolycodeProjectBrowserEvent") {
			switch(event->getEventCode()) {
				case PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND:
					PolycodeProjectBrowserEvent *bEvent = (PolycodeProjectBrowserEvent*) event;
					
					if(bEvent->command == "add_new_file") {					
						newFile();
					} else if(bEvent->command == "add_files") {
						addFiles();
					} else if(bEvent->command == "add_new_project") {
						newProject();
					} else if(bEvent->command == "add_new_folder") {				
						newGroup();
					} else if(bEvent->command == "refresh") {
						refreshProject();
					} else if(bEvent->command == "rename") {
						renameFile();
					} else if(bEvent->command == "remove") {
						removeFile();
					}																				
				break;
			}
		}
		
		if(event->getEventCode() == Event::CHANGE_EVENT) {
			BrowserUserData *selectedData = frame->getProjectBrowser()->getSelectedData();
						
			if(selectedData->type == 3) {
				projectManager->activeFolder = selectedData->parentProject->getRootFolder();
				projectManager->selectedFile = "";				
			} else if(selectedData->type == 0) {
				projectManager->activeFolder = "";
				projectManager->selectedFile = "";
			} else {
				projectManager->selectedFileEntry = selectedData->fileEntry;
				projectManager->selectedFile = selectedData->fileEntry.fullPath;
				if(selectedData->fileEntry.type == OSFileEntry::TYPE_FILE) {
					projectManager->activeFolder = selectedData->fileEntry.basePath;
				} else {
					projectManager->activeFolder = selectedData->fileEntry.fullPath;
				}			
			}
			
			projectManager->setActiveProject(selectedData->parentProject);
			
			if(selectedData->type == 0)
				return;			
			
			if(selectedData) {
				openFile(selectedData->fileEntry);
			}
		}
	}
	
	if(event->getDispatcher() == frame->playButton) {	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
			willRunProject = true;
		}
	}

	if(event->getDispatcher() == frame->stopButton) {	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
			stopProject();
		}
	}

	if(event->getDispatcher() == frame->yesNoCancelPopup) {
		if(frame->yesNoCancelPopup->action == "closeFile") {
			switch(event->getEventCode()) {
				case UIEvent::YES_EVENT:
				{
					PolycodeEditor *editor = editorManager->getCurrentEditor();
					if(editor) {
						editor->saveFile();
						closeFile();
					}
					frame->hideModal();					
				}
				break;
				case UIEvent::NO_EVENT:
				{
					PolycodeEditor *editor = editorManager->getCurrentEditor();
					if(editor) {
						editor->setHasChanges(false);
						closeFile();
					}
					frame->hideModal();
				}
				break;
				case UIEvent::CANCEL_EVENT:
				break;
			}
		}			
	} else if(event->getDispatcher() == frame->yesNoPopup) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CANCEL_EVENT) {
			if(frame->yesNoPopup->action == "saveAndRun") {
				runNextFrame = true;			
			}
			
			frame->hideModal();
			frame->yesNoPopup->action = "";		
		}
	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			if(frame->yesNoPopup->action == "removeFile") {
				doRemoveFile();
			}
			
			if(frame->yesNoPopup->action == "saveAndRun") {
				editorManager->saveAll();
				runNextFrame = true;
			}
			
			frame->hideModal();
			frame->yesNoPopup->action = "";
		}
	}
	
	if(event->getDispatcher() == frame->textInputPopup) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
						
			if(frame->textInputPopup->action == "newGroup") {	
				core->createFolder(projectManager->activeFolder+"/"+frame->textInputPopup->getValue());
				if(projectManager->getActiveProject()) {
					frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
				}			
			}
			
			if(frame->textInputPopup->action == "renameFile") {		
				core->moveDiskItem(projectManager->selectedFileEntry.fullPath, projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());			
				if(projectManager->getActiveProject()) {
					frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
				}
				
				PolycodeEditor *editor = editorManager->getEditorForPath(projectManager->selectedFileEntry.fullPath);
				if(editor) {
					editor->setFilePath(projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());
				}
				
				projectManager->selectedFileEntry.fullPath = projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue();
				projectManager->selectedFileEntry.name = frame->textInputPopup->getValue();				
			}
			
			frame->hideModal();			
		}
	}	

	if(event->getDispatcher() == frame->exportProjectWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->exportProject(projectManager->getActiveProject(), frame->exportProjectWindow->projectLocationInput->getText(), frame->exportProjectWindow->macCheckBox->isChecked(), frame->exportProjectWindow->winCheckBox->isChecked(), frame->exportProjectWindow->linCheckBox->isChecked());
			frame->hideModal();			
		}
	}

	
	if(event->getDispatcher() == frame->newProjectWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->createNewProject(frame->newProjectWindow->getTemplateFolder(), frame->newProjectWindow->getProjectName(), frame->newProjectWindow->getProjectLocation());
			frame->hideModal();			
		}
	}

	if(event->getDispatcher() == frame->newFileWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->createNewFile(frame->newFileWindow->getTemplatePath(), frame->newFileWindow->getFileName());
			frame->hideModal();			
			
			if(projectManager->getActiveProject()) {
				frame->projectBrowser->refreshProject(projectManager->getActiveProject());
			}			
		}
	}
	
	if(event->getDispatcher() == frame->exampleBrowserWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			String fullPath = String(core->getDefaultWorkingDirectory()+"/"+frame->exampleBrowserWindow->getExamplePath());
			PolycodeProject* project = projectManager->openProject(fullPath);
			OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
			projectManager->setActiveProject(project);
			openFile(projectEntry);			
			
			frame->hideModal();			
		}
	}	
}
コード例 #11
0
ファイル: PolycodeIDEApp.cpp プロジェクト: Mr-Nil/Polycode
void PolycodeIDEApp::handleEvent(Event *event) {

	if(event->getDispatcher() == frame->assetImporterWindow) {
        refreshProject();
	}
	
	if(event->getDispatcher() == projectManager && event->getEventCode() == Event::CHANGE_EVENT) {
		if(projectManager->getActiveProject()) {
		
			if(frame->getCurrentProjectBrowser()) {
				frame->getCurrentProjectBrowser()->removeAllHandlersForListener(this);
			}
		
			PolycodeProjectFrame *projectFame = frame->getProjectFrame(projectManager->getActiveProject());
			if(projectFame) {
				frame->switchToProjectFrame(projectFame);
			} else {
				frame->createProjectFrame(projectManager->getActiveProject());
			}	
			frame->getCurrentProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT);
			frame->getCurrentProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND);
		}
	}

	if(event->getDispatcher() == frame) {
		if(event->getEventCode() == Event::CHANGE_EVENT) {
			if(frame->getCurrentProjectBrowser()) {
				frame->getCurrentProjectBrowser()->removeAllHandlersForListener(this);
			}
			frame->getCurrentProjectBrowser()->addEventListener(this, Event::CHANGE_EVENT);
			frame->getCurrentProjectBrowser()->addEventListener(this, PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND);			
		}
			
		if(event->getEventCode() == UIEvent::CLOSE_EVENT) {
			closeFile();
		}
	}

	if(event->getDispatcher() == frame->fileDialog) {
		if(event->getEventCode() == UIEvent::OK_EVENT && event->getEventType() == "UIEvent") {
			String path = frame->fileDialog->getSelection();
			if(path != "") {
				if(frame->fileDialog->action == "openProject") {
					PolycodeProject *project = projectManager->openProject(path);
					if(project) {
						projectManager->setActiveProject(project);
					}
				} else if(frame->fileDialog->action == "addFiles") {
					OSFileEntry entry = OSFileEntry(path, OSFileEntry::TYPE_FILE);
					core->copyDiskItem(path, projectManager->activeFolder + "/" + entry.name);
 			                   refreshProject();
				} else if(frame->fileDialog->action == "openImportAssets") {
					frame->assetImporterWindow->setSourceFileAndTargetFolder(path, projectManager->activeFolder, projectManager->activeFolder.replace(projectManager->getActiveProject()->getRootFolder(), ""));
					frame->showModal(frame->assetImporterWindow);
					frame->assetImporterWindow->addEventListener(this, UIEvent::OK_EVENT);
				}
			}
		}
	}

	if(event->getDispatcher() == menuBar) {
		String action = menuBar->getSelectedItem();
	
		if(action == "new_file") {
			newFile();
		} else if(action == "new_project") {
			newProject();
		} else if(action == "new_folder") {
			newGroup();
		} else if(action == "open_project") {
			openProject();
		} else if(action == "close_project") {
			closeProject();
		} else if(action == "close_file") {
			closeFile();
		} else if(action == "remove_file") {
			removeFile();
		} else if(action == "refresh_project") {
			refreshProject();
		} else if(action == "save_file") {
			saveFile();
		} else if(action == "browse_examples") {
			browseExamples();
		} else if(action == "quit") {
			core->Shutdown();
		} else if(action == "run_project") {
			runProject();
		} else if(action == "export_project") {
			exportProject();
		} else if(action == "show_api") {
			openDocs();
		} else if(action == "show_about") {
			showAbout();
		} else if(action == "toggle_console") {
			toggleConsole();
		} else if(action == "settings") {
			showSettings();
		} else if(action == "find") {
			findText();
		}
	}

	if(event->getDispatcher() == frame->console->backtraceWindow) {
		if(event->getEventType() == "BackTraceEvent" && event->getEventCode() == BackTraceEvent::EVENT_BACKTRACE_SELECTED) {
			BackTraceEvent *btEvent = (BackTraceEvent*) event;
			openFileInProject(btEvent->project, btEvent->fileName);
			
			PolycodeEditor *editor = editorManager->getCurrentEditor();
			if(editor) {
				if(editor->getEditorType() == "PolycodeTextEditor") {
					PolycodeTextEditor *textEditor = (PolycodeTextEditor*) editor;
					textEditor->highlightLine(btEvent->lineNumber);
				}
				
			}	
		}
	}

	if(event->getDispatcher() == core) {
		switch(event->getEventCode()) {
			case Core::EVENT_LOST_FOCUS:
				core->setFramerate(3);
			break;		
			case Core::EVENT_GAINED_FOCUS:
				core->setFramerate(60);			
			break;					
			case Core::EVENT_CORE_RESIZE:
				if(menuBar) {
					frame->Resize(core->getXRes(), core->getYRes()-25);
					menuBar->Resize(core->getXRes(), 25);
				} else {
					frame->Resize(core->getXRes(), core->getYRes());
				}
			break;
		}
	}
	
	if(event->getDispatcher()  == frame->getCurrentProjectBrowser()) {
		
		if(event->getEventType() == "PolycodeProjectBrowserEvent") {
			switch(event->getEventCode()) {
				case PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND:
					PolycodeProjectBrowserEvent *bEvent = (PolycodeProjectBrowserEvent*) event;
					
					if(bEvent->command == "add_new_file") {					
						newFile();
					} else if(bEvent->command == "add_files") {
						addFiles();
					} else if(bEvent->command == "import_assets") {
						importAssets();		
					} else if(bEvent->command == "add_new_project") {
						newProject();
					} else if(bEvent->command == "add_new_folder") {				
						newGroup();
					} else if(bEvent->command == "refresh") {
						refreshProject();
					} else if(bEvent->command == "rename") {
						renameFile();
					} else if(bEvent->command == "remove") {
						removeFile();
					}																				
				break;
			}
		}
		
		if(event->getEventCode() == Event::CHANGE_EVENT) {
			PolycodeProjectBrowser *pb = frame->getCurrentProjectBrowser();
			BrowserUserData *selectedData = pb->getSelectedData();
						
			if(selectedData->type == 0) {
				projectManager->activeFolder = selectedData->parentProject->getRootFolder();
				projectManager->selectedFile = "";				
			} else {
				projectManager->selectedFileEntry = selectedData->fileEntry;
				projectManager->selectedFile = selectedData->fileEntry.fullPath;
				if(selectedData->fileEntry.type == OSFileEntry::TYPE_FILE) {
					projectManager->activeFolder = selectedData->fileEntry.basePath;
				} else {
					projectManager->activeFolder = selectedData->fileEntry.fullPath;
				}			
			}
			
			if(selectedData->type == 0)
				return;			
			
			// don't open the editor if the selection was made by UITreeContainer arrow-key navigation
			if (selectedData && pb->treeContainer->getRootNode()->getSelectedNode()->isSelectedByKey() == false) {
				openFile(selectedData->fileEntry);
			}
		}
	}
	
	if(event->getDispatcher() == frame->playButton) {	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
			willRunProject = true;
		}
	}

	if(event->getDispatcher() == frame->stopButton) {	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
			stopProject();
		}
	}

	if(event->getDispatcher() == frame->yesNoCancelPopup) {
		if(frame->yesNoCancelPopup->action == "closeFile") {
			switch(event->getEventCode()) {
				case UIEvent::YES_EVENT:
				{
					PolycodeEditor *editor = editorManager->getCurrentEditor();
					if(editor) {
						editor->saveFile();
						closeFile();
					}
					frame->yesNoCancelPopup->action = "";
					frame->hideModal();					
				}
				break;
				case UIEvent::NO_EVENT:
				{
					PolycodeEditor *editor = editorManager->getCurrentEditor();
					if(editor) {
						editor->setHasChanges(false);
						closeFile();
					}
					frame->yesNoCancelPopup->action = "";					
					frame->hideModal();
				}
				break;
				case UIEvent::CANCEL_EVENT:
				break;
			}
		} else if(frame->yesNoCancelPopup->action == "closeQuitFile") {
			switch(event->getEventCode()) {
				case UIEvent::YES_EVENT:
				{
					PolycodeEditor *editor = editorManager->getCurrentEditor();
					if(editor) {
						editor->saveFile();
						closeFile();
						if(editorManager->openEditors.size() > 0) {
							editorManager->setCurrentEditor(editorManager->openEditors[0]);
						} else{
							editorManager->setCurrentEditor(NULL);
						}						
					}
					frame->yesNoCancelPopup->action = "";
					frame->hideModal();
					if(quitApp()) {
						core->Shutdown();
					}
				}
				break;
				case UIEvent::NO_EVENT:
				{
					PolycodeEditor *editor = editorManager->getCurrentEditor();
					if(editor) {
						editor->setHasChanges(false);
						closeFile();
						if(editorManager->openEditors.size() > 0) {
							editorManager->setCurrentEditor(editorManager->openEditors[0]);
						} else{
							editorManager->setCurrentEditor(NULL);
						}						
					}
					frame->yesNoCancelPopup->action = "";					
					frame->hideModal();
					if(quitApp()) {
						core->Shutdown();
					}					
				}
				break;
				case UIEvent::CANCEL_EVENT:
					quittingApp = false;
				break;
			}					
		} else if (frame->yesNoCancelPopup->action == "closeProject") {
			switch (event->getEventCode()) {
				case UIEvent::YES_EVENT:
					saveFiles(tempEditorStore);
					doCloseProject();
					break;
				case UIEvent::NO_EVENT:
					doCloseProject();
					break;
				case UIEvent::CANCEL_EVENT:
					break;
			}
			frame->yesNoCancelPopup->action = "";
			frame->hideModal();
		}
		
		else if (frame->yesNoCancelPopup->action == "closeFiles") {
			switch (event->getEventCode()) {
				case UIEvent::YES_EVENT:
					saveFiles(tempEditorStore);
					doCloseFiles(tempEditorStore);
					break;
				case UIEvent::NO_EVENT:
					doCloseFiles(tempEditorStore);
					break;
				case UIEvent::CANCEL_EVENT:
					break;
			}
			frame->yesNoCancelPopup->action = "";
			frame->hideModal();
		}
	} else if(event->getDispatcher() == frame->yesNoPopup) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CANCEL_EVENT) {
			if(frame->yesNoPopup->action == "saveAndRun") {
				runNextFrame = true;			
			}
			
			frame->hideModal();
			frame->yesNoPopup->action = "";		
		}
	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			if(frame->yesNoPopup->action == "removeFile") {
				doRemoveFile();
			}
			
			if(frame->yesNoPopup->action == "saveAndRun") {
				editorManager->saveFilesForProject(projectManager->getActiveProject());
				runNextFrame = true;
			}
			
			frame->hideModal();
			frame->yesNoPopup->action = "";
		}
	}
	
	if(event->getDispatcher() == frame->textInputPopup) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
						
			if(frame->textInputPopup->action == "newGroup") {	
				core->createFolder(projectManager->activeFolder+"/"+frame->textInputPopup->getValue());
				if(projectManager->getActiveProject()) {
                    refreshProject();
				}			
			}
			
			if(frame->textInputPopup->action == "renameFile") {		
				core->moveDiskItem(projectManager->selectedFileEntry.fullPath, projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());			
				if(projectManager->getActiveProject()) {
                    refreshProject();
				}
				
				PolycodeEditor *editor = editorManager->getEditorForPath(projectManager->selectedFileEntry.fullPath);
				if(editor) {
					editor->setFilePath(projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());
				}
				
				projectManager->selectedFileEntry.fullPath = projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue();
				projectManager->selectedFileEntry.name = frame->textInputPopup->getValue();				
			}
			
			frame->hideModal();			
		}
	}	

	if(event->getDispatcher() == frame->settingsWindow) {
		if(event->getEventType() == "UIEvent") {
			Config *config = CoreServices::getInstance()->getConfig();
			SettingsWindow *settingsWindow = frame->settingsWindow;

			if(event->getEventCode() == UIEvent::OK_EVENT) {
				config->setStringValue("Polycode", "useExternalTextEditor", settingsWindow->useExternalTextEditorBox->isChecked() ? "true" : "false");
				config->setStringValue("Polycode", "externalTextEditorCommand", settingsWindow->externalTextEditorCommand->getText());
				config->setStringValue("Polycode", "uiTheme", settingsWindow->uiThemeBox->getSelectedItem()->label);
				
				if(settingsWindow->textureFilteringBox->getSelectedIndex() == 0) {
					config->setStringValue("Polycode", "textureFilteringMode", "linear");
				} else {
					config->setStringValue("Polycode", "textureFilteringMode", "nearest");				
				}
			
				frame->hideModal();
			}
		}
	}

	if(event->getDispatcher() == frame->exportProjectWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->exportProject(projectManager->getActiveProject(), frame->exportProjectWindow->projectLocationInput->getText(), frame->exportProjectWindow->macCheckBox->isChecked(), frame->exportProjectWindow->winCheckBox->isChecked(), frame->exportProjectWindow->linCheckBox->isChecked(), frame->exportProjectWindow->compileCheckBox->isChecked());
			frame->hideModal();			
		}
	}

	
	if(event->getDispatcher() == frame->newProjectWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->createNewProject(frame->newProjectWindow->getTemplateFolder(), frame->newProjectWindow->getProjectName(), frame->newProjectWindow->getProjectLocation());
			frame->hideModal();			
		}
	}

	if(event->getDispatcher() == frame->newFileWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->createNewFile(frame->newFileWindow->getTemplatePath(), frame->newFileWindow->getFileName());
			frame->hideModal();						
			if(projectManager->getActiveProject()) {
                refreshProject();
			}			
		}
	}
	
	if(event->getDispatcher() == frame->exampleBrowserWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			String fullPath = String(core->getDefaultWorkingDirectory()+"/"+frame->exampleBrowserWindow->getExamplePath());
			PolycodeProject* project = projectManager->openProject(fullPath);
			OSFileEntry projectEntry =	OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
			projectManager->setActiveProject(project);			
			frame->hideModal();			
		}
	}
	
	// close files and editors after the close file button is pressed
	/*
	if (event->getDispatcher() == frame->closeFileButton) {
		if (event->getEventCode() == UIEvent::CLICK_EVENT) {
			if (core->getInput()->getKeyState(KEY_RSHIFT) || core->getInput()->getKeyState(KEY_LSHIFT))
				closeFiles(editorManager->openEditors);
			else
				closeFile();
		}
	}
	*/
	
	// open an editor/file if project browser has focus and user hits enter or right-arrow key
	if (event->getDispatcher() == CoreServices::getInstance()->getCore()->getInput()) {
		if(frame->getActiveProjectFrame()) {
			if (event->getEventCode() == InputEvent::EVENT_KEYDOWN && frame->getCurrentProjectBrowser()->treeContainer->hasFocus) {
				InputEvent *inEvent = (InputEvent*)event;
				if (inEvent->keyCode() == KEY_RETURN || inEvent->keyCode() == KEY_RIGHT) {
					BrowserUserData *selectedData = frame->getCurrentProjectBrowser()->getSelectedData();
					if (selectedData)
						openFile(selectedData->fileEntry);
				}
			}
		}
	}
}
コード例 #12
0
ファイル: PolycodeIDEApp.cpp プロジェクト: Mr-Nil/Polycode
void PolycodeIDEApp::applyFinalConfig() {

	ObjectEntry *appWidth = configFile.root["app_width"];
	ObjectEntry *appHeight = configFile.root["app_height"];
		
	bool setResFromConfig = false;
	if(appWidth && appHeight) {
		int newXRes = appWidth->intVal;
		int newYRes = appHeight->intVal;		
		if(newXRes > 100 && newYRes > 100) {
			setResFromConfig = true;
			core->setVideoMode(newXRes, newYRes, false, true, 0, 0);
			frame->Resize(newXRes, newYRes);
		}
	}
	
	if(!setResFromConfig) {
		core->setVideoMode(1100, 700, false, true, 0, 0);	
		frame->Resize(1100, 700);			
	}


	ObjectEntry *consoleEntry = configFile.root["console"];	
	if(consoleEntry) {
		if((*consoleEntry)["size"]) {
			frame->getConsoleSizer()->setMainHeight((*consoleEntry)["size"]->NumberVal);
		}
		if((*consoleEntry)["showing"]) {
			if((*consoleEntry)["showing"]->boolVal) {
				frame->showConsole();
			} else {
				frame->hideConsole();			
			}
		}		
	}

	PolycodeProject *activeConfigProject = NULL;
	
	for(int i=0; i < projectsToOpen.size(); i++) {
		ObjectEntry *projectPathEntry = ((*projectsToOpen[i])["path"]);		
		if(projectPathEntry) {
			String projectPath = projectPathEntry->stringVal;
			PolycodeProject* project = projectManager->openProject(projectPath);
			
			ObjectEntry *projectActiveEntry = ((*projectsToOpen[i])["is_active"]);
			if(projectActiveEntry) {
				if(projectActiveEntry->boolVal) {
					activeConfigProject = project;
				}
			}
			
			PolycodeProjectFrame *projectFrame = frame->getProjectFrame(project);
			
			PolycodeProjectTab *activeTab = NULL;
			
			if(project) {
				OSFileEntry projectEntry =	OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);	
				ObjectEntry *frameEntry = ((*projectsToOpen[i])["frame"]);
				if(frameEntry) {
					ObjectEntry *tabs = (*frameEntry)["tabs"];
					if(tabs) {
						for(int i=0; i < tabs->length; i++) {
							ObjectEntry *tab = (*tabs)[i];
							if(tab) {
								ObjectEntry *tabName = (*tab)["tab_name"];
								ObjectEntry *tabActive = (*tab)["tab_active"];
								
								if(i == 0) {
									projectFrame->getTabAtIndex(0)->setTabName(tabName->stringVal);
									projectFrame->restructTabs();
								} else {
									projectFrame->addNewTab(tabName->stringVal);
								}			
													
								projectFrame->getTabAtIndex(i)->applyTabConfig(tab);
								
								if(tabActive->boolVal) {
									activeTab = projectFrame->getTabAtIndex(i);
								}
								
							}
						}
						
						if(activeTab) {
							projectFrame->showTab(activeTab);
						}
					}
				}
			}
		}				
	}
	
	if(activeConfigProject) {
		projectManager->setActiveProject(activeConfigProject);
		frame->switchToProjectFrame(frame->getProjectFrame(activeConfigProject));
	}

}
コード例 #13
0
ファイル: PolycodeIDEApp.cpp プロジェクト: baumicon/Polycode
void PolycodeIDEApp::handleEvent(Event *event) {

	if(event->getDispatcher() == frame->console->backtraceWindow) {
		if(event->getEventType() == "BackTraceEvent" && event->getEventCode() == BackTraceEvent::EVENT_BACKTRACE_SELECTED) {
			BackTraceEvent *btEvent = (BackTraceEvent*) event;
			openFileInProject(btEvent->project, btEvent->fileName);
			
			PolycodeEditor *editor = editorManager->getCurrentEditor();
			if(editor) {
				if(editor->getEditorType() == "PolycodeTextEditor") {
					PolycodeTextEditor *textEditor = (PolycodeTextEditor*) editor;
					textEditor->highlightLine(btEvent->lineNumber);
				}
				
			}	
		}
	}

	if(event->getDispatcher() == core) {
		switch(event->getEventCode()) {
			case Core::EVENT_CORE_RESIZE:
				frame->Resize(core->getXRes(), core->getYRes());
			break;
		}
	}
	
	if(event->getDispatcher()  == frame->getProjectBrowser()) {
		
		if(event->getEventType() == "PolycodeProjectBrowserEvent") {
			switch(event->getEventCode()) {
				case PolycodeProjectBrowserEvent::HANDLE_MENU_COMMAND:
					PolycodeProjectBrowserEvent *bEvent = (PolycodeProjectBrowserEvent*) event;
					
/*
			contextMenu->addOption("Add New File", "add_new_file");
			contextMenu->addOption("Add New Project", "add_new_project");
			contextMenu->addOption("Add New Folder", "add_new_folder");			
			contextMenu->addOption("--------", "");			
			contextMenu->addOption("Refresh", "refresh");
			contextMenu->addOption("Rename", "rename");						
			contextMenu->addOption("--------", "");		
			contextMenu->addOption("Remove", "remove");	
*/					
					if(bEvent->command == "add_new_file") {					
						newFile();
					} else if(bEvent->command == "add_new_project") {
						newProject();
					} else if(bEvent->command == "add_new_folder") {				
						newGroup();
					} else if(bEvent->command == "refresh") {
						refreshProject();
					} else if(bEvent->command == "rename") {
						renameFile();
					} else if(bEvent->command == "remove") {
						removeFile();
					}																				
				break;
			}
		}
		
		if(event->getEventCode() == Event::CHANGE_EVENT) {
			BrowserUserData *selectedData = frame->getProjectBrowser()->getSelectedData();
						
			if(selectedData->type == 3) {
				projectManager->activeFolder = selectedData->parentProject->getRootFolder();
				projectManager->selectedFile = "";				
			} else if(selectedData->type == 0) {
				projectManager->activeFolder = "";
				projectManager->selectedFile = "";
			} else {
				projectManager->selectedFileEntry = selectedData->fileEntry;
				projectManager->selectedFile = selectedData->fileEntry.fullPath;
				if(selectedData->fileEntry.type == OSFileEntry::TYPE_FILE) {
					projectManager->activeFolder = selectedData->fileEntry.basePath;
				} else {
					projectManager->activeFolder = selectedData->fileEntry.fullPath;
				}			
			}
			
			projectManager->setActiveProject(selectedData->parentProject);
			
			if(selectedData->type == 0)
				return;			
			
			if(selectedData) {
				openFile(selectedData->fileEntry);
			}
		}
	}
	
	if(event->getDispatcher() == frame->playButton) {	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
			willRunProject = true;
		}
	}

	if(event->getDispatcher() == frame->stopButton) {	
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::CLICK_EVENT) {
			stopProject();
		}
	}

	
	if(event->getDispatcher() == frame->textInputPopup) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			core->moveDiskItem(projectManager->selectedFileEntry.fullPath, projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());			
			if(projectManager->getActiveProject()) {
				frame->getProjectBrowser()->refreshProject(projectManager->getActiveProject());
			}
			
			PolycodeEditor *editor = editorManager->getEditorForPath(projectManager->selectedFileEntry.fullPath);
			if(editor) {
				editor->setFilePath(projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue());
			}
			
			projectManager->selectedFileEntry.fullPath = projectManager->selectedFileEntry.basePath + "/" + frame->textInputPopup->getValue();
			projectManager->selectedFileEntry.name = frame->textInputPopup->getValue();
			
			
			frame->hideModal();			
		}
	}	

	if(event->getDispatcher() == frame->exportProjectWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->exportProject(projectManager->getActiveProject(), frame->exportProjectWindow->projectLocationInput->getText(), frame->exportProjectWindow->macCheckBox->isChecked(), frame->exportProjectWindow->winCheckBox->isChecked(), frame->exportProjectWindow->linCheckBox->isChecked());
			frame->hideModal();			
		}
	}

	
	if(event->getDispatcher() == frame->newProjectWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->createNewProject(frame->newProjectWindow->getTemplateFolder(), frame->newProjectWindow->getProjectName(), frame->newProjectWindow->getProjectLocation());
			frame->hideModal();			
		}
	}

	if(event->getDispatcher() == frame->newFileWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			projectManager->createNewFile(frame->newFileWindow->getTemplatePath(), frame->newFileWindow->getFileName());
			frame->hideModal();			
			
			if(projectManager->getActiveProject()) {
				frame->projectBrowser->refreshProject(projectManager->getActiveProject());
			}			
		}
	}
	
	if(event->getDispatcher() == frame->exampleBrowserWindow) {
		if(event->getEventType() == "UIEvent" && event->getEventCode() == UIEvent::OK_EVENT) {
			String fullPath = String(core->getDefaultWorkingDirectory()+"/"+frame->exampleBrowserWindow->getExamplePath());
			PolycodeProject* project = projectManager->openProject(fullPath);
			OSFileEntry projectEntry =  OSFileEntry(project->getProjectFile(), OSFileEntry::TYPE_FILE);
			projectManager->setActiveProject(project);
			openFile(projectEntry);			
			
			frame->hideModal();			
		}
	}	
}