Revision: 14665
http://sourceforge.net/p/skim-app/code/14665
Author: hofman
Date: 2024-11-10 15:57:57 +0000 (Sun, 10 Nov 2024)
Log Message:
-----------
Save recent documents as setup bookmarks. Remember snapshots in bookmark when
they are initialized with incomplete setup, for instance from old recent
document info. Use recent documents to get recently closed documents, filtering
out currently open documents. Also save recent document info for Skim notes
documents.
Modified Paths:
--------------
trunk/NSDocument_SKExtensions.m
trunk/SKBookmark.h
trunk/SKBookmark.m
trunk/SKBookmarkController.h
trunk/SKBookmarkController.m
trunk/SKMainDocument.m
trunk/SKMainWindowController_UI.m
trunk/SKNotesDocument.m
Modified: trunk/NSDocument_SKExtensions.m
===================================================================
--- trunk/NSDocument_SKExtensions.m 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/NSDocument_SKExtensions.m 2024-11-10 15:57:57 UTC (rev 14665)
@@ -95,8 +95,12 @@
#pragma mark Document Setup
-- (void)saveRecentDocumentInfo:(BOOL)forced {}
+- (void)saveRecentDocumentInfo:(BOOL)forced {
+ if (forced)
+ [[SKBookmarkController sharedBookmarkController]
addRecentDocument:self];
+}
+
- (void)applySetup:(NSDictionary *)setup {}
- (void)applyOptions:(NSDictionary *)options {}
Modified: trunk/SKBookmark.h
===================================================================
--- trunk/SKBookmark.h 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKBookmark.h 2024-11-10 15:57:57 UTC (rev 14665)
@@ -54,11 +54,11 @@
+ (NSArray *)bookmarksForURLs:(NSArray<NSURL *> *)urls;
-- (nullable instancetype)initWithURL:(NSURL *)aURL
pageIndex:(NSUInteger)aPageIndex label:(NSString *)aLabel;
-- (nullable instancetype)initWithSetup:(NSDictionary<NSString *, id>
*)aSetupDict label:(NSString *)aLabel;
-- (nullable instancetype)initFolderWithChildren:(nullable NSArray<SKBookmark
*> *)aChildren label:(NSString *)aLabel;
+- (nullable instancetype)initWithURL:(NSURL *)aURL
pageIndex:(NSUInteger)aPageIndex label:(nullable NSString *)aLabel;
+- (nullable instancetype)initWithSetup:(NSDictionary<NSString *, id>
*)aSetupDict label:(nullable NSString *)aLabel;
+- (nullable instancetype)initFolderWithChildren:(nullable NSArray<SKBookmark
*> *)aChildren label:(nullable NSString *)aLabel;
- (nullable instancetype)initRootWithChildrenProperties:(nullable
NSArray<NSDictionary<NSString *, id> *> *)childrenProperties;
-- (nullable instancetype)initSessionWithSetups:(NSArray<NSDictionary<NSString
*, id> *> *)aSetupDicts label:(NSString *)aLabel;
+- (nullable instancetype)initSessionWithSetups:(NSArray<NSDictionary<NSString
*, id> *> *)aSetupDicts label:(nullable NSString *)aLabel;
- (nullable instancetype)initSeparator;
- (nullable instancetype)initWithProperties:(NSDictionary<NSString *, id>
*)dictionary;
@@ -73,6 +73,7 @@
@property (nonatomic) NSUInteger pageIndex;
@property (nonatomic, nullable, strong) NSNumber *pageNumber;
@property (nonatomic, readonly) BOOL hasSetup;
+@property (nonatomic, nullable, readonly) NSArray<NSDictionary<NSString *, id>
*> *snapshots;
@property (nonatomic, nullable, readonly) NSString *tabs;
@property (nonatomic, nullable, weak) SKBookmark *parent;
@property (nonatomic, readonly) NSArray<SKBookmark *> *containingBookmarks;
Modified: trunk/SKBookmark.m
===================================================================
--- trunk/SKBookmark.m 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKBookmark.m 2024-11-10 15:57:57 UTC (rev 14665)
@@ -60,6 +60,7 @@
#define ALIASDATA_KEY @"_BDAlias"
#define BOOKMARK_KEY @"bookmark"
#define TYPE_KEY @"type"
+#define SNAPSHOTS_KEY @"snapshots"
@interface SKPlaceholderBookmark : SKBookmark
@end
@@ -92,7 +93,7 @@
@implementation SKBookmark
@synthesize parent;
-@dynamic properties, bookmarkType, label, icon, alternateIcon, fileURL,
fileURLToOpen, fileDescription, toolTip, pageIndex, pageNumber, hasSetup, tabs,
containingBookmarks, children, countOfChildren, scriptingParent,
entireContents, bookmarks, expanded, skimURL;
+@dynamic properties, bookmarkType, label, icon, alternateIcon, fileURL,
fileURLToOpen, fileDescription, toolTip, pageIndex, pageNumber, hasSetup,
snapshots, tabs, containingBookmarks, children, countOfChildren,
scriptingParent, entireContents, bookmarks, expanded, skimURL;
static Class SKBookmarkClass = Nil;
@@ -205,6 +206,9 @@
- (BOOL)hasSetup { return NO; }
+- (NSArray *)snapshots { return nil; }
+- (NSString *)tabs { return nil; }
+
- (NSArray *)containingBookmarks { return @[]; }
- (NSArray *)children { return nil; }
@@ -463,8 +467,11 @@
if ([aSetupDict objectForKey:SKDocumentSetupWindowFrameKey]) {
setup = [aSetupDict mutableCopy];
[(NSMutableDictionary *)setup
removeObjectsForKeys:@[ALIASDATA_KEY, BOOKMARK_KEY, PAGEINDEX_KEY, LABEL_KEY]];
- } else
+ } else if ([aSetupDict objectForKey:SNAPSHOTS_KEY]) {
+ setup = @{SNAPSHOTS_KEY:[aSetupDict
objectForKey:SNAPSHOTS_KEY]};
+ } else {
setup = nil;
+ }
} else {
self = nil;
}
@@ -554,9 +561,13 @@
}
- (BOOL)hasSetup {
- return setup != nil;
+ return [setup objectForKey:SKDocumentSetupWindowFrameKey] != nil;
}
+- (NSArray *)snapshots {
+ return [setup objectForKey:SNAPSHOTS_KEY];
+}
+
- (NSString *)tabs {
return [setup objectForKey:SKDocumentSetupTabsKey];
}
Modified: trunk/SKBookmarkController.h
===================================================================
--- trunk/SKBookmarkController.h 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKBookmarkController.h 2024-11-10 15:57:57 UTC (rev 14665)
@@ -42,7 +42,7 @@
NS_ASSUME_NONNULL_BEGIN
-@class SKBookmark, SKRecentDocumentInfo, SKStatusBar;
+@class SKBookmark, SKStatusBar;
@interface SKBookmarkController : NSWindowController <NSWindowDelegate,
NSToolbarDelegate, NSMenuDelegate, SKOutlineViewDelegate,
NSOutlineViewDataSource, QLPreviewPanelDataSource, QLPreviewPanelDelegate,
NSTouchBarDelegate> {
SKOutlineView *outlineView;
@@ -56,8 +56,7 @@
NSButton *previewButton;
SKBookmark *bookmarkRoot;
SKBookmark *previousSession;
- SKBookmark *closedDocuments;
- NSMutableArray<SKRecentDocumentInfo *> *recentDocuments;
+ NSMutableArray<SKBookmark *> *recentDocuments;
NSUndoManager *undoManager;
NSArray<SKBookmark *> *draggedBookmarks;
NSDictionary<NSString *, NSToolbarItem *> *toolbarItems;
@@ -92,9 +91,7 @@
- (void)removeBookmarkAtIndex:(NSUInteger)anIndex ofBookmark:(SKBookmark
*)parent animate:(BOOL)animate;
- (void)replaceBookmarkAtIndex:(NSUInteger)anIndex ofBookmark:(SKBookmark
*)parent withBookmark:(SKBookmark *)bookmark animate:(BOOL)animate;
-- (void)addClosedDocumentWithSetup:(NSDictionary<NSString *, id> *)setup;
-
-- (void)addRecentDocumentForURL:(NSURL *)fileURL
pageIndex:(NSUInteger)pageIndex snapshots:(nullable
NSArray<NSDictionary<NSString *, id> *> *)setups;
+- (BOOL)addRecentDocument:(NSDocument *)document;
- (NSUInteger)pageIndexForRecentDocumentAtURL:(NSURL *)fileURL;
- (NSArray<NSDictionary<NSString *, id> *>
*)snapshotsForRecentDocumentAtURL:(NSURL *)fileURL;
Modified: trunk/SKBookmarkController.m
===================================================================
--- trunk/SKBookmarkController.m 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKBookmarkController.m 2024-11-10 15:57:57 UTC (rev 14665)
@@ -52,8 +52,8 @@
#import "NSView_SKExtensions.h"
#import "NSError_SKExtensions.h"
#import "SKDocumentController.h"
-#import "SKRecentDocumentInfo.h"
#import "NSPasteboard_SKExtensions.h"
+#import "NSDocument_SKExtensions.h"
#define SKPasteboardTypeBookmarkRow
@"net.sourceforge.skim-app.pasteboard.bookmarkrow"
@@ -158,7 +158,7 @@
recentDocuments = [[NSMutableArray alloc] init];
for (NSDictionary *dict in [bookmarkDictionary
objectForKey:RECENTDOCUMENTS_KEY]) {
- SKRecentDocumentInfo *info = [[SKRecentDocumentInfo alloc]
initWithProperties:dict];
+ SKBookmark *info = [[SKBookmark alloc]
initWithProperties:dict];
[recentDocuments addObject:info];
}
@@ -231,23 +231,17 @@
- (void)saveBookmarksData {
if (bookmarksCache == nil)
bookmarksCache = [[bookmarkRoot children] valueForKey:@"properties"];
- NSDictionary *bookmarksDictionary = @{BOOKMARKS_KEY:bookmarksCache,
RECENTDOCUMENTS_KEY:[recentDocuments valueForKey:@"properties"]};
+ NSUInteger maxCount = MAX(maxRecentDocumentsCount, [[[NSDocumentController
sharedDocumentController] documents] count]);
+ NSArray *recents = [recentDocuments count] > maxCount ? [recentDocuments
subarrayWithRange:NSMakeRange(0, maxCount)] : recentDocuments;
+ NSDictionary *bookmarksDictionary = @{BOOKMARKS_KEY:bookmarksCache,
RECENTDOCUMENTS_KEY:[recents valueForKey:@"properties"]};
[[NSUserDefaults standardUserDefaults]
setPersistentDomain:bookmarksDictionary forName:SKBookmarksIdentifier];
}
-#pragma mark Closed Documents
-
-- (void)addClosedDocumentWithSetup:(NSDictionary *)setup {
- if (closedDocuments == nil)
- closedDocuments = [[SKBookmark alloc] initFolderWithChildren:nil
label:NSLocalizedString(@"Recently Closed", @"Menu item title")];
- [closedDocuments insertObject:[[SKBookmark alloc] initWithSetup:setup
label:@""] inChildrenAtIndex:0];
-}
-
#pragma mark Recent Documents
-- (SKRecentDocumentInfo *)recentDocumentInfoAtURL:(NSURL *)fileURL {
+- (SKBookmark *)recentDocumentAtURL:(NSURL *)fileURL {
NSString *path = [fileURL path];
- for (SKRecentDocumentInfo *info in recentDocuments) {
+ for (SKBookmark *info in recentDocuments) {
if ([[[info fileURL] path] isCaseInsensitiveEqual:path])
return info;
}
@@ -254,32 +248,36 @@
return nil;
}
-- (void)addRecentDocumentForURL:(NSURL *)fileURL
pageIndex:(NSUInteger)pageIndex snapshots:(NSArray *)setups {
- if (fileURL == nil)
- return;
-
- SKRecentDocumentInfo *info = [[SKRecentDocumentInfo alloc]
initWithURL:fileURL pageIndex:pageIndex snapshots:setups];
- if (info) {
- SKRecentDocumentInfo *oldInfo = [self recentDocumentInfoAtURL:fileURL];
- if (oldInfo)
- [recentDocuments removeObjectIdenticalTo:oldInfo];
- [recentDocuments insertObject:info atIndex:0];
- NSUInteger maxCount = MAX(maxRecentDocumentsCount,
[[[NSDocumentController sharedDocumentController] documents] count]);
- while ([recentDocuments count] > maxCount)
- [recentDocuments removeLastObject];
+- (BOOL)addRecentDocument:(NSDocument *)document {
+ NSURL *fileURL = [document fileURL];
+ if (fileURL) {
+ SKBookmark *info = [[SKBookmark alloc] initWithSetup:[document
currentDocumentSetup] label:nil];
+ if (info) {
+ SKBookmark *oldInfo = [self recentDocumentAtURL:fileURL];
+ if (oldInfo)
+ [recentDocuments removeObjectIdenticalTo:oldInfo];
+ [recentDocuments insertObject:info atIndex:0];
+ NSUInteger maxCount = maxRecentDocumentsCount +
[[[NSDocumentController sharedDocumentController] documents] count];
+ while ([recentDocuments count] > maxCount)
+ [recentDocuments removeLastObject];
+
+ [[self class] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(saveBookmarksData) object:nil];
+ [self performSelector:@selector(saveBookmarksData) withObject:nil
afterDelay:SAVE_DELAY];
+
+ return YES;
+ }
}
- [[self class] cancelPreviousPerformRequestsWithTarget:self
selector:@selector(saveBookmarksData) object:nil];
- [self performSelector:@selector(saveBookmarksData) withObject:nil
afterDelay:SAVE_DELAY];
+ return NO;
}
- (NSUInteger)pageIndexForRecentDocumentAtURL:(NSURL *)fileURL {
- SKRecentDocumentInfo *info = fileURL ? [self
recentDocumentInfoAtURL:fileURL] : nil;
+ SKBookmark *info = fileURL ? [self recentDocumentAtURL:fileURL] : nil;
return info ? [info pageIndex] : NSNotFound;
}
- (NSArray *)snapshotsForRecentDocumentAtURL:(NSURL *)fileURL {
- return fileURL ? [[self recentDocumentInfoAtURL:fileURL] snapshots] : nil;
+ return fileURL ? [[self recentDocumentAtURL:fileURL] snapshots] : nil;
}
#pragma mark Bookmarks support
@@ -667,6 +665,16 @@
currentDocument = [[SKBookmark alloc]
initFolderWithChildren:[[NSArray alloc] initWithArray:currentBookmarks
copyItems:YES] label:NSLocalizedString(@"Current Document", @"Menu item
title")];
}
}
+ SKBookmark *closedDocuments = nil;
+ NSArray *openFileURLs = [[[NSDocumentController
sharedDocumentController] documents] valueForKey:@"fileURL"];
+ NSMutableArray *closedBms = [NSMutableArray array];
+ for (SKBookmark *aBm in recentDocuments) {
+ fileURL = [aBm fileURL];
+ if (fileURL && ([closedBms count] > 0 || [openFileURLs
containsObject:fileURL] == NO))
+ [closedBms addObject:aBm];
+ }
+ if ([closedBms count] > 0)
+ closedDocuments = [[SKBookmark alloc]
initFolderWithChildren:closedBms label:NSLocalizedString(@"Recently Closed",
@"Menu item title")];
if (previousSession || closedDocuments || currentDocument)
[menu addItem:[NSMenuItem separatorItem]];
if (previousSession) {
@@ -698,8 +706,7 @@
[menu addItem:[NSMenuItem separatorItem]];
break;
default:
- if ((bm != closedDocuments && bm != previousSession)
|| [aBm fileURL] != nil)
- [self addItemForBookmark:aBm toMenu:menu
isFolder:NO isAlternate:NO];
+ [self addItemForBookmark:aBm toMenu:menu isFolder:NO
isAlternate:NO];
break;
}
}
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKMainDocument.m 2024-11-10 15:57:57 UTC (rev 14665)
@@ -235,12 +235,8 @@
- (void)saveRecentDocumentInfo:(BOOL)forced {
if (forced || [[self mainWindowController] recentInfoNeedsUpdate]) {
- NSURL *fileURL = [self fileURL];
- NSUInteger pageIndex = [[[self pdfView] currentPage] pageIndex];
- if (fileURL && pageIndex != NSNotFound) {
- [[SKBookmarkController sharedBookmarkController]
addRecentDocumentForURL:fileURL pageIndex:pageIndex snapshots:[[[self
mainWindowController] snapshots] valueForKey:SKSnapshotCurrentSetupKey]];
+ if ([[SKBookmarkController sharedBookmarkController]
addRecentDocument:self])
[[self mainWindowController] setRecentInfoNeedsUpdate:NO];
- }
}
}
Modified: trunk/SKMainWindowController_UI.m
===================================================================
--- trunk/SKMainWindowController_UI.m 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKMainWindowController_UI.m 2024-11-10 15:57:57 UTC (rev 14665)
@@ -251,8 +251,6 @@
- (void)windowWillClose:(NSNotification *)notification {
if ([[notification object] isEqual:[self window]]) {
[[self document] saveRecentDocumentInfo:YES];
- if ([[self document] fileURL])
- [[SKBookmarkController sharedBookmarkController]
addClosedDocumentWithSetup:[[self document] currentDocumentSetup]];
if ([[pdfView document] isFinding])
[[pdfView document] cancelFindString];
if ((mwcFlags.isEditingTable || [pdfView isEditing]) && [self
commitEditing] == NO)
Modified: trunk/SKNotesDocument.m
===================================================================
--- trunk/SKNotesDocument.m 2024-11-10 09:56:34 UTC (rev 14664)
+++ trunk/SKNotesDocument.m 2024-11-10 15:57:57 UTC (rev 14665)
@@ -195,8 +195,7 @@
- (void)windowWillClose:(NSNotification *)notification {
[pdfDocument setContainingDocument:nil];
- if ([self fileURL])
- [[SKBookmarkController sharedBookmarkController]
addClosedDocumentWithSetup:[self currentDocumentSetup]];
+ [self saveRecentDocumentInfo:YES];
}
- (void)windowDidResize:(NSNotification *)notification {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit