Who should remove popup, calling app or popup itself? - apache-flex

Here is the scenario...I have an application that has an "Open" button. When you click the open button, a TitleWindow pops up (via the PopUpManager) a dialog that allows you to select a record. In that window, you can either click "Ok" once you've selected a record, or cancel the dialog which should close the window.
What is the best way to handle this, knowing I need to return the record number to the main application? Right now I have the main application opening up the custom TitleWindow. In the TitleWindow, I have an event that fires when the user clicks "Ok" and a record is selected. That's how the main application listens for the recordId. What I'm wondering is if I can do something like this:
private function RecordSelected():void
{
this.selectedRecord = someControl.selectedIndex;
this.dispatchEvent(new Event("RecordSelected"));
PopUpManager.removePopup(this);
}
Will the instance of the TitleWindow stay active until after the event is handled by the main application, or could it be removed before the main application fully handles the event (thus ending with a null reference exception)?
Alternatively, is it better to close the window in the event handler like so:
private function titleWindow_RecordSelected(event:Event)
{
var openDialog:CustomTitleWindow = CustomTitleWindow(e.currentTarget);
this._selectedRecord = openDialog.selectedRecord;
PopUpManager.removePopup(openDialog);
}
I'm also wondering if sending the selection out in an event is the best way to do this also. Any insight would be appreciated. Thanks in advance.

What is the best way to handle this,
knowing I need to return the record
number to the main application?
Best is always subjective, but I usually handle closing of the window in the window component; and then dispatch an event with appropriate data (In this case Record No) back to the application. It sounds like your 90% there. Just instead of dispatching an event Event, create a custom Event class with your recordID. Then it won't matter if the pop up is still in memory or not when you need to use the record ID.

Related

How to catch all and only button release events in Qt?

My team is developing an UI for an apparatus with touch screen and we would like it to emit a sound (from a buzzer) each time the user correctly presses a button (so using the release event). Notice that I don't want to play the sound after each click on the interface, but only when the click is over a button.
We use many types of button, sometimes QPushButton and most of the times customized buttons derived from QAbstractButton. In most cases these buttons get an objectName.
So I supposed in order to do that, I would have to catch the MouseButtonRelease event and since I'm already working with a subclass of QApplication to handle excetions, I decided to do this in the notify function.
I tried, then, some methods to recognized when the MouseButtonRelease was related to a button but none of them were successfull. The best one, verifying the receiver's objectName was still not good enought not only because not all buttons had an objectName (which, of course, can be handled), but specially because not always the event was caught for buttons with names set. In other words, sometimes I would click in a button and it recognizes the event and sometimes I would click in the same button and the event is not recognized.
I did some research and another method I found was to set an event filter in the MainWindow, but not all widgets have the MainWindow as their parent which means I would have to Ctrl+c / Ctrl+V the same code time after time when I obviously want something more localized (i.e. in only one spot).
So why it happens that the notify not always handles the events? And how could I do this? Any suggestions are appreciated specially one that is less heavier then handling the events globally.
As info, the other two ways I tried to catch the events with similar or even worst results inside notify were with receiver->inherits("...") and qobject_cast< QAbstractButton* >(receiver).

MFC: Is there any way to active button without On_Bn_Clicked() event?

I have a task that are hiding a dialog but I need to click the button belong to this dialog to
implement some function before go to the next dialog.
But when I hide this dialog, I can't click the button. Is there any way to implement this button without On_Bn_Clicked() event? I mean that when the dialog is called, the button is also activated.
Thank for the helps.
When you click the button a few Windows messages are sent. The important ones are WM_LBUTTONDOWN, WM_LBUTTONUP which tells the button you clicked the left mouse button down and up. Then some time later a WM_COMMAND message is sent to the parent window to handle the button click. At that point your ON_COMMAND() MFC handler is called. MFC abstracts this all away from you for the most part.
You could go and simulate this using the Win32 SendMessage API but if the message pump is blocking your button may not be clicked when you think it will. If you want a quick answer to your question then this is an approach to "get it done". It would look something like this:
SendMessage(button.GetSafeHwnd(), WM_LBUTTONDOWN, MK_LBUTTON, 0);
SendMessage(button.GetSafeHwnd(), WM_LBUTTONUP, MK_LBUTTON, 0);
I think a more sensible approach is to take the code that is in this On_Bn_Clicked() event handler and simply move it to a reusable function. This way you can call the code in On_Bn_Clicked() from anywhere in your program.
Just call On_Bn_Clicked() directly from your code. There is no harm in doing so. (I suppose you don't want to actually click the hidden button with the mouse...)

Detect right clicks on a RichEditableText

I am currently implementing squiggly in a flex application to enable spell checking. Due to certain requirements, I can not use SquigglyUI to hook onto my spark RichEditableText. I have successfully used com.adobe.linguistics.utils.TextTokenizer to tokenize and highlight mispelt words.
I would like to be able to let the user rightclick on a mispelled word and show a list of suggestions in the context menu using getSuggestions.
I have tried to attach a listener to my RichEditableText:
richtexteditor.addEventListener("rightClick", showSuggestions);
And this is my event handler:
private function showSuggestions(event:MouseEvent):void{
trace('hi there');
}
The problem is when debugging the application, I never get the trace in my console as the rightclick event is never dispatched. In addition, I need to detect the word the user has right clicked on. How can I go about doing this and how can I detect right clicks?
Cheers
All I had to do was add an event handler to the contextmenu property of the richeditable text:
richtexteditor.contextMenu.addEventListener(ContextMenuEvent.MENU_SELECT, doSomething);
r.addEventListener(MouseEvent.RIGHT_CLICK, listener)
This will listen for the right-click of the mouse (Flex4.5)

QTableView: Best way to change activation-trigger to double-click

In my application, I have one tableview of items, and a side-panel "preview":ing the latest selected item.
I want clicking on an item to change the selection, and double-clicking to cause a "run"-action to be performed. More specifically, I want the "run"-action (including key-navigation and pressing enter) to be bound to the "activation" of the item in the table-row.
My problem is; single-clicks does not only change the selection, but fires the "activated" signal on the item. I would like to tweak it such that:
Navigation Keys, Single Mouse Click: Selection-change, update preview-panel
Enter Key, Double Mouse Click: Activate/run/open action triggered.
Is there a nice clean way to do it, or are overriding the onclick/doubleclick events my best option? Or is there some other tabular list-widget better suiting my needs?
I would connect the slot for the preview action to the currentChanged() signal of the table view's selectionModel(). This covers single clicks and key navigation.
Then there's two options for the double clicks and Enter key presses:
Subclass your tableview, override doubleClickEvent() and keyPressEvent() and fire your custom signal in there, with maybe the model index or something else as an argument. Then just connect your run method to your own signal as you have full control over when it is fired.
If you don't want to subclass, you can use the installEventFilter() mechanism.
Either I'm getting your approach wrong or I'm too tired, but if you want to trigger a run event you should avoid the activated signal completely. Set the signal slot mechanism so that your double click and Enter key press event trigger your run() function, and then the single click/nav buttons should trigger the 'activated' slot which will return your index in the tableview.
I'm pretty certain Qt wants you to be explicit about which signal points to which slot or it'll ignore it or point to a default.

Show alert if moving on without saving in Flex?

Functionnaly :
On one of my components of my application, I have an editing/lock system. When a user starts editing, he locks the file so other users cannot edit it.
Problem scenario : When the user activates "edition mode" and leaves screen, I would like to show a alert with two options : save changes, or discard changes.
There are different ways to exit screen :
There is a List on the left side containing other possible editabel data. A click changes the data in my component.
There is a menubar on top leading to other screens.
The edition component is embedded in a Tab navigator. When changing tabs, the alert has to show.
Closing browser.
Do I have to catch all of these events and plug at all those places?
Is there any kind of focusout mecanism?
The answer to the first question is: YES.
You need to watch all possible exit events that could harm the currently edited data.
Well, the problem is now how to manage this properly. Using an MVC framework you would trigger the appropriate commands from your components:
CHANGE_LIST_ITEM (new item)
CHANGE_TAB (new tab)
CHANGE_SCREEN (new screen)
Each command then checks if the currently edited tab has been saved or not. If not, it displays the Alert. Else, if there are no changes, it allows the list, the screen chooser and the tab bar to continue.
So your components (list, screens, tabs) need to implement some kind of rollback or preventDefault mechanism. Generally, changing their state must be allowed by a central validator (in MVC the command).
In the case of the list: I would suggest that the list is not selectable by mouse click but only programmatically. You set a listener on the list item click event. If the command allows setting of a new item it will notify the list. In MVC usually by sending an async message that gets received by the list's mediator. [[And even more correct: The command would set some model properties (e.g. currentListItem) and the model than sends an async message.]]
Edit: For the browser close event, you need to call a JavaScript expert.

Resources