mirror of
https://github.com/TermiT/Flycut.git
synced 2025-02-22 15:05:23 +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 {
|
||||
int passedSeparator = 0;
|
||||
NSMenuItem *oldItem;
|
||||
NSMenuItem *item;
|
||||
NSString *pbMenuTitle;
|
||||
|
||||
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
|
||||
while( oldItem = [menuEnumerator nextObject] ) {
|
||||
for (NSMenuItem *oldItem in menuItems) {
|
||||
if( [oldItem isSeparatorItem]) {
|
||||
passedSeparator++;
|
||||
} else if ( passedSeparator == 2 ) {
|
||||
|
@ -492,8 +493,8 @@
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
while( pbMenuTitle = [clipEnumerator nextObject] ) {
|
||||
for(NSString *pbMenuTitle in clipStrings) {
|
||||
NSMenuItem *item;
|
||||
item = [[NSMenuItem alloc] initWithTitle:pbMenuTitle
|
||||
action:@selector(processMenuClippingSelection:)
|
||||
keyEquivalent:@""];
|
||||
|
@ -556,24 +557,35 @@
|
|||
|
||||
-(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];
|
||||
NSEnumerator *enumerator;
|
||||
NSDictionary *aSavedClipping;
|
||||
|
||||
|
||||
NSArray *savedJCList;
|
||||
NSRange loadRange;
|
||||
int rangeCap;
|
||||
if ( loadDict != nil ) {
|
||||
|
||||
int rangeCap;
|
||||
|
||||
if ( loadDict != nil ) {
|
||||
|
||||
savedJCList = [loadDict objectForKey:@"jcList"];
|
||||
|
||||
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);
|
||||
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"]
|
||||
ofType:[aSavedClipping objectForKey:@"Type"]];
|
||||
}
|
||||
|
||||
} else {
|
||||
NSLog(@"Not array");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue