home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / sys / next / programm / 6007 < prev    next >
Encoding:
Internet Message Format  |  1992-09-07  |  1.9 KB

  1. Path: sparky!uunet!rosie!NeXT.com
  2. From: sam_s@NeXT.com (Sam Streeper)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: How to hide on auto-launch?
  5. Message-ID: <4931@rosie.NeXT.COM>
  6. Date: 5 Sep 92 16:17:03 GMT
  7. References: <1992Sep4.174050.5261@jarvis.csri.toronto.edu>
  8. Sender: news@NeXT.COM
  9. Reply-To: sam_s@NeXT.com
  10. Lines: 54
  11.  
  12. Anees Munshi writes:
  13. > I'm trying to implement something like a hide-on-auto-launch
  14. > feature, so I need to detect if the application was
  15. > auto-launched by the Workspace. 
  16. > I'd appreciate any pointers on this one.
  17.  
  18. Here's the code I use to do this.  It could be argued that the proper
  19. app architecture has you deferring the creation of any UI elements
  20. (like loading a nib file) until the app gets unhidden.  However, if you're
  21. lazy, you might keep app state only in the UI and not in other variables,
  22. and thus you are dependent upon the existence of the UI and must create it
  23. in order to initialize your app.
  24.  
  25. - appDidInit:sender
  26. {
  27.     const char *autoLaunch;
  28.     
  29.     autoLaunch = NXGetDefaultValue([NXApp appName], "NXAutoLaunch");
  30.     if (strcmp(autoLaunch,"YES"))
  31.     {
  32.         [myWindow makeKeyAndOrderFront:self];
  33.         windowHasBeenDisplayed = YES;
  34.     }
  35.     else [NXApp hide:self];
  36.     
  37.     return self;
  38. }
  39.  
  40. - appDidUnhide:sender
  41. {
  42.     if (!windowHasBeenDisplayed)
  43.     {
  44.         [myWindow makeKeyAndOrderFront:self];
  45.         windowHasBeenDisplayed = YES;
  46.     }
  47.     return self;
  48. }
  49.  
  50.  
  51. Here I should probably note that I have seen a NeXT FAQ that says that sending  
  52. a "hide:" message from within "appDidInit:" doesn't work (although it works  
  53. fine for me) and that several NeXT apps have been doing this all along.
  54.  
  55. Note too that if you do this, you should probably make your main nib
  56. display no windows when it gets loaded (do this manually with  
  57. "makeKeyAndOrderFront") because otherwise they will flash when they
  58. get hidden.
  59.  
  60. -sam
  61.  
  62.  
  63. --
  64. Opinions expressed herein are not those of my employer.  They're not even
  65. mine.  They're probably wrong besides.  How did they get in here, anyway?
  66.