1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-02 17:55:22 +00:00

begins of individual action menus

This commit is contained in:
Mitchell Livingston 2007-08-08 01:03:34 +00:00
parent a4fe201b05
commit d2cbbe01fa
8 changed files with 198 additions and 19 deletions

View file

@ -99,6 +99,8 @@
A261F1DC0A69A1610002815A /* Growl.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A261F1DB0A69A1610002815A /* Growl.framework */; };
A261F1E40A69A1B10002815A /* Growl.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = A261F1DB0A69A1610002815A /* Growl.framework */; };
A2710E770A86796000CE4F7D /* PrefsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = A2710E750A86796000CE4F7D /* PrefsWindow.m */; };
A277DA0B0C693D9C00DA2CD4 /* ActionOn.png in Resources */ = {isa = PBXBuildFile; fileRef = A277DA090C693D9C00DA2CD4 /* ActionOn.png */; };
A277DA0C0C693D9C00DA2CD4 /* ActionOff.png in Resources */ = {isa = PBXBuildFile; fileRef = A277DA0A0C693D9C00DA2CD4 /* ActionOff.png */; };
A27A53570A06A76400E1F16F /* StatusSep.png in Resources */ = {isa = PBXBuildFile; fileRef = A27A53560A06A76400E1F16F /* StatusSep.png */; };
A27ABC240A6ADE410020EC71 /* ImageBackgroundView.m in Sources */ = {isa = PBXBuildFile; fileRef = A27ABC220A6ADE410020EC71 /* ImageBackgroundView.m */; };
A289EB0C0A33C56D00B082A3 /* ButtonBorder.png in Resources */ = {isa = PBXBuildFile; fileRef = A289EB0B0A33C56D00B082A3 /* ButtonBorder.png */; };
@ -423,6 +425,8 @@
A2710E750A86796000CE4F7D /* PrefsWindow.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = PrefsWindow.m; path = macosx/PrefsWindow.m; sourceTree = "<group>"; };
A27431D80A68538400FA780A /* FilterBarButton.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = FilterBarButton.h; path = macosx/FilterBarButton.h; sourceTree = "<group>"; };
A27431D90A68538400FA780A /* FilterBarButton.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = FilterBarButton.m; path = macosx/FilterBarButton.m; sourceTree = "<group>"; };
A277DA090C693D9C00DA2CD4 /* ActionOn.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ActionOn.png; path = macosx/Images/ActionOn.png; sourceTree = "<group>"; };
A277DA0A0C693D9C00DA2CD4 /* ActionOff.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = ActionOff.png; path = macosx/Images/ActionOff.png; sourceTree = "<group>"; };
A27A53420A06A62500E1F16F /* StatusSep.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StatusSep.png; path = macosx/Images/StatusSep.png; sourceTree = "<group>"; };
A27A53560A06A76400E1F16F /* StatusSep.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = StatusSep.png; path = macosx/Images/StatusSep.png; sourceTree = "<group>"; };
A27ABC210A6ADE410020EC71 /* ImageBackgroundView.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ImageBackgroundView.h; path = macosx/ImageBackgroundView.h; sourceTree = "<group>"; };
@ -723,6 +727,8 @@
A2E9AA750C249AF400085DCF /* Create.png */,
A2F011980C27418800576FC0 /* CreateLarge.png */,
4DF7500908A103AD007B0D70 /* Remove.png */,
A277DA090C693D9C00DA2CD4 /* ActionOn.png */,
A277DA0A0C693D9C00DA2CD4 /* ActionOff.png */,
35B037F90AC5B53800A10FDF /* ResumeNoWaitOn.png */,
35B037FA0AC5B53800A10FDF /* ResumeNoWaitOff.png */,
4D6DAAC4090CE00500F43C22 /* RevealOff.png */,
@ -1240,6 +1246,8 @@
A2085E3F0C53C949000BC3B7 /* LICENSE in Resources */,
A22BC9A30C5BBCF100F5FB72 /* BottomBorder.png in Resources */,
A2AE68330C628A35008753C9 /* Creator.nib in Resources */,
A277DA0B0C693D9C00DA2CD4 /* ActionOn.png in Resources */,
A277DA0C0C693D9C00DA2CD4 /* ActionOff.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

BIN
macosx/Images/ActionOff.png Normal file

Binary file not shown.

After

(image error) Size: 454 B

BIN
macosx/Images/ActionOn.png Normal file

Binary file not shown.

After

(image error) Size: 457 B

View file

@ -55,6 +55,8 @@
tr_file_stat_t * fileStat;
NSArray * fFileList, * fFlatFileList;
NSMenu * fTorrentMenu;
float fRatioLimit;
int fRatioSetting;
BOOL fFinishedSeeding, fWaitToStart, fError, fChecking, fStalled;
@ -208,6 +210,8 @@
- (BOOL) hasFilePriority: (int) priority forIndexes: (NSIndexSet *) indexSet;
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet;
- (NSMenu *) torrentMenu;
- (NSDate *) dateAdded;
- (NSDate *) dateCompleted;
- (NSDate *) dateActivity;

View file

@ -183,6 +183,8 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
[fFileList release];
[fFlatFileList release];
[fTorrentMenu release];
[fQuickPauseDict release];
[fBitmap release];
@ -1342,6 +1344,7 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return NO;
}
#warning rename to match priorities
- (NSSet *) filePrioritiesForIndexes: (NSIndexSet *) indexSet
{
BOOL low = NO, normal = NO, high = NO;
@ -1380,6 +1383,16 @@ static uint32_t kRed = BE(0xFF6450FF), //255, 100, 80
return priorities;
}
- (NSMenu *) torrentMenu
{
if (!fTorrentMenu)
{
fTorrentMenu = [[NSMenu alloc] initWithTitle: [@"TorrentMenu:" stringByAppendingString: [self name]]];
[fTorrentMenu setAutoenablesItems: NO];
}
return fTorrentMenu;
}
- (NSDate *) dateAdded
{
return fDateAdded;

View file

@ -183,7 +183,7 @@
[paragraphStyle release];
NSPoint pen = cellFrame.origin;
const float PADDING = 3.0, LINE_PADDING = 2.0, EXTRA_NAME_SHIFT = 1.0;
const float LINE_PADDING = 2.0, EXTRA_NAME_SHIFT = 1.0; //standard padding defined in TorrentCell.h
NSDictionary * info = [self objectValue];
@ -194,7 +194,8 @@
NSSize iconSize = [icon size];
pen.x += PADDING;
pen.y += (cellFrame.size.height - iconSize.height) * 0.5;
#warning use constant
pen.y += (cellFrame.size.height - (iconSize.height + ACTION_BUTTON_HEIGHT)) * 0.5;
[icon drawAtPoint: pen fromRect: NSMakeRect(0, 0, iconSize.width, iconSize.height)
operation: NSCompositeSourceOver fraction: 1.0];

View file

@ -25,8 +25,15 @@
#import <Cocoa/Cocoa.h>
#import <transmission.h>
#define PADDING 3.0
//button layout (from end of bar) is: padding, button, padding, button, padding
#define BUTTON_WIDTH 14.0
#define BUTTONS_TOTAL_WIDTH 39.0
#define ACTION_BUTTON_HEIGHT 12.0
#define ACTION_BUTTON_WIDTH 28.0
@class Controller;
@interface TorrentTableView : NSTableView
@ -39,15 +46,18 @@
NSUserDefaults * fDefaults;
IBOutlet NSMenu * fContextRow, * fContextNoRow;
NSImage * fResumeOnIcon, * fResumeOffIcon,
* fPauseOnIcon, * fPauseOffIcon,
* fResumeNoWaitOnIcon, * fResumeNoWaitOffIcon,
* fRevealOnIcon, * fRevealOffIcon;
NSImage * fResumeOnIcon, * fResumeOffIcon, * fPauseOnIcon, * fPauseOffIcon,
* fResumeNoWaitOnIcon, * fResumeNoWaitOffIcon, * fRevealOnIcon, * fRevealOffIcon,
* fActionOnIcon, * fActionOffIcon;
NSMutableArray * fKeyStrokes;
NSDictionary * fSmallStatusAttributes;
}
- (void) setTorrents: (NSArray *) torrents;
- (void) displayTorrentMenuForEvent: (NSEvent *) event;
- (void) checkFile: (id) sender;
@end

View file

@ -30,20 +30,21 @@
#define BUTTON_TO_TOP_REGULAR 33.0
#define BUTTON_TO_TOP_SMALL 20.0
//button layout (from end of bar) is: padding, button, padding, button, padding
//change BUTTONS_TOTAL_WIDTH in .h when changing these values, add 2.0 to that value
#define BUTTON_WIDTH 14.0
#define PADDING 3.0
#define ACTION_BUTTON_TO_TOP 47.0
@interface TorrentTableView (Private)
- (NSRect) pauseRectForRow: (int) row;
- (NSRect) revealRectForRow: (int) row;
- (BOOL) pointInPauseRect: (NSPoint) point;
- (BOOL) pointInRevealRect: (NSPoint) point;
- (NSRect) actionRectForRow: (int) row;
- (BOOL) pointInIconRect: (NSPoint) point;
- (BOOL) pointInMinimalStatusRect: (NSPoint) point;
- (BOOL) pointInPauseRect: (NSPoint) point;
- (BOOL) pointInRevealRect: (NSPoint) point;
- (BOOL) pointInActionRect: (NSPoint) point;
@end
@implementation TorrentTableView
@ -55,12 +56,16 @@
fResumeOnIcon = [NSImage imageNamed: @"ResumeOn.png"];
fResumeOffIcon = [NSImage imageNamed: @"ResumeOff.png"];
fPauseOnIcon = [NSImage imageNamed: @"PauseOn.png"];
fPauseOffIcon = [NSImage imageNamed: @"PauseOff.png"];
fResumeNoWaitOnIcon = [NSImage imageNamed: @"ResumeNoWaitOn.png"];
fResumeNoWaitOffIcon = [NSImage imageNamed: @"ResumeNoWaitOff.png"];
fPauseOffIcon = [NSImage imageNamed: @"PauseOff.png"];
fRevealOnIcon = [NSImage imageNamed: @"RevealOn.png"];
fRevealOffIcon = [NSImage imageNamed: @"RevealOff.png"];
fActionOnIcon = [NSImage imageNamed: @"ActionOn.png"];
fActionOffIcon = [NSImage imageNamed: @"ActionOff.png"];
fClickPoint = NSZeroPoint;
fKeyStrokes = [[NSMutableArray alloc] init];
@ -96,7 +101,14 @@
{
fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil];
if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint])
if ([self pointInActionRect: fClickPoint])
{
#warning use icon that doesn't change?
[self display]; //ensure button is pushed down
[self displayTorrentMenuForEvent: event];
#warning get icon to change back
}
else if (![self pointInPauseRect: fClickPoint] && ![self pointInRevealRect: fClickPoint])
{
if ([event modifierFlags] & NSAlternateKeyMask)
{
@ -234,6 +246,101 @@
[self scrollRowToVisible: row];
}
- (void) displayTorrentMenuForEvent: (NSEvent *) event
{
int row = [self rowAtPoint: [self convertPoint: [event locationInWindow] fromView: nil]];
if (row < 0)
return;
NSMenu * torrentMenu = [[fTorrents objectAtIndex: row] torrentMenu];
[torrentMenu setDelegate: self];
NSRect rect = [self actionRectForRow: row];
NSPoint location = rect.origin;
location.y += rect.size.height + 5.0;
location = [self convertPoint: location toView: nil];
NSEvent * newEvent = [NSEvent mouseEventWithType: [event type] location: location
modifierFlags: [event modifierFlags] timestamp: [event timestamp] windowNumber: [event windowNumber]
context: [event context] eventNumber: [event eventNumber] clickCount: [event clickCount] pressure: [event pressure]];
[NSMenu popUpContextMenu: torrentMenu withEvent: newEvent forView: self];
}
- (void) menuNeedsUpdate: (NSMenu *) menu
{
BOOL create = [menu numberOfItems] <= 0, folder;
Torrent * torrent = [fTorrents objectAtIndex: [self rowAtPoint: fClickPoint]];
NSMenu * supermenu = [menu supermenu];
NSArray * items;
if (supermenu)
items = [[[supermenu itemAtIndex: [supermenu indexOfItemWithSubmenu: menu]] representedObject] objectForKey: @"Children"];
else
items = [torrent fileList];
NSEnumerator * enumerator = [items objectEnumerator];
NSDictionary * dict;
while ((dict = [enumerator nextObject]))
{
NSMenuItem * item;
NSString * name = [dict objectForKey: @"Name"];
folder = [[dict objectForKey: @"IsFolder"] boolValue];
if (create)
{
item = [[NSMenuItem alloc] initWithTitle: name action: NULL keyEquivalent: @""];
[menu addItem: item];
[item release];
NSImage * icon;
if (!folder)
{
[item setAction: @selector(checkFile:)];
icon = [[dict objectForKey: @"Icon"] copy];
[icon setFlipped: NO];
}
else
{
NSMenu * menu = [[NSMenu alloc] initWithTitle: name];
[menu setAutoenablesItems: NO];
[item setSubmenu: menu];
[menu setDelegate: self];
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];
}
else
item = [menu itemWithTitle: name];
if (!folder)
{
NSIndexSet * indexSet = [dict objectForKey: @"Indexes"];
[item setState: [torrent checkForFiles: indexSet]];
[item setEnabled: [torrent canChangeDownloadCheckForFiles: indexSet]];
}
}
}
- (void) checkFile: (id) sender
{
NSIndexSet * indexes = [[sender representedObject] objectForKey: @"Indexes"];
Torrent * torrent = [fTorrents objectAtIndex: [self rowAtPoint: fClickPoint]];
[torrent setFileCheckState: [sender state] != NSOnState ? NSOnState : NSOffState forIndexes: indexes];
#warning reload inspector -> files
}
#warning only update shown
- (void) drawRect: (NSRect) r
{
NSRect rect;
@ -271,6 +378,10 @@
rect = [self revealRectForRow: i];
image = NSPointInRect(fClickPoint, rect) ? fRevealOnIcon : fRevealOffIcon;
[image compositeToPoint: NSMakePoint(rect.origin.x, NSMaxY(rect)) operation: NSCompositeSourceOver];
#warning make change
rect = [self actionRectForRow: i];
[fActionOffIcon compositeToPoint: NSMakePoint(rect.origin.x, NSMaxY(rect)) operation: NSCompositeSourceOver];
}
}
@ -298,18 +409,33 @@
cellRect.origin.y + buttonToTop, BUTTON_WIDTH, BUTTON_WIDTH);
}
- (NSRect) actionRectForRow: (int) row
{
#warning return small icon rect
if ([fDefaults boolForKey: @"SmallView"])
return NSZeroRect;
NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row];
#warning constant
return NSMakeRect(cellRect.origin.x + PADDING +
([[[fTorrents objectAtIndex: row] iconFlipped] size].width - ACTION_BUTTON_WIDTH) * 0.5,
cellRect.origin.y + ACTION_BUTTON_TO_TOP, ACTION_BUTTON_WIDTH, ACTION_BUTTON_HEIGHT);
}
- (BOOL) pointInIconRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0)
return NO;
#warning move to own method
NSRect cellRect = [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: row];
NSSize iconSize = [fDefaults boolForKey: @"SmallView"] ? [[[fTorrents objectAtIndex: row] iconSmall] size]
: [[[fTorrents objectAtIndex: row] iconFlipped] size];
NSRect iconRect = NSMakeRect(cellRect.origin.x + 3.0, cellRect.origin.y
+ (cellRect.size.height - iconSize.height) * 0.5, iconSize.width, iconSize.height);
NSRect iconRect = NSMakeRect(cellRect.origin.x + 3.0, cellRect.origin.y + (cellRect.size.height - iconSize.height) * 0.5,
iconSize.width, iconSize.height);
return NSPointInRect(point, iconRect);
}
@ -335,12 +461,29 @@
- (BOOL) pointInPauseRect: (NSPoint) point
{
return NSPointInRect(point, [self pauseRectForRow: [self rowAtPoint: point]]);
int row = [self rowAtPoint: point];
if (row < 0)
return NO;
return NSPointInRect(point, [self pauseRectForRow: row]);
}
- (BOOL) pointInRevealRect: (NSPoint) point
{
return NSPointInRect(point, [self revealRectForRow: [self rowAtPoint: point]]);
int row = [self rowAtPoint: point];
if (row < 0)
return NO;
return NSPointInRect(point, [self revealRectForRow: row]);
}
- (BOOL) pointInActionRect: (NSPoint) point
{
int row = [self rowAtPoint: point];
if (row < 0)
return NO;
return NSPointInRect(point, [self actionRectForRow: row]);
}
@end