removeFrameUsingName: doesn't?

  • Hi!

    I'm trying to remove the saved window frame of a window from the
    application preferences. So let's say I have a global:

    NSString *name = @"My_window_name";  // Actually the name I am using
    is UUID so it should be globally unique.

    The NSWindow gets initialized using [window
    setFrameAutosaveName:name]; This works fine and saves/restores the
    window frame.

    Then later on I want to remove the saved frame from the prefs. I
    tried to use

    [NSWindow removeFrameUsingName:name];

    But it does not seem to work. The prefs file still contains the frame
    for the window (key: "NSWindow Frame My_window_name"). (Yes, I made
    sure that the prefs where synchronized and I even quit the app to be
    sure I wasn't seeing any caching effects.)

    Then, thinking that somehow the window might undo my deletion, I tried:

    [window setFrameAutosaveName:@""];
    [NSWindow removeFrameUsingName:name];

    as well as:

    [NSWindow removeFrameUsingName:name];
    [window setFrameAutosaveName:@""];

    But neither of these variants made any difference.

    I can of course delete the saved window frame by doing the following:

    [[NSUserDefaults standardUserDefaults] removeObjectForKey:[NSString
    stringWithFormat:@"NSWindow Frame %@",name]];

    But that relies on knowledge of Cocoa internals which I would rather
    avoid.

    I'm testing this on Mac OS X 10.4.11 (PPC).

    I couldn't find any related comments in the list archives or via
    Google. So, any idea what I'm doing wrong? Is this a bug in Cocoa,
    i.e. does this work for anyone else?

    Thanks!
    Mike
    --
    Mike Fischer        Softwareentwicklung, EDV-Beratung
                                        Schulung, Vertrieb
    Web: <http://homepage.mac.com/mike_fischer/index.html>
    Note:                I read this list in digest mode!
              Send me a private copy for faster responses.
  • OK, nobody answered so I did a further test:

    I created a new Cocoa application project, modified the nib so that
    the Window had an Auto Save Name "xyz" and then added an AppControler
    class with a single IBAction and connected it up. The IBAction looks
    like this:

    - (IBAction)handleDeleteAutosaveFrame:(id)sender
    {
        NSString    *s = [fWindow frameAutosaveName];

        if ([s length] > 0) {
            [fWindow setFrameAutosaveName:@""];
            [NSWindow removeFrameUsingName:s];
        }
    }

    The first time I ran the app I adjusted the window position an size
    and then quit the app. As expected the prefs file contained the
    "NSWindow Frame xyz" key.

    Then I relaunched the app, used the IBAction to remove the Auto Save
    Name and quit the app again. The key was still there! So it's a bug
    in AppKit/Cocoa it seems. NSWindow -removeFrameUsingName: does
    nothing at all AFAICT.

    The same thing happens (doesn't happen) on Leopard 10.5.2 on Intel.
    And again switching the two statements around doesn't make any
    difference.

    I filed a bug: <rdar://5771541>

    Mike

    Am 26.02.2008 um 21:23 schrieb Mike Fischer:

    > Hi!
    >
    > I'm trying to remove the saved window frame of a window from the
    > application preferences. So let's say I have a global:
    >
    > NSString *name = @"My_window_name";  // Actually the name I am
    > using is UUID so it should be globally unique.
    >
    > The NSWindow gets initialized using [window
    > setFrameAutosaveName:name]; This works fine and saves/restores the
    > window frame.
    >
    > Then later on I want to remove the saved frame from the prefs. I
    > tried to use
    >
    > [NSWindow removeFrameUsingName:name];
    >
    > But it does not seem to work. The prefs file still contains the
    > frame for the window (key: "NSWindow Frame My_window_name"). (Yes,
    > I made sure that the prefs where synchronized and I even quit the
    > app to be sure I wasn't seeing any caching effects.)
    >
    > Then, thinking that somehow the window might undo my deletion, I
    > tried:
    >
    > [window setFrameAutosaveName:@""];
    > [NSWindow removeFrameUsingName:name];
    >
    > as well as:
    >
    > [NSWindow removeFrameUsingName:name];
    > [window setFrameAutosaveName:@""];
    >
    > But neither of these variants made any difference.
    >
    >
    > I can of course delete the saved window frame by doing the following:
    >
    > [[NSUserDefaults standardUserDefaults] removeObjectForKey:[NSString
    > stringWithFormat:@"NSWindow Frame %@",name]];
    >
    > But that relies on knowledge of Cocoa internals which I would
    > rather avoid.
    >
    > I'm testing this on Mac OS X 10.4.11 (PPC).
    >
    >
    > I couldn't find any related comments in the list archives or via
    > Google. So, any idea what I'm doing wrong? Is this a bug in Cocoa,
    > i.e. does this work for anyone else?
    >
    >
    > Thanks!
    > Mike
    > --
    > Mike Fischer        Softwareentwicklung, EDV-Beratung
    > Schulung, Vertrieb
    > Web: <http://homepage.mac.com/mike_fischer/index.html>
    > Note:                I read this list in digest mode!
    > Send me a private copy for faster responses.
    >

    --
    Mike Fischer        Softwareentwicklung, EDV-Beratung
                                        Schulung, Vertrieb
    Web: <http://homepage.mac.com/mike_fischer/index.html>
    Note:                I read this list in digest mode!
              Send me a private copy for faster responses.
  • On Feb 28, 2008, at 12:25, Mike Fischer wrote:

    > OK, nobody answered so I did a further test:
    ...
    > Then I relaunched the app, used the IBAction to remove the Auto Save
    > Name and quit the app again. The key was still there! So it's a bug
    > in AppKit/Cocoa it seems. NSWindow -removeFrameUsingName: does
    > nothing at all AFAICT.

    Well this time I got interested enough to go read the NSWindow class
    reference for removeFrameUsingName. It doesn't say that this method is
    supposed to remove the key from the preferences. It *seems* to say
    that it leaves the key but removes the frame data (in the sense of
    setObject: @"" forKey: windowAutosaveName, it looks like, but I'm
    guessing).

    You didn't say whether you saw any non-blank saved frame data
    associated with the key after using removeFrameUsingName.
previous month february 2008 next month
MTWTFSS
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29    
Go to today
MindNode
MindNode offered a free license !