Custom "undo" for Webview - objective-c

OK, here's the situation. I have:
A Webview
Lots of NSTextFields
Other unrelated controls
Normally, the Edit > Undo menu item links to First Responder's undo: action. And everything works fine + you can even "undo" while typing in an NSTextField.
Now, what if I want to handle this "undo" action, in a different way, only for my WebView.
I've been thinking of two approaches:
Link the "Undo" item to a custom action and check who is the First Responder. If it's the Webview, then do what needs to be done. Else, "pass" the event to the control. (However, when attempting a [FIRST_RESPONDER performSelector:#selector(undo:)], first it doesn't seem to recognize the selector and last but not least nothing happens.)
Link the "Undo" to the first responder's undo:(as usual), subclass the Webview and add a custom - (void)undo:(id)sender action. In that case though, when the webview is active, the "Undo" item is grayed-out, so I can't do anything whatsoever, not even check whether the custom method would be called.
Suggestions? How would you go about that?
What am I missing?

I think this is the answer: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebEditingDelegate_Protocol/
Also reference this: Removing undo actions for a WebView's NSUndoManager

Related

How to get currently active UIEvent?

Background
I have a custom UIWindow implementation that posts a notification in the sendEvent method. Then I have a custom view that, once added to the window hierarchy, removes itself from superview as soon as the mentioned notification is posted (i.e. tapping anywhere, in this view or not, removes the view). Finally, I have a button that causes this custom view to be added to the view hierarchy. Now the problem is that when I tap this button, the view gets added to the view hierarchy, BUT, the event that was caused by this tap reaches my custom UIWindow sendEvent method AFTER the custom view is added, thus resulting in the custom view being removed immediately after it has been added.
Question
I want to somehow access whatever UIEvent is currently active. Is this possible to do, and if yes, then how?
I solved this by listening for the notification in order to track the most recent UIEvent (I provided the UIEvent in the userInfo). Then, when receiving the notification again, I made sure that it is not the same event as the one that occured just before the custom view appeared (if it is, I skip the removal of the custom view).
While this is an answer to my question, the solution to the underlaying problem that #matt proposed in an answer to the following SO question turned out to be much better: How can I know when any of the objects on screen were tapped?

UIActionSheet - add disabled button

Is there a way to add a disabled (non-clickable, greyed out) button to a UIActionSheet?
All I see is "addButtonWithTitle" which does not supply any properties to work with.
I believe there is no way to add disabled button in a UIActionSheet. From the class reference:
Use the UIActionSheet class to present the user with a set of
alternatives for how to proceed with a given task. You can also use
action sheets to prompt the user to confirm a potentially dangerous
action. The action sheet contains an optional title and one or more
buttons, each of which corresponds to an action to take.
If the button is disabled, it should not be added into the UIActionSheet in the first place since it is not an alternative on how to proceed with a given task.
UIActionSheet's interface doesn't really give you much control over appearance of the the whole view or the buttons.
You can use some other libraries. If you can't find one that gives such control, it would be simple to you to add that functionality. For example JLActionSheet or RDActionSheet.
You can also, try to retrieve the subviews of UIActionSheet by traversing the view stack recursively. self.view.subviews or by [[UIApplication sharedApplication].windows[0].subviews] "try both, I don't know which one is the right one". You can find the views using introspection, and find the button you want to disable.

Is there any way to highlight the status bar item programmatically?

I'd like to perform the following:
when I click on the status bar item (NSStatusItem) I want to highlight it (no menu) indefinitely and when the application loses focus I want to stop highlighting it.
Is there any way of doing this? I can't find it, tbh.
You can probably do this with a custom view that sends the status item a drawStatusBarBackgroundInRect:withHighlight: message.
I doubt there's any way to do it without a custom view, since, as I mentioned in my comment on the question, keeping the item highlighted when the user doesn't have the mouse down on it looks bad.
Old question, but I think it is worth adding this alternative answer.
This will not automatically un-highlight when the application loses focus, but this allows you to highlight without using a custom view (as the other answer requires):
NSStatusItem *statusItem = [self getStatusItem];
[statusItem.button setHighlighted:YES];
You can unhighlight it manually using the same method:
[statusItem.button setHighlighted:NO];
Note I got this answer from a similar question here.

Take an action when user switches tabs on an NSTabView

I have an application that contains an NSTabView. Whenever the user changes tabs, I need to run an operation. How can I do that?
I'm not entirely sure from your question, but I think you're looking for the one of the NSTabViewDelegate methods tabView:willSelectTabViewItem: or tabView:didSelectTabViewItem:. These methods will be called on the tab view's delegate when it changes tab view items.

Delay navigationController to pop detailView of UITableView

Im looking for some help regarding to put a save like confirmation if some changes where made to a UITextField and UISegmentedControl.
Can I prevent the UINavigationController from pop the view? And then pop based on buttons in a AlertView?
I use the UITextField and UISegmented control to POST data to a webservice.
I perhaps need to use a modalView for this? but wanted first to see if someone have another idea, because I would like to keep navigation clicks down if possible.
Any suggestions for this?
Thanks,
Why not just using a UIAlertView?
EDIT: On second thought, and re-reading your question + comment, I would recommend to use a Modal View with classics OK/Cancel buttons + a UIAlertView(s) for confirmation(s). (UIAlertView "poping" on OK/Cancel is easy to do via UIAlertViewDelegate)
That's what Modal views are for, block UI until some user action has been completed. Like a form. This is how I do all my forms, and how Apple does (just look at the create mail screen for an example, or any form of iOS apps)
Adding a "Magical" action requiring user interaction on the back button of a navigation controller is bad in terms of user experience, if you hit back, you expect the view to pop, nothing else. I would then be surprised if Apple SDK even allows to cancel that event...
You can do what you would like without the need of a modal view.
First, you can use your text field's UITextFieldDelegate to set a flag in your controller when the field content is modified. You can reset this flag when the data is sent out.
Then you could override your UIViewContorller's viewWillDisappear to show an alert to the user in case new data have not been posted at the moment the view is going to disappear and give him the possibility of sending it to the server. This method will be called when you move to a different controller in your navigation UI, and you will not have a chance to "reject" the operation.