Explorar o código

IDE Project icon and Mac file association

Ivan Safrin %!s(int64=13) %!d(string=hai) anos
pai
achega
e2023b4b52

BIN=BIN
Assets/Icons/file_icon_base.psd


BIN=BIN
Assets/Icons/polycode_project.icns


BIN=BIN
Assets/Icons/polycode_project.png


+ 15 - 0
IDE/Build/Mac OS X/Polycode-Info.plist

@@ -28,5 +28,20 @@
 	<string>MainMenu</string>
 	<key>NSPrincipalClass</key>
 	<string>NSApplication</string>
+	<key>CFBundleDocumentTypes</key>
+	<array>
+		<dict>
+			<key>CFBundleTypeIconFile</key>
+			<string>polycode_project</string>
+			<key>CFBundleTypeExtensions</key>
+			<array>
+				<string>polyproject</string>
+			</array>
+			<key>CFBundleTypeName</key>
+			<string>Polycode Project</string>
+			<key>CFBundleTypeRole</key>
+			<string>Editor</string>
+		</dict>
+	</array>
 </dict>
 </plist>

+ 4 - 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 */; };
+		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 */; };
 		6D3B6C5B14B820A900727F17 /* ToolWindows.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 6D3B6C5A14B820A900727F17 /* ToolWindows.cpp */; };
@@ -76,6 +77,7 @@
 		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>"; };
+		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>"; };
 		6D34143312B816BC0034FA9B /* IOKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = IOKit.framework; path = System/Library/Frameworks/IOKit.framework; sourceTree = SDKROOT; };
@@ -237,6 +239,7 @@
 		29B97317FDCFA39411CA2CEA /* Resources */ = {
 			isa = PBXGroup;
 			children = (
+				6D1CD96A164D9568006CDAB1 /* polycode_project.icns */,
 				6DFF77A9164090040040AED8 /* hdr.pak */,
 				6DFE89CB14B3FE3D00DA7ABD /* default.pak */,
 				6D8A55B814B3EABB005F6411 /* main_icon.icns */,
@@ -372,6 +375,7 @@
 				6D8A55B914B3EABB005F6411 /* main_icon.icns in Resources */,
 				6DFE89CC14B3FE3D00DA7ABD /* default.pak in Resources */,
 				6DFF77AA164090040040AED8 /* hdr.pak in Resources */,
+				6D1CD96B164D9568006CDAB1 /* polycode_project.icns in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};

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

@@ -40,6 +40,7 @@ public:
 	
 	NSMenu *projectMenu;
 	
+	String fileToOpen;
 	BOOL mustShowProjectMenu;
 }
 

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

@@ -14,6 +14,11 @@
 @synthesize polycodeView;
 @synthesize projectMenu;
 
+- (id) init {
+	app = NULL;
+	return [super init];
+}
+
 - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
 	// Insert code here to initialize your application 
 	
@@ -25,6 +30,10 @@
 	app = new PolycodeIDEApp(polycodeView);
 	app->addEventListener(eventHandler, PolycodeIDEApp::EVENT_SHOW_MENU);
 	
+	if(fileToOpen != "") {
+		app->openProject(fileToOpen);
+	}
+	
 	timer = [NSTimer timerWithTimeInterval:(1.0f/90.0f) target:self selector:@selector(animationTimer:) userInfo:nil repeats:YES];
 	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode];
 	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSEventTrackingRunLoopMode]; // ensure timer fires during resize	
@@ -71,6 +80,19 @@
 	return YES;
 }
 
+- (BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
+{
+	// this gets called before applicationDidFinishLaunching if 
+	// user double-clicks the file to open the app
+	
+	if(app) {
+		app->openProject([filename cStringUsingEncoding:NSUTF8StringEncoding]);
+	} else {
+		fileToOpen = [filename cStringUsingEncoding:NSUTF8StringEncoding];
+	}
+	return YES;
+}
+
 -(IBAction) refreshProject: (id) sender {
 	app->refreshProject();
 }	

+ 4 - 0
IDE/Contents/Include/PolycodeIDEApp.h

@@ -74,6 +74,10 @@ public:
 	void runProject();
 	void exportProject();
 	
+	// system callbacks
+	
+	void openProject(String projectFile);
+	
 	void refreshProject();	
 	
 	const static int EVENT_SHOW_MENU = 1;

+ 4 - 0
IDE/Contents/Source/PolycodeIDEApp.cpp

@@ -213,6 +213,10 @@ void PolycodeIDEApp::saveFile() {
 	}
 }
 
+void PolycodeIDEApp::openProject(String projectFile) {
+	projectManager->openProject(projectFile);
+}
+
 void PolycodeIDEApp::openFileInProject(PolycodeProject *project, String filePath) {
 	OSFileEntry fileEntry = OSFileEntry(project->getRootFolder()+"/"+filePath, OSFileEntry::TYPE_FILE);	
 	OSFILE *file = OSBasics::open(project->getRootFolder()+"/"+filePath,"r");

+ 7 - 0
IDE/Contents/Source/PolycodeProjectManager.cpp

@@ -35,6 +35,13 @@ PolycodeProjectManager::~PolycodeProjectManager() {
 
 
 PolycodeProject* PolycodeProjectManager::openProject(String path) {
+
+	for(int i=0; i < projects.size(); i++) {
+		if(projects[i]->getProjectFile() == path) {
+			return projects[i];
+		}
+	}	
+
 	printf("Opening project  %s\n", path.c_str());
 	
 	FILE *f = fopen(path.c_str(), "r");