Skip to content

Commit 751255e

Browse files
committed
SpreadJS 18.2.0 integration github:15886
Use appBase or template edition to customize designer
1 parent 2ef4971 commit 751255e

File tree

5 files changed

+242
-64
lines changed

5 files changed

+242
-64
lines changed

Project/Sources/Methods/COMPILER_private.4dm

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@ C_OBJECT:C1216(vp_isObjectValid; $1)
1616
C_OBJECT:C1216(vp_METADATA; $1)
1717
C_TEXT:C284(vp_METADATA; $2)
1818

19-
//___________________________________
20-
C_OBJECT:C1216(vp_UPDATE; $1)
21-
22-
//___________________________________
23-
C_OBJECT:C1216(vp_UPDATE_SJS; $1)
24-
2519
//___________________________________
2620
C_TEXT:C284(vp_endInit; $1)
2721
C_TEXT:C284(vp_endInit; $2)

Project/Sources/Methods/vp_UPDATE.4dm

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,7 @@ ________________________________________________________
1414
// Update according ViewPro version
1515
// ----------------------------------------------------
1616
// Declarations
17-
C_OBJECT:C1216($1)
18-
19-
20-
C_OBJECT:C1216($Obj_in)
21-
22-
If (False:C215)
23-
C_OBJECT:C1216(vp_UPDATE; $1)
24-
End if
25-
26-
// ----------------------------------------------------
27-
// Initialisations
28-
var $nbParameters:=Count parameters:C259
29-
30-
If (Asserted:C1132($nbParameters>=1; "Missing parameter"))
31-
32-
// Required parameters
33-
$Obj_in:=$1 // 4DVP object
34-
35-
// Optional parameters
36-
If ($nbParameters>=2)
37-
38-
// <NONE>
39-
40-
End if
41-
42-
Else
43-
44-
ABORT:C156
45-
46-
End if
17+
#DECLARE($Obj_in : Object)
4718

4819
// ----------------------------------------------------
4920
If (Storage:C1525.ViewPro.available)
@@ -69,9 +40,3 @@ If (Storage:C1525.ViewPro.available)
6940
vp_UPDATE_SJS($Obj_in.spreadJS)
7041

7142
End if
72-
73-
// ----------------------------------------------------
74-
// Return
75-
// <NONE>
76-
// ----------------------------------------------------
77-
// End

Project/Sources/Methods/vp_UPDATE_SJS.4dm

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,18 @@ var $Boo_updated : Boolean
2020
var $Lon_docMajor; $Lon_sjsMajor : Integer
2121
var $Txt_buffer; $Txt_property : Text
2222

23-
If (False:C215)
24-
C_OBJECT:C1216(vp_UPDATE_SJS; $1)
25-
End if
26-
27-
2823
// ----------------------------------------------------
2924
Case of
3025

3126
//______________________________________________________
3227
: ($Obj_in=Null:C1517)
3328

34-
err_THROW({code: 1 /*Invalid 4D View Pro object*/})
29+
err_THROW({code: 1/*Invalid 4D View Pro object*/})
3530

3631
//______________________________________________________
3732
: ($Obj_in.version=Null:C1517)
3833

39-
err_THROW({code: 1 /*Invalid 4D View Pro object*/})
34+
err_THROW({code: 1/*Invalid 4D View Pro object*/})
4035

4136
//______________________________________________________
4237
: ($Obj_in.version=Storage:C1525.ViewPro.spreadJSVersion) // Current version
@@ -59,7 +54,7 @@ Case of
5954
//……………………………………………………………………………………………………………………………………………………………………
6055
: ($Lon_docMajor<9)
6156

62-
err_THROW({code: 1 /*Invalid 4D View Pro object*/})
57+
err_THROW({code: 1/*Invalid 4D View Pro object*/})
6358

6459
//……………………………………………………………………………………………………………………………………………………………………
6560
: ($Lon_docMajor<=10)
@@ -98,7 +93,7 @@ Case of
9893
: ($Lon_docMajor>=11)
9994

10095
// v<$Lon_docMajor> to v17 open v<$Lon_docMajor> doc, adjust minor version
101-
$Boo_updated:=($Lon_sjsMajor>=$Lon_docMajor) && ($Lon_sjsMajor<=17)
96+
$Boo_updated:=($Lon_sjsMajor>=$Lon_docMajor)
10297

10398
//……………………………………………………………………………………………………………………………………………………………………
10499
End case

Project/Sources/Methods/vp_fillStorage.4dm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
$o.version:=1
55
$o.extension:=".4vp"
6-
$o.spreadJSVersion:="17.1.0"
6+
$o.spreadJSVersion:="18.2.0"
77
$o.options:=New shared object:C1526
88

99
Use ($o.options)

Resources/scripts/custom-designer-functions.js

Lines changed: 236 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ customDesignerFunctions.getCustomFunctionsList = function () {
111111
});
112112
};
113113

114+
customDesignerFunctions.getFirstCustomFunctionName = function () {
115+
const list = Utils.customFunctionNames;
116+
if (list.length == 0) {
117+
return "ABS" // just none
118+
}
119+
list.sort();
120+
return list[0];
121+
};
122+
114123
customDesignerFunctions.fillWithArraySystemFonts = function () {
115124
return vp_fonts.map(val => { return { text: val, value: val }; });
116125
};
@@ -122,20 +131,235 @@ customDesignerFunctions.fillWithTruncatedArraySystemFonts = function () {
122131
});
123132
};
124133

134+
customDesignerFunctions.handlerExportCsvSetting = function (setting) {
135+
var rowDelimiter = (setting.rowDelimiter || "\r");
136+
let columnDelimiter = setting.columnDelimiter || ",";
137+
setting.rowDelimiter = rowDelimiter.replace(/\\r/g, "\r").replace(/\\n/g, "\n").replace(/\\t/g, "\t");
138+
setting.columnDelimiter = columnDelimiter.replace(/\\r/g, '\r').replace(/\\n/g, '\n').replace(/\\t/g, '\t');
139+
};
140+
125141

126142
customDesignerFunctions.init = function () {
127-
/*
128-
let moduleSupportedFunctions = exported_modules.c["./src/commands/ribbon/formulas/functions/supportedFunctions/supportedFunctions.ts"].exports;
129-
moduleSupportedFunctions.allFunctionItems = moduleSupportedFunctions.allFunctionItems.concat(customDesignerFunctions.getCustomFunctionsList());
130-
moduleSupportedFunctions.allFunctionItems.sort(function (a, b) {
131-
return a.text.localeCompare(b.text);
132-
});
143+
var TemplateNames = GC.Spread.Sheets.Designer.TemplateNames;
133144

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

139-
// add custom functions to the custom section of the insert function dialog
140-
vp_insertFunctionDialogTemplate.content[0].children[0].children[1].children[1].children[13].items = customDesignerFunctions.getCustomFunctionsList();
168+
// If not found at known path, search recursively
169+
if (!removed) {
170+
console.warn("Button not found at known path, searching entire template...");
171+
172+
function findAndRemoveButton(obj, path = "") {
173+
if (!obj || typeof obj !== 'object') return null;
174+
175+
if (Array.isArray(obj)) {
176+
for (let i = 0; i < obj.length; i++) {
177+
if (obj[i] && obj[i].bindingPath === "button_export_javascript") {
178+
const foundPath = path + "[" + i + "]";
179+
console.error("ALERT: Button found at NEW PATH:", foundPath);
180+
console.error("Please update the code with this new path!");
181+
console.log("Button object:", obj[i]);
182+
obj.splice(i, 1);
183+
console.log("Successfully removed 'export JS file' button!");
184+
return foundPath;
185+
}
186+
const result = findAndRemoveButton(obj[i], path + "[" + i + "]");
187+
if (result) return result;
188+
}
189+
} else {
190+
for (let key in obj) {
191+
if (obj.hasOwnProperty(key)) {
192+
const result = findAndRemoveButton(obj[key], path + "." + key);
193+
if (result) return result;
194+
}
195+
}
196+
}
197+
return null;
198+
}
199+
200+
removed = findAndRemoveButton(template, "template");
201+
if (!removed) {
202+
console.error("ERROR: 'export JS file' button with bindingPath 'button_export_javascript' not found in entire template!");
203+
}
204+
}
205+
if (removed) {
206+
GC.Spread.Sheets.Designer.registerTemplate(TemplateNames.FileMenuPanelTemplate, template);
207+
}
208+
209+
// console.log("Add custom functions to the custom section of the insert function dialog")
210+
template = GC.Spread.Sheets.Designer.getTemplate(TemplateNames.InsertFunctionDialogTemplate);
211+
try {
212+
const prop$8 = (o, o1) => `${o}.${o1}`;
213+
template.content[0].children[0].children[1].children[1].children.unshift({
214+
type: "List",
215+
visibleWhen: prop$8("functionDesc", "functionCategory") + "=" + String(template.content[0].children[0].children[1].children[1].children.length),
216+
bindingPath: prop$8("functionDesc", "customFunction"),
217+
items: customDesignerFunctions.getCustomFunctionsList(),
218+
keyboardSearch: true,
219+
dblClickSubmit: true
220+
});
221+
template.content[0].children[0].children[0].children[1].items.sort(function (a, b) {
222+
return a.text.localeCompare(b.text);
223+
});
224+
GC.Spread.Sheets.Designer.registerTemplate(TemplateNames.InsertFunctionDialogTemplate, template);
225+
} catch (error) {
226+
console.warn("Add custom functions to the custom section: ", error.message);
227+
}
228+
template = GC.Spread.Sheets.Designer.getTemplate(TemplateNames.InsertFunctionAllowDynamicArrayDialogTemplate);
229+
try {
230+
const prop$8 = (o, o1) => `${o}.${o1}`;
231+
template.content[0].children[0].children[1].children[1].children.unshift({
232+
type: "List",
233+
visibleWhen: prop$8("functionDesc", "functionCategory") + "=" + String(template.content[0].children[0].children[1].children[1].children.length),
234+
bindingPath: prop$8("functionDesc", "customFunction"),
235+
items: customDesignerFunctions.getCustomFunctionsList(),
236+
keyboardSearch: true,
237+
dblClickSubmit: true
238+
});
239+
template.content[0].children[0].children[0].children[1].items.sort(function (a, b) {
240+
return a.text.localeCompare(b.text);
241+
});
242+
GC.Spread.Sheets.Designer.registerTemplate(TemplateNames.InsertFunctionAllowDynamicArrayDialogTemplate, template);
243+
} catch (error) {
244+
console.warn("Add custom functions to the custom dynamic section: ", error.message);
245+
}
246+
247+
248+
// todo localize stuff here?
141249
};
250+
251+
class ViewProAppBase {
252+
constructor() {
253+
this._ms = [ null, null, () => { return 0 }, () => {} ];
254+
}
255+
notifyReady() {
256+
customDesignerFunctions.notifyReady();
257+
}
258+
showOpenDialog(options) {
259+
return Promise.reject({
260+
status: "",
261+
fileName: ""
262+
});
263+
}
264+
open(fileName) {
265+
return {
266+
status: "",
267+
message: "",
268+
data: "",
269+
fileName: ""
270+
};
271+
}
272+
save(fileName, data2, isJSFile) {
273+
// customDesignerFunctions.saveAs
274+
return failed;
275+
}
276+
exit() {}
277+
importFile(fileName, options) {
278+
return Promise.resolve(failed);
279+
}
280+
showSaveDialog(options) {
281+
return cancelled;
282+
}
283+
exportFile(fileName, data2) {
284+
return Promise.resolve(failed);
285+
}
286+
needActive() {
287+
return true;
288+
}
289+
setClipboardData(data2) {}
290+
getClipboardText() {
291+
return "";
292+
}
293+
getBase64(fileName) {
294+
return "";
295+
}
296+
getClipboardHTML() {
297+
return "";
298+
}
299+
getSystemFonts() {
300+
return customDesignerFunctions.fillWithTruncatedArraySystemFonts();
301+
}
302+
closeAllWindows() {}
303+
setClipboardText(text) {}
304+
setClipboardHTML(string) {}
305+
getFileInfo(fullPath) {
306+
// dir, fileName
307+
return {};
308+
}
309+
joinPath(segments) {
310+
return segments && segments.toString();
311+
}
312+
config(name, value) {
313+
if (value === void 0) {
314+
return this.getConfig(name);
315+
} else {
316+
this.setConfig(name, value);
317+
return osEnv;
318+
}
319+
}
320+
getConfig(name) {
321+
this.initConfig(true);
322+
let path = name.split(".");
323+
let value = this._config;
324+
if (value) {
325+
for (let i = 0; i < path.length; i++) {
326+
let sub = value[path[i]];
327+
if (sub === void 0) {
328+
return void 0;
329+
}
330+
value = sub;
331+
}
332+
if (name === _createdDateKey) {
333+
let n = parseInt(value, 36);
334+
return isNaN(n) ? null : new Date(n);
335+
}
336+
return value;
337+
} else {
338+
return void 0;
339+
}
340+
}
341+
initConfig(onget) {
342+
if (this._config === void 0) {
343+
this._config = {};
344+
}
345+
}
346+
setConfig(name, value) {
347+
this.initConfig(false);
348+
let path = name.split(".");
349+
let item = this._config;
350+
if (item) {
351+
for (let i = 0; i < path.length - 1; i++) {
352+
let sub = item[path[i]];
353+
if (sub === void 0) {
354+
item[path[i]] = sub = {};
355+
}
356+
item = sub;
357+
}
358+
item[path[path.length - 1]] = value;
359+
}
360+
}
361+
restartApp() {}
362+
}
363+
364+
window.osenv = new ViewProAppBase();
365+
window.gc_native_app = true;

0 commit comments

Comments
 (0)