Detect right clicks on a RichEditableText - apache-flex

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)

Related

FLEX- disable the cursor click event on busyCursor

I am using a flex2 in a web application. I have added a busy-cursor in my application successful but I need to disable the cursor click event as long as the cursor animates.
Can I do this? How can I do it?
I am new to flex. Please provide me a sample code.
Thanks in advance.
Not that I know of off the top of my head. But you can always remove the "click" listener to the components on the page.
E.g.,
myComponent.removeEventListener(MouseEvent.CLICK, onMouseClickEventDoThis);
It's a pain though, since you would have to do this for every visual component.
What I've done in the past, is just make the component.enable = false. That way, it greys out and doesn't listen to any events.
myComponent.enable = false;
Just remember to re-enable it when you're done with the busy cursor.
myComponent.enable = true;

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.

Receive events when QCustomContextMenu is open

I have an issue capturing the key and mouse events. I have a class which inherits QGLWidget. I invoke a context menu QCustomContextMenu by setting the context menu policy of the widget. As the context menu is open, I am unable to capture the mouse and key events. I will need the events to be captured even when the context menu is open.
Thanks!
i believe you have heard about the installEventFilter.
you have to install the event filter for the object you want events to be received (e.g Contextmenu).
install event filter, and create event filter method to handle event in a way you want.

Who should remove popup, calling app or popup itself?

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.

Resources