0

Is there a way to define a window as unique ?
What I mean exactly is: when the window is already open, I want it to get focus, instead of opening it again.

For now my menu click event just does:

onMenuItemClick: function(){
    Ext.create('Mb.view.UniqueWindow').show()
},
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121

2 Answers2

2

Give it a unique id, then verify if it already exists before creating it, otherwise just show it, something like

function onMenuItemClick() {
var wnd = Ext.getCmp('myUniqueWindow');

if (!wnd) {
    wnd = Ext.create('Ext.window.Window', {
        id: 'myUniqueWindow',
        title: 'Unique Window',
        height: 200,
        width: 400,
        layout: 'fit',
        closeAction: 'hide', // This is really important otherwise closing it will destroy the window!
        items: { // Let's put an empty grid in just to illustrate fit layout
            xtype: 'grid',
            border: false,
            columns: [{
                header: 'Hello World'
            }], // One header just for show. There's no data,
            store: Ext.create('Ext.data.ArrayStore', {}) // A dummy empty data store
        }
    });
} else {
    wnd.getEl().highlight()
}

wnd.show();

}

You can see a working sample here

overlordhammer
  • 1,303
  • 11
  • 17
1

Save a reference to it:

if (!MyApp.someWin) {
    MyApp.someWin = new Ext.window.Window();
}
MyApp.someWin.show();
Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66