mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-25 07:31:07 +00:00
Improve help support ... fallback to a panel to display text if no external
application is available. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/themes@23698 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
03a95d3ca9
commit
52d252d932
4 changed files with 184 additions and 49 deletions
|
@ -4,6 +4,9 @@
|
|||
Make themes in panel be in alphabetical order except for the
|
||||
default theme (always first in the list).
|
||||
Allow setting of default theme for application.
|
||||
* Source/NSHelpManager.m:
|
||||
* Source/NSHelpPanel.m: Implement simple fallback help panel display
|
||||
for systems where no rtf/rtfd viewing application is installed.
|
||||
|
||||
2006-09-30 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
|
|
|
@ -48,43 +48,43 @@
|
|||
//
|
||||
// Accessing the Help Panel
|
||||
//
|
||||
+ (NSHelpPanel *)sharedHelpPanel;
|
||||
+ (NSHelpPanel *)sharedHelpPanelWithDirectory:(NSString *)helpDirectory;
|
||||
+ (NSHelpPanel *) sharedHelpPanel;
|
||||
+ (NSHelpPanel *) sharedHelpPanelWithDirectory: (NSString *)helpDirectory;
|
||||
|
||||
//
|
||||
// Managing the Contents
|
||||
//
|
||||
+ (void)setHelpDirectory:(NSString *)helpDirectory;
|
||||
- (void)addSupplement:(NSString *)helpDirectory
|
||||
inPath:(NSString *)supplementPath;
|
||||
- (NSString *)helpDirectory;
|
||||
- (NSString *)helpFile;
|
||||
+ (void) setHelpDirectory: (NSString *)helpDirectory;
|
||||
- (void) addSupplement: (NSString *)helpDirectory
|
||||
inPath: (NSString *)supplementPath;
|
||||
- (NSString *) helpDirectory;
|
||||
- (NSString *) helpFile;
|
||||
|
||||
//
|
||||
// Attaching Help to Objects
|
||||
//
|
||||
+ (void)attachHelpFile:(NSString *)filename
|
||||
markerName:(NSString *)markerName
|
||||
to:(id)anObject;
|
||||
+ (void)detachHelpFrom:(id)anObject;
|
||||
+ (void) attachHelpFile: (NSString *)filename
|
||||
markerName: (NSString *)markerName
|
||||
to: (id)anObject;
|
||||
+ (void) detachHelpFrom: (id)anObject;
|
||||
|
||||
//
|
||||
// Showing Help
|
||||
//
|
||||
- (void)showFile:(NSString *)filename
|
||||
atMarker:(NSString *)markerName;
|
||||
- (BOOL)showHelpAttachedTo:(id)anObject;
|
||||
- (void) showFile: (NSString *)filename
|
||||
atMarker: (NSString *)markerName;
|
||||
- (BOOL) showHelpAttachedTo: (id)anObject;
|
||||
|
||||
//
|
||||
// Printing
|
||||
//
|
||||
- (void)print:(id)sender;
|
||||
- (void) print: (id)sender;
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
//
|
||||
- (void)encodeWithCoder: (NSCoder *)aCoder;
|
||||
- initWithCoder: (NSCoder *)aDecoder;
|
||||
- (void) encodeWithCoder: (NSCoder *)aCoder;
|
||||
- (id) initWithCoder: (NSCoder *)aDecoder;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
*/
|
||||
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSNotification.h>
|
||||
#include <Foundation/NSFileManager.h>
|
||||
#include <Foundation/NSString.h>
|
||||
|
@ -36,6 +37,7 @@
|
|||
#include "AppKit/NSApplication.h"
|
||||
#include "AppKit/NSWorkspace.h"
|
||||
#include "AppKit/NSHelpManager.h"
|
||||
#include "AppKit/NSHelpPanel.h"
|
||||
#include "AppKit/NSGraphics.h"
|
||||
|
||||
#include "GNUstepGUI/GSHelpManagerPanel.h"
|
||||
|
@ -195,6 +197,51 @@
|
|||
{
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
NSHelpPanel *panel = [NSHelpPanel sharedHelpPanel];
|
||||
NSString *ext = [file pathExtension];
|
||||
NSTextView *tv;
|
||||
id object;
|
||||
|
||||
tv = [(NSScrollView*)[panel contentView] documentView];
|
||||
|
||||
if (ext == nil
|
||||
|| [ext isEqualToString: @""]
|
||||
|| [ext isEqualToString: @"txt"]
|
||||
|| [ext isEqualToString: @"text"])
|
||||
{
|
||||
object = [NSString stringWithContentsOfFile: file];
|
||||
}
|
||||
else if ([ext isEqualToString: @"rtf"])
|
||||
{
|
||||
NSData *data = [NSData dataWithContentsOfFile: file];
|
||||
|
||||
object = [[NSAttributedString alloc] initWithRTF: data
|
||||
documentAttributes: 0];
|
||||
AUTORELEASE (object);
|
||||
}
|
||||
else if ([ext isEqualToString: @"rtfd"])
|
||||
{
|
||||
NSFileWrapper *wrapper;
|
||||
|
||||
wrapper = [[NSFileWrapper alloc] initWithPath: file];
|
||||
AUTORELEASE (wrapper);
|
||||
object = [[NSAttributedString alloc]
|
||||
initWithRTFDFileWrapper: wrapper
|
||||
documentAttributes: 0];
|
||||
AUTORELEASE (object);
|
||||
}
|
||||
|
||||
if (object != nil)
|
||||
{
|
||||
[[tv textStorage] setAttributedString: object];
|
||||
[tv sizeToFit];
|
||||
}
|
||||
[tv setNeedsDisplay: YES];
|
||||
[panel makeKeyAndOrderFront: self];
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,9 @@
|
|||
#include "config.h"
|
||||
#include "AppKit/NSHelpPanel.h"
|
||||
#include "AppKit/NSHelpManager.h"
|
||||
#include "AppKit/NSScrollView.h"
|
||||
#include "AppKit/NSTextView.h"
|
||||
#include "AppKit/NSTextContainer.h"
|
||||
|
||||
|
||||
@implementation NSApplication (NSHelpPanel)
|
||||
|
@ -40,49 +43,68 @@
|
|||
|
||||
@implementation NSHelpPanel
|
||||
|
||||
static NSString *_helpDirectory = nil;
|
||||
static NSString *_helpFile = nil;
|
||||
static NSHelpPanel *_sharedPanel = nil;
|
||||
|
||||
//
|
||||
// Class methods
|
||||
//
|
||||
+ (void)initialize
|
||||
+ (void) initialize
|
||||
{
|
||||
if (self == [NSHelpPanel class])
|
||||
{
|
||||
// Initial version
|
||||
[self setVersion:1];
|
||||
[self setVersion: 1];
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Accessing the Help Panel
|
||||
//
|
||||
+ (NSHelpPanel *)sharedHelpPanel
|
||||
+ (NSHelpPanel*) sharedHelpPanel
|
||||
{
|
||||
NSRunAlertPanel (NULL, @"Help Panel not implemented yet",
|
||||
@"OK", NULL, NULL);
|
||||
return nil;
|
||||
if (_sharedPanel == nil)
|
||||
{
|
||||
return [self new];
|
||||
}
|
||||
return _sharedPanel;
|
||||
}
|
||||
|
||||
+ (NSHelpPanel *)sharedHelpPanelWithDirectory:(NSString *)helpDirectory
|
||||
+ (NSHelpPanel *) sharedHelpPanelWithDirectory: (NSString *)helpDirectory
|
||||
{
|
||||
return nil;
|
||||
[self setHelpDirectory: helpDirectory];
|
||||
return [self sharedHelpPanel];
|
||||
}
|
||||
|
||||
//
|
||||
// Managing the Contents
|
||||
//
|
||||
+ (void)setHelpDirectory:(NSString *)helpDirectory
|
||||
{}
|
||||
+ (void) setHelpDirectory: (NSString *)helpDirectory
|
||||
{
|
||||
ASSIGN(_helpDirectory, helpDirectory);
|
||||
}
|
||||
|
||||
//
|
||||
// Attaching Help to Objects
|
||||
//
|
||||
+ (void)attachHelpFile:(NSString *)filename
|
||||
markerName:(NSString *)markerName
|
||||
to:(id)anObject
|
||||
{}
|
||||
+ (void) attachHelpFile: (NSString *)filename
|
||||
markerName: (NSString *)markerName
|
||||
to: (id)anObject
|
||||
{
|
||||
if ([filename isAbsolutePath] == NO)
|
||||
{
|
||||
filename = [[[NSHelpPanel sharedHelpPanel] helpDirectory]
|
||||
stringByAppendingPathComponent: filename];
|
||||
}
|
||||
[[NSHelpManager sharedHelpManager] setContextHelp: (id)filename
|
||||
forObject: anObject];
|
||||
}
|
||||
|
||||
+ (void)detachHelpFrom:(id)anObject
|
||||
{}
|
||||
+ (void) detachHelpFrom: (id)anObject
|
||||
{
|
||||
[[NSHelpManager sharedHelpManager] removeContextHelpForObject: anObject];
|
||||
}
|
||||
|
||||
//
|
||||
// Instance methods
|
||||
|
@ -90,37 +112,100 @@ to:(id)anObject
|
|||
//
|
||||
// Managing the Contents
|
||||
//
|
||||
- (void)addSupplement:(NSString *)helpDirectory
|
||||
inPath:(NSString *)supplementPath
|
||||
{}
|
||||
|
||||
- (NSString *)helpDirectory
|
||||
- (void) addSupplement: (NSString *)helpDirectory
|
||||
inPath: (NSString *)supplementPath
|
||||
{
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (NSString *)helpFile
|
||||
- (NSString *) helpDirectory
|
||||
{
|
||||
return nil;
|
||||
return _helpDirectory;
|
||||
}
|
||||
|
||||
- (NSString *) helpFile
|
||||
{
|
||||
return _helpFile;
|
||||
}
|
||||
|
||||
- (id) initWithContentRect: (NSRect)contentRect
|
||||
styleMask: (unsigned int)aStyle
|
||||
backing: (NSBackingStoreType)bufferingType
|
||||
defer: (BOOL)flag
|
||||
screen: (NSScreen*)aScreen
|
||||
{
|
||||
if (_sharedPanel == nil)
|
||||
{
|
||||
NSScrollView *s;
|
||||
NSTextView *v;
|
||||
NSRect r;
|
||||
|
||||
self = [super initWithContentRect: NSMakeRect(100,100,400,500)
|
||||
styleMask: NSTitledWindowMask|NSClosableWindowMask|NSResizableWindowMask
|
||||
backing: NSBackingStoreBuffered
|
||||
defer: NO
|
||||
screen: nil];
|
||||
[self setReleasedWhenClosed: NO];
|
||||
[self setTitle: @"Help"];
|
||||
s = [[NSScrollView alloc] initWithFrame: contentRect];
|
||||
[s setHasHorizontalScroller: YES];
|
||||
[s setHasVerticalScroller: YES];
|
||||
[s setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
|
||||
[self setContentView: s];
|
||||
RELEASE(s);
|
||||
|
||||
r = [[s documentView] frame];
|
||||
v = [[NSTextView alloc] initWithFrame: r];
|
||||
[v setHorizontallyResizable: YES];
|
||||
[v setVerticallyResizable: YES];
|
||||
[v setEditable: NO];
|
||||
[v setRichText: YES];
|
||||
[v setMinSize: NSMakeSize (0, 0)];
|
||||
[v setMaxSize: NSMakeSize (1E7, 1E7)];
|
||||
[v setAutoresizingMask: NSViewHeightSizable | NSViewWidthSizable];
|
||||
[[v textContainer] setContainerSize:
|
||||
NSMakeSize (r.size.width, 1e7)];
|
||||
[[v textContainer] setWidthTracksTextView: YES];
|
||||
|
||||
[s setDocumentView: v];
|
||||
RELEASE(v);
|
||||
|
||||
_sharedPanel = self;
|
||||
}
|
||||
else
|
||||
{
|
||||
RELEASE(self);
|
||||
}
|
||||
return _sharedPanel;
|
||||
}
|
||||
|
||||
//
|
||||
// Showing Help
|
||||
//
|
||||
- (void)showFile:(NSString *)filename
|
||||
atMarker:(NSString *)markerName
|
||||
{}
|
||||
|
||||
- (BOOL)showHelpAttachedTo:(id)anObject
|
||||
- (void) showFile: (NSString *)filename
|
||||
atMarker: (NSString *)markerName
|
||||
{
|
||||
return NO;
|
||||
if ([filename isAbsolutePath] == NO)
|
||||
{
|
||||
filename = [[[NSHelpPanel sharedHelpPanel] helpDirectory]
|
||||
stringByAppendingPathComponent: filename];
|
||||
}
|
||||
[[NSHelpManager sharedHelpManager] setContextHelp: (id)filename
|
||||
forObject: self];
|
||||
[self showHelpAttachedTo: self];
|
||||
}
|
||||
|
||||
- (BOOL) showHelpAttachedTo: (id)anObject
|
||||
{
|
||||
return [[NSHelpManager sharedHelpManager]
|
||||
showContextHelpForObject: anObject locationHint: NSZeroPoint];
|
||||
}
|
||||
|
||||
//
|
||||
// Printing
|
||||
//
|
||||
- (void)print:(id)sender
|
||||
{}
|
||||
- (void) print: (id)sender
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// NSCoding protocol
|
||||
|
|
Loading…
Reference in a new issue