Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Remembering + setting multiple split view divider position



Hi all,

I¹m very confused....  I¹ve hunted through the Apple lists and Googled, and
I can¹t seem to find a way to save the split view divider positions when my
app quits, and then restore them when I re-launch.

I have three dividers, creating four panes in a window.  One vertical
divider divides the right and left sections, and then each one of those
sections has a horizontal divider creating a top and bottom section.  There
are scroll/table views in each of the four panes.

I tried every permutation of "bounds" and "size" by script -- I can save &
set the position of the vertical divider this way, but only after it is done
exactly four times...  Mirroring what another poster described here, it
looks rather odd.  However, I can't seem to set the position of the
horizontal dividers at all that way.

I followed the advice of this post:
http://lists.apple.com/archives/applescript-studio/2002/Nov/msg00116.html

...and created the appropriate files.  First I tested this with the left
horizontal divider -- it worked!  But a subsequent identical call method for
the right horizontal divider failed...?

So what to do with the vertical divider, as this post was for horizontal
only?  I went to this post:
http://lists.apple.com/archives/applescript-studio/2002/Nov/msg00146.html

...and tried to create the method as indicated, with a "vertical" boolean
that would indicate to the function which type of divider was being passed.
No love.

Here are my Cocoa-illerate attempts to apply the advice of the 2nd post:
==================================================

//========Split.h========
//  Special Thanks to Adriaan Tijsseling and Brent Simmons
// (creator of the awesome NetNewsWire)
//  Modified by Graham Jones on 1/12/06.

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@interface NSApplication (ASKAsplit)

- (NSString *) splitViewPosition: (NSSplitView *) splitView vertical: (BOOL)
vertical;
- (void) setSplitViewPosition: (NSSplitView *) splitView position: (NSString
*) s;

@end

==================================================

//========Split.m========

#import "Split.h"

@implementation NSApplication (ASKAsplit)

/*Split view saving and restoring*/

- (NSString *) splitViewPosition: (NSSplitView *) splitView vertical: (BOOL)
vertical
{
NSArray *subViews = [splitView subviews];
int lenFirst, lenSecond;

if (vertical) {

lenFirst = [[subViews objectAtIndex: 0] frame].size.width;

lenSecond = [[subViews objectAtIndex: 1] frame].size.width;
} /*if*/

else {

lenFirst = [[subViews objectAtIndex: 0] frame].size.height;

lenSecond = [[subViews objectAtIndex: 1] frame].size.height;
} /*else*/

return [NSString stringWithFormat: @"%i %i", lenFirst, lenSecond];
}

- (void) setSplitViewPosition: (NSSplitView *) splitView position: (NSString
*) s
{
NSArray *subViews = [splitView subviews];
NSRect newBounds;
float dividerWidth = [splitView dividerThickness];
NSView *viewZero = [subViews objectAtIndex: 0];
NSView *viewOne = [subViews objectAtIndex: 1];
NSArray *stringComponents = [s componentsSeparatedByString: @" "];
int valueZero, valueOne;

valueZero = [[stringComponents objectAtIndex: 0] intValue];    valueOne =
[[stringComponents objectAtIndex: 1] intValue];

int topSize = valueZero;
int bottomSize = valueOne;

if ((topSize + bottomSize + dividerWidth) != [splitView frame].size.height)
topSize = [splitView frame].size.height - dividerWidth - bottomSize;

newBounds = [viewZero frame];
newBounds.size.height = topSize; // leftSize for vertical divider
newBounds.origin.y = 0;
[viewZero setFrame: newBounds];

newBounds = [viewOne frame];
newBounds.size.height = bottomSize;    // rightSize for vertical divider
newBounds.origin.y = topSize + dividerWidth; // leftSize for vertical
[viewOne setFrame: newBounds];
}

@end
==================================================

But when I try to call the method to save the position:

set splitHorizLeftString to call method "splitViewPosition:" with parameters
{theLeftView, false}

I get nothing.

Can anyone please help me see where I'm going wrong?

Thanks,
Graham Jones.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.