Implementing applicationShouldTerminateWhenLa

Help
mox
2007-02-11
2013-04-25
  • mox
    mox
    2007-02-11

    I want my application to terminate when my "last" window is closed.

    Actually it's a one window application and I don't want it to work in "Document mode" like every applications.

    I'm currently working on a SSH Front End (similar to Putty / SecureCRT) for OS X

    Here is a screenshot of a pre-beta http://www.mox.ca/photos/OSXssh.jpg

    Once I finish the "Connections" window and that everything works I will put it on sourceforge.net.

    If anyone wants to see the source or wants to help me I can be contacted on msn or email at mox@mox.ca

    Thanks!

     
    • mox
      mox
      2007-02-11

      Ok.. looks like I found the answer by myself.. after ~3-4 days of searching.. lol

      1) Open the .pm with your project name.. (ProjectName.pm, not ProjectNameWindowController.pm)
      2) add "applicationShouldTerminateAfterLastWindowClosed" in the properties of your ProjectName class
      3) create the following sub:
      ------
      sub applicationShouldTerminateAfterLastWindowClosed : Selector(applicationShouldTerminateAfterLastWindowClosed:) ArgTypes(@) ReturnTypes(v) {
        my ($self) = @_;
        NSApplication->sharedApplication->terminate($self);
      }
      ------

      Et voila ! :)

       
    • Sherm Pendley
      Sherm Pendley
      2007-03-12

      Ouch. No, that is *not* what this delegate method is for. Like all delegate methods with names like fooShouldBar, the idea here is to give the delegate "veto power" to either allow Bar to proceed, or not. The correct return value (as is clearly stated in the Cocoa docs...) is a BOOL (c), not void (v).

      You return TRUE (i.e. 1 from Perl) if the app should be allowed to terminate, and 0 if not.