From 41d5f3c8f5c8de94fa1a0cdff5e68645af6d588b Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 18 Aug 2007 01:56:10 +0000 Subject: [PATCH] clean code up a little --- macosx/Torrent.m | 1 - macosx/TorrentTableView.m | 101 ++++++++++++++++++++------------------ 2 files changed, 52 insertions(+), 50 deletions(-) diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 02de4add1..18c924f6e 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -521,7 +521,6 @@ static int static_lastid = 0; return fStat->ratio; } -#warning make enum - (int) ratioSetting { return fRatioSetting; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index d353faa77..6dbdf8cef 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -352,9 +352,6 @@ BOOL create = [menu numberOfItems] <= 0, folder; - NSMenu * supermenu = [menu supermenu]; - NSArray * items; - NSDictionary * folderDict; #warning move to submethod if (menu == fUploadMenu || menu == fDownloadMenu) { @@ -391,67 +388,73 @@ return; } - else if ((folderDict = [[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject])) - items = [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject] objectForKey: @"Children"]; - else - items = [fMenuTorrent fileList]; - - #warning move rest to submethod - NSEnumerator * enumerator = [items objectEnumerator]; - NSDictionary * dict; - NSMenuItem * item; - while ((dict = [enumerator nextObject])) + else if ([menu supermenu]) //assume the menu is part of the file list { - NSString * name = [dict objectForKey: @"Name"]; + NSMenu * supermenu = [menu supermenu]; + NSArray * items; + NSDictionary * folderDict; + if ((folderDict = [[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject])) + items = [folderDict objectForKey: @"Children"]; + else + items = [fMenuTorrent fileList]; - folder = [[dict objectForKey: @"IsFolder"] boolValue]; - - if (create) + NSEnumerator * enumerator = [items objectEnumerator]; + NSDictionary * dict; + NSMenuItem * item; + while ((dict = [enumerator nextObject])) { - item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""]; + NSString * name = [dict objectForKey: @"Name"]; - NSImage * icon; - if (!folder) + folder = [[dict objectForKey: @"IsFolder"] boolValue]; + + if (create) { - icon = [[dict objectForKey: @"Icon"] copy]; - [icon setFlipped: NO]; + item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""]; + + NSImage * icon; + if (!folder) + { + icon = [[dict objectForKey: @"Icon"] copy]; + [icon setFlipped: NO]; + } + else + { + NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name]; + [itemMenu setAutoenablesItems: NO]; + [item setSubmenu: itemMenu]; + [itemMenu setDelegate: self]; + [itemMenu release]; + + icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy]; + } + + [item setRepresentedObject: dict]; + + [icon setScalesWhenResized: YES]; + [icon setSize: NSMakeSize(16.0, 16.0)]; + [item setImage: icon]; + [icon release]; + + [item setAction: @selector(checkFile:)]; + + [menu addItem: item]; + [item release]; } else - { - NSMenu * itemMenu = [[NSMenu alloc] initWithTitle: name]; - [itemMenu setAutoenablesItems: NO]; - [item setSubmenu: itemMenu]; - [itemMenu setDelegate: self]; - [itemMenu release]; - - icon = [[[NSWorkspace sharedWorkspace] iconForFileType: NSFileTypeForHFSTypeCode('fldr')] copy]; - } + item = [menu itemWithTitle: name]; - [item setRepresentedObject: dict]; - - [icon setScalesWhenResized: YES]; - [icon setSize: NSMakeSize(16.0, 16.0)]; - [item setImage: icon]; - [icon release]; - - [item setAction: @selector(checkFile:)]; - - [menu addItem: item]; - [item release]; + NSIndexSet * indexSet = [dict objectForKey: @"Indexes"]; + [item setState: [fMenuTorrent checkForFiles: indexSet]]; + [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]]; } - else - item = [menu itemWithTitle: name]; - - NSIndexSet * indexSet = [dict objectForKey: @"Indexes"]; - [item setState: [fMenuTorrent checkForFiles: indexSet]]; - [item setEnabled: [fMenuTorrent canChangeDownloadCheckForFiles: indexSet]]; } + else; } - (void) setQuickLimitMode: (id) sender { int tag = [sender tag]; - int mode; + tr_speedlimit_t mode; if (tag == ACTION_MENU_UNLIMITED_TAG) mode = TR_SPEEDLIMIT_UNLIMITED; else if (tag == ACTION_MENU_LIMIT_TAG)