mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-15 03:33:52 +00:00
Restructure reopening of Files. Introduced some regression with the welcome screen being shown too often.
This commit is contained in:
@@ -50,8 +50,14 @@
|
|||||||
|
|
||||||
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
|
- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag {
|
||||||
if(!flag) {
|
if(!flag) {
|
||||||
[self _loadWelcomeWindow];
|
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
||||||
[self.welcomeWindow orderFront:self];
|
BOOL showWelcomeScreen = YES;
|
||||||
|
if(reopen) {
|
||||||
|
showWelcomeScreen = ![self _reopenLastDocument];
|
||||||
|
}
|
||||||
|
if(showWelcomeScreen) {
|
||||||
|
[self _showWelcomeWindow];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@@ -70,7 +76,7 @@
|
|||||||
selector:@selector(_applicationDidFinishRestoringWindows:)
|
selector:@selector(_applicationDidFinishRestoringWindows:)
|
||||||
name:NSApplicationDidFinishRestoringWindowsNotification
|
name:NSApplicationDidFinishRestoringWindowsNotification
|
||||||
object:nil];
|
object:nil];
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,38 +87,18 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
- (void)applicationDidFinishLaunching:(NSNotification *)notification {
|
||||||
serverDaemon = [[MPServerDaemon alloc] init];
|
serverDaemon = [[MPServerDaemon alloc] init];
|
||||||
lockDaemon = [[MPLockDaemon alloc] init];
|
lockDaemon = [[MPLockDaemon alloc] init];
|
||||||
autotypeDaemon = [[MPAutotypeDaemon alloc] init];
|
autotypeDaemon = [[MPAutotypeDaemon alloc] init];
|
||||||
//autotypeDaemon = [[MPAutotypeDaemon alloc] init];
|
|
||||||
|
|
||||||
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
BOOL reopen = [[NSUserDefaults standardUserDefaults] boolForKey:kMPSettingsKeyReopenLastDatabaseOnLaunch];
|
||||||
|
BOOL showWelcomeScreen = !_shouldOpenFile;
|
||||||
if(reopen && !_restoredWindows && !_shouldOpenFile) {
|
if(reopen && !_restoredWindows && !_shouldOpenFile) {
|
||||||
NSDocumentController *documentController = [NSDocumentController sharedDocumentController];
|
showWelcomeScreen = ![self _reopenLastDocument];
|
||||||
NSArray *documents = [documentController documents];
|
}
|
||||||
if([documents count] > 0) {
|
if(showWelcomeScreen) {
|
||||||
return; // There's a document open
|
[self _showWelcomeWindow];
|
||||||
}
|
|
||||||
|
|
||||||
NSArray *recentDocuments = [documentController recentDocumentURLs];
|
|
||||||
NSURL *documentUrl;
|
|
||||||
if([recentDocuments count] > 0) {
|
|
||||||
documentUrl = recentDocuments[0];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
NSString *lastPath = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyLastDatabasePath];
|
|
||||||
documentUrl = [NSURL URLWithString:lastPath];
|
|
||||||
}
|
|
||||||
if([documentUrl isFileURL]) {
|
|
||||||
[documentController openDocumentWithContentsOfURL:documentUrl display:YES
|
|
||||||
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {}];
|
|
||||||
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
[self _loadWelcomeWindow];
|
|
||||||
[self.welcomeWindow orderFront:self];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -167,6 +153,11 @@
|
|||||||
_restoredWindows = [documents count] > 0;
|
_restoredWindows = [documents count] > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)_showWelcomeWindow {
|
||||||
|
[self _loadWelcomeWindow];
|
||||||
|
[self.welcomeWindow makeKeyAndOrderFront:nil];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)_loadWelcomeWindow {
|
- (void)_loadWelcomeWindow {
|
||||||
if(!_welcomeWindow) {
|
if(!_welcomeWindow) {
|
||||||
NSArray *topLevelObject;
|
NSArray *topLevelObject;
|
||||||
@@ -175,4 +166,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (BOOL)_reopenLastDocument {
|
||||||
|
NSDocumentController *documentController = [NSDocumentController sharedDocumentController];
|
||||||
|
NSArray *documents = [documentController documents];
|
||||||
|
if([documents count] > 0) {
|
||||||
|
return YES; // The document is already open
|
||||||
|
}
|
||||||
|
NSArray *recentDocuments = [[NSDocumentController sharedDocumentController] recentDocumentURLs];
|
||||||
|
NSURL *documentUrl = nil;
|
||||||
|
if([recentDocuments count] > 0) {
|
||||||
|
documentUrl = recentDocuments[0];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
NSString *lastPath = [[NSUserDefaults standardUserDefaults] stringForKey:kMPSettingsKeyLastDatabasePath];
|
||||||
|
documentUrl =[NSURL URLWithString:lastPath];
|
||||||
|
}
|
||||||
|
BOOL isFileURL = [documentUrl isFileURL];
|
||||||
|
if(isFileURL) {
|
||||||
|
[documentController openDocumentWithContentsOfURL:documentUrl
|
||||||
|
display:YES
|
||||||
|
completionHandler:^(NSDocument *document, BOOL documentWasAlreadyOpen, NSError *error) {}];
|
||||||
|
}
|
||||||
|
return isFileURL;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -56,7 +56,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>2528</string>
|
<string>2531</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user