Skip to content

Commit 1582c47

Browse files
committed
Remove 'export JS file' button from interface"
Add "custom" category in the insert function dialogAdd "custom" category in the insert function dialog sorting categories in insert function dialog
1 parent 0533070 commit 1582c47

File tree

1 file changed

+99
-25
lines changed

1 file changed

+99
-25
lines changed

Resources/scripts/custom-designer-functions.js

Lines changed: 99 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -131,38 +131,112 @@ customDesignerFunctions.handlerExportCsvSetting = function (setting) {
131131

132132

133133
customDesignerFunctions.init = function () {
134-
/*
135-
let moduleSupportedFunctions = exported_modules.c["./src/commands/ribbon/formulas/functions/supportedFunctions/supportedFunctions.ts"].exports;
136-
moduleSupportedFunctions.allFunctionItems = moduleSupportedFunctions.allFunctionItems.concat(customDesignerFunctions.getCustomFunctionsList());
137-
moduleSupportedFunctions.allFunctionItems.sort(function (a, b) {
138-
return a.text.localeCompare(b.text);
139-
});
134+
var TemplateNames = GC.Spread.Sheets.Designer.TemplateNames;
140135

141-
let moduleInsertFunctionDialog = exported_modules.c["./src/commands/ribbon/formulas/functionHandler/insertFunctionDialog.tpl.ts"].exports;
142-
moduleInsertFunctionDialog.insertFunctionDialogTemplate.content[0].children[0].children[1].children[1].children[13].items = customDesignerFunctions.getCustomFunctionsList();
143-
moduleInsertFunctionDialog.insertFunctionDialogTemplate.content[0].children[0].children[1].children[1].children[0].items = moduleSupportedFunctions.allFunctionItems;
144-
*/
136+
console.log("Remove 'export JS file' button from interface")
137+
var template = GC.Spread.Sheets.Designer.getTemplate(TemplateNames.FileMenuPanelTemplate);
138+
// Try the known path first
139+
let removed = false;
140+
try {
141+
const exportSSJsonPanel = template.content[0].children[0].children[1].children[2].children[1].children[1].children[0].children;
142+
143+
if (exportSSJsonPanel && Array.isArray(exportSSJsonPanel)) {
144+
const buttonIndex = exportSSJsonPanel.findIndex(child =>
145+
child && child.bindingPath === "button_export_javascript"
146+
);
147+
148+
if (buttonIndex !== -1) {
149+
console.log("Found 'export JS file' button at known path, index:", buttonIndex);
150+
exportSSJsonPanel.splice(buttonIndex, 1);
151+
console.log("Successfully removed 'export JS file' button!");
152+
removed = true;
153+
}
154+
}
155+
} catch (error) {
156+
console.warn("Remove 'export JS file' button from interface: Known path not accessible:", error.message);
157+
}
145158

146-
// add custom functions to the custom section of the insert function dialog
159+
// If not found at known path, search recursively
160+
if (!removed) {
161+
console.warn("Button not found at known path, searching entire template...");
162+
163+
function findAndRemoveButton(obj, path = "") {
164+
if (!obj || typeof obj !== 'object') return null;
165+
166+
if (Array.isArray(obj)) {
167+
for (let i = 0; i < obj.length; i++) {
168+
if (obj[i] && obj[i].bindingPath === "button_export_javascript") {
169+
const foundPath = path + "[" + i + "]";
170+
console.error("ALERT: Button found at NEW PATH:", foundPath);
171+
console.error("Please update the code with this new path!");
172+
console.log("Button object:", obj[i]);
173+
obj.splice(i, 1);
174+
console.log("Successfully removed 'export JS file' button!");
175+
return foundPath;
176+
}
177+
const result = findAndRemoveButton(obj[i], path + "[" + i + "]");
178+
if (result) return result;
179+
}
180+
} else {
181+
for (let key in obj) {
182+
if (obj.hasOwnProperty(key)) {
183+
const result = findAndRemoveButton(obj[key], path + "." + key);
184+
if (result) return result;
185+
}
186+
}
187+
}
188+
return null;
189+
}
147190

148-
console.log("inject custom function in panel")
191+
removed = findAndRemoveButton(template, "template");
192+
if (!removed) {
193+
console.error("ERROR: 'export JS file' button with bindingPath 'button_export_javascript' not found in entire template!");
194+
}
195+
}
196+
if (removed) {
197+
GC.Spread.Sheets.Designer.registerTemplate(TemplateNames.FileMenuPanelTemplate, template);
198+
}
149199

150-
var InsertFunctionDialogTemplate = "insertFunctionDialogTemplate" // TemplateNames.InsertFunctionDialogTemplate
151-
var template = GC.Spread.Sheets.Designer.getTemplate(InsertFunctionDialogTemplate);
200+
console.log("Add custom functions to the custom section of the insert function dialog")
201+
template = GC.Spread.Sheets.Designer.getTemplate(TemplateNames.InsertFunctionDialogTemplate);
202+
try {
152203
const prop$8 = (o, o1) => `${o}.${o1}`;
153-
// TODO BETTER: inject new ones
154-
//template.content[0].children[0].children[1].children[1].children[12].items = customDesignerFunctions.getCustomFunctionsList();
155-
template.content[0].children[0].children[1].children[1].children.push({
156-
type: "List",
157-
visibleWhen: prop$8("functionDesc", "functionCategory") + "=14",
158-
bindingPath: prop$8("functionDesc", "customFunction"),
159-
items: customDesignerFunctions.getCustomFunctionsList(),
160-
keyboardSearch: true,
161-
dblClickSubmit: true
162-
});
204+
template.content[0].children[0].children[1].children[1].children.unshift({
205+
type: "List",
206+
visibleWhen: prop$8("functionDesc", "functionCategory") + "=" + String(template.content[0].children[0].children[1].children[1].children.length),
207+
bindingPath: prop$8("functionDesc", "customFunction"),
208+
items: customDesignerFunctions.getCustomFunctionsList(),
209+
keyboardSearch: true,
210+
dblClickSubmit: true
211+
});
212+
template.content[0].children[0].children[0].children[1].items.sort(function (a, b) {
213+
return a.text.localeCompare(b.text);
214+
});
215+
GC.Spread.Sheets.Designer.registerTemplate(TemplateNames.InsertFunctionDialogTemplate, template);
216+
} catch (error) {
217+
console.warn("Add custom functions to the custom section: ", error.message);
218+
}
219+
template = GC.Spread.Sheets.Designer.getTemplate(TemplateNames.InsertFunctionAllowDynamicArrayDialogTemplate);
220+
try {
221+
const prop$8 = (o, o1) => `${o}.${o1}`;
222+
template.content[0].children[0].children[1].children[1].children.unshift({
223+
type: "List",
224+
visibleWhen: prop$8("functionDesc", "functionCategory") + "=" + String(template.content[0].children[0].children[1].children[1].children.length),
225+
bindingPath: prop$8("functionDesc", "customFunction"),
226+
items: customDesignerFunctions.getCustomFunctionsList(),
227+
keyboardSearch: true,
228+
dblClickSubmit: true
229+
});
230+
template.content[0].children[0].children[0].children[1].items.sort(function (a, b) {
231+
return a.text.localeCompare(b.text);
232+
});
233+
GC.Spread.Sheets.Designer.registerTemplate(TemplateNames.InsertFunctionAllowDynamicArrayDialogTemplate, template);
234+
} catch (error) {
235+
console.warn("Add custom functions to the custom dynamic section: ", error.message);
236+
}
237+
163238

164239
// todo localize stuff here?
165-
GC.Spread.Sheets.Designer.registerTemplate("insertFunctionDialogTemplate", template);
166240
};
167241

168242
class ViewProAppBase {

0 commit comments

Comments
 (0)