mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-20 19:16:30 +00:00
Make number of remembered recent documents configurable with a user
preference and fix a bug where one extra document was remembered. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@30366 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
cfb8299e07
commit
f77c5f6bca
2 changed files with 31 additions and 6 deletions
|
@ -65,6 +65,7 @@ static NSString *CFBundleTypeRole = @"CFBundleTypeRole";
|
|||
|
||||
// FIXME: Looks like this was changed to @"NSRecentDocumentRecords"
|
||||
static NSString *NSRecentDocuments = @"NSRecentDocuments";
|
||||
static NSString *NSMaximumRecentDocumentCount = @"NSMaximumRecentDocumentCount";
|
||||
|
||||
static NSString *NSEditorRole = @"Editor";
|
||||
static NSString *NSViewerRole = @"Viewer";
|
||||
|
@ -274,7 +275,7 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
|||
objectForKey: NSRecentDocuments];
|
||||
if (_recent_documents)
|
||||
{
|
||||
int i, count;
|
||||
int i, count, max;
|
||||
|
||||
_recent_documents = [_recent_documents mutableCopy];
|
||||
count = [_recent_documents count];
|
||||
|
@ -297,6 +298,12 @@ TypeInfoForHumanReadableName (NSArray *types, NSString *typeName)
|
|||
[_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]);
|
||||
|
@ -1281,8 +1288,19 @@ static BOOL _shouldClose = YES;
|
|||
// The number of remembered recent documents
|
||||
- (NSUInteger) maximumRecentDocumentCount
|
||||
{
|
||||
// FIXME: Should come from user defaults
|
||||
return 5;
|
||||
NSUserDefaults *sud = [NSUserDefaults standardUserDefaults];
|
||||
NSInteger count = 5;
|
||||
if ([sud objectForKey: NSMaximumRecentDocumentCount])
|
||||
{
|
||||
count = [sud integerForKey: NSMaximumRecentDocumentCount];
|
||||
if (count < 0)
|
||||
count = 5;
|
||||
}
|
||||
else
|
||||
{
|
||||
count = 5;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
- (void) noteNewRecentDocument: (NSDocument *)aDocument
|
||||
|
@ -1303,7 +1321,7 @@ static BOOL _shouldClose = YES;
|
|||
// Always keep the current object at the end of the list
|
||||
[_recent_documents removeObjectAtIndex: index];
|
||||
}
|
||||
else if ([_recent_documents count] > [self maximumRecentDocumentCount])
|
||||
else if ([_recent_documents count] >= [self maximumRecentDocumentCount])
|
||||
{
|
||||
[_recent_documents removeObjectAtIndex: 0];
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue