version 6.01 1 MainForm PrintRtfForm 3 16 5 0 0 6 1 0 5 0 0 0 53 4 1 2 2 0 0 0 793 546 C:\WINDOWS\Profiles\woi\Eigene Dateien\HTC_P4350 My Documents\TreeEdit\TreeEdit32.ico 4 FormLib.dll HardwareDesktop.dll RichTextBoxDesktop.dll TreeView.dll 3 TreeView.dll FormLib.dll Hardware.dll 15 previewbox:RichTextBoxDesktop node:Node fontdialog1:FontDialog treeiteratorposition:Node depthnode:Node treeiteratorparentnode:Node lastselectednode:Node filestopnode:Node tempnode2:Node tempnode1:Node mainformlib:FormLib tree:TreeView tempnode3:Node hardware1:Hardware maincontextmenu:ContextMenu Sub designer addform(MainForm,"TreeEdit","",222,255,222)@ addarraylist(mainform,DeletedNodeList,85,25,80,25)@ addarraylist(mainform,NodeList,0,25,80,25)@ addsavedialog(mainform,SaveDialog,30,0,TreeEdit File|*.tef|Text File|*.txt|All Files|*.*)@ addopendialog(mainform,OpenDialog,0,0,TreeEdit Files|*.tef|Text Files|*.txt|All Files|*.*)@ addlabel(mainform,TreeViewSpace,0,-153,240,90,"Reserved for TreeView",222,255,222,0,0,0,True,False,9)@ addtextbox(mainform,textBoxNodeName,0,90,240,22,"Node name",196,255,196,0,0,0,True,True,False,9)@ addtextbox(mainform,textBoxNodeText,0,110,240,40,"Node text",222,255,222,0,0,0,True,True,True,9)@ addbutton(mainform,buttonAddBefore,3,160,55,23,"Be&fore",212,208,200,0,0,0,True,True,8)@ addbutton(mainform,buttonAddBelow,62,160,55,23,"Be&low",212,208,200,0,0,0,True,True,8)@ addbutton(mainform,buttonAddAfter,121,160,55,23,"Af&ter",212,208,200,0,0,0,True,True,8)@ addbutton(mainform,buttonDelete,180,160,55,23,"&Delete",212,208,200,0,0,0,True,True,8)@ addpanel(mainform,panelSearch,0,190,240,80,222,222,222,True,False)@ addlabel(panelsearch,labelReplace,3,31,65,21,"Repl. with:",222,222,222,0,0,0,True,True,9)@ addlabel(panelsearch,labelSearch,3,6,60,21,"Search:",222,222,222,0,0,0,True,True,9)@ addtextbox(panelsearch,textBoxSearch,70,3,165,22,"",255,255,255,0,0,0,True,True,False,9)@ addtextbox(panelsearch,textBoxReplace,70,28,165,22,"",255,255,255,0,0,0,True,True,False,9)@ addbutton(panelsearch,buttonFind,3,53,70,23,"Find &Next",212,208,200,0,0,0,True,True,8)@ addbutton(panelsearch,buttonReplace,77,53,70,23,"&Replace",212,208,200,0,0,0,True,True,8)@ addbutton(panelsearch,buttonReplaceAll,151,53,80,23,"Replace &All",212,208,200,0,0,0,True,True,8)@ addbutton(mainform,buttonShowTree,3,57,80,23,"&Show Tree",212,208,200,0,0,0,True,False,8)@ r addmenuitem(mainform,mnuFile,"&File",True,False)@r addmenuitem(mnufile,mnuFileNew,"&New",True,False)@r addmenuitem(mnufile,mnuFileOpen,"&Open",True,False)@r addmenuitem(mnufile,mnuFileRecent,"&Recent Files",True,False)@r addmenuitem(mnufilerecent,mnuFileRecent0,"(none)",False,False)@r addmenuitem(mnufilerecent,mnuFileRecent1,"(none)",False,False)@r addmenuitem(mnufilerecent,mnuFileRecent2,"(none)",False,False)@r addmenuitem(mnufilerecent,mnuFileRecent3,"(none)",False,False)@r addmenuitem(mnufile,mnuFileSave,"&Save",False,False)@r addmenuitem(mnufile,mnuFileSaveAs,"S&ave As...",False,False)@r addmenuitem(mnufile,mnuFileQuit,"&Quit",True,False)@r addmenuitem(mnufile,mnuFileSeparator1,"-",True,False)@r addmenuitem(mnufile,mnuFilePrintRtf,"Print or RTF export...",True,False)@r addmenuitem(mnufile,mnuFileFileStatistics,"File S&tatistics",True,False)@r addmenuitem(mnufile,mnuFileInfo,"&Info",True,False)@r addmenuitem(mainform,mnuEdit,"&Edit",True,False)@r addmenuitem(mnuedit,mnuEditCut,"Cu&t",False,False)@r addmenuitem(mnuedit,mnuEditCopy,"&Copy",True,False)@r addmenuitem(mnuedit,mnuEditPaste,"&Paste",True,False)@r addmenuitem(mnuedit,mnuEditTree,"T&ree",True,False)@r addmenuitem(mnuedittree,mnuEditTreePasteBefore,"Paste Be&fore",True,False)@r addmenuitem(mnuedittree,mnuEditTreePasteAfter,"Paste Af&ter",True,False)@r addmenuitem(mnuedittree,mnuEditTreeSeparator1,"-",True,False)@r addmenuitem(mnuedittree,mnuEditTreeExpandAll,"&Expand All",True,False)@r addmenuitem(mnuedittree,mnuEditTreeCollapseAll,"&Collapse All",True,False)@r addmenuitem(mnuedittree,mnuEditTreeSeparator2,"-",True,False)@r addmenuitem(mnuedittree,mnuEditTreeShowTree,"&Show Tree",False,False)@r addmenuitem(mnuedit,mnuEditNote,"&Note",True,False)@r addmenuitem(mnueditnote,mnuEditNoteAddBefore,"Add Note Be&fore",True,False)@r addmenuitem(mnueditnote,mnuEditNoteAddBelow,"Add Note Be&low",True,False)@r addmenuitem(mnueditnote,mnuEditNoteAddAfter,"Add Note Af&ter",True,False)@r addmenuitem(mnueditnote,mnuEditNoteSeparator1,"-",True,False)@r addmenuitem(mnueditnote,mnuEditNoteDelete,"&Delete Note Tree",True,False)@r addmenuitem(mnuedit,mnuEditFind,"&Find",True,False)@r addmenuitem(mnueditfind,mnuEditFindFind,"&Find/Replace...",True,False)@r addmenuitem(mnueditfind,mnuEditFindNext,"Find &Next",True,False)@r addmenuitem(mnueditfind,mnuEditFindReplaceNext,"&Replace Next",True,False)@r addmenuitem(mnueditfind,mnuFindReplaceAll,"Replace &All",True,False)@r addmenuitem(mnueditfind,mnuEditFindSeparator1,"-",True,False)@r addmenuitem(mnueditfind,mnuEditFindMatchCase,"Match &Case",True,False)@r addmenuitem(mnueditfind,mnuEditFindWrapSearch,"&Wrap Search",True,False)@r addmenuitem(mnuedit,mnuEditOptions,"&Options",True,False)@r addmenuitem(mnueditoptions,mnuEditOptionsShowCheckboxes,"Show &Checkboxes",True,False)@r addmenuitem(mnueditoptions,mnuEditOptionsSaveAsASCII,"Save As &ASCII",True,False)@r addmenuitem(mnueditoptions,mnuEditOptionsSeparator1,"-",True,False)@r addmenuitem(mnueditoptions,mnuEditOptionsKeyboardSpace,"&Keyboard Space",True,False)@r addmenuitem(mnueditoptions,mnuEditOptionsAutomaticFullscreen,"Automatic &Fullscreen",True,True)@r addmenuitem(mnueditoptions,mnuEditOptionsLargeTree,"&Large Tree",True,False)@ addform(PrintRtfForm,"Print and RTF Export","",220,220,220)@ addbutton(printrtfform,buttonPrintDefaults,665,520,125,23,"Reset to Defaults",212,208,200,0,0,0,True,True,9)@ addcheckbox(printrtfform,CheckBoxCheckboxes,120,395,135,25,"Show checkboxes",220,220,220,0,0,0,True,True,False,9)@ addcheckbox(printrtfform,CheckBoxNoteNumbers,5,395,115,25,"Number notes",220,220,220,0,0,0,True,True,False,9)@ addsavedialog(printrtfform,SaveDialogPrint,760,475,RTF Files|*.rtf)@ addbutton(printrtfform,buttonPrintExportRtf,335,520,85,23,"Export RTF",212,208,200,0,0,0,True,True,9)@ addbutton(printrtfform,buttonPrintPrint,255,520,75,23,"Print",212,208,200,0,0,0,True,True,9)@ addbutton(printrtfform,buttonPrintSetup,165,520,85,23,"Print Setup",212,208,200,0,0,0,True,True,9)@ addbutton(printrtfform,buttonPrintPreview,85,520,75,23,"Preview",212,208,200,0,0,0,True,True,9)@ addcheckbox(printrtfform,CheckBoxExtraSkipAfterName,5,455,250,25,"Add extra line skip after note name",220,220,220,0,0,0,True,True,False,9)@ addcheckbox(printrtfform,CheckBoxExtraSkipText,5,485,250,25,"Add extra line skip after each paragraph",220,220,220,0,0,0,True,True,False,9)@ addcheckbox(printrtfform,CheckBoxExtraSkipBeforeName,5,425,250,25,"Add extra line skip before note name",220,220,220,0,0,0,True,True,False,9)@ addbutton(printrtfform,buttonPrintRtfClose,5,520,75,23,"Close",212,208,200,0,0,0,True,True,9)@ addnum(printrtfform,NumL1Right,375,30,60,0,100,255,255,255,True,True)@ addnum(printrtfform,NumL1Hanging,310,30,60,0,100,255,255,255,True,True)@ addnum(printrtfform,NumL1Left,245,30,60,0,100,255,255,255,True,True)@ addbutton(printrtfform,buttonL1Font,145,30,95,23,"Choose Font",212,208,200,0,0,0,True,True,9)@ addlabel(printrtfform,LabelLevel1,5,30,130,23,"Note Name Level 1:",220,220,220,0,0,0,True,True,9)@ addnum(printrtfform,NumT1Right,375,60,60,0,100,255,255,255,True,True)@ addnum(printrtfform,NumT1Hanging,310,60,60,0,100,255,255,255,True,True)@ addnum(printrtfform,NumT1Left,245,60,60,0,100,255,255,255,True,True)@ addbutton(printrtfform,buttonT1Font,145,60,95,23,"Choose Font",212,208,200,0,0,0,True,True,9)@ addlabel(printrtfform,LabelText1,5,60,130,23,"Note Text Level 1:",220,220,220,0,0,0,True,True,9)@ addlabel(printrtfform,LabelTitles,245,5,190,25," Left Hanging Right",220,220,220,0,0,0,True,True,9)@ End Sub @EndOfDesignText@' TreeEdit ' ' Copyleft 2007-2008 Jens R. Woinowski ' http://www.woinowski.eu ' ' TreeEdit is published under the terms AND conditions of the GNU ' General Public Licence, Version 3 ' ' If you obtained the official TreeEditSetup.Exe OR CAB you will find ' the source code in the installation target of your handheld device. ' ' Any DLLs required to run this are NOT open source and subject to copyright by other ' copyright holders (most of them Anywhere Software, home of B4PPC) ' ' Remark for anyone trying to make any patent claims against anybody because of this code: ' Tree navigation and manipulation is state of the art of the 1970's (or even earlier) ' and topic of the third semester (or earlier) in a typical German university computer ' science curriculum ' ' Compiling requires Basic4PPC Version 6.0 and the following libraries ' ' Formlib ' Hardware(Device and Desktop) ' TreeView ' RichTextBoxDesktop Sub Globals #Region TreeIterator Globals TreeIteratorTreeViewName = "" TreeIteratorDirectionForward = true TreeIteratorFinished = false TreeIteratorCallOnDown = "" TreeIteratorCallOnClosed = "" TreeIteratorCallOnUp = "" #End Region #Region Tree Globals cNewNode = "New Node" gTreeDirty = false gNewNodeNumber = 0 gLastSelection = false cMaxNodeDepth = 10 #End Region #Region GUI Globals gMsgboxChoice = 0 cConfirmationNewFileTitle = "New File" cConfirmationOpenFileTitle = "Open File" cConfirmationQuitTitle = "Quit TreeEdit" cConfirmationSaveChanges = "File has been altered." & crlf & "Save changes?" cConfirmationHideCheckboxesTitle = "Hide Checkboxes" cConfirmationHideCheckboxesText = "Hiding checkboxes will uncheck all notes. Continue?" cInfoTitle = "TreeEdit Info" cInfoText = "TreeEdit 2.0 beta" & crlf & "Open Source Software" & crlf & "©/GNU GPL 2007-2008" & crlf & "Jens R. Woinowski" & crlf & "www.woinowski.eu" cSearchWrappedTitle = "Reached Last Note" cSearchWrappedText = "Search reached last node, continue with first note?" cSearchReplacedTitle = "Replace Info" cSearchReplacedText = "Replaced # occurences." cStatNodes = "Notes: " cStatNodesNotEmpty = " w/o empty: " cStatNodesChecked = " checked: " cStatDepth = "Depth: " cStatWords = "Words: " cStatWordsText = " w/o titles: " cStatWordsChecked = " checked nodes: " cStatTitle = "File Statistics" cFileWriteErrorTitle = "Write Error" cFileWriteErrorText = "Could not save file correctly. Maybe the file is write protected." cFileWriteReadErrorTitle = "Read Error" cFileReadText = "Could not open file." cFileReadErrorTitle = "Write Error" cFileReadErrorText = "Could not open file correctly. Maybe the file does not exist." cFileReadErrorTitle = "Read Error" cFileWriteReadText = "Could not open file." cMnuTreeOnTop = "Tree &On Top" cQuote = Chr(34) gFocusControl = "" gSearchFocusControl = "textBoxNodeName" gLastSearchControl = "" gSearchTrueSearchSearch = "" gSearchTrueSearchTextBox = "" gSearchFound = -1 gFinished = false gFound = false gSearchWrap = true gSearchIsReplaceAll = false cTreeEditTitle = "TreeEdit" cSpaceBeforeButtons = 3 cSpaceBottom = 3 cSpaceKeyboard = 50 cVerticalTree = 0.35 cHorizontalTree = 0.4 cLargeTree = 0.2 gFreeScreenHeight = 0 gVerticalLayout = true gButtonTop = 0 gInit = true gKeyboardSpace = false gTreeOnTop = false Dim Type(menuName, fullName) LastFiles(4) LastFiles(0).fullName = "" LastFiles(1).fullName = "" LastFiles(2).fullName = "" LastFiles(3).fullName = "" Dim words(0) As String gPrintRtfFormRealClose = false #Region ClipBoard Globals gClipboardString = "" gClipboardNodeDepth = 0 #End Region #End Region #Region File Save/Open Globals cFileModeString = 1 cFileModeFile = 2 gFileMode = cFileModeFile gFileString = "" gFileStringPosition = 0 gFileDepth = 0 gFileCurrentDepth = 0 cSaveEncodingUTF8 = "" cSaveNocheckboxes = "" cSaveCheckboxes = "" cSaveChecked = "" cSaveFormatBegin = "" cSaveFormatEnd = "" cSaveFormatBoxesBegin = "" cSaveFormatBoxesEnd = "" cSaveNodeBegin = "" cSaveNodeEnd = "" cSaveNameBegin = "" cSaveNameEnd = "" cSaveTextBegin = "" cSaveTextEnd = "" gFileName = "" MainForm.Text = cTreeEditTitle gFile = "" gFileLookahead = "" gFileCurrentLine = "" gFileCurrentLineNo = 0 cErrorInLine = "In Line: " cExpected = "Expected: " cReadLine = "Found: " cFileOpenError = "Open File Error" #End Region #Region Print Format Globals Dim gFormatData(0) As String cMaxFormatUsed = 5 Dim Type ( Alignment, Font, Bold, Italic, StrikeOut, Underline, FontSize, FontScript, LeftIndent, HangingIndent, RightIndent) gFormats(10,2) gCheckBoxCheckboxesChecked = false gCheckBoxNoteNumbersChecked = false gCheckBoxExtraSkipAfterNameChecked = false gCheckBoxExtraSkipTextChecked = false gCheckBoxExtraSkipBeforeNameChecked = false gFormats(0,0).Alignment = 0 '0 left, 1 right, 2 centred gFormats(0,0).Font= "Arial" gFormats(0,0).Bold = True gFormats(0,0).Italic = False gFormats(0,0).StrikeOut = False gFormats(0,0).Underline = False gFormats(0,0).FontSize = 12 gFormats(0,0).FontScript = 1 '0 Western,1 Default,2 Symbol,128 Japanese,161 Greek,162 Turkish '163 Vietnamese,177 Hebrew,178 Arabic,186 Baltic,204 Cyrillic,238 Central European gFormats(0,0).LeftIndent = 0 gFormats(0,0).HangingIndent = 0 gFormats(0,0).RightIndent = 0 gFormats(0,1).Alignment = 0 '0 left, 1 right, 2 centred gFormats(0,1).Font= "Times New Roman" gFormats(0,1).Bold = False gFormats(0,1).Italic = False gFormats(0,1).StrikeOut = False gFormats(0,1).Underline = False gFormats(0,1).FontSize = 9.75 gFormats(0,1).FontScript = 1 '0 Western,1 Default,2 Symbol,128 Japanese,161 Greek,162 Turkish '163 Vietnamese,177 Hebrew,178 Arabic,186 Baltic,204 Cyrillic,238 Central European gFormats(0,1).LeftIndent = 0 gFormats(0,1).HangingIndent = 0 gFormats(0,1).RightIndent = 0 cMaxIndent = 100 cCheckboxUnchecked = Chr(168) ' Requires Wingdings font! cCheckboxChecked = Chr(254) ' Requires Wingdings font! gPrintFirstLine = true gPrintLevel = 0 gIndentNextText = -1 Dim gPrintNumbers(cMaxNodeDepth + 1) #End Region End Sub Sub App_Start #Region Main Form Init gInit = true MainForm.Show MainFormLib.New1("MainForm", B4PObject(1)) Tree.New1("MainForm", 0, 0, 240, 90) Tree.Color = Rgb(255, 255, 255) MainContextMenu.New1 MainContextMenu.AddItem("Cut") MainContextMenu.AddItem("Copy") MainContextMenu.AddItem("Paste") MainFormLib.AddContextMenu("textBoxNodeName", MainContextMenu.Value) MainFormLib.AddContextMenu("textBoxNodeText", MainContextMenu.Value) MainFormLib.AddContextMenu("textBoxSearch", MainContextMenu.Value) MainFormLib.AddContextMenu("textBoxReplace", MainContextMenu.Value) AddEvent("mnuFileRecent0", Click, "mnuFileRecentX_Click") AddEvent("mnuFileRecent1", Click, "mnuFileRecentX_Click") AddEvent("mnuFileRecent2", Click, "mnuFileRecentX_Click") AddEvent("mnuFileRecent3", Click, "mnuFileRecentX_Click") Hardware1.New1 If CPPC Then cSpaceKeyboard = Hardware1.SIPHeight - (cSpaceBeforeButtons + buttonAddBefore.Height + cSpaceBottom) End If gClipboardString = Hardware1.GetClipboardData SetClipboardNodeDepth If Not(CPPC) Then MainFormLib.MinimizeBox = True End If #End Region #Region Form Print Rtf Init If CPPC Then mnuFilePrint.Enabled = false Else FontDialog1.New1 SetDefaultPrintFormats End If ' Add Further controls plus events For i = 1 To 5 If i > 1 Then If i < 5 Then labelEnd = ":" Else labelEnd = " and up:" End If AddNumUpDown ("PrintRtfForm","NumL" & i & "Right",375, 30 + (i - 1) * 75,60) AddNumUpDown ("PrintRtfForm","NumL" & i & "Hanging",310, 30 + (i - 1) * 75,60) AddNumUpDown ("PrintRtfForm","NumL" & i & "Left",245, 30 + (i - 1) * 75,60) AddButton("PrintRtfForm","buttonL" & i & "Font",145, 30 + (i - 1) * 75,95,23,"Choose Font") AddLabel("PrintRtfForm","LabelLevel" & i,5, 30 + (i - 1) * 75,145,23, "Note Name Level " & i & labelEnd) Control("LabelLevel" & i, Label).Color = LabelLevel1.Color AddNumUpDown ("PrintRtfForm","NumT" & i & "Right",375, 60 + (i - 1) * 75,60) AddNumUpDown ("PrintRtfForm","NumT" & i & "Hanging",310,60 + (i - 1) * 75,60) AddNumUpDown ("PrintRtfForm","NumT" & i & "Left",245,60 + (i - 1) * 75,60) AddButton("PrintRtfForm","buttonT" & i & "Font",145,60 + (i - 1) * 75,95,23,"Choose Font") AddLabel("PrintRtfForm","LabelText" & i,5,60 + (i - 1) * 75,145,23,"Note Text Level " & i & labelEnd) Control("LabelText" & i, Label).Color = LabelLevel1.Color End If AddEvent("buttonL" & i & "Font", Click, "buttonXYFont_Click") AddEvent("buttonT" & i & "Font", Click, "buttonXYFont_Click") AddEvent("NumL" & i & "Left", ValueChanged, "NumXYZ_ValueChanged") AddEvent("NumT" & i & "Left", ValueChanged, "NumXYZ_ValueChanged") AddEvent("NumL" & i & "Hanging", ValueChanged, "NumXYZ_ValueChanged") AddEvent("NumT" & i & "Hanging", ValueChanged, "NumXYZ_ValueChanged") AddEvent("NumL" & i & "Right", ValueChanged, "NumXYZ_ValueChanged") AddEvent("NumT" & i & "Right", ValueChanged, "NumXYZ_ValueChanged") Control("NumL" & i & "Left", NumUpDown).Maximum = cMaxIndent Control("NumT" & i & "Left", NumUpDown).Maximum = cMaxIndent Control("NumL" & i & "Hanging", NumUpDown).Maximum = cMaxIndent Control("NumT" & i & "Hanging", NumUpDown).Maximum = cMaxIndent Control("NumL" & i & "Right", NumUpDown).Maximum = cMaxIndent Control("NumT" & i & "Right", NumUpDown).Maximum = cMaxIndent Next i previewPos = NumL1Right.Left + NumL1Right.Width + 10 PreviewBox.New1("PrintRtfForm", previewPos, 30, PrintRtfForm.Width - (previewPos + 10), PrintRtfForm.Height - 60) AddEvent("CheckBoxCheckboxes", Click, "CheckBoxX_Click") AddEvent("CheckBoxNoteNumbers", Click, "CheckBoxX_Click") AddEvent("CheckBoxExtraSkipBeforeName", Click, "CheckBoxX_Click") AddEvent("CheckBoxExtraSkipAfterName", Click, "CheckBoxX_Click") AddEvent("CheckBoxExtraSkipText", Click, "CheckBoxX_Click") #End Region #Region TreeIterator Init Code TreeIteratorPosition.New1 TreeIteratorParentNode.New1 #End Region #Region Tree Init Code TempNode1.New1 TempNode2.New1 TempNode3.New1 DepthNode.New1 LastSelectedNode.New1 FileStopNode.New1 NewTree(true) buttonShowTree_Click buttonAddBefore.Focus gInit = false MainForm_AfterInit Resize Tree_AfterSelect End Sub #End Region #Region TreeIterator Functions Sub TreeIterator_Init(treeName, forward, callDown, callNext, callUp) TreeIteratorTreeViewName = treeName TreeIteratorDirectionForward = forward If callDown = "" Then TreeIteratorCallOnDown = "TreeIteratorNop" Else TreeIteratorCallOnDown = callDown End If If callNext = "" Then TreeIteratorCallOnClosed = "TreeIteratorNop" Else TreeIteratorCallOnClosed = callNext End If If callUp = "" Then TreeIteratorCallOnUp = "TreeIteratorNop" Else TreeIteratorCallOnUp = callUp End If If Control(treeName, TreeView).Count = 0 Then TreeIteratorFinished = true Return Else TreeIteratorFinished = false CallSub(TreeIteratorCallOnDown) If forward Then ' Forward: Start node is root of TreeView TreeIteratorPosition.Value = Control(treeName, TreeView).GetNode(0) Else ' Backward: Start node would be last node of forward iteration TreeIteratorPosition.Value = Control(treeName, TreeView).GetNode(Control(treeName, TreeView).Count -1) Do While TreeIteratorPosition.Count > 0 TreeIteratorPosition.Value = TreeIteratorPosition.GetNode(TreeIteratorPosition.Count -1 ) Loop End If End If End Sub Sub TreeIterator_Next If TreeIteratorFinished Then Return If TreeIteratorPosition.IsRoot Then ' Iteration for root nodes If TreeIteratorDirectionForward Then ' Forward iteration If TreeIteratorPosition.Count > 0 Then ' Current node has children TreeIteratorPosition.Value = TreeIteratorPosition.GetNode(0) CallSub(TreeIteratorCallOnDown) Else ' Current node has no children index = Control(TreeIteratorTreeViewName, TreeView).IndexOfNode(TreeIteratorPosition.Value) CallSub(TreeIteratorCallOnClosed) ' CUrrent node is finished If index = Control(TreeIteratorTreeViewName, TreeView).Count - 1 Then ' We are at the last node CallSub(TreeIteratorCallOnUp) ' Up to level '0' TreeIteratorFinished = true Else ' Take next root node, stay on same level! TreeIteratorPosition.Value = Control(TreeIteratorTreeViewName, TreeView).GetNode(index + 1) End If End If Else ' Backward iteration (NO CallOn* !!!) index = Control(TreeIteratorTreeViewName, TreeView).IndexOfNode(TreeIteratorPosition.Value) If index > 0 Then ' Find last node of (root) sibling before the current node TreeIteratorPosition.Value = Control(TreeIteratorTreeViewName, TreeView).GetNode(index -1) Do While TreeIteratorPosition.Count > 0 TreeIteratorPosition.Value = TreeIteratorPosition.GetNode(TreeIteratorPosition.Count -1 ) Loop Else ' We are at the last node TreeIteratorFinished = true End If End If Else ' Iteration for non-root nodes If TreeIteratorDirectionForward Then ' Forward iteration If TreeIteratorPosition.Count > 0 Then ' Current node has children TreeIteratorPosition.Value = TreeIteratorPosition.GetNode(0) CallSub(TreeIteratorCallOnDown) Else ' Current node has no children TreeIteratorParentNode.Value = TreeIteratorPosition.Parent index = TreeIteratorParentNode.IndexOfNode(TreeIteratorPosition.Value) CallSub(TreeIteratorCallOnClosed) 'Current node is finished ' We have to climb up to the first node with children - if existing Do While Not(TreeIteratorParentNode.IsRoot) AND (index = TreeIteratorParentNode.Count - 1) TreeIteratorPosition.Value = TreeIteratorParentNode.Value TreeIteratorParentNode.Value = TreeIteratorParentNode.Parent index = TreeIteratorParentNode.IndexOfNode(TreeIteratorPosition.Value) CallSub(TreeIteratorCallOnClosed) 'Current node is finished CallSub(TreeIteratorCallOnUp) Loop If TreeIteratorParentNode.IsRoot AND (index = TreeIteratorParentNode.Count - 1) Then ' Has the root node a sibling below? TreeIteratorPosition.Value = TreeIteratorParentNode.Value index = Control(TreeIteratorTreeViewName, TreeView).IndexOfNode(TreeIteratorPosition.Value) CallSub(TreeIteratorCallOnClosed) 'Current node is finished CallSub(TreeIteratorCallOnUp) If index = Control(TreeIteratorTreeViewName, TreeView).Count - 1 Then ' if no: we are finished TreeIteratorFinished = true Else ' if yes: continue with next root node, stay on same level! TreeIteratorPosition.Value = Control(TreeIteratorTreeViewName, TreeView).GetNode(index + 1) End If Else ' Take next node TreeIteratorPosition.Value = TreeIteratorParentNode.GetNode(index + 1) End If End If Else ' Backward iteration (NO CallOn* !!!) TreeIteratorParentNode.Value = TreeIteratorPosition.Parent index = TreeIteratorParentNode.IndexOfNode(TreeIteratorPosition.Value) If index = 0 Then ' Easy: parent of a node is before the node itself TreeIteratorPosition.Value = TreeIteratorParentNode.Value Else ' Find last node of sibling before the current node TreeIteratorPosition.Value = TreeIteratorParentNode.GetNode(index -1) Do While TreeIteratorPosition.Count > 0 TreeIteratorPosition.Value = TreeIteratorPosition.GetNode(TreeIteratorPosition.Count -1) Loop End If End If End If Return TreeIteratorFinished End Sub Sub TreeIteratorNop End Sub #End Region #Region MainForm Events #Region MainForm After Initialization and Close Event Sub MainForm_AfterInit If CPPC Then iniName = "TreeEditDevice.ini" Else iniName = "TreeEditDesktop.ini" End If ErrorLabel(StartAnyhow) If FileExist(AppPath & "\" & iniName) Then FileOpen(conf, AppPath & "\" & iniName, cRead) FileRead(conf) ' Ignore Version of INI file mnuEditFindMatchCase.Checked = StrToBool(FileRead(conf)) mnuEditFindWrapSearch.Checked = StrToBool(FileRead(conf)) mnuEditOptionsKeyboardSpace.Checked = StrToBool(FileRead(conf)) mnuEditOptionsAutomaticFullscreen.Checked = StrToBool(FileRead(conf)) mnuEditOptionsLargeTree.Checked = StrToBool(FileRead(conf)) For i = 0 To 3 CheckRecent(FileRead(conf), false) Next FileClose(conf) If ArrayLen(args()) > 0 AND FileExist(args(0)) Then CheckRecent(args(0), false) End If If mnuFileRecent0.Enabled Then gFileName = LastFiles(0).fullName FileOpenCurrent End If End If If CPPC Then gKeyboardSpace = mnuEditOptionsKeyboardSpace.Checked Else mnuEditOptionsKeyboardSpace.Text = cMnuTreeOnTop gTreeOnTop = mnuEditOptionsKeyboardSpace.Checked End If Return StartAnyhow: FileClose(conf) End Sub Sub MainForm_Close If Not(confirmCloseFile (cConfirmationQuitTitle)) Then MainForm.CancelClose If CPPC Then iniName = "TreeEditDevice.ini" Else iniName = "TreeEditDesktop.ini" End If ' ErrorLabel(StopAnyhow) FileOpen(conf, AppPath & "\" & iniName, cWrite) FileWrite(conf, "1.0") ' Ignore Version of INI file FileWrite(conf, "mnuEditFindMatchCase=" & BoolToStr(mnuEditFindMatchCase.Checked)) FileWrite(conf, "mnuEditFindWrapSearch=" & BoolToStr(mnuEditFindWrapSearch.Checked)) FileWrite(conf, "mnuEditOptionsKeyboardSpace=" & BoolToStr(mnuEditOptionsKeyboardSpace.Checked)) FileWrite(conf, "mnuEditOptionsAutomaticFullscreen=" & BoolToStr(mnuEditOptionsAutomaticFullscreen.Checked)) FileWrite(conf, "mnuEditOptionsLargeTree=" & BoolToStr(mnuEditOptionsLargeTree.Checked)) For i = 3 To 0 Step - 1 FileWrite(conf, LastFiles(i).fullName) Next FileClose(conf) Return StopAnyhow: FileClose(conf) End Sub Sub StrToBool(str) position = StrIndexOf(str,"=",0) If position > - 1 Then str = SubString(str, position + 1, StrLength(str) - (position + 1)) End If If str = "True" Then Return true Else Return false End If End Sub Sub BoolToStr(boolVar) If boolVar Then Return "True" Else Return "False" End If End Sub #End Region #Region Resize Event Sub MainFormLib_Resize AutoFullscreen End Sub Sub Hardware1_SIPChanged AutoFullscreen End Sub Sub Resize If gInit Then Return If MainForm.Height >= MainForm.Width OR gTreeOnTop Then gVerticalLayout = true Else gVerticalLayout = false End If gFreeScreenHeight = MainForm.Height If gKeyboardSpace AND Hardware1.SIPEnabled Then gFreeScreenHeight = gFreeScreenHeight - cSpaceKeyboard End If If panelSearch.Visible Then panelSearch.Height = cSpaceKeyboard + cSpaceBeforeButtons + buttonAddBefore.Height + cSpaceBottom gFreeScreenHeight = gFreeScreenHeight - panelSearch.Height gButtonTop = 0 Else gFreeScreenHeight = gFreeScreenHeight - (cSpaceBeforeButtons + buttonAddBefore.Height + cSpaceBottom) gButtonTop = gFreeScreenHeight + cSpaceBeforeButtons End If Tree.Visible = true If mnuEditOptionsLargeTree.Checked Then treeUses = cLargeTree Else treeUses = 0.0 End If If gVerticalLayout Then ' Size Tree treeUses = treeUses + cVerticalTree Tree.Width = MainForm.Width Tree.Height = gFreeScreenHeight * treeUses gFreeScreenHeight = gFreeScreenHeight - ( Tree.Height + textBoxNodeName.Height ) ' Place Node Name textBoxNodeName.Width = MainForm.Width textBoxNodeName.Left = 0 textBoxNodeName.Top = Tree.Height ' Place Node Text textBoxNodeText.Width = MainForm.Width textBoxNodeText.Height = gFreeScreenHeight textBoxNodeText.Left = 0 textBoxNodeText.Top = textBoxNodeName.Top + textBoxNodeName.Height Else ' Size Tree treeUses = treeUses + cHorizontalTree Tree.Width = MainForm.Width * treeUses Tree.Height = gFreeScreenHeight ' Place Node Name textBoxNodeName.Width = MainForm.Width - tree.Width textBoxNodeName.Left = tree.Width textBoxNodeName.Top = 0 ' Place Node Text textBoxNodeText.Width = MainForm.Width - tree.Width textBoxNodeText.Height = gFreeScreenHeight - textBoxNodeName.Height textBoxNodeText.Left = tree.Width textBoxNodeText.Top = textBoxNodeName.Top + textBoxNodeName.Height End If ' Place Panel If panelSearch.Visible Then panelSearch.Width = MainForm.Width panelSearch.Top = textBoxNodeText.Top + textBoxNodeText.Height End If ' Place Buttons buttonShowTree.Visible = false If gButtonTop = 0 Then buttonAddAfter.Visible = false buttonAddBefore.Visible = false buttonAddBelow.Visible = false buttonDelete.Visible = false Else buttonAddAfter.Visible = true buttonAddBefore.Visible = true buttonAddBelow.Visible = true buttonDelete.Visible = true buttonAddAfter.Top = gButtonTop buttonAddBefore.Top = gButtonTop buttonAddBelow.Top = gButtonTop buttonDelete.Top = gButtonTop buttonShowTree.Top = gButtonTop End If End Sub #End Region #Region Menu Click Events #Region Menu File Sub confirmCloseFile(title) gMsgboxChoice = 0 If Not(gTreeDirty) Then Return true gMsgboxChoice = Msgbox(cConfirmationSaveChanges, title, cMsgboxYesNoCancel, cMsgboxQuestion) If gMsgboxChoice = cNo Then Return true If gMsgboxChoice = cYes Then mnuFileSave_Click If gMsgboxChoice = cCancel Then Return false ' TODO: Save file Return true End If Return false End Sub Sub mnuFileNew_Click If confirmCloseFile(cConfirmationNewFileTitle) Then buttonShowTree_Click buttonAddBefore.Focus NewTree(true) mnuFileRecent0.Checked = false End If End Sub Sub mnuFileOpen_Click If confirmCloseFile(cConfirmationOpenFileTitle) Then gMsgboxChoice = OpenDialog.Show If gMsgboxChoice = cCancel Then Return buttonShowTree_Click buttonAddBefore.Focus NewTree(false) gFileName = OpenDialog.File FileOpenCurrent End If End Sub Sub FileOpenCurrent MainForm.Text = FileName(gFileName) loadResultOK = OpenTree(gFileName, cFileModeFile, "mnuEditOptionsSaveAsASCII", "mnuEditOptionsShowCheckboxes") If Not (loadResultOK) Then NewTree(true) End If If Tree.Count > 0 Then gLastSelection = false Tree.SelectedNode = Tree.GetNode(0) Tree.ExpandAll End If gTreeDirty = mnuEditOptionsShowCheckboxes.Checked UpdateActionsEnabled CheckRecent(gFileName, true) Tree.ExpandAll End Sub Sub mnuFileRecentX_Click no = SubString(Sender, StrLength(Sender)- 1, 1) ' The file is already open If Control("mnuFileRecent" & no).Checked Then Return End If If confirmCloseFile(cConfirmationOpenFileTitle) Then gFileName = LastFiles(no).fullName FileOpenCurrent End If End Sub Sub CheckRecent(fullName, check) isAt = -1 firstFree = -1 For i = 0 To 3 Control("mnuFileRecent" & i).Checked = false If LastFiles(i).fullName = fullName Then isAt = i End If If LastFiles(i).fullName = "" AND firstFree < 0 Then firstFree = i End If Next If fullName = "" OR fullName = eof Then Return End If menuName = FileName(fullName) ' If isAt >= 0 Then ' Control("mnuFileRecent" & isAt).Checked = true ' Return ' End If If firstFree >= 0 AND isAt < 0 Then Control("mnuFileRecent" & firstFree).Enabled = true Control("mnuFileRecent" & firstFree).Text = menuName LastFiles(firstFree).fullName = fullName LastFiles(firstFree).menuName = menuName isAt = firstFree Else If firstFree < 0 AND isAt < 0 Then isAt = 3 End If End If For i = isAt - 1 To 0 Step - 1 j = i + 1 Control("mnuFileRecent" & j).Text = Control("mnuFileRecent" & i).Text LastFiles(j).fullName = LastFiles(i).fullName LastFiles(j).menuName = LastFiles(i).menuName Next Control("mnuFileRecent" & "0").Checked = check Control("mnuFileRecent" & "0").Enabled = true Control("mnuFileRecent" & "0").Text = menuName LastFiles(0).fullName = fullName LastFiles(0).menuName = menuName End Sub Sub mnuFileSave_Click If gFileName = "" Then gMsgboxChoice = SaveDialog.Show If gMsgboxChoice = cCancel Then Return gFileName = SaveDialog.File MainForm.Text = FileName(gFileName) End If SaveTree(gFileName, cFileModeFile, mnuEditOptionsSaveAsASCII.Checked, mnuEditOptionsShowCheckboxes.Checked) gTreeDirty = mnuEditOptionsShowCheckboxes.Checked UpdateActionsEnabled CheckRecent(gFileName, true) End Sub Sub mnuFileSaveAs_Click gMsgboxChoice = SaveDialog.Show If gMsgboxChoice <> cCancel Then gFileName = SaveDialog.File MainForm.Text = FileName(gFileName) mnuFileSave_Click End If End Sub Sub mnuFileQuit_Click MainForm.Close End Sub Sub mnuFilePrintRtf_Click PrintRtfForm.Show End Sub Sub mnuFileFileStatistics_Click Tree_AfterSelect WaitCursor(true) wordCount = 0 textCount = 0 nodeCount = 0 emptyCount = 0 checkedWords = 0 checkedNodes = 0 maxDepth = 0 TreeIterator_Init("Tree", true, "", "", "") Do While Not (TreeIteratorFinished) text = TreeIteratorPosition.Text If TreeIteratorPosition.Checked Then checkedNodes = checkedNodes + 1 End If words() = StrSplit(text," ,;.:-_#'+~*´`^°!§$%&/()=?\<>|@€0123456789" & crlf & Chr(34) & Chr(8)) For i = 0 To ArrayLen(words()) - 1 If words(i) <> "" Then wordCount = wordCount + 1 End If Next text = GetNodeText("TreeIteratorPosition") If text = "" Then emptyCount = emptyCount + 1 End If words() = StrSplit(text," ,;.:-_#'+~*´`^°!§$%&/()=?\<>|@€0123456789" & crlf & Chr(34) & Chr(8)) For i = 0 To ArrayLen(words()) - 1 If words(i) <> "" Then wordCount = wordCount + 1 textCount = textCount + 1 If TreeIteratorPosition.Checked Then checkedWords = checkedWords + 1 End If End If Next depth = NodeDepth("TreeIteratorPosition") If depth > maxDepth Then maxDepth = depth End If nodeCount = nodeCount + 1 TreeIterator_Next Loop WaitCursor(false) notEmptyCount = nodeCount - emptyCount If mnuEditOptionsShowCheckboxes.Checked Then Msgbox(cStatNodes & nodeCount & crlf & cStatNodesNotEmpty & notEmptyCount& crlf & cStatNodesChecked & checkedNodes & crlf & cStatDepth & maxDepth & crlf& cStatWords & wordCount & crlf & cStatWordsText & textCount & crlf & cStatWordsChecked & checkedWords, cStatTitle, cMsgBoxOK, cMsgBoxAsterisk) Else Msgbox(cStatNodes & nodeCount & crlf & cStatNodesNotEmpty & notEmptyCount& crlf & cStatDepth & maxDepth & crlf& cStatWords & wordCount & crlf & cStatWordsText & textCount, cStatTitle, cMsgBoxOK, cMsgBoxAsterisk) End If End Sub Sub mnuFileInfo_Click Msgbox(cInfoText, cInfoTitle, cMsgboxOK, cMsgBoxAsterisk) End Sub #End Region #Region Menu Edit Sub mnuEditCut_Click mnuEditCopy_Click Select StrToLower(gFocusControl) Case "" mnuEditNoteDelete_Click Case "textboxnodename" DeleteSelection(gFocusControl) Case "textboxnodetext" DeleteSelection(gFocusControl) Case "textboxsearch" DeleteSelection(gFocusControl) Case "textboxreplace" DeleteSelection(gFocusControl) End Select End Sub Sub mnuEditCopy_Click gClipboardNodeDepth = 1 'We can paste simple text as a new node! Select StrToLower(gFocusControl) Case "" SaveTree("", cFileModeString, false, true) gClipboardString = gFileString If gFileDepth > 0 Then gClipboardNodeDepth = gFileDepth End If Case "textboxnodename" CopySelection(gFocusControl) Case "textboxnodetext" CopySelection(gFocusControl) Case "textboxsearch" CopySelection(gFocusControl) Case "textboxreplace" CopySelection(gFocusControl) End Select Hardware1.SetClipboardData(gClipboardString) UpdateActionsEnabled End Sub Sub mnuEditPaste_Click gTreeDirty = true If CPPC Then ' This only works on the Device, not the Desktop gClipboardString = Hardware1.GetClipboardData End If Tree_AfterSelect Select StrToLower(gFocusControl) Case "" If StrIndexOf(gClipBoardString, cSaveEncodingUTF8, 0) = 0 Then OpenTree(gClipboardString, cFileModeString, "", "") Else mnuEditNoteAddBelow_Click length = StrIndexOf(gClipBoardString, crlf, 0) If length = - 1 Then LastSelectedNode.Text = gClipboardString Else LastSelectedNode.Text = SubString(gClipboardString, 0, length) End If textBoxNodeName.Text = LastSelectedNode.Text textBoxNodeName.SelectionStart = 0 textBoxNodeName.SelectionLength = 0 End If Case Else If StrIndexOf(gClipBoardString, cSaveEncodingUTF8, 0) = 0 Then OpenTree(gClipboardString, cFileModeString, "", "") Else PasteSelection(gFocusControl) End If End Select End Sub Sub CopySelection(controlName) text = Control(controlName, TextBox).Text start = Control(controlName, TextBox).SelectionStart length = Control(controlName, TextBox).SelectionLength If start < 0 OR length < 0 OR start + length > StrLength(text) Then gClipboardString = "" Else gClipboardString = SubString(text, start, length) End If End Sub Sub DeleteSelection(controlName) text = Control(controlName, TextBox).Text start = Control(controlName, TextBox).SelectionStart length = Control(controlName, TextBox).SelectionLength If start < 0 OR length < 0 OR start + length > StrLength(text) Then Return Else leftText = SubString(text, 0, start) rightText = SubString(text, start + length, StrLength(text) - (start + length)) Control(controlName, TextBox).Text = leftText & rightText Control(controlName, TextBox).SelectionStart = start Control(controlName, TextBox).SelectionLength = 0 End If End Sub Sub PasteSelection(controlName) text = Control(controlName, TextBox).Text start = Control(controlName, TextBox).SelectionStart length = Control(controlName, TextBox).SelectionLength If start < 0 OR length < 0 OR start + length > StrLength(text) Then Return Else pasteLength = StrIndexOf(gClipBoardString, crlf, 0) If pasteLength = - 1 OR StrToLower(controlName) = "textboxnodetext" Then paste = gClipboardString Else paste = SubString(gClipboardString, 0, pasteLength) End If leftText = SubString(text, 0, start) If StrLength(text) - (start + length) > 0 Then rightText = SubString(text, start + length, StrLength(text) - (start + length)) Else rightText = "" End If Control(controlName, TextBox).Text = leftText & paste & rightText Control(controlName, TextBox).SelectionLength = 0 Control(controlName, TextBox).SelectionStart = start + StrLength(paste) End If End Sub Sub SetClipboardNodeDepth gClipboardNodeDepth = 1 'We can paste simple text as node! If StrIndexOf(gClipBoardString, cSaveEncodingUTF8, 0) = 0 Then TreeFileOpen(gClipBoardString, cFileModeString, cRead, false) FileReadNextLine depth = 0 Do While gFileCurrentLine <> eof If gFileCurrentLine = cSaveNodeBegin Then depth = depth + 1 If depth > gClipboardNodeDepth Then gClipboardNodeDepth = depth End If Else If gFileCurrentLine = cSaveNodeEnd Then depth = depth - 1 End If End If Loop TreeFileClose End If End Sub #Region Menu Edit Note Sub mnuEditNoteAddBefore_Click If gLastSelection Then If LastSelectedNode.IsRoot Then index = Tree.IndexOfNode(LastSelectedNode.Value) AddNewNode("Tree", cNewNode, "", true, index ) Else TempNode2.Value = LastSelectedNode.Parent index = TempNode2.IndexOfNode(LastSelectedNode.Value) AddNewNode("TempNode2", cNewNode, "", true, index ) End If Else AddNewNode("Tree", cNewNode, "", true, 0 ) End If gTreeDirty = true Tree.SelectedNode = TempNode1.Value textBoxNodeName.SelectionStart = 0 textBoxNodeName.SelectionLength = StrLength(textBoxNodeName.Text) End Sub Sub mnuEditNoteAddBelow_Click If gLastSelection Then AddNewNode("LastSelectedNode", cNewNode, "", true, 0 ) Else AddNewNode("Tree", cNewNode, "", true, 0 ) End If gTreeDirty = true Tree.SelectedNode = TempNode1.Value textBoxNodeName.SelectionStart = 0 textBoxNodeName.SelectionLength = StrLength(textBoxNodeName.Text) End Sub Sub mnuEditNoteAddAfter_Click If gLastSelection Then If LastSelectedNode.IsRoot Then index = Tree.IndexOfNode(LastSelectedNode.Value) AddNewNode("Tree", cNewNode, "", true, index + 1) Else TempNode2.Value = LastSelectedNode.Parent index = TempNode2.IndexOfNode(LastSelectedNode.Value) AddNewNode("TempNode2", cNewNode, "", true, index + 1) End If Else AddNewNode("Tree", cNewNode, "", true, -1 ) End If gTreeDirty = true Tree.SelectedNode = TempNode1.Value textBoxNodeName.SelectionStart = 0 textBoxNodeName.SelectionLength = StrLength(textBoxNodeName.Text) End Sub Sub mnuEditNoteDelete_Click If gLastSelection AND ( Not(LastSelectedNode.IsRoot) OR Tree.Count > 1) Then gLastSelection = false DeleteNode("LastSelectedNode") gTreeDirty = true End If Tree.SelectedNode = TempNode1.Value End Sub #End Region #Region Menu Edit Tree Sub mnuEditTreePasteBefore_Click mnuEditPaste_Click TempNode3.Value = LastSelectedNode.Value TempNode2.Value = TempNode3.Parent TempNode2.RemoveNode(LastSelectedNode.Value) If TempNode2.IsRoot Then index = Tree.IndexOfNode(TempNode2.Value) Tree.InsertNode(index, TempNode3.Value) Else TempNode1.Value = TempNode2.Parent index = TempNode1.IndexOfNode(TempNode2.Value) TempNode1.InsertNode(index, TempNode3.Value) End If Tree.SelectedNode = TempNode3.Value End Sub Sub mnuEditTreePasteAfter_Click mnuEditPaste_Click TempNode3.Value = LastSelectedNode.Value TempNode2.Value = TempNode3.Parent TempNode2.RemoveNode(LastSelectedNode.Value) If TempNode2.IsRoot Then index = Tree.IndexOfNode(TempNode2.Value) Tree.InsertNode(index + 1, TempNode3.Value) Else TempNode1.Value = TempNode2.Parent index = TempNode1.IndexOfNode(TempNode2.Value) TempNode1.InsertNode(index + 1, TempNode3.Value) End If Tree.SelectedNode = TempNode3.Value End Sub Sub mnuEditTreeExpandAll_Click Tree.ExpandAll Tree.SelectedNode = Tree.GetNode(0) End Sub Sub mnuEditTreeCollapseAll_Click Tree.CollapseAll Tree.SelectedNode = Tree.GetNode(0) End Sub Sub mnuEditTreeShowTree_Click autoFull = mnuEditOptionsAutomaticFullscreen.Checked mnuEditOptionsAutomaticFullscreen.Checked = false Tree.Visible = true Resize If gFocusControl = "" AND autoFull Then buttonAddBefore.Focus End If buttonShowTree.Visible = false mnuEditTreeShowTree.Enabled = false mnuEditOptionsAutomaticFullscreen.Checked = autoFull End Sub #End Region #Region menu Edit Find Sub mnuEditFindFind_Click mnuEditFindFind.Checked = Not(mnuEditFindFind.Checked) If mnuEditFindFind.Checked Then If gFocusControl = "" Then If gLastSelection Then textBoxSearch.Text = LastSelectedNode.Text End If Else saveClip = gClipboardString mnuEditCopy_Click textBoxSearch.Text = gClipboardString gClipboardString = saveClip End If End If panelSearch.Visible = mnuEditFindFind.Checked AutoFullscreen End Sub Sub mnuEditFindNext_Click If textBoxSearch.Text = "" Then Return SearchInit gSearchIsReplaceAll = false ' want those local :-) start = Control(gSearchFocusControl, TextBox).SelectionStart length = Control(gSearchFocusControl, TextBox).SelectionLength nameStart = textBoxNodeName.SelectionStart nameLength = textBoxNodeName.SelectionLength textStart = textBoxNodeText.SelectionStart textLength = textBoxNodeText.SelectionLength TempNode3.Value = Tree.SelectedNode If StrIndexOf(SubString(gSearchTrueSearchTextBox, start, length), gSearchTrueSearchSearch, 0) = 0 Then Control(gSearchFocusControl, TextBox).SelectionLength = 0 Control(gSearchFocusControl, TextBox).SelectionStart = start + 1 End If If Not (SearchNext) Then Tree.SelectedNode = TempNode3.Value Control(gLastSearchControl, TextBox).Focus textBoxNodeName.SelectionStart = nameStart textBoxNodeName.SelectionLength = nameLength textBoxNodeText.SelectionStart = textStart textBoxNodeText.SelectionLength = textLength End If End Sub Sub mnuEditFindReplaceNext_Click If textBoxSearch.Text = "" OR textBoxSearch.Text = textBoxReplace.Text Then Return SearchInit gSearchIsReplaceAll = false ' want those local :-) nameStart = textBoxNodeName.SelectionStart nameLength = textBoxNodeName.SelectionLength textStart = textBoxNodeText.SelectionStart textLength = textBoxNodeText.SelectionLength textBoxNodeName.SelectionStart = 0 textBoxNodeName.SelectionLength = 0 textBoxNodeText.SelectionStart = 0 textBoxNodeText.SelectionLength = 0 TempNode3.Value = Tree.SelectedNode If SearchNext Then gLastSelection = false Tree_AfterSelect saveClip = gClipboardString gClipboardString = textBoxReplace.Text PasteSelection(gSearchFocusControl) gClipboardString = saveClip Tree_AfterSelect Else Tree.SelectedNode = TempNode3.Value Control(gLastSearchControl, TextBox).Focus textBoxNodeName.SelectionStart = nameStart textBoxNodeName.SelectionLength = nameLength textBoxNodeText.SelectionStart = textStart textBoxNodeText.SelectionLength = textLength End If End Sub Sub mnuEditFindReplaceAll_Click If textBoxSearch.Text = "" OR textBoxSearch.Text = textBoxReplace.Text Then Return ' want those local :-) nameStart = textBoxNodeName.SelectionStart nameLength = textBoxNodeName.SelectionLength textStart = textBoxNodeText.SelectionStart textLength = textBoxNodeText.SelectionLength TempNode3.Value = Tree.SelectedNode textBoxNodeName.SelectionStart = 0 textBoxNodeName.SelectionLength = 0 textBoxNodeText.SelectionStart = 0 textBoxNodeText.SelectionLength = 0 gSearchIsReplaceAll = true SearchInit gLastSelection = false Tree_AfterSelect replacedNo = 0 Do While SearchNext Tree_AfterSelect saveClip = gClipboardString gClipboardString = textBoxReplace.Text PasteSelection(gSearchFocusControl) gClipboardString = saveClip Tree_AfterSelect replacedNo = replacedNo + 1 If mnuEditFindMatchCase.Checked Then gSearchTrueSearchTextBox = Control(gSearchFocusControl, TextBox).Text Else gSearchTrueSearchTextBox = StrToLower(Control(gSearchFocusControl, TextBox).Text) End If Loop Tree.SelectedNode = TempNode3.Value If replacedNo > 0 Then Control(gLastSearchControl, TextBox).Focus textBoxNodeName.SelectionStart = nameStart textBoxNodeName.SelectionLength = 0 textBoxNodeText.SelectionStart = textStart textBoxNodeText.SelectionLength = 0 Else textBoxNodeName.SelectionStart = nameStart textBoxNodeName.SelectionLength = nameLength textBoxNodeText.SelectionStart = textStart textBoxNodeText.SelectionLength = textLength End If Msgbox (StrReplace(cSearchReplacedText, "#", replacedNo), cSearchReplacedTitle, cMsgboxOK) End Sub Sub SearchInit If gSearchFocusControl = "" Then gLastSearchControl = "textBoxNodeName" Else gLastSearchControl = gSearchFocusControl End If If gSearchIsReplaceAll Then gLastSearchControl = "textBoxNodeName" TreeIteratorPosition.Value = Tree.GetNode(0) Tree.SelectedNode = TreeIteratorPosition.Value End If Tree_AfterSelect gSearchWrap = mnuEditFindWrapSearch.Checked TreeIterator_Init("Tree", true, "", "", "") If gLastSelection AND Not (gSearchIsReplaceAll) Then TreeIteratorPosition.Value = LastSelectedNode.Value End If If mnuEditFindMatchCase.Checked Then gSearchTrueSearchSearch = textBoxSearch.Text gSearchTrueSearchTextBox = Control(gSearchFocusControl, TextBox).Text Else gSearchTrueSearchSearch = StrToLower(textBoxSearch.Text) gSearchTrueSearchTextBox = StrToLower(Control(gSearchFocusControl, TextBox).Text) End If gLastSelection = false End Sub Sub SearchNext gFinished = false gFound = false gSearchFound = -1 Do ' TODO: Do not work in the textboxes start = Control(gSearchFocusControl, TextBox).SelectionStart FindSearchText(start) Loop Until gFinished Return gFound End Sub Sub FindSearchText(start) gSearchFound = StrIndexOf(gSearchTrueSearchTextBox, gSearchTrueSearchSearch, start) If gSearchFound > = 0 Then gFinished = true gFound = true ' TODO: Do not work in the textboxes Control(gSearchFocusControl, TextBox).Focus Control(gSearchFocusControl, TextBox).SelectionStart = gSearchFound Control(gSearchFocusControl, TextBox).SelectionLength = StrLength(gSearchTrueSearchSearch) Else TextNotFound End If End Sub Sub TextNotFound If StrToLower(gSearchFocusControl) = "textboxnodename" Then gSearchFocusControl = "textBoxNodeText" If mnuEditFindMatchCase.Checked Then gSearchTrueSearchTextBox = Control(gSearchFocusControl, TextBox).Text Else gSearchTrueSearchTextBox = StrToLower(Control(gSearchFocusControl, TextBox).Text) End If Tree_AfterSelect Else gSearchFocusControl = "textBoxNodeName" Tree.SelectedNode = TreeIteratorPosition.Value TreeIterator_Next If TreeIteratorFinished AND Not (gSearchWrap) AND Not (gSearchIsReplaceAll) Then gMsgboxChoice = Msgbox(cSearchWrappedText, cSearchWrappedTitle, cMsgboxYesNo, cMsgboxQuestion) If gMsgboxChoice = cYes Then gSearchWrap = true End If End If If TreeIteratorFinished AND gSearchWrap Then TreeIterator_Init("Tree", true, "", "", "") gSearchWrap = false Else gFinished = TreeIteratorFinished End If If Not (gFinished) Then Tree.SelectedNode = TreeIteratorPosition.Value If mnuEditFindMatchCase.Checked Then gSearchTrueSearchTextBox = Control(gSearchFocusControl, TextBox).Text Else gSearchTrueSearchTextBox = StrToLower(Control(gSearchFocusControl, TextBox).Text) End If Else gSearchFocusControl = "textBoxNodeText" End If End If Control(gSearchFocusControl, TextBox).Focus If Not (gFinished) Then Control(gSearchFocusControl).SelectionLength = 0 Control(gSearchFocusControl).SelectionStart = 0 End If End Sub Sub mnuEditFindMatchCase_Click mnuEditFindMatchCase.Checked = Not(mnuEditFindMatchCase.Checked) End Sub Sub mnuEditFindWrapSearch_Click mnuEditFindWrapSearch.Checked = Not(mnuEditFindWrapSearch.Checked) End Sub #End Region #Region Menu Edit Options Sub mnuEditOptionsShowCheckboxes_Click If mnuEditOptionsShowCheckboxes.Checked Then gMsgboxChoice = Msgbox(cConfirmationHideCheckboxesText, cConfirmationHideCheckboxesTitle, cMsgboxYesNo, cMsgboxQuestion) If gMsgboxChoice <> cYes Then Return End If mnuEditOptionsShowCheckboxes.Checked = Not (mnuEditOptionsShowCheckboxes.Checked) gTreeDirty = true Tree.CheckBoxes = mnuEditOptionsShowCheckboxes.Checked Tree.ExpandAll UpdateActionsEnabled End Sub Sub mnuEditOptionsKeyboardSpace_Click mnuEditOptionsKeyboardSpace.Checked = Not(mnuEditOptionsKeyboardSpace.Checked) If CPPC Then gKeyboardSpace = mnuEditOptionsKeyboardSpace.Checked Else gTreeOnTop = mnuEditOptionsKeyboardSpace.Checked End If AutoFullscreen End Sub Sub mnuEditOptionsAutomaticFullscreen_Click mnuEditOptionsAutomaticFullscreen.Checked = Not (mnuEditOptionsAutomaticFullscreen.Checked) AutoFullscreen End Sub Sub mnuEditOptionsLargeTree_Click mnuEditOptionsLargeTree.Checked = Not (mnuEditOptionsLargeTree.Checked) AutoFullscreen End Sub Sub mnuEditOptionsSaveAsASCII_Click mnuEditOptionsSaveAsASCII.Checked = Not(mnuEditOptionsSaveAsASCII.Checked) gTreeDirty = true UpdateActionsEnabled End Sub #End Region #End Region #End Region #Region Button Click Events ' These events are all wired to menu events Sub buttonAddBefore_Click buttonAddBefore.Enabled = false mnuEditNoteAddBefore_Click buttonAddBefore.Enabled = true End Sub Sub buttonAddBelow_Click buttonAddBelow.Enabled = false mnuEditNoteAddBelow_Click UpdateActionsEnabled End Sub Sub buttonAddAfter_Click buttonAddAfter.Enabled = false mnuEditNoteAddAfter_Click buttonAddAfter.Enabled = true End Sub Sub buttonDelete_Click buttonDelete.Enabled = false mnuEditNoteDelete_Click UpdateActionsEnabled End Sub Sub buttonShowTree_Click mnuEditTreeShowTree_Click End Sub Sub buttonFind_Click mnuEditFindNext_Click End Sub Sub buttonReplace_Click mnuEditFindReplaceNext_Click End Sub Sub buttonReplaceAll_Click mnuEditFindReplaceAll_Click End Sub #End Region #Region MainContextMenu Click Event Sub MainContextMenu_Click Select MainContextMenu.SelectedText Case "Cut" mnuEditCut_Click Case "Copy" mnuEditCopy_Click Case "Paste" mnuEditPaste_Click End Select End Sub #End Region #Region TextBox Focus Events Sub textBoxNodeName_GotFocus gFocusControl = Sender gSearchFocusControl = Sender AutoFullscreen UpdateActionsEnabled gLastSelection = true End Sub Sub textBoxNodeName_KeyPress(key) gTreeDirty = true UpdateActionsEnabled End Sub Sub textBoxNodeName_LostFocus gFocusControl = "" LastSelectedNode.Value = Tree.SelectedNode Tree_AfterSelect End Sub Sub textBoxNodeText_GotFocus gFocusControl = Sender gSearchFocusControl = Sender AutoFullscreen UpdateActionsEnabled gLastSelection = true End Sub Sub textBoxNodeText_KeyPress(key) gTreeDirty = true UpdateActionsEnabled End Sub Sub textBoxNodeText_LostFocus gFocusControl = "" LastSelectedNode.Value = Tree.SelectedNode Tree_AfterSelect End Sub Sub textBoxSearch_GotFocus gFocusControl = Sender End Sub Sub textBoxSearch_LostFocus gFocusControl = "" End Sub Sub textBoxReplace_GotFocus gFocusControl = Sender End Sub Sub textBoxReplace_LostFocus gFocusControl = "" End Sub Sub AutoFullscreen Resize If mnuEditOptionsAutomaticFullscreen.Checked AND (StrToLower(gFocusControl) = "textboxnodename" OR StrToLower(gFocusControl) = "textboxnodetext") Then textBoxNodeName.Top = 0 textBoxNodeText.Top = textBoxNodeName.Height If panelSearch.Visible Then textBoxNodeText.Height = MainForm.Height - (textBoxNodeName.Height + panelSearch.Height) If gKeyboardSpace AND Hardware1.SIPEnabled Then textBoxNodeText.Height = textBoxNodeText.Height - cSpaceKeyboard End If panelSearch.Top = textBoxNodeText.Top + textBoxNodeText.Height Else textBoxNodeText.Height = MainForm.Height - (textBoxNodeName.Height + buttonAddAfter.Height + cSpaceBottom + cSpaceBeforeButtons) If gKeyboardSpace AND Hardware1.SIPEnabled Then textBoxNodeText.Height = textBoxNodeText.Height - cSpaceKeyboard End If End If textBoxNodeName.Left = 0 textBoxNodeName.Width = MainForm.Width textBoxNodeText.Left = 0 textBoxNodeText.Width = MainForm.Width buttonShowTree.Top = buttonAddAfter.Top buttonShowTree.Visible = true mnuEditTreeShowTree.Enabled = true buttonAddBefore.Visible = false buttonAddBelow.Visible = false buttonAddAfter.Visible = false buttonDelete.Visible = false Control(gFocusControl, TextBox).Focus Else gLastSelection = false Tree_AfterSelect If gFocusControl = "" Then buttonAddBefore.Focus ' Else ' Control(gFocusControl, TextBox) End If buttonShowTree.Visible = false mnuEditTreeShowTree.Enabled = false End If End Sub #End Region #Region TreeView After Select Event Sub Tree_AfterSelect If gInit Then Return ErrorLabel(NoLastSelection) If gLastSelection Then LastSelectedNode.Text = textBoxNodeName.Text SetNodeText("LastSelectedNode", textBoxNodeText.Text) End If UpdateActionsEnabled NoLastSelection: If Tree.Count > 0 Then gLastSelection = true LastSelectedNode.Value = Tree.SelectedNode textBoxNodeName.Text = LastSelectedNode.Text textBoxNodeText.Text= GetNodeText("LastSelectedNode") UpdateActionsEnabled End If UpdateActionsEnabled Return End Sub Sub UpdateActionsEnabled If gTreeDirty AND gFileName <> "" Then mnuFileSave.Enabled = true Else mnuFileSave.Enabled = false End If If gLastSelection AND Tree.Count >0 AND (Not (LastSelectedNode.IsRoot) OR Tree.Count > 1) Then buttonDelete.Enabled = true mnuEditCut.Enabled = true mnuEditNoteDelete.Enabled = true Else buttonDelete.Enabled = false If gFocusControl <> "" Then mnuEditCut.Enabled = true Else mnuEditCut.Enabled = false End If mnuEditNoteDelete.Enabled = false End If If gLastSelection Then ' First, everything that happens below the node! ' Adding nodes depth = NodeDepth("LastSelectedNode") If depth >= cMaxNodeDepth Then addBelow = false Else addBelow = true End If buttonAddBelow.Enabled = addBelow mnuEditNoteAddBelow.Enabled = addBelow ' Pasting Nodes If depth + gClipboardNodeDepth > cMaxNodeDepth Then pasteTreeBelow = false Else pasteTreeBelow = true End If If gFocusControl <> "" AND StrIndexOf(gClipBoardString, cSaveEncodingUTF8, 0) <> 0 Then mnuEditPaste.Enabled = true Else mnuEditPaste.Enabled = pasteTreeBelow End If ' Pasting on the same level If depth + gClipboardNodeDepth > cMaxNodeDepth + 1 Then mnuEditTreePasteBefore.Enabled = false mnuEditTreePasteAfter.Enabled = false Else mnuEditTreePasteBefore.Enabled = true mnuEditTreePasteAfter.Enabled = true End If Else buttonAddBelow.Enabled = true mnuEditNoteAddBelow.Enabled = true mnuEditPaste.Enabled = true mnuEditTreePasteBefore.Enabled = true mnuEditTreePasteAfter.Enabled = true End If End Sub #End Region #End Region #Region PrintRtfForm Events Sub PrintRtfForm_Close If gPrintRtfFormRealClose Then gPrintRtfFormRealClose = false Else PrintRtfForm.CancelClose MainForm.Close End If End Sub Sub buttonPrintRtfClose_Click gPrintRtfFormRealClose = true PrintRtfForm.Close End Sub Sub buttonPrintPreview_Click PrepareRtf PreviewBox.PrintPreview PrintRtfFormUpdatePreview End Sub Sub buttonPrintSetup_Click PrepareRtf PreviewBox.PageSetup PrintRtfFormUpdatePreview End Sub Sub buttonPrintDefaults_Click SetDefaultPrintFormats gTreeDirty = true PrintRtfForm_Show End Sub Sub buttonPrintPrint_Click PrepareRtf PreviewBox.Print PrintRtfFormUpdatePreview End Sub Sub buttonPrintExportRtf_Click PrepareRtf If SaveDialogPrint.Show = cOK Then PreviewBox.SaveFile(SaveDialogPrint.File) End If PrintRtfFormUpdatePreview End Sub Sub PrepareRtf gPrintFirstLine = true gPrintLevel = 0 gIndentNextText = -1 For i = 0 To 10 gPrintNumbers(i) = 0 Next i PreviewBox.Clear TreeIterator_Init("Tree", true, "PrintOnDown", "PrintOnClose", "PrintOnUp") Do While Not (TreeIteratorFinished) noteNumber = "" If CheckBoxNoteNumbers.Checked AND StrAt(TreeIteratorPosition.Text, 0) <> "-" AND StrAt(TreeIteratorPosition.Text, 0) <> "*" Then For i = 1 To gPrintLevel noteNumber = noteNumber & gPrintNumbers(i) If i < gPrintLevel Then noteNumber = noteNumber & "." End If Next i noteNumber = noteNumber & " " End If PrintAddText(gPrintLevel, 0, TreeIteratorPosition.Checked, noteNumber & TreeIteratorPosition.Text) If StrAt(TreeIteratorPosition.Text, 0) = "-" OR StrAt(TreeIteratorPosition.Text, 0) = "*" Then gIndentNextText = gFormats(gPrintLevel, 0).LeftIndent + gFormats(gPrintLevel, 0).FontSize End If PrintAddText(gPrintLevel, 1, false, GetNodeText("TreeIteratorPosition")) gIndentNextText = -1 TreeIterator_Next Loop End Sub Sub PrintOnDown gPrintLevel = gPrintLevel + 1 gPrintNumbers(gPrintLevel) = gPrintNumbers(gPrintLevel) + 1 End Sub Sub PrintOnClose gPrintNumbers(gPrintLevel) = gPrintNumbers(gPrintLevel) + 1 End Sub Sub PrintOnUp For i = gPrintLevel To cMaxNodeDepth gPrintNumbers(i) = 0 Next i gPrintLevel = gPrintLevel - 1 gPrintNumbers(gPrintLevel) = gPrintNumbers(gPrintLevel) + 1 End Sub Sub PrintRtfForm_Show For i = 1 To 5 Control("NumL" & i & "Left", NumUpDown).Value = gFormats(i, 0).LeftIndent Control("NumT" & i & "Left", NumUpDown).Value = gFormats(i, 1).LeftIndent Control("NumL" & i & "Hanging", NumUpDown).Value = gFormats(i, 0).HangingIndent Control("NumT" & i & "Hanging", NumUpDown).Value = gFormats(i, 1).HangingIndent Control("NumL" & i & "Right", NumUpDown).Value = gFormats(i, 0).RightIndent Control("NumT" & i & "Right", NumUpDown).Value = gFormats(i, 1).RightIndent Next i CheckBoxCheckboxes.Checked = gCheckBoxCheckboxesChecked CheckBoxNoteNumbers.Checked = gCheckBoxNoteNumbersChecked CheckBoxExtraSkipAfterName.Checked = gCheckBoxExtraSkipAfterNameChecked CheckBoxExtraSkipText.Checked = gCheckBoxExtraSkipTextChecked CheckBoxExtraSkipBeforeName.Checked = gCheckBoxExtraSkipBeforeNameChecked CheckBoxCheckboxes.Enabled = mnuEditOptionsShowCheckboxes.Checked If Not (CheckBoxCheckboxes.Enabled) Then If gCheckBoxCheckboxesChecked Then gTreeDirty = true End If CheckBoxCheckboxes.Checked = false gCheckBoxCheckboxesChecked = false End If PrintRtfFormUpdatePreview End Sub Sub PrintRtfFormUpdatePreview gPrintFirstLine = true PreviewBox.Clear For level = 1 To 5 For nodeName = 0 To 1 SetPrintFormat(level, nodeName) If nodeName = 0 Then If CheckBoxNoteNumbers.Checked Then noteNumber = SubString("1.1.1.1.1.", 0, level * 2 - 1) & " " Else noteNumber = "" End If If level = 2 OR level = 3 Then noteCheck = true Else noteCheck = false End If PrintAddText(level, nodeName, noteCheck, noteNumber & "Level " & level & " Note name (" & gFormats(level, nodeName).Font & " " & Round(gFormats(level, nodeName).FontSize) & "pt)") Else PrintAddText(level, nodeName, false, "Note text (" & gFormats(level, nodeName).Font & " " & Round(gFormats(level, nodeName).FontSize) & "pt)" & CRLF & "Note text. Note text. Note text. Note text. Note text. Note text. Note text. Note text. " ) If level = 5 Then PrintAddText(level, nodeName, false, "- Bullet 1 (-)" & CRLF & "* Bullet 2 (*)") End If End If Next nodeName Next level End Sub Sub PrintAddText(level, nodeName, checked, text) SetPrintFormat(level, nodeName) If gIndentNextText > -1 Then PreviewBox.LeftIndent = gIndentNextText PreviewBox.HangingIndent = 0 End If ' Not optimal if clauses, but logically like interface :-) If nodeName = 0 AND CheckBoxExtraSkipBeforeName.Checked AND Not (gPrintFirstLine) Then PreviewBox.AddText(CRLF) End If If nodeName = 0 AND CheckBoxCheckboxes.Checked Then PreviewBox.Font = "Wingdings" PreviewBox.Bold = false PreviewBox.Italic = false PreviewBox.FontSize = gFormats(1, 0).FontSize + 2 PreviewBox.Offset = - PreviewBox.FontSize / 10 If checked Then noteCheck = cCheckboxChecked Else noteCheck = cCheckboxUnchecked End If PreviewBox.AddText(noteCheck & " ") SetPrintFormat(level, nodeName) PreviewBox.Offset = 0 End If text = text & CRLF If nodeName = 1 AND CheckBoxExtraSkipText.Checked Then text = StrReplace(text, CRLF, CRLF & CRLF) End If If nodeName = 0 AND CheckBoxExtraSkipText.Checked Then text = text & CRLF End If Do While text <> "" pos = StrIndexOf(text, CRLF, 0) If pos < 0 Then para = text text = "" Else para = SubString (text, 0, pos + StrLength(CRLF)) text = SubString (text, pos + StrLength(CRLF), StrLength(text) - (pos + StrLength(CRLF))) Do While StrIndexOf(text, CRLF, 0) = 0 para = para & CRLF text = SubString (text, StrLength(CRLF), StrLength(text) - StrLength(CRLF)) Loop End If bullets = false Select StrAt(para, 0) Case "-" bullets = true Case "*" bullets = true End Select finalCRLF = "" If bullets Then PreviewBox.Bulleted = true PreviewBox.HangingIndent = gFormats(level, NodeName).FontSize Do para = SubString(para, 1, StrLength(para) - 1) Loop Until para = "" OR StrAt(para, 0) <> " " Do While StrIndexOf(para, CRLF & CRLF, StrLength(Para) - 2 * StrLength(CRLF) ) > 0 para = SubString(para, 0, StrLength(para) - StrLength(CRLF)) finalCRLF = finalCRLF & CRLF Loop End If If para <> "" Then PreviewBox.AddText(para) End If PreviewBox.Bulleted = false PreviewBox.HangingIndent = gFormats(level, NodeName).HangingIndent PreviewBox.AddText(finalCRLF) Loop If nodeName = 0 AND CheckBoxExtraSkipAfterName.Checked Then PreviewBox.AddText(CRLF) End If gPrintFirstLine = false End Sub Sub SetDefaultPrintFormats gCheckBoxCheckboxesChecked = false gCheckBoxNoteNumbersChecked = false gCheckBoxExtraSkipAfterNameChecked = false gCheckBoxExtraSkipTextChecked = false gCheckBoxExtraSkipBeforeNameChecked = false ' Copy default Formats For i = 1 To 9 For j = 0 To 1 For k = 0 To 10 gFormats(i, j, k) = gFormats(0, j, k) Next k Next j Next i ' Note name settings depending on level gFormats(1,0).FontSize = 15.75 gFormats(2,0).FontSize = 14.25 gFormats(3,0).FontSize = 12.00 gFormats(4,0).FontSize = 9.75 gFormats(5,0).FontSize = 9.75 gFormats(5,0).Bold = false gFormats(5,0).Italic= true End Sub Sub SetPrintFormat(level, nodeName) If level > 5 Then level = 5 End If PreviewBox.Alignment = gFormats(level, nodeName).Alignment PreviewBox.Font = gFormats(level, nodeName).Font PreviewBox.Bold = gFormats(level, nodeName).Bold PreviewBox.Italic = gFormats(level, nodeName).Italic PreviewBox.StrikeOut = gFormats(level, nodeName).StrikeOut PreviewBox.Underline = gFormats(level, nodeName).Underline PreviewBox.FontSize = gFormats(level, nodeName).FontSize PreviewBox.FontScript = gFormats(level, nodeName).FontScript PreviewBox.LeftIndent = gFormats(level, nodeName).LeftIndent PreviewBox.HangingIndent = gFormats(level, nodeName).HangingIndent PreviewBox.RightIndent = gFormats(level, nodeName).RightIndent End Sub Sub buttonXYFont_Click level = StrAt(Sender, 7) If StrAt(Sender, 6) = "t" Then nodeName = 1 Else nodeName = 0 End If If FontDialog1.Show = cOK Then gFormats(level, nodeName).Font = FontDialog1.Font gFormats(level, nodeName).Bold = FontDialog1.Bold gFormats(level, nodeName).Italic = FontDialog1.Italic gFormats(level, nodeName).StrikeOut = FontDialog1.StrikeOut gFormats(level, nodeName).Underline = FontDialog1.Underline gFormats(level, nodeName).FontSize = FontDialog1.FontSize gFormats(level, nodeName).FontScript = 1 PrintRtfFormUpdatePreview gTreeDirty = true End If End Sub Sub NumXYZ_ValueChanged level = StrAt(Sender, 4) If StrAt(Sender, 3) = "t" Then nodeName = 1 Else nodeName = 0 End If Select StrAt(Sender, 5) Case "l" gFormats(level, nodeName).LeftIndent = Control(Sender, NumUpDown).Value Case "h" gFormats(level, nodeName).HangingIndent = Control(Sender, NumUpDown).Value Case "r" gFormats(level, nodeName).RightIndent = Control(Sender, NumUpDown).Value End Select gTreeDirty = true PrintRtfFormUpdatePreview End Sub Sub CheckBoxX_Click gTreeDirty = true ' The easy way, just all of them :-) gCheckBoxCheckboxesChecked = CheckBoxCheckboxes.Checked gCheckBoxNoteNumbersChecked = CheckBoxNoteNumbers.Checked gCheckBoxExtraSkipAfterNameChecked = CheckBoxExtraSkipAfterName.Checked gCheckBoxExtraSkipTextChecked = CheckBoxExtraSkipText.Checked gCheckBoxExtraSkipBeforeNameChecked = CheckBoxExtraSkipBeforeName.Checked PrintRtfFormUpdatePreview End Sub #End Region #Region Tree Functions Sub NewTree(createOneNode) WaitCursor(true) Tree.Enabled = false Tree.Visible = false Tree.RemoveAllNodes Tree.Enabled = true Tree.Visible = true textBoxNodeName.Enabled = false textBoxNodeText.Enabled = false NodeList.Clear DeletedNodeList.Clear gTreeDirty = false gNewNodeNumber = 0 If createOneNode Then gFileName = "" MainForm.Text = cTreeEditTitle AddNewNode("Tree", cNewNode, "", true, 0) gLastSelection = false UpdateActionsEnabled Tree.CheckBoxes = false Tree.ExpandAll Tree.SelectedNode = TempNode1.Value Else gLastSelection = false End If mnuFileSaveAs.Enabled = true mnuEditOptionsShowCheckboxes.Checked = false textBoxNodeName.Enabled = true textBoxNodeText.Enabled = true textBoxNodeName.Focus SetDefaultPrintFormats WaitCursor(false) End Sub ' Post condition: TempNode1 is the new node Sub AddNewNode(parent, name, text, number, position) If number Then gNewNodeNumber = gNewNodeNumber + 1 name = name & " (" & gNewNodeNumber & ")" End If TempNode1.CreateNew(name) TempNode1.Text = name TempNode1.ImageIndex = GetNewNodeTextIndex(text) TempNode1.Checked = false TempNode1.Expand If parent = "Tree" Then If position = -1 Then position = Control(parent, TreeView).Count End If Control(parent, TreeView).InsertNode(position, TempNode1.Value) Else If position = -1 Then position = Control(parent, Node).Count End If Control(parent, Node).InsertNode(position, TempNode1.Value) End If End Sub Sub GetNewNodeTextIndex(text) If DeletedNodeList.Count > 0 Then index = DeletedNodeList.Item(0) DeletedNodeList.RemoveAt(0) NodeList.Item(index) = text Else index = NodeList.Count NodeList.Add(text) End If Return index End Sub Sub GetNodeText(nodeName) Return NodeList.Item(Control(nodeName, Node).ImageIndex) End Sub Sub SetNodeText(nodeName, text) NodeList.Item(Control(nodeName, Node).ImageIndex) = text End Sub ' Deletes a node if it is not the last one in thetree ' Post condition: TempNode1 is the node before the deleted node ' (according to the TreeIterator forward direction) Sub DeleteNode(nodeName) TreeIterator_Init("Tree", true, "","","") TreeIteratorPosition.Value = Control(nodeName, Node).Value TreeIterator_Next If Control(nodeName, Node).isRoot Then If Tree.Count > 1 Then DeletedNodeList.Add(Control(nodeName, Node).ImageIndex) index = Tree.IndexOfNode(Control(nodeName, Node).Value) Tree.RemoveNodeAt(index) If index < 1 Then index = 1 End If Else ' The last node cannot be deleted index = 1 End If TempNode1.Value = Tree.GetNode(index - 1) Else DeletedNodeList.Add(Control(nodeName, Node).ImageIndex) TempNode2.Value = Control(nodeName, Node).Parent index = TempNode2.IndexOfNode(Control(nodeName, Node).Value) TempNode2.RemoveNodeAt(index) If index < 1 Then TempNode1.Value = TempNode2.Value Else TempNode1.Value = TempNode2.GetNode(index - 1) End If End If If Not (TreeIteratorFinished) Then TempNode1.Value = TreeIteratorPosition.Value End If End Sub Sub TreeFileOpen(input, mode, readWrite, isASCII) ErrorLabel(FileError) gFileMode = mode If gFileMode = cFileModeString Then If readWrite = cWrite Then gFileString ="" Else gFileString = input gFileStringPosition = 0 End If Else If isASCII Then If readWrite = cWrite Then FileOpen(gFile, input, cWrite,, cASCII) Else FileOpen(gFile, input, cRead,, cASCII) End If Else If readWrite = cWrite Then FileOpen(gFile, input, cWrite) Else FileOpen(gFile, input, cRead) End If End If End If Return true FileError: If gFileMode = cFileModeFile Then If readWrite = cWrite Then Msgbox(cFileWriteErrorText, cFileWriteErrorTitle, cMsgBoxOK, cMsgBoxExclamation) Else Msgbox(cFileReadErrorText, cFileReadErrorTitle, cMsgBoxOK, cMsgBoxExclamation) End If End If Return false End Sub Sub TreeFileClose If gFIleMode = cFileModeFile Then FileClose(gFile) End If End Sub Sub TreeFileWrite(text, protectChars) If protectChars Then text = StrReplace(StrReplace(StrReplace(text, "&", "&"), "<", "<"),">",">") End If If gFileMode = cFileModeFile Then FileWrite(gFile, text) Else gFileString = gFileString & text & crlf End If End Sub Sub TreeFileRead(unprotectChars) If gFileMode = cFileModeFile Then result = FileRead(gFile) Else If gFileStringPosition >= StrLength(gFileString) Then result = eof Else lineEnd = StrIndexOf(gFileString, crlf, gFileStringPosition) If lineEnd = - 1 Then result = SubString(gFileString, gFileStringPosition, StrLength(gFileString) - gFileStringPosition) gFileStringPosition = StrLength(gFileString) Else result = SubString(gFileString, gFileStringPosition, lineEnd - gFileStringPosition) gFileStringPosition = lineEnd + StrLength(crlf) End If End If End If If unprotectChars Then result = unprotectString(result) End If Return result End Sub Sub unprotectString(text) Return StrReplace(StrReplace(StrReplace(text, "<", "<"), ">", ">"),"&","&") End Sub Sub SaveTree(name, mode, useASCII, checkboxes) If mode = cFileModeFile Then ErrorLabel(FileWriteError) End If Tree_AfterSelect #Region Save options If Not (TreeFileOpen(name, mode, cWrite, useASCII)) Then Return If Not (useASCII) Then TreeFileWrite(cSaveEncodingUTF8, false) End If If checkboxes Then TreeFileWrite(cSaveCheckboxes, false) Else TreeFileWrite(cSaveNoCheckboxes, false) End If #End Region #Region Save format data If mode = cFileModeFile Then TreeFileWrite(cSaveFormatBegin, false) TreeFileWrite(cSaveFormatBoxesBegin, false) TreeFileWrite(BoolToStr(gCheckBoxCheckboxesChecked), false) TreeFileWrite(BoolToStr(gCheckBoxNoteNumbersChecked), false) TreeFileWrite(BoolToStr(gCheckBoxExtraSkipAfterNameChecked), false) TreeFileWrite(BoolToStr(gCheckBoxExtraSkipTextChecked), false) TreeFileWrite(BoolToStr(gCheckBoxExtraSkipBeforeNameChecked), false) TreeFileWrite(cSaveFormatBoxesEnd, false) i = 1 j = 0 Do While i <= cMaxFormatUsed outLine = "" outLine = outLine & gFormats(i,j).Alignment & ";" outLine = outLine & gFormats(i,j).Font & ";" outLine = outLine & BoolToStr(gFormats(i,j).Bold) & ";" outLine = outLine & BoolToStr(gFormats(i,j).Italic) & ";" outLine = outLine & BoolToStr(gFormats(i,j).StrikeOut) & ";" outLine = outLine & BoolToStr(gFormats(i,j).Underline) & ";" outLine = outLine & gFormats(i,j).FontSize & ";" outLine = outLine & gFormats(i,j).FontScript & ";" outLine = outLine & gFormats(i,j).LeftIndent & ";" outLine = outLine & gFormats(i,j).HangingIndent & ";" outLine = outLine & gFormats(i,j).RightIndent & ";" TreeFileWrite(outLine, true) ' Next format If j = 0 Then j = 1 Else j = 0 i = i + 1 End If Loop TreeFileWrite(cSaveFormatEnd, false) End If #End Region ' Initialize Iterator TreeIterator_Init("Tree", true, "", "SaveTreeNodeNext", "SaveTreeNodeUp") #Region Clipboard only If mode = cFileModeString Then If Not (gLastSelection) Then Return Else TreeIteratorPosition.Value = LastSelectedNode.Value FileStopNode.Value = LastSelectedNode.Value Do While FileStopNode.Count > 0 FileStopNode.Value = FileStopNode.GetNode (FileStopNode.Count -1) Loop End If End If #End Region #Region Iterate through tree WaitCursor(true) endLoop = false gFileDepth = 0 gFileCurrentDepth = 0 Do While Not (TreeIteratorFinished) If mode = cFileModeString AND FileStopNode.ImageIndex = TreeIteratorPosition.ImageIndex Then endLoop = true End If TreeFileWrite(cSaveNodeBegin, false) gFileCurrentDepth = gFileCurrentDepth + 1 If gFileCurrentDepth > gFileDepth Then gFileDepth = gFileCurrentDepth End If If TreeIteratorPosition.Checked Then TreeFileWrite(cSaveChecked, false) End If TreeFileWrite(cSaveNameBegin, false) TreeFileWrite(TreeIteratorPosition.Text, true) TreeFileWrite(cSaveNameEnd, false) writeText = GetNodeText("TreeIteratorPosition") TreeFileWrite(cSaveTextBegin, false) If writeText <> "" Then TreeFileWrite(writeText, true) End If TreeFileWrite(cSaveTextEnd, false) TreeIterator_Next If endLoop Then TreeIteratorFinished = true End If Loop TreeFileClose WaitCursor(false) #End Region Return FileWriteError: Msgbox(cFileWriteErrorText, cFileWriteErrorTitle, cMsgBoxOK, cMsgBoxExclamation) WaitCursor(False) End Sub Sub SaveTreeNodeNext TreeFileWrite(cSaveNodeEnd, false) gFileCurrentDepth = gFileCurrentDepth - 1 End Sub Sub SaveTreeNodeUp gFileCurrentDepth = gFileCurrentDepth - 1 End Sub Sub OpenTree(name, mode, useASCIIControl, checkboxesControl) selectedFirst = false #Region Mode specific preparations If gFileMode = cFileModeFile Then NewTree(false) isRoot = true Else If Not(gLastSelection) Then Return false Else Tree_AfterSelect isRoot = false TempNode2.Value = LastSelectedNode.Value ErrorLabel(FileReadError) End If End If #End Region #Region Read global options ' Open and check if ASCII file gFileCurrentLineNo = 0 gFileCurrentLine = "" gFileLookahead = "" If Not (TreeFileOpen(name, mode, cRead, false)) Then Return false End If FileReadNextLine If gFileLookahead = cSaveEncodingUTF8 Then If(gFileMode = cFileModeFile) Then Control(useASCIIControl).Checked = false End If FileReadNextLine Else TreeFileClose gFileCurrentLineNo = 0 If Not (TreeFileOpen(name, mode, cRead, true)) Then Return false End If If(gFileMode = cFileModeFile) Then Control(useASCIIControl).Checked = true End If End If ' Checkboxes yes or no? If gFileMode = cFileModeFile Then Tree.CheckBoxes = false Control(checkboxesControl).Checked = false End If If gFileLookahead = cSaveCheckboxes Then If gFileMode = cFileModeFile Then Control(checkboxesControl).Checked = true End If FileReadNextLine Else If gFileLookahead = cSaveNoCheckboxes Then FileReadNextLine End If End If FileReadNextLine If gFileMode = cFileModeFile Then Tree.CheckBoxes = Control(checkboxesControl).Checked End If #End Region #Region Read format data If gFileMode = cFileModeFile Then If gFileCurrentLine = cSaveFormatBegin Then FileReadNextLine ' Global options set with checkboxes If gFileCurrentLine = cSaveFormatBoxesBegin Then FileReadNextLine gCheckBoxCheckboxesChecked = StrToBool(gFileCurrentLine) FileReadNextLine gCheckBoxNoteNumbersChecked = StrToBool(gFileCurrentLine) FileReadNextLine gCheckBoxExtraSkipAfterNameChecked = StrToBool(gFileCurrentLine) FileReadNextLine gCheckBoxExtraSkipTextChecked = StrToBool(gFileCurrentLine) FileReadNextLine gCheckBoxExtraSkipBeforeNameChecked = StrToBool(gFileCurrentLine) FileReadNextLine ' Read cSaveFormatBoxesEnd FileReadNextLine ' Drop cSaveFormatBoxesEnd End If i = 1 j = 0 Do While gFileCurrentLine <> eof AND gFileCurrentLine <> cSaveFormatEnd gFormatData() = StrSplit(unprotectString(gFileCurrentLine), ";") ' Ignore incorrect input completely If ArrayLen(gFormatData()) >= 11 Then gFormats(i,j).Alignment = gFormatData(0) gFormats(i,j).Font= gFormatData(1) gFormats(i,j).Bold = StrToBool(gFormatData(2)) gFormats(i,j).Italic = StrToBool(gFormatData(3)) gFormats(i,j).StrikeOut = StrToBool(gFormatData(4)) gFormats(i,j).Underline = StrToBool(gFormatData(5)) gFormats(i,j).FontSize = gFormatData(6) gFormats(i,j).FontScript = gFormatData(7) gFormats(i,j).LeftIndent = gFormatData(8) gFormats(i,j).HangingIndent = gFormatData(9) gFormats(i,j).RightIndent = gFormatData(10) End If ' Next format If j = 0 Then j = 1 Else j = 0 i = i + 1 End If FileReadNextLine Loop FileReadNextLine End If End If #End Region #Region Read complete tree WaitCursor(true) Do While gFileCurrentLine <> eof If Not(CheckFileCurrentLine(cSaveNodeBegin)) Then Return false nodeChecked = false If gFileCurrentLine = cSaveChecked Then If(gFileMode = cFileModeFile) Then Control(checkboxesControl).Checked = true End If nodeChecked = true FileReadNextLine End If If Not(CheckFileCurrentLine(cSaveNameBegin)) Then Return false nodeName = gFileCurrentLine FileReadNextLine If Not(CheckFileCurrentLine(cSaveNameEnd)) Then Return false ' To variants of the position of cSaveChecked If gFileCurrentLine = cSaveChecked Then If(gFileMode = cFileModeFile) Then Control(checkboxesControl).Checked = true End If nodeChecked = true FileReadNextLine End If nodeText = "" If Not(CheckFileCurrentLine(cSaveTextBegin)) Then Return false If gFileCurrentLine <> cSaveTextEnd Then Do While (gFileCurrentLine <> eof) AND (gFileCurrentLine <> cSaveTextEnd) nodeText = nodeText & gFileCurrentLine FileReadNextLine If gFileCurrentLine <> cSaveTextEnd Then nodeText = nodeText & crlf End If Loop End If FileReadNextLine If isRoot Then AddNewNode("Tree", unprotectString(nodeName), unprotectString(nodeText), false, -1) Else AddNewNode("TempNode2", unprotectString(nodeName), unprotectString(nodeText), false, -1) End If If mode = cFileModeFile Then gLastSelection = false Tree.SelectedNode = Tree.GetNode(0) Else If Not (selectedFirst) Then Tree_AfterSelect selectedFirst = true Tree.SelectedNode = TempNode1.Value End If End If TempNode1.Checked = nodeChecked TempNode2.Value = TempNode1.Value If gFileCurrentLine = cSaveNodeEnd Then FileReadNextLine Do While gFileCurrentLine = cSaveNodeEnd FileReadNextLine isRoot = TempNode2.IsRoot If Not (isRoot) Then TempNode2.Value = TempNode2.Parent End If Loop isRoot = TempNode2.IsRoot If Not (isRoot) Then TempNode2.Value = TempNode2.Parent End If Else TempNode2.Value = TempNode1.Value isRoot = false End If Loop TreeFileClose If mode = cFileModeFile Then Tree.CheckBoxes = Control(checkboxesControl).Checked gTreeDirty = Control(checkboxesControl).Checked End If Tree_AfterSelect WaitCursor(false) #End Region Return true FileReadError: Msgbox(cFileReadErrorText, cFileReadErrorTitle, cMsgBoxOK, cMsgBoxExclamation) WaitCursor(false) Return false End Sub Sub FileReadNextLine gFileCurrentLine = gFileLookahead gFileLookahead = TreeFileRead(false) gFileCurrentLineNo = gFileCurrentLineNo + 1 ' Msgbox("Current: " & gFileCurrentLine & " Lookahead: " & gFileLookahead & " Line: " & gFileCurrentLineNo, "Read line") End Sub Sub CheckFileCurrentLine(value) result = true If gFileCurrentLine <> value Then Msgbox(cErrorInLine & (gFileCurrentLineNo - 1) & crlf & cExpected & value & crlf & cReadLine & gFileCurrentLine, cFileOpenError) TreeFileClose result = false Else FileReadNextLine End If Return Result End Sub Sub NodeDepth(controlName) ErrorLabel(NoSelection) depth = 1 DepthNode.Value = Control(controlName, Node).Value Do While Not (DepthNode.isRoot) depth = depth + 1 DepthNode.Value = DepthNode.Parent Loop Return depth NoSelection: Return -1 End Sub #End Region