81 lines
2.0 KiB
JavaScript
81 lines
2.0 KiB
JavaScript
|
|
//这个函数在整个wps加载项中是第一个执行的
|
|
function OnAddinLoad(ribbonUI) {
|
|
if (typeof (window.Application.ribbonUI) != "object") {
|
|
window.Application.ribbonUI = ribbonUI
|
|
}
|
|
|
|
if (typeof (window.Application.Enum) != "object") { // 如果没有内置枚举值
|
|
window.Application.Enum = WPS_Enum
|
|
}
|
|
|
|
window.Application.PluginStorage.setItem("EnableFlag", false) //往PluginStorage中设置一个标记,用于控制两个按钮的置灰
|
|
window.Application.PluginStorage.setItem("ApiEventFlag", false) //往PluginStorage中设置一个标记,用于控制ApiEvent的按钮label
|
|
return true
|
|
}
|
|
|
|
var WebNotifycount = 0;
|
|
|
|
function OnAction(control) {
|
|
const eleId = control.Id
|
|
switch (eleId) {
|
|
case "btnShowMsg":
|
|
{
|
|
const doc = window.Application.ActiveDocument
|
|
if (!doc) {
|
|
alert("当前没有打开任何文档")
|
|
return
|
|
}
|
|
alert(doc.Name)
|
|
}
|
|
break;
|
|
default:
|
|
break
|
|
}
|
|
return true
|
|
}
|
|
|
|
function GetImage(control) {
|
|
const eleId = control.Id
|
|
switch (eleId) {
|
|
case "btnShowMsg":
|
|
return "images/1.svg"
|
|
default:
|
|
;
|
|
}
|
|
return "images/newFromTemp.svg"
|
|
}
|
|
|
|
function OnGetEnabled(control) {
|
|
const eleId = control.Id
|
|
switch (eleId) {
|
|
case "btnShowMsg":
|
|
return true
|
|
break
|
|
default:
|
|
break
|
|
}
|
|
return true
|
|
}
|
|
|
|
function OnGetVisible(control) {
|
|
return true
|
|
}
|
|
|
|
function OnGetLabel(control) {
|
|
const eleId = control.Id
|
|
switch (eleId) {
|
|
case "btnIsEnbable":
|
|
{
|
|
let bFlag = window.Application.PluginStorage.getItem("EnableFlag")
|
|
return bFlag ? "按钮Disable" : "按钮Enable"
|
|
break
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
function OnNewDocumentApiEvent(doc) {
|
|
alert("新建文件事件响应,取文件名: " + doc.Name)
|
|
}
|