I have two drawers and two buttons assigned to the same. if i click on one button then drawer opens and if i click on second button then that drawer open under the first drawer, so its not visible. i want to close current open drawer and then open new drawer.
i have tried following:
on Push_(sender)
set currentDrawer to curent application’s NSDrawer -----assigning current open drawer to currentDrawer
set drawerState to current application’s NSDrawerOpenState ----assigning value of currently open drawer
if drawerState as integer is 2 then
currentDrawer’s |close|() ----closing current open drawer
myDrawer’s |open| () --myDrawer linked to drawer to be opened.
end if
end Push_
but its not working, it says “unrecognised selector sent to class”
This line doesn’t do what you think it’s doing – all that does is set the variable currentDrawer to the class NSDrawer, not to your current drawer. You need to have IBOutlets for your 2 drawers, say drawer1 and drawer2. Then in the action methods for your buttons send close to one and open to the other:
on openDrawer1_(sender)
drawer2's |close|()
drawer1's |open|()
end openDrawer1_
on openDrawer2_(sender)
drawer1's |close|()
drawer2's |open|()
end openDrawer2_
but i have six buttons on the window and it opens six different drawers. these drawers contains different buttons. so user can open any drawer according to his choice. therefore, is there any method to close the currently opened drawer and then open new drawer.
define a instance variable currentOpenedDrawer (or whatever name you like).
Every time a drawer opens, assign the object reference to this instance variable.
pseudo code:
on openDrawer(theDrawer)
if currentOpenedDrawer is not nil and currentOpenedDrawer is open then close currentOpenedDrawer
open theDrawer
set currentOpenedDrawer to theDrawer
end
it’s unlikely because (a) drawers are discouraged these days, and (b) the idea of having more than one, let alone six, would probably give someone in Cupertino apoplexy…
It would be a good idea for you to describe what you are trying to do with all these drawers. The latest Apple Human Interface Guidelines say:
Drawers are rarely used in modern Mac OS X apps. As much as possible, redesign your UI to avoid using drawers; if you’re creating a new app, avoid adding a drawer to the design. Typically, a drawer contains frequently accessed controls that don’t need to be visible at all times.
Certainly, you shouldn’t have 6 drawers for “frequently accessed controls”.