- Fixed some errors
- Added a new tool: Expressive, a regular expression utility
- Redesigned Window Cloning Tool
Edit: reuploaded screenshot.
oldbrother wrote:Windows XP SP3.
awwwwyeaaahhh hahahafischgeek wrote:oldbrother wrote:Windows XP SP3.
I think it should be R1(Gui, Add, Edit, w%DefaultWidth% r1) and let Windows(or AutoHotkey) calculate it internally. Using a fix height is not advisable especially if the user is using a custom Windows theme.PumpkinShortie wrote:The default height for edit boxes and hotkey boxes should be 21 pixels.
The Edit menu is for the script editor only.Undo and Redo in the Edit menu do not work for me.
While this issue is not fixed, individually select each control with Ctrl + click.It is impossible to drag the mouse to select controls inside a group box.
Code: Select all
ParseScript(Source) {
m.Source := ""
;Added to disable these vars unless in the script beibg loaded -RH
Script.NoEnv := 0
Script.Warn := ""
Script.SingleInstance := ""
Script.WorkingDir := ""
Script.SendMode := ""
hAnchor := {}
Loop Parse, Source, `n
{
CtlLoad := A_LoopField
IfInString A_LoopField, %Delimiter% ;Detects when delimiter is reached - RH
GuiLoaded = 1
IfInString A_LoopField, hwnd ;Removes hwnd varible from string used to get control options, otherwise controls are not registered correctly -RH
{
CtlLoad := ""
Loop Parse, A_LoopField, %A_Space%
IfNotInString A_LoopField, hWnd
CtlLoad .= " " . A_LoopField
}
IfInString A_LoopField, Gui Add`, Tab2`, ;Sets the Tabindex and Tabcontrol numbers for the current controls -RH
fTabControl++
If (RegExMatch(A_LoopField, "iO)^\s*?Gui\s*\,?\s*(\w+\:)?\s?Tab,\s?(?P<TabIndex>([\w\+\-\s]+))", Rex))
fTabIndex := RegExReplace(Rex.TabIndex, "[\r\n]*")
If !Guiloaded
{
; Get Window Events in script to set proper checkboxes -RH
IfInString A_LoopField, Close:
g.Window.GuiClose := 1
IfInString A_LoopField, Escape:
g.Window.GuiEscape := 1
IfInString A_LoopField, Size:
g.Window.GuiSize := 1
IfInString A_LoopField, ContextMenu:
g.Window.GuiContextMenu := 1
IfInString A_LoopField, DropFiles:
g.Window.GuiDropFiles := 1
IfInString A_LoopField, OnClipboardChange:
g.Window.OnClipboardChange := 1
;Get Script Options to set correct Checkboxes and set correct item in dropdown choices -RH
IfInString A_LoopField, #NoEnv
Script.NoEnv := 1
IfInString A_LoopField, #Warn
If (SubStr(A_LoopField,9) = "")
Script.Warn := "MsgBox"
Else
Script.Warn := RegExReplace(SubStr(A_LoopField,9), "[\r\n]*")
IfInString A_LoopField, #SingleInstance
Script.SingleInstance := SubStr(A_LoopField,17)
IfInString A_LoopField, #NoTrayIcon
Script.NoTrayIcon := 1
IfInString A_LoopField, SetWorkingDir
{
Script.WorkingDir := SubStr(A_LoopField,15)
SetWorkingDir % RegExReplace(SubStr(A_LoopField,15), "[\r\n]*")
}
IfInString A_LoopField, SendMode
Script.SendMode := RegExReplace(SubStr(A_LoopField,10), "[\r\n]*")
IfInString A_LoopField, SetBatchLines
Script.NoBatchLines := 1
IfInString A_LoopField, ListLines
Script.ListLinesOff := 1
IfInString A_LoopField, #Persistent
Script.Persistent := 1
IfInString A_LoopField, Menu Tray`, UseErrorLevel
Script.IgnoreMenuErrors := 1
;Get Font Info, for some reason needs to be applied 2 lines after it appears in script to be be applied to the correct control - RH
If (fft = A_Index-2)
{
g[hwnd].fontoptions := flfont
fft = 0
}
IfInString A_LoopField, Font`,
{
flFont := Substr(A_Loopfield,11)
fft := A_Index
}
}
; Menu item
If (RegExMatch(A_LoopField, "iO)^Menu\s*\,?\s*(?P<MenuName>([\w]+)),\s?Add(,\s?(?P<MenuItem>.*),\s?(?P<GoSub>([\w\:]+)))?", Rex)) {
m.Source .= "Menu " . Rex.MenuName . ", Add, " . Rex.MenuItem . ", " . Rex.GoSub . "`n"
Menu % Rex.MenuName, Add, % Rex.MenuItem, % Rex.GoSub
} Else If (RegExMatch(A_LoopField, "iO)^Menu\s*\,?\s*(?P<MenuName>([\w]+)),\s?Add", Rex)) {
m.Source .= "Menu " . Rex.MenuName . ", Add`n"
Menu % Rex.MenuName, Add
}
;Added to Load Window options - RH
If (RegExMatch(A_LoopField, "iO)^\s*?Gui\s*\,?\s*(\w+\:)?\s?New,\s?(?P<Options>([\w\+\-\s]+))", Rex)) {
g.Window.Options := RegExReplace(Rex.Options, "([\,\s]?g\w+|[\,\s]?v\w+)")
g.Window.Options := StrReplace(g.window.options, "+OwnDialo", "+OwnDialogs")
IfInString A_LoopField, : New
g.Window.Name := SubStr(A_LoopField, 5,InStr(A_LoopField, ":")-5)
Loop Parse, % g.Window.Options, %A_Space%
{
IfInString A_LoopField, Label
g.Window.Label := SubStr(A_LoopField,6)
IfInString A_LoopField, hwnd
g.Window.hWndvar := SubStr(A_LoopField,5)
}
g.Window.Options := StrReplace(g.window.options, "Label"g.window.label)
g.Window.Options := StrReplace(g.window.options, "hWnd"g.window.hWndVar)
}
IfInString A_LoopField, Gui Color`, ;Loads the background Colour -RH
g.Window.Color := SubStr(A_LoopField,12)
IfInString A_LoopField, Menu Tray`, Icon ;Loads the Tray Icon - RH
Loop Parse, A_LoopField, `,
{
If A_Index = 3
g.Window.Icon := SubStr(A_LoopField,2)
If A_Index = 4
g.Window.IconIndex := SubStr(A_LoopField,2)
}
; Control
If (RegExMatch(CtlLoad, "iO)^\s*?Gui\s*\,?\s*(\w+\:)?\s?Add,\s?(?P<Type>([A-Za-z]+)\d?),\s?(?P<Options>([\w\+\-\s]+))(,\s?(?P<Text>(.+)))?", Rex)) {
Options := RegExReplace(Rex.Options, "([\,\s]?g\w+|[\,\s]?v\w+)")
TabPos := [fTabIndex, fTabControl] ; Controls Tab placement of controls -RH
IfInString A_LoopField, Gui Add`, Tab2`,
TabPos := ""
If (Rex.Type = "StatusBar" && StatusBarExist()) {
GuiControl %Child%: Show, msctls_statusbar321
} Else {
If fTabIndex ; Puts the controls into the correct tab in gui window - RH
Gui %Child%: Tab, % TabPos[1], % TabPos[2]
Gui %Child%: Add, % Rex.Type, % "hWndhWnd " . Options, % Rex.Text
}
If (Rex.Type = "TreeView") {
Parent := TV_Add("TreeView")
TV_Add("Child", Parent)
}
;Added to load properties - RH
fMatch := "gvxywh0E"
Loop parse, A_LoopField, `,
If A_index = 3
strf := A_LoopField
Loop parse, strf, %A_Space% ;this loop makes sure these options arent stores as vVar or gLabel - RH
{ ;and gets the hWndVar, style, exstyle values
If Substr(A_Loopfield,1,1) = "v"
If (A_LoopField != "vscroll" OR A_LoopField != "vertical")
fvVar := Substr(A_Loopfield,2)
Else
fOptions .= A_LoopField . " "
If Substr(A_Loopfield,1,1) = "g"
If (A_LoopField != "grid")
fgLabel := Substr(A_Loopfield,2)
Else
fOptions .= A_LoopField . " "
If Substr(A_Loopfield,1,4) = "hwnd"
fhwndVar := Substr(A_Loopfield,5)
If Substr(A_Loopfield,1,1) = "0"
fStyle := A_LoopField
If Substr(A_Loopfield,1,1) = "E"
fExStyle := A_LoopField
IfNotInString fMatch, % Substr(A_Loopfield,1,1)
fOptions .= A_LoopField . " "
}
If fhWndVar ;Stores the hwndvariable and hwnd to attach an anchor later if one exists - RH
ObjRawSet(hAnchor, fhWndVar, hWnd)
GuiControlGet c, %Child%: Pos, %hWnd%
g.Register(hWnd, Rex.Type, "", Rex.Text, cx, cy, cw, ch, fhWndVar, fvVar, fgLabel, fOptions, fStyle, fExStyle, flFont, "", TabPos)
g.ControlList.Insert(hWnd)
fExStyle := "" ;Resets all the control option variables for the next control - RH
fStyle := ""
fhwndVar := ""
fvVar := ""
fgLabel := ""
fOptions := ""
strf := ""
}
IfInString A_LoopField, Anchor( ;Detects if there are anchored controls, sets the anchor flag and loads the anchor coords into the controls variables list -RH
{
StringReplace scr, A_Loopfield, `", , All ;"; extra quote in comment stops of syntax hilighting incorretly for the following lines :) - RH
(RegExMatch(scr, "iO)^\s*?Anchor\s*\(?\s*(?P<CtlhWndVar>([\w\+\-\s]+)),\s?(?P<Anchor>(.+))", Rex))
g.Anchor := True
g[hAnchor[rex.ctlhwndvar]].Anchor := SubStr(Rex.Anchor,1,-2)
}
If (RegExMatch(A_LoopField, "iO)^Gui\s?\,?\s?Show,\s?(?P<Options>([\w\s]+)),\s?(?P<Title>(.+))", Rex)) {
Gui %Child%: Show, % Rex.Options, % Rex.Title
g.Window.Title := Rex.Title
}
}
SetWorkingDir %A_ScriptDir%
If (m.Source != "") {
m.Source .= "Gui Menu, MenuBar`n"
Gui %Child%: Menu, MenuBar
}
If (g.ToolbarIcons.MaxIndex()) {
AddToolbar(g.ToolbarIL, g.ToolbarItems, g.ToolbarOptions)
}
g.UpdateSource()
Properties_Reload()
}
Code: Select all
ShowProperties:
If (!WinExist("ahk_id " . hPropWnd)) {
Gui Properties: New, LabelProperties hWndhPropWnd -MinimizeBox Owner%Child%
SetIconEx(hPropWnd, IconLib, 24)
ClassNNList := ""
For Each, Item In g.ControlList {
ClassNNList .= g[Item].ClassNN . "|"
}
Gui Add, Picture, gBlinkControlBorder x12 y13 w16 h16 Icon5, % IconLib
Gui Add, DropDownList, hWndhCbxClassNN vCbxClassNN gOnDropDownChange x40 y12 w203, % "Window||" . ClassNNList
Gui Add, Button, hWndhReloadBtn gReloadSub x248 y11 w23 h23
GuiButtonIcon(hReloadBtn, IconLib, 90, "L1 T1")
Try {
Gui Add, % "Tab3", hWndhPropTab vCurrentTab x6 y41 w270 h303 AltSubmit, General|Options|Window|Events|Script
} Catch {
Gui Add, Tab2, hWndhPropTab vCurrentTab x6 y41 w270 h303 AltSubmit, General|Options|Window|Events|Script
}
Control Style, 0x54010040,, ahk_id %hPropTab%
Gui Tab, 1 ; General
Gui Add, GroupBox, vGrpText x16 y65 w250 h48, Text
Gui Add, Edit, vEdtText x26 y83 w230 h21
Gui Add, GroupBox, x16 y116 w250 h99, Variables
Gui Add, Text, x26 y132 w60 h21 +0x200, hWnd var:
Gui Add, Edit, vEdtHWndVar x95 y132 w160 h21
Gui Add, Text, vTxtVVar x26 y158 w60 h21 +0x200, v-Var:
Gui Add, Edit, vEdtvVar x95 y158 w160 h21
Gui Add, Text, vTxtGLabel x26 y184 w60 h21 +0x200, g-Label:
Gui Add, Edit, vEdtgLabel x95 y184 w160 h21
Gui Add, GroupBox, x16 y217 w250 h74, Position
Gui Add, Text, x57 y232 w16 h22 +0x200, &X:
Gui Add, Edit, vEdtX x75 y232 w50 h21
Gui Add, UpDown, gAdjustPosition Range-65536-65536, 1
Gui Add, Text, x157 y232 w16 h22 +0x200, &Y:
Gui Add, Edit, vEdtY x175 y232 w50 h21
Gui Add, UpDown, gAdjustPosition Range-65536-65536, 1
Gui Add, Text, x57 y260 w16 h22 +0x200, &W:
Gui Add, Edit, vEdtW x75 y260 w50 h21
Gui Add, UpDown, gAdjustPosition Range-65536-65536, 1
Gui Add, Text, x157 y260 w16 h22 +0x200, &H:
Gui Add, Edit, vEdtH x175 y260 w50 h21
Gui Add, UpDown, gAdjustPosition Range-65536-65536, 1
Gui Add, GroupBox, x16 y293 w250 h40, Anchor
Gui Add, CheckBox, vChkAnchorX gRequireHWndVar x75 y305 w40 h23, X
Gui Add, CheckBox, vChkAnchorY gRequireHWndVar x115 y305 w40 h23, Y
Gui Add, CheckBox, vChkAnchorW gRequireHWndVar x155 y305 w40 h23, W
Gui Add, CheckBox, vChkAnchorH gRequireHWndVar x195 y305 w40 h23, H
;Loads these variables if menu is created by Opening GUI from File Menu -RH
If GuiLoaded
{
GuiControl,, EdtText, % g.Window.Title
GuiControl,, EdthwndVar, % g.Window.hwndvar
GuiControl,, EdtgLabel, % g.Window.Label
GuiControl,, EdtvVar, % g.Window.Name
}
Gui Tab, 2 ; Options
Gui Add, GroupBox, vGrpOptions x16 y71 w250 h60, Options
Gui Add, Button, hWndhOptionsBtn x28 y92 w24 h24 gShowContextMenu, ...
GuiButtonIcon(hOptionsBtn, IconLib, 91, "L1 T1")
Gui Add, Edit, vEdtOptions x54 y94 w200 h21
Gui Add, GroupBox, x16 y144 w250 h84, Styles
Gui Add, Text, x33 y165 w60 h23 +0x200, Style:
Gui Add, Edit, hWndhEdtStyle vEdtStyle x96 y166 w82 h22
SendMessage 0x1501, True, "Default",, ahk_id %hEdtStyle%
Gui Add, Button, vBtnChangeStyle gShowStylesDialog x184 y165 w75 h23, Change...
Gui Add, Text, x33 y193 w60 h23 +0x200, Extended:
Gui Add, Edit, hWndhEdtExStyle vEdtExStyle x96 y193 w82 h22
SendMessage 0x1501, True, "Default",, ahk_id %hEdtExStyle%
Gui Add, Button, vBtnChangeExStyle gShowStylesDialog x184 y193 w75 h23, Change...
Gui Add, GroupBox, x16 y242 w250 h84, Font
Gui Add, Edit, vEdtFont x27 y264 w227 h23 Center ReadOnly, Default
Gui Add, Button, gShowFontDialog x180 y296 w75 h23, Change...
Gui Tab, 3 ; Window
Gui Add, CheckBox, vChkResizable x20 y72 w110 h23, Resizable
Gui Add, CheckBox, vChkNoMinimize x20 y97 w110 h24, No minimize button
Gui Add, CheckBox, vChkNoMaximize x20 y122 w111 h22, No maximize button
Gui Add, CheckBox, vChkNoSysMenu x20 y147 w111 h23, No system menu
Gui Add, CheckBox, vChkNoTheme x20 y172 w110 h23, No theme
Gui Add, CheckBox, vChkCenter x140 y72 w120 h23 Checked, Center on screen
Gui Add, CheckBox, vChkAlwaysOnTop x140 y97 w120 h23, Always on top
Gui Add, CheckBox, vChkOwnDialogs x140 y122 w120 h23, Own dialogs
Gui Add, CheckBox, vChkToolWindow x140 y147 w120 h23, Tool window
Gui Add, CheckBox, vChkNoDPIScale x140 y172 w120 h23, No DPI scale
Gui Add, CheckBox, vChkBGColor x20 y200 w111 h24, Background color:
Gui Add, ListView, vColorPreview x140 y201 w20 h20 -Hdr Border, Color
Color := DllCall("GetSysColor", "UInt", 15) ; COLOR_3DFACE
Color := (Color & 0xFF00) + ((Color & 0xFF0000) >> 16) + ((Color & 0xFF) << 16)
GuiControl % "+Background" . ToHex(Color), ColorPreview
Gui Add, Button, gChooseBGColor x168 y199 w90 h23, Change Color
Gui Add, CheckBox, vChkTrayIcon x20 y228 w111 h23, Window/tray icon:
Gui Add, Text, x140 y230 w20 h20 +0x1000
Gui Add, Picture, vTrayIcon gShowIconPath x142 y232 w16 h16 , % A_AhkPath
Gui Add, Button, gChooseTrayIcon x168 y228 w90 h23, Change Icon
;Added to Load Window Variables - RH
If GuiLoaded
{
If (g.Window.Color != "") {
Color := g.Window.Color
GuiControl,, ChkBGColor, 1
GuiControl % "+Background" . ToHex(Color), ColorPreview
}
If (g.Window.Icon != "") {
GuiControl,, ChkTrayIcon, 1
GuiControl,, TrayIcon, % "*Icon" . g.Window.IconIndex . " " . g.Window.Icon
}
svar := g.window.options
IfInString svar, Resize, GuiControl,, ChkResizable, 1
IfInString svar, MinimizeBox, GuiControl,, ChkNoMinimize, 1
IfInString svar, MaximizeBox, GuiControl,, ChkNoMaximize, 1
IfInString svar, SysMenu, GuiControl,, ChkNoSysMenu, 1
IfInString svar, AlwaysOnTop, GuiControl,, ChkAlwaysOnTop, 1
IfInString svar, OwnD, GuiControl,, ChkOwnDialogs, 1
IfInString svar, ToolWindow, GuiControl,, ChkToolWindow, 1
IfInString svar, Theme, GuiControl,, ChkNoTheme, 1
IfInString svar, DPIScale, GuiControl,, ChkNoDPIScale, 1
}
Gui Tab, 4 ; Events
Gui Add, GroupBox, x16 y71 w250 h100, Standard
Gui Add, CheckBox, vChkGuiClose x30 y90 w100 h23 Checked, GuiClose
Gui Add, CheckBox, vChkGuiEscape x30 y115 w100 h23 Checked, GuiEscape
Gui Add, CheckBox, vChkGuiSize x30 y140 w100 h23, GuiSize
Gui Add, CheckBox, vChkGuiContextMenu x140 y90 w100 h23, GuiContextMenu
Gui Add, CheckBox, vChkGuiDropFiles x140 y115 w100 h23, GuiDropFiles
Gui Add, CheckBox, vChkOnClipboardChange x140 y140 w120 h23, OnClipboardChange
;Added to Load Event Variables - RH
If GuiLoaded
{
If g.Window.OnClipboardChange
GuiControl,, ChkOnClipboardChange, 1
If g.Window.GuiClose
GuiControl,, ChkGuiClose, 1
If g.Window.GuiEscape
GuiControl,, ChkGuiEscape, 1
If g.Window.GuiSize
GuiControl,, ChkGuiSize, 1
If g.Window.GuiContextMenu
GuiControl,, ChkGuiContextMenu, 1
If g.Window.GuiDropFiles
GuiControl,, ChkGuiDropFiles, 1
}
Gui Tab, 5 ; Script
Gui Add, CheckBox, vChkNoEnv x20 y72 w113 h23 Checked, #NoEnv
Gui Add, CheckBox, vChkNoTrayIcon x140 y72 w113 h23, #NoTrayIcon
Gui Add, CheckBox, vChkWarn x20 y98 w113 h23 Checked, #Warn
Gui Add, DropDownList, vCbxWarn x140 y98 w120, Off|MsgBox||StdOut|OutputDebug
Gui Add, CheckBox, vChkSingleInstance x20 y126 w113 h23, #SingleInstance
Gui Add, DropDownList, vCbxSingleInstance x140 y124 w120, Force||Ignore|Off
Gui Add, CheckBox, vChkSetWorkingDir x20 y153 w113 h23 Checked, SetWorkingDir
Gui Add, Edit, vEdtSetWorkingDir x140 y153 w121 h21, `%A_ScriptDir`%
Gui Add, CheckBox, vChkSendMode x20 y179 w113 h23, SendMode
Gui Add, DropDownList, vCbxSendMode x140 y180 w120, Input||Play|Event|InputThenPlay
Gui Add, CheckBox, vChkSetBatchLines x20 y207 w113 h23, SetBatchLines -1
Gui Add, CheckBox, vChkPersistent x20 y233 w113 h23, #Persistent
Gui Add, CheckBox, vChkListLines x140 y207 w113 h23, ListLines Off
Gui Add, CheckBox, vChkIgnoreMenuErrors x140 y233 w113 h23, Ignore Menu Errors
;Added to Load Script Variables - RH
If GuiLoaded
{
If (Script.NoEnv != 0)
GuiControl,, ChkNoEnv, 1
Else
GuiControl,, ChkNoEnv, 0
If (Script.NoTrayIcon != 0)
GuiControl,, ChkNoTrayIcon, 1
If (Script.Warn != "") {
GuiControl,, ChkWarn, 1
GuiControl ChooseString, CbxWarn, % Script.Warn
}
Else
GuiControl,, ChkWarn, 0
If (Script.SingleInstance != "") {
GuiControl,, ChkSingleInstance, 1
GuiControl ChooseString, CbxSingleInstance, % Script.SingleInstance
}
Else
GuiControl,, ChkSingleInstance, 0
If (Script.WorkingDir != "") {
GuiControl,, ChkSetWorkingDir, 1
GuiControl,, EdtSetWorkingDir, % Script.WorkingDir
}
Else
GuiControl,, ChkSetWorkingDir, 0
If (Script.SendMode != "") {
GuiControl,, ChkSendMode, 1
GuiControl ChooseString, CbxSendMode, % Script.SendMode
}
Else
GuiControl,, ChkSendMode, 0
If (Script.NoBatchLines != 0)
GuiControl,, ChkSetBatchLines, 1
If (Script.Persistent != 0)
GuiControl,, ChkPersistent, 1
If (Script.ListLinesOff != 0)
GuiControl,, ChkListLines, 1
If (Script.IgnoreMenuErrors != 0)
GuiControl,, ChkIgnoreMenuErrors, 1
}
Gui Tab
GuiLoaded := 0 ;Resets to option to defaults for the next file thats opened - RH
Gui Add, Button, hWndhHelpBtn x8 y350 w24 h23 gMenuHandler
GuiButtonIcon(hHelpBtn, "shell32.dll", 24, "L1 T1")
Gui Add, Button, gReset x38 y350 w75 h23, Reset
Gui Add, Button, gPropertiesClose x118 y350 w75 h23, Close
Gui Add, Button, gApplyProperties x198 y350 w75 h23 Default, Apply
WinGetPos ax, ay, aw,, ahk_id %hAutoWnd%
IniRead px, %IniFile%, Properties, x, % (ax + aw - 281 - 40)
IniRead py, %IniFile%, Properties, y, % ay + 40
Gui Properties: Show, % "x" . px . " y" . py . " w281 h382", Properties
} Else {
NA := (A_ThisFunc != "" && A_ThisFunc != "OnToolbar") ? "NA" : ""
Gui Properties: Show, % NA
}
ClassNN := g[g_Control].ClassNN
If (ClassNN = "") {
ClassNN := "Window"
}
GuiControl Properties: ChooseString, CbxClassNN, % ClassNN
Gosub OnDropDownChange
Return
Code: Select all
; Expressive - Regular Expressions Utility (v1.1)
If (A_PtrSize = 8 || !A_IsUnicode) {
SplitPath A_AhkPath,, AhkDir
U32 := AhkDir . "\AutoHotkeyU32.exe"
If (FileExist(U32)) {
Run % U32 . " " . Chr(34) . A_LineFile . Chr(34)
ExitApp
} Else {
MsgBox 0x2010, AutoGUI, AutoHotkey 32-bit Unicode not found.
ExitApp
}
}
#NoEnv
#Warn All, Off
#SingleInstance Off
#NoTrayIcon
SetWorkingDir %A_ScriptDir%
SetControlDelay -1
SetBatchLines -1
#Include %A_ScriptDir%\..\Lib\Scintilla.ahk
Global SciLexer := A_ScriptDir . "\..\SciLexer.dll"
, hMatchCount
, Groups := False
, Replace := False
, IconLib := A_ScriptDir . "\..\Icons\Expressive.icl"
Menu Tray, Icon, %IconLib%, 1
Gui New, hWndhWindow -DPIScale
; Regular Expression
Gui Font, s9 Bold, Segoe UI
Gui Add, Text, hWndhRegExHdr x10 y12 w710 h29 +0x200 +E0x200, %A_Space%Regular Expression
Gui Font
Gui Add, Picture, hWndhHelpIcon gShowHelp x697 y18 w16 h16 Icon4, %IconLib%
Gui Font, s13, Lucida Console
Gui Add, Edit, vRegEx gSearch x10 y44 w710 h25 -VScroll
Gui Font
Gui Font, s8, MS Shell Dlg 2
If (A_ScreenDPI > 96) {
Gui Add, CheckBox, vIgnoreCase gSetOption x12 y72 w90 h23, Ignore case
Gui Add, CheckBox, vMultiline gSetOption x110 y72 w80 h23, Multiline
Gui Add, CheckBox, vHighlightAll gSearch x580 y72 w140 h23 Checked, Highlight all matches
} Else {
Gui Add, CheckBox, vIgnoreCase gSetOption x12 y72 w80 h23, Ignore case
Gui Add, CheckBox, vMultiline gSetOption x100 y72 w80 h23, Multiline
Gui Add, CheckBox, vHighlightAll gSearch x600 y72 w120 h23 Checked, Highlight all matches
}
; Text
Gui Font, s9 Bold, Segoe UI
Gui Add, Text, hWndhTextHdr x10 y98 w710 h29 +0x200 +E0x200, %A_Space%Text
Gui Add, Text, % "hWndhMatchCount x612 y" . (A_ScreenDPI > 96 ? 102 : 104) . " w100 h20 Right"
Gui Font
Global Sci := New Scintilla
Sci.Add(hWindow, 10, 130, 710, 232, SciLexer)
Sci.SetLexer(SCLEX_CONTAINER)
Sci.StyleClearAll()
Sci.SetWrapMode(1)
Sci.SetMarginWidthN(0, 0)
Sci.SetMarginWidthN(1, 0)
Sci.StyleSetFont(SCE_AHKL_NEUTRAL, "Lucida Console")
Sci.StyleSetSize(SCE_AHKL_NEUTRAL, 10)
Sci.SetSelFore(1, "0xFFFFFF")
Sci.SetSelBack(1, "0x3399FF")
Sci.StyleSetBack(SCE_AHKL_USERDEFINED1, 0xABDFEE)
Sci.StyleSetFont(SCE_AHKL_USERDEFINED1, "Lucida Console")
Sci.StyleSetSize(SCE_AHKL_USERDEFINED1, 10)
Sci.Notify := "OnNotify"
; Groups
Gui Font, Bold, Segoe UI
Gui Add, Text, hWndhGroupsHdr gShowGroups x10 y368 w710 h29 +0x200 +E0x200, %A_Space%Groups
Gui Font
Gui Add, Picture, hWndhGroupsChevron x697 y374 w16 h16 Icon2, %IconLib%
Global SciGroups := CreateScintilla(hWindow, 10, 282, 710, 115, SciLexer, "Hidden")
SciGroups.SetReadOnly(True)
; Replace
Gui Font, Bold, Segoe UI
Gui Add, Text, hWndhReplaceHdr gShowReplace x10 y403 w710 h29 +0x200 +E0x200, %A_Space%Replace
Gui Font
Gui Add, Picture, hWndhReplaceChevron x697 y409 w16 h16 Icon2, %IconLib%
Gui Font, s13, Lucida Console
Gui Add, Edit, hWndhReplaceField vReplacement gReplace x10 y267 w710 h25 -VScroll -0x10000000
Gui Font
Global SciReplace := CreateScintilla(hWindow, 10, 297, 710, 100, SciLexer, "Hidden")
Gui Add, Picture, hWndhCollapseChevron x-16 y0 w16 h16 Icon3, %IconLib%
ControlColor(hCollapseChevron, hWindow, 0x336699)
ControlColor(hRegExHdr, hWindow, 0x336699, 0xFFFFFF)
ControlColor(hHelpIcon, hWindow, 0x336699)
ControlColor(hTextHdr, hWindow, 0x336699, 0xFFFFFF)
ControlColor(hMatchCount, hWindow, 0x336699, 0xFFFFFF)
ControlColor(hGroupsHdr, hWindow, 0xC0C0C0, 0xFFFFFF)
ControlColor(hGroupsChevron, hWindow, 0xC0C0C0)
ControlColor(hReplaceHdr, hWindow, 0xC0C0C0, 0xFFFFFF)
ControlColor(hReplaceChevron, hWindow, 0xC0C0C0)
Gui Show, w730 h441, Expressive - Regular Expressions Utility
hSysMenu := DllCall("GetSystemMenu", "UInt", hWindow, "Int", False)
DllCall("AppendMenu", "UInt", hSysMenu, "UInt", 0x800, "UInt", 0, "Str", "")
DllCall("AppendMenu", "UInt", hSysMenu, "UInt", 1, "UInt", 0, "Str", "Version 1.1")
Return ; End of the auto-execute section
Search:
Gui Submit, NoHide
; Clear old matches
sci.StartStyling(0, 0x1F)
sci.SetStyling(Sci.GetLength() + 1, STYLE_DEFAULT)
If (RegExMatch(RegEx, "^([\w``]*)i([\w``]*)\)")) {
If (!IgnoreCase) {
GuiControl,, IgnoreCase, 1
}
} Else If (IgnoreCase) {
GuiControl,, IgnoreCase, 0
}
If (RegExMatch(RegEx, "^([\w``]*)m([\w``]*)\)")) {
If (!Multiline) {
GuiControl,, Multiline, 1
}
} Else If (Multiline) {
GuiControl,, Multiline, 0
}
If (RegEx == "") {
GuiControl,, %hMatchCount%, No Match
SciGroups.SetReadOnly(False)
SciGroups.ClearAll()
SciGroups.SetReadOnly(True)
Return
}
Sci.GetText(Sci.GetLength() + 1, SciText)
RegEx := RegExReplace(RegEx, "^(\w*)\)", "P$1)", Count)
If (!Count) {
RegEx := "P)" . RegEx
}
Pos := 1
If (HighlightAll) {
While (FoundPos := RegExMatch(SciText, RegEx, Length, Pos)) {
If (Length == 0) {
Return
}
Highlight(FoundPos, Length)
Pos := FoundPos + 1
}
} Else {
If (FoundPos := RegExMatch(SciText, RegEx, Length, Pos)) {
Highlight(FoundPos, Length)
}
}
UpdateCounter(SciText, RegEx)
If (Groups) {
GoSub UpdateGroups
}
If (Replace) {
GoSub Replace
}
Return
SetOption:
Gui Submit, NoHide
If (A_GuiControl = "IgnoreCase") {
Option := "i"
} Else If (A_GuiControl = "Multiline") {
Option := "m"
}
If (RegExMatch(RegEx, "^([\w``]*)" . Option . "([\w``]*)\)")) {
NewStr := RegExReplace(RegEx, "^([\w``]*)" . Option . "([\w``]*)\)", "$1$2)")
If (SubStr(NewStr, 1, 1) == ")") {
NewStr := SubStr(NewStr, 2)
}
} Else {
If (!RegExMatch(RegEx, "^[\w``]+\)")) {
Option .= ")"
}
NewStr := Option . RegEx
}
GuiControl,, RegEx, % NewStr
Return
Highlight(Pos, Length) {
Sci.StartStyling(Pos - 1, 0x1F)
Sci.SetStyling(Length, SCE_AHKL_USERDEFINED1)
}
UpdateCounter(Text, RegEx) {
Count := 0
Pos := 1
While (FoundPos := RegExMatch(Text, RegEx,, Pos)) {
Count++
Pos := FoundPos + 1
}
If (Count == 0) {
CountMsg := "No Match"
} Else If (Count == 1) {
CountMsg := "1 Match"
} Else If (Count > 1) {
CountMsg := Count . " Matches"
}
GuiControl,, %hMatchCount%, %CountMsg%
}
ShowHelp:
HelpFile := A_AhkPath . "\..\AutoHotkey.chm"
Run HH mk:@MSITStore:%HelpFile%::/docs/misc/RegEx-QuickRef.htm
Return
ShowGroups:
If (!Groups) {
ControlMove,,,,, 115, % "ahk_id " . Sci.hWnd
GuiControl Move, %hGroupsHdr%, y250
GuiControl Move, %hCollapseChevron%, x697 y256
Control Show,,, % "ahk_id " . SciGroups.hWnd
ControlColor(hGroupsHdr, hWindow, 0x336699, 0xFFFFFF)
Groups := True
GuiControl Move, %hReplaceHdr%, y403
Control Hide,,, % "ahk_id " . hReplaceField
Control Hide,,, % "ahk_id " . SciReplace.hWnd
ControlColor(hReplaceHdr, hWindow, 0xC0C0C0, 0xFFFFFF)
Replace := False
GoSub UpdateGroups
} Else {
ControlMove,,,,, 232, % "ahk_id " . Sci.hWnd
GuiControl Move, %hGroupsHdr%, y368
GuiControl Move, %hCollapseChevron%, x-16
Control Hide,,, % "ahk_id " . SciGroups.hWnd
ControlColor(hGroupsHdr, hWindow, 0xC0C0C0, 0xFFFFFF)
Groups := False
}
WinSet Redraw,, ahk_id%hWindow%
Return
UpdateGroups:
Gui Submit, NoHide
If (RegEx == "") {
Return
}
Sci.GetText(Sci.GetLength() + 1, SciText)
RegEx := RegExReplace(RegEx, "^(\w*)\)", "O$1)", Count)
If (!Count) {
RegEx := "O)" . RegEx
}
RegExMatch(SciText, RegEx, o)
GrpCount := o.Count()
Output := ""
Loop % GrpCount {
n := (o.Name(A_Index) != "") ? o.Name(A_Index) : A_Index
Value := (o.Value(A_Index) != "") ? o.Value(A_Index) : "None"
Output .= n . ": " . Value . "`n"
}
SciGroups.SetReadOnly(False)
If (GrpCount) {
SciGroups.SetText("", Output)
} Else {
SciGroups.ClearAll()
}
SciGroups.SetReadOnly(True)
Return
ShowReplace:
If (!Replace) {
ControlMove,,,,, 100, % "ahk_id " . Sci.hWnd
GuiControl Move, %hReplaceHdr%, y235
GuiControl Move, %hCollapseChevron%, x697 y241
Control Show,,, % "ahk_id " . hReplaceField
Control Show,,, % "ahk_id " . SciReplace.hWnd
ControlColor(hReplaceHdr, hWindow, 0x336699, 0xFFFFFF)
Replace := True
Control Hide,,, % "ahk_id " . SciGroups.hWnd
GuiControl Move, %hGroupsHdr%, y403
ControlColor(hGroupsHdr, hWindow, 0xC0C0C0, 0xFFFFFF)
Groups := False
ControlFocus,, ahk_id%hReplaceField%
} Else {
ControlMove,,,,, 232, % "ahk_id " . Sci.hWnd
GuiControl Move, %hReplaceHdr%, y403
GuiControl Move, %hCollapseChevron%, x-16
Control Hide,,, % "ahk_id " . hReplaceField
Control Hide,,, % "ahk_id " . SciReplace.hWnd
ControlColor(hReplaceHdr, hWindow, 0xC0C0C0, 0xFFFFFF)
Replace := False
GuiControl Move, %hGroupsHdr%, y368
}
WinSet Redraw,, ahk_id%hWindow%
Return
Replace:
Gui Submit, NoHide
If (RegEx == "") {
SciReplace.ClearAll()
Return
}
Sci.GetText(Sci.GetLength() + 1, SciText)
NewStr := RegExReplace(SciText, RegEx, Replacement)
SciReplace.SetText("", NewStr)
Return
CreateScintilla(hParent, x, y, w, h, SciLexer, Options := "") {
Scintilla := New Scintilla
Scintilla.Add(hParent, x, y, w, h, SciLexer, Options)
Scintilla.SetLexer(SCLEX_CONTAINER)
Scintilla.SetMarginWidthN(0, 0)
Scintilla.SetMarginWidthN(1, 0)
Scintilla.SetWrapMode(1)
Scintilla.StyleSetFont(SCE_AHKL_NEUTRAL, "Lucida Console")
Scintilla.StyleSetSize(SCE_AHKL_NEUTRAL, 10)
Scintilla.SetSelFore(1, "0xFFFFFF")
Scintilla.SetSelBack(1, "0x3399FF")
Return Scintilla
}
OnNotify(wParam, lParam, msg, hWnd, obj) {
If (obj.SCNCode = SCN_MODIFIED && obj.modType != 20) {
GoSub Search
}
}
ControlColor(Control, Window, bc := "", tc := "", Redraw := 1) {
a := {}
a["c"] := Control
a["g"] := Window
a["bc"] := (bc = "") ? "" : (((bc & 255) << 16) + (((bc >> 8) & 255) << 8) + (bc >> 16))
a["tc"] := (tc = "") ? "" : (((tc & 255) << 16) + (((tc >> 8) & 255) << 8) + (tc >> 16))
WindowProc("Set", a, "", "")
If (Redraw) {
SizeOfWINDOWINFO := 60
VarSetCapacity(WINDOWINFO, SizeOfWINDOWINFO, 0)
NumPut(SizeOfWINDOWINFO, WINDOWINFO, "UInt")
DllCall("GetWindowInfo", "Ptr", Control, "Ptr", &WINDOWINFO)
DllCall("ScreenToClient", "Ptr", Window, "Ptr", &WINDOWINFO+20) ; x1, y1 of client area
DllCall("ScreenToClient", "Ptr", Window, "Ptr", &WINDOWINFO+28) ; x2, y2 of client area
DllCall("RedrawWindow", "Ptr", Window, "UInt", &WINDOWINFO+20, "UInt", 0, "UInt", 0x101)
}
}
WindowProc(hWnd, uMsg, wParam, lParam) {
Static Win := {}
Critical
If uMsg Between 0x132 And 0x138
If (Win[hWnd].HasKey(lParam)) {
If (tc := Win[hWnd, lParam, "tc"]) {
DllCall("SetTextColor", "UInt", wParam, "UInt", tc)
}
If (bc := Win[hWnd, lParam, "bc"]) {
DllCall("SetBkColor", "UInt", wParam, "UInt", bc)
}
Return Win[hWnd, lParam, "Brush"] ; Return the HBRUSH to notify the OS that we altered the HDC.
}
If (hWnd = "Set") {
a := uMsg
Win[a.g, a.c] := a
If (Win[a.g, a.c, "tc"] = "") And (Win[a.g, a.c, "bc"] = "")
Win[a.g].Remove(a.c, "")
If Not Win[a.g, "WindowProcOld"]
Win[a.g,"WindowProcOld"] := DllCall("SetWindowLong", "Ptr", a.g, "Int", -4, "Int", RegisterCallback("WindowProc", "", 4), "UInt")
If Win[a.g, a.c, "Brush"]
DllCall("DeleteObject", "Ptr", Brush)
If (Win[a.g, a.c, "bc"] != "")
Win[a.g, a.c, "Brush"] := DllCall("CreateSolidBrush", "UInt", a.bc)
Return
}
Return DllCall("CallWindowProcA", "UInt", Win[hWnd, "WindowProcOld"], "UInt", hWnd, "UInt", uMsg, "UInt", wParam, "UInt", lParam)
}
GuiEscape:
GuiClose:
ExitApp
Users browsing this forum: No registered users and 8 guests