01-24-2013 07:33 AM
I'm having a strange behaviour with context menus.
I have two lists in my app with two contextual menus, one menu for each list.
I have some logic to determine if context menu has to be launched or not, and if not, I prevent ContextMenuEvent.OPENING event, so menu is not launched. Fine. But after that, context menu stops working for the other list.
I think something in ContexMenu classes must be left in a bad state after preventDefault on OPENING event.
What will be then the best way to stop opening one context menu and still work for other components?
See the sample...
package
{
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import qnx.fuse.ui.actionbar.ActionBar;
import qnx.fuse.ui.core.Action;
import qnx.fuse.ui.core.ActionBase;
import qnx.fuse.ui.core.ActionSet;
import qnx.fuse.ui.core.TabAction;
import qnx.fuse.ui.events.ContextMenuEvent;
import qnx.fuse.ui.events.DragEvent;
import qnx.fuse.ui.listClasses.List;
import qnx.ui.data.DataProvider;
public class TestPush extends Sprite
{
private var actionBarOverflow:Sprite;
private var content:Sprite = new Sprite();
private var slideX:Number = 0;
public function TestPush()
{
super();
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.addEventListener( Event.RESIZE, function( e:Event ):void
{
actBar.y = stage.stageHeight - actBar.height;
} );
content.addChild( new Bitmap( new BitmapData( stage.stageWidth, stage.stageHeight, false, 0xffffff ) ) );
// support autoOrients
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
var dp:DataProvider=new DataProvider();
dp.addItem({"label":"item1"});
dp.addItem({"label":"item2"});
dp.addItem({"label":"item3"});
dp.addItem({"label":"item4"});
dp.addItem({"label":"item5"});
dp.addItem({"label":"item6"});
dp.addItem({"label":"item7"});
dp.addItem({"label":"item8"});
dp.addItem({"label":"item9"});
dp.addItem({"label":"item10"});
var list:List=new List();
list.dataProvider=dp;
actionBarOverflow = new Sprite();
var actBar:ActionBar=new ActionBar();
actBar.showTabsFirstOnBar(false);
actBar.reserveActionSpace(true);
actBar.backButton = null;
actBar.tabOverflowParent = actionBarOverflow;
actBar.width=stage.stageWidth;
actBar.showTabsFirstOnBar(false);
actBar.addAction(new TabAction("TEST"));
actBar.addAction(new TabAction("TEST2"));
actBar.addAction(new Action("Test1"));
actBar.addAction(new Action("Test2"));
actBar.addAction(new Action("Test3"));
var list2:List=new List();
list2.dataProvider=dp;
addChild(actionBarOverflow);
addChild( content );
content.addChild(list);
content.addChild(list2);
content.addChild(actBar);
actBar.x=0;
actBar.y=stage.stageHeight-actBar.height;
list.width=list2.width=stage.stageWidth;
list.x=list2.x=0;
list.height=(stage.stageHeight-actBar.height)/2;
list2.height=(stage.stageHeight-actBar.height)/2;
list.y=0;
list2.y=list.height;
list.addEventListener(ContextMenuEvent.OPENING, contextOpening);
var actionsForBar:Vector.<ActionBase> = new Vector.<ActionBase>;
actionsForBar.push(new ActionBase("Action 1"));
actionsForBar.push(new ActionBase("Action 2"));
var actionset:ActionSet=new ActionSet(actionsForBar);
var contextactions:Vector.<ActionSet>=new Vector.<ActionSet>();
contextactions.push(actionset);
var actionsForBar2:Vector.<ActionBase> = new Vector.<ActionBase>;
actionsForBar2.push(new ActionBase("Action 3"));
actionsForBar2.push(new ActionBase("Action 4"));
var actionset2:ActionSet=new ActionSet(actionsForBar2);
var contextactions2:Vector.<ActionSet>=new Vector.<ActionSet>();
contextactions2.push(actionset2);
list.contextActions=contextactions;
list2.contextActions=contextactions2;
actBar.addEventListener( DragEvent.DRAG_MOVE, onDragMove );
}
private function contextOpening(e:ContextMenuEvent):void{
trace("CANCEL OPENING");
e.preventDefault();
}
private function onDragMove( event:DragEvent ):void
{
slideX += event.deltaX;
content.x = Math.round( slideX + stage.stageWidth );
}
}
}
Solved! Go to Solution.
01-24-2013 07:42 AM
01-24-2013 07:45 AM
Because depending on the pressed item I want to show it or not ![]()
i.e. a file browser. I want to show a context menu on file but don't want on folders.
01-24-2013 07:56 AM - edited 01-24-2013 07:56 AM
Another way to solve this is to have two different ListItemComponents in your listview - one for files, and the other for folders. You can have a different context menu for each list item type by putting the ActionSet inside the ListItemComponent, rather than in the ListView:
ListView {
listItemComponents: [
ListItemComponent {
type: "file"
contextActions: [
ActionSet {
ActionItem {
// will only show for "file" item
}
}
]
}
ListItemComponent {
type: "folder"
}
}
}
All you need to do now is make sure your datamodel returns the correct itemtype for each item. The itemType() callback function in QML is a good place to start looking
01-24-2013 08:00 AM
01-24-2013 08:01 AM
01-24-2013 11:23 AM
Although strobejb's could be a solution, it implies lots of changes on my code at this moment, but I think I found a good solution.
Instead of dealing with ContextMenu I forget it and override onLongPress method extending the list.
override protected function onLongPress():void{
}
And if I have to display context menu I can do from withing the method with:
showContextMenu()
01-24-2013 11:31 AM
01-24-2013 11:54 AM
I'm pretty sure don't, context actions are asigned to list, not to items, but I think you could have an approach defining ContextActions on the ItemRenderer for each one so as ContextMEnu is launched for the renderer and not for the list.
HAven't tested, but should work.