| 1 |
/* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */ |
| 2 |
|
| 3 |
/* AbiSource Application Framework |
| 4 |
* Copyright (C) 2005 Francis James Franklin |
| 5 |
* |
| 6 |
* This program is free software; you can redistribute it and/or |
| 7 |
* modify it under the terms of the GNU General Public License |
| 8 |
* as published by the Free Software Foundation; either version 2 |
| 9 |
* of the License, or (at your option) any later version. |
| 10 |
* |
| 11 |
* This program is distributed in the hope that it will be useful, |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
* GNU General Public License for more details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License |
| 17 |
* along with this program; if not, write to the Free Software |
| 18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 19 |
* 02110-1301 USA. |
| 20 |
*/ |
| 21 |
|
| 22 |
#include "ut_assert.h" |
| 23 |
|
| 24 |
#include "xap_CocoaToolProvider.h" |
| 25 |
#include "ap_CocoaTool.h" |
| 26 |
|
| 27 |
@implementation XAP_CocoaToolProvider |
| 28 |
|
| 29 |
+ (XAP_CocoaToolProvider *)AbiWordToolProvider |
| 30 |
{ |
| 31 |
XAP_CocoaToolProvider * provider = [[XAP_CocoaToolProvider alloc] initWithName:@"AbiWord"]; |
| 32 |
|
| 33 |
[AP_CocoaTool addStandardToolsToProvider:provider]; |
| 34 |
|
| 35 |
[provider autorelease]; |
| 36 |
|
| 37 |
return provider; |
| 38 |
} |
| 39 |
|
| 40 |
- (id)initWithName:(NSString *)name |
| 41 |
{ |
| 42 |
if (![super init]) |
| 43 |
{ |
| 44 |
return nil; |
| 45 |
} |
| 46 |
UT_ASSERT(name); |
| 47 |
|
| 48 |
m_name = name; |
| 49 |
[m_name retain]; |
| 50 |
|
| 51 |
m_identifiers = [[NSMutableArray alloc] initWithCapacity:16]; |
| 52 |
m_tools = [[NSMutableDictionary alloc] initWithCapacity:16]; |
| 53 |
return self; |
| 54 |
} |
| 55 |
|
| 56 |
- (void)dealloc |
| 57 |
{ |
| 58 |
[m_name release]; |
| 59 |
[m_identifiers release]; |
| 60 |
[m_tools release]; |
| 61 |
[super dealloc]; |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Get the name of the provider. |
| 66 |
* |
| 67 |
* \return The name identifying the provider. |
| 68 |
*/ |
| 69 |
- (NSString *)name |
| 70 |
{ |
| 71 |
return m_name; |
| 72 |
} |
| 73 |
|
| 74 |
/** |
| 75 |
* Add a tool to the provider's list of tools. The provider will send the tool a setProvider: message. |
| 76 |
* |
| 77 |
* \param tool An object which implements the XAP_CocoaPlugin_Tool protocol. |
| 78 |
*/ |
| 79 |
- (void)addTool:(id <NSObject, XAP_CocoaPlugin_Tool>)tool |
| 80 |
{ |
| 81 |
NSString * identifier = [tool identifier]; |
| 82 |
|
| 83 |
if ([m_identifiers containsObject:identifier] == NO) |
| 84 |
{ |
| 85 |
[m_identifiers addObject:identifier]; |
| 86 |
|
| 87 |
[m_tools setObject:tool forKey:identifier]; |
| 88 |
|
| 89 |
[tool setProvider:self]; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
/** |
| 94 |
* Remove a tool from the provider's list of tools. The provider will send the tool a setProvider:nil message. |
| 95 |
* |
| 96 |
* \param identifier The identifier of the tool which is to be removed. |
| 97 |
*/ |
| 98 |
- (void)removeToolWithIdentifier:(NSString *)identifier |
| 99 |
{ |
| 100 |
if ([m_identifiers containsObject:identifier]) |
| 101 |
{ |
| 102 |
id <NSObject, XAP_CocoaPlugin_Tool> tool = (id <NSObject, XAP_CocoaPlugin_Tool>) [m_tools objectForKey:identifier]; |
| 103 |
|
| 104 |
[m_identifiers removeObject:identifier]; |
| 105 |
|
| 106 |
[m_tools removeObjectForKey:identifier]; |
| 107 |
|
| 108 |
if (tool) |
| 109 |
{ |
| 110 |
[tool setProvider:nil]; |
| 111 |
} |
| 112 |
} |
| 113 |
} |
| 114 |
|
| 115 |
/** |
| 116 |
* Get the tool with the specified identifier. |
| 117 |
* |
| 118 |
* \param identifier The identifier of the tool which is desired. |
| 119 |
* |
| 120 |
* \return The specified tool, or nil if the identifier is not matched. |
| 121 |
*/ |
| 122 |
- (id <NSObject, XAP_CocoaPlugin_Tool>)toolWithIdentifier:(NSString *)identifier |
| 123 |
{ |
| 124 |
id <NSObject, XAP_CocoaPlugin_Tool> tool = (id <NSObject, XAP_CocoaPlugin_Tool>) [m_tools objectForKey:identifier]; |
| 125 |
|
| 126 |
return tool; |
| 127 |
} |
| 128 |
|
| 129 |
/** |
| 130 |
* Get the identifiers of the tools provided. |
| 131 |
* |
| 132 |
* \return The identifiers of the tools provided. |
| 133 |
*/ |
| 134 |
- (NSArray *)toolIdentifiers |
| 135 |
{ |
| 136 |
return m_identifiers; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* See whether the provider provides a specific tool, and get the description (tooltip). |
| 141 |
* |
| 142 |
* \param identifier The internal identifier of the desired tool. |
| 143 |
* |
| 144 |
* \return The description (the tooltip) of the tool if the identifier is recognized, otherwise nil. |
| 145 |
*/ |
| 146 |
- (NSString *)toolDescription:(NSString *)identifier |
| 147 |
{ |
| 148 |
id <NSObject, XAP_CocoaPlugin_Tool> tool = (id <NSObject, XAP_CocoaPlugin_Tool>) [m_tools objectForKey:identifier]; |
| 149 |
|
| 150 |
return tool ? [tool description] : 0; |
| 151 |
} |
| 152 |
|
| 153 |
@end |