Stripped down version of the toolbar customization

branch by Quentin Mathe <qmathe@club-internet.fr>.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27835 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2009-02-10 21:02:33 +00:00
parent 570b8a4963
commit 1be0d6ca24
11 changed files with 530 additions and 68 deletions

View file

@ -1,3 +1,21 @@
2009-02-10 Fred Kiefer <FredKiefer@gmx.de>
* Source/NSToolbarFrameworkPrivate.h: Add method
_setCustomizationPaletteIsRunning:.
* Source/NSToolbar.m: (-runCustomizationPalette:): Code to run
customization palette.
* Source/NSToolbarItem.m (-copyWithZone:): Try to copy the view.
* Source/GSToolbarCustomizationPalette.h
* Source/GSToolbarCustomizationPalette.m: New files.
* GNUmakefile: Add new files.
* Panels/English.lproj/GSToolbarCustomizationPalette.gorm
* Panels/English.lproj/GSToolbarCustomizationPalette.gorm/data.info
* Panels/English.lproj/GSToolbarCustomizationPalette.gorm/data.classes
* Panels/English.lproj/GSToolbarCustomizationPalette.gorm/objects.gorm
* Panels/GNUmakefile: Add new panel.
This is a stripped down version of the toolbar customization
branch by Quentin Mathe <qmathe@club-internet.fr>.
2009-02-08 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSThemePrivate.h:

View file

@ -0,0 +1,30 @@
{
"## Comment" = "Do NOT change this file, Gorm maintains it";
FirstResponder = {
Actions = (
"show:"
);
Super = NSObject;
};
GSToolbarCustomizationPalette = {
Actions = (
"show:"
);
Outlets = (
_customizationWindow,
_customizationView,
_defaultTemplateView,
_sizeCheckBox,
_displayPopup,
_doneButton
);
Super = NSObject;
};
GSToolbarCustomizationView = {
Actions = (
);
Outlets = (
);
Super = NSView;
};
}

View file

@ -33,6 +33,7 @@ LOCALIZED_RESOURCE_COMPONENTS = \
GSDataLinkPanel.gorm \
GSPageLayout.gorm \
GSPrintPanel.gorm \
GSToolbarCustomizationPalette.gorm \
GSSpellPanel.gorm
-include GNUmakefile.preamble

View file

@ -219,6 +219,7 @@ GSNibLoading.m \
GSTitleView.m \
GSToolTips.m \
GSToolbarView.m \
GSToolbarCustomizationPalette.m \
GSStandardWindowDecorationView.m \
GSWindowDecorationView.m \
GSPrinting.m \

View file

@ -0,0 +1,58 @@
/*
GSToolbarCustomizationPalette.h
The palette which allows to customize toolbar
Copyright (C) 2007 Free Software Foundation, Inc.
Author: Quentin Mathe <qmathe@club-internet.fr>
Date: January 2007
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,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSToolbarCustomizationPalette
#define _GNUstep_H_GSToolbarCustomizationPalette
#include <Foundation/NSObject.h>
@class NSMutableArray;
@class NSToolbar;
@interface GSToolbarCustomizationPalette : NSObject
{
id _customizationWindow;
id _customizationView;
id _defaultTemplateView;
id _sizeCheckBox;
id _displayPopup;
id _doneButton;
NSMutableArray *_allowedItems;
NSMutableArray *_defaultItems;
NSToolbar *_toolbar;
}
+ (id) palette;
- (void) showForToolbar: (NSToolbar *)toolbar;
@end
#endif /* _GNUstep_H_GSToolbarCustomizationPalette */

View file

@ -0,0 +1,297 @@
/*
GSToolbarCustomizationPalette.m
The palette which allows to customize toolbar
Copyright (C) 2007 Free Software Foundation, Inc.
Author: Quentin Mathe <qmathe@club-internet.fr>
Date: January 2007
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,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <Foundation/NSArray.h>
#include <Foundation/NSDebug.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSEnumerator.h>
#include "AppKit/NSNibLoading.h"
#include "AppKit/NSWindow.h"
#include "AppKit/NSToolbar.h"
#include "AppKit/NSToolbarItem.h"
#include "NSToolbarFrameworkPrivate.h"
#include "GSToolbarCustomizationPalette.h"
#define DEBUG_LEVEL @"Toolbar"
/* Customization View */
@interface GSToolbarCustomizationView : NSView
{
}
- (void) setToolbarItems: (NSArray *)items;
- (NSArray *) paletteItemsWithToolbarItems: (NSArray *)items;
- (void) layout;
@end
@implementation GSToolbarCustomizationView
/* If the toolbar item has a custom view and the item is in use in the
toolbar, this view has already a superview. We need to make a copy of it
in order to be able to put it in the customization view.
As a safety measure, we makes a copy of all toolbar items, thereby of all
views. This ensures the toolbar items displayed in the palette don't
reference a toolbar. */
- (NSArray *) paletteItemsWithToolbarItems: (NSArray *)items
{
NSMutableArray *paletteItems = [NSMutableArray array];
NSEnumerator *e = [items objectEnumerator];
NSToolbarItem *item = nil;
e = [items objectEnumerator];
while ((item = [e nextObject]) != nil)
{
NSToolbarItem *newItem = [item copy];
if ([newItem paletteLabel] != nil)
[newItem setLabel: [newItem paletteLabel]];
[newItem setEnabled: YES];
[newItem _layout];
[paletteItems addObject: newItem];
}
NSDebugLLog(DEBUG_LEVEL, @"Generated palette items %@ from toolbar items %@",
paletteItems, items);
return paletteItems;
}
- (void) layout
{
NSSize boundsSize = [self bounds].size;
float maxWidth = boundsSize.width;
float maxHeight = boundsSize.height;
float hAccumulator = 0.0;
float vAccumulator = 0.0;
NSEnumerator *e = [[self subviews] objectEnumerator];
NSView *layoutedView = nil;
int lastRow = 0;
int index = 0;
// Loop over all subviews
while ((layoutedView = [e nextObject]) != nil)
{
NSRect frame = [layoutedView frame];
NSSize size = frame.size;
float height = size.height;
float width = size.width;
if ((hAccumulator + width) <= maxWidth)
{
// Position view in row
if (vAccumulator < height)
{
vAccumulator = height;
// FIXME: need to adjust all other elements of row
}
}
else
{
// Move on to next row
maxHeight -= vAccumulator;
hAccumulator = 0.0;
vAccumulator = height;
lastRow = index;
}
[layoutedView setFrameOrigin: NSMakePoint(hAccumulator,
maxHeight - vAccumulator)];
hAccumulator += width;
index++;
}
}
- (void) setToolbarItems: (NSArray *)items
{
NSArray *paletteItems = [self paletteItemsWithToolbarItems: items];
NSEnumerator *e;
NSView *itemView;
NSToolbarItem *item;
// Remove all old subviews
e = [[self subviews] objectEnumerator];
while ((itemView = [e nextObject]) != nil)
{
[itemView removeFromSuperview];
}
NSDebugLLog(DEBUG_LEVEL, @"Will insert the views of toolbar items %@ in \
customization view", paletteItems);
e = [paletteItems objectEnumerator];
while ((item = [e nextObject]) != nil)
{
itemView = [item _backView];
if (itemView != nil)
{
[self addSubview: itemView];
}
else
{
NSLog(@"Toolbar item %@ will not be visible in the customization \
view or if you insert it in a toolbar now. The view is already in \
use in superview or does not implement NSCoding protocol", item);
}
}
[self layout];
}
@end
/* Main implementation */
@implementation GSToolbarCustomizationPalette
+ (id) palette
{
return AUTORELEASE([[GSToolbarCustomizationPalette alloc]
init]);
}
- (id) init
{
self = [super init];
if (self != nil)
{
BOOL nibLoaded = [NSBundle loadNibNamed: @"GSToolbarCustomizationPalette"
owner: self];
if (nibLoaded == NO)
{
NSLog(@"Failed to load GSToolbarCustomizationPalette");
RELEASE(self);
return nil;
}
_allowedItems = [NSMutableArray new];
_defaultItems = [NSMutableArray new];
}
return self;
}
- (void) dealloc
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc removeObserver: self];
DESTROY(_customizationWindow);
DESTROY(_customizationView);
DESTROY(_defaultTemplateView);
DESTROY(_sizeCheckBox);
DESTROY(_displayPopup);
DESTROY(_doneButton);
DESTROY(_defaultItems);
DESTROY(_allowedItems);
[super dealloc];
}
- (void) awakeFromNib
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
NSDebugLLog(DEBUG_LEVEL, @"GSToolbarCustomizationPalette awaking from nib");
[nc addObserver: self
selector: @selector(paletteDidEnd:)
name: NSWindowWillCloseNotification
object: _customizationWindow];
}
/* It's safer to keep no reference on the toolbar itself. The customization
palette isn't bound to the toolbar passed as parameter, in other words the
palette can be used to customize other toolbars with the same identifier.
In spite of this, a reference must be kept on the toolbar which initiated
the customization to let it know when the customization has ended. */
- (void) showForToolbar: (NSToolbar *)toolbar
{
NSArray *itemIdentifiers = nil;
NSEnumerator *e = nil;
NSString *identifier = nil;
id delegate = [toolbar delegate];
[_allowedItems removeAllObjects];
[_defaultItems removeAllObjects];
if (delegate == nil)
{
NSLog(@"The toolbar %@ needs a delegate to allow customization",
toolbar);
return;
}
itemIdentifiers = [delegate toolbarAllowedItemIdentifiers: toolbar];
e = [itemIdentifiers objectEnumerator];
while ((identifier = [e nextObject]) != nil)
{
[_allowedItems addObject: [delegate toolbar: toolbar
itemForItemIdentifier: identifier
willBeInsertedIntoToolbar: NO]];
}
itemIdentifiers = [delegate toolbarDefaultItemIdentifiers: toolbar];
e = [itemIdentifiers objectEnumerator];
while ((identifier = [e nextObject]) != nil)
{
[_defaultItems addObject: [delegate toolbar: toolbar
itemForItemIdentifier: identifier
willBeInsertedIntoToolbar: NO]];
}
[_customizationView setToolbarItems: _allowedItems];
/* We retain ourself to keep us alive until the palette is closed (this is
useful in case nobody retains us). */
RETAIN(self);
/* No need to retain the toolbar because it will first request us to close
when it goes away. */
_toolbar = toolbar;
[_customizationWindow makeKeyAndOrderFront: self];
}
- (void) close
{
[_customizationWindow close];
}
- (void) paletteDidEnd: (NSNotification *)notif
{
[_toolbar _setCustomizationPaletteIsRunning: NO];
_toolbar = nil;
/* We can now get rid safely of the extra retain done in -showForToolbar: */
RELEASE(self);
}
@end

View file

@ -45,13 +45,14 @@
#include "AppKit/NSEvent.h"
#include "AppKit/NSMenu.h"
#include "AppKit/NSNibLoading.h"
#include "AppKit/NSToolbar.h"
#include "AppKit/NSToolbarItem.h"
#include "AppKit/NSView.h"
#include "AppKit/NSWindow.h"
#include "GNUstepGUI/GSToolbarView.h"
#include "AppKit/NSToolbar.h"
#include "NSToolbarFrameworkPrivate.h"
#include "GSToolbarCustomizationPalette.h"
// internal
static NSNotificationCenter *nc = nil;
@ -598,13 +599,20 @@ static GSValidationCenter *vc = nil;
- (void) runCustomizationPalette: (id)sender
{
_customizationPaletteIsRunning =
[NSBundle loadNibNamed: @"GSToolbarCustomizationPalette" owner: self];
GSToolbarCustomizationPalette *palette;
if (!_customizationPaletteIsRunning)
if (_customizationPaletteIsRunning)
{
NSLog(@"Failed to load gorm for GSToolbarCustomizationPalette");
NSLog(@"Customization palette is already running for toolbar: %@", self);
return;
}
palette = [GSToolbarCustomizationPalette palette];
if (palette != nil)
_customizationPaletteIsRunning = YES;
[palette showForToolbar: self];
}
- (void) validateVisibleItems
@ -640,6 +648,11 @@ static GSValidationCenter *vc = nil;
return _customizationPaletteIsRunning;
}
- (void) _setCustomizationPaletteIsRunning: (BOOL)isRunning
{
_customizationPaletteIsRunning = isRunning;
}
- (id) delegate
{
return _delegate;

View file

@ -103,8 +103,11 @@
- (void) _toolbarViewWillMoveToSuperview: (NSView *)newSuperview;
// Accessors
- (void) _setCustomizationPaletteIsRunning: (BOOL)isRunning;
- (void) _setToolbarView: (GSToolbarView *)toolbarView;
- (GSToolbarView *) _toolbarView;
// Deprecated
- (void) setUsesStandardBackgroundColor: (BOOL)standard;
- (BOOL) usesStandardBackgroundColor;
@end

View file

@ -31,6 +31,7 @@
#include <Foundation/NSObject.h>
#include <Foundation/NSArray.h>
#include <Foundation/NSArchiver.h>
#include <Foundation/NSDictionary.h>
#include <Foundation/NSString.h>
#include "AppKit/NSApplication.h"
@ -255,17 +256,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{
NSToolbar *toolbar = [_toolbarItem toolbar];
if ([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization])
if (([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization])
|| [toolbar customizationPaletteIsRunning] || toolbar == nil)
{
NSSize viewSize = [self frame].size;
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
NSCell *cell = [self cell];
NSPasteboard *pboard;
int index;
int index = -1;
AUTORELEASE(image);
// Prepare the drag
RETAIN(self);
@ -286,17 +286,21 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil];
index = [toolbar _indexOfItem: _toolbarItem];
if (toolbar != nil)
{
index = [toolbar _indexOfItem: _toolbarItem];
}
[pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType];
[self dragImage: image
at: NSMakePoint(0.0, 0.0)
at: NSMakePoint(0.0, viewSize.height)
offset: NSMakeSize(0.0, 0.0)
event: event
pasteboard: pboard
source: self
slideBack: NO];
RELEASE(image);
}
else if ([event modifierFlags] != NSCommandKeyMask)
{
@ -490,7 +494,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem;
- (NSToolbarItem *) toolbarItem;
- (void) layout;
- (BOOL) enabled;
- (BOOL) isEnabled;
- (void) setEnabled: (BOOL)enabled;
@end
@ -710,45 +714,48 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{
NSToolbar *toolbar = [_toolbarItem toolbar];
if ([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization])
if (([event modifierFlags] == NSCommandKeyMask
&& [toolbar allowsUserCustomization])
|| [toolbar customizationPaletteIsRunning] || toolbar == nil)
{
NSSize viewSize = [self frame].size;
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
NSPasteboard *pboard;
int index;
AUTORELEASE(image);
// Prepare the drag
RETAIN(self);
/* We need to keep this view (aka self) to be able to draw the drag
image. */
// Draw the drag content in an image
/* The code below is only partially supported by GNUstep, then NSImage
needs to be improved. */
[image lockFocus];
[self drawRect:
NSMakeRect(0, 0, viewSize.width, viewSize.height)];
[image unlockFocus];
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil];
NSSize viewSize = [self frame].size;
NSImage *image = [[NSImage alloc] initWithSize: viewSize];
NSPasteboard *pboard;
int index = -1;
// Prepare the drag
RETAIN(self);
/* We need to keep this view (aka self) to be able to draw the drag
image. */
// Draw the drag content in an image
/* The code below is only partially supported by GNUstep, then NSImage
needs to be improved. */
[image lockFocus];
[self drawRect:
NSMakeRect(0, 0, viewSize.width, viewSize.height)];
[image unlockFocus];
pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
[pboard declareTypes: [NSArray arrayWithObject: GSMovableToolbarItemPboardType]
owner: nil];
if (toolbar != nil)
{
index = [toolbar _indexOfItem: _toolbarItem];
[pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType];
[self dragImage: image
at: NSMakePoint(0.0, 0.0)
offset: NSMakeSize(0.0, 0.0)
event: event
pasteboard: pboard
source: self
slideBack: NO];
}
[pboard setString: [NSString stringWithFormat:@"%d", index]
forType: GSMovableToolbarItemPboardType];
[self dragImage: image
at: NSMakePoint(0.0, viewSize.height)
offset: NSMakeSize(0.0, 0.0)
event: event
pasteboard: pboard
source: self
slideBack: NO];
RELEASE(image);
}
else if ([event modifierFlags] != NSCommandKeyMask)
{
@ -760,6 +767,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
{
NSToolbar *toolbar = [_toolbarItem toolbar];
// FIXME: Where is this released?
RETAIN(_toolbarItem);
/* We retain the toolbar item to be able to have have it reinsered later by
the dragging destination. */
@ -788,14 +796,14 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
return _toolbarItem;
}
- (BOOL) enabled
- (BOOL) isEnabled
{
id view = [_toolbarItem view];
if ([view respondsToSelector: @selector(setEnabled:)])
{
return [view enabled];
}
if ([view respondsToSelector: @selector(isEnabled)])
{
return [view isEnabled];
}
return _enabled;
}
@ -806,9 +814,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
_enabled = enabled;
if ([view respondsToSelector: @selector(setEnabled:)])
{
[view setEnabled: enabled];
}
{
[view setEnabled: enabled];
}
}
@end
@ -826,14 +834,13 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
@implementation GSToolbarSeparatorItem
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
NSImage *image = [NSImage imageNamed: @"common_ToolbarSeparatorItem"];
self = [super initWithItemIdentifier: itemIdentifier];
if (!self)
return nil;
[(NSButton *)[self _backView] setImagePosition: NSImageOnly];
[(NSButton *)[self _backView] setImage: image];
[(NSButton *)[self _backView] setImage:
[NSImage imageNamed: @"common_ToolbarSeparatorItem"]];
/* We bypass the toolbar item accessor to set the image in order to have it
(48 * 48) not resized. */
@ -854,7 +861,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
// Override the default implementation
[(id)backView layout];
[backView setFrameSize: NSMakeSize(30, [backView frame].size.height)];
if ([self toolbar] != nil)
[backView setFrameSize: NSMakeSize(30, [backView frame].size.height)];
}
@end
@ -868,8 +876,10 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
[self setLabel: @""];
if (!self)
return nil;
[self setPaletteLabel: _(@"Space")];
return self;
}
@ -889,7 +899,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
[self setLabel: @""];
if (!self)
return nil;
[self setPaletteLabel: _(@"Flexible Space")];
[self _layout];
return self;
@ -906,7 +918,10 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
[(id)backView layout];
[backView setFrameSize: NSMakeSize(0, [backView frame].size.height)];
/* If the item is not part of a toolbar, this usually means it is used by
customization palette, we shouldn't resize it in this case. */
if ([self toolbar] != nil)
[backView setFrameSize: NSMakeSize(0, [backView frame].size.height)];
// Override the default implementation in order to reset the _backView to a zero width
}
@ -928,6 +943,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
if (!self)
return nil;
[self setImage: [NSImage imageNamed: @"common_ToolbarShowColorsItem"]];
[self setLabel: _(@"Colors")];
@ -949,6 +966,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
if (!self)
return nil;
[self setImage: [NSImage imageNamed: @"common_ToolbarShowFontsItem"]];
[self setLabel: _(@"Fonts")];
@ -970,12 +989,14 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
if (!self)
return nil;
[self setImage: [NSImage imageNamed: @"common_ToolbarCustomizeToolbarItem"]];
[self setLabel: _(@"Customize")];
// Set action...
[self setTarget: nil]; // Goes to first responder..
[self setAction: @selector(runCustomizationPalette:)];
[self setAction: @selector(runToolbarCustomizationPalette:)];
return self;
}
@ -991,6 +1012,8 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
{
self = [super initWithItemIdentifier: itemIdentifier];
if (!self)
return nil;
[self setImage: [NSImage imageNamed: @"common_Printer"]];
[self setLabel: _(@"Print...")];
@ -1527,7 +1550,6 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
// Copy all items individually...
[new setTarget: [self target]];
[new setAction: [self action]];
[new setView: [self view]];
[new setToolTip: [[self toolTip] copyWithZone: zone]];
[new setTag: [self tag]];
[new setImage: [[self image] copyWithZone: zone]];
@ -1541,6 +1563,25 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
[new setMenuFormRepresentation: [[self menuFormRepresentation]
copyWithZone: zone]];
if ([self view] != nil)
{
NSData *encodedView = nil;
NSView *superview = nil;
/* NSView doesn't implement -copyWithZone:, that's why we encode
then decode the view to create a copy of it. */
superview = [[self view] superview];
/* We must avoid to encode view hierarchy */
[[self view] removeFromSuperviewWithoutNeedingDisplay];
NSLog(@"Encode toolbar item with label %@, view %@ and superview %@",
[self label], [self view], superview);
// NOTE: Keyed archiver would fail on NSSlider here.
encodedView = [NSArchiver archivedDataWithRootObject: [self view]];
[new setView: [NSUnarchiver unarchiveObjectWithData: encodedView]];
// Re-add the view to its hierarchy
[superview addSubview: [self view]];
}
return new;
}