Просмотр исходного кода

Tweaks to the external text editor pull request

Ivan Safrin 12 лет назад
Родитель
Сommit
7030403eca

+ 2 - 1
Core/Contents/Source/PolyCocoaCore.mm

@@ -217,11 +217,12 @@ void CocoaCore::launchApplicationWithFile(String application, String file) {
 
 String CocoaCore::executeExternalCommand(String command,  String args, String inDirectory) {
 
-	String finalCommand = command+" "+args;
+	String finalCommand = "\""+command+"\"1 "+args;
 	if(inDirectory != "") {
 		finalCommand = "cd \""+inDirectory+"\" && "+finalCommand;
 	}
 	
+	
 	FILE *fp = popen(finalCommand.c_str(), "r");
 	if(!fp) {
 		return "Unable to execute command";

+ 16 - 2
IDE/Build/Mac OS X/English.lproj/MainMenu.xib

@@ -701,7 +701,6 @@
 							<string key="NSFrameSize">{800, 600}</string>
 							<reference key="NSSuperview" ref="439893737"/>
 							<reference key="NSWindow"/>
-							<reference key="NSNextKeyView"/>
 							<object class="NSOpenGLPixelFormat" key="NSPixelFormat">
 								<object class="NSMutableData" key="NSPixelAttributes">
 									<bytes key="NS.bytes">AAAAYAAAAAA</bytes>
@@ -1180,6 +1179,14 @@
 					</object>
 					<int key="connectionID">614</int>
 				</object>
+				<object class="IBConnectionRecord">
+					<object class="IBActionConnection" key="connection">
+						<string key="label">showSettings:</string>
+						<reference key="source" ref="976324537"/>
+						<reference key="destination" ref="609285721"/>
+					</object>
+					<int key="connectionID">615</int>
+				</object>
 			</object>
 			<object class="IBMutableOrderedSet" key="objectRecords">
 				<object class="NSArray" key="orderedObjects">
@@ -1975,7 +1982,7 @@
 				<reference key="dict.values" ref="0"/>
 			</object>
 			<nil key="sourceID"/>
-			<int key="maxID">614</int>
+			<int key="maxID">615</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<object class="NSMutableArray" key="referencedPartialClassDescriptions">
@@ -2003,6 +2010,7 @@
 							<string>runProject:</string>
 							<string>saveFile:</string>
 							<string>showAbout:</string>
+							<string>showSettings:</string>
 							<string>toggleConsole:</string>
 						</object>
 						<object class="NSArray" key="dict.values">
@@ -2024,6 +2032,7 @@
 							<string>id</string>
 							<string>id</string>
 							<string>id</string>
+							<string>id</string>
 						</object>
 					</object>
 					<object class="NSMutableDictionary" key="actionInfosByName">
@@ -2046,6 +2055,7 @@
 							<string>runProject:</string>
 							<string>saveFile:</string>
 							<string>showAbout:</string>
+							<string>showSettings:</string>
 							<string>toggleConsole:</string>
 						</object>
 						<object class="NSArray" key="dict.values">
@@ -2114,6 +2124,10 @@
 								<string key="name">showAbout:</string>
 								<string key="candidateClassName">id</string>
 							</object>
+							<object class="IBActionInfo">
+								<string key="name">showSettings:</string>
+								<string key="candidateClassName">id</string>
+							</object>
 							<object class="IBActionInfo">
 								<string key="name">toggleConsole:</string>
 								<string key="candidateClassName">id</string>

+ 6 - 0
IDE/Build/Mac OS X/Polycode.xcodeproj/project.pbxproj

@@ -11,6 +11,7 @@
 		256AC3DA0F4B6AC300CF3369 /* PolycodeAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 256AC3D90F4B6AC300CF3369 /* PolycodeAppDelegate.m */; };
 		6D06CCF314BC203800E4CB4C /* libPolycore_d.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D06CCF214BC203800E4CB4C /* libPolycore_d.a */; };
 		6D06CCF514BC204200E4CB4C /* libPolycodeUI_d.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D06CCF414BC204200E4CB4C /* libPolycodeUI_d.a */; };
+		6D128ABD174A9940007B0375 /* SettingsWindow.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D128ABC174A9940007B0375 /* SettingsWindow.cpp */; };
 		6D1CD96B164D9568006CDAB1 /* polycode_project.icns in Resources */ = {isa = PBXBuildFile; fileRef = 6D1CD96A164D9568006CDAB1 /* polycode_project.icns */; };
 		6D2AC99B14B8500400BB63DA /* PolycodeProjectEditor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D2AC99A14B8500400BB63DA /* PolycodeProjectEditor.cpp */; };
 		6D34143412B816BC0034FA9B /* IOKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6D34143312B816BC0034FA9B /* IOKit.framework */; };
@@ -81,6 +82,8 @@
 		29B97325FDCFA39411CA2CEA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
 		6D06CCF214BC203800E4CB4C /* libPolycore_d.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPolycore_d.a; path = ../../../Release/Darwin/Framework/Core/lib/libPolycore_d.a; sourceTree = "<group>"; };
 		6D06CCF414BC204200E4CB4C /* libPolycodeUI_d.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libPolycodeUI_d.a; path = ../../../Release/Darwin/Framework/Modules/lib/libPolycodeUI_d.a; sourceTree = "<group>"; };
+		6D128ABA174A9936007B0375 /* SettingsWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsWindow.h; sourceTree = "<group>"; };
+		6D128ABC174A9940007B0375 /* SettingsWindow.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SettingsWindow.cpp; sourceTree = "<group>"; };
 		6D1CD96A164D9568006CDAB1 /* polycode_project.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; name = polycode_project.icns; path = ../../../Assets/Icons/polycode_project.icns; sourceTree = "<group>"; };
 		6D2AC99A14B8500400BB63DA /* PolycodeProjectEditor.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PolycodeProjectEditor.cpp; sourceTree = "<group>"; };
 		6D2AC99D14B8500A00BB63DA /* PolycodeProjectEditor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PolycodeProjectEditor.h; sourceTree = "<group>"; };
@@ -298,6 +301,7 @@
 				6D80E91312AB53FB0037A708 /* PolycodeFrame.h */,
 				6D80E91412AB53FB0037A708 /* PolycodeIDEApp.h */,
 				6D80E91512AB53FB0037A708 /* PolycodeProject.h */,
+				6D128ABA174A9936007B0375 /* SettingsWindow.h */,
 				6D80E91612AB53FB0037A708 /* PolycodeProjectBrowser.h */,
 				6D80E91712AB53FB0037A708 /* PolycodeProjectManager.h */,
 			);
@@ -308,6 +312,7 @@
 		6D80E91812AB53FB0037A708 /* Source */ = {
 			isa = PBXGroup;
 			children = (
+				6D128ABC174A9940007B0375 /* SettingsWindow.cpp */,
 				6D8A845C16F593D000F3BA08 /* PolycodeClipboard.cpp */,
 				6DC67A531656F693004FD1EF /* TextureBrowser.cpp */,
 				6D79732D167F0D4600646407 /* PolycodeSpriteEditor.cpp */,
@@ -450,6 +455,7 @@
 				6D79732E167F0D4600646407 /* PolycodeSpriteEditor.cpp in Sources */,
 				6D797333167F0EB100646407 /* PolycodeProps.cpp in Sources */,
 				6D8A845D16F593D000F3BA08 /* PolycodeClipboard.cpp in Sources */,
+				6D128ABD174A9940007B0375 /* SettingsWindow.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

+ 1 - 1
IDE/Build/Mac OS X/PolycodeAppDelegate.h

@@ -70,5 +70,5 @@ public:
 -(IBAction) findText: (id) sender;
 -(IBAction) openDocs: (id) sender;
 -(IBAction) showAbout: (id) sender;
-
+-(IBAction) showSettings: (id) sender;
 @end

+ 4 - 0
IDE/Build/Mac OS X/PolycodeAppDelegate.m

@@ -170,4 +170,8 @@
 	app->toggleConsole();
 }
 
+-(IBAction) showSettings: (id) sender {
+	app->showSettings();
+}
+
 @end

+ 2 - 0
IDE/Contents/Include/PolycodeEditorManager.h

@@ -35,6 +35,8 @@ class PolycodeEditorManager : public EventDispatcher {
 		PolycodeEditor *getEditorForPath(String path);
 		PolycodeEditor *createEditorForExtension(String extension);
 		void registerEditorFactory(PolycodeEditorFactory *editorFactory);
+		
+		PolycodeEditorFactory *getEditorFactoryForExtension(String extension);
 	
 		void handleEvent(Event *event);
 		

+ 12 - 0
IDE/Contents/Include/PolycodeToolLauncher.h

@@ -34,11 +34,23 @@ class PolycodeRunner : public Threaded {
 		String polyappPath;
 };
 
+class GenericRunner : public Threaded {
+	public:
+		GenericRunner(String app, String file, String inFolder);
+		
+		void runThread();
+		
+		String app;
+		String file;	
+		String inFolder;	
+};
+
 class PolycodeToolLauncher {
 	public: 
 		PolycodeToolLauncher();
 		~PolycodeToolLauncher();		
 		
+		static void openExternalEditor(String app, String file, String inFolder);
 		static String generateTempPath(PolycodeProject *project);
 		static void buildProject(PolycodeProject *project, String destinationPath);
 

+ 10 - 0
IDE/Contents/Source/PolycodeEditorManager.cpp

@@ -31,6 +31,16 @@ PolycodeEditorManager::~PolycodeEditorManager() {
 	
 }
 
+PolycodeEditorFactory *PolycodeEditorManager::getEditorFactoryForExtension(String extension) {
+	for(int i=0;i < editorFactories.size(); i++) {
+		PolycodeEditorFactory *factory = editorFactories[i];
+		if(factory->canHandleExtension(extension)) {
+			return factory;
+		}
+	}
+	return NULL;
+}
+
 PolycodeEditor *PolycodeEditorManager::createEditorForExtension(String extension) {
 	for(int i=0;i < editorFactories.size(); i++) {
 		PolycodeEditorFactory *factory = editorFactories[i];

+ 11 - 7
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -534,18 +534,22 @@ void PolycodeIDEApp::openFileInProject(PolycodeProject *project, String filePath
 }
 
 void PolycodeIDEApp::openFile(OSFileEntry file) {
-	PolycodeEditor *editor;
-	editor = editorManager->getEditorForPath(file.fullPath);
 
-	if(editor) {
+	PolycodeEditorFactory *factory = editorManager->getEditorFactoryForExtension(file.extension);
+	if(dynamic_cast<PolycodeTextEditorFactory*>(factory)) {
 		CoreServices *core = CoreServices::getInstance();
-		Config *config = core->getConfig();
+		Config *config = core->getConfig();	
 		bool useExternalTextEditor = (config->getStringValue("Polycode", "useExternalTextEditor") == "true") && (config->getStringValue("Polycode", "externalTextEditorCommand") != "");
-		if(editor->getEditorType() == "PolycodeTextEditor" && useExternalTextEditor) {
-			core->getCore()->executeExternalCommand(config->getStringValue("Polycode", "externalTextEditorCommand"), file.fullPath, projectManager->getActiveProject()->getRootFolder());
+		
+		if(useExternalTextEditor) {
+			PolycodeToolLauncher::openExternalEditor(config->getStringValue("Polycode", "externalTextEditorCommand"), file.fullPath, projectManager->getActiveProject()->getRootFolder());
 			return;
-		}
+		}	
+	}
 
+	PolycodeEditor *editor = editorManager->getEditorForPath(file.fullPath);
+	
+	if(editor) {
 		frame->showEditor(editor);
 	} else {
 		editor = editorManager->createEditorForExtension(file.extension);

+ 20 - 5
IDE/Contents/Source/PolycodeToolLauncher.cpp

@@ -26,6 +26,21 @@
 	#include "PolyCocoaCore.h"
 #endif
 
+GenericRunner::GenericRunner(String app, String file, String inFolder) : Threaded() {
+	this->app = app;
+	this->file = file;
+	this->inFolder = inFolder;
+}
+
+void GenericRunner::runThread() {
+#if defined(__APPLE__) && defined(__MACH__)
+	CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
+	cocoaCore->openFileWithApplication(file, app);
+#else
+	String ret = CoreServices::getInstance()->getCore()->executeExternalCommand(app, file, inFolder);	
+#endif
+}
+
 PolycodeRunner::PolycodeRunner(String polyappPath) : Threaded() {
 	this->polyappPath = polyappPath;
 }
@@ -98,13 +113,14 @@ void PolycodeToolLauncher::buildProject(PolycodeProject *project, String destina
 
 }
 
+void PolycodeToolLauncher::openExternalEditor(String app, String file, String inFolder) {
+	GenericRunner *runner = new GenericRunner(app, file, inFolder);
+	CoreServices::getInstance()->getCore()->createThread(runner);
+}
+
 void PolycodeToolLauncher::runPolyapp(String polyappPath) {
 
 	PolycodeConsole::clearBacktraces();
-
-
-//	PolycodeRunner *runner = new PolycodeRunner(polyappPath);
-//	CoreServices::getInstance()->getCore()->createThread(runner);
 							
 #if defined(__APPLE__) && defined(__MACH__)
 	CocoaCore *cocoaCore = (CocoaCore*) CoreServices::getInstance()->getCore();
@@ -112,7 +128,6 @@ void PolycodeToolLauncher::runPolyapp(String polyappPath) {
 	String polycodeBasePath = CoreServices::getInstance()->getCore()->getDefaultWorkingDirectory();
 	String command = polycodeBasePath+"/Standalone/Player/PolycodePlayer.app"; 
 	
-//	cocoaCore->launchApplicationWithFile(command, polyappPath);
 	cocoaCore->openFileWithApplication(polyappPath, command);
 #else
 	PolycodeRunner *runner = new PolycodeRunner(polyappPath);

+ 4 - 2
IDE/Contents/Source/SettingsWindow.cpp

@@ -32,7 +32,7 @@ SettingsWindow::SettingsWindow() : UIWindow(L"Settings", SETTINGS_WINDOW_WIDTH,
 	label->setPosition(padding, 50);
 
 
-	useExternalTextEditorBox = new UICheckBox("Use external text editor?", false);
+	useExternalTextEditorBox = new UICheckBox("Use external text editor", false);
 	addChild(useExternalTextEditorBox); 
 	useExternalTextEditorBox->setPosition(padding, 85);
 
@@ -84,6 +84,8 @@ void SettingsWindow::handleEvent(Event *event) {
 				CoreFileExtension ext;
 #ifdef _WINDOWS
 				ext.extension = "exe"
+#elif defined(__APPLE__) && defined(__MACH__)
+				ext.extension = "app";
 #else
 				ext.extension = "";
 #endif
@@ -91,7 +93,7 @@ void SettingsWindow::handleEvent(Event *event) {
 				extensions.push_back(ext);
 				std::vector<String> path = CoreServices::getInstance()->getCore()->openFilePicker(extensions, false);
 
-				if(path.size == 0) {
+				if(path.size() == 0) {
 					return;
 				}