Skip to content

Commit d121f18

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

File tree

6 files changed

+244
-65
lines changed

6 files changed

+244
-65
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
release:
44
types: [published]
55
env:
6-
DEPENDENCIES_BRANCH: main
6+
DEPENDENCIES_BRANCH: 18.2.0/custom
77
jobs:
88
create:
99
name: "Create"

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: 237 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,16 @@ customDesignerFunctions.getCustomFunctionsList = function () {
111111
});
112112
};
113113

114+
customDesignerFunctions.getFirstCustomFunctionName = function () {
115+
const list = Utils.customFunctionNames;
116+
if (list.length == 0) {
117+
console.log("not yey");
118+
return "ABS" // just none
119+
}
120+
list.sort();
121+
return list[0];
122+
};
123+
114124
customDesignerFunctions.fillWithArraySystemFonts = function () {
115125
return vp_fonts.map(val => { return { text: val, value: val }; });
116126
};
@@ -122,20 +132,235 @@ customDesignerFunctions.fillWithTruncatedArraySystemFonts = function () {
122132
});
123133
};
124134

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

126143
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-
});
144+
var TemplateNames = GC.Spread.Sheets.Designer.TemplateNames;
133145

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-
*/
146+
// console.log("Remove 'export JS file' button from interface")
147+
var template = GC.Spread.Sheets.Designer.getTemplate(TemplateNames.FileMenuPanelTemplate);
148+
// Try the known path first
149+
let removed = false;
150+
try {
151+
const exportSSJsonPanel = template.content[0].children[0].children[1].children[2].children[1].children[1].children[0].children;
152+
153+
if (exportSSJsonPanel && Array.isArray(exportSSJsonPanel)) {
154+
const buttonIndex = exportSSJsonPanel.findIndex(child =>
155+
child && child.bindingPath === "button_export_javascript"
156+
);
157+
158+
if (buttonIndex !== -1) {
159+
// console.log("Found 'export JS file' button at known path, index:", buttonIndex);
160+
exportSSJsonPanel.splice(buttonIndex, 1);
161+
// console.log("Successfully removed 'export JS file' button!");
162+
removed = true;
163+
}
164+
}
165+
} catch (error) {
166+
console.warn("Remove 'export JS file' button from interface: Known path not accessible:", error.message);
167+
}
138168

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

0 commit comments

Comments
 (0)