mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-30 02:30:37 +00:00
Major revision of services - all menu services stuff in place now.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@3363 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
558b6da8c2
commit
141a4d603a
11 changed files with 1434 additions and 861 deletions
|
@ -32,12 +32,13 @@ GNUSTEP_MAKEFILES = $(GNUSTEP_SYSTEM_ROOT)/Makefiles
|
|||
include $(GNUSTEP_MAKEFILES)/common.make
|
||||
|
||||
# The applications to be compiled
|
||||
TOOL_NAME = gpbs make_services
|
||||
TOOL_NAME = gpbs make_services set_show_service
|
||||
SERVICE_NAME = example
|
||||
|
||||
# The source files to be compiled
|
||||
gpbs_OBJC_FILES = gpbs.m dummy.m
|
||||
make_services_OBJC_FILES = make_services.m dummy.m
|
||||
set_show_service_OBJC_FILES = set_show_service.m dummy.m
|
||||
|
||||
example_OBJC_FILES = example.m dummy.m
|
||||
|
||||
|
|
|
@ -54,6 +54,22 @@ NSBeep(void)
|
|||
{
|
||||
}
|
||||
|
||||
void GSfill() {}
|
||||
void GSsetgray() {}
|
||||
void GSnewpath() {}
|
||||
void GSgrestore() {}
|
||||
void GSrectfill() {}
|
||||
void GSsetlinewidth() {}
|
||||
void GSclosepath() {}
|
||||
void GSshow() {}
|
||||
void GStranslate() {}
|
||||
void GSmoveto() {}
|
||||
void GSgsave() {}
|
||||
void GSlineto() {}
|
||||
void GSstroke() {}
|
||||
void GSrlineto() {}
|
||||
void GSrectclip() {}
|
||||
|
||||
void NSFrameRect(NSRect aRect)
|
||||
{
|
||||
}
|
||||
|
@ -79,3 +95,15 @@ void NSDrawGroove(NSRect aRect, NSRect clipRect)
|
|||
@implementation GMUnarchiver
|
||||
@end
|
||||
|
||||
@interface NSWindowView : NSObject
|
||||
@end
|
||||
|
||||
@implementation NSWindowView
|
||||
@end
|
||||
|
||||
@interface GPSDrawContext : NSObject
|
||||
@end
|
||||
|
||||
@implementation GPSDrawContext
|
||||
@end
|
||||
|
||||
|
|
|
@ -31,13 +31,16 @@
|
|||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSDistributedLock.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSSerialization.h>
|
||||
|
||||
static void scanDirectory(NSMutableDictionary *services, NSString *path);
|
||||
static void scanDynamic(NSMutableDictionary *services, NSString *path);
|
||||
static NSMutableArray *validateEntry(id svcs, NSString* path);
|
||||
static NSMutableDictionary *validateService(NSDictionary *service, NSString* path, unsigned i);
|
||||
|
||||
static NSString *appsName = @".GNUstepAppList";
|
||||
static NSString *cacheName = @".GNUstepServices";
|
||||
static NSString *infoLoc = @"Resources/Info-gnustep.plist";
|
||||
|
||||
|
@ -65,6 +68,7 @@ main(int argc, char** argv)
|
|||
unsigned index;
|
||||
BOOL isDir;
|
||||
NSMutableDictionary *fullMap;
|
||||
NSDictionary *oldMap;
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
|
@ -132,18 +136,43 @@ main(int argc, char** argv)
|
|||
}
|
||||
|
||||
roots = [NSMutableArray arrayWithCapacity: 3];
|
||||
services = [NSMutableDictionary dictionaryWithCapacity: 200];
|
||||
|
||||
/*
|
||||
* Build a list of 'root' directories to search for applications.
|
||||
* Order is important - later duplicates of services are ignored.
|
||||
*
|
||||
* Make sure that the users 'GNUstep/Services' directory exists.
|
||||
*/
|
||||
str = [env objectForKey: @"GNUSTEP_USER_ROOT"];
|
||||
if (str != nil)
|
||||
usrRoot = str;
|
||||
else
|
||||
usrRoot = [NSString stringWithFormat: @"%@/GNUstep", NSHomeDirectory()];
|
||||
|
||||
mgr = [NSFileManager defaultManager];
|
||||
if (([mgr fileExistsAtPath: usrRoot isDirectory: &isDir] && isDir) == 0)
|
||||
{
|
||||
if ([mgr createDirectoryAtPath: usrRoot attributes: nil] == NO)
|
||||
{
|
||||
NSLog(@"couldn't create %@\n", usrRoot);
|
||||
[pool release];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
[roots addObject: usrRoot];
|
||||
|
||||
usrRoot = [usrRoot stringByAppendingPathComponent: @"Services"];
|
||||
if (([mgr fileExistsAtPath: usrRoot isDirectory: &isDir] && isDir) == 0)
|
||||
{
|
||||
if ([mgr createDirectoryAtPath: usrRoot attributes: nil] == NO)
|
||||
{
|
||||
NSLog(@"couldn't create %@\n", usrRoot);
|
||||
[pool release];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
str = [env objectForKey: @"GNUSTEP_LOCAL_ROOT"];
|
||||
if (str != nil)
|
||||
[roots addObject: str];
|
||||
|
@ -156,14 +185,19 @@ main(int argc, char** argv)
|
|||
else
|
||||
[roots addObject: @"/usr/GNUstep"];
|
||||
|
||||
/*
|
||||
* Before doing the main scan, we examine the 'Services' directory to
|
||||
* see if any application has registered dynamic services - these take
|
||||
* precedence over any listed in an applications Info_gnustep.plist.
|
||||
*/
|
||||
scanDynamic(services, usrRoot);
|
||||
|
||||
/*
|
||||
* List of directory names to search within each root directory
|
||||
* when looking for applications providing services.
|
||||
*/
|
||||
locations = [NSArray arrayWithObjects: @"Apps", @"Library/Services", nil];
|
||||
|
||||
services = [NSMutableDictionary dictionaryWithCapacity: 200];
|
||||
|
||||
for (index = 0; index < [roots count]; index++)
|
||||
{
|
||||
NSString *root = [roots objectAtIndex: index];
|
||||
|
@ -178,33 +212,57 @@ main(int argc, char** argv)
|
|||
}
|
||||
}
|
||||
|
||||
mgr = [NSFileManager defaultManager];
|
||||
if (([mgr fileExistsAtPath: usrRoot isDirectory: &isDir] && isDir) == 0)
|
||||
{
|
||||
if ([mgr createDirectoryAtPath: usrRoot attributes: nil] == NO)
|
||||
{
|
||||
NSLog(@"couldn't create %@\n", usrRoot);
|
||||
[pool release];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fullMap = [NSMutableDictionary dictionaryWithCapacity: 5];
|
||||
[fullMap setObject: services forKey: @"ByPath"];
|
||||
[fullMap setObject: serviceMap forKey: @"ByService"];
|
||||
[fullMap setObject: filterMap forKey: @"ByFilter"];
|
||||
[fullMap setObject: printMap forKey: @"ByPrint"];
|
||||
[fullMap setObject: spellMap forKey: @"BySpell"];
|
||||
[fullMap setObject: applicationMap forKey: @"Applications"];
|
||||
|
||||
str = [usrRoot stringByAppendingPathComponent: cacheName];
|
||||
data = [NSSerializer serializePropertyList: fullMap];
|
||||
if ([data writeToFile: str atomically: YES] == NO)
|
||||
if ([mgr fileExistsAtPath: str])
|
||||
{
|
||||
NSLog(@"couldn't write %@\n", str);
|
||||
[pool release];
|
||||
exit(1);
|
||||
data = [NSData dataWithContentsOfFile: str];
|
||||
oldMap = [NSDeserializer deserializePropertyListFromData: data
|
||||
mutableContainers: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
oldMap = nil;
|
||||
}
|
||||
if ([fullMap isEqual: oldMap] == NO)
|
||||
{
|
||||
data = [NSSerializer serializePropertyList: fullMap];
|
||||
if ([data writeToFile: str atomically: YES] == NO)
|
||||
{
|
||||
NSLog(@"couldn't write %@\n", str);
|
||||
[pool release];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
str = [usrRoot stringByAppendingPathComponent: appsName];
|
||||
if ([mgr fileExistsAtPath: str])
|
||||
{
|
||||
data = [NSData dataWithContentsOfFile: str];
|
||||
oldMap = [NSDeserializer deserializePropertyListFromData: data
|
||||
mutableContainers: NO];
|
||||
}
|
||||
else
|
||||
{
|
||||
oldMap = nil;
|
||||
}
|
||||
if ([applicationMap isEqual: oldMap] == NO)
|
||||
{
|
||||
data = [NSSerializer serializePropertyList: applicationMap];
|
||||
if ([data writeToFile: str atomically: YES] == NO)
|
||||
{
|
||||
NSLog(@"couldn't write %@\n", str);
|
||||
[pool release];
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
[pool release];
|
||||
exit(0);
|
||||
}
|
||||
|
@ -331,6 +389,54 @@ scanDirectory(NSMutableDictionary *services, NSString *path)
|
|||
[arp release];
|
||||
}
|
||||
|
||||
static void
|
||||
scanDynamic(NSMutableDictionary *services, NSString *path)
|
||||
{
|
||||
NSFileManager *mgr = [NSFileManager defaultManager];
|
||||
NSAutoreleasePool *arp = [NSAutoreleasePool new];
|
||||
NSArray *contents = [mgr directoryContentsAtPath: path];
|
||||
unsigned index;
|
||||
|
||||
for (index = 0; index < [contents count]; index++)
|
||||
{
|
||||
NSString *name = [contents objectAtIndex: index];
|
||||
NSString *infPath;
|
||||
NSDictionary *info;
|
||||
|
||||
/*
|
||||
* Ignore anything with a leading dot.
|
||||
*/
|
||||
if ([name hasPrefix: @"."])
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
infPath = [path stringByAppendingPathComponent: name];
|
||||
|
||||
info = [NSDictionary dictionaryWithContentsOfFile: infPath];
|
||||
if (info)
|
||||
{
|
||||
id svcs = [info objectForKey: @"NSServices"];
|
||||
|
||||
if (svcs)
|
||||
{
|
||||
NSMutableArray *entry;
|
||||
|
||||
entry = validateEntry(svcs, infPath);
|
||||
if (entry)
|
||||
{
|
||||
[services setObject: entry forKey: infPath];
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"bad app info - %@\n", infPath);
|
||||
}
|
||||
}
|
||||
[arp release];
|
||||
}
|
||||
|
||||
static NSMutableArray*
|
||||
validateEntry(id svcs, NSString *path)
|
||||
{
|
||||
|
|
93
Tools/set_show_service.m
Normal file
93
Tools/set_show_service.m
Normal file
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
set_show_servicaes.m
|
||||
|
||||
GNUstep utility to enable or disable a service for the current user.
|
||||
|
||||
Copyright (C) 1998 Free Software Foundation, Inc.
|
||||
|
||||
Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
|
||||
Date: November 1998
|
||||
|
||||
This file is part of the GNUstep GUI Library.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Library General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2 of the License, or (at your option) any later version.
|
||||
|
||||
This library 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 Library General Public
|
||||
License along with this library; see the file COPYING.LIB.
|
||||
If not, write to the Free Software Foundation,
|
||||
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
NSAutoreleasePool *pool;
|
||||
NSProcessInfo *proc;
|
||||
NSArray *args;
|
||||
unsigned index;
|
||||
|
||||
// [NSObject enableDoubleReleaseCheck: YES];
|
||||
|
||||
pool = [NSAutoreleasePool new];
|
||||
|
||||
proc = [NSProcessInfo processInfo];
|
||||
if (proc == nil)
|
||||
{
|
||||
NSLog(@"unable to get process information!\n");
|
||||
[pool release];
|
||||
exit(0);
|
||||
}
|
||||
|
||||
args = [proc arguments];
|
||||
|
||||
for (index = 0; index < [args count]; index++)
|
||||
{
|
||||
if ([[args objectAtIndex: index] isEqual: @"--help"])
|
||||
{
|
||||
printf(
|
||||
"set_show_service enables or disables the display of a specified service\n"
|
||||
"item. It's should be in the form 'set_show_services --enable name' or \n"
|
||||
"'set_show_service --disable name' where 'name' is a service name.\n");
|
||||
exit(0);
|
||||
}
|
||||
if ([[args objectAtIndex: index] isEqual: @"--enable"])
|
||||
{
|
||||
if (index >= [args count] - 1)
|
||||
{
|
||||
NSLog(@"No name specified for enable.\n");
|
||||
exit(1);
|
||||
}
|
||||
NSSetShowsServicesMenuItem([args objectAtIndex: ++index], YES);
|
||||
exit(0);
|
||||
}
|
||||
if ([[args objectAtIndex: index] isEqual: @"--disable"])
|
||||
{
|
||||
if (index >= [args count] - 1)
|
||||
{
|
||||
NSLog(@"No name specified for disable.\n");
|
||||
exit(1);
|
||||
}
|
||||
NSSetShowsServicesMenuItem([args objectAtIndex: ++index], NO);
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
NSLog(@"Nothing to do.\n");
|
||||
return(1);
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue