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
|
/*
Grr RSS Reader
Copyright (C) 2006, 2007 Guenther Noack <guenther@unix-ag.uni-kl.de>
Copyright (C) 2009 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 "ArticleTextViewPlugin.h"
#import "Article.h"
#import "NSString+TolerantHTML.h"
#import "ExtendedWindow.h"
#ifdef __APPLE__
#import "GNUstep.h"
#endif
@implementation ArticleTextViewPlugin
-(void)awakeFromNib
{
NSNotificationCenter* notifCenter;
[_view retain];
ASSIGN(textView, [scrollView documentView]);
[textView setDelegate: self];
notifCenter = [NSNotificationCenter defaultCenter];
[notifCenter addObserver: self
selector: @selector(scrollUp:)
name: ScrollArticleUpNotification
object: nil];
[notifCenter addObserver: self
selector: @selector(scrollDown:)
name: ScrollArticleDownNotification
object: nil];
}
-(void)componentDidUpdateSet: (NSNotification*) aNotification
{
NSSet* articles = [[aNotification object] objectsForPipeType: [PipeType articleType]];
if ([articles count] == 1) {
id<Article> article = [[articles allObjects] objectAtIndex: 0];
[headlineView setStringValue: [article headline]];
NS_DURING
[[textView textStorage] setAttributedString: [[article content] parseHTML]];
NS_HANDLER
NSLog(
@"ERROR: HTML PARSING:\n name: %@\n desc: %@",
[localException name],
[localException description]
);
[[textView textStorage] setAttributedString:
AUTORELEASE([[NSAttributedString alloc] initWithString: [article content]])];
NS_ENDHANDLER
[article setRead: YES];
// Scroll to top
//[textView scrollRangeToVisible: NSMakeRange(0,0)];
[[scrollView contentView] scrollToPoint: NSMakePoint(0.0,0.0)];
} else if ([articles count] == 0) {
[headlineView setStringValue: NSLocalizedString(
@"No articles selected.",
@"Shown in the article view headline"
)];
[textView setString: @""];
} else {
// too many articles
[headlineView setStringValue: [NSString stringWithFormat: NSLocalizedString(
@"%d articles selected",
@"Shown in the article view headline"
), [articles count]]];
[textView setString: NSLocalizedString(
@"\nPlease select only one article.",
@"Shown in the article view text area"
)];
}
}
-(void) scrollDown: (id)sender
{
[self scrollWithDownFlag: YES];
}
-(void) scrollUp: (id)sender
{
[self scrollWithDownFlag: NO];
}
/**
* Scrolls the visible part of the article view down or up.
*/
-(void) scrollWithDownFlag: (BOOL) isDown
{
NSRect aRect = [scrollView documentVisibleRect];
double delta = aRect.size.height - [scrollView verticalPageScroll];
if (isDown == NO) {
delta = -delta;
}
aRect.origin.y += delta;
[textView scrollRectToVisible: aRect];
}
/**
* Is executed when the user clicks a link.
*/
-(BOOL) textView: (NSTextView*) textView
clickedOnLink: (id) link
atIndex: (unsigned) charIndex
{
BOOL result = NO;
NSLog(@"textView:clickedOnLink: %@ atIndex: %d", link, charIndex);
if ([link isKindOfClass: [NSURL class]]) {
result = [[NSWorkspace sharedWorkspace] openURL: (NSURL*)link];
}
return result;
}
@end
|