VERSION DVX 1.00 ' helpedit.frm -- DVX Help Editor ' ' A .dhs help source editor with syntax highlighting and ' live preview via the DVX Help Viewer. ' ' Add commdlg.bas and help.bas to your project, then click Run. Begin Form HelpEdit Caption = "DVX Help Editor" Layout = VBox AutoSize = False Resizable = True Centered = True Width = 640 Height = 440 Begin HBox ToolBar Weight = 0 Begin CommandButton BtnNew Caption = "New" MinWidth = 60 End Begin CommandButton BtnOpen Caption = "Open" MinWidth = 60 End Begin CommandButton BtnSave Caption = "Save" MinWidth = 60 End Begin Spacer Spc1 MinWidth = 16 End Begin CommandButton BtnCompile Caption = "Compile" MinWidth = 80 End Begin CommandButton BtnPreview Caption = "Preview" MinWidth = 80 End Begin Spacer Spc2 Weight = 1 End Begin Label LblStatus Caption = "Ready." MinWidth = 150 End End Begin TextArea Editor Weight = 1 End End DIM currentFile AS STRING DIM hlpFile AS STRING currentFile = "" hlpFile = "" Load HelpEdit HelpEdit.Show ' Configure the editor Editor.SetSyntaxMode "dhs" Editor.SetShowLineNumbers True Editor.SetAutoIndent True Editor.SetCaptureTabs True Editor.SetTabWidth 2 ' Start with a template Editor.Text = ".topic intro" + CHR$(10) + ".title My Help File" + CHR$(10) + ".toc 0 My Help File" + CHR$(10) + ".default" + CHR$(10) + CHR$(10) + ".h1 Welcome" + CHR$(10) + CHR$(10) + "This is your help file. Edit the .dhs source here," + CHR$(10) + "then click Compile and Preview to see the result." + CHR$(10) LblStatus.Caption = "New file." DO DoEvents LOOP SUB BtnNew_Click currentFile = "" hlpFile = "" Editor.Text = ".topic intro" + CHR$(10) + ".title My Help File" + CHR$(10) + ".toc 0 My Help File" + CHR$(10) + ".default" + CHR$(10) + CHR$(10) + ".h1 Welcome" + CHR$(10) + CHR$(10) LblStatus.Caption = "New file." HelpEdit.Caption = "DVX Help Editor" END SUB SUB BtnOpen_Click DIM path AS STRING path = basFileOpen("Open Help Source", "*.dhs") IF path = "" THEN EXIT SUB END IF ' Read the entire file DIM text AS STRING DIM line AS STRING text = "" OPEN path FOR INPUT AS #1 DO WHILE NOT EOF(1) LINE INPUT #1, line IF text <> "" THEN text = text + CHR$(10) END IF text = text + line LOOP CLOSE #1 Editor.Text = text currentFile = path hlpFile = "" LblStatus.Caption = path HelpEdit.Caption = "DVX Help Editor - " + path END SUB SUB BtnSave_Click DIM path AS STRING IF currentFile <> "" THEN path = currentFile ELSE path = basFileSave("Save Help Source", "*.dhs") IF path = "" THEN EXIT SUB END IF END IF ' Write the editor contents to file OPEN path FOR OUTPUT AS #1 PRINT #1, Editor.Text CLOSE #1 currentFile = path LblStatus.Caption = "Saved: " + path HelpEdit.Caption = "DVX Help Editor - " + path END SUB SUB BtnCompile_Click ' Save first if we have a file IF currentFile = "" THEN DIM path AS STRING path = basFileSave("Save Help Source", "*.dhs") IF path = "" THEN LblStatus.Caption = "Save cancelled." EXIT SUB END IF OPEN path FOR OUTPUT AS #1 PRINT #1, Editor.Text CLOSE #1 currentFile = path ELSE OPEN currentFile FOR OUTPUT AS #1 PRINT #1, Editor.Text CLOSE #1 END IF ' Derive .hlp filename from .dhs filename DIM baseName AS STRING baseName = currentFile ' Strip .dhs extension if present IF LEN(baseName) > 4 THEN IF UCASE$(RIGHT$(baseName, 4)) = ".DHS" THEN baseName = LEFT$(baseName, LEN(baseName) - 4) END IF END IF hlpFile = baseName + ".hlp" LblStatus.Caption = "Compiling..." DoEvents IF HelpCompile(currentFile, hlpFile) THEN LblStatus.Caption = "Compiled: " + hlpFile ELSE LblStatus.Caption = "Compile failed!" hlpFile = "" END IF END SUB SUB BtnPreview_Click IF hlpFile = "" THEN ' Try compiling first BtnCompile_Click END IF IF hlpFile = "" THEN LblStatus.Caption = "Nothing to preview. Compile first." EXIT SUB END IF LblStatus.Caption = "Opening viewer..." HelpView hlpFile END SUB SUB HelpEdit_QueryUnload(Cancel AS INTEGER) ' Could prompt to save here END SUB