Get window name from sender

Hi,

I have some extra window that can appear as sheet over the main window.
In every of these extra window there are button “OK” that close the window.
For every close I have this routine:

on helpClose:sender
tell current application’s NSApp to stopModal()
pWindowHelp’s orderOut:me – < change only this
pWindowMain’s displayIfNeeded()
end helpClose:

Basically is the same for every window:
Stop Modal
Close the window attached to main as sheet
refresh

The only change is line 3 the line that close the window by it’s name.
How is possible to get from sender the window name and have in this way a unique handler that can be called from various button?

Ame

Browser: Safari 537.74.9
Operating System: Mac OS X (10.8)

Try sender’s |window|().

Hi Shane,

you are simply great. You have always an answer. Thanks again.

I post here two solution. Latest has a shortest form:

on helpClose:sender
set windowRef to sender’s |window|()
tell current application’s NSApp to stopModal()
windowRef’s orderOut:me
pWindowMain’s displayIfNeeded()
end helpClose:

on helpCloseShort:sender
tell current application’s NSApp to stopModal()
sender’s |window|()'s orderOut:me
pWindowMain’s displayIfNeeded()
end helpCloseShort:

Hi,

Using the Myriad helpers class (NSWindow+MyriadHelpers.h and NSWindow+MyriadHelpers.m) of Shane Book the generic handler that can be called from various windows (help, alerts…) attached as sheet to mainWindow and close them become:

on customWindowClose:sender
tell current application’s NSApp to endSheet:(sender’s |window|())
pWindowMain’s displayIfNeeded()
end customWindowClose:

Ame

I have been using Myriad helpers a lot lately and have found that using the following two methods works well for me:


property currentKeyWindow : missing value

-- THIS METHOD IS CALLED WHENEVER A NEW WINDOW/SHEET BECOMES FRONTMOST (ACTIVE)
    on windowDidBecomeKey_(aNotification)
          set currentKeyWindow to (aNotification's object) -- SET VARIABLE TO THE WINDOW OBJECT
    end windowDidBecomeKey_

    -- CALLED BY OTHER METHODS/UI BUTTONS TO CLOSE THE CURRENTLY ACTIVE WINDOW
    on closeCurrentWindow_(sender)
          tell current application's NSApp to endSheet_(currentKeyWindow)
    end closeCurrentWindow_