1 'encoding UTF-8 Do not remove or change this line!
2 '*******************************************************************************
3 '* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 '* Copyright 2008 by Sun Microsystems, Inc.
7 '* OpenOffice.org - a multi-platform office productivity suite
9 '* $RCSfile: t_files.inc,v $
13 '* last change: $Author: rt $ $Date: 2008-08-28 11:59:04 $
15 '* This file is part of OpenOffice.org.
17 '* OpenOffice.org is free software: you can redistribute it and/or modify
18 '* it under the terms of the GNU Lesser General Public License version 3
19 '* only, as published by the Free Software Foundation.
21 '* OpenOffice.org is distributed in the hope that it will be useful,
22 '* but WITHOUT ANY WARRANTY; without even the implied warranty of
23 '* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 '* GNU Lesser General Public License version 3 for more details
25 '* (a copy is included in the LICENSE file that accompanied this code).
27 '* You should have received a copy of the GNU Lesser General Public License
28 '* version 3 along with OpenOffice.org. If not, see
29 '* <http://www.openoffice.org/license.html>
30 '* for a copy of the LGPLv3 License.
32 '/******************************************************************************
34 '* Owner : thorsten.bosbach@sun.com
36 '* short description : Global routines for loading, saving, printing, export
38 '\******************************************************************************
40 private const C_INFO = TRUE ' Set this to TRUE to increase verbosity of some functions
41 private const VERBOSE = true
43 function hGrafikEinfuegen ( Grafik$ ) as Boolean
44 '/// hGrafikEinfuegen hGraphicInsert
45 '/// A graphic will be inserted (not linked).
46 '/// <u>Input</u>: Filename with complete path
47 '/// <u>Return</u>: TRUE or FALSE if the graphic could be inserted or not.
49 Dim DieDatei as String
50 Dim IsActive as Boolean
52 DieDatei = ConvertPath ( Grafik$ )
54 InsertGraphicsFromFile
58 If Active.Exists(1) then
59 warnlog " Hinweis: " & Active.GetText
64 Kontext "GrafikEinfuegenDlg"
65 if ( GrafikEinfuegenDlg.exists( 2 ) ) then
68 if gApplication <> "HTML" AND gApplication <> "HTML" then
72 Dateiname.SetText DieDatei
73 DateiTyp.Select 1 ' set the filter to 'all formats'
77 if Active.Exists(2) then
78 Warnlog " Hinweis: " & Active.GetText
88 Kontext "GrafikEinfuegenDlg"
89 if GrafikEinfuegenDlg.Exists then
90 GrafikEinfuegenDlg.Cancel
93 hGrafikEinfuegen = IsImageLoaded
96 'GrafikEinfuegeDlg not open
100 '-------------------------------------------------------------------------------
102 function hGrafikVerknuepftEinfuegen ( Grafik$ ) as Boolean
103 '/// hGrafikEinfuegenEinfuegen hGraphicInsertLinked
104 '/// A graphic will be inserted <b>LINKED</b>
105 '/// <u>Input</u>: Filename with complete path
106 '/// <u>Return</u>: TRUE or FALSE if the graphic could be inserted or not.
107 Dim DieDatei as String
108 Dim IsActive as Boolean
110 DieDatei = ConvertPath ( Grafik$ )
112 InsertGraphicsFromFile
116 If Active.Exists(1) then
117 warnlog " Hinweis: " & Active.GetText
120 Kontext "GrafikEinfuegenDlg"
121 if ( GrafikEinfuegenDlg.exists( 1 ) ) then
124 if gApplication <> "HTML" AND gApplication <> "HTML" then
128 Dateiname.SetText DieDatei
129 DateiTyp.Select 1 ' set the filter to 'all formats'
133 if Active.Exists(2) then
134 Warnlog " Hinweis: " + Active.GetText
140 Kontext "GrafikEinfuegenDlg"
141 if GrafikEinfuegenDlg.Exists then
142 GrafikEinfuegenDlg.Cancel
145 hGrafikVerknuepftEinfuegen = IsImageLoaded
148 'GrafikEinfuegenDlg not open
152 '-------------------------------------------------------------------------------
154 function IsItSaved as boolean
156 '/// Wait until document is saved.
163 'Calling slot 'IsDocSaving'
164 IsItSaved = IsDocSaving
169 if IsItSaved = TRUE then
177 '-------------------------------------------------------------------------------
179 function IsItLoaded as boolean
181 '/// Wait until document is loaded
188 'Calling slot 'IsDocLoading'
189 IsItLoaded = IsDocLoading
194 if IsItLoaded = TRUE then
202 '-------------------------------------------------------------------------------
204 function hIsNamedDocLoaded (ShouldFile as String, optional bSilent as boolean) as Boolean
206 '/// hIsNamedDocLoaded ///'
207 '/// !fails always if a template is loaded, because you have to set a new filename in the save-dialog -> not usable in this case ! ///'
208 '/// Input: name of loaded file; Output: True/False ///'
209 '///+' if a doc got loaded, the filename in a 'SaveAs' Dlg is different from "" ///
210 '///+' usually the file name of the loaded document with an changed extension chosen from SO ///
212 if (isMissing(bSilent)) then
216 hIsNamedDocLoaded = FALSE ' Let's start WorstCase :-(
218 Kontext "SpeichernDlg"
219 If DateiOhneExt(DateiExtract(Dateiname.GetSelText)) = DateiOhneExt(DateiExtract(ShouldFile)) Then
220 hIsNamedDocLoaded = True
222 sTemp = left(right(ShouldFile,2),1) ' get the 2nd last character ' vor;dot;sti;pot;std;xlt
223 if (((sTemp="o") or (sTemp="t") or (sTemp="l")) and ((left(right(ShouldFile,4),1)=".") or (left(right(ShouldFile,5),1)="."))) then
224 hIsNamedDocLoaded = TRUE ' exception! for linux! and MS-Office Templates
226 if ((Dateiname.GetSeltext = "") and not bSilent) then
227 Warnlog "Default filename is empty!"+left(right(ShouldFile,3),1)
234 '-------------------------------------------------------------------------------
236 function IsImageLoaded
238 '/// Wait until images in document are loaded
239 Dim i% : Dim Herbert as Boolean
244 Herbert = IsDocImageLoading
248 if Herbert = TRUE then
254 IsImageLoaded = FALSE
260 '-------------------------------------------------------------------------------
262 sub hIsWebPageLoaded as boolean
263 'Author: Joerg Sievers
264 '/// If a document in StarOffice Writer is loaded all 9 items in the
265 '///+ statusbar are visible otherwise not.
266 '///+ This sub checks the state of these items.
268 Dim iGibtdenStatusraus as integer
269 printlog "- global::tools::inc::tfiles.inc::hIsWebPageLoaded"
270 hIsWebPageLoaded = FALSE
272 Kontext "DocumentWriter"
273 if DocumentWriter.Exists(3) then
274 'Count the items on the status bar.
275 iGibtdenStatusraus = DocumentWriter.StatusGetItemCount
276 'There are nine items on the status bar if the web page has been loaded.
277 if iGibtdenStatusraus = 9 then
278 hIsWebPageLoaded = TRUE
286 '-------------------------------------------------------------------------------
289 '/// Change from system to StarOffice-internal file-dialog (only for Win32)
290 if gPlatgroup <> "unx" then
291 Call hhSysToInt ( TRUE )
296 '-------------------------------------------------------------------------------
299 '/// Change from StarOffice-internal to system file-dialog (only for Win32)
300 if gPlatgroup <> "unx" then
301 Call hhSysToInt ( FALSE )
306 '-------------------------------------------------------------------------------
308 sub hhSysToInt ( bwhats as Boolean )
309 '/// subroutine for <i>hSys2IntDlg</i> and </i>hInt2SysDlg</i>
311 hToolsOptions ( "StarOffice", "General" )
312 if bwhats = TRUE then
313 StarOfficeDialogeBenutzen.Check
315 StarOfficeDialogeBenutzen.Uncheck
318 Kontext "OptionenDlg"
323 '-------------------------------------------------------------------------------
325 function hGetUsedFilter () as string
326 '/// Get used filter for loaded file.
329 Kontext "SpeichernDlg"
330 hGetUsedFilter = dateityp.getseltext
333 hGetUsedFilter = "Not possible; try/catch fail in function"
337 '-------------------------------------------------------------------------------
339 function hFileExport (sName as string, sFilter as string) as boolean
340 '/// Wrapper function to simplify the use of the export functions, just give a filename and export format.
341 '///+ INPUT:<ul><li>sName: filename</li><li>sFilter: "PDF": call export for PDF</li></ul>
342 '///+ RETURN: execution success?
344 case "PDF" : '/// use the function 'hExportAsPDF' with RECOMMENDED values /// '
345 hFileExport = hExportAsPDFmulti (3, TRUE, sName, FALSE, TRUE, 1, 1)
348 if active.exists(5) then
350 printlog active.getText
352 warnLog "i26820 - errormessage about saving"
354 printlog "pdf unexpected error in hFileExport()"
359 '-------------------------------------------------------------------------------
361 function hExportAsPDFmulti (iTypeOfCall as integer, bExecute as boolean, sFileName as string, bAutoExtension as boolean, bOverwriteFile as boolean, iRange as integer, iConpression as integer, optional sRange as string) as boolean
362 '/// Export a document to PDF with various options.
364 '///+<ul><li>iTypeOfCall</li><ul><li>1: via the icon in the functionbar (no options selectable, since only file dialog comes up!)</li>
365 '///+<li>2: via File->Send->Document As PDF Attachment... (makes no sense either, because after the mail window comes up... (you can't handle by the testtool))</li>
366 '///+<li>3 via File->Export As PDF... (RECOMMENDED)</li></ul>
367 '///+<li>bExecute: Shall all dialogs left with OK? TRUE (RECOMMENDED) / FALSE</li>
368 '///+<li>sFileName: Filename to use</li>
369 '///+<li>bAutoExtension: Shall the file extension be chosen by StarOffice? TRUE / FALSE (RECOMMENDED)</li>
370 '///+<li>bOverwriteFile: If filename already exists should it be overwritten? TRUE (RECOMMENDED) / FALSE</li>
371 '///+<li>iRange:</li><ol><li>1: All (RECOMMENDED)</li>
372 '///+<li>2: Pages: The range is set in the optional parameter 'sRange' at the end</li>
373 '///+<li>3: Selection</li></ol>
374 '///+<li>iConpression:</li><ol><li>1: JpegCompression check and ReduceImageResolution check</li>
375 '///+<li>2: JpegCompression check and ReduceImageResolution uncheck</li>
376 '///+<li>3: LosslessCompression check and ReduceImageResolution uncheck</li></ol>
377 '///+<li>sRange: Optional parameter only used for iRange=2; takes the page range as text</li>
378 '///+<li>RETURN: Any Errors? TRUE / FALSE</li></ul>
382 dim sTFileName as string
383 dim iCount as integer
385 sPDF = "PDF - Portable Document Format (.pdf)"
386 hExportAsPDFmulti = TRUE ' optimistic
389 select case (iTypeOfCall)
390 case 1 : '/// click the button 'Export Directly as PDF' on the Functionbar ///'
391 kontext "Standardbar"
395 Warnlog "Button 'Export directly as PDF' not accessible!"
396 hExportAsPDFmulti = FALSE
399 case 2 : '/// File->Send->Document As PDF Attachment... ///'
401 FileSendDocumentAsPDF
403 Warnlog "'Export as PDF' not accessible!"
404 hExportAsPDFmulti = FALSE
407 case 3 : '/// File->Export As PDF... ///'
409 FileExportAsPDF ' works in draw/impress, too but is not 'legal' in the UI :-)
411 Warnlog "Button 'Export as PDF' not accessible!"
412 hExportAsPDFmulti = FALSE
417 ' only if the type is 1 OR 3 then the File Save dialog appear
418 ' just kept here for compatibility reasons - has to get removed around july 2007
419 if (iTypeOfCall = 1 OR iTypeOfCall = 3) then
420 kontext "ExportierenDlg"
421 if ExportierenDlg.exists(5) then
425 Warnlog "Unable to select filter: '" + sPDF + "'"
426 ExportierenDlg.Cancel
427 hExportAsPDFmulti = FALSE
431 sTemp = Dateityp.GetSelText
432 if (sTemp <> sPDF) then
433 Warnlog "filter for PDF export is missing :-( '" + sPDF + "'"
435 '/// set Textbox 'File name' ///'
436 Dateiname.SetText sFileName
437 'if the file has no pdf extension then add the extension
438 if (lCase(right(sFileName, 4))=".pdf") then
439 sTFileName = sFileName
441 sTFileName = sFileName + ".pdf"
443 '/// click on the button 'Export...' ///'
446 kontext "AlienWarning"
447 if AlienWarning.exists(5) then
448 warnlog "#i41983# Alien Warning on export not allowed."
451 if (iTypeOfCall = 1) then
452 ''Export Directly as PDF'
455 ' wait until file exists for max 5 minutes
456 while ((dir(sTFileName)="") AND (iCount < 30))
462 'ExportierenDlg.Cancel
465 ' if file exists, there is a message...
467 if NOT PDFOptions.exists then
469 if messagebox.exists (5) then
470 if (bOverwriteFile) then
474 kontext "ExportierenDlg"
475 ExportierenDlg.Cancel
476 hExportAsPDFmulti = FALSE
483 ' only if the type is 2 OR 3 then the PDF option dialog appear
484 if (iTypeOfCall = 2 OR iTypeOfCall = 3) then
487 case 1 : '/// check radiobutton 'All' ///'
491 Warnlog "Radiobutton 'All' not accessible!"
493 hExportAsPDFmulti = FALSE
496 case 2 : '/// check radiobutton 'Pages' ///'
500 Warnlog "Radiobutton 'Range' not accessible!"
502 hExportAsPDFmulti = FALSE
505 if isMissing(sRange) then
506 Warnlog "parameter 'sRange' in function 'hExportAsPDFmulti' is not optional if 'iRange' = 2"
507 hExportAsPDFmulti = FALSE
509 '/// set range textbox the given value ///'
510 RangePagesEdit.SetText sRange
512 case 3 : '/// check radiobutton 'Selection' (not enabled in math!) ///'
514 if (RangeSelection.IsEnabled <> TRUE)then
515 Warnlog "RangeSelection is disabled :-("
520 Warnlog "Radiobutton 'Selection' not accessible!"
522 hExportAsPDFmulti = FALSE
527 select case (iConpression)
528 case 1 : '/// JpegCompression check and ReduceImageResolution check///'
530 JpegCompression.Check
531 ReduceImageResolution.Check
533 Warnlog "Radiobutton 'Reduce Image Resolution' not accessible!"
535 hExportAsPDFmulti = FALSE
538 case 2 : '/// JpegCompression check and ReduceImageResolution uncheck ///'
540 JpegCompression.Check
541 ReduceImageResolution.UnCheck
543 Warnlog "Radiobutton 'Jpeg Compression' not accessible!"
545 hExportAsPDFmulti = FALSE
548 case 3 : '/// LosslessCompression check and ReduceImageResolution uncheck ///'
550 LosslessCompression.Check
551 ReduceImageResolution.UnCheck
553 Warnlog "Radiobutton 'Lossless Compression' not accessible!"
555 hExportAsPDFmulti = FALSE
563 qaErrorlog "ImprovementOfSave: PDF export loops?"
569 ' only if the type is 1 OR 3 then the File Save dialog appear
570 kontext "ExportierenDLG"
571 if (iTypeOfCall = 1 OR iTypeOfCall = 3) then
572 if ExportierenDLG.exists(5) then
576 Warnlog "Unable to select filter: '" + sPDF + "'"
577 ExportierenDLG.Cancel
578 hExportAsPDFmulti = FALSE
582 sTemp = Dateityp.GetSelText
583 if (sTemp <> sPDF) then
584 Warnlog "filter for PDF export is missing :-( '" + sPDF + "'"
586 '/// set Textbox 'File name' ///'
587 Dateiname.SetText sFileName
588 'if the file has no pdf extension then add the extension
589 if (lCase(right(sFileName, 4))=".pdf") then
590 sTFileName = sFileName
592 sTFileName = sFileName + ".pdf"
594 '/// click on the button 'Export...' ///'
597 kontext "AlienWarning"
598 if AlienWarning.exists(5) then
599 warnlog "#i41983# Alien Warning on export not allowed."
602 if (iTypeOfCall = 1) then
603 ''Export Directly as PDF'
606 ' wait until file exists for max 5 minutes
607 while ((dir(sTFileName)="") AND (iCount < 30))
614 ExportierenDLG.Cancel
616 printlog "export not there"
620 ' if file exists, there is a message...
622 if NOT PDFOptions.exists then
624 if messagebox.exists (5) then
625 if (bOverwriteFile) then
629 kontext "ExportierenDLG"
630 ExportierenDLG.Cancel
631 hExportAsPDFmulti = FALSE
639 '-------------------------------------------------------------------------------
641 function hDeleteFile( cFileOrig as string ) as boolean
643 const CFN = "global::tools::includes::required::t_files.inc::hDeleteFile():"
645 cHome = gOfficePath & "user"
646 cHome = convertpath( cHome )
648 cFile = convertpath( cFileOrig )
650 '///<h3>Delete a file</h3>
651 '///<i>In many cases it is a good idea to use this function outside the testcase.<br>
652 '///+ You should always evaluate the returncode</i><br>
655 '///+<li>Filename (string)</li>
657 '///+<li>The function converts the path to system specific syntax (convertpath)
658 '///+ but does <b>not</b> modify the input parameter</li>
663 '///+<li>Errorstatus (boolean)</li>
665 '///+<li>TRUE: File was deleted/does not exist</li>
666 '///+<li>FALSE: File could not be deleted/any other error</li>
669 '///<u>Description</u>:
672 ' this function tries to delete a file and does some very basic error-
673 ' handling. Returns 'true' on success, only error while deleting returns
674 ' 'false', if the file does not exist, it is considered to be successfully
676 ' i introduced this function due to a number of cases where deleting files
677 ' actually failed because of weird code or situations where the user lacks
678 ' accessrights to files are not handled at all.
680 '///+<li>We may never delete a file outside gOfficePath/user/work</li>
681 if ( instr( cFile , cHome ) = 0 ) then
682 qaerrorlog( CFN & "Trying to delete file outside (default)homedir -> forbidden" )
683 qaerrorlog( CFN & "Home: " & cHome )
684 qaerrorlog( CFN & "File: " & cFile )
685 hDeleteFile() = false
689 cFile = convertpath( cFile )
691 '///+<li>Check that the file exists</li>
692 if ( FileExists( cFile ) ) then
694 '///+<li>Use kill to delete</li>
699 '///+<li>Verify that the file does not exist anymore</li>
700 if ( FileExists( cFile ) ) then
701 warnlog( CFN & "File was not deleted: " & cFile )
702 hDeleteFile() = false
704 if ( VERBOSE ) then printlog( CFN & "File successfully deleted: " & cFile )
710 '///+<li>in very rare cases 'kill' fails and can be handled this way</li>
711 qaerrorlog( CFN & "Deleting file failed: " & cFile )
712 hDeleteFile() = false
718 '///+<li>write some text to the log if the file does not exist</li>
719 printlog( CFN & "Nothing to do." )
728 '-------------------------------------------------------------------------------
730 function hFileCloseAll() as integer
732 dim iDocumentCount as integer : iDocumentCount = 0
733 Do Until GetDocumentCount = 0
734 Call hCloseDocument()
735 iDocumentCount = iDocumentCount + 1
737 hFileCloseAll() = iDocumentCount
741 '-------------------------------------------------------------------------------
743 function hFileOpen( cFile as string ) as boolean
745 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
747 const CFN = "global::tools::inc::t_files.inc::hFileOpen():"
748 if ( C_INFO ) then printlog( CFN & "Load: " & sFile )
749 FileOpen( "URL", sFile, "FrameName", "_default" )
750 if ( hFileWait( FALSE ) >= 0 ) then hFileOpen() = TRUE
754 '-------------------------------------------------------------------------------
756 function hFileOpenSpecial( cFile as string, cFlag as string ) as boolean
758 ' Open a file with some special options
759 ' cFlag = "ReadOnly" opens file read-onlx
760 ' cFlag = "AsTemplate" opens file as templat
761 ' cFlag = <Any other string> treats string as password
763 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
764 const CFN = "global::tools::inc::t_files.inc::hFileOpenSpecial():"
765 hFileOpenSpecial() = FALSE
766 if ( C_INFO ) then printlog( "Load (Flag): " & sFile & " (" & cFlag & ")" )
768 select case( lcase( cFlag ) )
770 printlog( CFN & "Load file read-only: " & sFile )
771 FileOpen( "URL", sFile, "FrameName", "_default", "ReadOnly", TRUE)
773 printlog( CFN & "Load file as template: " & sFile )
774 FileOpen( "URL", sFile, "FrameName", "_default", "AsTemplate" , TRUE )
776 printlog( CFN & "Load file with password: " & sFile )
777 FileOpen( "URL", sFile, "FrameName", "_default", "Password" , cFlag )
780 if ( hFileWait( FALSE ) >= 0 ) then hFileOpenSpecial() = TRUE
786 '-------------------------------------------------------------------------------
788 function hFileOpenWithFilter( cFile as string, cFilter as string )
790 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
791 const CFN = "global::tools::inc::t_files.inc::hFileOpenWithFilter():"
792 hFileOpenWithFilter() = FALSE
793 if ( C_INFO ) then printlog( CFN & "Load (Filter): " & sFile & " (" & cFilter & ")" )
794 FileOpen( "URL", sFile, "FrameName", "_default", "FilterName", cFilter )
795 if ( hFileWait( FALSE ) >= 0 ) then hFileOpenWithFilter() = TRUE
799 '-------------------------------------------------------------------------------
801 function hFileSave() as boolean
803 const CFN = "global::tools::inc::t_files.inc::hFileSave():"
805 if ( C_INFO ) then printlog( CFN & "Save file." )
806 FileSave( "SynchronMode", TRUE )
807 if ( hFileWait( TRUE ) >= 0 ) then hFileSave() = TRUE
811 '-------------------------------------------------------------------------------
813 function hFileSaveAs( cFile as string ) as boolean
815 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
816 const CFN = "global::tools::inc::t_files.inc::hFileSaveAs():"
817 hFileSaveAs() = FALSE
818 if ( C_INFO ) then printlog( CFN & "Save: " & sFile )
819 FileSaveAs( "URL", sFile, "Overwrite", FALSE )
820 if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAs() = TRUE
824 '-------------------------------------------------------------------------------
826 function hFileSaveAsKill( cFile as string ) as boolean
828 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
829 const CFN = "global::tools::inc::t_files.inc::hFileSaveAsKill():"
830 hFileSaveAsKill() = FALSE
831 if ( C_INFO ) then printlog( CFN & "Save, replacing: " & sFile )
832 FileSaveAs( "URL", sFile, "Overwrite", TRUE )
833 if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsKill() = TRUE
837 '-------------------------------------------------------------------------------
839 function hFileSaveAsKillWithPassword( cFile as string, cPassword as string ) as boolean
841 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
842 const CFN = "global::tools::inc::t_files.inc::hFileSaveAsKillWithPassword():"
843 hFileSaveAsKillWithPassword() = FALSE
844 if ( C_INFO ) then printlog( CFN & "Save with password, replacing: " & sFile & "::" & cPassword )
845 FileSaveAs( "URL", sFile, "Overwrite", TRUE, "Password", cPassword )
846 if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsKillWithPassword() = TRUE
850 '-------------------------------------------------------------------------------
852 function hFileSaveAsWithFilter( cFile as string, cFilter as string ) as boolean
854 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
855 const CFN = "global::tools::inc::t_files.inc::hFileSaveAsWithFilter():"
856 hFileSaveAsWithFilter() = FALSE
857 if ( C_INFO ) then printlog( CFN & "Save with filter: " & sFile & "::" & cFilter )
858 FileSaveAs( "URL", sFile, "FilterName", cFilter, "Overwrite", FALSE )
859 if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsWithFilter() = TRUE
863 '-------------------------------------------------------------------------------
865 function hFileSaveAsWithFilterKill( cFile as string, cFilter as string ) as boolean
867 dim sFile as string : sFile = convertToURL( convertpath( cFile ) )
868 const CFN = "global::tools::inc::t_files.inc::hFileSaveAsWithFilterKill():"
869 hFileSaveAsWithFilterKill() = FALSE
870 if ( C_INFO ) then printlog( CFN & "Save with filter, replacing: " & sFile & "::" & cFilter )
871 FileSaveAs( "URL", sFile, "FilterName", cFilter, "Overwrite", TRUE )
872 if ( hFileWait( TRUE ) >= 0 ) then hFileSaveAsWithFilterKill() = TRUE
876 '-------------------------------------------------------------------------------
878 function hFileWait( optional bWarn as boolean ) as integer
880 ' Wait max 10 seconds for the FileOpen/FileSave slot to finish
881 ' Returns the time it took the slot to finish
882 ' Negaitve returnvalues are given on timeout or any blocking dialog
884 const CFN = "global::tools::inc::t_files.inc::hFileWait():"
886 dim iWait as integer : iWait = 0
887 dim bWarnlog as boolean
889 if ( IsMissing( bWarn ) ) then
895 do while( WaitSlot() <> WSFinished )
899 ' This is the timeout
900 if ( iWait = MAX_WAIT ) then
905 ' LOAD: Security warning prevents slot from finishing
906 kontext "SecurityWarning"
907 if ( SecurityWarning.exists() ) then
912 ' LOAD: Password dialog
913 kontext "PasswordFileOpen"
914 if ( PasswordFileOpen.exists() ) then
919 ' SAVE: Password dialog
920 kontext "PasswordDlg"
921 if ( PasswordDlg.exists() ) then
926 ' LOAD: Master Password Dialog
927 kontext "MasterPasswordEnter"
928 if ( MasterPasswordEnter.exists() ) then
930 warnlog( CFN & "Master Password dialog displayed. Tests are likely to fail" )
934 ' LOAD: Filter selection dialog
935 Kontext "Filterauswahl"
936 if ( FilterAuswahl.exists() ) then
941 ' LOAD: ASCII Filter Options dialog
942 kontext "ASCIIFilterOptionen"
943 if AsciiFilterOptionen.Exists() then
948 ' LOAD/SAVE: Some other dialogs that may interrupt file I/O
950 if ( Active.exists() ) then
951 printlog( Active.getText() )
953 ' This is most likely a warning
954 if ( Active.getButtonCount() = 1 ) then
959 ' This is probably the update links dialog
960 if ( Active.getButtonCount() = 2 ) then
965 ' This is probably the styles not matching dialog
966 if ( Active.getButtonCount() = 3 ) then
977 case -1 : printlog( CFN & "Timeout reached, rc = " & iWait )
978 case -2 : printlog( CFN & "Macro security warning displayed, rc = " & iWait )
979 case -3 : printlog( CFN & "Password dialog (load) displayed, rc = " & iWait )
980 case -4 : printlog( CFN & "Password dialog (save) displayed, rc = " & iWait )
981 case -5 : printlog( CFN & "Filter Selection dialog displayed, rc = " & iWait )
982 case -6 : printlog( CFN & "ASCII filter options dialog displayed, rc = " & iWait )
983 case -7 : printlog( CFN & "A dialog box is in the way (1 button), rc = " & iWait )
984 case -8 : printlog( CFN & "A dialog box is in the way (2 buttons), rc = " & iWait )
985 case -9 : printlog( CFN & "A dialog box is in the way (3 buttons), rc = " & iWait )
986 case -10 : printlog( CFN & "Master Password Dialog displayed, rc = " & iWait )
987 case else : printlog( CFN & "File I/O completed in " & iWait & " seconds" )
991 if ( bWarnlog and ( iWait < 0 ) ) then
992 warnlog( CFN & "The messagebox was not expected at this point" )