2

为桌面快捷方式设置工具提示的最佳方法是什么?

在我的 getDesktopConfig() 中,我创建了一个包含图标Cls、模块、名称字段的快捷方式数据数组。下面是向数组添加用户模块快捷方式,然后将数组设置为快捷方式数据存储的数据属性的示例,该属性用于创建桌面快捷方式:

Ext.define("MyDesktop.App", {
extend: "Ext.ux.desktop.App",

....

getDesktopConfig:            function () {
    var b = this;
    var a = b.callParent();

    .....

    shortcut_data.push({
            iconCls:        "users-shortcut",
            module:         "users-module-window",
            name:           "Users"
        });

    ......

    return Ext.apply(a,{
        contextMenuItems:    [{
            text:           "Dashboards",
            handler:         b.onDashboards,
            scope:           b
        }],
        shortcuts:           Ext.create("Ext.data.Store",{
            model:          "Ext.ux.desktop.ShortcutModel",
            data:            shortcut_data
        }),
        wallpaper:          "/assets/MyApp_Wallpaper.jpg",
        wallpaperStretch:    false
    })
})
},
.....
4

2 回答 2

1

为您的工具提示添加一个字段到 Ext.ux.desktop.ShortcutModel。在这里,我将其命名为 qtipText。Ext.ux.desktop.ShortcutModel 显示现在看起来像这样:

Ext.define('Ext.ux.desktop.ShortcutModel', {
    extend: 'Ext.data.Model',
    fields: [
       { name: 'name' },
       { name: 'iconCls' },
       { name: 'module' },
       { name: 'qtipText' }
    ]
}); 

现在,当您定义快捷方式时,为工具提示添加此字段的值:

shortcut_data.push({
            iconCls:        "users-shortcut",
            module:         "users-module-window",
            name:           "Users",
            qtipText:       "Open Users Window"
        });

在 Ext.ux.desktop.Desktop 的 initComponent 方法中,您会看到为快捷方式视图设置了 itemclick 事件的监听器。只需为 itemmouseenter 事件添加另一个侦听器:

me.shortcutsView.on('itemmouseenter', me.onShortcutItemMouseEnter, me);

定义处理程序如下:

onShortcutItemMouseEnter: function (dataView, record) {
    if(!dataView.tip)
         dataView.tip = Ext.create('Ext.tip.ToolTip', {
          target: dataView.el,
          delegate: dataView.itemSelector,                            
          trackMouse: true,
          html: record.get('qtipText')
      });
    else
      dataView.tip.update(record.get('qtipText'));
},

dataView.tip 第一次不存在,我们为此视图创建了一个工具提示。稍后,我们只是根据记录更新提示文本(对应于鼠标移过的快捷方式)。

于 2013-10-29T11:43:57.620 回答
0

假设快捷方式是由按钮衍生生成的,我会使用 tooltip:'some text' config for the shortcut_data 。

于 2011-12-15T00:33:49.927 回答