mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
* Headers/AppKit/AppKit.h: added NSHelpManager.h.
* Headers/AppKit/NSHelpManager.h: declaration for new method -pathForHelpResource: * Source/NSHelpManager.m: implemented -pathForHelpResource: in the NSBundle category. -pathForHelpResource: looks for help files giving the priority to localized resources. -showHelp: looks for rtfd files too. * Source/GSHelpManagerPanel.m: various fixes to avoid a crash when quitting and to resize correctly the NSTextView. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@23164 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b718aee750
commit
30dc6bf85a
5 changed files with 177 additions and 76 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
2006-07-15 Enrico Sersale <enrico@fibernet.ro>
|
||||
|
||||
* Headers/AppKit/AppKit.h: added NSHelpManager.h.
|
||||
* Headers/AppKit/NSHelpManager.h: declaration for new method -pathForHelpResource:
|
||||
* Source/NSHelpManager.m: implemented -pathForHelpResource: in the NSBundle
|
||||
category. -pathForHelpResource: looks for help files giving the priority
|
||||
to localized resources.
|
||||
-showHelp: looks for rtfd files too.
|
||||
* Source/GSHelpManagerPanel.m: various fixes to avoid a crash when quitting
|
||||
and to resize correctly the NSTextView.
|
||||
|
||||
2006-07-14 01:17 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSNibCompatibility.h:
|
||||
|
|
|
@ -81,6 +81,7 @@
|
|||
#include <AppKit/NSForm.h>
|
||||
#include <AppKit/NSFormCell.h>
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
#include <AppKit/NSHelpManager.h>
|
||||
#include <AppKit/NSHelpPanel.h>
|
||||
#include <AppKit/NSImage.h>
|
||||
#include <AppKit/NSImageCell.h>
|
||||
|
|
|
@ -37,7 +37,8 @@
|
|||
@class NSAttributedString;
|
||||
|
||||
@interface NSBundle (NSHelpManager)
|
||||
- (NSAttributedString*) contextHelpForKey: (NSString*) key;
|
||||
- (NSString *)pathForHelpResource:(NSString *)fileName;
|
||||
- (NSAttributedString *)contextHelpForKey:(NSString *)key;
|
||||
@end
|
||||
|
||||
@interface NSApplication (NSHelpManager)
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "AppKit/NSApplication.h"
|
||||
#include "AppKit/NSAttributedString.h"
|
||||
#include "AppKit/NSTextView.h"
|
||||
#include "AppKit/NSTextContainer.h"
|
||||
#include "AppKit/NSScrollView.h"
|
||||
#include "AppKit/NSClipView.h"
|
||||
#include "AppKit/NSColor.h"
|
||||
|
@ -46,68 +47,69 @@ static GSHelpManagerPanel* _GSsharedGSHelpPanel;
|
|||
return _GSsharedGSHelpPanel;
|
||||
}
|
||||
|
||||
/* This window should not be destroyed... So we don't allow it to! */
|
||||
- (id) retain
|
||||
- (id)init
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) release
|
||||
{
|
||||
}
|
||||
|
||||
- (id) autorelease
|
||||
{
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
NSScrollView *scrollView;
|
||||
NSRect scrollViewRect = {{0, 0}, {470, 150}};
|
||||
NSRect winRect = {{100, 100}, {470, 150}};
|
||||
unsigned int style = NSTitledWindowMask | NSClosableWindowMask
|
||||
| NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||
unsigned int style = NSTitledWindowMask | NSClosableWindowMask
|
||||
| NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||
|
||||
self = [super initWithContentRect: winRect
|
||||
styleMask: style
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
|
||||
[self initWithContentRect: winRect
|
||||
styleMask: style
|
||||
backing: NSBackingStoreRetained
|
||||
defer: NO];
|
||||
[self setFloatingPanel: YES];
|
||||
[self setRepresentedFilename: @"Help"];
|
||||
[self setTitle: @"Help"];
|
||||
[self setDocumentEdited: NO];
|
||||
if (self) {
|
||||
NSRect scrollViewRect = {{0, 0}, {470, 150}};
|
||||
NSRect r;
|
||||
NSScrollView *scrollView;
|
||||
|
||||
scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect];
|
||||
[scrollView setHasHorizontalScroller: NO];
|
||||
[scrollView setHasVerticalScroller: YES];
|
||||
[scrollView setAutoresizingMask: NSViewHeightSizable];
|
||||
|
||||
textView = [[NSTextView alloc] initWithFrame:
|
||||
[[scrollView contentView] frame]];
|
||||
[textView setEditable: NO];
|
||||
[textView setRichText: YES];
|
||||
[textView setSelectable: YES];
|
||||
// off white
|
||||
[textView setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.85
|
||||
alpha: 1.0]];
|
||||
[scrollView setDocumentView: textView];
|
||||
[[self contentView] addSubview: scrollView];
|
||||
RELEASE(scrollView);
|
||||
[self setReleasedWhenClosed: NO];
|
||||
[self setFloatingPanel: YES];
|
||||
// [self setTitle: NSLocalizedString(@"Help", @"")];
|
||||
[self setTitle: @"Help"];
|
||||
|
||||
scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect];
|
||||
[scrollView setHasHorizontalScroller: NO];
|
||||
[scrollView setHasVerticalScroller: YES];
|
||||
[scrollView setAutoresizingMask: NSViewHeightSizable];
|
||||
|
||||
r = [[scrollView contentView] frame];
|
||||
textView = [[NSTextView alloc] initWithFrame: r];
|
||||
[textView setRichText: YES];
|
||||
[textView setEditable: NO];
|
||||
[textView setSelectable: NO];
|
||||
[textView setHorizontallyResizable: NO];
|
||||
[textView setVerticallyResizable: YES];
|
||||
[textView setMinSize: NSMakeSize (0, 0)];
|
||||
[textView setMaxSize: NSMakeSize (1E7, 1E7)];
|
||||
[textView setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
||||
[[textView textContainer] setContainerSize: NSMakeSize(r.size.width, 1e7)];
|
||||
[[textView textContainer] setWidthTracksTextView: YES];
|
||||
[textView setUsesRuler: NO];
|
||||
// [textView setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0]];
|
||||
|
||||
[scrollView setDocumentView: textView];
|
||||
RELEASE(textView);
|
||||
|
||||
[[self contentView] addSubview: scrollView];
|
||||
RELEASE(scrollView);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) setHelpText: (NSAttributedString*) helpText
|
||||
- (void)setHelpText:(NSAttributedString *)helpText
|
||||
{
|
||||
// FIXME: The attributed text should be set, but there is
|
||||
// no public method for this.
|
||||
[textView setText: [helpText string]];
|
||||
[[textView textStorage] setAttributedString: helpText];
|
||||
}
|
||||
|
||||
- (void) close
|
||||
{
|
||||
[NSApp stopModal];
|
||||
if ([self isVisible])
|
||||
{
|
||||
[NSApp stopModal];
|
||||
}
|
||||
[super close];
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
@ -41,33 +42,107 @@
|
|||
|
||||
@implementation NSBundle (NSHelpManager)
|
||||
|
||||
- (NSAttributedString*) contextHelpForKey: (NSString*) key
|
||||
- (NSString *)pathForHelpResource:(NSString *)fileName
|
||||
{
|
||||
id helpFile = nil;
|
||||
NSDictionary *contextHelp =
|
||||
RETAIN([NSDictionary dictionaryWithContentsOfFile:
|
||||
[self pathForResource: @"Help" ofType: @"plist"]]);
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSMutableArray *array = [NSMutableArray array];
|
||||
NSArray *languages = [NSUserDefaults userLanguages];
|
||||
NSString *rootPath = [self bundlePath];
|
||||
NSString *primary;
|
||||
NSString *language;
|
||||
NSEnumerator *enumerator;
|
||||
|
||||
primary = [rootPath stringByAppendingPathComponent: @"Resources"];
|
||||
|
||||
enumerator = [languages objectEnumerator];
|
||||
|
||||
while ((language = [enumerator nextObject]))
|
||||
{
|
||||
NSString *langDir = [NSString stringWithFormat: @"%@.lproj", language];
|
||||
[array addObject: [primary stringByAppendingPathComponent: langDir]];
|
||||
}
|
||||
|
||||
[array addObject: primary];
|
||||
|
||||
primary = rootPath;
|
||||
|
||||
enumerator = [languages objectEnumerator];
|
||||
|
||||
while ((language = [enumerator nextObject]))
|
||||
{
|
||||
NSString *langDir = [NSString stringWithFormat: @"%@.lproj", language];
|
||||
[array addObject: [primary stringByAppendingPathComponent: langDir]];
|
||||
}
|
||||
|
||||
[array addObject: primary];
|
||||
|
||||
enumerator = [array objectEnumerator];
|
||||
|
||||
while ((rootPath = [enumerator nextObject]) != nil)
|
||||
{
|
||||
NSString *helpDir;
|
||||
NSString *helpPath;
|
||||
BOOL isdir;
|
||||
|
||||
helpPath = [rootPath stringByAppendingPathComponent: fileName];
|
||||
|
||||
if ([fm fileExistsAtPath: helpPath])
|
||||
{
|
||||
return helpPath;
|
||||
}
|
||||
|
||||
helpDir = [rootPath stringByAppendingPathComponent: @"Help"];
|
||||
|
||||
if ([fm fileExistsAtPath: helpDir isDirectory: & isdir] && isdir)
|
||||
{
|
||||
helpPath = [helpDir stringByAppendingPathComponent: fileName];
|
||||
|
||||
if ([fm fileExistsAtPath: helpPath])
|
||||
{
|
||||
return helpPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSAttributedString *)contextHelpForKey:(NSString *)key
|
||||
{
|
||||
NSFileManager *fm = [NSFileManager defaultManager];
|
||||
NSString *dictPath = [self pathForResource: @"Help" ofType: @"plist"];
|
||||
NSDictionary *contextHelp = nil;
|
||||
id helpFile = nil;
|
||||
|
||||
if (dictPath && [fm fileExistsAtPath: dictPath])
|
||||
{
|
||||
contextHelp = [NSDictionary dictionaryWithContentsOfFile: dictPath];
|
||||
}
|
||||
|
||||
if (contextHelp)
|
||||
{
|
||||
helpFile = [contextHelp objectForKey: key];
|
||||
}
|
||||
|
||||
|
||||
if (helpFile)
|
||||
{
|
||||
return [NSUnarchiver unarchiveObjectWithData:
|
||||
[helpFile objectForKey: @"NSHelpRTFContents"]];
|
||||
}
|
||||
else
|
||||
NSData *data = [helpFile objectForKey: @"NSHelpRTFContents"];
|
||||
return ((data != nil) ? [NSUnarchiver unarchiveObjectWithData: data] :
|
||||
nil) ;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
helpFile = [self
|
||||
pathForResource: key
|
||||
ofType: @"rtf"
|
||||
inDirectory: @"Help"];
|
||||
return AUTORELEASE([[NSAttributedString alloc] initWithPath: (NSString *)helpFile
|
||||
documentAttributes: NULL]);
|
||||
}
|
||||
helpFile = [self pathForHelpResource: key];
|
||||
|
||||
if (helpFile)
|
||||
{
|
||||
NSString *helpstr = [[NSAttributedString alloc] initWithPath: helpFile
|
||||
documentAttributes: NULL];
|
||||
return TEST_AUTORELEASE (helpstr);
|
||||
}
|
||||
}
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
|
@ -83,22 +158,33 @@
|
|||
|
||||
help = [info objectForKey: @"GSHelpContentsFile"];
|
||||
|
||||
if (!help)
|
||||
if (help == nil)
|
||||
{
|
||||
help = [info objectForKey: @"NSExecutable"];
|
||||
// If there's no specification, we look for a file named "appname.rtf"
|
||||
// If there's no specification, we look for a files named
|
||||
// "appname.rtfd" or "appname.rtf"
|
||||
}
|
||||
|
||||
if (help)
|
||||
{
|
||||
NSString *file = [mb pathForResource: help ofType: @"rtf"];
|
||||
|
||||
if (file)
|
||||
NSString *file;
|
||||
|
||||
if ([[help pathExtension] length] == 0)
|
||||
{
|
||||
[[NSWorkspace sharedWorkspace] openFile: file];
|
||||
return;
|
||||
}
|
||||
file = [mb pathForHelpResource: [help stringByAppendingPathExtension: @"rtfd"]];
|
||||
|
||||
if (file == nil)
|
||||
{
|
||||
file = [mb pathForHelpResource: [help stringByAppendingPathExtension: @"rtf"]];
|
||||
}
|
||||
}
|
||||
|
||||
if (file) {
|
||||
[[NSWorkspace sharedWorkspace] openFile: file];
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
NSBeep();
|
||||
}
|
||||
|
||||
|
@ -205,7 +291,7 @@ static BOOL _gnu_contextHelpActive = NO;
|
|||
|
||||
- (BOOL) showContextHelpForObject: (id)object locationHint: (NSPoint) point
|
||||
{
|
||||
id contextHelp = [self contextHelpForObject: object];
|
||||
NSAttributedString *contextHelp = [self contextHelpForObject: object];
|
||||
|
||||
if (contextHelp)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue