Jump to content

Text Editor v2.8 (**Updated 7-7-12**)


Recommended Posts

This a Text Editor I Made to Be Like Notepad and it Turned out better than i thought it would.

(Updated (7-7-12)

+Added HotKeys

+Added Misc. Options (All Caps, All Lowercase, Readonly

+Moved Default and Custom Options to there own Menus Under Edit

+Cleaned up Code a little Bit

+Added Cut, Copy, And Paste to Edit Menu

-There is still a small Bug with word wrap. When you turn it off it appears to be off but its not. (Adds Horizontal Scroll bar at bottom)

+Im Currently working on a 'Run Script' Option and have added it under an 'Action' Menu but it is disabled.

(Updated 7-3-12)

+Added Word Wrap Option

+Fixed Save Bug

(Updated 6-29-12)

+Fixed a compilation bug

It Would be best to download the Archive and Extract the Script because some stuff is wierd when you copy the code and paste it into a Script. Like Hotkeys Being displayed in the Menus.

#NoTrayIcon
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Icon.ico
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIEdit.au3>
#include <Misc.au3>
#include <GUIStatusBar.au3>
#include <GUIMenu.au3>
#include <SendMessage.au3>

;Created by ReaperX

FileCheck()
Main()
SetFileAttr()

Func FileCheck()

If FileExists(@ScriptDir & "/config.ini") Then
$CE = IniReadSectionNames(@ScriptDir & "/config.ini")
If $CE[0] > 0 Then
For $i = 2 To $CE[0]
If Not FileExists($CE[$i]) Then IniDelete(@ScriptDir & "/config.ini", $CE[$i])
Next
EndIf
Main()
Else
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "11")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", "")
EndIf
Sleep(100)

EndFunc ;==>FileCheck


Func Main()
Global Const $GUI_TITLE = "Text Editor v2.8"
Global Const $GUI_STYLE = BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)
Local $Ext = ".au3 ,.bat ,.vbs ,.htm ,.html" ; Script Types Allowed to Be Executed (Only Extensions)
If IniRead(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1") = 1 Then
Global $EDIT_STYLE = BitOR($ES_WANTRETURN, $WS_VSCROLL)
Else
Global $EDIT_STYLE = $GUI_SS_DEFAULT_EDIT
EndIf

$Main = GUICreate($GUI_TITLE, 650, 280, -1, -1, $GUI_STYLE)
GUISetIcon("Icon.ico")
;File Menu ========================================================================
$FileMenu = GUICtrlCreateMenu("File")
$New = GUICtrlCreateMenuItem("New Ctrl+N", $FileMenu)
HotKeySet("^n", "_New")
$Open = GUICtrlCreateMenuItem("Open Ctrl+O", $FileMenu)
HotKeySet("^o", "_Open")
$Save = GUICtrlCreateMenuItem("Save Ctrl+S", $FileMenu)
HotKeySet("^s", "_Save")
$SaveAs = GUICtrlCreateMenuItem("Save As...", $FileMenu)
GUICtrlCreateMenuItem("", $FileMenu)
$Exit = GUICtrlCreateMenuItem("Exit", $FileMenu)
;=================================================================================
;View Menu =======================================================================
$ViewMenu = GUICtrlCreateMenu("View")
$DocInfo = GUICtrlCreateMenuItem("Document Info", $ViewMenu)
;=================================================================================
;Action Menu =====================================================================
$ActionMenu = GUICtrlCreateMenu("Action")
$Run = GUICtrlCreateMenuItem("Run Script", $ActionMenu)
GUICtrlSetState($Run, $GUI_DISABLE)
;=================================================================================
;Edit Menu =======================================================================
$EditMenu = GUICtrlCreateMenu("Edit")
$Undo = GUICtrlCreateMenuItem("Undo Ctrl+Z", $EditMenu, 0)
HotKeySet("^z", "_Undo")
GUICtrlCreateMenuItem("", $EditMenu, 1)
$Cut = GUICtrlCreateMenuItem("Cut Ctrl+X", $EditMenu, 2)
$Copy = GUICtrlCreateMenuItem("Copy Ctrl+C", $EditMenu, 3)
$Paste = GUICtrlCreateMenuItem("Paste Ctrl+P", $EditMenu, 4)
GUICtrlCreateMenuItem("", $EditMenu, 5)
$Find = GUICtrlCreateMenuItem("Find... Ctrl+F", $EditMenu, 6)
HotKeySet("^f", "_Find")
GUICtrlCreateMenuItem("", $EditMenu, 7)
;Edit -> Default Settings Menu ===================================================
Local $DefaultSett = GUICtrlCreateMenu("Default Settings", $EditMenu, 8)
$DefaultFont = GUICtrlCreateMenuItem("Edit Default Font", $DefaultSett)
$DefaultBGColor = GUICtrlCreateMenuItem("Edit Default BG Color", $DefaultSett)
$ResetDefaults = GUICtrlCreateMenuItem("Reset Default Settings", $DefaultSett)
;=================================================================================
GUICtrlCreateMenuItem("", $EditMenu, 9)
;Edit -> Custom Settings Menu ====================================================
Local $CustomSett = GUICtrlCreateMenu("Custom Settings", $EditMenu, 10)
$CustomFont = GUICtrlCreateMenuItem("Set Custom Font", $CustomSett)
GUICtrlSetState(-1, $GUI_DISABLE)
$CustomBGColor = GUICtrlCreateMenuItem("Set Custom BG Color", $CustomSett)
GUICtrlSetState(-1, $GUI_DISABLE)
$EraseCustomOpt = GUICtrlCreateMenuItem("Erase Custom Settings", $CustomSett)
GUICtrlSetState(-1, $GUI_DISABLE)
;=================================================================================
GUICtrlCreateMenuItem("", $EditMenu, 11)
$SetFileAttr = GUICtrlCreateMenuItem("Set File Attributes", $EditMenu, 12)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateMenuItem("", $EditMenu, 13)
;Edit -> Misc Options Menu =======================================================
$MiscOptions = GUICtrlCreateMenu("Misc. Options", $EditMenu, 14)
Local $Readonly = GUICtrlCreateMenuItem("Readonly", $MiscOptions)
GUICtrlSetState(-1, $GUI_UNCHECKED)
$CAPS = GUICtrlCreateMenuItem("All Caps (Not CAPS Lock)", $MiscOptions)
GUICtrlSetState(-1, $GUI_UNCHECKED)
$LOWERCASE = GUICtrlCreateMenuItem("All Lowercase", $MiscOptions)
GUICtrlSetState(-1, $GUI_UNCHECKED)
;=================================================================================
$SelectAll = GUICtrlCreateMenuItem("Select All Ctrl+A", $EditMenu, 15)
HotKeySet("^a", "_SelectAll")
$TimeAndDate = GUICtrlCreateMenuItem("Insert Time/Date F7", $EditMenu, 16)
HotKeySet("{F7}", "_TimeAndDate")
$SpeakText = GUICtrlCreateMenuItem("Speak Highlighted Text", $EditMenu, 17)
$WordWrap = GUICtrlCreateMenuItem("Word Wrap", $EditMenu, 18)
If IniRead(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1") = 1 Then
GUICtrlSetState(-1, $GUI_CHECKED)
Else
GUICtrlSetState(-1, $GUI_UNCHECKED)
EndIf
;=================================================================================
;Help Menu =======================================================================
$HelpMenu = GUICtrlCreateMenu("Help")
$About = GUICtrlCreateMenuItem("About", $HelpMenu, 1)
$AboutCustomSett = GUICtrlCreateMenuItem("Custom Settings", $HelpMenu, 2)
;=================================================================================

;Create Edit Control ===================================================================================
Global $Edit = GUICtrlCreateEdit("", 0, 0, 650, 238, $EDIT_STYLE)
;=======================================================================================================
;Create Status bar ============================================================
Local $Parts[1] = [70]
Global $StatusBar = _GUICtrlStatusBar_Create($Main, $Parts, $SB_SIMPLEID)
_GUICtrlStatusBar_SetParts($StatusBar, $Parts)
_GUICtrlStatusBar_SetText($StatusBar, "New Document")
;==============================================================================


If FileExists("temp") Then
GUICtrlSetData(-1, FileRead("temp")) ;For When and If Main() Has to be Called again. It Restores the Text in $Edit.
FileDelete("temp")
EndIf

GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"))
GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000"))
GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF"))

GUISetState()
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While 1
$Msg = GUIGetMsg()
Switch $Msg
Case -3
If FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) = GUICtrlRead($Edit) Then
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
Else
$Confirm = MsgBox(35, "Confirm", "Do You Want To Save Before Exiting?")
If $Confirm = 6 Then
If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
EndIf
$SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir)
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite($SaveDir, GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
EndIf
EndIf
EndIf
If $Confirm = 7 Then
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
EndIf
Case $New
_New()
Case $Open
_Open()
Case $DefaultBGColor
$NewBG = _ChooseColor(2)
If Not @error Then
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", $NewBG)
GUICtrlSetBkColor($Edit, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF"))
EndIf
Case $DefaultFont
$NewFont = _ChooseFont(IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), 0, 400, False, False, False, $Main)
If Not @error Then
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontsize", $NewFont[3])
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "attributes", $NewFont[1])
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontweight", $NewFont[4])
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", $NewFont[7])
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontname", $NewFont[2])
GUICtrlSetFont($Edit, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"))
GUICtrlSetColor($Edit, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000"))
EndIf
Case $ResetDefaults
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "11")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0")
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", "")
MsgBox(64, "Ok", "Default Settings Reset. Your Custom Options Were not Changed.")
Case $SaveAs
$SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
GUICtrlSetState($SetFileAttr, $GUI_ENABLE)
GUICtrlSetState($CustomFont, $GUI_ENABLE)
GUICtrlSetState($CustomBGColor, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir)
$INI = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "")
$GetExt = StringTrimLeft($INI, StringLen($INI) - 3) ; Get the Extension of the Currently Opened File
If StringInStr($Ext, $GetExt) Then GUICtrlSetState($Run, $GUI_ENABLE)
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
GUICtrlSetState($Save, $GUI_ENABLE)
_GUICtrlStatusBar_SetText($StatusBar, "Saving...")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
EndIf
Case $Save
_Save()
Case $TimeAndDate
_TimeAndDate()
Case $SpeakText
$SelText = _GUICtrlEdit_GetSel($Edit)
If $SelText[1] = 0 Then
MsgBox(16, "Error!", "Select Text First!")
Else
Global $Voice = ObjCreate("Sapi.SpVoice")
SpeakSelectedText(0.5, 100)
EndIf
Case $About
MsgBox(64, "About", "Text Editor" & @LF & @LF & "Version: 2.8" & @LF & @LF & "Created By ReaperX (C) 2011 - 2012")
Case $Find
_Find()
Case $SelectAll
_SelectAll()
Case $DocInfo
MsgBox(0, "Information", "Characters: " & _GUICtrlEdit_GetTextLen($Edit) & @LF & "Lines: " & _GUICtrlEdit_GetLineCount($Edit))
Case $Cut
Send("^x")
Case $Copy
Send("^c")
Case $Paste
GUICtrlSetData($Edit, GUICtrlRead($Edit) & ClipGet())
Case $Exit
If GUICtrlRead($Edit) = FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
Else
$Confirm = MsgBox(35, "Confirm", "Do You Want To Save Before Exiting?")
If $Confirm = 6 Then
If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
Exit
EndIf
$SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir)
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite($SaveDir, GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
Else
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
EndIf
EndIf
EndIf
If $Confirm = 7 Then
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
Exit
EndIf
Case $Undo
_Undo()
Case $CustomBGColor
$iFile = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")
$NewBG = _ChooseColor(2)
If Not @error Then
GUICtrlSetState($EraseCustomOpt, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", $iFile, "bgcolor", $NewBG)
GUICtrlSetBkColor($Edit, IniRead(@ScriptDir & "/config.ini", $iFile, "bgcolor", "0xFFFFFF"))
_GUICtrlStatusBar_SetText($StatusBar, "Custom Background Color Options Saved!")
Sleep(1000)
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!"))
EndIf
Case $CustomFont
$iFile = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")
$NewFont = _ChooseFont(IniRead(@ScriptDir & "/config.ini", $iFile, "fontname", "Arial"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontsize", "11"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontcolor", "0x000000"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontweight", "400"))
If Not @error Then
GUICtrlSetState($EraseCustomOpt, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", $iFile, "fontname", $NewFont[2])
IniWrite(@ScriptDir & "/config.ini", $iFile, "fontsize", $NewFont[3])
IniWrite(@ScriptDir & "/config.ini", $iFile, "attributes", $NewFont[1])
IniWrite(@ScriptDir & "/config.ini", $iFile, "fontweight", $NewFont[4])
IniWrite(@ScriptDir & "/config.ini", $iFile, "fontcolor", $NewFont[7])
GUICtrlSetFont($Edit, IniRead(@ScriptDir & "/config.ini", $iFile, "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", $iFile, "attributes", "0"), IniRead(@ScriptDir & "/config.ini", $iFile, "fontname", "Arial"))
GUICtrlSetColor($Edit, IniRead(@ScriptDir & "/config.ini", $iFile, "fontcolor", "0x000000"))
_GUICtrlStatusBar_SetText($StatusBar, "Custom Font Options Saved!")
Sleep(1000)
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!"))
EndIf
Case $EraseCustomOpt
$iFile = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!")
IniDelete(@ScriptDir & "/config.ini", $iFile)
GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"))
GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000"))
GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF"))
GUICtrlSetState($EraseCustomOpt, $GUI_DISABLE)
_GUICtrlStatusBar_SetText($StatusBar, "Custom File Options Erased!")
Sleep(1000)
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!"))
Case $SetFileAttr
$Attr = FileGetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"))
If Not @error Then
SetFileAttr()
Else
MsgBox(16, "Error!", "The File Attributes Could Not be Retrieved!")
EndIf
Case $AboutCustomSett
MsgBox(0, "About Custom Settings", "Custom BG and Font Settings are for Specific Files. You can open a file and have a Specific Background and Font color set for that file and No other file. This Doesnt mess with Default Settings. Default Settings Load When the Application first Opens and When no Custom Settings are Set For Any Open File.")
Case $WordWrap
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($WordWrap, $GUI_UNCHECKED)
GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "0")
Else
GUICtrlSetState($WordWrap, $GUI_CHECKED)
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL))
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "wordwrap", "1")
EndIf
Case $CAPS
If BitAND(GUICtrlRead($CAPS), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($CAPS, $GUI_UNCHECKED)
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL))
Else
GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)
EndIf
Else
GUICtrlSetState($CAPS, $GUI_CHECKED)
If BitAND(GUICtrlRead($LOWERCASE), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($LOWERCASE, $GUI_UNCHECKED)
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_UPPERCASE))
Else
GUICtrlSetStyle($Edit, $ES_UPPERCASE)
EndIf
EndIf
Case $Readonly
If BitAND(GUICtrlRead($Readonly), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($Readonly, $GUI_UNCHECKED)
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL))
Else
GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)
EndIf
Else
GUICtrlSetState($Readonly, $GUI_CHECKED)
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_READONLY))
Else
GUICtrlSetStyle($Edit, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
EndIf
EndIf
Case $LOWERCASE
If BitAND(GUICtrlRead($LOWERCASE), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetState($LOWERCASE, $GUI_UNCHECKED)
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL))
Else
GUICtrlSetStyle($Edit, $GUI_SS_DEFAULT_EDIT)
EndIf
Else
GUICtrlSetState($LOWERCASE, $GUI_CHECKED)
If BitAND(GUICtrlRead($CAPS), $GUI_CHECKED) = $GUI_CHECKED Then GUICtrlSetState($CAPS, $GUI_UNCHECKED)
If BitAND(GUICtrlRead($WordWrap), $GUI_CHECKED) = $GUI_CHECKED Then
GUICtrlSetStyle($Edit, BitOR($ES_WANTRETURN, $WS_VSCROLL, $ES_LOWERCASE))
Else
GUICtrlSetStyle($Edit, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
EndIf
EndIf
Case $Run
$INI = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "")
$GetExt = StringTrimLeft($INI, StringLen($INI) - 4) ; Get the Extension of the Currently Opened File
If Not $INI = "" Then
If StringInStr($Ext, $GetExt) Then
ShellExecute($INI)
If @Error Then
MsgBox(16, "Run Script", "An Error Occurred!")
EndIf
EndIf
EndIf
EndSwitch
WEnd
EndFunc ;==>Main


Func _Open()
Global $Edit, $StatusBar, $SetFileAttr, $CustomBGColor, $CustomFont, $EraseCustomOpt, $Main, $Run
Local $Ext = ".au3 ,.bat ,.vbs ,.htm ,.html" ; Script Types Allowed to Be Executed (Only Extensions)
If WinActive($GUI_TITLE) Then
If GUICtrlRead($Edit) = FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
$File = FileOpenDialog("Choose a Readable File", @ScriptDir, "All Files (*.*)|Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)")
If Not @error Then
GUICtrlSetState($SetFileAttr, $GUI_ENABLE)
GUICtrlSetState($CustomFont, $GUI_ENABLE)
GUICtrlSetState($CustomBGColor, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $File)

;$INI = IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "")
;$GetExt = StringTrimLeft($INI, StringLen($INI) - 4) ; Get the Extension of the Currently Opened File
;If StringInStr($Ext, $GetExt) Then
;GUICtrlSetState($Run, $GUI_ENABLE)
;EndIf

GUICtrlSetData($Edit, FileRead($File))
$A = IniReadSection(@ScriptDir & "/config.ini", $File)
If Not @error Then
GUICtrlSetFont($Edit, IniRead(@ScriptDir & "/config.ini", $File, "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", $File, "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", $File, "attributes", "0"), IniRead(@ScriptDir & "/config.ini", $File, "fontname", "Arial"))
GUICtrlSetColor($Edit, IniRead(@ScriptDir & "/config.ini", $File, "fontcolor", "0x000000"))
GUICtrlSetBkColor($Edit, IniRead(@ScriptDir & "/config.ini", $File, "bgcolor", "0xFFFFFF"))
GUICtrlSetState($EraseCustomOpt, $GUI_ENABLE)
EndIf
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File)
If StringInStr(FileGetAttrib($File), "R") Then
GUICtrlSetStyle($Edit, BitOR($GUI_SS_DEFAULT_EDIT, $ES_READONLY))
MsgBox(48, "Text Editor", "This File is set to Readonly and cannot be edited.")
EndIf
EndIf
Else
$Confirm = MsgBox(36, "Confirm", "Do You Want To Save Before Opening a New File?")
If $Confirm = 6 Then
If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
_GUICtrlStatusBar_SetText($StatusBar, "Saving...")
Sleep(1000)
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
$File = FileOpenDialog("Choose a Readable File", @ScriptDir, "All Files (*.*)|Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)")
If Not @error Then
GUICtrlSetState($SetFileAttr, $GUI_ENABLE)
GUICtrlSetState($CustomFont, $GUI_ENABLE)
GUICtrlSetState($CustomBGColor, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $File)
GUICtrlSetData($Edit, FileRead($File))
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File)
EndIf
Else
$SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir)
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite($SaveDir, GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
_GUICtrlStatusBar_SetText($StatusBar, "Saving...")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File)
EndIf
EndIf
Else
$File = FileOpenDialog("Choose a Readable File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
GUICtrlSetState($SetFileAttr, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $File)
GUICtrlSetData($Edit, FileRead($File))
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & $File)
EndIf
EndIf
EndIf
EndIf
EndFunc ;==>_Open

Func _New()
Global $Edit, $StatusBar
If WinActive($GUI_TITLE) Then
If GUICtrlRead($Edit) = FileRead(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
GUICtrlSetData($Edit, "")
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"))
GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000"))
GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF"))
_GUICtrlStatusBar_SetText($StatusBar, "New Document")
Else
$Confirm = MsgBox(36, "Confirm", "Do You Want To Save Before Starting a New File?")
If $Confirm = 6 Then
If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
_GUICtrlStatusBar_SetText($StatusBar, "Saving...")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
GUICtrlSetData($Edit, "")
GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"))
GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000"))
GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF"))
EndIf
$SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir)
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite($SaveDir, GUICtrlRead($Edit))
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
_GUICtrlStatusBar_SetText($StatusBar, "Saving...")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
GUICtrlSetData($Edit, "")
GUICtrlSetFont(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontsize", "10"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontweight", "400"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "attributes", "0"), IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontname", "Arial"))
GUICtrlSetColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "fontcolor", "0x000000"))
GUICtrlSetBkColor(-1, IniRead(@ScriptDir & "/config.ini", "CONFIG", "bgcolor", "0xFFFFFF"))
_GUICtrlStatusBar_SetText($StatusBar, "New Document")
EndIf
Else
GUICtrlSetData($Edit, "")
IniDelete(@ScriptDir & "/config.ini", "CONFIG", "file")
_GUICtrlStatusBar_SetText($StatusBar, "New Document")
EndIf
EndIf
EndIf
EndFunc ;==>_New

Func _Save()
Global $StatusBar, $SetFileAttr, $CustomBGColor, $CustomFont
If WinActive($GUI_TITLE) Then
If FileExists(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound")) Then
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!"))
Else
$SaveDir = FileSaveDialog("Save File", @ScriptDir, "Text Files (*.txt)|Config Files (*.ini)|HTML Files (*.html)|XML Files (*.xml)|Batch Files (*.bat)|All Files (*.*)")
If Not @error Then
GUICtrlSetState($SetFileAttr, $GUI_ENABLE)
GUICtrlSetState($CustomFont, $GUI_ENABLE)
GUICtrlSetState($CustomBGColor, $GUI_ENABLE)
IniWrite(@ScriptDir & "/config.ini", "CONFIG", "file", $SaveDir)
FileDelete(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"))
FileWrite(IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "NotFound"), GUICtrlRead($Edit))
_GUICtrlStatusBar_SetText($StatusBar, "Saving...")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "File Saved!")
Sleep(500)
_GUICtrlStatusBar_SetText($StatusBar, "Current File: " & IniRead(@ScriptDir & "/config.ini", "CONFIG", "file", "Error!"))
EndIf
EndIf
EndIf
EndFunc ;==>_Save

Func _SelectAll()
Global $Edit
If WinActive($GUI_TITLE) Then
_GUICtrlEdit_SetSel($Edit, 0, _GUICtrlEdit_GetTextLen($Edit))
EndIf
EndFunc ;==>_SelectAll

Func _Undo()
Global $Edit
If WinActive($GUI_TITLE) Then
_GUICtrlEdit_Undo($Edit)
EndIf
EndFunc ;==>_Undo

Func _Find()
Global $Edit
If WinActive($GUI_TITLE) Then
_GUICtrlEdit_Find($Edit)
EndIf
EndFunc ;==>_Find

Func _TimeAndDate()
Global $Edit
If WinActive($GUI_TITLE) Then
If @WDAY = 1 Then $Day = "Sunday"
If @WDAY = 2 Then $Day = "Monday"
If @WDAY = 3 Then $Day = "Tuesday"
If @WDAY = 4 Then $Day = "Wednesday"
If @WDAY = 5 Then $Day = "Thursday"
If @WDAY = 6 Then $Day = "Friday"
If @WDAY = 7 Then $Day = "Saturday"
If @HOUR < 12 Then $i = "AM"
If @HOUR > 12 Then $i = "PM"
GUICtrlSetData($Edit, GUICtrlRead($Edit) & $Day & " - " & @MON & "/" & @MDAY & "/" & @YEAR & " - " & @HOUR & ":" & @MIN & " " & $i)
EndIf
EndFunc ;==>_TimeAndDate


Func SetFileAttr()
GUICreate("Set File Attributes", 200, 140)
Local $Attr = FileGetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"))
Local $Readonly = GUICtrlCreateCheckbox("Readonly", 20, 20)
If StringInStr($Attr, "R") Then GUICtrlSetState(-1, $GUI_CHECKED)
Local $Archive = GUICtrlCreateCheckbox("Archive", 100, 20)
If StringInStr($Attr, "A") Then GUICtrlSetState(-1, $GUI_CHECKED)
Local $Hidden = GUICtrlCreateCheckbox("Hidden", 20, 40)
If StringInStr($Attr, "H") Then GUICtrlSetState(-1, $GUI_CHECKED)
Local $Compress = GUICtrlCreateCheckbox("Compress", 100, 40)
If StringInStr($Attr, "C") Then GUICtrlSetState(-1, $GUI_CHECKED)
Local $Apply = GUICtrlCreateButton("Apply", 40, 80, 50, 30)
Local $Cancel = GUICtrlCreateButton("Cancel", 100, 80, 50, 30)

GUISetState()

While 1
$iMsg = GUIGetMsg()
Switch $iMsg
Case -3
GUIDelete()
ExitLoop
Case $Apply
;Readonly ==================================================================
If BitOR(GUICtrlRead($Readonly), $GUI_CHECKED) = $GUI_CHECKED Then
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+R")
Else
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-R")
EndIf
;Archive ====================================================================
If BitOR(GUICtrlRead($Archive), $GUI_CHECKED) = $GUI_CHECKED Then
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+A")
Else
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-A")
EndIf
;Hidden =====================================================================
If BitOR(GUICtrlRead($Hidden), $GUI_CHECKED) = $GUI_CHECKED Then
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+H")
Else
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-H")
EndIf
;Compress =================================================================
If BitOR(GUICtrlRead($Compress), $GUI_CHECKED) = $GUI_CHECKED Then
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "+C")
Else
FileSetAttrib(IniRead("config.ini", "CONFIG", "file", "Error!"), "-C")
EndIf
MsgBox(64, "Ok", "File Attributes Set and Saved.")
GUIDelete()
ExitLoop
Case $Cancel
GUIDelete()
ExitLoop
EndSwitch
WEnd
EndFunc ;==>SetFileAttr


Func SpeakSelectedText($iRate, $iVolume)
Global $Voice
Send("^C")
Local $iText = ClipGet()
$Voice.Rate = $iRate
$Voice.Volume = $iVolume
$Voice.Speak($iText)
Local $iText = ClipPut("")
EndFunc ;==>SpeakSelectedText


Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
Global $StatusBar
_GUICtrlStatusBar_Resize($StatusBar)
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_SIZE

Heres an Archive with the Updated Script (Also Compiled Version) and the Icon.

Text Editor.rar

Edited by ReaperX

Formerly ReaperX

Link to comment
Share on other sites

Seems pretty cool however when i tried out the speak selected text function it started reading out the entire code of the program lol?

Edit: I can't seem to make this error reoccure however.

Edited by Venix
Link to comment
Share on other sites

Wait... ill Check into that xD

Edit: You Copied the Code from above and pasted into the Editor Right? Well It Speaks the Text from the Clip Board so just Highlight the text you want it to Speak and it Copies it to the Clipboard for you. Its Not a Bug but i should probably make that better.

Just Highlight the Text you want to Speak and Go to EDIT > SPEAK HIGHLIGHTED TEXT

Edited by ReaperX

Formerly ReaperX

Link to comment
Share on other sites

  • 2 weeks later...

Hi ReaperX,

I just ran your program and it does work quite nicely. The speak function works well.

One thing I did notice was when I opened a notepad document with your program is that

your program did not have word wrap and files that have been made with word wrap are

one long line.

You have made a very good start.

REB

MEASURE TWICE - CUT ONCE

Link to comment
Share on other sites

  • 2 weeks later...

Hi ReaperX,

I just ran your program and it does work quite nicely. The speak function works well.

One thing I did notice was when I opened a notepad document with your program is that

your program did not have word wrap and files that have been made with word wrap are

one long line.

You have made a very good start.

REB

Ill Work on adding an Option for word wrap Edited by ReaperX

Formerly ReaperX

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...