@@ -17,6 +17,7 @@ import { Root, createRoot } from "react-dom/client";
17
17
18
18
import { initLocale , getLocaleID } from "../utils/locale" ;
19
19
import { getPrefGlobalName } from "../utils/prefs" ;
20
+ import { MenuitemOptions } from "zotero-plugin-toolkit/dist/managers/menu" ;
20
21
21
22
const TRANSLATORS_PATH = `chrome://${ config . addonRef } /content/translators` ;
22
23
const TRANSLATOR_LABELS = [
@@ -1084,47 +1085,24 @@ class ZoteroOverlay {
1084
1085
// /******************************************/
1085
1086
// // Create XUL for Zotero menu elements
1086
1087
zoteroPopup ( menuName : MenuSelectionType , doc : Document ) {
1087
- const ns =
1088
- "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" ;
1089
- const zoteroMenu = doc . getElementById ( `zotero-${ menuName } menu` ) ;
1090
- if ( zoteroMenu === null ) {
1091
- // Don't do anything if elements not loaded yet
1092
- return ;
1093
- }
1094
-
1095
- const wikiciteSeparator = doc . createElementNS ( ns , "menuseparator" ) ;
1096
- const wikiciteSeparatorID = `wikicite-${ menuName } submenu-separator` ;
1097
- wikiciteSeparator . setAttribute ( "id" , wikiciteSeparatorID ) ;
1098
- zoteroMenu . appendChild ( wikiciteSeparator ) ;
1099
- WikiciteChrome . registerXUL ( wikiciteSeparatorID , doc ) ;
1100
-
1101
1088
// Wikicite submenu
1102
- const wikiciteSubmenu = doc . createElementNS ( ns , "menu" ) ;
1103
- const wikiciteSubmenuID = `wikicite-${ menuName } submenu` ;
1104
- wikiciteSubmenu . setAttribute ( "id" , wikiciteSubmenuID ) ;
1105
- wikiciteSubmenu . setAttribute (
1106
- "label" ,
1107
- Wikicite . getString ( `wikicite.submenu.label` ) ,
1108
- ) ;
1109
- zoteroMenu . appendChild ( wikiciteSubmenu ) ;
1110
- WikiciteChrome . registerXUL ( wikiciteSubmenuID , doc ) ;
1111
-
1112
- // Wikicite submenu popup
1113
- const wikiciteSubmenuPopup = doc . createElementNS ( ns , "menupopup" ) ;
1114
- wikiciteSubmenuPopup . setAttribute (
1115
- "id" ,
1116
- `wikicite-${ menuName } submenu-popup` ,
1117
- ) ;
1118
- wikiciteSubmenu . appendChild ( wikiciteSubmenuPopup ) ;
1089
+ ztoolkit . Menu . register ( menuName , {
1090
+ tag : "menuseparator" ,
1091
+ id : `wikicite-${ menuName } submenu-separator` ,
1092
+ } ) ;
1119
1093
1120
- this . createMenuItems (
1094
+ const menuItems = this . createMenuItems (
1121
1095
menuName ,
1122
- wikiciteSubmenuPopup ,
1123
1096
`wikicite-${ menuName } submenu-` ,
1124
- false ,
1125
- doc ,
1126
1097
) ;
1127
1098
1099
+ ztoolkit . Menu . register ( menuName , {
1100
+ tag : "menu" ,
1101
+ id : `wikicite-${ menuName } submenu` ,
1102
+ label : Wikicite . getString ( `wikicite.submenu.label` ) ,
1103
+ children : menuItems ,
1104
+ } ) ;
1105
+
1128
1106
this . refreshZoteroPopup ( menuName , doc ) ;
1129
1107
}
1130
1108
@@ -1176,11 +1154,8 @@ class ZoteroOverlay {
1176
1154
// Create Zotero item menu items as children of menuPopup
1177
1155
createMenuItems (
1178
1156
menuName : MenuSelectionType ,
1179
- menuPopup : Element ,
1180
1157
IDPrefix : string ,
1181
- elementsAreRoot : boolean ,
1182
- doc : Document ,
1183
- ) {
1158
+ ) : MenuitemOptions [ ] {
1184
1159
const menuFunctions : Map <
1185
1160
MenuFunction ,
1186
1161
( menuName : MenuSelectionType ) => void
@@ -1193,6 +1168,8 @@ class ZoteroOverlay {
1193
1168
[ "addAsCitations" , ( ) => this . addAsCitations ( menuName ) ] ,
1194
1169
[ "localCitationNetwork" , ( ) => this . localCitationNetwork ( menuName ) ] ,
1195
1170
] ) ;
1171
+
1172
+ const options : MenuitemOptions [ ] = [ ] ;
1196
1173
for ( const [ functionName , func ] of menuFunctions ) {
1197
1174
if (
1198
1175
menuName === "collection" &&
@@ -1208,13 +1185,10 @@ class ZoteroOverlay {
1208
1185
functionName ,
1209
1186
func ,
1210
1187
IDPrefix ,
1211
- doc ,
1212
1188
) ;
1213
- menuPopup . appendChild ( menuFunc ) ;
1214
- if ( elementsAreRoot ) {
1215
- WikiciteChrome . registerXUL ( menuFunc . id , doc ) ;
1216
- }
1189
+ options . push ( menuFunc ) ;
1217
1190
}
1191
+ return options ;
1218
1192
}
1219
1193
1220
1194
// Create Zotero item menu item
@@ -1223,25 +1197,27 @@ class ZoteroOverlay {
1223
1197
functionName : MenuFunction ,
1224
1198
func : ( menuName : MenuSelectionType ) => void ,
1225
1199
IDPrefix : string ,
1226
- doc : Document ,
1227
1200
) {
1228
- const ns =
1229
- "http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" ;
1230
- const menuFunc = doc . createElementNS ( ns , "menuitem" ) ;
1231
- menuFunc . setAttribute ( "id" , IDPrefix + functionName ) ;
1232
- menuFunc . setAttribute (
1233
- "label" ,
1234
- Wikicite . getString ( `wikicite.submenu.${ functionName } ` ) ,
1235
- ) ;
1236
- menuFunc . addEventListener (
1237
- "command" ,
1238
- ( event ) => {
1201
+ let label : string ;
1202
+ Zotero . log ( `Building menu for ${ functionName } ` ) ;
1203
+ if ( functionName . includes ( "getFromIndexer." ) ) {
1204
+ const indexerName = functionName . split ( "." ) [ 1 ] ;
1205
+ label = Wikicite . formatString (
1206
+ "wikicite.submenu.get-from-indexer" ,
1207
+ indexerName ,
1208
+ ) ;
1209
+ Zotero . log ( label ) ;
1210
+ } else label = Wikicite . getString ( `wikicite.submenu.${ functionName } ` ) ;
1211
+ const menuOptions : MenuitemOptions = {
1212
+ tag : "menuitem" ,
1213
+ id : IDPrefix + functionName ,
1214
+ label : label ,
1215
+ commandListener : ( event ) => {
1239
1216
event . stopPropagation ( ) ;
1240
1217
func ( menuName ) ;
1241
1218
} ,
1242
- false ,
1243
- ) ;
1244
- return menuFunc ;
1219
+ } ;
1220
+ return menuOptions ;
1245
1221
}
1246
1222
}
1247
1223
0 commit comments