From 64f684599bdde631630c7c9f00731b0a4be63946 Mon Sep 17 00:00:00 2001 From: VladimirTechMan Date: Fri, 23 May 2014 13:16:11 +0400 Subject: [PATCH] Switching some more auxiliary files to ARC. Minor code updates and cleanup. Removal of some dead code. --- ControlPlane.xcodeproj/project.pbxproj | 12 +-- Source/ContextSelectionButton.h | 4 +- Source/ContextSelectionButton.m | 22 +--- Source/DNDArrayController.h | 25 ----- Source/DNDArrayController.m | 141 ------------------------- Source/NSString+ShellScriptHelper.m | 34 +++--- Source/PopButton.h | 10 +- Source/PopButton.m | 63 ++++------- 8 files changed, 50 insertions(+), 261 deletions(-) delete mode 100755 Source/DNDArrayController.h delete mode 100755 Source/DNDArrayController.m diff --git a/ControlPlane.xcodeproj/project.pbxproj b/ControlPlane.xcodeproj/project.pbxproj index cb863c3e4..52c196ad7 100644 --- a/ControlPlane.xcodeproj/project.pbxproj +++ b/ControlPlane.xcodeproj/project.pbxproj @@ -23,8 +23,7 @@ 7CA6847717947E2200563601 /* LaptopLidEvidenceSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 7CA6847617947E2200563601 /* LaptopLidEvidenceSource.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; 7CFF034917246B770098990F /* SearchDomainRule.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CFF034B17246B770098990F /* SearchDomainRule.xib */; }; 7CFF035A172471DD0098990F /* ServerAddressRule.xib in Resources */ = {isa = PBXBuildFile; fileRef = 7CFF035C172471DD0098990F /* ServerAddressRule.xib */; }; - 8D01634F0C029913004AD8DB /* DNDArrayController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D01634D0C029913004AD8DB /* DNDArrayController.m */; }; - 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; }; + 8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); COMPILER_FLAGS = "-fobjc-arc"; }; }; 8D11072F0486CEB800E47090 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; }; 8D1493F70C824B6D00D29FE8 /* BonjourEvidenceSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D1493F50C824B6D00D29FE8 /* BonjourEvidenceSource.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; 8D185DC60BF428CF00A06B03 /* AdvancedPrefs.png in Resources */ = {isa = PBXBuildFile; fileRef = 8D185DC50BF428CF00A06B03 /* AdvancedPrefs.png */; }; @@ -68,7 +67,7 @@ 8D90E51F0B71C4C9007D39FD /* CPController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D90E51E0B71C4C9007D39FD /* CPController.m */; }; 8D91F17D0C47148200D9FC0F /* USBEvidenceSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D35A34D0BBBA0CB006ACBB0 /* USBEvidenceSource.m */; }; 8D9AE3790BE0D11800D4D4E4 /* plus-arrow.png in Resources */ = {isa = PBXBuildFile; fileRef = 8D9AE3780BE0D11800D4D4E4 /* plus-arrow.png */; }; - 8D9AE3A60BE0DA7E00D4D4E4 /* PopButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9AE3A40BE0DA7E00D4D4E4 /* PopButton.m */; }; + 8D9AE3A60BE0DA7E00D4D4E4 /* PopButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 8D9AE3A40BE0DA7E00D4D4E4 /* PopButton.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; 8DA2F4150CE8630200F92D4D /* DesktopBackgroundAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DA2F4130CE8630200F92D4D /* DesktopBackgroundAction.m */; }; 8DB1EF240C6C60A300586F84 /* MailIMAPServerAction.m in Sources */ = {isa = PBXBuildFile; fileRef = 8DB1EF220C6C60A300586F84 /* MailIMAPServerAction.m */; }; 8DB8917C0BB89BD8005347C2 /* oui.txt in Resources */ = {isa = PBXBuildFile; fileRef = 8DB8917B0BB89BD8005347C2 /* oui.txt */; }; @@ -106,7 +105,7 @@ DA312CA3156DD42E009C1389 /* BWQuincyUI.m in Sources */ = {isa = PBXBuildFile; fileRef = DA312CA2156DD42E009C1389 /* BWQuincyUI.m */; }; DA41954D151C17F000FF7BA0 /* ActionSubmenuItem.m in Sources */ = {isa = PBXBuildFile; fileRef = DA41954C151C17F000FF7BA0 /* ActionSubmenuItem.m */; }; DA4411A514EE03C9005E7B3B /* MapKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DA4411A414EE03C9005E7B3B /* MapKit.framework */; }; - DA461C0C14C33E3C0019594A /* NSString+ShellScriptHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DA461C0B14C33E3B0019594A /* NSString+ShellScriptHelper.m */; }; + DA461C0C14C33E3C0019594A /* NSString+ShellScriptHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DA461C0B14C33E3B0019594A /* NSString+ShellScriptHelper.m */; settings = {COMPILER_FLAGS = "-fobjc-arc"; }; }; DA49AF6C14C3E0AB00D03D6A /* TogglePrinterSharingAction.m in Sources */ = {isa = PBXBuildFile; fileRef = DA49AF6B14C3E0AB00D03D6A /* TogglePrinterSharingAction.m */; }; DA4A629313E2546800CE976F /* ControlPlane Help in Resources */ = {isa = PBXBuildFile; fileRef = DA4A629213E2546800CE976F /* ControlPlane Help */; }; DA4A629513E25C9D00CE976F /* Credits.html in Resources */ = {isa = PBXBuildFile; fileRef = DA4A629413E25C9D00CE976F /* Credits.html */; }; @@ -365,8 +364,6 @@ 7CFF0360172472980098990F /* pt-PT */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "pt-PT"; path = "pt-PT.lproj/ServerAddressRule.xib"; sourceTree = ""; }; 7CFF0361172472990098990F /* pt-BR */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = "pt-BR"; path = "pt-BR.lproj/ServerAddressRule.xib"; sourceTree = ""; }; 7CFF03621724729A0098990F /* it */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = it; path = it.lproj/ServerAddressRule.xib; sourceTree = ""; }; - 8D01634C0C029913004AD8DB /* DNDArrayController.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = DNDArrayController.h; path = Source/DNDArrayController.h; sourceTree = ""; }; - 8D01634D0C029913004AD8DB /* DNDArrayController.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = DNDArrayController.m; path = Source/DNDArrayController.m; sourceTree = ""; }; 8D1107310486CEB800E47090 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist; path = Info.plist; sourceTree = ""; }; 8D1493F40C824B6D00D29FE8 /* BonjourEvidenceSource.h */ = {isa = PBXFileReference; explicitFileType = sourcecode.c.h; fileEncoding = 30; name = BonjourEvidenceSource.h; path = Source/BonjourEvidenceSource.h; sourceTree = ""; }; 8D1493F50C824B6D00D29FE8 /* BonjourEvidenceSource.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = BonjourEvidenceSource.m; path = Source/BonjourEvidenceSource.m; sourceTree = ""; }; @@ -921,8 +918,6 @@ children = ( 8D447DF60C3E65CF00DAB17A /* ContextSelectionButton.h */, 8D447DF70C3E65CF00DAB17A /* ContextSelectionButton.m */, - 8D01634C0C029913004AD8DB /* DNDArrayController.h */, - 8D01634D0C029913004AD8DB /* DNDArrayController.m */, 8D9AE3A30BE0DA7E00D4D4E4 /* PopButton.h */, 8D9AE3A40BE0DA7E00D4D4E4 /* PopButton.m */, 8D38B6690C49D50200290F47 /* SliderWithValue.h */, @@ -1497,7 +1492,6 @@ 8D9AE3A60BE0DA7E00D4D4E4 /* PopButton.m in Sources */, 8D75A6200BE6F68B0069DF3F /* ToggleBluetoothAction.m in Sources */, 8D649BA50BE8033A00716059 /* ToggleWiFiAction.m in Sources */, - 8D01634F0C029913004AD8DB /* DNDArrayController.m in Sources */, 8DC4E7FD0C178917007E7E41 /* MuteAction.m in Sources */, 8DC4E8000C17891D007E7E41 /* MailSMTPServerAction.m in Sources */, DA07C11018FE04A3008FE8B5 /* ContextEvidenceSource.m in Sources */, diff --git a/Source/ContextSelectionButton.h b/Source/ContextSelectionButton.h index 7e5872287..56cc324a8 100644 --- a/Source/ContextSelectionButton.h +++ b/Source/ContextSelectionButton.h @@ -8,9 +8,7 @@ #import "ContextsDataSource.h" -@interface ContextSelectionButton : NSPopUpButton { - ContextsDataSource *contextsDataSource; -} +@interface ContextSelectionButton : NSPopUpButton - (void)setContextsDataSource:(ContextsDataSource *)dataSource; diff --git a/Source/ContextSelectionButton.m b/Source/ContextSelectionButton.m index aa20e3907..a1d21192c 100644 --- a/Source/ContextSelectionButton.m +++ b/Source/ContextSelectionButton.m @@ -7,23 +7,8 @@ #import "ContextSelectionButton.h" - -@interface ContextSelectionButton (Private) - -- (void)selectionChanged:(NSNotification *)notification; - -@end - -@implementation ContextSelectionButton - -- (id)init -{ - if (!(self = [super init])) - return nil; - - contextsDataSource = nil; - - return self; +@implementation ContextSelectionButton { + ContextsDataSource *contextsDataSource; } - (void)setSelectedObject:(id)arg @@ -55,8 +40,9 @@ - (void)contextsChanged:(NSNotification *)notification object:[self menu]]; } [self setMenu:[contextsDataSource hierarchicalMenu]]; - if (lastUUID) + if (lastUUID != nil) { [self selectItemAtIndex:[self indexOfItemWithRepresentedObject:lastUUID]]; + } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(selectionChanged:) name:NSMenuDidSendActionNotification diff --git a/Source/DNDArrayController.h b/Source/DNDArrayController.h deleted file mode 100755 index ef1e0fb08..000000000 --- a/Source/DNDArrayController.h +++ /dev/null @@ -1,25 +0,0 @@ -// -// DNDArrayController.h -// ControlPlane -// -// Created by David Symonds on 29/03/07. -// - - -@interface DNDArrayController : NSArrayController -{ - IBOutlet NSTableView *tableView; -} - -// table view drag and drop support -- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray *)rows toPasteboard:(NSPasteboard *)pboard; -- (NSDragOperation)tableView:(NSTableView *)tv validateDrop:(id )info proposedRow:(int)row proposedDropOperation:(NSTableViewDropOperation)op; -- (BOOL)tableView:(NSTableView *)tv acceptDrop:(id )info row:(int)row dropOperation:(NSTableViewDropOperation)op; - - -// utility methods -- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)index; -- (NSIndexSet *)indexSetFromRows:(NSArray *)rows; -- (NSUInteger)rowsAboveRow:(NSUInteger)row inIndexSet:(NSIndexSet *)indexSet; - -@end diff --git a/Source/DNDArrayController.m b/Source/DNDArrayController.m deleted file mode 100755 index 238b43413..000000000 --- a/Source/DNDArrayController.m +++ /dev/null @@ -1,141 +0,0 @@ -// This is all addapted from mmalc's freely distributed DNDArrayController on his site. - -#import "DNDArrayController.h" - - -NSString *MovedRowsType = @"MOVED_ROWS_TYPE"; - -@implementation DNDArrayController - - -- (void)awakeFromNib -{ - // register for drag and drop - [tableView registerForDraggedTypes:[NSArray arrayWithObject:MovedRowsType]]; - - [super awakeFromNib]; -} - -- (BOOL)tableView:(NSTableView *)tv writeRows:(NSArray *)rows toPasteboard:(NSPasteboard *)pboard -{ - // declare our own pasteboard types - NSArray *typesArray = [NSArray arrayWithObjects:MovedRowsType, nil]; - - [pboard declareTypes:typesArray owner:self]; - - // add rows array for local move - [pboard setPropertyList:rows forType:MovedRowsType]; - - return YES; -} - -- (NSDragOperation)tableView:(NSTableView *)tv - validateDrop:(id )info - proposedRow:(int)row - proposedDropOperation:(NSTableViewDropOperation)op -{ - // Only support internal drags (i.e. moves) - if ([info draggingSource] != tableView) - return NSDragOperationNone; - - [tv setDropRow:row dropOperation:NSTableViewDropAbove]; - return NSDragOperationMove; -} - -- (BOOL)tableView:(NSTableView *)tv - acceptDrop:(id )info - row:(int)row - dropOperation:(NSTableViewDropOperation)op -{ - if (row < 0) - row = 0; - - // Only support internal drags (i.e. moves) - if ([info draggingSource] != tableView) - return NO; - - NSArray *rows = [[info draggingPasteboard] propertyListForType:MovedRowsType]; - NSIndexSet *indexSet = [self indexSetFromRows:rows]; - - [self moveObjectsInArrangedObjectsFromIndexes:indexSet toIndex:row]; - - // set selected rows to those that were just moved - // Need to work out what moved where to determine proper selection... - NSUInteger rowsAbove = [self rowsAboveRow:row inIndexSet:indexSet]; - - NSRange range = NSMakeRange(row - rowsAbove, [indexSet count]); - indexSet = [NSIndexSet indexSetWithIndexesInRange:range]; - [self setSelectionIndexes:indexSet]; - - return YES; -} - -- (void)tableView:(NSTableView *)aTableView willDisplayCell:(id)aCell forTableColumn:(NSTableColumn *)aTableColumn row:(int)rowIndex -{ - if ([aCell class] != [NSTextFieldCell class]) - return; - - BOOL drawInGrey = NO; - - NSDictionary *thisRow = [[self arrangedObjects] objectAtIndex:rowIndex]; - NSNumber *enabled; - if ((enabled = [thisRow objectForKey:@"enabled"]) && ![enabled boolValue]) - drawInGrey = YES; - - if (drawInGrey) - [aCell setTextColor:[NSColor colorWithDeviceWhite:0.5 alpha:1.0]]; - else - [aCell setTextColor:[NSColor colorWithDeviceWhite:0 alpha:1.0]]; -} - -#pragma mark - - -- (void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet *)indexSet toIndex:(NSUInteger)insertIndex -{ - NSArray *objects = [self arrangedObjects]; - NSUInteger index = [indexSet lastIndex]; - - NSUInteger aboveInsertIndexCount = 0, removeIndex; - id object; - - while (index != NSNotFound) { - if (index >= insertIndex) { - removeIndex = index + aboveInsertIndexCount; - aboveInsertIndexCount += 1; - } else { - removeIndex = index; - insertIndex -= 1; - } - object = [objects objectAtIndex:removeIndex]; - [self removeObjectAtArrangedObjectIndex:removeIndex]; - [self insertObject:object atArrangedObjectIndex:insertIndex]; - - index = [indexSet indexLessThanIndex:index]; - } -} - -- (NSIndexSet *)indexSetFromRows:(NSArray *)rows -{ - NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]; - NSEnumerator *rowEnumerator = [rows objectEnumerator]; - NSNumber *idx; - while ((idx = [rowEnumerator nextObject])) - [indexSet addIndex:[idx intValue]]; - return indexSet; -} - - -- (NSUInteger)rowsAboveRow:(NSUInteger)row inIndexSet:(NSIndexSet *)indexSet -{ - NSUInteger currentIndex = [indexSet firstIndex], i = 0; - - while (currentIndex != NSNotFound) { - if (currentIndex < row) - i++; - currentIndex = [indexSet indexGreaterThanIndex:currentIndex]; - } - - return i; -} - -@end diff --git a/Source/NSString+ShellScriptHelper.m b/Source/NSString+ShellScriptHelper.m index 6fa997eb2..db1a7a516 100644 --- a/Source/NSString+ShellScriptHelper.m +++ b/Source/NSString+ShellScriptHelper.m @@ -11,7 +11,8 @@ @implementation NSString (ShellScriptHelper) -- (NSMutableArray *) interpreterFromFile { +- (NSMutableArray *) interpreterFromFile +{ NSError *readFileError; // get lines @@ -21,18 +22,18 @@ - (NSMutableArray *) interpreterFromFile { NSArray *fileLines = [fileContents componentsSeparatedByString:@"\n"]; // get the shebang line - if (fileLines.count == 0) + if (fileLines.count == 0) { return nil; + } - NSString *firstLine = [fileLines objectAtIndex: 0]; - firstLine = [firstLine stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]]; + NSString *firstLine = fileLines[0]; + firstLine = [firstLine stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; // check first line while handling a special case where the first line is : - if ([firstLine rangeOfString: @"#!"].location == NSNotFound && ![firstLine isEqualToString:@":"]) + if ([firstLine rangeOfString: @"#!"].location == NSNotFound && ![firstLine isEqualToString:@":"]) { return nil; + } - - NSMutableArray *args = nil; // TRIVIA, first check if the file starts with a colon. Apparently @@ -42,31 +43,34 @@ - (NSMutableArray *) interpreterFromFile { } else { // split shebang and it's parameters - args = [[[firstLine componentsSeparatedByString: @" "] mutableCopy] autorelease]; + args = [[firstLine componentsSeparatedByString:@" "] mutableCopy]; [args removeObject: @""]; } // remove shebang characterss #! - if ([[args objectAtIndex: 0] length] > 2) - [args replaceObjectAtIndex: 0 - withObject: [[args objectAtIndex: 0] substringFromIndex: 2]]; + if ([args[0] length] > 2) { + [args replaceObjectAtIndex:0 withObject:[args[0] substringFromIndex:2]]; + } // or there might have been a space between #! and the interpreter // so the first item in args is just '#!' - else - [args removeObjectAtIndex: 0]; + else { + [args removeObjectAtIndex:0]; + } return args; } -- (NSString *) interpreterFromExtension { +- (NSString *) interpreterFromExtension +{ NSString *app, *extension; NSString *result = @"/bin/bash"; // Get the file type of the script - if (![NSWorkspace.sharedWorkspace getInfoForFile: self application: &app type: &extension]) + if (![NSWorkspace.sharedWorkspace getInfoForFile: self application: &app type: &extension]) { return result; + } extension = extension.lowercaseString; // check type diff --git a/Source/PopButton.h b/Source/PopButton.h index ea91885ea..c79064a3f 100644 --- a/Source/PopButton.h +++ b/Source/PopButton.h @@ -4,13 +4,11 @@ // // Created by David Symonds on 26/04/07. // +// Modified by VladimirTechMan (Vladimir Beloborodov) on 22 May 2014. +// +@interface PopButton : NSButton -@interface PopButton : NSButton { - NSMenu *menu; -} - -- (NSMenu *)menu; -- (void)setMenu:(NSMenu *)theMenu; +@property (nonatomic,strong) NSMenu *menu; @end diff --git a/Source/PopButton.m b/Source/PopButton.m index bea51854a..330969cc7 100644 --- a/Source/PopButton.m +++ b/Source/PopButton.m @@ -4,68 +4,43 @@ // // Created by David Symonds on 26/04/07. // +// Modified by VladimirTechMan (Vladimir Beloborodov) on 22 May 2014. +// +// IMPORTANT: This code is intended to be compiled for the ARC mode +// #import "PopButton.h" - @implementation PopButton -- (id)init -{ - if (!(self = [super init])) - return nil; - - menu = nil; - - return self; -} - -- (void)dealloc -{ - if (menu) - [menu release]; - [super dealloc]; -} - -- (NSMenu *)menu -{ - return menu; -} - -- (void)setMenu:(NSMenu *)theMenu -{ - [theMenu retain]; - if (menu) - [menu release]; - menu = theMenu; -} - - (void)mouseDown:(NSEvent *)theEvent { - if (![self isEnabled] || !menu) + if (![self isEnabled] || (_menu == nil)) { return; - + } + NSRect rect = [self bounds]; NSPoint pt = NSMakePoint(rect.origin.x, rect.origin.y + rect.size.height + 5); NSEvent *event = [NSEvent mouseEventWithType:[theEvent type] - location:[self convertPoint:pt toView:nil] - modifierFlags:[theEvent modifierFlags] - timestamp:[theEvent timestamp] - windowNumber:[theEvent windowNumber] - context:[theEvent context] - eventNumber:[theEvent eventNumber] - clickCount:[theEvent clickCount] - pressure:[theEvent pressure]]; - + location:[self convertPoint:pt toView:nil] + modifierFlags:[theEvent modifierFlags] + timestamp:[theEvent timestamp] + windowNumber:[theEvent windowNumber] + context:[theEvent context] + eventNumber:[theEvent eventNumber] + clickCount:[theEvent clickCount] + pressure:[theEvent pressure]]; + [self highlight:YES]; - [NSMenu popUpContextMenu:menu withEvent:event forView:self]; + [NSMenu popUpContextMenu:_menu withEvent:event forView:self]; [self highlight:NO]; } - (void)mouseUp:(NSEvent *)theEvent { - if ([self isEnabled]) + if ([self isEnabled]) { [self highlight:NO]; + } } @end