1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
//
// Lynkeos
// $Id$
//
// Created by Jean-Etienne LAMIAUD on Tue May 22 2007.
// Copyright (c) 2007-2018. Jean-Etienne LAMIAUD
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//
#include "MyPluginsController.h"
#include "MyDocument.h"
#include "MyImageListWindow.h"
NSString * const toolbarProcPrefix = @"LynkeosProcToolbarItem_";
@implementation MyImageListWindow(Toolbar)
- (NSArray *)toolbarSelectableItemIdentifiers:(NSToolbar *)toolbar
{
if ( toolbar != _toolBar )
return( nil );
// Toolbar items identifiers are derived from their class name
NSMutableArray *allowed = [NSMutableArray array];
NSEnumerator *procList = [[[MyPluginsController defaultPluginController]
getProcessingViews] objectEnumerator];
LynkeosProcessingViewRegistry *reg;
while ( (reg = [procList nextObject]) != nil )
{
NSMutableString *ident =
[NSMutableString stringWithString:toolbarProcPrefix];
[ident appendString:[reg->controller className]];
if ( reg->ident != nil )
[ident appendString:reg->ident];
[allowed addObject:ident];
}
return( allowed );
}
- (NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar
{
if ( toolbar != _toolBar )
return( nil );
NSMutableArray *allowed =
(NSMutableArray*)[self toolbarSelectableItemIdentifiers:toolbar];
[allowed addObjectsFromArray:
[NSArray arrayWithObjects:
NSToolbarCustomizeToolbarItemIdentifier,
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarSpaceItemIdentifier,
NSToolbarSeparatorItemIdentifier, nil]];
return( allowed );
}
- (NSArray *) toolbarDefaultItemIdentifiers: (NSToolbar *) toolbar
{
if ( toolbar != _toolBar )
return( nil );
return( [NSArray arrayWithObjects:
@"LynkeosProcToolbarItem_MyListManagement",
@"LynkeosProcToolbarItem_MyImageAlignerView",
@"LynkeosProcToolbarItem_MyImageAnalyzerView",
@"LynkeosProcToolbarItem_MyImageStackerView",
@"LynkeosProcToolbarItem_MyDeconvolutionView",
@"LynkeosProcToolbarItem_MyUnsharpMaskView",
@"LynkeosProcToolbarItem_MyWaveletView",
@"LynkeosProcToolbarItem_MyProcessStackView",
NSToolbarFlexibleSpaceItemIdentifier,
NSToolbarCustomizeToolbarItemIdentifier,
nil] );
}
- (NSToolbarItem *) toolbar:(NSToolbar *)toolbar
itemForItemIdentifier:(NSString *)itemIdentifier
willBeInsertedIntoToolbar:(BOOL)flag
{
if ( toolbar != _toolBar )
return( nil );
NSToolbarItem *item = nil;
// Retrieve the class from the identifier
if ([itemIdentifier hasPrefix:toolbarProcPrefix])
{
NSEnumerator *list = [[[MyPluginsController defaultPluginController]
getProcessingViews] objectEnumerator];
LynkeosProcessingViewRegistry *reg = nil;
NSUInteger tag = NSNotFound, i = 0;
while( (reg = [list nextObject]) != nil )
{
NSMutableString *procIdent =
[NSMutableString stringWithString:toolbarProcPrefix];
[procIdent appendString:[reg->controller className]];
if ( reg->ident != nil )
[procIdent appendString:reg->ident];
if ( [procIdent isEqual:itemIdentifier] )
{
tag = i;
break;
}
i++;
}
if (tag == NSNotFound)
// Item not available (for instance, a plugin has been deinstalled)
return(nil);
// Initialize the item
item = [[[NSToolbarItem alloc] initWithItemIdentifier:
itemIdentifier] autorelease];
NSString *menuTitle, *title, *key, *tip;
NSImage *icon;
[reg->controller getProcessingTitle:&menuTitle toolTitle:&title
key:&key icon:&icon tip:&tip
forConfig:reg->config];
[item setLabel:title];
[item setPaletteLabel:title];
[item setToolTip:tip];
[item setImage:icon];
[item setTag:tag];
[item setTarget:self];
[item setAction:@selector(activateProcessingView:)];
}
return item;
}
- (BOOL)validateToolbarItem:(NSToolbarItem *)theItem
{
unsigned int mask = ProcessingViewAuthorized|_listMode;
return( !_isProcessing &&
(_processingAuthorization[[theItem tag]] & mask) == mask );
}
@end
|