mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-18 06:29:30 +00:00
Only store last document, when MacPass is terminating
Moved code from MPDocument to MPDocumentController
This commit is contained in:
@@ -36,8 +36,9 @@ APPKIT_EXTERN NSString *const MPDidChangeStoredKeyFilesSettings;
|
||||
@property (strong) IBOutlet NSMenu *exportMenu;
|
||||
|
||||
@property (strong, readonly) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
||||
@property (readonly) BOOL isTerminating;
|
||||
|
||||
@property (nonatomic, assign) BOOL isAllowedToStoreKeyFile;
|
||||
@property (nonatomic) BOOL isAllowedToStoreKeyFile;
|
||||
|
||||
- (IBAction)checkForUpdates:(id)sender;
|
||||
- (IBAction)showPreferences:(id)sender;
|
||||
|
||||
@@ -92,6 +92,7 @@ typedef NS_OPTIONS(NSInteger, MPAppStartupState) {
|
||||
_userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init];
|
||||
self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||
_shouldOpenFile = NO;
|
||||
_isTerminating = NO;
|
||||
self.startupState = MPAppStartupStateNone;
|
||||
|
||||
[NSNotificationCenter.defaultCenter addObserver:self
|
||||
@@ -185,6 +186,7 @@ typedef NS_OPTIONS(NSInteger, MPAppStartupState) {
|
||||
}
|
||||
|
||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
||||
_isTerminating = YES;
|
||||
[self hideWelcomeWindow];
|
||||
if(MPTemporaryFileStorageCenter.defaultCenter.hasPendingStorages) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
|
||||
@@ -240,13 +240,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
||||
|
||||
- (void)close {
|
||||
[self _cleanupLock];
|
||||
/*
|
||||
We store the last url. Restored windows are automatically handled.
|
||||
If closeAllDocuments is set, all docs get this message
|
||||
*/
|
||||
if(self.fileURL.isFileURL) {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:self.fileURL.absoluteString forKey:kMPSettingsKeyLastDatabasePath];
|
||||
}
|
||||
self.tree = nil;
|
||||
[super close];
|
||||
}
|
||||
|
||||
@@ -83,6 +83,16 @@
|
||||
[super addDocument:document];
|
||||
}
|
||||
|
||||
- (void)removeDocument:(NSDocument *)document {
|
||||
MPAppDelegate *appDelegate = (MPAppDelegate *)NSApp.delegate;
|
||||
if(appDelegate.isTerminating) {
|
||||
if(document.fileURL.isFileURL) {
|
||||
[[NSUserDefaults standardUserDefaults] setObject:document.fileURL.absoluteString forKey:kMPSettingsKeyLastDatabasePath];
|
||||
}
|
||||
}
|
||||
[super removeDocument:document];
|
||||
}
|
||||
|
||||
- (BOOL)reopenLastDocument {
|
||||
if(self.documents.count > 0) {
|
||||
return YES; // The document is already open
|
||||
@@ -93,7 +103,12 @@
|
||||
}
|
||||
else {
|
||||
NSString *lastPath = [NSUserDefaults.standardUserDefaults stringForKey:kMPSettingsKeyLastDatabasePath];
|
||||
documentUrl =[NSURL URLWithString:lastPath];
|
||||
documentUrl = [NSURL URLWithString:lastPath];
|
||||
NSError *error;
|
||||
if(![documentUrl checkResourceIsReachableAndReturnError:&error]) {
|
||||
[NSUserDefaults.standardUserDefaults removeObjectForKey:kMPSettingsKeyLastDatabasePath];
|
||||
documentUrl = nil;
|
||||
}
|
||||
}
|
||||
BOOL isFileURL = documentUrl.fileURL;
|
||||
if(isFileURL) {
|
||||
|
||||
Reference in New Issue
Block a user