group together pause and resume toolbar buttons

This commit is contained in:
Mitchell Livingston 2007-12-06 17:21:42 +00:00
parent f0f71ec09c
commit d2049cc048
6 changed files with 202 additions and 33 deletions

View File

@ -73,6 +73,7 @@
A21282A80CA6C66800EAEE0F /* StatusBarView.m in Sources */ = {isa = PBXBuildFile; fileRef = A21282A60CA6C66800EAEE0F /* StatusBarView.m */; };
A21567ED0A9A5034004DECD6 /* MessageWindow.nib in Resources */ = {isa = PBXBuildFile; fileRef = A21567EB0A9A5034004DECD6 /* MessageWindow.nib */; };
A215760B0C0D449A0057A26A /* NSBezierPathAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = A21576090C0D449A0057A26A /* NSBezierPathAdditions.m */; };
A219798B0D07B78400438EA7 /* ButtonGroupToolbarItem.m in Sources */ = {isa = PBXBuildFile; fileRef = A219798A0D07B78400438EA7 /* ButtonGroupToolbarItem.m */; };
A21DFF100A292B2B007C5F76 /* Transfers.png in Resources */ = {isa = PBXBuildFile; fileRef = A21DFF0F0A292B2B007C5F76 /* Transfers.png */; };
A21F5B890AF25FB6008CE5CE /* ActionMenuRatioToDisplayRatioTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = A21F5B870AF25FB6008CE5CE /* ActionMenuRatioToDisplayRatioTransformer.m */; };
A21F5C040AF26DD5008CE5CE /* ActionMenuSpeedToDisplayLimitTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = A21F5C020AF26DD5008CE5CE /* ActionMenuSpeedToDisplayLimitTransformer.m */; };
@ -406,6 +407,8 @@
A21282A60CA6C66800EAEE0F /* StatusBarView.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = StatusBarView.m; path = macosx/StatusBarView.m; sourceTree = "<group>"; };
A21576090C0D449A0057A26A /* NSBezierPathAdditions.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = NSBezierPathAdditions.m; path = macosx/NSBezierPathAdditions.m; sourceTree = "<group>"; };
A215760A0C0D449A0057A26A /* NSBezierPathAdditions.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = NSBezierPathAdditions.h; path = macosx/NSBezierPathAdditions.h; sourceTree = "<group>"; };
A21979890D07B78400438EA7 /* ButtonGroupToolbarItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ButtonGroupToolbarItem.h; path = macosx/ButtonGroupToolbarItem.h; sourceTree = "<group>"; };
A219798A0D07B78400438EA7 /* ButtonGroupToolbarItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ButtonGroupToolbarItem.m; path = macosx/ButtonGroupToolbarItem.m; sourceTree = "<group>"; };
A21DFF0F0A292B2B007C5F76 /* Transfers.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = Transfers.png; path = macosx/Images/Transfers.png; sourceTree = "<group>"; };
A21F5B860AF25FB6008CE5CE /* ActionMenuRatioToDisplayRatioTransformer.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = ActionMenuRatioToDisplayRatioTransformer.h; path = macosx/ActionMenuRatioToDisplayRatioTransformer.h; sourceTree = "<group>"; };
A21F5B870AF25FB6008CE5CE /* ActionMenuRatioToDisplayRatioTransformer.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; name = ActionMenuRatioToDisplayRatioTransformer.m; path = macosx/ActionMenuRatioToDisplayRatioTransformer.m; sourceTree = "<group>"; };
@ -780,6 +783,8 @@
A28E1DD50CFFD8A700E16385 /* BottomBarView.h */,
A2C89D5F0CFCBF57004CC2BC /* ButtonToolbarItem.m */,
A28E1DDF0CFFD8EC00E16385 /* ButtonToolbarItem.h */,
A21979890D07B78400438EA7 /* ButtonGroupToolbarItem.h */,
A219798A0D07B78400438EA7 /* ButtonGroupToolbarItem.m */,
A257C17F0CAD3003004E121C /* PeerTableView.h */,
A257C1800CAD3003004E121C /* PeerTableView.m */,
A2E23AC30CB5E1930002BB25 /* InfoTabButtonCell.h */,
@ -1633,6 +1638,7 @@
A2C89D600CFCBF57004CC2BC /* ButtonToolbarItem.m in Sources */,
A28E1DBA0CFFD41800E16385 /* BottomBarView.m in Sources */,
A28E1E160D00574A00E16385 /* ActionPopUpButton.m in Sources */,
A219798B0D07B78400438EA7 /* ButtonGroupToolbarItem.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};

View File

@ -0,0 +1,34 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2007 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#import <Cocoa/Cocoa.h>
@interface ButtonGroupToolbarItem : NSToolbarItem
{
NSArray * fIdentifiers;
}
- (void) setIdentifiers: (NSArray *) identifiers;
@end

View File

@ -0,0 +1,60 @@
/******************************************************************************
* $Id$
*
* Copyright (c) 2007 Transmission authors and contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#import "ButtonGroupToolbarItem.h"
@implementation ButtonGroupToolbarItem
- (void) dealloc
{
[fIdentifiers release];
[super dealloc];
}
- (void) setIdentifiers: (NSArray *) identifiers
{
[fIdentifiers release];
fIdentifiers = [identifiers retain];
}
- (void) validate
{
NSSegmentedControl * control = (NSSegmentedControl *)[self view];
int i;
for (i = 0; i < [control segmentCount]; i++)
[control setEnabled: [[self target] validateToolbarItem:
[[[NSToolbarItem alloc] initWithItemIdentifier: [fIdentifiers objectAtIndex: i]] autorelease]] forSegment: i];
}
/*- (NSMenuItem *) menuFormRepresentation
{
NSMenuItem * menu = [[NSMenuItem alloc] initWithTitle: [self label] action: [self action] keyEquivalent: @""];
[menu setTarget: [self target]];
[menu setEnabled: [[self target] validateToolbarItem: self]];
return [menu autorelease];
}*/
@end

View File

@ -213,6 +213,8 @@
- (void) toggleFilterBar: (id) sender;
- (void) showFilterBar: (BOOL) show animate: (BOOL) animate;
- (void) selectedToolbarClicked: (id) sender;
- (void) doNothing: (id) sender; //needed for menu items that use bindings with no associated action
- (void) setWindowSizeToFit;

View File

@ -32,6 +32,7 @@
#import "StatsWindowController.h"
#import "AboutWindowController.h"
#import "ButtonToolbarItem.h"
#import "ButtonGroupToolbarItem.h"
#import "NSApplicationAdditions.h"
#import "NSStringAdditions.h"
#import "UKKQueue.h"
@ -43,15 +44,17 @@
#import <Sparkle/Sparkle.h>
#define TOOLBAR_CREATE @"Toolbar Create"
#define TOOLBAR_OPEN @"Toolbar Open"
#define TOOLBAR_REMOVE @"Toolbar Remove"
#define TOOLBAR_INFO @"Toolbar Info"
#define TOOLBAR_PAUSE_ALL @"Toolbar Pause All"
#define TOOLBAR_RESUME_ALL @"Toolbar Resume All"
#define TOOLBAR_PAUSE_SELECTED @"Toolbar Pause Selected"
#define TOOLBAR_RESUME_SELECTED @"Toolbar Resume Selected"
#define TOOLBAR_FILTER @"Toolbar Toggle Filter"
#define TOOLBAR_CREATE @"Toolbar Create"
#define TOOLBAR_OPEN @"Toolbar Open"
#define TOOLBAR_REMOVE @"Toolbar Remove"
#define TOOLBAR_INFO @"Toolbar Info"
#define TOOLBAR_PAUSE_ALL @"Toolbar Pause All"
#define TOOLBAR_RESUME_ALL @"Toolbar Resume All"
#define TOOLBAR_PAUSE_RESUME_ALL @"Toolbar Pause / Resume All"
#define TOOLBAR_PAUSE_SELECTED @"Toolbar Pause Selected"
#define TOOLBAR_RESUME_SELECTED @"Toolbar Resume Selected"
#define TOOLBAR_PAUSE_RESUME_SELECTED @"Toolbar Pause / Resume Selected"
#define TOOLBAR_FILTER @"Toolbar Toggle Filter"
#define SORT_DATE @"Date"
#define SORT_NAME @"Name"
@ -214,7 +217,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (void) awakeFromNib
{
NSToolbar * toolbar = [[NSToolbar alloc] initWithIdentifier: @"Transmission Toolbar"];
NSToolbar * toolbar = [[NSToolbar alloc] initWithIdentifier: @"TRMainToolbar"];
[toolbar setDelegate: self];
[toolbar setAllowsUserCustomization: YES];
[toolbar setAutosavesConfiguration: YES];
@ -2637,7 +2640,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (NSToolbarItem *) toolbar: (NSToolbar *) toolbar itemForItemIdentifier: (NSString *) ident willBeInsertedIntoToolbar: (BOOL) flag
{
ButtonToolbarItem * item = [[ButtonToolbarItem alloc] initWithItemIdentifier: ident];
ButtonToolbarItem * item = [[[ButtonToolbarItem alloc] initWithItemIdentifier: ident] autorelease];
NSButton * button = [[NSButton alloc] initWithFrame: NSZeroRect];
[button setBezelStyle: NSTexturedRoundedBezelStyle];
@ -2707,23 +2710,70 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[item setTarget: self];
[item setAction: @selector(resumeAllTorrents:)];
}
else if ([ident isEqualToString: TOOLBAR_PAUSE_SELECTED])
else if ([ident isEqualToString: TOOLBAR_PAUSE_RESUME_ALL])
{
[item setLabel: NSLocalizedString(@"Pause", "Pause toolbar item -> label")];
[item setPaletteLabel: NSLocalizedString(@"Pause Selected", "Pause toolbar item -> palette label")];
[item setToolTip: NSLocalizedString(@"Pause selected transfers", "Pause toolbar item -> tooltip")];
[item setImage: [NSImage imageNamed: @"PauseSelected.png"]];
[item setTarget: self];
[item setAction: @selector(stopSelectedTorrents:)];
ButtonGroupToolbarItem * groupItem = [[[ButtonGroupToolbarItem alloc] initWithItemIdentifier: ident] autorelease];
NSSegmentedControl * segmentedControl = [[NSSegmentedControl alloc] initWithFrame: NSZeroRect];
[groupItem setView: segmentedControl];
[segmentedControl setSegmentCount: 2];
[(NSSegmentedCell *)[segmentedControl cell] setTrackingMode: NSSegmentSwitchTrackingMomentary];
NSSize groupSize = NSMakeSize(72.0, 25.0);
[groupItem setMinSize: groupSize];
[groupItem setMaxSize: groupSize];
[groupItem setLabel: NSLocalizedString(@"Apply All", "All toolbar item -> label")];
[groupItem setPaletteLabel: NSLocalizedString(@"Pause / Resume All", "All toolbar item -> palette label")];
[groupItem setTarget: self];
[groupItem setAction: @selector(allToolbarClicked:)];
[groupItem setIdentifiers: [NSArray arrayWithObjects: TOOLBAR_PAUSE_ALL, TOOLBAR_RESUME_ALL, nil]];
[segmentedControl setImage: [NSImage imageNamed: @"PauseAll.png"] forSegment: 0];
[(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Pause all transfers",
"All toolbar item -> tooltip") forSegment: 0];
[segmentedControl setImage: [NSImage imageNamed: @"ResumeAll.png"] forSegment: 1];
[(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Resume all transfers",
"All toolbar item -> tooltip") forSegment: 1];
[segmentedControl release];
return groupItem;
}
else if ([ident isEqualToString: TOOLBAR_RESUME_SELECTED])
else if ([ident isEqualToString: TOOLBAR_PAUSE_RESUME_SELECTED])
{
[item setLabel: NSLocalizedString(@"Resume", "Resume toolbar item -> label")];
[item setPaletteLabel: NSLocalizedString(@"Resume Selected", "Resume toolbar item -> palette label")];
[item setToolTip: NSLocalizedString(@"Resume selected transfers", "Resume toolbar item -> tooltip")];
[item setImage: [NSImage imageNamed: @"ResumeSelected.png"]];
[item setTarget: self];
[item setAction: @selector(resumeSelectedTorrents:)];
ButtonGroupToolbarItem * groupItem = [[[ButtonGroupToolbarItem alloc] initWithItemIdentifier: ident] autorelease];
NSSegmentedControl * segmentedControl = [[NSSegmentedControl alloc] initWithFrame: NSZeroRect];
[groupItem setView: segmentedControl];
[segmentedControl setSegmentCount: 2];
[(NSSegmentedCell *)[segmentedControl cell] setTrackingMode: NSSegmentSwitchTrackingMomentary];
NSSize groupSize = NSMakeSize(72.0, 25.0);
[groupItem setMinSize: groupSize];
[groupItem setMaxSize: groupSize];
[groupItem setLabel: NSLocalizedString(@"Apply Selected", "Selected toolbar item -> label")];
[groupItem setPaletteLabel: NSLocalizedString(@"Pause / Resume Selected", "Selected toolbar item -> palette label")];
[groupItem setTarget: self];
[groupItem setAction: @selector(selectedToolbarClicked:)];
[groupItem setIdentifiers: [NSArray arrayWithObjects: TOOLBAR_PAUSE_SELECTED, TOOLBAR_RESUME_SELECTED, nil]];
[segmentedControl setImage: [NSImage imageNamed: @"PauseSelected.png"] forSegment: 0];
[(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Pause selected transfers",
"Selected toolbar item -> tooltip") forSegment: 0];
[segmentedControl setImage: [NSImage imageNamed: @"ResumeSelected.png"] forSegment: 1];
[(NSSegmentedCell *)[segmentedControl cell] setToolTip: NSLocalizedString(@"Resume selected transfers",
"Selected toolbar item -> tooltip") forSegment: 1];
[segmentedControl release];
return groupItem;
}
else if ([ident isEqualToString: TOOLBAR_FILTER])
{
@ -2736,20 +2786,37 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
[item setAutovalidates: NO];
}
else
{
[item release];
return nil;
}
return [item autorelease];
return item;
}
#warning use constants
- (void) allToolbarClicked: (id) sender
{
if ([sender selectedSegment] == 0)
[self stopAllTorrents: sender];
else if ([sender selectedSegment] == 1)
[self resumeAllTorrents: sender];
else;
}
#warning use constants
- (void) selectedToolbarClicked: (id) sender
{
if ([sender selectedSegment] == 0)
[self stopSelectedTorrents: sender];
else if ([sender selectedSegment] == 1)
[self resumeSelectedTorrents: sender];
else;
}
- (NSArray *) toolbarAllowedItemIdentifiers: (NSToolbar *) toolbar
{
return [NSArray arrayWithObjects:
TOOLBAR_CREATE, TOOLBAR_OPEN, TOOLBAR_REMOVE,
TOOLBAR_PAUSE_SELECTED, TOOLBAR_RESUME_SELECTED,
TOOLBAR_PAUSE_ALL, TOOLBAR_RESUME_ALL, TOOLBAR_FILTER, TOOLBAR_INFO,
TOOLBAR_PAUSE_RESUME_SELECTED, TOOLBAR_PAUSE_RESUME_ALL,
TOOLBAR_FILTER, TOOLBAR_INFO,
NSToolbarSeparatorItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
@ -2761,7 +2828,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
return [NSArray arrayWithObjects:
TOOLBAR_CREATE, TOOLBAR_OPEN, TOOLBAR_REMOVE,
NSToolbarSeparatorItemIdentifier,
TOOLBAR_PAUSE_ALL, TOOLBAR_RESUME_ALL,
TOOLBAR_PAUSE_RESUME_ALL,
NSToolbarFlexibleSpaceItemIdentifier,
TOOLBAR_FILTER, TOOLBAR_INFO, nil];
}
@ -2769,7 +2836,7 @@ void sleepCallBack(void * controller, io_service_t y, natural_t messageType, voi
- (BOOL) validateToolbarItem: (NSToolbarItem *) toolbarItem
{
NSString * ident = [toolbarItem itemIdentifier];
//enable remove item
if ([ident isEqualToString: TOOLBAR_REMOVE])
return [fTableView numberOfSelectedRows] > 0;