mirror of
https://github.com/gnustep/apps-gorm.git
synced 2025-04-23 06:20:47 +00:00
drag and drop logic for formatters
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/apps/gorm/trunk@11628 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
aacc97f46b
commit
26a3cd1f4e
4 changed files with 141 additions and 8 deletions
|
@ -24,6 +24,11 @@
|
|||
|
||||
#include "GormPrivate.h"
|
||||
|
||||
#define HASFORMATTER(obj) \
|
||||
[obj respondsToSelector: @selector(cell)] && \
|
||||
[[obj cell] respondsToSelector: @selector(formatter)] && \
|
||||
[[obj cell] formatter] != nil
|
||||
|
||||
/*
|
||||
* The GormEmptyInspector is a placeholder for an empty selection.
|
||||
*/
|
||||
|
@ -262,6 +267,14 @@
|
|||
[item setKeyEquivalent: @"4"];
|
||||
[item setTag: 3];
|
||||
|
||||
[popup addItemWithTitle: @"Custom Class"];
|
||||
item = [popup itemAtIndex: 4];
|
||||
[item setTarget: self];
|
||||
[item setAction: @selector(setCurrentInspector:)];
|
||||
[item setKeyEquivalent: @"5"];
|
||||
[item setTag: 4];
|
||||
[item setEnabled: NO];
|
||||
|
||||
bar = [[NSBox alloc] initWithFrame: NSMakeRect (0, 0, IVW, 2)];
|
||||
[bar setBorderType: NSGrooveBorder];
|
||||
[bar setTitlePosition: NSNoTitle];
|
||||
|
@ -304,7 +317,12 @@
|
|||
selector: @selector(handleNotification:)
|
||||
name: NSWindowDidResignKeyNotification
|
||||
object: panel];
|
||||
|
||||
[nc addObserver: self
|
||||
selector: @selector(updateInspectorPopUp:)
|
||||
name: NSPopUpButtonWillPopUpNotification
|
||||
object: popup];
|
||||
[popup setTarget: self];
|
||||
[popup setAction: @selector(updateInspectorPopUp:)];
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -322,7 +340,7 @@
|
|||
[panel makeKeyAndOrderFront: self];
|
||||
current = 1;
|
||||
}
|
||||
else if (current == 4)
|
||||
else if (current >= [popup numberOfItems])
|
||||
{
|
||||
current = 1;
|
||||
}
|
||||
|
@ -389,6 +407,21 @@
|
|||
case 1: newInspector = [obj connectInspectorClassName]; break;
|
||||
case 2: newInspector = [obj sizeInspectorClassName]; break;
|
||||
case 3: newInspector = [obj helpInspectorClassName]; break;
|
||||
case 5:
|
||||
{
|
||||
// If the object doesn't understand formatter then default to attributes
|
||||
if (HASFORMATTER(obj))
|
||||
{
|
||||
newInspector = [ [[obj cell] formatter] inspectorClassName];
|
||||
}
|
||||
else
|
||||
{
|
||||
current = 0;
|
||||
[popup selectItemAtIndex: 0];
|
||||
newInspector = [obj inspectorClassName];
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: newInspector = [obj classInspectorClassName]; break;
|
||||
}
|
||||
}
|
||||
|
@ -489,9 +522,45 @@
|
|||
[inspectorView addSubview: newView];
|
||||
}
|
||||
}
|
||||
|
||||
[inspector setObject: obj];
|
||||
}
|
||||
|
||||
/* This is to include the formatter item in the pop up button
|
||||
* if the selected object in Gorm has a formatter set
|
||||
*/
|
||||
- (void) updateInspectorPopUp: (NSNotification*)aNotification
|
||||
{
|
||||
NSArray *selection = [[(id<IB>)NSApp selectionOwner] selection];
|
||||
id obj = [selection lastObject];
|
||||
|
||||
// See if the selected object has a formatter
|
||||
if (HASFORMATTER(obj))
|
||||
{
|
||||
// Ifso add the Formatter menu item if not already there
|
||||
if ([popup numberOfItems] < 6)
|
||||
{
|
||||
NSMenuItem *item;
|
||||
[popup addItemWithTitle: @"Formatter"];
|
||||
item = [popup itemAtIndex: 5];
|
||||
[item setTarget: self];
|
||||
[item setAction: @selector(setCurrentInspector:)];
|
||||
[item setKeyEquivalent: @"6"];
|
||||
[item setTag: 5];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Remove the Formatter menu item
|
||||
if ([popup numberOfItems] == 6)
|
||||
{
|
||||
[popup removeItemAtIndex: 5];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
|
|
|
@ -71,7 +71,8 @@ static NSImage *dragImage = nil;
|
|||
{
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
IBCellPboardType, IBMenuPboardType, IBMenuCellPboardType,
|
||||
IBObjectPboardType, IBViewPboardType, IBWindowPboardType, nil]];
|
||||
IBObjectPboardType, IBViewPboardType, IBWindowPboardType,
|
||||
IBFormatterPboardType,nil]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
@ -188,7 +189,8 @@ static NSImage *dragImage = nil;
|
|||
pb = [NSPasteboard pasteboardWithName: NSDragPboard];
|
||||
ASSIGN(dragPb, pb);
|
||||
[active copyObject: obj type: type toPasteboard: pb];
|
||||
|
||||
NSDebugLog(@"type: %@, obj: %@,", type, obj);
|
||||
|
||||
[self dragImage: dragImage
|
||||
at: rect.origin
|
||||
offset: NSMakeSize(0,0)
|
||||
|
|
|
@ -1343,7 +1343,7 @@ static BOOL done_editing;
|
|||
- (unsigned) draggingEntered: (id<NSDraggingInfo>)sender
|
||||
{
|
||||
NSArray *types;
|
||||
|
||||
|
||||
dragPb = [sender draggingPasteboard];
|
||||
types = [dragPb types];
|
||||
if ([types containsObject: IBViewPboardType] == YES)
|
||||
|
@ -1354,6 +1354,10 @@ static BOOL done_editing;
|
|||
{
|
||||
dragType = GormLinkPboardType;
|
||||
}
|
||||
else if ([types containsObject: IBFormatterPboardType] == YES)
|
||||
{
|
||||
dragType = IBFormatterPboardType;
|
||||
}
|
||||
else
|
||||
{
|
||||
dragType = nil;
|
||||
|
@ -1383,9 +1387,13 @@ static BOOL done_editing;
|
|||
[NSApp displayConnectionBetween: [NSApp connectSource] and: sub];
|
||||
return NSDragOperationLink;
|
||||
}
|
||||
else
|
||||
else if (dragType == IBFormatterPboardType)
|
||||
{
|
||||
return 0;
|
||||
return NSDragOperationCopy;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NSDragOperationNone;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1449,7 +1457,7 @@ static BOOL done_editing;
|
|||
* Permit views and connections to be dragged in to the window.
|
||||
*/
|
||||
[self registerForDraggedTypes: [NSArray arrayWithObjects:
|
||||
IBViewPboardType, GormLinkPboardType, nil]];
|
||||
IBViewPboardType, GormLinkPboardType, IBFormatterPboardType, nil]];
|
||||
|
||||
[win setInitialFirstResponder: self];
|
||||
return self;
|
||||
|
@ -1587,6 +1595,44 @@ static BOOL done_editing;
|
|||
[NSApp displayConnectionBetween: [NSApp connectSource] and: sub];
|
||||
[NSApp startConnecting];
|
||||
}
|
||||
else if (dragType == IBFormatterPboardType)
|
||||
{
|
||||
NSData *data;
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
id obj = [super hitTest: loc];
|
||||
id fmtr;
|
||||
|
||||
data = [dragPb dataForType: IBFormatterPboardType];
|
||||
if (data == nil)
|
||||
{
|
||||
NSLog(@"Pasteboard %@ doesn't contain any formatter data", dragPb);
|
||||
return NO;
|
||||
}
|
||||
fmtr = [[NSUnarchiver unarchiveObjectWithData: data] objectAtIndex:0];
|
||||
|
||||
if (![fmtr isKindOfClass: [NSFormatter class]] )
|
||||
{
|
||||
NSLog(@"Object in pasteboard %@ not a formatter (%@)", [fmtr class]);
|
||||
return NO;
|
||||
}
|
||||
|
||||
// If object respond to formatter then set it up and make it the
|
||||
// current selection so that inspector displays ok
|
||||
if ([obj respondsToSelector: @selector(cell)] &&
|
||||
[[obj cell] respondsToSelector: @selector(formatter)] &&
|
||||
[[obj cell] formatter] == nil )
|
||||
{
|
||||
NSDebugLog (@"Setting formatter %@ for cell %@",fmtr, [obj cell]);
|
||||
[[obj cell] setFormatter: fmtr];
|
||||
[[obj cell] setObjectValue: [[fmtr class] defaultFormatValue] ];
|
||||
|
||||
[self makeSelectionVisible: NO];
|
||||
|
||||
[self selectObjects: [NSArray arrayWithObject: obj]];
|
||||
[self displayIfNeeded];
|
||||
[self makeSelectionVisible: YES];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Drop with unrecognized type (%@)!", dragType);
|
||||
|
@ -1622,6 +1668,21 @@ static BOOL done_editing;
|
|||
return YES;
|
||||
}
|
||||
}
|
||||
else if (dragType == IBFormatterPboardType)
|
||||
{
|
||||
NSPoint loc = [sender draggingLocation];
|
||||
NSView *sub = [super hitTest: loc];
|
||||
/*
|
||||
* We can accept a formatter dropped on a cell of type text.
|
||||
*/
|
||||
if (sub != nil && sub != self &&
|
||||
[sub isKindOfClass: [NSTextField class]] )
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ NSString *IBMenuCellPboardType = @"IBMenuCellPboardType";
|
|||
NSString *IBObjectPboardType = @"IBObjectPboardType";
|
||||
NSString *IBViewPboardType = @"IBViewPboardType";
|
||||
NSString *IBWindowPboardType = @"IBWindowPboardType";
|
||||
NSString *IBFormatterPboardType = @"IBFormatterPboardType";
|
||||
|
||||
@implementation IBPalette
|
||||
|
||||
|
|
Loading…
Reference in a new issue