1. #1
    Sencha User
    Join Date
    Jul 2012
    Posts
    55
    Vote Rating
    0
    srxx123 is on a distinguished road

      0  

    Default Where to place contextmenu?

    Where to place contextmenu?


    Hi,

    I have a tree panel which shall show a context menu. When I place the menu as child of the tree panel Ext.getCmp or this.getComponent does not find the menu. Is this a bug?
    Thank you

  2. #2
    Sencha User
    Join Date
    May 2010
    Location
    Las Vegas, NV
    Posts
    133
    Vote Rating
    2
    billtricarico is on a distinguished road

      0  

    Default


    The approach I have used is to build a context menu on the fly and make it show at the point where the mouse was clicked. In your itemcontextmenu event, add some code like this:

    Code:
    e.stopEvent();
    
    var ctxMenu = new Ext.menu.Menu({
        items:
        [
        {
            itemId : 'newSomething',
            handler : this.onNewSomething
        },
        {
            itemId : 'editSomething',
            handler : this.onEditSomething
        },
        {
            itemId : 'deleteSomething',
            handler : this.onDeleteSomething
        }
            
        ]
    });
    
    
    var newSomethingItem = ctxMenu.getComponent('newSomething');
    var editSomethingItem = ctxMenu.getComponent('editSomething');
    var deleteSomethingItem = ctxMenu.getComponent('closeSomething');
    
    
    newSomethingItem.setText('New Something...');
    editSomethingItem.setText('Edit Something...');
    deleteSomethingItem.setText('Delete Something...');
    
    
    ctxMenu.showAt(e.getXY());
    Then define those functions elsewhere in your controller:

    Code:
    onNewSomething:function() { ... }
    onEditSomething:function() { ... }
    onDeleteSomething:function() { ... }

  3. #3
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,080
    Vote Rating
    113
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    I'd recommend creating a top level menu as a subclass and then using it as proposed by billtricarico above.

    For example drag out a Menu, put some menu items in it...

    then put a subscription to the contextnode event and do something like:
    Code:
    e.stopEvent();
    if (!this.menu) {
       this.menu = Ext.create('MyApp.view.MyMenu');
    }
    this.menu.showAt(e.getXY());
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  4. #4
    Sencha User
    Join Date
    Jul 2012
    Posts
    55
    Vote Rating
    0
    srxx123 is on a distinguished road

      0  

    Default


    OK; this works of course. But I want to create the view completely with SA not by code. I have placed it now as top level component and marked it as floating. This works. But it is not very intuitive - the contextmenu should be placeable as child of the component where it is used. Why can't I do this?

  5. #5
    Sencha User
    Join Date
    Jul 2012
    Posts
    55
    Vote Rating
    0
    srxx123 is on a distinguished road

      0  

    Default


    Quote Originally Posted by aconran View Post
    I'd recommend creating a top level menu as a subclass
    As subclass? How do I do this with SA? Just a new view?

  6. #6
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,080
    Vote Rating
    113
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Quote Originally Posted by srxx123 View Post
    OK; this works of course. But I want to create the view completely with SA not by code. I have placed it now as top level component and marked it as floating. This works. But it is not very intuitive - the contextmenu should be placeable as child of the component where it is used. Why can't I do this?
    We have yet to add any convenience mechanism for marking something as a contextmenu. A lot of times you will want additional custom code, for example conditionally showing a different menu based off of the node clicked on, etc

    We are working on making Architect further from the code so that you can do more and more without touching the code.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

  7. #7
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    9,080
    Vote Rating
    113
    aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold aconran is a splendid one to behold

      0  

    Default


    Quote Originally Posted by srxx123 View Post
    As subclass? How do I do this with SA? Just a new view?
    Yes, every top level instance is a subclass in Sencha Architect.
    Aaron Conran
    @aconran
    Sencha Architect Development Team

Thread Participants: 2