Revision: 28817
http://sourceforge.net/p/bibdesk/svn/28817
Author: hofman
Date: 2024-02-25 16:01:10 +0000 (Sun, 25 Feb 2024)
Log Message:
-----------
Allow passing a placeholder URL for a missing file to the fileview, to provide
a title and tooltip for the icon
Modified Paths:
--------------
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h
trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h 2024-02-25
09:20:36 UTC (rev 28816)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.h 2024-02-25
16:01:10 UTC (rev 28817)
@@ -420,6 +420,11 @@
When the delegate handles downloads, it is responsible for adding back its
progress indicators. */
- (void)resetProgressIndicators;
+/** Returns a placeholder URL for a missing file.
+
+ The path can be an absolute or relative path, or an empty string or nil.
Allows providng a title and tool tip for missing files. This is also used
internally when a nil or NSNull URL is provided. */
++ (NSURL *)missingFileURLWithPath:(NSString *)path;
+
@end
/** @var FVZoomInMenuItemTag
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2024-02-25
09:20:36 UTC (rev 28816)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVFileView.m 2024-02-25
16:01:10 UTC (rev 28817)
@@ -3156,7 +3156,7 @@
- (void)_openURLs:(NSArray *)URLs
{
for (NSURL *aURL in URLs) {
- if ([aURL isEqual:[FVIcon missingFileURL]] == NO &&
+ if ([FVIcon isMissingFileURL:aURL] == NO &&
([[self delegate]
respondsToSelector:@selector(fileView:shouldOpenURL:)] == NO ||
[[self delegate] fileView:self shouldOpenURL:aURL] == YES))
[[NSWorkspace sharedWorkspace] openURL:aURL];
@@ -3177,7 +3177,9 @@
if ([theURL isFileURL]) {
[theURL getResourceValue:&name forKey:NSURLLocalizedNameKey
error:NULL];
if (name == nil)
- name = [[theURL path] lastPathComponent];
+ name = [theURL lastPathComponent];
+ } else if ([FVIcon isMissingFileURL:theURL]) {
+ name = [theURL lastPathComponent];
} else {
#if defined(MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_9
name = [[theURL absoluteString] stringByRemovingPercentEncoding];
@@ -3296,7 +3298,7 @@
if ([event clickCount] > 1 && i != NSNotFound) {
if (flags & NSEventModifierFlagOption) {
NSURL *aURL = [self URLAtIndex:i];
- if (aURL && NO == [aURL isEqual:[FVIcon missingFileURL]])
+ if (aURL && NO == [FVIcon isMissingFileURL:aURL])
[self _previewURL:aURL forIconInRect:[self
_rectOfIconInRow:r column:c]];
} else {
[self openSelectedURLs:self];
@@ -3834,7 +3836,7 @@
SEL action = [anItem action];
// generally only check this for actions that are dependent on single
selection
- BOOL isMissing = [aURL isEqual:[FVIcon missingFileURL]];
+ BOOL isMissing = [FVIcon isMissingFileURL:aURL];
BOOL isEditable = [self isEditable];
NSUInteger selectionCount = [_selectionIndexes count];
@@ -3874,7 +3876,7 @@
if (selectionCount > 1) {
for (NSURL *url in [self _selectedURLs]) {
// if we find a single file URL that isn't the missing file
URL, enable the menu
- if ([url isEqual:[FVIcon missingFileURL]] == NO && [url
isFileURL])
+ if ([FVIcon isMissingFileURL:url] == NO && [url isFileURL])
enabled = YES;
}
}
@@ -4690,6 +4692,18 @@
}
}
++ (NSURL *)missingFileURLWithPath:(NSString *)path {
+ if ([path length] == 0)
+ return [FVIcon missingFileURL];
+#if defined(MAC_OS_X_VERSION_10_9) && MAC_OS_X_VERSION_MIN_REQUIRED >=
MAC_OS_X_VERSION_10_9
+ path = [path
stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet
URLPathAllowedCharacterSet]];
+#else
+ path = [path
stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
+#endif
+ NSString *prefix = [path isAbsolutePath] ? @"x-missing-file://localhost" :
@"x-missing-file://localhost/";
+ return [NSURL URLWithString:[prefix stringByAppendingString:path]];
+}
+
@end
#pragma mark -
@@ -4706,9 +4720,11 @@
NSString *name = nil;
[aURL getResourceValue:&name forKey:NSURLLocalizedNameKey
error:NULL];
if (name == nil)
- _name = [[aURL path] lastPathComponent];
+ _name = [aURL lastPathComponent];
else
_name = [name copy];
+ } else if ([FVIcon isMissingFileURL:aURL]) {
+ _name = [aURL lastPathComponent];
} else {
NSString *name = [aURL absoluteString];
NSRange range = [name rangeOfString:@"://"];
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h 2024-02-25 09:20:36 UTC
(rev 28816)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.h 2024-02-25 16:01:10 UTC
(rev 28817)
@@ -150,6 +150,11 @@
@return A URL that is appropriate for a missing file to be passed to
iconWithURL:. Don't rely on the scheme or path for anything. */
+ (NSURL *)missingFileURL;
+/** Returns whether the URL represents a missing file.
+
+ @return Is the scheme equalto the scheme used for missing files? */
++ (BOOL)isMissingFileURL:(NSURL *)aURL;
+
/** Only public factory method.
Decides which concrete subclass to return based on the scheme and/or UTI of
the URL or its target.
Modified: trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m
===================================================================
--- trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m 2024-02-25 09:20:36 UTC
(rev 28816)
+++ trunk/bibdesk_vendorsrc/amaxwell/FileView/FVIcon.m 2024-02-25 16:01:10 UTC
(rev 28817)
@@ -63,7 +63,7 @@
FVIconClass = self;
- _missingFileURL = [[NSURL alloc]
initWithString:@"x-fileview://localhost/missing"];
+ _missingFileURL = [[NSURL alloc]
initWithString:@"x-missing-file://localhost/missing"];
[self _initializeCategory];
}
@@ -126,6 +126,11 @@
return _missingFileURL;
}
++ (BOOL)isMissingFileURL:(NSURL *)aURL;
+{
+ return [[aURL scheme] isEqualToString:@"x-missing-file"];
+}
+
+ (id)iconWithURL:(NSURL *)representedURL;
{
return [[self alloc] initWithURL:representedURL];
@@ -157,7 +162,7 @@
NSParameterAssert(nil != representedURL);
// newWithURLScheme: requires a scheme, so there's not much we can do
without it
- if ([representedURL isEqual:_missingFileURL] || nil == [representedURL
scheme]) {
+ if ([FVIcon isMissingFileURL:representedURL] || nil == [representedURL
scheme]) {
return (id)[FVFinderIcon newMissing];
}
else if (NO == [representedURL isFileURL]) {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit