Tidy windows menu stuff

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@5235 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 1999-11-18 13:48:00 +00:00
parent 72ec90f181
commit 8970da9f6d
2 changed files with 61 additions and 42 deletions

View file

@ -1357,13 +1357,6 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
[NSException raise: NSInvalidArgumentException
format: @"Object of bad type passed as window"];
/*
* If Menus are implemented as a subclass of window we must make sure
* to exclude them from the windows menu.
*/
if ([aWindow isKindOfClass: [NSMenu class]])
return;
/*
* Can't permit an untitled window in the window menu.
*/
@ -1473,67 +1466,74 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
{
if (windows_menu)
{
NSMutableArray *windows;
NSMenu *menu;
id win;
NSArray *windows;
NSMenu *menu;
unsigned count;
unsigned i;
menu = [self windowsMenu];
if (menu == aMenu)
return;
/*
* Remove all the windows from the old windows menu and store
* them in a temporary array for insertion into the new menu.
* Remove all the windows from the old windows menu.
*/
windows = [NSMutableArray arrayWithCapacity: 10];
if (menu)
{
NSArray *itemArray;
unsigned count;
unsigned i;
NSArray *itemArray = [menu itemArray];
itemArray = [menu itemArray];
count = [itemArray count];
for (i = 0; i < count; i++)
{
id item = [itemArray objectAtIndex: i];
id item = [itemArray objectAtIndex: i];
id win = [item target];
win = [item target];
if ([win isKindOfClass: [NSWindow class]])
{
[windows addObject: win];
[menu removeItem: item];
}
}
}
/*
* Now use [-changeWindowsItem: title: filename: ] to build the new menu.
* Now use [-changeWindowsItem:title:filename:] to build the new menu.
*/
[main_menu setSubmenu: aMenu forItem: (id<NSMenuItem>)windows_menu];
while ((win = [windows lastObject]) != nil)
windows = [self windows];
count = [windows count];
for (i = 0; i < count; i++)
{
[self changeWindowsItem: win
title: [win title]
filename: [win representedFilename] != nil];
[windows removeLastObject];
NSWindow *win = [windows objectAtIndex: i];
if ([win isExcludedFromWindowsMenu] == NO)
{
NSString *t = [win title];
NSString *f = [win representedFilename];
[self changeWindowsItem: win
title: t
filename: [t isEqual: f]];
}
}
[aMenu sizeToFit];
[aMenu update];
}
}
- (void) updateWindowsItem: aWindow
- (void) updateWindowsItem: (NSWindow*)aWindow
{
NSMenu *menu;
NSMenuView *view;
menu = [self windowsMenu];
if (menu)
if (menu != nil)
{
NSArray *itemArray;
unsigned count;
unsigned i;
BOOL found = NO;
view = [menu menuRepresentation];
itemArray = [menu itemArray];
count = [itemArray count];
for (i = 0; i < count; i++)
@ -1542,15 +1542,22 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
if ([item target] == aWindow)
{
NSCellImagePosition oldPos = [item imagePosition];
NSImage *oldImage = [item image];
BOOL changed = NO;
NSMenuItemCell *cell;
NSCellImagePosition oldPos;
NSImage *oldImage;
BOOL changed;
found = YES;
cell = [view menuItemCellForItemAtIndex: i];
oldPos = [cell imagePosition];
oldImage = [cell image];
changed = NO;
if ([aWindow representedFilename] == nil)
{
if (oldPos != NSNoImage)
{
[item setImagePosition: NSNoImage];
[cell setImagePosition: NSNoImage];
changed = YES;
}
}
@ -1560,7 +1567,7 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
if (oldPos != NSImageLeft)
{
[item setImagePosition: NSImageLeft];
[cell setImagePosition: NSImageLeft];
changed = YES;
}
if ([aWindow isDocumentEdited])
@ -1573,19 +1580,27 @@ NSAssert([event retainCount] > 0, NSInternalInconsistencyException);
}
if (newImage != oldImage)
{
[item setImage: newImage];
[cell setImage: newImage];
changed = YES;
}
}
if (changed)
{
[(id)[item controlView] sizeToFit];
[menu sizeToFit];
[menu update];
}
break;
}
}
if (found == NO)
{
NSString *t = [aWindow title];
NSString *f = [aWindow representedFilename];
[self changeWindowsItem: aWindow
title: t
filename: [t isEqual: f]];
}
}
}

View file

@ -316,10 +316,15 @@ static NSMapTable* windowmaps = NULL;
DPSgrestore(context);
NSMapInsert (windowmaps, (void*)window_num, self);
/* I'm not sure we even need this if menu_exclude is set correctly */
if ([self level] >= NSDockWindowLevel)
[[NSApplication sharedApplication] removeWindowsItem: self];
if (_f.menu_exclude == NO)
{
BOOL isDoc = [window_title isEqual: represented_filename];
[NSApp addWindowsItem: self
title: window_title
filename: isDoc];
}
NSDebugLog(@"NSWindow end of init\n");
return self;
}
@ -386,12 +391,11 @@ static NSMapTable* windowmaps = NULL;
- (void) setRepresentedFilename: (NSString*)aString
{
id old = represented_filename;
id old = represented_filename;
BOOL changed = (_f.menu_exclude == NO && [aString isEqual: old] == NO);
ASSIGN(represented_filename, aString);
if (_f.menu_exclude == NO
&& ((represented_filename != nil && old == nil)
|| (represented_filename == nil && old != nil)))
if (changed)
{
[NSApp updateWindowsItem: self];
}