mirror of
https://github.com/MacPass/MacPass.git
synced 2026-02-01 11:28:15 +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) IBOutlet NSMenu *exportMenu;
|
||||||
|
|
||||||
@property (strong, readonly) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
@property (strong, readonly) MPEntryContextMenuDelegate *itemActionMenuDelegate;
|
||||||
|
@property (readonly) BOOL isTerminating;
|
||||||
|
|
||||||
@property (nonatomic, assign) BOOL isAllowedToStoreKeyFile;
|
@property (nonatomic) BOOL isAllowedToStoreKeyFile;
|
||||||
|
|
||||||
- (IBAction)checkForUpdates:(id)sender;
|
- (IBAction)checkForUpdates:(id)sender;
|
||||||
- (IBAction)showPreferences:(id)sender;
|
- (IBAction)showPreferences:(id)sender;
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ typedef NS_OPTIONS(NSInteger, MPAppStartupState) {
|
|||||||
_userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init];
|
_userNotificationCenterDelegate = [[MPUserNotificationCenterDelegate alloc] init];
|
||||||
self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
self.itemActionMenuDelegate = [[MPEntryContextMenuDelegate alloc] init];
|
||||||
_shouldOpenFile = NO;
|
_shouldOpenFile = NO;
|
||||||
|
_isTerminating = NO;
|
||||||
self.startupState = MPAppStartupStateNone;
|
self.startupState = MPAppStartupStateNone;
|
||||||
|
|
||||||
[NSNotificationCenter.defaultCenter addObserver:self
|
[NSNotificationCenter.defaultCenter addObserver:self
|
||||||
@@ -185,6 +186,7 @@ typedef NS_OPTIONS(NSInteger, MPAppStartupState) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender {
|
||||||
|
_isTerminating = YES;
|
||||||
[self hideWelcomeWindow];
|
[self hideWelcomeWindow];
|
||||||
if(MPTemporaryFileStorageCenter.defaultCenter.hasPendingStorages) {
|
if(MPTemporaryFileStorageCenter.defaultCenter.hasPendingStorages) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
|
|||||||
@@ -240,13 +240,6 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGrou
|
|||||||
|
|
||||||
- (void)close {
|
- (void)close {
|
||||||
[self _cleanupLock];
|
[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;
|
self.tree = nil;
|
||||||
[super close];
|
[super close];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,6 +83,16 @@
|
|||||||
[super addDocument:document];
|
[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 {
|
- (BOOL)reopenLastDocument {
|
||||||
if(self.documents.count > 0) {
|
if(self.documents.count > 0) {
|
||||||
return YES; // The document is already open
|
return YES; // The document is already open
|
||||||
@@ -93,7 +103,12 @@
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
NSString *lastPath = [NSUserDefaults.standardUserDefaults stringForKey:kMPSettingsKeyLastDatabasePath];
|
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;
|
BOOL isFileURL = documentUrl.fileURL;
|
||||||
if(isFileURL) {
|
if(isFileURL) {
|
||||||
|
|||||||
Reference in New Issue
Block a user