Open and close drawer with custom handler

Hi,

I would like to manage the open and closed drawer with a single button in my ASOC interface.
The button is connected to bluebox with handleDrawer_ routine, but something don’t work.
Where I need to connect the myDrawer property?

Also, I have “brain” difficult with the 's terminology (I prefer the other). What I would like to manage is something like that:

on handleDrawer_(sender)
set drawerState to current application’s NSDrawerClosedState
–display dialog drawerState – until here all is OK.
if drawerState is 0 then
– display dialog “Drawer will open”
myDrawer’s |open|()
else
– display dialog “Drawer will closed”
myDrawer’s |close|()
end if
end handleDrawer_

PS: I read the chapter 11 on Shane book but in the Shane example all is managed automatically with two buttons connected to open and close default handlers of bluebox drawer.

Alex

drawerState is an NSInteger – you need to coerce it to an integer:

		if drawerState as integer is 0 then

This is probably the most common mistake apart from typing errors. It takes a while to get into the habit.

Also note that the toggle: method will save you the test; it automatically opens if it’s closed, and closes if it’s open.

Right – less code is good!

Many thanks Shane.
After post I found the link to toggle to bluebox Drawer.
Your book is invaluable value. Without it, is impossible to walking in the Asoc land.
Please write a second and I will buy it !!!

Alex

Got to get more people to buy the existing one first :slight_smile:

Seriously, I’m more likely to expand the book than write another.

This is interesting. I tackled the same problem. Here is my solution. It is essentially the same thing, just a tad sorter:

on checkIfVisible_(sender)
	set x to myDrawer's state as integer
	if x = 0 then
		myDrawer's open_(me)
	else
		myDrawer's close_(me)
	end if
end checkIfVisible_

Iv’e a disclosure button and I try to get the drawer state to change its label from “Open drawer” when drawer is closed and “Close Drawer” on the contrary.

I tried both in #5 goodtime post but with first on handleDrawer_(sender) I get this error:

No result was returned from some part of this expression.

and with second on checkIfVisible_(sender) I get this error:

this class is not key value coding-compliant for the key state.

I’ve a property myDrawer : missing value connected to the drawer in IB

Are you sure your property is connected to the drawer and not the drawer’s view?

Add some log statments to find exactly where the problem is happening.

Hi everybody,

I made even worse in one of my apps: as the disclosure button has a standard behavior, I made one on my window and send the toggle action to the drawer, all in IB.

Not a single line of code.

Regards,

Thanks a lot Shane, you are right, I wrong link it to drawer’ view instead of drawer blue cube.

Just for info, this work:

    
	property myDrawer : missing value -- link to drawer object

	on setDrawerTitle_(sender)
		set x to myDrawer's state as integer
		if x = 0 then
			myDrawer's open_(me)
		else
			myDrawer's close_(me)
		end if
	end setDrawerTitle_

This don’t work:


	property myDrawer : missing value -- link to drawer object

	on setDrawerTitle_(sender)
	set myDrawer to current application's NSDrawerClosedState
		if myDrawer's |state|() as integer is 0 then
			display dialog "Drawer will open"
			myDrawer's |open|()
		else
			display dialog "Drawer will closed"
			myDrawer's |close|()
		end if
	 end setDrawerTitle_

no dialog appear and return with No result was returned from some part of this expression. error.

This doesn’t work because you set the property myDrawer to an enumerated constant (NSDrawerClosedState) which is in fact an integer 0 value. This destroys the connection to the drawer object


on setDrawerTitle_(sender)
		if myDrawer's |state|() is current application's NSDrawerClosedState then
			display dialog "Drawer will open"
			myDrawer's |open|()
			else
			display dialog "Drawer will closed"
			myDrawer's |close|()
		end if
    end setDrawerTitle_