mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:50:48 +00:00
Updated NSMenu, NSMenuItem decoding code for change in NSMenu, NSMenuItem
code in the gui library git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@7482 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c50bc395ea
commit
daafa04baf
1 changed files with 43 additions and 18 deletions
|
@ -805,28 +805,57 @@ void __dummy_GMAppKit_functionForLinking() {}
|
||||||
decodeObjectWithName:@"mixedStateImage"]];
|
decodeObjectWithName:@"mixedStateImage"]];
|
||||||
[self setKeyEquivalent:[unarchiver decodeStringWithName:@"keyEquivalent"]];
|
[self setKeyEquivalent:[unarchiver decodeStringWithName:@"keyEquivalent"]];
|
||||||
[self setState:[unarchiver decodeIntWithName:@"state"]];
|
[self setState:[unarchiver decodeIntWithName:@"state"]];
|
||||||
[self setTarget:[unarchiver decodeObjectWithName:@"target"]];
|
|
||||||
[self setAction:[unarchiver decodeSelectorWithName:@"action"]];
|
[self setAction:[unarchiver decodeSelectorWithName:@"action"]];
|
||||||
[self setTag:[unarchiver decodeIntWithName:@"tag"]];
|
[self setTag:[unarchiver decodeIntWithName:@"tag"]];
|
||||||
[self setEnabled:[unarchiver decodeBOOLWithName:@"isEnabled"]];
|
[self setEnabled:[unarchiver decodeBOOLWithName:@"isEnabled"]];
|
||||||
[self setChangesState:[unarchiver decodeBOOLWithName:@"changesState"]];
|
[self setChangesState:[unarchiver decodeBOOLWithName:@"changesState"]];
|
||||||
[self setMenu:nil];
|
|
||||||
[self setSubmenu:[unarchiver decodeObjectWithName:@"submenu"]];
|
|
||||||
[self setRepresentedObject:[unarchiver
|
[self setRepresentedObject:[unarchiver
|
||||||
decodeObjectWithName:@"representedObject"]];
|
decodeObjectWithName:@"representedObject"]];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Here we have quite a delicate point.
|
||||||
|
* In OPENSTEP 4.x, NSMenuItems with submenus have their submenu
|
||||||
|
* as target; they do not answer to -submenu, so the encoded submenu
|
||||||
|
* is nil; the submenu is actually encoded as the target.
|
||||||
|
*
|
||||||
|
* In GNUstep the target is instead the menu, and the submenu
|
||||||
|
* is stored in an additional ivar.
|
||||||
|
*
|
||||||
|
* I don't know about MacOS-X.
|
||||||
|
*
|
||||||
|
* This code needs to be able to decode gmodels created on OPENSTEP 4.x too,
|
||||||
|
* that's why we have the following.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Safety assignment. */
|
||||||
|
[self setMenu: nil];
|
||||||
|
/* Set submenu. If submenu is nil, this will set target to nil too. */
|
||||||
|
[self setSubmenu: [unarchiver decodeObjectWithName: @"submenu"]];
|
||||||
|
/* Set target. This does not touch submenu. */
|
||||||
|
[self setTarget: [unarchiver decodeObjectWithName: @"target"]];
|
||||||
|
|
||||||
|
/* Now we fix the submenu from the target if needed: */
|
||||||
#ifdef GNU_GUI_LIBRARY
|
#ifdef GNU_GUI_LIBRARY
|
||||||
/*
|
/*
|
||||||
* Set submenu from target if not set
|
* Set submenu from target if not set (this happens if the gmodel
|
||||||
|
* was created on OPENSTEP).
|
||||||
*/
|
*/
|
||||||
if ([NSStringFromSelector ([self action])
|
if ([NSStringFromSelector ([self action])
|
||||||
isEqualToString: @"submenuAction:"])
|
isEqualToString: @"submenuAction:"])
|
||||||
{
|
{
|
||||||
if ([self submenu] == nil)
|
if ([self submenu] == nil)
|
||||||
[self setSubmenu: [self target]];
|
{
|
||||||
|
[self setSubmenu: [self target]];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* NB: The target might now be wrong (in case the gmodel was encoded
|
||||||
|
in a platform where the target is the submenu while we now want
|
||||||
|
the target to be the menu) ! This is automatically fixed later,
|
||||||
|
because after the NSMenuItem is decoded, it is added to its
|
||||||
|
container NSMenu, which will fix the target. */
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
NSLog (@"menu item %@: target = %@, isEnabled = %d",
|
NSLog (@"menu item %@: target = %@, isEnabled = %d",
|
||||||
[self title], [self target], [self isEnabled]);
|
[self title], [self target], [self isEnabled]);
|
||||||
|
@ -859,24 +888,20 @@ void __dummy_GMAppKit_functionForLinking() {}
|
||||||
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
- (id)initWithModelUnarchiver:(GMUnarchiver*)unarchiver
|
||||||
{
|
{
|
||||||
int i, count;
|
int i, count;
|
||||||
NSMutableArray* itemArray = [self itemArray];
|
NSMutableArray* decodedItems;
|
||||||
NSMutableArray* decodedItems
|
|
||||||
= [unarchiver decodeObjectWithName:@"itemArray"];
|
|
||||||
|
|
||||||
for (i = 0, count = [decodedItems count]; i < count; i++)
|
decodedItems = [unarchiver decodeObjectWithName: @"itemArray"];
|
||||||
[self addItem:[decodedItems objectAtIndex:i]];
|
count = [decodedItems count];
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
id item = [itemArray objectAtIndex:i];
|
id item = [decodedItems objectAtIndex: i];
|
||||||
|
|
||||||
if ([item hasSubmenu])
|
[self addItem: item];
|
||||||
[self setSubmenu:[item submenu] forItem:item];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[self setAutoenablesItems:
|
[self setAutoenablesItems: [unarchiver decodeBOOLWithName:
|
||||||
[unarchiver decodeBOOLWithName:@"autoenablesItems"]];
|
@"autoenablesItems"]];
|
||||||
|
|
||||||
[self sizeToFit];
|
[self sizeToFit];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue