mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 19:01:15 +00:00
Finally implemented toolbar customization (works well, but not yet really polished). Most of the work has been done in GSToolbarCustomizationPalette and GSToolbarCustomizationView. In particular NSToolbarItem has been modified to support custom view copy. GSToolbarView has been updated to take care of dragging initiated from the customization palette.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/branches/Toolbar@24325 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
5a8b852b66
commit
9ccae52d11
8 changed files with 402 additions and 42 deletions
43
ChangeLog
43
ChangeLog
|
@ -1,3 +1,46 @@
|
|||
2007-01-08 Quentin Mathe <qmathe@club-internet.fr>
|
||||
|
||||
Finally introduced toolbar customization... :-)
|
||||
* Headers/Additions/GNUstepGUI/GSToolbarCustomizationPalette.h:
|
||||
* Source/GSToolbarCustomizationPalette.m:
|
||||
New ivars _allowedItems, _defaultItems, _toolbar
|
||||
(-paletteWithToolbar:): Replaced by -palette.
|
||||
(-initWithToolbar:): Replaced by -init.
|
||||
(-show:): Replaced by -showForToolbar:.
|
||||
(+palette):
|
||||
(-init):
|
||||
(-dealloc):
|
||||
(-awakeFromNib):
|
||||
(-showForToolbar:):
|
||||
(-close):
|
||||
(-paletteDidEnd:):
|
||||
New methods that introduce most of the implementation.
|
||||
(GSToolbarCustomizationView): New class which uses GSFlow to display the
|
||||
toolbar items available in the palette.
|
||||
* Source/NSToolbarItem.m: Added NSArchiver include.
|
||||
(-[GSToolbarButton, GSToolbarBackView mouseDown:]): Modified to handle
|
||||
mouse click when the toolbar item is used as element of the
|
||||
customization palette. Index has now a default value of -1 when the item
|
||||
is located in the customization palette.
|
||||
(-[GSToolbarButton, GSToolbarBackView draggedImage:beganAt:]): Modified
|
||||
to avoid the item removal when it is part of the customization palette.
|
||||
(-[GSToolbarSeparatorItem, GSToolbarSpaceItem, GSToolbarFlexibleSpaceItem
|
||||
initWithItemIdentifier]): Updated to set a palette label.
|
||||
(-[GSToolbarSeparatorItem, GSToolbarFlexibleSpaceItem _layout]): Updated to
|
||||
avoid layout override when the item is used in the customization palette.
|
||||
(-isEnabled, -setEnabled:): Fixed to handle enabling properly when the
|
||||
toolbar item uses a custom view.
|
||||
(-copyWithZone:): Improved to copy the label and the custom view.
|
||||
* Source/NSToolbarView.m (-draggingEnded:, -performDragOperation:):
|
||||
Modified to handle the case when the toolbar item comes from the
|
||||
customization palette.
|
||||
* Source/GSToolbar.m:
|
||||
(-_setCustomizationPaletteIsRunning): New private accessor.
|
||||
(-runCustomizationPalette): Updated to match changes made to
|
||||
GSToolbarCustomizationPalette.
|
||||
* Panels/English.lproj/GSToolbarCustomizationPalette.gorm: Updated to use
|
||||
GSToolbarCustomizationView.
|
||||
|
||||
2007-01-07 Quentin Mathe <qmathe@club-internet.fr>
|
||||
|
||||
* Headers/Additions/GNUstepGUI/GSFlow.h:
|
||||
|
|
|
@ -42,12 +42,15 @@
|
|||
id _sizeCheckBox;
|
||||
id _displayPopup;
|
||||
id _doneButton;
|
||||
|
||||
NSMutableArray *_allowedItems;
|
||||
NSMutableArray *_defaultItems;
|
||||
GSToolbar *_toolbar;
|
||||
}
|
||||
|
||||
+ (GSToolbarCustomizationPalette *) paletteWithToolbar: (GSToolbar *)toolbar;
|
||||
- (GSToolbarCustomizationPalette *) initWithToolbar: (GSToolbar *)toolbar;
|
||||
+ (id) palette;
|
||||
|
||||
- (void) show: (id)sender;
|
||||
- (void) showForToolbar: (GSToolbar *)toolbar;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -20,4 +20,11 @@
|
|||
);
|
||||
Super = NSObject;
|
||||
};
|
||||
GSToolbarCustomizationView = {
|
||||
Actions = (
|
||||
);
|
||||
Outlets = (
|
||||
);
|
||||
Super = NSView;
|
||||
};
|
||||
}
|
Binary file not shown.
|
@ -100,6 +100,7 @@ static NSMutableArray *toolbars;
|
|||
- (GSToolbarView *) _toolbarView;
|
||||
- (void) _setWindow: (NSWindow *)window;
|
||||
- (NSWindow *) _window;
|
||||
- (void) _setCustomizationPaletteIsRunning: (BOOL)isRunning;
|
||||
@end
|
||||
|
||||
@interface NSToolbarItem (GNUstepPrivate)
|
||||
|
@ -277,18 +278,18 @@ static NSMutableArray *toolbars;
|
|||
- (void) runCustomizationPalette: (id)sender
|
||||
{
|
||||
GSToolbarCustomizationPalette *palette = [GSToolbarCustomizationPalette
|
||||
paletteWithToolbar: self];
|
||||
palette];
|
||||
|
||||
if (_customizationPaletteIsRunning)
|
||||
{
|
||||
NSLog("Customization palette is already running for toolbar: %@", self);
|
||||
NSLog(@"Customization palette is already running for toolbar: %@", self);
|
||||
return;
|
||||
}
|
||||
|
||||
if (palette != nil)
|
||||
_customizationPaletteIsRunning = YES;
|
||||
|
||||
[palette show: self];
|
||||
[palette showForToolbar: self];
|
||||
}
|
||||
|
||||
- (void) validateVisibleItems
|
||||
|
@ -816,6 +817,11 @@ static NSMutableArray *toolbars;
|
|||
|
||||
// Private Accessors
|
||||
|
||||
- (void) _setCustomizationPaletteIsRunning: (BOOL)isRunning
|
||||
{
|
||||
_customizationPaletteIsRunning = NO;
|
||||
}
|
||||
|
||||
- (void) _setToolbarView: (GSToolbarView *)toolbarView
|
||||
{
|
||||
//GSToolbar *toolbarModel = [self _toolbarModel];
|
||||
|
|
|
@ -28,19 +28,134 @@
|
|||
|
||||
#include "AppKit/NSNibLoading.h"
|
||||
#include "AppKit/NSWindow.h"
|
||||
#include "AppKit/NSToolbarItem.h"
|
||||
#include "GNUstepGUI/GSFlow.h"
|
||||
#include "GNUstepGUI/GSToolbar.h"
|
||||
#include "GNUstepGUI/GSToolbarCustomizationPalette.h"
|
||||
|
||||
#define DEBUG_LEVEL @"Toolbar"
|
||||
|
||||
/* Private methods */
|
||||
|
||||
@interface GSToolbar (Private)
|
||||
- (void) _setCustomizationPaletteIsRunning: (BOOL)isRunning;
|
||||
@end
|
||||
|
||||
@interface NSToolbarItem (Private)
|
||||
- (void) _layout;
|
||||
@end
|
||||
|
||||
/* Customization View */
|
||||
|
||||
// TODO: Make subclass of GSFlow once GSFlow will be refactored as a subclass
|
||||
// of NSView
|
||||
@interface GSToolbarCustomizationView : NSView
|
||||
{
|
||||
GSFlow *flowLayout;
|
||||
}
|
||||
|
||||
- (void) setToolbarItems: (NSArray *)items;
|
||||
|
||||
@end
|
||||
|
||||
@implementation GSToolbarCustomizationView
|
||||
|
||||
- (id) initWithFrame: (NSRect)frame
|
||||
{
|
||||
self = [super initWithFrame: frame];
|
||||
|
||||
if (self != nil)
|
||||
{
|
||||
flowLayout = [[GSFlow alloc] initWithViews: nil viewContainer: self];
|
||||
NSDebugLLog(DEBUG_LEVEL, @"New toolbar customization view with flow %@",
|
||||
flowLayout);
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) dealloc
|
||||
{
|
||||
DESTROY(flowLayout);
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
/* 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) setToolbarItems: (NSArray *)items
|
||||
{
|
||||
NSArray *paletteItems = [self paletteItemsWithToolbarItems: items];
|
||||
NSArray *itemViews = [paletteItems valueForKey: @"_backView"];
|
||||
NSEnumerator *e = [itemViews objectEnumerator];
|
||||
NSView *itemView = nil;
|
||||
|
||||
NSDebugLLog(DEBUG_LEVEL, @"Will insert the views %@ of toolbar items %@ in \
|
||||
customization view", itemViews, paletteItems);
|
||||
|
||||
while ((itemView = [e nextObject]) != nil)
|
||||
{
|
||||
if (itemView != nil)
|
||||
{
|
||||
[flowLayout addView: itemView];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Toolbar item view %@ 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", itemView, [itemView superview]);
|
||||
}
|
||||
}
|
||||
|
||||
[flowLayout setUpViewTree];
|
||||
[flowLayout layout];
|
||||
|
||||
NSDebugLLog(DEBUG_LEVEL, @"Views displayed by flow in %@: %@",
|
||||
[flowLayout viewContainer], [[flowLayout viewContainer] subviews]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
/* Main implementation */
|
||||
|
||||
@implementation GSToolbarCustomizationPalette
|
||||
|
||||
+ (GSToolbarCustomizationPalette *) paletteWithToolbar: (GSToolbar *)toolbar
|
||||
+ (id) palette
|
||||
{
|
||||
return AUTORELEASE([[GSToolbarCustomizationPalette alloc]
|
||||
initWithToolbar: toolbar]);
|
||||
init]);
|
||||
}
|
||||
|
||||
- (GSToolbarCustomizationPalette *) initWithToolbar: (GSToolbar *)toolbar
|
||||
- (id) init
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
|
@ -54,14 +169,125 @@
|
|||
NSLog(@"Failed to load gorm for GSToolbarCustomizationPalette");
|
||||
return nil;
|
||||
}
|
||||
|
||||
_allowedItems = [NSMutableArray new];
|
||||
_defaultItems = [NSMutableArray new];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) show: (id)sender
|
||||
- (void) dealloc
|
||||
{
|
||||
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
[nc removeObserver: self];
|
||||
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: (GSToolbar *)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];
|
||||
identifier = nil;
|
||||
|
||||
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
|
||||
|
||||
// NSView *view = _view;
|
||||
// GSToolbar *toolbar = [self toolbar];
|
||||
// /* 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 try to return a copy of any view which has a
|
||||
// superview already set. */
|
||||
//
|
||||
// if (([view superview] != nil || [toolbar customizationPaletteIsRunning])
|
||||
// && [view respondsToSelector: @selector(copyWithZone:)])
|
||||
// {
|
||||
// view = [_view copyWithZone: NULL];
|
||||
// AUTORELEASE(view);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// NSLog(@"Toolbar item view %@ 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 %@", _view, [view superview]);
|
||||
// }
|
||||
|
|
|
@ -471,9 +471,15 @@ static void initSystemExtensionsColors(void)
|
|||
NSString *str = [pboard stringForType: [[pboard types] objectAtIndex: 0]];
|
||||
int index = [str intValue];
|
||||
GSToolbar *toolbar = [self toolbar];
|
||||
|
||||
[toolbar _concludeRemoveItem:
|
||||
[[info draggingSource] toolbarItem] atIndex: index broadcast: YES];
|
||||
|
||||
/* When index is equal to -1, it means the toolbar item comes from the
|
||||
customization palette. We could also test in this case whether
|
||||
[[[info draggingSource] toolbarItem] toolbar] is nil. */
|
||||
if (index > -1)
|
||||
{
|
||||
[toolbar _concludeRemoveItem:
|
||||
[[info draggingSource] toolbarItem] atIndex: index broadcast: YES];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) draggingExited: (id <NSDraggingInfo>)info
|
||||
|
@ -495,11 +501,21 @@ static void initSystemExtensionsColors(void)
|
|||
NSToolbarItem *item = [[info draggingSource] toolbarItem];
|
||||
int newIndex = [self _insertionIndexAtPoint: [info draggingLocation]];
|
||||
// Calculate the index
|
||||
|
||||
[toolbar _insertPassivelyItem:item atIndex: index];
|
||||
RELEASE(item);
|
||||
[toolbar _moveItemFromIndex: index toIndex: newIndex broadcast: YES];
|
||||
|
||||
|
||||
/* The item is not yet part of the toolbar but coming from the customization
|
||||
palette. We will insert it as a new item. */
|
||||
if (index == -1)
|
||||
{
|
||||
[toolbar insertItemWithItemIdentifier: [item itemIdentifier]
|
||||
atIndex: newIndex];
|
||||
}
|
||||
else
|
||||
{
|
||||
[toolbar _insertPassivelyItem:item atIndex: index];
|
||||
RELEASE(item);
|
||||
[toolbar _moveItemFromIndex: index toIndex: newIndex broadcast: YES];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include <Foundation/NSDictionary.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSArchiver.h>
|
||||
#include "AppKit/NSApplication.h"
|
||||
#include "AppKit/NSButton.h"
|
||||
#include "AppKit/NSButtonCell.h"
|
||||
|
@ -259,7 +260,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
layoutedHeight = [attrStr size].height + InsetItemTextY * 2;
|
||||
break;
|
||||
default:
|
||||
; // Invalid
|
||||
; // Invalid
|
||||
}
|
||||
DESTROY(attrStr);
|
||||
|
||||
|
@ -277,15 +278,17 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
- (void) mouseDown: (NSEvent *)event
|
||||
{
|
||||
GSToolbar *toolbar = [_toolbarItem toolbar];
|
||||
|
||||
if ([event modifierFlags] == NSCommandKeyMask
|
||||
|
||||
/* toolbar is nil when the item is located in the customization palette */
|
||||
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);
|
||||
|
||||
|
@ -309,9 +312,12 @@ 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];
|
||||
forType: GSMovableToolbarItemPboardType];
|
||||
|
||||
[self dragImage: image
|
||||
at: NSMakePoint(0.0, 0.0)
|
||||
|
@ -334,8 +340,11 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
RETAIN(_toolbarItem);
|
||||
/* We retain the toolbar item to be able to have have it reinsered later by
|
||||
the dragging destination. */
|
||||
|
||||
[toolbar _performRemoveItem: _toolbarItem];
|
||||
|
||||
/* If the item is located in the customization palette (toolbar is nil), we
|
||||
must take care of not trying to remove it. */
|
||||
if (toolbar != nil)
|
||||
[toolbar _performRemoveItem: _toolbarItem];
|
||||
}
|
||||
|
||||
- (void) draggedImage: (NSImage *)dragImage
|
||||
|
@ -662,7 +671,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
[view removeFromSuperview];
|
||||
break;
|
||||
default:
|
||||
; // Invalid
|
||||
; // Invalid
|
||||
}
|
||||
|
||||
/* If the view is visible...
|
||||
|
@ -728,14 +737,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
- (void) mouseDown: (NSEvent *)event
|
||||
{
|
||||
GSToolbar *toolbar = [_toolbarItem toolbar];
|
||||
|
||||
if ([event modifierFlags] == NSCommandKeyMask
|
||||
|
||||
/* toolbar is nil when the item is located in the customization palette */
|
||||
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;
|
||||
int index = -1;
|
||||
|
||||
AUTORELEASE(image);
|
||||
|
||||
|
@ -757,9 +768,12 @@ 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];
|
||||
forType: GSMovableToolbarItemPboardType];
|
||||
|
||||
[self dragImage: image
|
||||
at: NSMakePoint(0.0, 0.0)
|
||||
|
@ -783,7 +797,10 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
/* We retain the toolbar item to be able to have have it reinsered later by
|
||||
the dragging destination. */
|
||||
|
||||
[toolbar _performRemoveItem: _toolbarItem];
|
||||
/* If the item is located in the customization palette (toolbar is nil), we
|
||||
must take care of not trying to remove it. */
|
||||
if (toolbar != nil)
|
||||
[toolbar _performRemoveItem: _toolbarItem];
|
||||
}
|
||||
|
||||
- (void) draggedImage: (NSImage *)dragImage
|
||||
|
@ -848,6 +865,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
NSImage *image = [NSImage imageNamed: @"common_ToolbarSeparatorItem"];
|
||||
|
||||
self = [super initWithItemIdentifier: itemIdentifier];
|
||||
[self setPaletteLabel: _(@"Separator")];
|
||||
[(NSButton *)[self _backView] setImagePosition: NSImageOnly];
|
||||
[(NSButton *)[self _backView] setImage: image];
|
||||
/* We bypass the toolbar item accessor to set the image in order to have it
|
||||
|
@ -870,7 +888,11 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
// Override the default implementation
|
||||
|
||||
[(id)backView layout];
|
||||
[backView setFrameSize: NSMakeSize(30, [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(30, [backView frame].size.height)];
|
||||
}
|
||||
@end
|
||||
|
||||
|
@ -884,7 +906,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
||||
{
|
||||
self = [super initWithItemIdentifier: itemIdentifier];
|
||||
[self setLabel: @""];
|
||||
[self setPaletteLabel: _(@"Space")];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
@ -905,7 +927,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
- (id) initWithItemIdentifier: (NSString *)itemIdentifier
|
||||
{
|
||||
self = [super initWithItemIdentifier: itemIdentifier];
|
||||
[self setLabel: @""];
|
||||
[self setPaletteLabel: _(@"Flexible Space")];
|
||||
[self _layout];
|
||||
|
||||
return self;
|
||||
|
@ -921,8 +943,11 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
NSView *backView = [self _backView];
|
||||
|
||||
[(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
|
||||
}
|
||||
|
@ -1170,8 +1195,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
if (_flags._isEnabled)
|
||||
{
|
||||
return [(id)_backView isEnabled];
|
||||
if (_view != nil)
|
||||
{
|
||||
return [_view isEnabled];
|
||||
}
|
||||
else
|
||||
{
|
||||
return [(id)_backView isEnabled];
|
||||
}
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
@ -1246,7 +1279,16 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
- (void) setEnabled: (BOOL)enabled
|
||||
{
|
||||
if (_flags._setEnabled)
|
||||
[(id)_backView setEnabled: enabled];
|
||||
{
|
||||
if (_view != nil)
|
||||
{
|
||||
[_view setEnabled: enabled];
|
||||
}
|
||||
else
|
||||
{
|
||||
[(id)_backView setEnabled: enabled];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) setImage: (NSImage *)image
|
||||
|
@ -1268,7 +1310,7 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
ASSIGN(_label, label);
|
||||
|
||||
if ([_backView isKindOfClass: [NSButton class]])
|
||||
[(NSButton *)_backView setTitle:_label];
|
||||
[(NSButton *)_backView setTitle: _label];
|
||||
|
||||
_modified = YES;
|
||||
if (_toolbar != nil)
|
||||
|
@ -1513,19 +1555,36 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType";
|
|||
{
|
||||
NSToolbarItem *new = [[NSToolbarItem allocWithZone: zone]
|
||||
initWithItemIdentifier: _itemIdentifier];
|
||||
NSData *encodedView = nil;
|
||||
NSView *superview = nil;
|
||||
|
||||
// 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]];
|
||||
[new setEnabled: [self isEnabled]];
|
||||
[new setLabel: [[self label] copyWithZone: zone]];
|
||||
[new setPaletteLabel: [[self paletteLabel] copyWithZone: zone]];
|
||||
[new setMinSize: NSMakeSize(_minSize.width, _minSize.height)];
|
||||
[new setMaxSize: NSMakeSize(_maxSize.width, _maxSize.height)];
|
||||
|
||||
if ([self view] == nil)
|
||||
return new;
|
||||
|
||||
/* 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] removeFromSuperview];
|
||||
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]];
|
||||
[superview addSubview: [self view]];
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue