Code: Select all
#SingleInstance Force
;#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%
;#Include C:\Users\benri\OneDrive\Desktop\My Files\Apps and Programs\Windows Programs\Helpers\Gdip_All.exe ; Include graphics handeler.
Menu Tray, Icon, Logo.ico ; Set icon on taskbar.
; Create the sub-menus for the menu bar:
Menu, FileMenu, Add, &New, FileNew
Menu, FileMenu, Icon, &New, %A_ScriptDir%\Icons\1New.png, 1
Menu, FileMenu, Add, &Open, FileOpen
Menu, FileMenu, Icon, &Open, %A_ScriptDir%\Icons\2Open.png, 1
Menu, FileMenu, Add, &Save, FileSave
Menu, FileMenu, Icon, &Save, %A_ScriptDir%\Icons\3Save.png, 1
Menu, FileMenu, Add, Save &As, FileSaveAs
Menu, FileMenu, Icon, Save &As, %A_ScriptDir%\Icons\4SaveAs.png, 1
Menu, FileMenu, Add, Print, FilePrint
Menu, FileMenu, Add, Close File, FileClose
Menu, FileMenu, Icon, Close File, %A_ScriptDir%\Icons\5CloseFile.png, 1
Menu, FileMenu, Add ; Separator line.
Menu, FileMenu, Add, E&xit, FileExit
Menu, FileMenu, Icon, E&xit, %A_ScriptDir%\Icons\6ExitApp.png, 1
Menu, ActionMenu, Add, &Undo, ActionUndo
Menu, ActionMenu, Add, &Redo, ActionRedo
Menu, ActionMenu, Add, &Copy all Text, ActionCopyAll
Menu, HelpMenu, Add, &About, HelpAbout
Menu, HelpMenu, Icon, &About, %A_ScriptDir%\Icons\8About.png, 1
Menu, HelpMenu, Add ; Separator line.
Menu, HelpMenu, Add, Send Feedback, HelpFeed
Menu, HelpMenu, Icon, Send Feedback, %A_ScriptDir%\Icons\9MessageSendFeedBack.png, 1
; Create the menu bar by attaching the sub-menus to it:
Menu, MyMenuBar, Add, &File, :FileMenu
Menu, MyMenuBar, Add, &Action, :ActionMenu
Menu, MyMenuBar, Add, &Help, :HelpMenu
; Attach the menu bar to the window:
Gui, Main:Menu, MyMenuBar
; Create the main Edit control and display the window:
Gui, Main:+Resize ; Make the window resizable.
; Add the toolbar:
Gui, Main:Add, Picture, w50 h-1 gToolNew, %A_ScriptDir%\Icons\Toolbar\1New.png
Gui, Main:Add, Picture, w50 h-1 gToolSave, %A_ScriptDir%\Icons\Toolbar\2Open.png
Gui, Main:Add, Picture, w50 h-1 gToolCloseFile, %A_ScriptDir%\Icons\Toolbar\3CloseFile.png
Gui, Main:Add, Picture, w50 h-1 gToolUndo, %A_ScriptDir%\Icons\Toolbar\4Undo.png
Gui, Main:Add, Picture, w50 h-1 gToolRedo ym, %A_ScriptDir%\Icons\Toolbar\5Redo.png
Gui, Main:Add, Edit, vMainEdit WantTab W1000 R50 +Multi
Gui, Main:Show,, Untitled File - TexType
CurrentFileName := "" ; Indicate that there is no current file.
return
ToolNew:
gosub FileNew
return
ToolSave:
gosub FileSave
return
ToolCloseFile:
gosub FileClose
return
ToolUndo:
Send, ^z
return
ToolRedo:
Send, ^+z
return
FileNew:
GuiControl,, MainEdit ; Clear the Edit control.
return
FileOpen:
Gui, Main:+OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open File, Open a Text Document (*.txt)
if not SelectedFileName ; No file selected.
MsgBox, 36, TexType Question, No file selected! Try again?
IfMsgBox Yes
Gosub FileOpen
IfMsgBox No
return
Gosub FileRead
return
FileRead: ; Caller has set the variable SelectedFileName for us.
FileRead, MainEdit, %SelectedFileName% ; Read the file's contents into the variable.
if ErrorLevel
{
MsgBox, 0x34, TexType ERROR!, Could not open "%SelectedFileName%".
return
}
GuiControl, Main:, MainEdit, %MainEdit% ; Put the text into the control.
CurrentFileName := SelectedFileName
Gui, Main:Show,, %CurrentFileName% - TexType ; Show file name in title bar.
return
FileSave:
if not CurrentFileName ; No filename selected yet, so do Save-As instead.
Goto FileSaveAs
Gosub SaveCurrentFile
return
FileSaveAs:
Gui, Main:+OwnDialogs ; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, S16,, Save File, Save Your Text Document (*.txt)
if not SelectedFileName ; No file selected.
return
CurrentFileName := SelectedFileName
Gosub SaveCurrentFile
return
SaveCurrentFile: ; Caller has ensured that CurrentFileName is not blank.
if FileExist(CurrentFileName)
{
FileDelete %CurrentFileName%
if ErrorLevel
{
MsgBox, 0x34, TexType ERROR, The attempt to save and overwrite "%CurrentFileName%" failed.
return
}
}
GuiControlGet, MainEdit ; Retrieve the contents of the Edit control.
FileAppend, %MainEdit%, %CurrentFileName% ; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):
Gui, Main:Show,, %CurrentFileName% - TexType
return
FilePrint:
gosub FileSave
Run, print %CurrentFileName%
return
FileClose:
MsgBox, 36, TexType Question, Close file?
IfMsgBox Yes
MsgBox, 36, TexType Question, Save file first?
IfMsgBox Yes
gosub FileSave
GuiControl, Main:, MainEdit ; Clear the Edit control.
IfMsgBox No
GuiControl, Main:, MainEdit ; Clear the Edit control.
IfMsgBox No
return
return
ActionUndo:
Send, ^z
return
ActionRedo:
Send, ^+z
return
ActionCopyAll:
MsgBox, Copied!
return
HelpAbout:
Gui, About:+Toolwindow
Gui, About:Add, Picture, w150 h-1 gMainLogo, C:\Users\benri\OneDrive\Desktop\My Files\Logos, Loaders, Icons, and Home Screens\Logos\Formal Software\Logo.jpeg
Gui, About:Add, Text,, TEXTYPE infomation:
Gui, About:Add, Text,, TexType is a simple text editor used for editing TXT files.
Gui, About:Add, Text,, Do not reproduce this work without permission from Formal Software. © Formal Software 2022.
Gui, About:Add, Picture, w200 h-1 ym gTexLogo, %A_ScriptDir%\Logo.png
Gui, About:Show,, About TexType, NoHide
return
TexLogo:
Gui, TexLogoGUI:+AlwaysOnTop -Caption +Toolwindow
Gui, TexLogoGUI:Add, Text,, Opening...
Gui, TexLogoGUI:Show
Sleep, 1000
Gui, TexLogoGUI:Destroy
Run, www.forsoft.wixsite.com/formalsoftware/projects/textype-text-editor
return
MainLogo:
Gui, MainLogoGUI:+AlwaysOnTop -Caption +Toolwindow
Gui, MainLogoGUI:Add, Text,, Opening...
Gui, MainLogoGUI:Show
Sleep, 1000
Gui, MainLogoGUI:Destroy
Run, www.forsoft.wixsite.com/formalsoftware
return
HelpFeed:
Gui, FeedGUI:+AlwaysOnTop -Caption +Toolwindow
Gui, FeedGUI:Add, Text,, Opening...
Gui, FeedGUI:Show
Sleep, 1000
Gui, FeedGUI:Destroy
Run, www.forsoft.wixsite.com/formalsoftware/give-feedback-from-sofware-texteditor-textype-feedbackform
return
AboutGuiClose:
Gui, About:Destroy ; Destroy the about box.
return
GuiDropFiles: ; Support drag & drop.
Loop, Parse, A_GuiEvent, `n
{
SelectedFileName := A_LoopField ; Get the first file only (in case there's more than one).
break
}
Gosub FileRead
return
GuiMainSize:
if (ErrorLevel = 1) ; The window has been minimized. No action needed.
return
; Otherwise, the window has been resized or maximized. Resize the Edit control to match.
NewWidth := A_GuiWidth - 20
NewHeight := A_GuiHeight - 20
GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return
FileExit: ; User chose "Exit" from the File menu.
MsgBox, 36, TexType Question, Save current file before closing?
IfMsgBox Yes
gosub FileSave
Gui, Main:Destroy ; Destroy the main window.
ExitApp
IfMsgBox No
Gui, Main:Destroy ; Destroy the main window.
ExitApp
GuiClose: ; User closed the window.
MsgBox, 36, TexType Question, Save current file before closing?
IfMsgBox Yes
gosub FileSave
Gui, Main:Destroy ; Destroy the main window.
ExitApp
IfMsgBox No
Gui, Main:Destroy ; Destroy the main window.
ExitApp
GuiEscape:
MsgBox, 36, TexType Question, Close program?
IfMsgBox Yes
ExitApp
IfMsgBox No
return
ExitApp