mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 19:21:56 +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
ad09d1f672
commit
9b48dd63dc
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>
|
2006-07-14 01:17 Gregory John Casamento <greg_casamento@yahoo.com>
|
||||||
|
|
||||||
* Headers/Additions/GNUstepGUI/GSNibCompatibility.h:
|
* Headers/Additions/GNUstepGUI/GSNibCompatibility.h:
|
||||||
|
|
|
@ -81,6 +81,7 @@
|
||||||
#include <AppKit/NSForm.h>
|
#include <AppKit/NSForm.h>
|
||||||
#include <AppKit/NSFormCell.h>
|
#include <AppKit/NSFormCell.h>
|
||||||
#include <AppKit/NSGraphicsContext.h>
|
#include <AppKit/NSGraphicsContext.h>
|
||||||
|
#include <AppKit/NSHelpManager.h>
|
||||||
#include <AppKit/NSHelpPanel.h>
|
#include <AppKit/NSHelpPanel.h>
|
||||||
#include <AppKit/NSImage.h>
|
#include <AppKit/NSImage.h>
|
||||||
#include <AppKit/NSImageCell.h>
|
#include <AppKit/NSImageCell.h>
|
||||||
|
|
|
@ -37,7 +37,8 @@
|
||||||
@class NSAttributedString;
|
@class NSAttributedString;
|
||||||
|
|
||||||
@interface NSBundle (NSHelpManager)
|
@interface NSBundle (NSHelpManager)
|
||||||
- (NSAttributedString*) contextHelpForKey: (NSString*) key;
|
- (NSString *)pathForHelpResource:(NSString *)fileName;
|
||||||
|
- (NSAttributedString *)contextHelpForKey:(NSString *)key;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSApplication (NSHelpManager)
|
@interface NSApplication (NSHelpManager)
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "AppKit/NSApplication.h"
|
#include "AppKit/NSApplication.h"
|
||||||
#include "AppKit/NSAttributedString.h"
|
#include "AppKit/NSAttributedString.h"
|
||||||
#include "AppKit/NSTextView.h"
|
#include "AppKit/NSTextView.h"
|
||||||
|
#include "AppKit/NSTextContainer.h"
|
||||||
#include "AppKit/NSScrollView.h"
|
#include "AppKit/NSScrollView.h"
|
||||||
#include "AppKit/NSClipView.h"
|
#include "AppKit/NSClipView.h"
|
||||||
#include "AppKit/NSColor.h"
|
#include "AppKit/NSColor.h"
|
||||||
|
@ -46,68 +47,69 @@ static GSHelpManagerPanel* _GSsharedGSHelpPanel;
|
||||||
return _GSsharedGSHelpPanel;
|
return _GSsharedGSHelpPanel;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This window should not be destroyed... So we don't allow it to! */
|
- (id)init
|
||||||
- (id) retain
|
|
||||||
{
|
{
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) release
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) autorelease
|
|
||||||
{
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) init
|
|
||||||
{
|
|
||||||
NSScrollView *scrollView;
|
|
||||||
NSRect scrollViewRect = {{0, 0}, {470, 150}};
|
|
||||||
NSRect winRect = {{100, 100}, {470, 150}};
|
NSRect winRect = {{100, 100}, {470, 150}};
|
||||||
unsigned int style = NSTitledWindowMask | NSClosableWindowMask
|
unsigned int style = NSTitledWindowMask | NSClosableWindowMask
|
||||||
| NSMiniaturizableWindowMask | NSResizableWindowMask;
|
| NSMiniaturizableWindowMask | NSResizableWindowMask;
|
||||||
|
|
||||||
|
self = [super initWithContentRect: winRect
|
||||||
|
styleMask: style
|
||||||
|
backing: NSBackingStoreRetained
|
||||||
|
defer: NO];
|
||||||
|
|
||||||
[self initWithContentRect: winRect
|
if (self) {
|
||||||
styleMask: style
|
NSRect scrollViewRect = {{0, 0}, {470, 150}};
|
||||||
backing: NSBackingStoreRetained
|
NSRect r;
|
||||||
defer: NO];
|
NSScrollView *scrollView;
|
||||||
[self setFloatingPanel: YES];
|
|
||||||
[self setRepresentedFilename: @"Help"];
|
|
||||||
[self setTitle: @"Help"];
|
|
||||||
[self setDocumentEdited: NO];
|
|
||||||
|
|
||||||
scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect];
|
[self setReleasedWhenClosed: NO];
|
||||||
[scrollView setHasHorizontalScroller: NO];
|
[self setFloatingPanel: YES];
|
||||||
[scrollView setHasVerticalScroller: YES];
|
// [self setTitle: NSLocalizedString(@"Help", @"")];
|
||||||
[scrollView setAutoresizingMask: NSViewHeightSizable];
|
[self setTitle: @"Help"];
|
||||||
|
|
||||||
textView = [[NSTextView alloc] initWithFrame:
|
scrollView = [[NSScrollView alloc] initWithFrame: scrollViewRect];
|
||||||
[[scrollView contentView] frame]];
|
[scrollView setHasHorizontalScroller: NO];
|
||||||
[textView setEditable: NO];
|
[scrollView setHasVerticalScroller: YES];
|
||||||
[textView setRichText: YES];
|
[scrollView setAutoresizingMask: NSViewHeightSizable];
|
||||||
[textView setSelectable: YES];
|
|
||||||
// off white
|
r = [[scrollView contentView] frame];
|
||||||
[textView setBackgroundColor: [NSColor colorWithCalibratedWhite: 0.85
|
textView = [[NSTextView alloc] initWithFrame: r];
|
||||||
alpha: 1.0]];
|
[textView setRichText: YES];
|
||||||
[scrollView setDocumentView: textView];
|
[textView setEditable: NO];
|
||||||
[[self contentView] addSubview: scrollView];
|
[textView setSelectable: NO];
|
||||||
RELEASE(scrollView);
|
[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;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) setHelpText: (NSAttributedString*) helpText
|
- (void)setHelpText:(NSAttributedString *)helpText
|
||||||
{
|
{
|
||||||
// FIXME: The attributed text should be set, but there is
|
[[textView textStorage] setAttributedString: helpText];
|
||||||
// no public method for this.
|
|
||||||
[textView setText: [helpText string]];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void) close
|
- (void) close
|
||||||
{
|
{
|
||||||
[NSApp stopModal];
|
if ([self isVisible])
|
||||||
|
{
|
||||||
|
[NSApp stopModal];
|
||||||
|
}
|
||||||
[super close];
|
[super close];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <Foundation/NSUserDefaults.h>
|
||||||
#include <Foundation/NSNotification.h>
|
#include <Foundation/NSNotification.h>
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
|
@ -41,33 +42,107 @@
|
||||||
|
|
||||||
@implementation NSBundle (NSHelpManager)
|
@implementation NSBundle (NSHelpManager)
|
||||||
|
|
||||||
- (NSAttributedString*) contextHelpForKey: (NSString*) key
|
- (NSString *)pathForHelpResource:(NSString *)fileName
|
||||||
{
|
{
|
||||||
id helpFile = nil;
|
NSFileManager *fm = [NSFileManager defaultManager];
|
||||||
NSDictionary *contextHelp =
|
NSMutableArray *array = [NSMutableArray array];
|
||||||
RETAIN([NSDictionary dictionaryWithContentsOfFile:
|
NSArray *languages = [NSUserDefaults userLanguages];
|
||||||
[self pathForResource: @"Help" ofType: @"plist"]]);
|
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)
|
if (contextHelp)
|
||||||
{
|
{
|
||||||
helpFile = [contextHelp objectForKey: key];
|
helpFile = [contextHelp objectForKey: key];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (helpFile)
|
if (helpFile)
|
||||||
{
|
{
|
||||||
return [NSUnarchiver unarchiveObjectWithData:
|
NSData *data = [helpFile objectForKey: @"NSHelpRTFContents"];
|
||||||
[helpFile objectForKey: @"NSHelpRTFContents"]];
|
return ((data != nil) ? [NSUnarchiver unarchiveObjectWithData: data] :
|
||||||
}
|
nil) ;
|
||||||
else
|
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
helpFile = [self
|
helpFile = [self pathForHelpResource: key];
|
||||||
pathForResource: key
|
|
||||||
ofType: @"rtf"
|
|
||||||
inDirectory: @"Help"];
|
|
||||||
return AUTORELEASE([[NSAttributedString alloc] initWithPath: (NSString *)helpFile
|
|
||||||
documentAttributes: NULL]);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (helpFile)
|
||||||
|
{
|
||||||
|
NSString *helpstr = [[NSAttributedString alloc] initWithPath: helpFile
|
||||||
|
documentAttributes: NULL];
|
||||||
|
return TEST_AUTORELEASE (helpstr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,22 +158,33 @@
|
||||||
|
|
||||||
help = [info objectForKey: @"GSHelpContentsFile"];
|
help = [info objectForKey: @"GSHelpContentsFile"];
|
||||||
|
|
||||||
if (!help)
|
if (help == nil)
|
||||||
{
|
{
|
||||||
help = [info objectForKey: @"NSExecutable"];
|
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)
|
if (help)
|
||||||
{
|
{
|
||||||
NSString *file = [mb pathForResource: help ofType: @"rtf"];
|
NSString *file;
|
||||||
|
|
||||||
if (file)
|
if ([[help pathExtension] length] == 0)
|
||||||
{
|
{
|
||||||
[[NSWorkspace sharedWorkspace] openFile: file];
|
file = [mb pathForHelpResource: [help stringByAppendingPathExtension: @"rtfd"]];
|
||||||
return;
|
|
||||||
}
|
if (file == nil)
|
||||||
|
{
|
||||||
|
file = [mb pathForHelpResource: [help stringByAppendingPathExtension: @"rtf"]];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
[[NSWorkspace sharedWorkspace] openFile: file];
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NSBeep();
|
NSBeep();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +291,7 @@ static BOOL _gnu_contextHelpActive = NO;
|
||||||
|
|
||||||
- (BOOL) showContextHelpForObject: (id)object locationHint: (NSPoint) point
|
- (BOOL) showContextHelpForObject: (id)object locationHint: (NSPoint) point
|
||||||
{
|
{
|
||||||
id contextHelp = [self contextHelpForObject: object];
|
NSAttributedString *contextHelp = [self contextHelpForObject: object];
|
||||||
|
|
||||||
if (contextHelp)
|
if (contextHelp)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue