mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 07:00:46 +00:00
File opening tidyups
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@16405 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
7fec3a5ad6
commit
a4ace9f14b
4 changed files with 101 additions and 84 deletions
|
@ -1,3 +1,12 @@
|
|||
2003-04-09 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Headers/gnustep/gui/GSServicesManager.h: Expost file open methods.
|
||||
* Source/GSServicesManager.m: Tidy file opening methods.
|
||||
* Source/NSApplication.m: Use methods from GSServicesManager
|
||||
Activate NSApp when opening a file. Use NSDocumentController if the
|
||||
app delegate won't open a file. Remove temporary files once they
|
||||
are opened.
|
||||
|
||||
2003-04-09 Serg Stoyan <stoyan@hologr.com>
|
||||
|
||||
* Source/NSMenuView.m: return back horizontal menu code.
|
||||
|
|
|
@ -57,6 +57,14 @@
|
|||
}
|
||||
+ (GSServicesManager*) newWithApplication: (NSApplication*)app;
|
||||
+ (GSServicesManager*) manager;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFile: (NSString*)file;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFileWithoutUI: (NSString*)file;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openTempFile: (NSString*)file;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
printFile: (NSString*)file;
|
||||
- (void) doService: (NSMenuItem*)item;
|
||||
- (BOOL) hasRegisteredTypes: (NSDictionary*)service;
|
||||
- (NSString*) item2title: (NSMenuItem*)item;
|
||||
|
|
|
@ -54,9 +54,14 @@
|
|||
#include <AppKit/NSPanel.h>
|
||||
#include <AppKit/NSWindow.h>
|
||||
#include <AppKit/NSWorkspace.h>
|
||||
#include <AppKit/NSDocumentController.h>
|
||||
|
||||
#include <AppKit/GSServicesManager.h>
|
||||
|
||||
@interface NSDocumentController (ApplicationPrivate)
|
||||
+ (BOOL) isDocumentBasedApplication;
|
||||
@end
|
||||
|
||||
/*
|
||||
* The GSListener class is for talking to other applications.
|
||||
* It is a proxy with some dangerous methods implemented in a
|
||||
|
@ -74,14 +79,6 @@
|
|||
- (void) release;
|
||||
- (id) retain;
|
||||
- (id) self;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFile: (NSString*)file;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFileWithoutUI: (NSString*)file;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openTempFile: (NSString*)file;
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
printFile: (NSString*)file;
|
||||
- (void) performService: (NSString*)name
|
||||
withPasteboard: (NSPasteboard*)pb
|
||||
userData: (NSString*)ud
|
||||
|
@ -224,7 +221,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
|
|||
return [servicesProvider performv: aSel :frame];
|
||||
|
||||
/*
|
||||
* If tha applications delegate can handle the message - forward to it.
|
||||
* If the applications delegate can handle the message - forward to it.
|
||||
*/
|
||||
delegate = [[NSApplication sharedApplication] delegate];
|
||||
if ([delegate respondsToSelector: aSel] == YES)
|
||||
|
@ -252,7 +249,7 @@ NSRegisterServicesProvider(id provider, NSString *name)
|
|||
}
|
||||
|
||||
/*
|
||||
* If tha applications delegate can handle the message - forward to it.
|
||||
* If the applications delegate can handle the message - forward to it.
|
||||
*/
|
||||
delegate = [[NSApplication sharedApplication] delegate];
|
||||
if ([delegate respondsToSelector: aSel] == YES)
|
||||
|
@ -265,47 +262,6 @@ NSRegisterServicesProvider(id provider, NSString *name)
|
|||
format: @"method %@ not implemented", selName];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFile: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
return [del application: theApp openFile: file];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFileWithoutUI: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
return [del application: theApp openFileWithoutUI: file];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openTempFile: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
return [del application: theApp openTempFile: file];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
printFile: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
return [del application: theApp openFile: file];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) performService: (NSString*)name
|
||||
withPasteboard: (NSPasteboard*)pb
|
||||
userData: (NSString*)ud
|
||||
|
@ -428,6 +384,70 @@ static NSString *disabledName = @".GNUstepDisabled";
|
|||
return manager;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFile: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
BOOL result = NO;
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
{
|
||||
[NSApp activateIgnoringOtherApps: YES];
|
||||
result = [del application: theApp openFile: file];
|
||||
}
|
||||
else if ([NSDocumentController isDocumentBasedApplication] == YES)
|
||||
{
|
||||
[NSApp activateIgnoringOtherApps: YES];
|
||||
if ([[NSDocumentController sharedDocumentController]
|
||||
openDocumentWithContentsOfFile: file display: YES] != nil)
|
||||
{
|
||||
result = YES;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openFileWithoutUI: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
BOOL result = NO;
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
{
|
||||
result = [del application: theApp openFileWithoutUI: file];
|
||||
}
|
||||
else if ([NSDocumentController isDocumentBasedApplication] == YES)
|
||||
{
|
||||
if ([[NSDocumentController sharedDocumentController]
|
||||
openDocumentWithContentsOfFile: file display: NO] != nil)
|
||||
{
|
||||
result = YES;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
openTempFile: (NSString*)file
|
||||
{
|
||||
BOOL result = [self application: theApp openFile: file];
|
||||
|
||||
[[NSFileManager defaultManager] removeFileAtPath: file handler: nil];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
- (BOOL) application: (NSApplication*)theApp
|
||||
printFile: (NSString*)file
|
||||
{
|
||||
id del = [NSApp delegate];
|
||||
|
||||
if ([del respondsToSelector: _cmd])
|
||||
return [del application: theApp printFile: file];
|
||||
return NO;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
NSString *appName;
|
||||
|
@ -1151,7 +1171,7 @@ static NSString *disabledName = @".GNUstepDisabled";
|
|||
if (title == nil && [[item submenu] isKindOfClass: [NSMenu class]])
|
||||
{
|
||||
NSArray *sub = [[item submenu] itemArray];
|
||||
int j;
|
||||
unsigned j;
|
||||
|
||||
shouldBeEnabled = NO;
|
||||
for (j = 0; j < [sub count]; j++)
|
||||
|
|
|
@ -218,8 +218,7 @@ initialize_gnustep_backend(void)
|
|||
* from the bundle. */
|
||||
backend = NSClassFromString (@"GSBackend");
|
||||
NSCAssert1 (backend != Nil,
|
||||
_(@"Backend at path %@ doesn't contain the GSBackend class"),
|
||||
path);
|
||||
_(@"Backend at path %@ doesn't contain the GSBackend class"), path);
|
||||
[backend initializeBackend];
|
||||
}
|
||||
#else
|
||||
|
@ -802,35 +801,24 @@ static NSCell* tileCell = nil;
|
|||
* Now check to see if we were launched with arguments asking to
|
||||
* open a file. We permit some variations on the default name.
|
||||
*/
|
||||
if ((filePath = [defs stringForKey: @"GSFilePath"]) != nil ||
|
||||
(filePath = [defs stringForKey: @"NSOpen"]) != nil)
|
||||
if ((filePath = [defs stringForKey: @"GSFilePath"]) != nil
|
||||
|| (filePath = [defs stringForKey: @"NSOpen"]) != nil)
|
||||
{
|
||||
[self _openDocument: filePath];
|
||||
[_listener application: self openFile: filePath];
|
||||
}
|
||||
else if ((filePath = [defs stringForKey: @"GSTempPath"]) != nil)
|
||||
{
|
||||
if ([_delegate respondsToSelector: @selector(application:openTempFile:)])
|
||||
{
|
||||
[_delegate application: self openTempFile: filePath];
|
||||
}
|
||||
else
|
||||
{
|
||||
// FIXME: Should remember that this is a temp file
|
||||
[[NSDocumentController sharedDocumentController]
|
||||
openDocumentWithContentsOfFile: filePath display: YES];
|
||||
}
|
||||
[_listener application: self openTempFile: filePath];
|
||||
}
|
||||
else if ((filePath = [defs stringForKey: @"NSPrint"]) != nil)
|
||||
{
|
||||
if ([_delegate respondsToSelector: @selector(application:printFile:)])
|
||||
{
|
||||
[_delegate application: self printFile: filePath];
|
||||
}
|
||||
[_listener application: self printFile: filePath];
|
||||
[self terminate: self];
|
||||
}
|
||||
else if ([_delegate respondsToSelector: @selector(applicationShouldOpenUntitledFile:)] &&
|
||||
([_delegate applicationShouldOpenUntitledFile: self] == YES) &&
|
||||
[_delegate respondsToSelector: @selector(applicationOpenUntitledFile:)])
|
||||
else if ([_delegate respondsToSelector:
|
||||
@selector(applicationShouldOpenUntitledFile:)]
|
||||
&& ([_delegate applicationShouldOpenUntitledFile: self] == YES)
|
||||
&& [_delegate respondsToSelector: @selector(applicationOpenUntitledFile:)])
|
||||
{
|
||||
[_delegate applicationOpenUntitledFile: self];
|
||||
}
|
||||
|
@ -1660,7 +1648,7 @@ delegate.
|
|||
return _delegate;
|
||||
}
|
||||
if ([NSDocumentController isDocumentBasedApplication]
|
||||
&& [[NSDocumentController sharedDocumentController]
|
||||
&& [[NSDocumentController sharedDocumentController]
|
||||
respondsToSelector: aSelector])
|
||||
{
|
||||
return [NSDocumentController sharedDocumentController];
|
||||
|
@ -2535,15 +2523,7 @@ image.
|
|||
|
||||
- (void) _openDocument: (NSString*)filePath
|
||||
{
|
||||
if ([_delegate respondsToSelector: @selector(application:openFile:)])
|
||||
{
|
||||
[_delegate application: self openFile: filePath];
|
||||
}
|
||||
else
|
||||
{
|
||||
[[NSDocumentController sharedDocumentController]
|
||||
openDocumentWithContentsOfFile: filePath display: YES];
|
||||
}
|
||||
[_listener application: self openFile: filePath];
|
||||
}
|
||||
|
||||
- (void) _windowDidBecomeKey: (NSNotification*) notification
|
||||
|
|
Loading…
Reference in a new issue