From a13872e4c5d28a293ef0371b8a2ec90ea323f624 Mon Sep 17 00:00:00 2001 From: rfm Date: Fri, 7 Dec 2007 12:31:51 +0000 Subject: [PATCH] Fixup response of services menu to set_show_service git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@25698 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 5 +++++ Source/GSServicesManager.m | 32 +++++++++++++++++++++++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0ef31275c..31590ef8c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-12-07 Richard Frith-Macdonald + + * Source/GSServicesManager.m: Fixup to add/remove menu items + when the available items have changed. + 2007-12-06 Fred Kiefer * Source/NSView.m (-initWithCoder:): Handle NSFrameSize. diff --git a/Source/GSServicesManager.m b/Source/GSServicesManager.m index bb292fe27..b55962d98 100644 --- a/Source/GSServicesManager.m +++ b/Source/GSServicesManager.m @@ -858,7 +858,12 @@ static NSString *disabledName = @".GNUstepDisabled"; } if (changed) { - [self rebuildServices]; + /* If we have changed the enabled/disabled services, + * or there have been services added/removed + * then we must rebuild the services menu to add/remove + * items as appropriate. + */ + [self rebuildServicesMenu]; } } @@ -881,6 +886,10 @@ static NSString *disabledName = @".GNUstepDisabled"; return _port; } +/** + * Makes the current set of usable services consistent with the + * data types currently available. + */ - (void) rebuildServices { NSDictionary *services; @@ -955,6 +964,9 @@ static NSString *disabledName = @".GNUstepDisabled"; } } +/** Adds or removes items in the services menu in response to a change + * in the services which are available to the app. + */ - (void) rebuildServicesMenu { if (_servicesMenu != nil) @@ -967,9 +979,10 @@ static NSString *disabledName = @".GNUstepDisabled"; NSMenu *submenu = nil; [_servicesMenu setAutoenablesItems: NO]; - pos = [_servicesMenu numberOfItems]; - for (; pos; pos--) - [_servicesMenu removeItemAtIndex: 0]; + for (pos = [_servicesMenu numberOfItems]; pos > 0; pos--) + { + [_servicesMenu removeItemAtIndex: 0]; + } [_servicesMenu setAutoenablesItems: YES]; keyEquivalents = [NSMutableSet setWithCapacity: 4]; @@ -977,17 +990,23 @@ static NSString *disabledName = @".GNUstepDisabled"; { NSString *title = [_menuTitles objectAtIndex: pos]; NSString *equiv = @""; - NSDictionary *info = [_title2info objectForKey: title]; + NSDictionary *info; NSDictionary *titles; NSDictionary *equivs; NSRange r; unsigned lang; id item; + if (NSShowsServicesMenuItem(title) == NO) + { + continue; // We don't want to show this one. + } + /* * Find the key equivalent corresponding to this menu title * in the service definition. */ + info = [_title2info objectForKey: title]; titles = [info objectForKey: @"NSMenuItem"]; equivs = [info objectForKey: @"NSKeyEquivalent"]; for (lang = 0; lang < [_languages count]; lang++) @@ -1216,6 +1235,9 @@ static NSString *disabledName = @".GNUstepDisabled"; if (didChange) { + /* Types have changed, so we need to enable/disable items in the + * services menu depending on what types they support. + */ [self rebuildServices]; } }