@@ -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+
114123customDesignerFunctions . 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
126142customDesignerFunctions . 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