mirror of
https://github.com/TermiT/Flycut.git
synced 2025-02-22 23:13:34 +08:00
Refactoring more NSEnumerator to NSFastEnumeration and minor cleanup for readability
This commit is contained in:
parent
7efaff666c
commit
c277d12f42
1 changed files with 31 additions and 19 deletions
|
@ -475,16 +475,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)updateMenu {
|
- (void)updateMenu {
|
||||||
int passedSeparator = 0;
|
|
||||||
NSMenuItem *oldItem;
|
|
||||||
NSMenuItem *item;
|
|
||||||
NSString *pbMenuTitle;
|
|
||||||
NSArray *returnedDisplayStrings = [clippingStore previousDisplayStrings:[[NSUserDefaults standardUserDefaults] integerForKey:@"displayNum"]];
|
NSArray *returnedDisplayStrings = [clippingStore previousDisplayStrings:[[NSUserDefaults standardUserDefaults] integerForKey:@"displayNum"]];
|
||||||
NSEnumerator *menuEnumerator = [[jcMenu itemArray] reverseObjectEnumerator];
|
|
||||||
NSEnumerator *clipEnumerator = [returnedDisplayStrings reverseObjectEnumerator];
|
NSArray *menuItems = [[[jcMenu itemArray] reverseObjectEnumerator] allObjects];
|
||||||
|
|
||||||
|
NSArray *clipStrings = [[returnedDisplayStrings reverseObjectEnumerator] allObjects];
|
||||||
|
|
||||||
|
int passedSeparator = 0;
|
||||||
|
|
||||||
//remove clippings from menu
|
//remove clippings from menu
|
||||||
while( oldItem = [menuEnumerator nextObject] ) {
|
for (NSMenuItem *oldItem in menuItems) {
|
||||||
if( [oldItem isSeparatorItem]) {
|
if( [oldItem isSeparatorItem]) {
|
||||||
passedSeparator++;
|
passedSeparator++;
|
||||||
} else if ( passedSeparator == 2 ) {
|
} else if ( passedSeparator == 2 ) {
|
||||||
|
@ -492,8 +493,8 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(NSString *pbMenuTitle in clipStrings) {
|
||||||
while( pbMenuTitle = [clipEnumerator nextObject] ) {
|
NSMenuItem *item;
|
||||||
item = [[NSMenuItem alloc] initWithTitle:pbMenuTitle
|
item = [[NSMenuItem alloc] initWithTitle:pbMenuTitle
|
||||||
action:@selector(processMenuClippingSelection:)
|
action:@selector(processMenuClippingSelection:)
|
||||||
keyEquivalent:@""];
|
keyEquivalent:@""];
|
||||||
|
@ -556,24 +557,35 @@
|
||||||
|
|
||||||
-(void) loadEngineFromPList
|
-(void) loadEngineFromPList
|
||||||
{
|
{
|
||||||
NSString *path = [[NSString stringWithString:@"~/Library/Application Support/Flycut/JCEngine.save"] stringByExpandingTildeInPath];
|
NSString *path = [[NSString
|
||||||
|
stringWithString:@"~/Library/Application Support/Flycut/JCEngine.save"] stringByExpandingTildeInPath];
|
||||||
NSDictionary *loadDict = [[NSDictionary alloc] initWithContentsOfFile:path];
|
NSDictionary *loadDict = [[NSDictionary alloc] initWithContentsOfFile:path];
|
||||||
NSEnumerator *enumerator;
|
|
||||||
NSDictionary *aSavedClipping;
|
|
||||||
NSArray *savedJCList;
|
NSArray *savedJCList;
|
||||||
NSRange loadRange;
|
NSRange loadRange;
|
||||||
int rangeCap;
|
|
||||||
if ( loadDict != nil ) {
|
int rangeCap;
|
||||||
|
|
||||||
|
if ( loadDict != nil ) {
|
||||||
|
|
||||||
savedJCList = [loadDict objectForKey:@"jcList"];
|
savedJCList = [loadDict objectForKey:@"jcList"];
|
||||||
|
|
||||||
if ( [savedJCList isKindOfClass:[NSArray class]] ) {
|
if ( [savedJCList isKindOfClass:[NSArray class]] ) {
|
||||||
// There's probably a nicer way to prevent the range from going out of bounds, but this works.
|
|
||||||
rangeCap = [savedJCList count] < [[NSUserDefaults standardUserDefaults] integerForKey:@"rememberNum"] ? [savedJCList count] : [[NSUserDefaults standardUserDefaults] integerForKey:@"rememberNum"];
|
int rememberNumPref = [[NSUserDefaults standardUserDefaults]
|
||||||
|
integerForKey:@"rememberNum"];
|
||||||
|
// There's probably a nicer way to prevent the range from going out of bounds, but this works.
|
||||||
|
rangeCap = [savedJCList count] < rememberNumPref ? [savedJCList count] : rememberNumPref;
|
||||||
loadRange = NSMakeRange(0, rangeCap);
|
loadRange = NSMakeRange(0, rangeCap);
|
||||||
enumerator = [[savedJCList subarrayWithRange:loadRange] reverseObjectEnumerator];
|
|
||||||
while ( aSavedClipping = [enumerator nextObject] ) {
|
NSArray *toBeRestoredClips = [[[savedJCList subarrayWithRange:loadRange] reverseObjectEnumerator] allObjects];
|
||||||
|
|
||||||
|
for( NSDictionary *aSavedClipping in toBeRestoredClips) {
|
||||||
[clippingStore addClipping:[aSavedClipping objectForKey:@"Contents"]
|
[clippingStore addClipping:[aSavedClipping objectForKey:@"Contents"]
|
||||||
ofType:[aSavedClipping objectForKey:@"Type"]];
|
ofType:[aSavedClipping objectForKey:@"Type"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
NSLog(@"Not array");
|
NSLog(@"Not array");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue