Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #NoEnv
- #SingleInstance Force
- SendMode Input
- SetWorkingDir %A_ScriptDir%
- ;ini file generation / read section for options.
- Start:
- If !FileExist(A_APPDATA "\AutoTyper")
- {
- FileCreateDir, %A_APPDATA%\AutoTyper
- If ErrorLevel
- {
- Msgbox, Something went wrong with creating the folder %A_APPDATA%\AutoTyper`n`nAutoTyper will use defaults instead. Configuration not available.
- }
- }
- If !FileExist(A_APPDATA "\AutoTyper\Settings.ini")
- {
- IniWrite, 15, %A_APPDATA%\AutoTyper\Settings.ini, General, MaxNumRows
- If ErrorLevel
- {
- Msgbox, Something went wrong with creating or writing the settings.ini file in %A_APPDATA%\AutoTyper`n`nAutoTyper will use defaults instead. Configuration not available.
- }
- MaxNumRows = 15
- IniWrite, ^1, %A_APPDATA%\AutoTyper\Settings.ini, General, Hotkey
- If ErrorLevel
- {
- Msgbox, Something went wrong with creating or writing the settings.ini file in %A_APPDATA%\AutoTyper`n`nAutoTyper will use defaults instead. Configuration not available.
- }
- GuiHotkey = ^1
- } else {
- IniRead, MaxNumRows, %A_APPDATA%\AutoTyper\Settings.ini, General, MaxNumRows, 15
- IniRead, GuiHotkey, %A_APPDATA%\AutoTyper\Settings.ini, General, Hotkey, ^1
- }
- Hotkey, %GuiHotkey%, Begin
- return
- ;config section
- CONFIG:
- Hotkey, %GuiHotkey%, Begin, Off
- gui, destroy
- gui, font, bold
- gui, add, text,, Config Section:
- gui, font
- gui, add, text,, Hotkey for gui (default CTRL-1):
- gui, add, hotkey, vGuiHotkey, %GuiHotkey%
- gui, add, text,, Max number of rows per column`n(default 15)
- gui, add, edit, vMaxNumRows, %MaxNumRows%
- gui, add, button, gConfigOK section, OK
- gui, add, button, gConfigReset ys, RESET
- gui, show
- return
- CONFIGOK:
- gui, submit
- gui, destroy
- IniWrite, %GuiHotkey%, %A_APPDATA%\AutoTyper\Settings.ini, General, Hotkey
- IniWrite, %MaxNumRows%, %A_APPDATA%\AutoTyper\Settings.ini, General, MaxNumRows
- reload
- ExitApp
- CONFIGRESET:
- FileRemoveDir, %A_APPDATA%\AutoTyper, 1
- reload
- ExitApp
- ;Hotkey element
- Begin:
- Hotkey, %GuiHotkey%, Begin, Off
- ;capture old clipboard to attempt to put it back
- OldClipboard := clipboard
- WinGetActiveTitle, WinTitle
- ;init arrays
- FileArray:= []
- FileNameArray:= []
- FolderArray := []
- ;define standard gui top section
- Gui,+AlwaysOnTop
- gui, add, text, x1 y1 section, Pasting into %WinTitle%
- gui, add, text,, Press OK or Enter after choosing a selection below
- gui, add, button, gOK default ys, OK - PASTE
- gui, add, button, gCONFIG y+1, CONFIG
- ;enumerate .txt files in Script Directory
- Loop, Files, %A_ScriptDir%\*.txt, R
- {
- FileNameArray.Push(A_LoopFileLongPath)
- StringReplace, FileName, A_LoopFileName, .txt
- FileArray.Push(FileName)
- StringReplace, FolderName, A_LoopFileDir, %A_ScriptDir%\
- FolderArray.Push(FolderName)
- }
- ;begin pushing files into dynamic gui
- CurFolder =
- NumFilesCol = 0
- If (!FileArray.MaxIndex()) ;handle zero files
- {
- gui, font, bold
- gui, add, text, x2 y55 section, No .txt Files in script Folder!
- gui, font
- }
- For index, file in FileArray
- {
- NumFilesCol += 1
- Filenum := A_Index
- ;if the folder of the next file has changed, create a new bold category.
- If (FolderArray[A_Index] <> CurFolder)
- {
- CurFolder := FolderArray[A_Index]
- FolderCount = 0
- For Indexb, folder in FolderArray
- ;count number of files in the folder, according to array
- {
- If (CurFolder = folder)
- {
- FolderCount += 1
- }
- }
- If (NumFilesCol + FolderCount > MaxNumRows) or (NumFilesCol > MaxNumRows)
- {
- ;if this file is of a new folder, and there's too many files in it to fit in
- ;NumFilesCol (default 15), create a new column (ys)
- gui, font, bold
- gui, add, text, ys, %CurFolder%
- NumFilesCol = 0
- gui, font
- } else if (Filenum = 1) {
- ;if it is the first option, create a new section of gui
- If (CurFolder = A_ScriptDir) ;handle no folders
- {
- gui, font, bold
- gui, add, text, x2 y55 section, Files
- gui, font
- }
- else
- {
- gui, font, bold
- gui, add, text, x2 y55 section, %CurFolder%
- gui, font
- }
- } else {
- ;if this file is of a new folder but doesn't exceed NumFilesCol (def 15)
- ;don't create a new column.
- gui, font, bold
- gui, add, text,, %CurFolder%
- gui, font
- }
- }
- If NumFilesCol > MaxNumRows
- ;if for some reason the file is exceeding NumFilesCol, put it on a new column
- {
- gui, add, checkbox, ys vV%index%, %file%
- } else {
- gui, add, checkbox, vV%index%, %file%
- }
- }
- ;show gui, wait for input
- gui, show
- return
- OK:
- ButtonOK:
- Gui, Submit
- Gui, Destroy
- Goto Next
- ;gui close, do not submit vars
- GuiClose:
- GuiEscape:
- clipboard := OldClipboard
- Hotkey, %GuiHotkey%, Begin, On
- Gui, Destroy
- Goto Start
- ;pasting from files, loop through the total entries in enumerated files
- ;if variable V# is 1, read from file related to that index # num and paste with simple ctrl-v
- Next:
- clipboard =
- Loop, % FileArray.MaxIndex()
- {
- If V%a_index% = 1
- {
- FileRead, FileContent, % FileNameArray[A_Index]
- clipboard := FileContent
- ClipWait, 2
- If ErrorLevel
- {
- MsgBox, The attempt to copy text onto the clipboard failed.
- clipboard := OldClipboard
- return
- }
- break
- }
- }
- WinActivate, %WinTitle%
- WinWaitActive, %WinTitle%
- Send ^v
- ;sleep because the clipboard action below can actually run before the ^v input is fully sent due to keydelay!
- sleep 1
- ;clean up variables to allow changes and prevent accidental transferral of variable contents between
- ;pasting uses.
- For index, file in FileArray
- {
- V%index% = 0
- }
- clipboard := OldClipboard
- Hotkey, %GuiHotkey%, Begin, On
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement