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
|
/*
Grr RSS Reader
Copyright (C) 2006, 2007 Guenther Noack <guenther@unix-ag.uni-kl.de>
Copyright (C) 2009-2010 GNUstep Application Team
Riccardo Mottola
This application 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 3 of the License, or (at your option) any later version.
This application 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
Library General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
*/
#import <RSSKit/RSSArticleProtocol.h>
#import "ArticleOperations.h"
#import "Article.h"
#ifdef __APPLE__
#import "GNUstep.h"
#endif
#define BROWSE_IDENTIFIER @"Article.Ops.Browse"
@implementation ArticleOperationsComponent
-(id)init
{
if ((self = [super init]) != nil)
{
NSArray* identifiers;
NSMenu* menu;
menu = [[[NSApp mainMenu] itemWithTag:2] submenu];
// Article browsing toolbar item
browseItem = [[NSToolbarItem alloc] initWithItemIdentifier: BROWSE_IDENTIFIER];
[browseItem setLabel: _(@"View in WWW")];
[browseItem setImage: [NSImage imageNamed: @"ArticleLink"]];
[browseItem setAction: @selector(browseSelectedArticles)];
[browseItem setTarget: self];
// Article browsing menu item
browseMenuItem = [[NSMenuItem alloc] initWithTitle: _(@"View in WWW")
action: @selector(browseSelectedArticles)
keyEquivalent: @"b"];
[browseMenuItem setTarget: self];
// Add the menu
[menu addItem: browseMenuItem];
// Provided identifiers
identifiers = [NSArray arrayWithObjects:
BROWSE_IDENTIFIER,
nil
];
ASSIGN(allowedIdentifiers, identifiers);
ASSIGN(defaultIdentifiers, allowedIdentifiers);
// Init selected articles with empty set
ASSIGN(selectedArticles, [NSSet new]);
}
return self;
}
// input accepting component protocol
-(void)componentDidUpdateSet: (NSNotification*) aNotification
{
BOOL isEnabled;
id<OutputProvidingComponent> component = [aNotification object];
ASSIGN(selectedArticles, [component objectsForPipeType: [PipeType articleType]]);
isEnabled = ([selectedArticles count] > 0) ? YES : NO;
[browseItem setEnabled: isEnabled];
#ifdef GRRRDEBUG
[debugItem setEnabled: isEnabled];
#endif
}
// toolbar delegate protocol
- (NSToolbarItem*)toolbar: (NSToolbar*)toolbar
itemForItemIdentifier: (NSString*)itemIdentifier
willBeInsertedIntoToolbar: (BOOL)flag
{
if ([itemIdentifier isEqualToString: BROWSE_IDENTIFIER]) {
return browseItem;
}
#ifdef GRRRDEBUG
else if ([itemIdentifier isEqualToString: @"Grr Debug Article"]) {
return debugItem;
}
#endif
return nil; // this identifier was not found here
}
- (NSArray*) toolbarAllowedItemIdentifiers: (NSToolbar*)toolbar
{
return allowedIdentifiers;
}
- (NSArray*) toolbarDefaultItemIdentifiers: (NSToolbar*)toolbar
{
return defaultIdentifiers;
}
// own methods
-(void)browseSelectedArticles
{
NSEnumerator* enumerator = [selectedArticles objectEnumerator];
id<RSSArticle> article;
while ((article = [enumerator nextObject]) != nil) {
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString:[article url]]];
}
}
#ifdef GRRRDEBUG
-(void)debugSelectedArticles
{
NSEnumerator* enumerator = [selectedArticles objectEnumerator];
id<Article> article;
while ((article = [enumerator nextObject]) != nil)
{
NSLog(@"Article %@ is \n%@", [article headline], [article plistDictionary]);
NSLog(@"Storage reseult: %d", [article store]);
}
}
#endif
@end
|