/* //!LABEL= Delete empty textlines //!SHORTCUT= //!ENABLED= // --------------------------------------------------------------- // // capDeleteEmptyTextlines.fsl // Copyright 2002 Michael Müller-Hillebrand, All Rights Reserved. // http://cap-studio.de // mailto:info@cap-studio // Version: // 1.0 - 2002-01-10 mmh // 1.1 - 2002-08-06 mmh German and Menu install // 1.2 - 2002-08-09 mmh DEBUG: Cursor in deleted TextLine crashes FM // Resolved by setting TextSelection to Flow // // Purpose: // Check all textlines in book or document: // Delete if it is empty or contains only one space // Report number of deleted/found textlines // // To do: // // --------------------------------------------------------------- /* PSEUDO CODE Is Book open? Loop BookComponents Process Doc Is Doc Open? Process Doc sub Process Doc: Loop Graphics of type TextLine Check .Text property */ Run Main; // --------------------------------------------------------------- Sub Main Local vSessionLabel; // Set String Variables If ((cMsgActiveDoc = 0) or (cMsgActiveDoc = '')) Set cMsgActiveDoc = '…ffnen Sie ein Buch oder Dokument.'; EndIf Set cMsgTLDocs = 'Untersuchte Dokumente: '; Set cMsgTLFound = 'Gefundene Textzeilen: '; Set cMsgTLEmpty = 'Leere und damit gelšschte Textzeilen: '; Set cMsgFinish = 'Alle Dokumente sind offen und nicht gespeichert.'; Set vAllCnt = 0; Set vDelCnt = 0; Set vNumberOfDocs = 0; Set vCurrentBook = 0; Set vCurrentDoc = 0; Set vReportDoc = 0; If (ActiveBook) Set vCurrentBook = ActiveBook; Else If (ActiveDoc) Set vCurrentDoc = ActiveDoc; Else MsgBox cMsgActiveDoc Mode(Warn); LeaveSub; EndIf EndIf // Set vSessionLabel = Session.Label; If (vCurrentBook) Run subProcessBook Using pCurrentBook(vCurrentBook); Set vCurrentBook.IsInFront = True; Else If (vCurrentDoc) Run subProcessDoc Using pCurrentDoc(vCurrentDoc); Else MsgBox cMsgActiveDoc Mode(Warn); LeaveSub; EndIf EndIf // Set Session.Label = vSessionLabel; Display cMsgTLDocs + vNumberOfDocs + CharCR + cMsgTLFound + vAllCnt + CharCR + cMsgTLEmpty + vDelCnt + CharCR + CharCR + cMsgFinish; EndSub // Main // ----------------------------------------------------------------------- // --------------------------------------------------------------- Sub subProcessBook Using pCurrentBook Local vCurBkBomp; Loop ForEach(BookComponent) In(pCurrentBook) LoopVar(vCurBkBomp) Run subIsDocOpenAlready FileName(vCurBkBomp.Name) Returns vDocObj(vCurrentDoc) Returns vDocIsOpen; If (vCurrentDoc = 0) Set ErrorCode = 0; Open Document File(vCurBkBomp.Name) NewVar(vCurrentDoc) UpdateTextReferences(No) UpdateXRefs(No) RefFileNotFound(AllowAllRefFilesUnFindable) MakeVisible(True) AlertUserAboutFailure(False) MakeIconic(True) ; // If (ErrorCode) // If the document could not be opened, write message to console. Write Console 'Dokument '+vCurBkBomp.Name+' konnte nicht gešffnet werden.'; EndIf EndIf If (vCurrentDoc) // Set vCurrentDoc.IsIconified = false; Set vCurrentDoc.IsInFront = true; Run subProcessDoc Using pCurrentDoc(vCurrentDoc); // If (vDocIsOpen = 0) // Close Document DocObject(vCurrentDoc) IgnoreMods; // EndIf EndIf EndLoop EndSub // subProcessBook // --------------------------------------------------------------- Sub subProcessDoc Using pCurrentDoc Local vGphVar; Local vNextGphVar; Set pCurrentDoc.IsInFront = True; If (pCurrentDoc.TextSelection) If (pCurrentDoc.TextSelection.Begin.Object.Objectname = 'TextLine') Set pCurrentDoc.TextSelection = pCurrentDoc.MainFlowInDoc; EndIf EndIf Set vGphVar = pCurrentDoc.FirstGraphicInDoc; Loop While(vGphVar) Set vNextGphVar = vGphVar.NextGraphicInDoc; If (vGphVar.Objectname = 'TextLine') Set vAllCnt = vAllCnt + 1; If ((vGphVar.Text = '') or (vGphVar.Text = ' ')) Delete Object(vGphVar); Set vDelCnt = vDelCnt + 1; EndIf EndIf Set vGphVar = vNextGphVar; EndLoop Set vNumberOfDocs = vNumberOfDocs + 1; EndSub // subProcessDoc // --------------------------------------------------------------- Sub subIsDocOpenAlready Using Filename vDocObj vDocIsOpen // subIsDocOpenAlready subroutine checks to see if documents are already open. // Local TFileName; Local TestDocObj; Local TName; Get String FromString(Filename) Uppercase NewVar(TFileName); // Upper case the string Set vDocObj = 0; Loop ForEach(Doc) In(Session) LoopVar(TestDocObj) Get String FromString (TestDocObj.Name) Uppercase NewVar(TName); // Upper case the string If (TName = TFileName) Set vDocObj = TestDocObj; Set vDocIsOpen = True; LeaveLoop; Else Set vDocIsOpen = False; EndIf EndLoop EndSub // subIsDocOpenAlready // -----------------------------------------------------------------------