mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-03 03:00:42 +00:00
* Source/NSDocumentFrameworkPrivate.h,
* Source/NSDocumentController.m: Open recent menu to clear items that have been deleted whenever it reloads. Based on patch by Paul Landers <paul.landers@testplant.com>. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38242 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ef8a6da853
commit
c331982016
3 changed files with 92 additions and 47 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2014-12-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSDocumentFrameworkPrivate.h,
|
||||||
|
* Source/NSDocumentController.m:
|
||||||
|
Open recent menu to clear items that have been deleted whenever it reloads.
|
||||||
|
Based on patch by Paul Landers <paul.landers@testplant.com>.
|
||||||
|
|
||||||
2014-12-08 Fred Kiefer <FredKiefer@gmx.de>
|
2014-12-08 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/GSToolTips.m: Fixed two issues with tooltips.
|
* Source/GSToolTips.m: Fixed two issues with tooltips.
|
||||||
|
|
|
@ -277,42 +277,8 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
||||||
_documents = [[NSMutableArray alloc] init];
|
_documents = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
/* Get list of recent documents */
|
/* Get list of recent documents */
|
||||||
_recent_documents = [[NSUserDefaults standardUserDefaults]
|
[self _loadRecentDocuments];
|
||||||
objectForKey: NSRecentDocuments];
|
|
||||||
if (_recent_documents)
|
|
||||||
{
|
|
||||||
int i, count, max;
|
|
||||||
|
|
||||||
_recent_documents = [_recent_documents mutableCopy];
|
|
||||||
count = [_recent_documents count];
|
|
||||||
for (i = 0; i < count; i++)
|
|
||||||
{
|
|
||||||
NSString *str;
|
|
||||||
NSURL *url;
|
|
||||||
|
|
||||||
str = [_recent_documents objectAtIndex: i];
|
|
||||||
url = [NSURL URLWithString: str];
|
|
||||||
if (url == nil)
|
|
||||||
{
|
|
||||||
NSLog(@"NSRecentItems value '%@' is not valid ... ignored", str);
|
|
||||||
[_recent_documents removeObjectAtIndex: i];
|
|
||||||
i--;
|
|
||||||
count--;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[_recent_documents replaceObjectAtIndex: i withObject: url];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
max = [self maximumRecentDocumentCount];
|
|
||||||
if (count > max)
|
|
||||||
{
|
|
||||||
[_recent_documents removeObjectsInRange: NSMakeRange(0, count - max)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
_recent_documents = RETAIN([NSMutableArray array]);
|
|
||||||
[self setShouldCreateUI: YES];
|
[self setShouldCreateUI: YES];
|
||||||
|
|
||||||
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
[[[NSWorkspace sharedWorkspace] notificationCenter]
|
||||||
|
@ -1347,7 +1313,6 @@ static BOOL _shouldClose = YES;
|
||||||
- (void) noteNewRecentDocumentURL: (NSURL *)anURL
|
- (void) noteNewRecentDocumentURL: (NSURL *)anURL
|
||||||
{
|
{
|
||||||
NSUInteger index = [_recent_documents indexOfObject: anURL];
|
NSUInteger index = [_recent_documents indexOfObject: anURL];
|
||||||
NSMutableArray *a;
|
|
||||||
|
|
||||||
if (index != NSNotFound)
|
if (index != NSNotFound)
|
||||||
{
|
{
|
||||||
|
@ -1362,16 +1327,8 @@ static BOOL _shouldClose = YES;
|
||||||
[_recent_documents addObject: anURL];
|
[_recent_documents addObject: anURL];
|
||||||
|
|
||||||
// Save the changed list
|
// Save the changed list
|
||||||
a = [_recent_documents mutableCopy];
|
[self _saveRecentDocuments];
|
||||||
index = [a count];
|
|
||||||
while (index-- > 0)
|
|
||||||
{
|
|
||||||
[a replaceObjectAtIndex: index withObject:
|
|
||||||
[[a objectAtIndex: index] absoluteString]];
|
|
||||||
}
|
|
||||||
[[NSUserDefaults standardUserDefaults]
|
|
||||||
setObject: a forKey: NSRecentDocuments];
|
|
||||||
RELEASE(a);
|
|
||||||
[self _updateRecentDocumentsMenu];
|
[self _updateRecentDocumentsMenu];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1658,6 +1615,7 @@ static NSString *processName = nil;
|
||||||
- (void) _updateRecentDocumentsMenu
|
- (void) _updateRecentDocumentsMenu
|
||||||
{
|
{
|
||||||
NSMenu *recentMenu;
|
NSMenu *recentMenu;
|
||||||
|
BOOL listUpdated;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
recentMenu = [self _recentDocumentsMenu];
|
recentMenu = [self _recentDocumentsMenu];
|
||||||
|
@ -1670,10 +1628,31 @@ static NSString *processName = nil;
|
||||||
[recentMenu setAutoenablesItems: NO];
|
[recentMenu setAutoenablesItems: NO];
|
||||||
[recentMenu setMenuChangedMessagesEnabled: NO];
|
[recentMenu setMenuChangedMessagesEnabled: NO];
|
||||||
|
|
||||||
|
// remove from list all deleted or otherwise inaccessable files
|
||||||
|
listUpdated = NO;
|
||||||
|
for (i = [_recent_documents count] - 1; i >= 0; i--)
|
||||||
|
{
|
||||||
|
NSURL *u = [_recent_documents objectAtIndex: i];
|
||||||
|
NSError *error;
|
||||||
|
// Check if resource has been deleted
|
||||||
|
if (![u checkResourceIsReachableAndReturnError: &error])
|
||||||
|
{
|
||||||
|
[_recent_documents removeObjectAtIndex: i];
|
||||||
|
listUpdated = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (listUpdated)
|
||||||
|
{
|
||||||
|
// Save the changed list
|
||||||
|
[self _saveRecentDocuments];
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove them all
|
||||||
while ([recentMenu numberOfItems] > 0)
|
while ([recentMenu numberOfItems] > 0)
|
||||||
{
|
{
|
||||||
[recentMenu removeItemAtIndex: 0]; // remove them all
|
[recentMenu removeItemAtIndex: 0];
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = [_recent_documents count] - 1; i >= -2; i--)
|
for (i = [_recent_documents count] - 1; i >= -2; i--)
|
||||||
{
|
{
|
||||||
// add all items incl. a Clear List item if needed
|
// add all items incl. a Clear List item if needed
|
||||||
|
@ -1751,4 +1730,61 @@ static NSString *processName = nil;
|
||||||
[self presentError: err];
|
[self presentError: err];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void) _saveRecentDocuments
|
||||||
|
{
|
||||||
|
NSMutableArray *a = [_recent_documents mutableCopy];
|
||||||
|
NSUInteger index = [a count];
|
||||||
|
|
||||||
|
while (index-- > 0)
|
||||||
|
{
|
||||||
|
[a replaceObjectAtIndex: index withObject:
|
||||||
|
[[a objectAtIndex: index] absoluteString]];
|
||||||
|
}
|
||||||
|
[[NSUserDefaults standardUserDefaults]
|
||||||
|
setObject: a forKey: NSRecentDocuments];
|
||||||
|
RELEASE(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) _loadRecentDocuments
|
||||||
|
{
|
||||||
|
_recent_documents = [[NSUserDefaults standardUserDefaults]
|
||||||
|
objectForKey: NSRecentDocuments];
|
||||||
|
if (_recent_documents)
|
||||||
|
{
|
||||||
|
int i, count, max;
|
||||||
|
|
||||||
|
_recent_documents = [_recent_documents mutableCopy];
|
||||||
|
count = [_recent_documents count];
|
||||||
|
for (i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
NSString *str;
|
||||||
|
NSURL *url;
|
||||||
|
|
||||||
|
str = [_recent_documents objectAtIndex: i];
|
||||||
|
url = [NSURL URLWithString: str];
|
||||||
|
if (url == nil)
|
||||||
|
{
|
||||||
|
NSLog(@"NSRecentItems value '%@' is not valid ... ignored", str);
|
||||||
|
[_recent_documents removeObjectAtIndex: i];
|
||||||
|
i--;
|
||||||
|
count--;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[_recent_documents replaceObjectAtIndex: i withObject: url];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
max = [self maximumRecentDocumentCount];
|
||||||
|
if (count > max)
|
||||||
|
{
|
||||||
|
[_recent_documents removeObjectsInRange: NSMakeRange(0, count - max)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_recent_documents = RETAIN([NSMutableArray array]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -50,6 +50,8 @@
|
||||||
- (void) _setRecentDocumentsMenu: (NSMenu *)menu;
|
- (void) _setRecentDocumentsMenu: (NSMenu *)menu;
|
||||||
- (void) _updateRecentDocumentsMenu;
|
- (void) _updateRecentDocumentsMenu;
|
||||||
- (IBAction) _openRecentDocument: (id)sender;
|
- (IBAction) _openRecentDocument: (id)sender;
|
||||||
|
- (void) _saveRecentDocuments;
|
||||||
|
- (void) _loadRecentDocuments;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSDocument (Private)
|
@interface NSDocument (Private)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue