Commits

Jason Harris committed a1921f7

- Fix issue 48. By default save the first untitled document as ~/Application
Support/MacHg/Repositories.mchg so that the user will not be questioned to save the
document, however the user can open other documents if they so choose to and MacHg will
still open the most recently used document, its just that if the user wants a single
document and wants to use it more like Mail, or ical, or itunes, which only really have
one document then they can. See the discussion in the bug report.

Comments (0)

Files changed (1)

Classes/Application/AppController.m

 		[[self theInitilizationWizardController] showWizard];	
 }
 
-- (NSString*) applicationSupportFolder;
+- (NSString*) applicationSupportVersionedFolder;
 {
 	NSArray* searchPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
 	NSString* applicationSupportFolder = [searchPaths objectAtIndex:0];
 	return [NSString stringWithFormat:@"%@/%@/%@", applicationSupportFolder, [[NSProcessInfo processInfo] processName], [self shortVersionNumberString]];
 }
 
+- (NSString*) applicationSupportFolder;
+{
+	NSArray* searchPaths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES);
+	NSString* applicationSupportFolder = [searchPaths objectAtIndex:0];
+	return fstr(@"%@/%@", applicationSupportFolder, [[NSProcessInfo processInfo] processName]);
+}
+
+
 
 - (void) checkConfigFileForEditingExtensions:(BOOL)onStartup;
 {
 
 	// Create the named versioned application support extensions directory
 	NSError* theError;
-	NSString* supportFolder = [[self applicationSupportFolder] stringByAppendingPathComponent:@"extensions"];
+	NSString* supportFolder = [[self applicationSupportVersionedFolder] stringByAppendingPathComponent:@"extensions"];
 	[fileManager createDirectoryAtPath:supportFolder withIntermediateDirectories:YES attributes:nil error:&theError];
 	
 	NSString* histeditDest = [supportFolder stringByAppendingPathComponent:@"histedit.py"];
 				if ([[NSFileManager defaultManager] fileExistsAtPath:[url path]])
 					if ([docController openDocumentWithContentsOfURL:url display:YES error:nil])
 						return NO;
+
+		// look for ~/Application Support/MacHg/Repositories.machg
+		NSString* defaultDocumentPath = fstr(@"%@/Repositories.mchg",[self applicationSupportFolder]);
+		NSURL* defaultURL = [NSURL fileURLWithPath:defaultDocumentPath];
+		if ([[NSFileManager defaultManager] fileExistsAtPath:[defaultURL path]])
+			if ([docController openDocumentWithContentsOfURL:defaultURL display:YES error:nil])
+				return NO;
+
+		// create document ~/Application Support/MacHg/Repositories.machg
+		NSError* err = nil;
+		MacHgDocument* newDoc = [docController openUntitledDocumentAndDisplay:YES error:&err];
+		if (newDoc)
+		{
+			[newDoc saveToURL:defaultURL ofType:@"MacHgDocument" forSaveOperation:NSSaveAsOperation error:&err];
+			[newDoc showWindows];
+			return NO;
+		}
+		return YES;
 	}
+
 	startingUp = NO;
 	
 	if (OnStartupOpenFromDefaults() == eDontOpenAnything)