Skip to content

Commit

Permalink
Moved to RichCode.ahk library
Browse files Browse the repository at this point in the history
  • Loading branch information
G33kDude committed Aug 18, 2017
1 parent 848f3ef commit 0568e4a
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 427 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "RichCode.ahk"]
path = RichCode.ahk
url = https://github.com/G33kDude/Richcode.ahk
42 changes: 19 additions & 23 deletions CodeQuickTester.ahk
Expand Up @@ -17,39 +17,34 @@ FileEncoding, UTF-8
Settings :=
( LTrim Join Comments
{
"Font": {
"Typeface": "Microsoft Sans Serif",
"Size": 8,
"Bold": False
},

; Editor (colors are 0xBBGGRR)
"FGColor": 0xCDEDED,
"FGColor": 0xEDEDCD,
"BGColor": 0x3F3F3F,
"TabSize": 4,
"CodeFont": {
"Font": {
"Typeface": "Consolas",
"Size": 11,
"Bold": False
},

; Highlighter (colors are 0xRRGGBB)
"UseHighlighter": True,
"Highlighter": "HighlightAHK",
"HighlightDelay": 200, ; Delay until the user is finished typing
"Colors": [
0x7F9F7F, ; Comments
0x7F9F7F, ; Multiline comments
0x7CC8CF, ; Directives
0x97C0EB, ; Punctuation
0xF79B57, ; Numbers
0xCC9893, ; Strings
0xF79B57, ; A_Builtins
0xE4EDED, ; Flow
0xCDBFA3, ; Commands
0x7CC8CF, ; Functions
0xCB8DD9, ; Keynames
0xE4EDED, ; Other keywords
0xEDEDCD ; Text
; RRGGBB ; ; AHK
0x7F9F7F, ; 1 ; Comments
0x7F9F7F, ; 2 ; Multiline comments
0x7CC8CF, ; 3 ; Directives
0x97C0EB, ; 4 ; Punctuation
0xF79B57, ; 5 ; Numbers
0xCC9893, ; 6 ; Strings
0xF79B57, ; 7 ; A_Builtins
0xE4EDED, ; 8 ; Flow
0xCDBFA3, ; 9 ; Commands
0x7CC8CF, ; 10 ; Functions
0xCB8DD9, ; 11 ; Key names
0xE4EDED ; 12 ; Other keywords
],

; Auto-Indenter
Expand Down Expand Up @@ -90,11 +85,12 @@ TesterClose(Tester)
return
*/

#Include %A_ScriptDir%\RichCode.ahk\RichCode.ahk
#Include %A_ScriptDir%\RichCode.ahk\Highlighters\AHK.ahk
#Include %A_ScriptDir%\lib
#Include CQT.ahk
#Include ServiceHandler.ahk
#Include WinEvents.ahk
#Include AutoIndent.ahk
#Include Utils.ahk
#Include Publish.ahk
#Include Highlight.ahk
#Include Publish.ahk
1 change: 1 addition & 0 deletions RichCode.ahk
Submodule RichCode.ahk added at a61533
104 changes: 10 additions & 94 deletions lib/CQT.MenuButtons.ahk
Expand Up @@ -12,7 +12,7 @@ class MenuButtons
if ErrorLevel
return

FileOpen(FilePath, "w").Write(this.Parent.Code)
FileOpen(FilePath, "w").Write(this.Parent.RichCode.Value)
}

Open()
Expand All @@ -35,7 +35,7 @@ class MenuButtons
if ErrorLevel
return

FileOpen(FilePath, "w").Write(this.Parent.Code)
FileOpen(FilePath, "w").Write(this.Parent.RichCode.Value)
PreprocessScript(Text, FilePath, [])
FileOpen(FilePath, "w").Write(Text)
}
Expand Down Expand Up @@ -81,12 +81,14 @@ class MenuButtons
Menu, % this.Parent.Menus[4], Check, &Highlighter
else
Menu, % this.Parent.Menus[4], Uncheck, &Highlighter
this.Parent.Code := this.Parent.Code

; Force refresh the code, adding/removing any highlighting
this.Parent.RichCode.Value := this.Parent.RichCode.Value
}

AutoIndent()
{
this.Parent.LoadCode(AutoIndent(this.Parent.Code, this.Parent.Settings.Indent))
this.Parent.LoadCode(AutoIndent(this.Parent.RichCode.Value, this.Parent.Settings.Indent))
}

Help()
Expand Down Expand Up @@ -121,107 +123,21 @@ class MenuButtons

Comment()
{
hCodeEditor := this.Parent.hCodeEditor

Text := StrSplit(this.Parent.Code, "`n", "`r")

VarSetCapacity(s, 8, 0), SendMessage(0x0B0, &s, &s+4, hCodeEditor) ; EM_GETSEL
Left := NumGet(s, 0, "UInt"), Right := NumGet(s, 4, "UInt")

Top := SendMessage(0x436, 0, Left, hCodeEditor) ; EM_EXLINEFROMCHAR
Bottom := SendMessage(0x436, 0, Right, hCodeEditor) ; EM_EXLINEFROMCHAR

Count := Bottom-Top + 1
Loop, % Count
Text[A_Index+Top] := ";" Text[A_Index+Top]
for each, Line in Text
Out .= "`r`n" Line
Out := SubStr(Out, 3)

this.Parent.Code := Out

NumPut(NumGet(s, "UInt") + 1, &s, "UInt")
NumPut(NumGet(s, 4, "UInt") + Count, &s, 4, "UInt")
SendMessage(0x437, 0, &s, hCodeEditor) ; EM_EXSETSEL
this.Parent.RichCode.IndentSelection(False, ";")
}

Uncomment()
{
hCodeEditor := this.Parent.hCodeEditor

Text := StrSplit(this.Parent.Code, "`n", "`r")

VarSetCapacity(s, 8, 0), SendMessage(0x0B0, &s, &s+4, hCodeEditor) ; EM_GETSEL
Left := NumGet(s, 0, "UInt"), Right := NumGet(s, 4, "UInt")

Top := SendMessage(0x436, 0, Left, hCodeEditor) ; EM_EXLINEFROMCHAR
Bottom := SendMessage(0x436, 0, Right, hCodeEditor) ; EM_EXLINEFROMCHAR

Removed := 0
Loop, % Bottom-Top + 1
if InStr(Text[A_Index+Top], ";") == 1
Text[A_Index+Top] := SubStr(Text[A_Index+Top], 2), Removed++
for each, Line in Text
Out .= "`r`n" Line
Out := SubStr(Out, 3)

this.Parent.Code := Out

NumPut(NumGet(s, "UInt") - 1, &s, "UInt")
NumPut(NumGet(s, 4, "UInt") - Removed, &s, 4, "UInt")
SendMessage(0x437, 0, &s, hCodeEditor) ; EM_EXSETSEL
this.Parent.RichCode.IndentSelection(True, ";")
}

Indent()
{
hCodeEditor := this.Parent.hCodeEditor

Text := StrSplit(this.Parent.Code, "`n", "`r")

VarSetCapacity(s, 8, 0), SendMessage(0x0B0, &s, &s+4, hCodeEditor) ; EM_GETSEL
Left := NumGet(s, 0, "UInt"), Right := NumGet(s, 4, "UInt")

Top := SendMessage(0x436, 0, Left, hCodeEditor) ; EM_EXLINEFROMCHAR
Bottom := SendMessage(0x436, 0, Right, hCodeEditor) ; EM_EXLINEFROMCHAR

Count := Bottom-Top + 1
Loop, % Count
Text[A_Index+Top] := "`t" Text[A_Index+Top]
for each, Line in Text
Out .= "`r`n" Line
Out := SubStr(Out, 3)

this.Parent.Code := Out

NumPut(NumGet(s, "UInt") + 1, &s, "UInt")
NumPut(NumGet(s, 4, "UInt") + Count, &s, 4, "UInt")
SendMessage(0x437, 0, &s, hCodeEditor) ; EM_EXSETSEL
this.Parent.RichCode.IndentSelection()
}

Unindent()
{
hCodeEditor := this.Parent.hCodeEditor

Text := StrSplit(this.Parent.Code, "`n", "`r")

VarSetCapacity(s, 8, 0), SendMessage(0x0B0, &s, &s+4, hCodeEditor) ; EM_GETSEL
Left := NumGet(s, 0, "UInt"), Right := NumGet(s, 4, "UInt")

Top := SendMessage(0x436, 0, Left, hCodeEditor) ; EM_EXLINEFROMCHAR
Bottom := SendMessage(0x436, 0, Right, hCodeEditor) ; EM_EXLINEFROMCHAR

Removed := 0
Loop, % Bottom-Top + 1
if InStr(Text[A_Index+Top], "`t") == 1
Text[A_Index+Top] := SubStr(Text[A_Index+Top], 2), Removed++
for each, Line in Text
Out .= "`r`n" Line
Out := SubStr(Out, 3)

this.Parent.Code := Out

NumPut(NumGet(s, "UInt") - 1, &s, "UInt")
NumPut(NumGet(s, 4, "UInt") - Removed, &s, 4, "UInt")
SendMessage(0x437, 0, &s, hCodeEditor) ; EM_EXSETSEL
this.Parent.RichCode.IndentSelection(True)
}
}
3 changes: 1 addition & 2 deletions lib/CQT.Paste.ahk
Expand Up @@ -8,7 +8,6 @@ class Paste
Gui, New, +Owner%ParentWnd% +ToolWindow +hWndhWnd
this.hWnd := hWnd
Gui, Margin, 5, 5
Gui, Font, % this.Parent.Settings.Font, % this.Parent.Settings.TypeFace

Gui, Add, Text, xm ym w30 h22 +0x200, Desc: ; 0x200 for vcenter
Gui, Add, Edit, x+5 yp w125 h22 hWndhPasteDesc, % this.Parent.Settings.DefaultDesc
Expand Down Expand Up @@ -51,7 +50,7 @@ class Paste
GuiControlGet, PasteChan,, % this.hPasteChan
this.GuiClose()

Link := Ahkbin(this.Parent.Code, PasteName, PasteDesc, PasteChan)
Link := Ahkbin(this.Parent.RichCode.Value, PasteName, PasteDesc, PasteChan)

MsgBox, 292, % this.Parent.Title " - Pasted", Link received:`n%Link%`n`nCopy to clipboard?
IfMsgBox, Yes
Expand Down

0 comments on commit 0568e4a

Please sign in to comment.