Jump to content

My HTML (picture) menu maker


Dan_555
 Share

Recommended Posts

Hi, here is my "HtmlMenuMaker" app. 

It helps me to create a Webpage menu (for  local usage), containing multiple files (pictures/music/JS examples etc etc).

This could be made in few lines, but i wanted to make it a bit more flexible, so it ended up having around 800+ lines of code. (not counting the includes ;) )

The full readme file is included in the source code, but here is the basic usage:

 

Start the app, add files (no drag'n'drop ...), sort them around (optionally), press preview, then click on save to generate 2 html files (!index.html, !mleft.html). 

The Save button will ask you to select a folder in which the 2 files will be saved.

Attached is a screenshot of the app, and in the background you can see an example of the generated file:htmlmenumaker.thumb.png.b8541200b91e250beb4485c16665cf2e.png

On the left side is the menu (of pictures, in this example but can be used for other displayable media), which are displayed in the right side (the picture is covered by the app window)

You can save the changes of the style, the Link creating text and the main form code to the HtmlMenuMaker.ini file. 

A knowledge of HTML is required to make these changes.

 

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=HtmlMenuMaker.exe
#AutoIt3Wrapper_Outfile_x64=HtmlMenuMaker_x64.exe
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <ButtonConstants.au3>
#include <GuiComboBox.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GuiEdit.au3>
#include <File.au3>
#include <GUIConstantsEx.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <GuiStatusBar.au3>
#include <GuiToolbar.au3>
#include <ToolbarConstants.au3>
#include <GuiToolTip.au3>
#include <ScrollBarsConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <WindowsConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPIDlg.au3>

Global $formTitle = "Html-Menu from File(s) maker"
Global $ReadmeEdit1, $readmeEditflag = 0, $AboutForm1

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate($formTitle, 819, 487, 220, 213, BitOR($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX, $WS_THICKFRAME), $WS_EX_ACCEPTFILES)
$L_File = GUICtrlCreateList("", 16, 84, 157, 344, BitOR($LBS_NOTIFY, $LBS_MULTIPLESEL, $WS_HSCROLL, $WS_VSCROLL, $LBS_DISABLENOSCROLL))
Global $ToolBar1 = _GUICtrlToolbar_Create($Form1, BitOR($TBSTYLE_LIST, $WS_VISIBLE, $WS_CHILD, $WS_BORDER, $WS_CLIPSIBLINGS))
GUICtrlCreateLabel("File List:", 24, 60, 42, 17)
Global $Edit1 = GUICtrlCreateEdit("", 184, 84, 273, 105)
$Label1 = GUICtrlCreateLabel("Style Text", 184, 60, 51, 17)
$Label2 = GUICtrlCreateLabel("Code before filename", 184, 200, 115, 13)
$Label3 = GUICtrlCreateLabel("Code - mid", 184, 250, 90, 17)
$Label4 = GUICtrlCreateLabel("Code - end part", 184, 303, 77, 13)
Global $StatusBar1 = _GUICtrlStatusBar_Create($Form1, -1, "", -1, $WS_EX_CLIENTEDGE)
$Group1 = GUICtrlCreateGroup("Link Creator", 8, 37, 481, 425)
$L_preset = GUICtrlCreateListView("nr|Name|start|mid|end", 184, 348, 241, 97)
$Button5 = GUICtrlCreateButton("<Add", 432, 408, 45, 17)
GUICtrlSetTip(-1, "Add the Code Before, Mid and End part to the listview and to the ini file")
$Button6 = GUICtrlCreateButton("<Del", 432, 428, 45, 17)
GUICtrlSetTip(-1, "Deletes the selection from the listview and from the ini file.")
$Button7 = GUICtrlCreateButton("Use", 432, 348, 45, 17)
GUICtrlSetTip(-1, "Select an item from the listview (to the left)" & @CRLF & " then click use to copy the contents to the edit areas above.")
$Combo1 = GUICtrlCreateCombo("Combo1", 240, 60, 153, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Button8 = GUICtrlCreateButton("+", 400, 60, 21, 21)
GUICtrlSetTip(-1, "Add new item or overwrites selected item.")
$Button9 = GUICtrlCreateButton("-", 424, 60, 21, 21)
GUICtrlSetTip(-1, "Delete a selected item.")
GUICtrlCreateGroup("", -99, -99, 1, 1)
Global $Edit2 = GUICtrlCreateEdit("", 496, 60, 317, 161)
$Label5 = GUICtrlCreateLabel(" Preview source - !mleft.html :", 496, 38, 180, 15)
$Button1 = GUICtrlCreateButton("^", 16, 426, 20, 18)
GUICtrlSetTip(-1, "Move selection Up")
$Button2 = GUICtrlCreateButton("v", 16, 444, 20, 18)
GUICtrlSetTip(-1, "Move selection down")
$Button3 = GUICtrlCreateButton("Del", 140, 444, 29, 18)
GUICtrlSetTip(-1, "Delete selected items")
$button4 = GUICtrlCreateButton("Clear", 100, 444, 40, 18)
GUICtrlSetTip(-1, "Empty the list")
$button13 = GUICtrlCreateButton("No Sel", 38, 426, 40, 18)
GUICtrlSetTip(-1, "Clear selection")
$button14 = GUICtrlCreateButton("Invert Sel", 78, 426, 60, 18)
GUICtrlSetTip(-1, "Invert selection")
Global $Input1 = GUICtrlCreateInput("", 184, 217, 297, 21)
Global $Input2 = GUICtrlCreateInput("", 184, 266, 297, 21)
Global $Input3 = GUICtrlCreateInput("", 184, 316, 297, 21)
Global $Edit3 = GUICtrlCreateEdit("", 496, 312, 317, 149)
GUICtrlCreateLabel("Main form code:", 500, 288, 80, 17)
$Combo2 = GUICtrlCreateCombo("Combo2", 584, 288, 157, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL))
$Button10 = GUICtrlCreateButton("+", 748, 288, 21, 21)
GUICtrlSetTip(-1, "Add new item or overwrites selected item.")
$Button11 = GUICtrlCreateButton("-", 772, 288, 21, 21)
GUICtrlSetTip(-1, "Delete a selected item.")
GUICtrlCreateLabel("File (link-name) option", 496, 228, 119, 17)
GUICtrlSetTip(-1, "Convert + to Space")
Global $Checkbox1 = GUICtrlCreateCheckbox("No Spaces", 736, 264, 77, 17)
GUICtrlSetTip(-1, "Do not use any space char !" & @CRLF & "Converted spaces will be removed")
Global $Checkbox2 = GUICtrlCreateCheckbox("Remove -", 496, 264, 77, 17)
GUICtrlSetTip(-1, "Remove - chars")
Global $Checkbox3 = GUICtrlCreateCheckbox("Space to _", 576, 244, 77, 17)
GUICtrlSetTip(-1, "Convert Space to  _")
Global $Checkbox4 = GUICtrlCreateCheckbox("Remove +", 656, 264, 77, 17)
GUICtrlSetTip(-1, "Remove + chars")
Global $Checkbox5 = GUICtrlCreateCheckbox("+ to Space", 656, 244, 77, 17)
GUICtrlSetTip(-1, "Convert + to Space")
Global $Checkbox6 = GUICtrlCreateCheckbox("- to Space", 496, 244, 77, 17)
GUICtrlSetTip(-1, "Convert - to Space")
Global $Checkbox7 = GUICtrlCreateCheckbox("No 2* Chars", 736, 244, 77, 17)
GUICtrlSetTip(-1, "If previous options have made 2 chars" & @CRLF & "near each other, this option will make single char of them")
Global $Checkbox8 = GUICtrlCreateCheckbox("_ to Space", 576, 264, 77, 17)
GUICtrlSetTip(-1, "Convert _ to Space")
Global $Checkbox9 = GUICtrlCreateCheckbox("NO folder", 656, 226, 65, 17)
GUICtrlSetTip(-1, "Do not use folder as link" & @CRLF & " if selected, then the files have to be" & @CRLF & " in the same directory as !mleft.html! ")
Global $Checkbox10 = GUICtrlCreateCheckbox("Add EXT", 736, 226, 65, 17)
GUICtrlSetTip(-1, "Add extension as a link name.")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


Global $folder = @ScriptDir, $fname = ""

If $CmdLine[0] > 0 Then
    If FileExists($CmdLine[1]) And IsDir($CmdLine[1]) Then
        $folder = $CmdLine[1]
        If StringRight($folder, 1) <> "\" Then $folder = $folder & "\"
    EndIf
EndIf

Global $g_iItem ; Command identifier of the button associated with the notification.
Global Enum $e_idNew = 1000, $e_idOpen = 1001, $e_idSave = 1002, $e_idHelp = 1003, $e_idPreview = 1004, $e_idAbout = 1005

Local $x, $y, $z, $t, $t1

Const $inifile = @ScriptDir & "\HtmlMenuMaker.ini"
;Const $inifile = "r:mytest.ini"
Const $inilinkentriesmax = 10
Const $inistyleentriesmax = 10
Const $inimainformentriesmax = 10
Const $c1 = Chr(34)
Const $sMessage = "Hold down Ctrl or Shift to choose multiple files. (Do not add link files !)"
Const $2crlf = @CRLF & @CRLF

Global $txt_mainform = "|", $txt_styleform = "|", $nr_mainform = -2, $nr_styleform = -2
Global $a_mainform[$inimainformentriesmax], $a_style[$inistyleentriesmax]

Global $closingdelay = 1000, $closecounter = 0, $TimeHandle = TimerInit(), $TimeDiff = TimerDiff($TimeHandle)

; Add standard system bitmaps
_GUICtrlToolbar_AddBitmap($ToolBar1, 1, -1, $IDB_STD_LARGE_COLOR)

; Add buttons
_GUICtrlToolbar_AddButton($ToolBar1, $e_idNew, $STD_FILENEW)
_GUICtrlToolbar_AddButton($ToolBar1, $e_idOpen, $STD_FILEOPEN)
_GUICtrlToolbar_AddButtonSep($ToolBar1, 12)
_GUICtrlToolbar_AddButton($ToolBar1, $e_idSave, $STD_FILESAVE)
_GUICtrlToolbar_AddButtonSep($ToolBar1, 24)
_GUICtrlToolbar_AddButton($ToolBar1, $e_idPreview, $STD_PRINTPRE)
_GUICtrlToolbar_AddButtonSep($ToolBar1, 520)
_GUICtrlToolbar_AddButton($ToolBar1, $e_idAbout, $STD_PROPERTIES)
GUICtrlSetLimit($L_File, 1500)       ; to limit horizontal scrolling

MemoWrite($Input1, "<a href=" & $c1, 1)
MemoWrite($Input2, $c1 & " TARGET=" & $c1 & "mainframe" & $c1 & "  >", 1)
MemoWrite($Input3, "</a></br>", 1)
MemoWrite($Edit1, "<style>" & @CRLF & " a{" & @CRLF & " font-family: verdana;" & @CRLF & " font-size: 70%;" & @CRLF & " }" & @CRLF & " </style>", 1)
MemoWrite($Edit3, "<HTML>" & @CRLF & "<HEAD>" & @CRLF & "<TITLE>My Web Page</TITLE>" & @CRLF & "</HEAD>" & @CRLF & "<FRAMESET COLS=" & $c1 & "14%,86%" & $c1 & ">" & @CRLF & "<FRAME NAME=" & $c1 & "menuLeft" & $c1 & " SRC=" & $c1 & "!mleft.html" & $c1 & ">" & @CRLF & "<FRAME NAME=" & $c1 & "mainframe" & $c1 & ">" & @CRLF & "</FRAMESET>" & @CRLF & "<NOFRAMES></NOFRAMES>" & @CRLF & "<BODY></BODY>" & @CRLF & "</HTML>", 1)

readlinkini2list()
IniGet("mainform")
IniGet("style")

;Register function for the toolbar and the statusbar
GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")         ; For the Toolbar buttons
GUIRegisterMsg($WM_SIZE, "WM_SIZE")
_GUICtrlEdit_SetLimitText($Edit2, 256000)
; MsgBox(0, "Information", "Text Limit: " & _GUICtrlEdit_GetLimitText($Edit2))

While 1
    CloseGuiOnDoubleClick("loop")
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            CloseGuiOnDoubleClick("button")
        Case $Checkbox6            ; - to Space
            CheckUncheck($Checkbox6, $Checkbox2)
        Case $Checkbox2            ;Rem -
            CheckUncheck($Checkbox2, $Checkbox6)
        Case $Checkbox4            ; Rem +
            CheckUncheck($Checkbox4, $Checkbox5)
        Case $Checkbox5            ; + to Space
            CheckUncheck($Checkbox5, $Checkbox4)
        Case $Checkbox3            ; Space to _
            CheckUncheck($Checkbox3, $Checkbox8)
        Case $Checkbox8            ; _ to Space
            CheckUncheck($Checkbox8, $Checkbox3)
        Case $Button1 ;Up       ^
            Listbox_ItemMoveUD($L_File, -1)
        Case $Button2 ;Down     v
            Listbox_ItemMoveUD($L_File, 1)
        Case $Button3
            Listbox_DeleteSelectedItems($L_File)
        Case $button4     ;Clear the listbox
            GUICtrlSetData($L_File, "")
        Case $button13                ;Clear selection from the listbox
            Listbox_ClearSelection($L_File)
        Case $button14                ;Reverse selection from the listbox
            Listbox_ReverseSelection($L_File)
        Case $Button5        ;<add
            Do_AddBtn()
        Case $Button6        ;<Del
            $t = GUICtrlRead(GUICtrlRead($L_preset))
            Local $ssp = StringSplit($t, "\|")
            If @error = 0 Then
                $t = $ssp[1]
                $t1 = $ssp[2]
                StatusWrite("Deleting item number " & $t & " : " & $t1)
                If MsgBox(1, "Confirm delete", $t & ": " & $t1) = 1 Then
                    IniWrite($inifile, "link", $t & "0", "")
                    EmptyListView($L_preset)
                    readlinkini2list()
                    StatusWrite("Item deleted " & $t & " : " & $t1)
                Else
                    StatusWrite("Cancelled")
                EndIf
            Else
                StatusWrite("Nothing to delete")
            EndIf
        Case $Button7                    ;Use button
            $t = GUICtrlRead(GUICtrlRead($L_preset))

            Local $ssp = StringSplit($t, "\|")
            If @error = 0 Then
                StatusWrite("Copied the selected item (" & $ssp[1] & ") into the edit fields.")
                If $ssp[0] >= 4 Then MemoWrite($Input1, $ssp[3], 1)
                If $ssp[0] >= 5 Then MemoWrite($Input2, $ssp[4], 1)
                If $ssp[0] == 6 Then MemoWrite($Input3, $ssp[5], 1)
            Else
                StatusWrite("Listview: Nothing is selected")
            EndIf
        Case $Button8               ; + Styleform
            IniAddButton("style")
            ;IniUpdateCombo
        Case $Button9                  ;- Styleform
            If _GUICtrlComboBox_GetEditText($Combo1) = $txt_styleform Then
                $x = IniUpdateCombo("style", "", $nr_styleform)
                If $x > 0 Then IniGet("style")
            EndIf
        Case $Button10                 ; + Mainform
            IniAddButton("mainform")
        Case $Button11                ; - Mainform
            StatusWrite("")
            If _GUICtrlComboBox_GetEditText($Combo2) = $txt_mainform Then
                $x = IniUpdateCombo("mainform", "", $nr_mainform)
                If $x > 0 Then
                    StatusWrite("Deleted #" & $nr_mainform & " : " & $txt_mainform)
                    IniGet("mainform")
                Else
                    StatusWrite("Mainform: User cancelled the deletion")
                EndIf
            Else
                StatusWrite("Mainform: Nothing is selected")
            EndIf
        Case $Combo1
            $nr_styleform = $a_style[_GUICtrlComboBox_GetCurSel($Combo1)]
            $txt_styleform = GUICtrlRead($Combo1)
            StringIniToEdit($Edit1, "style", $nr_styleform)
            StatusWrite("Style, Selected item #" & $nr_styleform)
        Case $Combo2
            $nr_mainform = $a_mainform[_GUICtrlComboBox_GetCurSel($Combo2)]
            $txt_mainform = GUICtrlRead($Combo2)
            StringIniToEdit($Edit3, "mainform", $nr_mainform)
            StatusWrite("Mainform, selected item #" & $nr_mainform)
    EndSwitch
WEnd


Func Do_AddBtn()
    StatusWrite("Adding Items to the list")
    $t = GUICtrlRead(GUICtrlRead($L_preset))
    Local $ssp = StringSplit($t, "\|")
    If @error = 0 Then                                ;There is an item selected, ask if it shall be replaced !
        Local $btn = MsgBox(35, "Overwrite", "item # " & $ssp[1] & @CRLF & "Name: " & $ssp[2] & @CRLF & "Yes: Overwrite; No: Add new; Cancel: Stop")
        If $btn = 6 Then                         ;overwrite
            StatusWrite("Listview: Overwriting item (" & $ssp[1] & ") ")
            EnterANameAndWrite($ssp[1])
        EndIf
    Else                                            ;No selection - create new item
        Local $btn = 7
    EndIf
    If $btn = 7 Then                                  ;;No selection - start creating new item
        Local $tst = -1
        $x = 0
        Do
            $t = IniRead($inifile, "link", ($x & "0"), "")
            If $t = "" Then
                $tst = $x
                $x = $inilinkentriesmax
            EndIf
            $x = $x + 1
        Until $x >= $inilinkentriesmax
        If $tst > -1 Then
            EnterANameAndWrite($tst)
        Else
            StatusWrite("Error - No free slots, maximum is " & $inilinkentriesmax)
        EndIf
    EndIf
EndFunc   ;==>Do_AddBtn

Func EnterANameAndWrite($it)
    Local $sInputBoxAnswer = InputBox("Enter a new name", "Please enter a name for this entry.", "Name")
    If $sInputBoxAnswer = "" Then $sInputBoxAnswer = "Name"
    If @error = 0 Then
        IniWrite($inifile, "link", $it & "0", $sInputBoxAnswer)
        WriteInputToIni($it)
        EmptyListView($L_preset)
        readlinkini2list()
        StatusWrite("Done")
    Else
        StatusWrite("User cancelled the operation")
    EndIf
EndFunc   ;==>EnterANameAndWrite

; WM_NOTIFY event handler
Func _WM_NOTIFY($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID, $wParam
    Local $tNMHDR, $hWndFrom, $iCode, $iNew, $iFlags, $iOld, $x
    Local $tNMTBHOTITEM
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $ToolBar1
            Switch $iCode
                Case $NM_LDOWN
                    ;----------------------------------------------------------------------------------------------

                    If $g_iItem > 0 Then

                        Switch _GUICtrlToolbar_CommandToIndex($ToolBar1, $g_iItem)

                            Case 0        ;new

                                If MsgBox(8500, "Start anew ?", "This will reset the file list and the preview text." & $2crlf & "Do you want to continue ?") = 6 Then
                                    GUICtrlSetData($L_File, "")
                                    GUICtrlSetData($Edit2, "")
                                EndIf
                            Case 1        ;open
                                GetFileWF()
                                $g_iItem = 0              ;Set to 0 to prevent unwanted behavior when clicking on the empty space of the toolbar
                            Case 3        ;save
                                Local $LC = _GUICtrlEdit_GetTextLen($Edit2)
                                Local $LC1 = _GUICtrlEdit_GetTextLen($Edit3)
                                If $LC = 0 Or $LC1 = 0 Then
                                    StatusWrite("One of the edit boxes is empty ! (Preview or Main form)")
                                Else
                                    Local $chfolder = FileSelectFolder("Choose a folder to save the html files.", $folder)
                                    If $chfolder <> "" Then
                                        $folder = $chfolder

                                        If SaveEditToFile($Edit2, $folder, "!mleft", ".html", 2) = 0 Then StatusWrite("Saved file: " & $fname)
                                        If SaveEditToFile($Edit3, $folder, "!index", ".html", 2) = 0 Then StatusWrite("Saved file: " & $fname)

                                    EndIf
                                EndIf

                            Case 5          ;Preview
                                doPreview()
                            Case 7
                                StatusWrite("Displaying Readme text")
                                If $readmeEditflag = 0 Then
                                    DisplayReadMe()
                                Else
                                    WinActivate($AboutForm1)
                                EndIf
                        EndSwitch
                    EndIf
                    ;----------------------------------------------------------------------------------------------
                Case $TBN_HOTITEMCHANGE
                    $tNMTBHOTITEM = DllStructCreate($tagNMTBHOTITEM, $lParam)
                    $iOld = DllStructGetData($tNMTBHOTITEM, "idOld")
                    $iNew = DllStructGetData($tNMTBHOTITEM, "idNew")
                    $g_iItem = $iNew
                    $iFlags = DllStructGetData($tNMTBHOTITEM, "dwFlags")
                    If BitAND($iFlags, $HICF_LEAVING) = $HICF_LEAVING Then
                        StatusWrite("")
                    Else
                        Switch $iNew
                            Case $e_idNew
                                StatusWrite("NEW: Clear the file list, and preview Source text.")

                            Case $e_idOpen
                                StatusWrite("Open: Select multiple files per one folder ! Do not choose too many files at once.")

                            Case $e_idSave
                                StatusWrite("Save: Save the HTML pages. (Press preview button to generate the code.)")

                            Case $e_idPreview
                                StatusWrite("Preview: Generate the HTML-Page")

                            Case $e_idAbout
                                StatusWrite("Displays about dialog.")

                        EndSwitch
                    EndIf
            EndSwitch
    EndSwitch

    Return $GUI_RUNDEFMSG

EndFunc   ;==>_WM_NOTIFY

Func SaveEditToFile($idEdit, $folder, $fna, $extension = "", $savetype = 1)
    ;Savetype 1=Append, 2=overwrite
    Local $skip = 0, $e = 0, $x, $y
    $fname = $fna & $extension

    If $savetype = 2 Then              ;Ask to overwrite or to rename !
        Do
            If FileExists($folder & $fname) Then
                If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
                $iMsgBoxAnswer = MsgBox(51, "File exists", $fname & $2crlf & "Click Yes to overwrite it" & @CRLF & "No to enter new name" & @CRLF & "Cancel to Stop !")
                Select
                    Case $iMsgBoxAnswer = 6 ;yes
                        $e = 1
                    Case $iMsgBoxAnswer = 7 ;No
                        $y = $extension & " will be added, if not typed in."
                        If StringLen($extension) <= 1 Then $y = "please enter an extension, if needed."
                        $fname = InputBox("New Filename required ", "Please enter a new filename" & @CRLF & "for " & $fna & @CRLF & $y)
                        If @error > 0 Or $fname = "" Then
                            $e = 1
                            $skip = 1
                        EndIf
                        $x = StringLen($fname)
                        $y = StringLen($extension)

                        If $y > 0 Then
                            If $x > 6 Then
                                If StringLower(StringRight($fname, $y)) <> $extension Then $fname = $fname & $extension
                            ElseIf $x > 0 And $x <= 6 Then
                                $fname = $fname & $extension
                            EndIf
                        EndIf

                    Case $iMsgBoxAnswer = 2     ;Cancel
                        $e = 1
                        $skip = 1
                EndSelect
            Else
                $e = 1
            EndIf
        Until $e > 0
    EndIf

    If $skip = 0 Then
        If StringRight($folder, 1) <> "\" Then $folder = $folder & "\"

        Local $hFile = FileOpen($folder & $fname, $savetype)
        Local $LC = _GUICtrlEdit_GetLineCount($idEdit)
        _GUICtrlEdit_BeginUpdate($idEdit)
        For $x = 0 To $LC
            FileWriteLine($hFile, _GUICtrlEdit_GetLine($idEdit, $x))
        Next
        _GUICtrlEdit_EndUpdate($idEdit)
        FileClose($hFile)
    EndIf
    Return $skip
EndFunc   ;==>SaveEditToFile

Func doPreview()
    GUICtrlSetData($Edit2, "")
    MemoWrite($Edit2, "<HTML>" & @CRLF & "<HEAD>" & @CRLF, 0)
    MemoWrite($Edit2, _GUICtrlEdit_GetText($Edit1), 0)
    MemoWrite($Edit2, "</HEAD>" & @CRLF & "<BODY>" & @CRLF, 0)
    Local $aCou = _GUICtrlListBox_GetCount($L_File)
    Local $TB, $TM, $TE, $FT, $FTL
    $TB = ControlGetText("", "", $Input1)
    $TM = ControlGetText("", "", $Input2)
    $TE = ControlGetText("", "", $Input3)
    _GUICtrlEdit_BeginUpdate($Edit2)

    For $i = 0 To $aCou - 1
        $FT = _GUICtrlListBox_GetText($L_File, $i)
        Local $sDrive = "", $sDir = "", $sFileName = "", $sExtension = ""
        Local $aPathSplit = _PathSplit($FT, $sDrive, $sDir, $sFileName, $sExtension)

        $FTL = $aPathSplit[3]                  ;Filename in to $FTL

        If _IsChecked($Checkbox2) Then $FTL = StringReplace($FTL, "-", "")
        If _IsChecked($Checkbox3) Then $FTL = StringReplace($FTL, " ", "_")
        If _IsChecked($Checkbox4) Then $FTL = StringReplace($FTL, "+", "")
        If _IsChecked($Checkbox5) Then $FTL = StringReplace($FTL, "+", " ")
        If _IsChecked($Checkbox6) Then $FTL = StringReplace($FTL, "-", " ")

        If _IsChecked($Checkbox7) Then        ;No double chars
            $FTL = StringReplace($FTL, "++", "+")
            $FTL = StringReplace($FTL, "--", "-")
            $FTL = StringReplace($FTL, "__", "_")
            $FTL = StringReplace($FTL, "  ", " ")
        EndIf

        If _IsChecked($Checkbox8) Then $FTL = StringReplace($FTL, "_", " ")
        If _IsChecked($Checkbox9) Then
            $FT = $aPathSplit[3] & $aPathSplit[4]
        Else
            $FT = $aPathSplit[0]
        EndIf
        If _IsChecked($Checkbox1) Then $FTL = StringReplace($FTL, " ", "") ; No Spaces !!!
        If _IsChecked($Checkbox10) Then $FTL = $FTL & $aPathSplit[4]
        MemoWrite($Edit2, $TB & $FT & $TM & $FTL & $TE & @CRLF, 0)
    Next
    MemoWrite($Edit2, @CRLF & "</BODY>" & @CRLF & "</HTML>", 0)
    _GUICtrlEdit_EndUpdate($Edit2)


EndFunc   ;==>doPreview


Func StatusWrite($sMessage)
    _GUICtrlStatusBar_SetText($StatusBar1, $sMessage)
EndFunc   ;==>StatusWrite

Func MemoWrite($ed, $sMessage = "", $clear = 1)
    If $clear = 1 Then GUICtrlSetData($ed, "")
    GUICtrlSetData($ed, $sMessage, $clear)
EndFunc   ;==>MemoWrite

Func CheckUncheck($chb_id1, $chb_id2)           ;Check Checkbox, uncheck if checked ! cheekmate !
    If _IsChecked($chb_id1) Then
        GUICtrlSetState($chb_id2, 4)
    EndIf
EndFunc   ;==>CheckUncheck

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked

Func GetFileWF()
    ;Get File with Folder in the filename
    Local $tmp = ""
    ;Local $fs = _WinAPI_GetOpenFileName($sMessage, "All Files (*.*)|Images (*.jpg;*.bmp;*.png;*.gif)|Videos (*.avi;*.mpg;*.mp4)|Sound (*.wav;*.ogg;*.mp3)", ".", "", "", 1, BitOR($OFN_ALLOWMULTISELECT, $OFN_EXPLORER), 0)
    Local $fs = _WinAPI_GetOpenFileName("Select (multiple) File(s)", "All Files (*.*)|Graphics (*.png;*.bmp;*.jpg;*.tif;*.tiff;*.gif;*.tga;*.webp;*.jpeg;*.psd)|Sound (*.wav;*.mp3;*.ogg;*.mid;*.mod;*.mdz)|Video (*.avi;*.mp4;*.mpg;*.wmv;*.mov;*.flv;*.mpeg)|Flash (*.swf;*.flv)|Text (*.txt;*.au3;*.bas;*.bb;*.ahk;*.c;*.lua;*.rtf;*.doc;*.pdf;*.guide;*.log;*.ini)|Archive (*.zip;*.7z;*.rar;*.lha;*.lzx;*.lhx)", $folder, @ScriptName, "", 1, BitOR($OFN_ALLOWMULTISELECT, $OFN_EXPLORER), 0)
    If Not @error Then
        Local $entry = "file"
        If StringLen($fs[1]) = 3 Then
            $fs[1] = StringLeft($fs[1], 2)
        EndIf
        $folder = $fs[1]
        For $x = 2 To $fs[0]
            MemoWrite($L_File, $fs[1] & "\" & $fs[$x], 0)
        Next
    EndIf
EndFunc   ;==>GetFileWF

; Resize the status bar when GUI size changes
Func WM_SIZE($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
    _GUICtrlStatusBar_Resize($StatusBar1)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE


Func Listbox_DeleteSelectedItems($hLB_ID)
    Local $aSel = _GUICtrlListBox_GetSelItems($hLB_ID)
    Local $i
    For $i = $aSel[0] To 1 Step -1
        _GUICtrlListBox_DeleteString($hLB_ID, $aSel[$i])
    Next
EndFunc   ;==>Listbox_DeleteSelectedItems

Func Listbox_ClearSelection($hLB_ID)
    Local $aSel = _GUICtrlListBox_GetSelItems($hLB_ID)            ;Code from Melba23 - Autoit Forum
    For $i = 1 To $aSel[0]
        _GUICtrlListBox_SetSel($hLB_ID, $aSel[$i], False)
    Next
EndFunc   ;==>Listbox_ClearSelection

Func Listbox_ReverseSelection($hLB_ID)
    Local $i
    Local $aCou = _GUICtrlListBox_GetCount($hLB_ID)
    Local $cSel = _GUICtrlListBox_GetCaretIndex($hLB_ID)    ;Save the caret
    For $i = 0 To $aCou
        _GUICtrlListBox_SetSel($hLB_ID, $i, Not (_GUICtrlListBox_GetSel($hLB_ID, $i)))
    Next
    _GUICtrlListBox_SetCaretIndex($hLB_ID, $cSel)            ;Restore the caret
EndFunc   ;==>Listbox_ReverseSelection


Func Listbox_ItemMoveUD($hLB_ID, $iDir = -1)
    ;$iDir: -1 up, 1 down
    Local $iCur, $iNxt, $aCou, $aSel, $i   ;Current, next, Count, Selection, loop

    $aSel = _GUICtrlListBox_GetSelItems($hLB_ID)
    $aCou = _GUICtrlListBox_GetCount($hLB_ID)

    Select
        Case $iDir = -1
            For $i = 1 To $aSel[0]
                If $aSel[$i] > 0 Then
                    $iNxt = _GUICtrlListBox_GetText($hLB_ID, $aSel[$i] - 1)   ;$iNxt means $i_previous
                    _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i] - 1, _GUICtrlListBox_GetText($hLB_ID, $aSel[$i]))
                    _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i], $iNxt)
                EndIf
            Next
            For $i = 1 To $aSel[0]
                If $aSel[$i] > 0 Then
                    _GUICtrlListBox_SetSel($hLB_ID, $aSel[$i] - 1, 1)
                EndIf
            Next
        Case $iDir = 1
            If $aSel[0] > 0 Then
                For $i = $aSel[0] To 1 Step -1
                    If $aSel[$i] < $aCou - 1 Then
                        $iNxt = _GUICtrlListBox_GetText($hLB_ID, $aSel[$i] + 1) ;$iNxt means $i_previous
                        _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i] + 1, _GUICtrlListBox_GetText($hLB_ID, $aSel[$i]))
                        _GUICtrlListBox_ReplaceString($hLB_ID, $aSel[$i], $iNxt)
                    EndIf
                Next
            EndIf
            For $i = $aSel[0] To 1 Step -1
                If $aSel[$i] < $aCou - 1 Then
                    _GUICtrlListBox_SetSel($hLB_ID, $aSel[$i] + 1, 1)
                EndIf
            Next
    EndSelect

EndFunc   ;==>Listbox_ItemMoveUD

Func EmptyListView($id)
    _GUICtrlListView_BeginUpdate($id)
    _GUICtrlListView_DeleteAllItems($id)
    _GUICtrlListView_EndUpdate($id)
EndFunc   ;==>EmptyListView

Func readlinkini2list($free = 0)
    ;$free=0 read ini $free=1 return a free spot to write!
    Local $y, $t0, $t1, $t2, $t3
    For $y = 0 To $inilinkentriesmax
        $t0 = IniRead($inifile, "link", ($y & "0"), "")
        $t1 = IniRead($inifile, "link", ($y & "1"), "")
        $t2 = IniRead($inifile, "link", ($y & "2"), "")
        $t3 = IniRead($inifile, "link", ($y & "3"), "")
        If $t0 <> "" Then
            GUICtrlCreateListViewItem($y & "|" & $t0 & "|" & $t1 & "|" & $t2 & "|" & $t3, $L_preset)
        EndIf
    Next
EndFunc   ;==>readlinkini2list

Func WriteInputToIni($nr)
    IniWrite($inifile, "link", $nr & "1", GUICtrlRead($Input1))
    IniWrite($inifile, "link", $nr & "2", GUICtrlRead($Input2))
    IniWrite($inifile, "link", $nr & "3", GUICtrlRead($Input3))
EndFunc   ;==>WriteInputToIni



Func IniAddButton($section)
    Local $ctxt = "", $t, $x, $txt, $Combo, $Edit, $nr

    If $section = "mainform" Then
        $Combo = $Combo2
        $Edit = $Edit3
        $txt = $txt_mainform
        $nr = $nr_mainform
    EndIf

    If $section = "style" Then
        $Combo = $Combo1
        $Edit = $Edit1
        $txt = $txt_styleform
        $nr = $nr_styleform
    EndIf

    $ctxt = _GUICtrlComboBox_GetEditText($Combo)
    If $ctxt = $txt Then
        $t = EditToIniString($Edit)
        $x = 0
        If $t <> "" Then $x = IniUpdateCombo($section, $t, $nr)
        If $x > 0 Then IniGet($section)
    ElseIf $ctxt <> "" Then
        $t = EditToIniString($Edit)
        $x = 0
        If $t <> "" Then $x = IniUpdateCombo($section, $t, -1, $ctxt)
        If $x > 0 Then IniGet($section)
    EndIf
EndFunc   ;==>IniAddButton

Func IniUpdateCombo($section, $txt, $nr = -1, $newname = "")
    ;if $txt="" delete, if $txt<>"" add
    Local $x, $y, $t, $z = 0, $cmbox, $t1, $t2, $done = 0
    If $section = "mainform" Then
        $cmbox = $Combo2
        $y = $inimainformentriesmax - 1
        $t1 = $txt_mainform
        $t2 = $nr_mainform
    EndIf

    If $section = "style" Then
        $cmbox = $Combo1
        $y = $inistyleentriesmax - 1
        $t1 = $txt_styleform
        $t2 = $nr_styleform
    EndIf

    If $txt = "" Then
        If $nr > -1 Then
            StatusWrite($section & ": Trying to delete item #" & $t2 & " : " & $t1)
            If MsgBox(1, "Delete", "Delete the #" & $t2 & @CRLF & $t1) = 1 Then
                IniWrite($inifile, $section, $nr & "0", "")
                $done = 1
            EndIf
        EndIf
    Else
        If $nr = -1 Then
            $z = 1
        Else
            If MsgBox(1, "Overwrite ?", "Do you want to overwrite" & @CRLF & $t2 & ": " & $t1 & @CRLF & "p.s. under the same name! ") = 1 Then
                IniWrite($inifile, $section, $nr & "1", $txt)
                $done = 1
            Else
                $z = 2
            EndIf
        EndIf

        If $z > 0 Then
            $x = 0
            Do
                $t = IniRead($inifile, $section, $x & "0", "")
                If $t = "" Then
                    If $z = 2 Then
                        $newname = InputBox("Name entry", "Please enter a new name", "New Name")
                        If $newname = "" And @error = 0 Then $newname = "Auto renamed"
                        If @error = 1 And $newname = "" Then $z = 5
                    EndIf
                    If $z < 5 Then
                        IniWrite($inifile, $section, $x & "0", $newname)
                        IniWrite($inifile, $section, $x & "1", $txt)
                        $done = 1
                    EndIf
                    $x = $y
                EndIf
                $x = $x + 1
            Until $x > $y

        EndIf
        StatusWrite("Operation successful!")
        If $done = 0 Then StatusWrite("Error - Could not save - Full slots or cancelled")
    EndIf

    Return $done
EndFunc   ;==>IniUpdateCombo

Func IniGet($section)
    Local $x, $y, $t, $txt, $z = 0, $cmbox

    If $section = "mainform" Then
        $cmbox = $Combo2
        $y = $inimainformentriesmax - 1
        For $x = 0 To $y
            $a_mainform[$x] = ""
        Next
    EndIf

    If $section = "style" Then
        $cmbox = $Combo1
        $y = $inistyleentriesmax - 1
        For $x = 0 To $y
            $a_style[$x] = ""
        Next
    EndIf
    _GUICtrlComboBox_ResetContent($cmbox)
    For $x = 0 To $y
        $t = IniRead($inifile, $section, $x & "0", "")

        If $t <> "" Then
            $txt = IniRead($inifile, $section, $x & "1", "")
            If $txt <> "" Then
                If $section = "mainform" Then $a_mainform[$z] = $x
                If $section = "style" Then $a_style[$z] = $x
                _GUICtrlComboBox_AddString($cmbox, $t)
                $z = $z + 1
            EndIf
        EndIf
    Next
EndFunc   ;==>IniGet

Func StringIniToEdit($ed, $section, $nr = -1)
    ;Local $txt="<HTML>~n<HEAD>~n<TITLE>My Web Page</TITLE>~n</HEAD>~n<FRAMESET COLS=" & $c1 & "14%,86%" & $c1 & ">~n<FRAME NAME=" & $c1 & "menuLeft" & $c1 & " SRC=" & $c1 & "!mleft.html" & $c1 & ">~n<FRAME NAME=" & $c1 & "mainframe" & $c1 & ">~n</FRAMESET>~n<NOFRAMES></NOFRAMES>~n<BODY></BODY>~n</HTML>~n"
    Local $txt
    $txt = IniRead($inifile, $section, $nr & "1", "")
    Local $str = StringReplace($txt, "~n", @CRLF)
    _GUICtrlEdit_BeginUpdate($ed)
    MemoWrite($ed, $str, 1)
    _GUICtrlEdit_EndUpdate($ed)
EndFunc   ;==>StringIniToEdit

Func EditToIniString($id)
    Local $LC = _GUICtrlEdit_GetLineCount($id), $t = "", $n = ""
    _GUICtrlEdit_BeginUpdate($id)
    For $x = 0 To $LC - 1
        If $x < ($LC - 1) Then
            $n = "~n"
        Else
            $n = ""
        EndIf
        $t = $t & _GUICtrlEdit_GetLine($id, $x) & $n
    Next
    _GUICtrlEdit_EndUpdate($id)
    Return $t
EndFunc   ;==>EditToIniString

Func CloseGuiOnDoubleClick($typ)
    $typ = StringLower($typ)
    Select
        Case $typ = "button"
            If $closecounter = 1 And TimerDiff($TimeHandle) <= $closingdelay Then
                GUIDelete()
                Exit
            EndIf
            If $closecounter = 0 Then
                $closecounter = 1
                $TimeHandle = TimerInit()
                WinSetTitle($Form1, "", "To close, use Slow doubleclick on the X ! Or (2* Alt F4) or (2*Esc)")
            EndIf
        Case $typ = "loop"
            If $closecounter = 1 And TimerDiff($TimeHandle) > $closingdelay Then
                $closecounter = 0
                WinSetTitle($Form1, "", $formTitle)
            EndIf
    EndSelect
EndFunc   ;==>CloseGuiOnDoubleClick


Func DisplayReadMe()
    $readmeEditflag = 1
    $AboutForm1 = GUICreate("Read Me", 550, 400, 10, 10, BitOR($WS_CAPTION, $WS_THICKFRAME, $WS_MAXIMIZEBOX))
    $ReadmeEdit1 = GUICtrlCreateEdit("", 0, 0, 549, 399)
    GUICtrlSetData(-1, "")
    GUISetState(@SW_SHOW)

    AddText("Written by Dan in 2020." & $2crlf & "How to use:" & @CRLF & "  1. Click on the open button from the toolbar. " & @CRLF & "  2. Select multiple files from a folder. " & @CRLF & "  3. Use checkboxes to change the appearance of the filename." & @CRLF & "  4. Then click on preview." & $2crlf)
    AddText("If you are satisfied with the code in the Preview Source edit box, then click on the disc icon (save). " & @CRLF & "If not, repeat the steps 3 and 4." & $2crlf)
    AddText("Before saving, you can manually edit the preview source. " & $2crlf & " You can only choose a folder where the files are saved. " & @CRLF & "The saved filenames are !index.html and !mleft.html" & @CRLF)
    AddText("If the files exists, you will be asked to overwrite them, or to enter a new name. The new name does not need to have an extension but:" & @CRLF & " The new index.html may not find the correct file for the !mleft.html, which is defined in the main form code text ! (if using the default settings)" & $2crlf)
    AddText("- Style Text and Main form code usage:" & @CRLF & "   Change the text in the edit boxes. " & @CRLF & "   Enter a name in the combo box and click on + to save it." & @CRLF & "   Choose an existing entry in the combo box, then click - to delete it." & $2crlf & "   To overwrite a specific entry in the combo box, choose one, and click on + and  you will be asked to overwrite under the same name. ")
    AddText("   Yes will overwrite it, No will ask you for a new name and save it (but only if there are free slots, else it would do nothing !) " & $2crlf & "- Link construction:" & @CRLF & "   Enter the desired html code in the 3 edit boxes (code before, mid, end part)" & $2crlf & "   Click on Add to save them for later usage." & @CRLF & "   If an entry is selected, you will be asked to overwite it. " & @CRLF & "   (yes to overwrite, no to add a new entry (if free slots are available) no to cancel)" & @CRLF)
    AddText("   Add button will ask for a name if nothing is selected, or ask to overwrite the selection." & @CRLF & "   Overwriting here will always ask for a name. If cancel is selected (on the name selection, it will not be saved." & $2crlf)
    AddText("P.S." & @CRLF & "Check the status bar for error messages or additional information  !" & @CRLF & "Changes are saved in the HtmlMenuMaker.ini file, in the same folder from which the .exe was started.(at least this app is trying to write there, if it has the writing permissions to do so!)" & @CRLF & "(checkbox states are not saved )" & $2crlf & "Deleting operation does not delete the code, it sets the name to an empty string ! " & @CRLF & "If something is accidentally deleted, then editing the .ini file and adding a text to the x0= entry will undelete it. ")
    AddText("(where x is the deleted number, e.g. 10= or 20= or 30=)(restarting the app is required after the ini change.)" & $2crlf & "To close the app, double click on the X 2 times, slowly." & @CRLF & "You can pass a folder to the .exe file as a parameter, and the opening folder will start there" & @CRLF & "e.g. HtmlMenuMaker.exe c:\games\")
    _GUICtrlEdit_SetSel($ReadmeEdit1, 0, 0)
    _GUICtrlEdit_Scroll($ReadmeEdit1, $SB_SCROLLCARET)
    While 1
        $nMsg = GUIGetMsg(1)
        Switch $nMsg[0]
            Case $GUI_EVENT_CLOSE
                If $nMsg[1] = $AboutForm1 Then
                    GUIDelete($AboutForm1)
                    $readmeEditflag = 0
                    ExitLoop
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>DisplayReadMe

Func AddText($edittxt)
    _GUICtrlEdit_AppendText($ReadmeEdit1, $edittxt & @CRLF)
EndFunc   ;==>AddText

; Check if the filepath is a directory/folder. Does not validate if the directory/folder exists.
Func IsDir($sFilePath)
    Return StringInStr(FileGetAttrib($sFilePath), "D") > 0
EndFunc   ;==>IsDir
Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...