A couple Q's

zots

Re-member
I am rewriting an app in cocoa, that I originally wrote in RB. It looks like this:
CBShot1.jpg

You enter whatever transactions and they will update in the lower window. Then you do file>>save and it write the preference file which looks like this:
CBShot2.jpg

My first question; I want to know what you think is the best way to make the pref file with cocoa. NSMutableDictionary? Can I read and write an NSMutableDictionary to a file with NSFileHandle?

My second question is about the setContentSize method of NSWindow. In the first two images you see the main window has different heights when the Check radio button is clicked to account for the extra fields. Here is the code I used for this in cocoa:
Code:
    NSSize checkSize,defaultSize;
    checkSize.width = 320;
    defaultSize.width = 320;
    checkSize.height = 181;
    defaultSize.height = 151;
    switch ([optType selectedRow])
    {
        case -1://fall through
        case 0://fall through
        case 1://fall through
        case 3://not a check
            [[sender window] setContentSize:defaultSize];
            [txtCheckNumber setEnabled:NO];
            [txtPayCheckTo setEnabled:NO];
            break;
        case 2://a check
            [[sender window] setContentSize:checkSize];
            [txtCheckNumber setEnabled:YES];
            [txtPayCheckTo setEnabled:YES];
            break;
    }
This works but the window is resizing from the top, you can see in these images:
CBShot3.jpg

CBShot4.jpg

Thanks for your help.
 
nsmutabledictionaries are fine. they inherit

Code:
- (BOOL)writeToURL:(NSURL *)url atomically:(BOOL)atomically;

from nsdictionary. so, to save your dictionary to disk, use

Code:
[myExpenses writeToFile:[@"~/Desktop/Expenses" stringByExpandingTildeInPath] atomically: YES];

to read them in again, use

Code:
NSDictionary myExpenses = [NSDictionary dictionaryWithContentsOfFile:     [@"~/Desktop/Expendes" stringByExpandingTildeInPath]];

how to convert this into a mutable dictionary is left as excercise to the reader. ;)

about the windows... you don't only want to change the size of the *contents* of the window, but of the window itself, right?

so, use

Code:
[myMainWindow setFrame:NSMakeRect(your new rect goes in here) display:YES animate:(YES gives you that nice effect here/NO is fine, too)];

please keep in mind that y = 0 is at the bottom of the screen, so you'll have to do some maths to expand the window to the bottom.

edit: stupid vb code
 
Thanks for the reply. I worked with the window resizing problem all day. I used what you gave me and it animates and everything, but I still have the same problem: it resizes at the top. Here is my code:
Code:
[[sender window] setFrame:NSMakeRect(NSMinX([[sender window] frame]),NSMinY([[sender window] frame]),NSWidth([[sender window] frame]),149) display:YES animate:YES];
To make the rect, I use the minX/minY of the window so that the origin remains the same. The only thing I change is the height(149) to 191. But the window grows upward(the origin is moving up).
 
that's what i meant with "y = 0" is at the bottom. say the origin of your window were 100,100 and the size were 50,50. now, if you resize your window to 50,100, you will have to move the origin to 100,50... does that make sense?
 
I understand what you're saying about y=0 is at the bottom of the screen. I still have a problem though. When the program runs it looks like this:
147.jpg

That is how it should be. When I click the Check radio it goes to this:
148.jpg

The frame size and origin is perfect, but I need the content to stay at the top so that the fields below the enter button show. It should look like this:
149.jpg

TIA
 
Back
Top