How to hide a button on an app with multiple windows? - Objective C OSX - objective-c

I have an application which has a button on the first window, once pressed this button should hide and perform an action, to hide the button i'm using this code:
[self.myButton setHidden:TRUE];
This works fine until I have multiple windows - new instances of this window do not have this button it's hidden by default. However when I create a new window and press the myButton on the first window it doesn't hide the button.
Furthermore if I create a new window and then close that window and press the myButton on the first and now only window it crashes.
It's clear it always seems to target the last window created, how can I make it always target the first window created, or the window the action is actually being sent from?
New windows are simply being created by calling a newDocument from the document controller like so:
[dc newDocument:self];

Most button actions look like this:
- (void)someAction:(NSButton* sender) {}
or
func someAction(sender : NSButton) {}
As you can see, a sender is passed with the action. Now this sender is actually the button you pressed. So you can simply hide this particular button by calling sender.hidden = true;
The sender is automatically added when you use Storyboards or Xibs to add the actions.
If you add the action programmatically, add a colon after the selector (ObjC) or string (Swift). The button instance should be passed to you then.
... action:#selector(someAction:)...
or
... action:"someAction:" ...

Related

Installer pane next button listener

I'm working on an installer plug in which currently looks like this:
Currently I disable the "Continue" button with [self setNextEnabled:NO] until all fields are input. What I would like to be able to do is actually run some code when the next button is clicked. Here I would ping the server, and only actually go to the next pane if I get pong.
How do I have a listener for this button?
My code goes a little like this:
#import "MyInstallerPane.h"
#implementation MyInstallerPane
- (void)didEnterPane:(InstallerSectionDirection)dir{
[self toggleContinueButton];
[self initTempDir];
}
.. + my own functions..
You can override the delegate method
- (BOOL)shouldExitPane:(InstallerSectionDirection)dir;
A subclass should override this method if it needs to prevent the
InstallerPane from exiting. Called to determine if a pane should exit
and allow another pane to be display on screen. Once the InstallerPane
decides it is time to exit, it can call gotoNextPane or
gotoPreviousPane to exit without calling shouldExitPane again.
For example:
- (BOOL)shouldExitPane:(InstallerSectionDirection)dir {
if (!good) {
return NO
}
return YES
}

wxWidgets Closing window from system menu

I am working on wxWidgets, In wxFrame I handled wxEVT_CLOSE event, inside the event handler I called Iconize(). When pressing the close button my window will be minimized it is work correctly. But while clicking quit from my system menu that time also my window is minimizing. But in my scenario I want to close my window from system menu and want to minimize while clicking close button.
This is my handler.
void Frame::OnClose(wxCloseEvent& event)
{
Iconize(true);
}
You can't distinguish between closing the window from the system menu and using the close button at wxWidgets API level. You can, however, do it using platform-specific code. For example, for MSW you can override MSWWindowProc() in your wxFrame-derived class and handle WM_SYSCOMMAND there and explicitly exit the application, instead of just iconizing it, when SC_CLOSE is received.
Just process menu command in other handler and call Destroy directly.
BEGIN_EVENT_TABLE(wxMyFrame,wxFrame)
EVT_MENU(wxMyFrame::idMenuQuit, wxMyFrame::OnMenuClose) // sample for using event table
END_EVENT_TABLE()
void wxMyFrame::OnMenuClose(wxCommandEvent& event)
{
Destroy();
}

Custom context menu XAML for WP8

I try to implement a custom ContextMenu in a LongListSelector.
I'm not using the ContextMenu from Microsoft.Phone.Controls.Toolkit, it's basically the same as in the Rowi App:
(source: hiddenpineapple.com)
Approach 1
My list item toggles a VisualState on hold and an overlay is shown with controls in it.
The problem
I can't find a way to go back to the default state when the user clicks outside of the list item (as in the default ContextMenu).
Approach 2
I've implemented a custom template for the toolkit ContextMenu which looks exactly the same. I had to move its margin top to -itemHeight, as by default it is below the item.
The problem
The problem with this solution is, that it automatically closes itself when opening and I couldn't figure out how to avoid this.
Another problem was that it didn't work well with TiltEffect.IsTiltEnabled from the Toolkit (visual problems).
I need your help
Any suggestions on how to get this working?
Answer
Thanks to Cheese, now I know how to properly close the menu when the user clicks outside.
His suggestion was to get the coordinates of a Tap event on the current page, and check if it's inside the menu. When not, close the menu.
So I added a Tap listener to the page when the menu opens, and removed it when the menu closes. From the page listener I got the event coordinates and could check if it's inside the control which holds the menu (same size and position). I received the position of the control with Point leftUpperPoint = control.TransformToVisual(page).Transform(new Point(0, 0)) and the rightLowerPoint by adding the ActualWidth and ActualHeight.
But then I realized:
Why should I even calculate if the tap is inside the menu? I always want to close the menu when the user taps anywhere on the screen. If it's outside, yes. If it's on a menu button, yes.
Another modification I made was to listen for MouseLeftButtonDown instead of Tap as it also triggers when the user swipes.
So I removed this code and came up with the following:
private void ToggleMenu(object sender, System.Windows.Input.GestureEventArgs e)
{
PhoneApplicationFrame frame = ((PhoneApplicationFrame)Application.Current.RootVisual);
VisualState state = this.States.CurrentState;
if (state == null || state.Name == "DefaultState")
{
frame.MouseLeftButtonDown += MouseDownDelegate;
this.State = "MenuState";
}
else
{
frame.MouseLeftButtonDown -= MouseDownDelegate;
this.State = "DefaultState";
}
}
private void MouseDownDelegate(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
ToggleMenu(sender, null);
}
This works perfectly!
Thanks to Cheese for the hint.
Something like this by #denniscode http://dotnet.dzone.com/articles/rowi-show-tap-menu
Approach 1 problem
The best solution would be:
Get the menus coordinates, when user makes a tap - you check are tap coordinates on menu or not, if not - dissmiss - simple.
Approach 2 problem
I guess you had some button in a corner and when you tapped on it - nothing happened? And when you dissmissed the Tilt all worked. It seems that tilt works faster than a click, so, tilt changes the button coordinates, and device thiks you have missed/or dragged off
You can use what #ScottIsAFool suggested and maybe create another Dependency Property on your TapMenu control of type UIElement named CloseWhenTappedElement and automatically listen for Tap events inside your control once set. For example
<Grid x:Name="TapArea"/>
<TapMenu CloseWhenTappedElement="{Binding ElementName=TapArea"}/>

Dojo emit click event to dojox.mobile.ToolBarButton

Im trying to fire a click event on a tool bar button Dojo 1.8.1.
<div data-dojo-type="dojox.mobile.ToolBarButton" class="backButton" moveTo="cartView" transition="slide">
I have tried
function backClick(){
var backButton = dojo.query(".backButton", dojo.byId(currentView.id))[0];
writeLog("backClick::"+backButton);
if(backButton){
var backDijit = dijit.registry.byId(backButton.id);
writeLog("backDijit::" + backDijit.id);
writeLog("emit Click");
backDijit.emit("click", {bubbles:true});
writeLog("emit mousedown");
backDijit.emit("mousedown",{bubbles:true});
writeLog("emit mouseup");
backDijit.emit("mouseup",{bubbles:true});
writeLog("touchstart");
backDijit.emit("touchstart");
writeLog("touchEnd");
backDijit.emit("touchend");
}else{
//Exit App notification
navigator.app.exitApp();
}
}
mousedown/mouseup combo works on the browser.
But on the device it does not work(Android). What is the event that i have to send to 'click' the button on a device?
It seems that the sequence of events that will activate the toolbar button 'click' on a touch device is touchstart followed by touchend.
I suppose that your example do not work because the synthetic touch events that you are emitting do not contains any data, which fails the different methods that handle it.
Another way to trigger the click handler of the toolbar button would be to call its _onClick method.

Loading UserControl within a Child Window

I have a child window created in silverlight. I need to load a user control within the child window(for a content change in the same child window) on a button click.
How can i acheive this?
Say for Example: If i have a child window with a Header -> Content -> Button.
I just need to change the content part and the button part on click of the button.
I need to change the buttons also since navigation is not possible using the same button click events.
Is it possible to acheive this in Silverlight 4.0 or 5.0?
Here is one way to do it. Create a canvas to hold the content and on button click, add the user control and add it as a child to the canvas. If you want to change the button, rather than changing the button, in the same button click the button content to a different text.
private void Button_Click_1(object sender, RoutedEventArgs e)
{
SilverlightControl1 control1 = new SilverlightControl1();
top.Children.Add(control1);
}
Hope this helps.