#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=changelog.ico
#AutoIt3Wrapper_outfile=Changelogcreator.exe
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_Res_Fileversion=1.0.0.3
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
#AutoIt3Wrapper_Res_LegalCopyright=Lucas Buchwald
#AutoIt3Wrapper_Res_Language=1031
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Array.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GuiComboBox.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>
#include <GuiButton.au3>
#include 'include/images_include.au3'



Global Const $imagepath = @TempDir & "\CC_IMG"
_Include_changelog_images_StartUp($imagepath)
OnAutoItExitRegister("_Include_changelog_images_ShutDown")

Global Const $REG_EX_GET_FUNC = '(?m:^|\n)Func\s([^(]*)'
Global Const $REG_EX_GET_VERSION = '(?m:^|\n)#AutoIt3Wrapper_Res_Fileversion=\s*(.*?)(?m:$|\r)'
Global $oChangeDict = ObjCreate("Scripting.Dictionary")
Global $hImagelist, $ButtonImageList[5]
Create_LV_Imagelist()


#region ### START Koda GUI section ### Form=
$hGUI = GUICreate("Changelog Creator", 627, 517, 192, 124)
GUICtrlCreateGroup("", 8, 8, 601, 81)
$Show_au3file_Path = GUICtrlCreateInput("", 16, 24, 353, 21, $ES_READONLY)
$Import_Au3_Button = GUICtrlCreateButton(".au3 Datei öffnen", 384, 24, 209, 25, $WS_GROUP)
$Show_Changefile_Path = GUICtrlCreateInput("", 16, 56, 353, 21, $ES_READONLY)
$Import_Changefile_Button = GUICtrlCreateButton("Changelog Datei öffnen", 384, 56, 209, 25, $WS_GROUP)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", 8, 96, 601, 329)
$All_Funcs_Combo = GUICtrlCreateCombo("", 16, 112, 153, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
$Add_Func_Button = GUICtrlCreateButton("Add", 184, 112, 105, 25, $WS_GROUP)
GUICtrlCreateLabel("Version", 360, 112, 55, 17)
$Version = GUICtrlCreateInput("", 424, 112, 121, 21)
$Changed_Funcs_Combo = GUICtrlCreateCombo("", 16, 144, 153, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
$Remove_Func_Button = GUICtrlCreateButton("Remove", 184, 144, 105, 25, $WS_GROUP)
$Status_Combo = GUICtrlCreateCombo("", 16, 176, 73, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData(-1, "Fixed|Added|Removed", "Fixed")
$Input_Text = GUICtrlCreateInput("", 96, 176, 153, 21)
$Add_Text_Button = GUICtrlCreateButton("Add Text", 264, 176, 105, 25, $WS_GROUP)
$Add_Link_Button = GUICtrlCreateButton("Add Link", 373, 176, 105, 25, $WS_GROUP)
$Remove_Text_Button = GUICtrlCreateButton("Remove Text", 482, 176, 105, 25, $WS_GROUP)
$hListView = GUICtrlCreateListView("", 16, 216, 565, 188, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_NOCOLUMNHEADER), 512)
_GUICtrlListView_SetExtendedListViewStyle(-1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_BORDERSELECT, $LVS_EX_ONECLICKACTIVATE, $LVS_EX_DOUBLEBUFFER))
_GUICtrlListView_AddColumn($hListView, "Data", 561)
_GUICtrlListView_SetImageList($hListView, $hImagelist, 1)
$cb = _GUICtrlListView_RegisterSortCallBack($hListView)
If Not IsHWnd($hListView) Then _GUICtrlListView_RegisterSortCallBack(GUICtrlGetHandle($hListView))
GUICtrlSetData(-1, "")
GUICtrlSetFont(-1, 8.5, 400, Default, "Courier New")
;~ $Sortbutton = GUICtrlCreateButton("", 565 + 16 + 2, 205 + 20, 24, 24, $BS_ICON)
;~ _GUICtrlButton_SetImageList($Sortbutton, $ButtonImageList[4], 4)
$upupbutton = GUICtrlCreateButton("", 565 + 16 + 2, 230 + 20, 24, 24, $BS_ICON)
_GUICtrlButton_SetImageList($upupbutton, $ButtonImageList[2], 4)
$upbutton = GUICtrlCreateButton("", 565 + 16 + 2, 255 + 20, 24, 24, $BS_ICON)
_GUICtrlButton_SetImageList($upbutton, $ButtonImageList[0], 4)
$downbutton = GUICtrlCreateButton("", 565 + 16 + 2, 285 + 20, 24, 24, $BS_ICON)
_GUICtrlButton_SetImageList($downbutton, $ButtonImageList[1], 4)
$downdownbutton = GUICtrlCreateButton("", 565 + 16 + 2, 310 + 20, 24, 24, $BS_ICON)
_GUICtrlButton_SetImageList($downdownbutton, $ButtonImageList[3], 4)

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", 8, 432, 601, 73)
GUICtrlCreateLabel("Exportformat", 16, 450, 209, 20, $SS_CENTER)
$Exportformat = GUICtrlCreateCombo("", 16, 472, 209, 25, $CBS_DROPDOWNLIST)
GUICtrlSetData($Exportformat, "BBCode|HTML", "BBCode")
$Copy_Clipboard_Button = GUICtrlCreateButton("Copy to Clipboard", 272, 455, 121, 40, $WS_GROUP)
$Export_Button = GUICtrlCreateButton("Export", 400, 455, 121, 40, $WS_GROUP)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Import_Au3_Button
			Open_Au3()
		Case $Import_Changefile_Button

		Case $Add_Func_Button
			Add_Changed_Func()
		Case $Remove_Func_Button
			Remove_Changed_Func()
		Case $Add_Text_Button
			Add_Text()
		Case $Remove_Text_Button
			Remove_Text()
		Case $Changed_Funcs_Combo
			Load_Changed_Func_Changelog()
		Case $upbutton
			Move_LV_Entry_up(False)
		Case $upupbutton
			Move_LV_Entry_up(True)
		Case $downbutton
			Move_LV_Entry_down(False)
		Case $downdownbutton
			Move_LV_Entry_down(True)
		Case $Add_Link_Button
			Add_Link()
		Case $Copy_Clipboard_Button
			Export(False)
		Case $Export_Button
			Export(True)
;~ 		Case $Sortbutton
;~ 			SortListview()
	EndSwitch
WEnd


Func Export($ToFile)
	If GUICtrlRead($Show_au3file_Path) = "" Then Return 0
	Local $sPath, $sFilter, $changedarray, $sRet, $type
	$rettype = GUICtrlRead($Exportformat)
	Switch $rettype
		Case "BBCode"
			$type = ".txt"
			$sFilter = "Textdatei (*." & $type & ")"
			$sRet = "[color=#0040FF][size=12][b]Version " & GUICtrlRead($Version) & "[/b][/size][/color]" & @CRLF
		Case "HTML"
			$type = ".html"
			$sFilter = "Htmldatei (*." & $type & ")"
			$sRet &= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">' & @CRLF
			$sRet &= '<html>' & @CRLF
			$sRet &= '<head>' & @CRLF
			$sRet &= '<title>Changelog</title>' & @CRLF
			$sRet &= '<style type="text/css">' & @CRLF
			$sRet &= '/* changelog_Outer */' & @CRLF
			$sRet &= '.changelog_Outer { background-color: #1d1d1d;}' & @CRLF
			$sRet &= '/* changelog_version */' & @CRLF
			$sRet &= '.changelog_version { color:#0040FF; padding-top:15px;padding-left:10px;}' & @CRLF
			$sRet &= '/* changelog_Inner */' & @CRLF
			$sRet &= '.changelog_Inner { color:#eee; }' & @CRLF
			$sRet &= '.changelog_Inner ul { font-size:18px; }' & @CRLF
			$sRet &= '.changelog_Inner ul li { }' & @CRLF
			$sRet &= '.changelog_Inner ul li ul { list-style-image: url("../images/nested.png"); padding:5px 0 5px 18px; font-size:15px; }' & @CRLF
			$sRet &= '.changelog_Inner ul li ul li { color:#bfe1f1; height:15px; margin-left:10px; }' & @CRLF
			$sRet &= '</style>' & @CRLF
			$sRet &= '</head>' & @CRLF
			$sRet &= '<body>' & @CRLF
			$sRet &= @TAB & '<div class="changelog_Outer">' & @CRLF
			$sRet &= @TAB & @TAB & '<div class="changelog_version">Version ' & GUICtrlRead($Version) & '</div>' & @CRLF
			$sRet &= @TAB & @TAB & @TAB & '<div class="changelog_Inner">' & @CRLF
			$sRet &= @TAB & @TAB & @TAB & @TAB & '<ul>' & @CRLF
	EndSwitch
	If $ToFile Then
		$sPath = FileOpenDialog("Speicherpfad wählen", @DesktopDir, $sFilter, "Export" & $type)
		If @error Then Return 0
	EndIf
	$changedarray = _GUICtrlComboBox_GetListArray($Changed_Funcs_Combo)
	For $I = 1 To $changedarray[0]
		$split = StringSplit($oChangeDict($changedarray[$I]), "&datasepchar;", 1)
		Switch $rettype
			Case "BBCode"
				$sRet &= "[color=#0000FF][size=10][b]" & $changedarray[$I] & "[/b][/size][/color]" & @CRLF
				$sRet &= "[list]" & @CRLF
			Case "HTML"
				$sRet &= @TAB & @TAB & @TAB & @TAB & @TAB & '<li>' & $changedarray[$I] & @CRLF
				$sRet &= @TAB & @TAB & @TAB & @TAB & @TAB & @TAB & '<ul>' & @CRLF
		EndSwitch
		For $k = 2 To $split[0]
			Switch $rettype
				Case "BBCode"
					$sRet &= "[*]" & $split[$k] & @CRLF
				Case "HTML"
					$sRet &= @TAB & @TAB & @TAB & @TAB & @TAB & @TAB & @TAB & '<li>' & _ConvertEntities($split[$k], False) & '</li>' & @CRLF
			EndSwitch
		Next
		Switch $rettype
			Case "BBCode"
				$sRet &= "[/list]" & @CRLF
			Case "HTML"
				$sRet &= @TAB & @TAB & @TAB & @TAB & @TAB & @TAB & '</ul>' & @CRLF
				$sRet &= @TAB & @TAB & @TAB & @TAB & @TAB & '</li>' & @CRLF
		EndSwitch
	Next
	If $rettype = "HTML" Then
		$sRet &= @TAB & @TAB & @TAB & @TAB & '</ul>' & @CRLF
		$sRet &= @TAB & @TAB & @TAB & '</div>' & @CRLF
		$sRet &= @TAB & @TAB & '</div>' & @CRLF
		$sRet &= @TAB & '</div>' & @CRLF
		$sRet &= '</body>' & @CRLF
		$sRet &= '</html>' & @CRLF
	EndIf
	If Not $ToFile Then
		ClipPut($sRet)
		MsgBox(64, "Erfolg", "Die Daten wurden in die Zwischenablage kopiert!")
	Else
		$hFile = FileOpen($sPath & $type, 10)
		FileWrite($hFile, $sRet)
		FileClose($hFile)
		MsgBox(64, "Erfolg", "Die Datei wurde erstellt!")
	EndIf
EndFunc   ;==>Export

Func SortListview()
	Local $hWnd
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	$sort = _GUICtrlListView_SortItems($hWnd, 0)
;~ 	ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sort = ' & $sort & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
EndFunc   ;==>SortListview

Func Open_Au3()
	$FilePath = FileOpenDialog("Au3 Datei öffnen", @DesktopDir, "AutoIt Source (*.au3)")
	GUICtrlSetData($Show_au3file_Path, $FilePath)
	$hFile = FileOpen($FilePath, 0)
	$Read = FileRead($hFile)
	FileClose($hFile)
	$Find_Version = StringRegExp($Read, $REG_EX_GET_VERSION, 3)
	If IsArray($Find_Version) Then GUICtrlSetData($Version, $Find_Version[0])
	$Funcs = StringRegExp($Read, $REG_EX_GET_FUNC, 3)
	If Not IsArray($Funcs) Then Return SetError(1, 0, 0)
	_ArraySort($Funcs)
	For $I = 0 To UBound($Funcs) - 1
		_GUICtrlComboBox_AddString($All_Funcs_Combo, $Funcs[$I])
	Next
EndFunc   ;==>Open_Au3

Func Add_Changed_Func()
	Local $hWnd
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	$CurSel = GUICtrlRead($All_Funcs_Combo)
	If $CurSel = "" Then Return 0
	_GUICtrlComboBox_AddString($Changed_Funcs_Combo, $CurSel)
	$oChangeDict($CurSel) = ""
	_GUICtrlComboBox_DeleteString($All_Funcs_Combo, _GUICtrlComboBox_GetCurSel($All_Funcs_Combo))
	Sort_Combobox($All_Funcs_Combo)
	Sort_Combobox($Changed_Funcs_Combo)
	_GUICtrlComboBox_SetCurSel($All_Funcs_Combo, -1)
	_GUICtrlComboBox_SetCurSel($Changed_Funcs_Combo, _GUICtrlComboBox_FindString($Changed_Funcs_Combo, $CurSel))
	_GUICtrlListView_DeleteAllItems($hWnd)
EndFunc   ;==>Add_Changed_Func

Func Remove_Changed_Func()
	$CurSel = GUICtrlRead($Changed_Funcs_Combo)
	If $CurSel = "" Then Return 0
	_GUICtrlComboBox_AddString($All_Funcs_Combo, $CurSel)
	$oChangeDict.remove($CurSel)
	_GUICtrlComboBox_DeleteString($Changed_Funcs_Combo, _GUICtrlComboBox_GetCurSel($Changed_Funcs_Combo))
	Sort_Combobox($All_Funcs_Combo)
	Sort_Combobox($Changed_Funcs_Combo)
	_GUICtrlComboBox_SetCurSel($Changed_Funcs_Combo, -1)
	Local $hWnd
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	_GUICtrlListView_DeleteAllItems($hWnd)
EndFunc   ;==>Remove_Changed_Func

Func Sort_Combobox($combobox)
	$Listarray = _GUICtrlComboBox_GetListArray($combobox)
	_ArrayDelete($Listarray, 0)
	If $Listarray[0] = "" Then _ArrayDelete($Listarray, 0)
	_ArraySort($Listarray)
	_GUICtrlComboBox_ResetContent($combobox)
	For $I = 0 To UBound($Listarray) - 1
		_GUICtrlComboBox_AddString($combobox, $Listarray[$I])
	Next
EndFunc   ;==>Sort_Combobox

Func Add_Text()
	Local $hWnd
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	If GUICtrlRead($Input_Text) = "" Then Return 0
	Local $icon
	$CurSel = GUICtrlRead($Changed_Funcs_Combo)
	If $CurSel = "" Then Return 0
	Switch GUICtrlRead($Status_Combo)
		Case "Fixed"
			$icon = 0
		Case "Added"
			$icon = 1
		Case "Removed"
			$icon = 2
	EndSwitch
	$oChangeDict($CurSel) = $oChangeDict($CurSel) & "&datasepchar;" & StringFormat("%-10s", GUICtrlRead($Status_Combo)) & ": " & GUICtrlRead($Input_Text)
	_GUICtrlListView_AddItem($hWnd, StringFormat("%-10s", GUICtrlRead($Status_Combo)) & ": " & @TAB & GUICtrlRead($Input_Text), $icon)
	GUICtrlSetData($Input_Text, "")
	_GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE)
	If _GUICtrlListView_GetColumnWidth($hWnd, 0) < 561 Then _GUICtrlListView_SetColumnWidth($hWnd, 0, 561)
	ControlFocus($hGUI, "", $Input_Text)
EndFunc   ;==>Add_Text

Func Remove_Text()
	Local $hWnd
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	$CurSelList = _GUICtrlListView_GetSelectedIndices($hWnd)
	If $CurSelList = "" Then Return SetError(1, 0, -1)
	$CurSel = GUICtrlRead($Changed_Funcs_Combo)
	If $CurSel = "" Then Return 0
	$oChangeDict($CurSel) = StringReplace($oChangeDict($CurSel), "&datasepchar;" & _GUICtrlListView_GetItemText($hWnd, $CurSelList), "")
	_GUICtrlListView_DeleteItem($hWnd, $CurSelList)
	_GUICtrlListView_SetColumnWidth($hWnd, 0, $LVSCW_AUTOSIZE)
	If _GUICtrlListView_GetColumnWidth($hWnd, 0) < 561 Then _GUICtrlListView_SetColumnWidth($hWnd, 0, 561)
EndFunc   ;==>Remove_Text

Func Create_LV_Imagelist()
	$hImagelist = _GUIImageList_Create(24, 24, 5, 1)
	_GUIImageList_AddIcon($hImagelist, $imagepath & "\fixed.ico", 0, True)
	_GUIImageList_AddIcon($hImagelist, $imagepath & "\add.ico", 0, True)
	_GUIImageList_AddIcon($hImagelist, $imagepath & "\remove.ico", 0, True)
	$ButtonImageList[0] = _GUIImageList_Create(24, 24, 5, 1)
	_GUIImageList_AddIcon($ButtonImageList[0], $imagepath & "\up.ico", 0, True)
	$ButtonImageList[1] = _GUIImageList_Create(24, 24, 5, 1)
	_GUIImageList_AddIcon($ButtonImageList[1], $imagepath & "\down.ico", 0, True)
	$ButtonImageList[2] = _GUIImageList_Create(24, 24, 5, 1)
	_GUIImageList_AddIcon($ButtonImageList[2], $imagepath & "\upup.ico", 0, True)
	$ButtonImageList[3] = _GUIImageList_Create(24, 24, 5, 1)
	_GUIImageList_AddIcon($ButtonImageList[3], $imagepath & "\downdown.ico", 0, True)
	$ButtonImageList[4] = _GUIImageList_Create(24, 24, 5, 1)
	_GUIImageList_AddIcon($ButtonImageList[4], $imagepath & "\Sort_asc.ico", 0, True)
EndFunc   ;==>Create_LV_Imagelist

Func Load_Changed_Func_Changelog()
	Local $hWnd, $icon
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	_GUICtrlListView_DeleteAllItems($hWnd)
	$CurSel = GUICtrlRead($Changed_Funcs_Combo)
	If $CurSel = "" Then Return 0
	$split = StringSplit($oChangeDict($CurSel), "&datasepchar;", 1)
	For $I = 2 To $split[0]
		Switch StringLeft($split[$I], 1)
			Case "F"
				$icon = 0
			Case "A"
				$icon = 1
			Case "R"
				$icon = 2
		EndSwitch
		_GUICtrlListView_AddItem($hWnd, $split[$I], $icon)
	Next
EndFunc   ;==>Load_Changed_Func_Changelog

Func Move_LV_Entry_up($step)
	Local $hWnd, $changeseltext
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	$CurSelList = _GUICtrlListView_GetSelectedIndices($hWnd)
	If $CurSelList = "" Then Return SetError(1, 0, -1)
	$CurSel = GUICtrlRead($Changed_Funcs_Combo)
	If $CurSel = "" Or $CurSelList = 0 Then
		ControlFocus($hGUI, "", $hWnd)
		Return 0
	EndIf
	_GUICtrlListView_BeginUpdate($hWnd)
	If Not $step Then
		_GUICtrlListView_InsertItem($hWnd, _GUICtrlListView_GetItemText($hWnd, $CurSelList), $CurSelList - 1, _GUICtrlListView_GetItemImage($hWnd, $CurSelList))
		_GUICtrlListView_DeleteItem($hWnd, $CurSelList + 1)
		_GUICtrlListView_SetItemSelected($hWnd, $CurSelList - 1, True, True)
	Else
		_GUICtrlListView_InsertItem($hWnd, _GUICtrlListView_GetItemText($hWnd, $CurSelList), 0, _GUICtrlListView_GetItemImage($hWnd, $CurSelList))
		_GUICtrlListView_DeleteItem($hWnd, $CurSelList + 1)
		_GUICtrlListView_SetItemSelected($hWnd, 0, True, True)
	EndIf
	_GUICtrlListView_EndUpdate($hWnd)
	ControlFocus($hGUI, "", $hWnd)
	$changeseltext = ""
	For $I = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
		$changeseltext &= "&datasepchar;" & _GUICtrlListView_GetItemText($hWnd, $I)
	Next
	$oChangeDict($CurSel) = $changeseltext
EndFunc   ;==>Move_LV_Entry_up

Func Move_LV_Entry_down($step)
	Local $hWnd, $changeseltext, $count
	If Not IsHWnd($hListView) Then
		$hWnd = GUICtrlGetHandle($hListView)
	Else
		$hWnd = $hListView
	EndIf
	$CurSelList = _GUICtrlListView_GetSelectedIndices($hWnd)
	If $CurSelList = "" Then Return SetError(1, 0, -1)
	$CurSel = GUICtrlRead($Changed_Funcs_Combo)
	$count = _GUICtrlListView_GetItemCount($hWnd) - 1
	If $CurSel = "" Or $CurSelList = $count Then
		ControlFocus($hGUI, "", $hWnd)
		Return 0
	EndIf
	_GUICtrlListView_BeginUpdate($hWnd)
	If Not $step Then
		$new = _GUICtrlListView_InsertItem($hWnd, _GUICtrlListView_GetItemText($hWnd, $CurSelList), $CurSelList + 2, _GUICtrlListView_GetItemImage($hWnd, $CurSelList))
		$del = _GUICtrlListView_DeleteItem($hWnd, $CurSelList)
		$sel = _GUICtrlListView_SetItemSelected($hWnd, $CurSelList + 1, True, True)
	Else
		_GUICtrlListView_InsertItem($hWnd, _GUICtrlListView_GetItemText($hWnd, $CurSelList), $count + 1, _GUICtrlListView_GetItemImage($hWnd, $CurSelList))
		_GUICtrlListView_DeleteItem($hWnd, $CurSelList)
		_GUICtrlListView_SetItemSelected($hWnd, $count + 1, True, True)
	EndIf
	_GUICtrlListView_EndUpdate($hWnd)
	ControlFocus($hGUI, "", $hWnd)
	$changeseltext = ""
	For $I = 0 To _GUICtrlListView_GetItemCount($hWnd) - 1
		$changeseltext &= "&datasepchar;" & _GUICtrlListView_GetItemText($hWnd, $I)
	Next
	$oChangeDict($CurSel) = $changeseltext
EndFunc   ;==>Move_LV_Entry_down

Func Add_Link()
	Local $sLink, $LinkDesc, $sString
	While True
		$sLink = InputBox("Link hinzufügen", "Bitte geben Sie die Adresse des Links ein", $sLink, " M")
		If @error = 1 Then Return 0
		$test = StringRegExp($sLink, "^(http(?:s)?\:\/\/[a-zA-Z0-9\-]+(?:\.[a-zA-Z0-9\-]+)*\.[a-zA-Z]{2,6}(?:\/?|(?:\/[\w\-]+)*)(?:\/?|\/\w+\.[a-zA-Z]{2,4}(?:\?[\w]+\=[\w\-]+)?)?(?:\&[\w]+\=[\w\-]+)*)$")
		If $test Then
			ExitLoop
		Else
			If MsgBox(262161, "Fehler", "Die eingebene Adresse ist kein Link!") = 2 Then Return 0
		EndIf
	WEnd
	$LinkDesc = InputBox("Beschreibung hinzufügen (Optional)", "Bitte geben Sie eine Beschreibung zum Link an")
	If @error = 1 Then $LinkDesc = $sLink
	$sString = "[url='" & $sLink & "']" & $LinkDesc & "[/url]"
	WinActivate($hGUI)
	ControlFocus($hGUI, "", $Input_Text)
	ControlCommand($hGUI, "", $Input_Text, "EditPaste", $sString)
EndFunc   ;==>Add_Link

; #FUNCTION# ====================================================================================================
; Description ...: _ConvertEntities
; Parameters ....: $sURL - IN - The Text to convert
; Return values .: Success - Converted string
; Author ........: Stephen Podhajecki {gehossafats at netmdc. com}
; Remarks .......: Replaces HTML escape sequences with character representation
;                  Based on information found here: http://www.theukwebdesigncompany.com/artic...-characters.php
;                  nbsp is changed to 32 instead of 160
; Related .......:
; ====================================================================================================
Func _ConvertEntities($sURL, $fEncode = True)
	Local $aEntities[96][2] = [["&quot;", 34],["&amp;", 38],["&lt;", 60],["&gt;", 62],["&nbsp;", 3],["&nbsp;", 32] _
			,["&iexcl;", 161],["&cent;", 162],["&pound;", 163],["&curren;", 164],["&yen;", 165],["&brvbar;", 166] _
			,["&sect;", 167],["&uml;", 168],["&copy;", 169],["&ordf;", 170],["&not;", 172],["&shy;", 173] _
			,["&reg;", 174],["&macr;", 175],["&deg;", 176],["&plusmn;", 177],["&sup2;", 178],["&sup3;", 179] _
			,["&acute;", 180],["&micro;", 181],["&para;", 182],["&middot;", 183],["&cedil;", 184],["&sup1;", 185] _
			,["&ordm;", 186],["&raquo;", 187],["&frac14;", 188],["&frac12;", 189],["&frac34;", 190],["&iquest;", 191] _
			,["&Agrave;", 192],["&Aacute;", 193],["&Atilde;", 195],["&Auml;", 196],["&Aring;", 197],["&AElig;", 198] _
			,["&Ccedil;", 199],["&Egrave;", 200],["&Eacute;", 201],["&Ecirc;", 202],["&Igrave;", 204],["&Iacute;", 205] _
			,["&Icirc;", 206],["&Iuml;", 207],["&ETH;", 208],["&Ntilde;", 209],["&Ograve;", 210],["&Oacute;", 211] _
			,["&Ocirc;", 212],["&Otilde;", 213],["&Ouml;", 214],["&times;", 215],["&Oslash;", 216],["&Ugrave;", 217] _
			,["&Uacute;", 218],["&Ucirc;", 219],["&Uuml;", 220],["&Yacute;", 221],["&THORN;", 222],["&szlig;", 223] _
			,["&agrave;", 224],["&aacute;", 225],["&acirc;", 226],["&atilde;", 227],["&auml;", 228],["&aring;", 229] _
			,["&aelig;", 230],["&ccedil;", 231],["&egrave;", 232],["&eacute;", 233],["&ecirc;", 234],["&euml;", 235] _
			,["&igrave;", 236],["&iacute;", 237],["&icirc;", 238],["&iuml;", 239],["&eth;", 240],["&ntilde;", 241] _
			,["&ograve;", 242],["&oacute;", 243],["&ocirc;", 244],["&otilde;", 245],["&ouml;", 246],["&divide;", 247] _
			,["&oslash;", 248],["&ugrave;", 249],["&uacute;", 250],["&ucirc;", 251],["&uuml;", 252],["&thorn;", 254]]
	If $fEncode Then
		For $x = 0 To UBound($aEntities) - 1
			$sURL = StringReplace($sURL, $aEntities[$x][0], Chr($aEntities[$x][1]), 0, 1)
		Next
		For $x = 32 To 255
			$sURL = StringReplace($sURL, "&#" & $x & ";", Chr($x))
		Next
	Else
		For $x = 0 To UBound($aEntities) - 1
			$sURL = StringReplace($sURL, Chr($aEntities[$x][1]), $aEntities[$x][0], 0, 1)
		Next
	EndIf
	Return $sURL
EndFunc   ;==>_ConvertEntities