AutoGUI - Script Editor, GUI Designer, Debugger and Tools

Old Topics related to the original "AutoGUI" ahk script editor.
Guest

Re: AutoGUI - GUI Designer and Script Editor

27 Jan 2017, 06:21

Using Import GUI & Mod does not work for me.
I have re-created and saved the GUI (see source above) in the MOD Version then "Import GUI".
instead of the Text inside the Tab a black rectangle is shown. When changing or adding controls,
the code tab is changed and all text controls are gone.
If closing the file, then re-importing the GUI, then the code Windows is also incorrect,
the GUI Windows is empty, no controls are visible.

Generally what i'm trying to do is creating a GUI then change it by adding/removing controls etc. later after re-starting AutoGUI.
For me at least, I haven't found a working solution, not with the mod, Import GUI, nor Windows Cloning Tool.
chasbas

Re: AutoGUI - GUI Designer and Script Editor

27 Jan 2017, 18:55

I don't know the AutoGUI source code well enough to tell you what the problem is, but from your error message I can see that you have unzipped the AutoGUI file at least twice to a default directory. If it were me, just to uncomplicate things I would re-unzip it into (as it describes in the installation instructions) a subdirectory of the AutoHotKey installation directory, and try to run it from there.

*Then* if you get the same problem it should be easier to work out what's happening. Just a thought. Sorry I don't have any more concrete ideas.

cb
JackPJ wrote:Hi,

could someone tell me if I'm doing something clearly wrong/stupid here?

I've just downloaded the zipped file, unzipped it and tried to run AutoGUI.ahk.

Yet all I get is the attached error?

Am I missing something simple here?

Thanks

Jack
Guest

Re: AutoGUI - GUI Designer and Script Editor

27 Jan 2017, 19:03

Thank you so much RH - I originally posted this question thinking "I can't be the only one having this issue" and sure enough you were kind enough to share your solution. I will definitely try it out.

I was thinking of doing mods myself along the lines of dumping every single executed GUI command into another file (as in, "Gui, Editbox, asdfasdf", ...). Then I thought some more and went to bed.

I have to say to Alguimist that this is the most professional, impressive, complete and robust piece of software I've ever seen one person write, for free. Thank you so much for all your efforts.
RazorHalo wrote:I don't use the window cloning tool.

If you use my mods then you reload the GUI via the file menu>>Import GUI

The code would need to be created from that version of AutoGUI w/the mods to reload properly. I have a GUI I have been working on for a while that has ~100 controls on it and it reloads everything for the GUI. All variables and options and positions etc.
User avatar
SnowFlake
Posts: 368
Joined: 28 Apr 2015, 05:41
Contact:

Re: AutoGUI - GUI Designer and Script Editor

04 Feb 2017, 09:32

It works with Wine aso if you compile the .ahk script,some hick ups bu it works overall :)

picture:
https://s24.postimg.org/kjrevpev9/desktop_1_001.png
:yawn:
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoGUI - GUI Designer and Script Editor

04 Feb 2017, 14:04

Is that ahk with wine?
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Rorqual
Posts: 10
Joined: 14 Jan 2017, 13:23

Re: AutoGUI - GUI Designer and Script Editor

15 Feb 2017, 18:49

I'll be making feature requests for reference here, I may implement them myself if I can figure it out
  • Add a new edit box to the top right or bottom left (ideal) of the program which searches the entire menu structure / control types of the program and activates that menu item or control type button upon pressing enter. An autocomplete dropdown should help the user find the menu item or control type that they partially type. This edit box should not have default keyboard focus (the editor should), the hotkey to give it focus should be Esc key, when the editor has focus. Then, Esc key again gives the editor focus back. Inspiration: Google docs and SlickEdit's command line
    Image
    Image
  • Better autocomplete in the editor, even after typing a random word like "RandomWord", typing "R" on the next line should show "RandomWord" as a match in the dropdown. When the autocomplete popup is shown, make the Ctrl+DownArrow and Ctrl+UpArrow keys not do what they normally do which is duplicate lines, instead, make the Caret move down or up respectively and cancel the autocomplete. This way the AutoComplete will not be as annoying when you don't need it and want to change lines. The previous hotkeys for moving / duplicating selection should be reinstated when the autocomplete is not shown.
    Speaking of the ctrl+up and ctrl+down hotkeys, they aren't consistent. Ctrl+down duplicates a line, Ctrl+Up moves a line up. How about ctrl+down moves a line down, and ctrl+shift+up duplicates a line up, and ctrl+shift+down duplicates a line down? Inspiration: LightTable (http://lighttable.com/)
    Image
    Image
  • After dragging something in the GUI design window, allow an undo (Ctrl+Z) and redo (Ctrl+Y) operation to move the selection backward/forward in history of its positions. Inspiration: Photoshop
  • Allow multi line editing of text. Currently holding down ALT and dragging a line will show the multiline cursor, but it does not type on all the lines. Inspiration: Ahk-Studio
  • After using an operation like Comment/Uncomment (Ctrl+K), highlight (select) the previous selection, so you can easily do something else to the selection without having to select again
  • Save text files in the background after every change, so the user never has to save. Save the undo/redo history of a file all the way back to the beginning, so a user can restore a previous state using undo/redo. Inspiration: zed editor (zedapp.org)
  • Display the current zoom percentage in the text editor, and allow to restore default zoom by a menu option. Inspiration: Notepad++
  • Menu option to pretty-format code / indent code / format braces in a given style. Inspiration: Ahk-Studio
  • Clone tool to clone individual tabs of a dialog not just the active tab
  • Code folding
  • Collapse/Expand all code folding, add these as menu options then give them hotkeys like Alt+0 and Alt+Shift+0. Inspiration: Notepad++
  • In the Find dialog, the Find Next/Previous should be able to go wrap the beginning/end of file instead of returning 'could not find' because it reached the beginning/end of a document. This should be an option below "Backslashed characters". The option should be named something like "Wrap at beginning/end". Inspiration: Slickedit (https://www.slickedit.com/)
    Image
  • After doing a "Mark All" operation from the find dialog, list the line numbers of each found string in a pane below the text editor, clicking each match/line should jump to that line in the editor. Inspiration: Notepad++
  • The left hand "Control Types" pane should have multiple tabs at the top or bottom, which can be toggled (when it has keyboard focus, Tab or Shift+Tab navigates to next tab or previous tab, when it doesn't, clicking other tabs navigates to them. Tabs can be disabled by a menu option. The first tab will be "Control Types", then "Function list", then "Label list", and then "Hotkey list" for the active document, which jumps to the function, label, or hotkey. The last tab should be a file explorer similar to AHK studios which shows all the .ahk files in the current workspace so we can quickly switch between many files. Inspiration: SlickEdit
    Image
  • Ability to highlight a selection, save it as a snippet and give the snippet a name in a pop up dialog. There should be a new menu option "Snippets" which lists all the named snippets in a drop down menu. We should be able to nest snippets under parent menus for handling a large amount of them. Entire files or just individual functions could be saved as snippets. Inspiration: Tidbit's editor
  • Menu option to upload the current file (or just a selection if a selection is highlighted) to http://p.ahkscript.org/, and then copy the link to the clipboard and open the default browser to that page. Name it something like "Upload to ahkbin".
  • Create include from selection - Adds a new Include to your project using the currently selected text. Inspiration: AHK-Studio
  • Navigating to Braces, Navigating to the borders of a code block. Navigate to the code block start, press Ctrl+Open Bracket, Navigate to the code block end, press Ctrl+Close Bracket. This seems to already be implemented, but not documented. It needs menu options so people know it's there. Suggest to put under "Edit" menu. It also needs an improvement, detect if the Caret is at a nested brace, if it is, the hotkey should jump to the matching brace at that nest level, not to the start/end of the block. Inspiration: WebStorm (https://www.jetbrains.com/webstorm/)
  • Clicking the line:column number in the status bar should fire the Go to line dialog. It would be fancy if the Go to line dialog was renamed "goto line:column" and allowed us to specify things like 80:4 in the edit box, so we can go to the 4th character position on line 80. Inspiration: WebStorm
    Image
  • Smartpaste (auto indent lines when you paste them in a block such as an if block). Inspiration: AhkStudio and SlickEdit
    Image
  • Change Editor Colors as a menu option similar to the Change Editor Font (the line number background color, font color, editor text color, editor background color)
  • Suggest rename "Constantine" in menu to "Windows API Constants Explorer", Suggest rename "Expressive" in menu to "Regular Expression Tool", Suggest rename "A_Variables" in menu to "AutoHotkey Built-in Variables". Because explanatory names help new users discover/click things for the first time rather than have to learn new vocabulary.
  • Make the Regular Expression Tool the same color scheme as the AutoHotkey Built in variables tool and the Windows API Constants Explorer, same font sizes too
    Image
  • Remove the horizontal scrollbar from the editor when it isn't needed. When "Wrap long lines" is turned off, a scrollbar appears for no reason because there is no whitespace that long (open a new file to test it and uncheck that menu option.)
  • Sort the controls in the Control Types pane alphabetically, it appears to start off this way but there is "ActiveX, Custom Class, and Command Link" at the end out of order
  • Add all of the Control Types to the main menu in its own menu item named "Control Types", then allow us to disable the Control types pane and just work with the menu. Suggest rename "Control Types" menu to "AutoBuild", have a menu item "Control", then all of the controls like Button, Checkbox, Combobox, listed under that parent. Later, you could add other things to be added such as "Snippet" to the "AutoBuild" menu, or even a list of autohotkey commands under a "Commands" menu item, all listed under the parent menu "AutoBuild" on the main menu
Edit:
I've made a couple of formatting changes to Expressive, Constantine, A_Variables, the Import GUI, sorted the controls, changed default font to Consolas size 11 (much easier to read) and I'm starting to get a little familiar with AutoGUI sourcecode, but I've also noticed new things:
The syntax highlighting appears to be messed up, sporadically letters get bolded and the foreground for that character only gets overridden to be transparent.
if you type "#SingleInstance, Force", the "Force" word should be syntax-highlighted but it isn't

changes gif:
Image

@Alguimist, is there a way for me to use Scite4AHK's syntax highlighting style out of the box in AutoGUI, then I could start altering that? I can't seem to narrow down what is causing the weird formatting glitch for AutoGUI's lexer.
Rorqual
Posts: 10
Joined: 14 Jan 2017, 13:23

Re: AutoGUI - GUI Designer and Script Editor

18 Feb 2017, 11:54

Below is a patch for Editor.ahk, previously, the 'Match Brace' behavior was bad, it would especially act up for some reason when word wrap was turned on, highlighting every character that triggered an autocomplete because there was no matchlist for what constituted a brace (Scintilla does not do this automatically).

Added functionality:
1) detects braces to the left AND right of the caret.
2) detects caret change, removes highlighting when caret leaves brace
3) ignores non-brace characters (added IsBrace() function)

Because it was driving me crazy, I also changed the CurPos variable to be named CaretPos, since the CURSOR is the mouse pointer floating around the screen :-)

I also added a background color to matched braces of bright yellow, and the foreground color of black since they become bolded on a match - this is because braces have to have a background color, if you don't specify one, it will default to some color and mess up the 'highlight active line' because the brace will have a different background color - so we might as well give it a consistent one, I chose yellow but that is easy to change.
Line 393,

Code: Select all

Sci[n].BraceHighlight(Invalid_Position, 999999999)
should ideally be

Code: Select all

Sci[n].BraceHighlight(Invalid_Position, Invalid_Position)
instead, but the dllcall in Scintilla.ahk could not handle a negative integer value of -1 (which is the value of Invalid_Position). I believe the dllcall was from Pulover's Macro Creator, and I'm not sure why it doesn't handle negative ints. It even has a comment that says it DOES handle negative ints, but it doesn't. Perhaps someone else can tell us?

Here is the dllcall code:

Code: Select all

/*
    Function : __sendEditor
    Posts the messages used to modify the control's behaviour.

    *This is an internal function and it is not needed in normal situations. Please use the scintilla object to call all functions.
    They call this function automatically*

    Parameters:
    __sendEditor(hwnd, msg, [wParam, lParam])

    hwnd    -   The hwnd of the control that you want to operate on. Useful for when you have more than 1
                Scintilla components in the same script. The wrapper will remember the last used hwnd,
                so you can specify it once and only specify it again when you want to operate on a different
                component.
                *Note: This is converted internally by the wrapper from the object calling method. It is recommended that you dont use this function.*
    msg     -   The message to be posted, full list can be found here:
                <http://www.scintilla.org/ScintillaDoc.html>
    wParam  -   wParam for the message
    lParam  -   lParam for the message

    Returns:
    Status code of the DllCall performed.

    Examples:
    (Start Code)
    __sendEditor(hSci1, "SCI_SETMARGINWIDTHN",0,40)  ; Set the margin 0 to 40px on the first component.
    __sendEditor(0, "SCI_SETWRAPMODE",1,0)           ; Set wrap mode to true on the last used component.
    __sendEditor(hSci2, "SCI_SETMARGINWIDTHN",0,50)  ; Set the margin 0 to 50px on the second component.
    (End)
*/
__sendEditor(hwnd, msg=0, wParam=0, lParam=0){
    static

    hwnd := !hwnd ? oldhwnd : hwnd, oldhwnd := hwnd, msg := !(msg+0) ? "SCI_" msg : msg

    if !%hwnd%_df
	{
        SendMessage, SCI_GETDIRECTFUNCTION,0,0,,ahk_id %hwnd%
        %hwnd%_df := ErrorLevel
        SendMessage, SCI_GETDIRECTPOINTER,0,0,,ahk_id %hwnd%
        %hwnd%_dp := ErrorLevel
	}

    if !msg && !wParam && !lParam   ; called only with the hwnd param from SCI_Add
        return                      ; Exit because we did what we needed to do already.
        
    ;OutputDebug %msg%

    ; The fast way to control Scintilla
    return DllCall(%hwnd%_df            ; DIRECT FUNCTION
                  ,"UInt" ,%hwnd%_dp    ; DIRECT POINTER
                  ,"UInt" ,!(msg+0) ? %msg% : msg
                  ,"Int"  ,inStr(wParam, "-") ? wParam : (%wParam%+0 ? %wParam% : wParam) ; handles negative ints
                  ,"Int"  ,%lParam%+0 ? %lParam% : lParam)
}

Code: Select all

SetScintilla(n) { 
    Sci[n].SetLexer(200) ; SCLEX_AHKL
    Sci[n].SetCodePage(65001)
    Sci[n].SetWrapMode(WordWrap)

    ; Indentation
    Sci[n].SetIndent(TabSize)
    Sci[n].SetTabWidth(TabSize)
    Sci[n].SetUseTabs(False) ; Indent with spaces
    Sci[n].SetIndentationGuides(g_IndentGuides ? 3 : 0)

    Sci[n].MarginLen := 0
    SciSetStyle(n, Sci.FontName, Sci.FontSize)    
    Sci[n].Notify := "OnWM_NOTIFY"
    Sci[n].SetExtraAscent(2) ; Increase space between lines

    ; Autocomplete settings
    Sci[n].AutoCSetIgnoreCase(True)
    Sci[n].AutoCSetMaxHeight(g_AutoCMaxItems)
    Sci[n].AutoCSetOrder(1) ; SC_ORDER_PERFORMSORT

    ; Calltip settings
    Sci[n].CalltipSetFore(CvtClr(0x000000))
    Sci[n].CalltipSetBack(CvtClr(0xFFFFDD))
    Sci[n].SetMouseDwellTime(1000) ; Hover time

    Sci[n].AssignCmdKey(SCK_END, SCI_LINEENDWRAP)
    Sci[n].AssignCmdKey(SCK_HOME, SCI_HOMEWRAP)

    If (g_ShowSymbols) {
        g_ShowSymbols := False
        GoSub ToggleSymbols
    }
}

IsBrace(n) {
    ; Return true for the (,),[,],{,},<,> character codes
    if n in 40,41,91,93,123,125,60,62
        return true
    else
        return false
}

SciSetStyle(n, FontName := "Lucida Console", FontSize := 10) {
    Sci[n].StyleSetFont(STYLE_DEFAULT, FontName, 2)
    Sci[n].StyleSetSize(STYLE_DEFAULT, FontSize)

    Sci[n].StyleSetBack(STYLE_DEFAULT, CvtClr(0xFAFAFA))
    Sci[n].StyleClearAll() ; This message sets all styles to have the same attributes as STYLE_DEFAULT.

    ; Active line background color
    Sci[n].SetCaretLineBack(CvtClr(g_HighlightActiveLine ? 0xD8F3FF : 0xFFFFFF))
    Sci[n].SetCaretLineVisible(True)
    Sci[n].SetCaretLineVisibleAlways(1)

    ; Margin settings
    Sci[n].SetMarginTypeN(0, 1)
    SetLineNumberWidth(n)
    Sci[n].SetMarginLeft(0, 2) ; Left padding
    Sci[n].SetMarginWidthN(1, 2) ; Line number right margin
    Sci[n].StyleSetFore(33, CvtClr(0xCFD2CA)) ; Margin foreground color
    Sci[n].StyleSetBack(33, CvtClr(0xFFFFFF)) ; Margin background color

    ; Matching braces
    Sci[n].StyleSetFore(STYLE_BRACELIGHT, CvtClr(0x000000))
    Sci[n].StyleSetBack(STYLE_BRACELIGHT, CvtClr(0xFFFF00))
    Sci[n].StyleSetBold(STYLE_BRACELIGHT, True)
    Sci[n].StyleSetFore(STYLE_BRACEBAD, CvtClr(0xFF0000))

    ; Selection
    Sci[n].SetSelFore(1, CvtClr(0xFFFFFF))
    Sci[n].SetSelBack(1, CvtClr(0x3399FF))

    If (SyntaxHighlighting) {
        ; AHK syntax elements
        Sci[n].StyleSetFore(SCE_AHKL_IDENTIFIER     , CvtClr(0x000000))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTDOC     , CvtClr(0x008888))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTLINE    , CvtClr(0x969896))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTBLOCK   , CvtClr(0x969896))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTKEYWORD , CvtClr(0xA50000))
        Sci[n].StyleSetFore(SCE_AHKL_STRING         , CvtClr(0x183691))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGOPTS     , CvtClr(0x0000EE))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGBLOCK    , CvtClr(0x183691))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGCOMMENT  , CvtClr(0xFF0000))
        Sci[n].StyleSetFore(SCE_AHKL_LABEL          , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_HOTKEY         , CvtClr(0x00AADD))
        Sci[n].StyleSetFore(SCE_AHKL_HOTSTRING      , CvtClr(0x00BBBB))
        Sci[n].StyleSetFore(SCE_AHKL_HOTSTRINGOPT   , CvtClr(0x990099))
        Sci[n].StyleSetFore(SCE_AHKL_HEXNUMBER      , CvtClr(0x880088))
        Sci[n].StyleSetFore(SCE_AHKL_DECNUMBER      , CvtClr(0x606870))
        Sci[n].StyleSetFore(SCE_AHKL_VAR            , CvtClr(0x9F1F6F))
        Sci[n].StyleSetFore(SCE_AHKL_VARREF         , CvtClr(0x990055))
        Sci[n].StyleSetFore(SCE_AHKL_OBJECT         , CvtClr(0x008888))
        Sci[n].StyleSetFore(SCE_AHKL_USERFUNCTION   , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_DIRECTIVE      , CvtClr(0x0000CF))
        Sci[n].StyleSetFore(SCE_AHKL_COMMAND        , CvtClr(0x0080C0))
        Sci[n].StyleSetFore(SCE_AHKL_PARAM          , CvtClr(0x0080C0))
        Sci[n].StyleSetFore(SCE_AHKL_CONTROLFLOW    , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_BUILTINFUNCTION, CvtClr(0x0F707F))
        Sci[n].StyleSetFore(SCE_AHKL_BUILTINVAR     , CvtClr(0x9F1F6F))
        Sci[n].StyleSetFore(SCE_AHKL_KEY            , CvtClr(0xA2A2A2))
        ;Sci[n].StyleSetFore(SCE_AHKL_USERDEFINED1   , CvtClr(0x000000))
        ;Sci[n].StyleSetFore(SCE_AHKL_USERDEFINED2   , CvtClr(0x000000))
        Sci[n].StyleSetFore(SCE_AHKL_ESCAPESEQ      , CvtClr(0x660000))
        ;Sci[n].StyleSetFore(SCE_AHKL_ERROR          , 0xFF0000)

        ; Keywords
        Sci[n].SetKeywords(0, Keywords.Directives, 2)
        Sci[n].SetKeywords(1, Keywords.Commands, 2)
        Sci[n].SetKeywords(2, Keywords.Parameters, 2)
        Sci[n].SetKeywords(3, Keywords.ControlFlow, 2)
        Sci[n].SetKeywords(4, Keywords.Functions, 2)
        Sci[n].SetKeywords(5, Keywords.BuiltinVariables, 2)
        Sci[n].SetKeywords(6, Keywords.Keys, 2)
        ;Sci[n].SetKeywords(7, Keywords.UserDefined1, 2)
        ;Sci[n].SetKeywords(8, Keywords.UserDefined2, 2)
    }
}

NewTab:
    NewTab()
Return

NewTab() {
    Static TabCounter := 1
    TabCounter++
    TabIndex := TabEx.GetCount() + 1
    Sci[TabIndex] := New Scintilla
    x := (DesignMode) ? 169 : 7
    Sci[TabIndex].Add(hAutoWnd, x, 60, 1576, 1420, SciLexer, 0x50010000, 0)
    SetScintilla(TabIndex)
    TabEx.SetIcon(TabEx.Add("Untitled " . TabCounter), 1)
    TabEx.SetSel(TabIndex)
    GoSub AutoSize
    Sci[TabIndex].Number := TabCounter ; Untitled number
    Return TabIndex
}

NewFromTemplate:
    n := TabEx.GetSel()
    If (n == g_GuiTab || Sci[n].GetModify() || Sci[n].FileName != "") {
        n := NewTab()    
    }
    
    Template := A_WinDir . "\ShellNew\Template.ahk"

    If (FileExist(Template) && !GetKeyState("Shift", "P")) {
        FileRead Template, %Template%
    } Else {
        Template := 
        (LTrim
            "#NoEnv
            #Warn
            #SingleInstance Force
            SetWorkingDir %A_ScriptDir%
            SendMode Input
            SetBatchLines -1"
        )
        Template .= CRLF
    }

    Sci[n].SetText("", Template . CRLF, 2)
    Sci[n].GoToPos(10000)
Return

DuplicateTab:
    n := TabEx.GetSel()
    nLen := Sci[n].GetText(Sci[n].GetLength() + 1, SciText)
    Sci[n].GetText(nLen + 1, SciText)
    Sci[NewTab()].SetText("", SciText, 2)
Return

CloseTab:
    CloseTab(TabEx.GetSel())
Return

CloseTabN:
    CloseTab(g_TabIndex)
Return

CloseTab(TabIndex) {
    If (Sci[TabIndex].GetModify()) {
        TabEx.SetSel(TabIndex)
        TabCaption := TabEx.GetText(TabIndex)
        Gui Auto: +OwnDialogs
        MsgBox 0x33, %TabCaption%, The file was modified. Do you want to save it?
        IfMsgBox Yes, {
            If (!Save()) {
                Return
            }
        } Else IfMsgBox Cancel, {
            Return
        }
    }

    If (TabIndex == g_GuiTab) {
        Gui %Child%: Destroy
        g_GuiTab := 0
        g_GuiSB := False
        SetStatusBar()
    }

    If (TabEx.GetCount() > 1) {
        SendMessage 0x1308, % TabIndex - 1, 0,, ahk_id %hTab% ; TCM_DELETEITEM
        DestroyWindow(Sci[TabIndex].hWnd)
        Sci.Remove(TabIndex)
        If (TabIndex > 1) {
            TabIndex -= 1    
        }
    } Else {
        ClearFile(1)
    }

    TabEx.SetSel(TabIndex)
}

ClearFile(n) {
    Sci[n].FullFileName := ""
    Sci[n].FileName := ""
    Sci[n].Modified := ""
    Sci[n].ClearAll()
    Sci[n].SetSavePoint()
    TabEx.SetIcon(n, 1)
}

ToggleReadOnly() {
    ToggleReadOnly:
    n := TabEx.GetSel()
    ReadOnly := !Sci[n].GetReadOnly()
    sci[n].SetReadOnly(ReadOnly)
    Menu AutoOptionsMenu, ToggleCheck, &Read Only
    SendMessage TB_CHECKBUTTON, 2170, ReadOnly,, ahk_id %hEditorTB%
    If (WinActive("ahk_id" . hAutoWnd)) {
        If (ReadOnly) {
            SB_SetText("Read only", 3)
        } Else {
            If (Sci[n].GetModify()) {
                SB_SetText("Modified", 3)
            } Else {
                SB_SetText("", 3)
            }
        }
    }
    Return
}

ToggleWordWrap() {
    n := TabEx.GetSel()
    WordWrap := !Sci[n].GetWrapMode()
    Sci[n].SetWrapMode(WordWrap)
    Menu AutoOptionsMenu, ToggleCheck, &Wrap Long Lines ; &Word Wrap
    SendMessage TB_CHECKBUTTON, 2160, WrapMode,, ahk_id %hEditorTB%
}

ToggleLineNumbers:
    LineNumbers := !LineNumbers

    Loop % Sci.MaxIndex() {
        SetLineNumberWidth(A_Index)
    }

    Menu AutoOptionsMenu, ToggleCheck, &Line Numbering
Return

ToggleSyntaxHighlighting:
    SyntaxHighlighting := !SyntaxHighlighting

    If (SyntaxHighlighting) {
        Loop % Sci.Length() {
            SciSetStyle(A_Index, Sci.FontName, Sci.FontSize)
        }
    } Else {
        Loop % Sci.Length() {
            Sci[A_Index].StyleClearAll()
            Sci[A_Index].StyleSetFore(33, CvtClr(0xCFD2CA)) ; Margin foreground color
            Sci[A_Index].StyleSetBack(33, CvtClr(0xFFFFFF)) ; Margin background color
        }
    }

    Menu AutoOptionsMenu, ToggleCheck, Syntax &Highlighting
    SendMessage TB_CHECKBUTTON, 2180, %SyntaxHighlighting%,, ahk_id %hEditorTB%
Return

ToggleAutoComplete:
    g_AutoCEnabled := !g_AutoCEnabled
    Menu AutoOptionsMenu, ToggleCheck, &Code Completion ; &Autocompletion
Return

ToggleCalltips:
    g_Calltips := !g_Calltips
    Menu AutoOptionsMenu, ToggleCheck, Code &ToolTips ; &Calltips
Return

ToggleAutoBrackets:
    AutoBrackets := !AutoBrackets
    Menu AutoOptionsMenu, ToggleCheck, Autoclose &Brackets
Return

Undo:
    Sci[TabEx.GetSel()].Undo()
Return

Redo:
    Sci[TabEx.GetSel()].Redo()
Return

Cut:
    Sci[TabEx.GetSel()].Cut()
Return

Copy:
    Sci[TabEx.GetSel()].Copy()
Return

Paste:
    Sci[TabEx.GetSel()].Paste()
Return

Clear:
    Sci[TabEx.GetSel()].Clear()
Return

SelectAll:
    Sci[TabEx.GetSel()].SelectAll()
Return

Lowercase:
    Sci[TabEx.GetSel()].LowerCase()
Return

Uppercase:
    Sci[TabEx.GetSel()].UpperCase()
Return

TitleCase:
    n := TabEx.GetSel()
    Start := Sci[n].GetSelectionStart()
    End := Sci[n].GetSelectionEnd()
    Sci[n].GetTextRange([Start, End], Selection)
    StringUpper Selection, Selection, T
    Sci[n].ReplaceSel("", Selection, 2)
    Sci[n].SetSel(Start, End)
Return

OnWM_NOTIFY(wParam, lParam, msg, hWnd, obj) {
    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()

    If (obj.SCNCode == SCN_UPDATEUI) {
        ; The updated field is set to the bit set of things changed since the previous notification.
        ; SC_UPDATE_CONTENT 	0x01 	Contents, styling or markers have been changed.
        ; SC_UPDATE_SELECTION 	0x02 	Selection has been changed.
        ; SC_UPDATE_V_SCROLL 	0x04 	Scrolled vertically.
        ; SC_UPDATE_H_SCROLL 	0x08 	Scrolled horizontally.

        If (obj.updated < 4 && g_HighlightIdenticalText) {
            Sci[n].SetIndicatorCurrent(2)
            Sci[n].IndicatorClearRange(0, Sci[n].GetLength())

            WordStartPos := Sci[n].WordStartPosition(caretPos, True)
            WordEndPos := Sci[n].WordEndPosition(caretPos, True)
            SelStart := Sci[n].GetSelectionStart()
            SelEnd := Sci[n].GetSelectionEnd()
            If (SelStart != SelEnd && WordStartPos == SelStart && WordEndPos == SelEnd) {
                HighlightIdenticalText(GetSelectedText())
            }
        }
        ; Brace Matching
        ; Has the caret changed position?
        If (lastCaretPos != caretPos) {
            lastCaretPos := caretPos
            bracePos1 := -1
            bracePos2 := -1
        }
            ; Is there a brace to the left or right?
            If (caretPos > 0 && IsBrace(Sci[n].GetCharAt(caretPos - 1)))
            {
                bracePos1 := (caretPos -1)
            }
            Else If (IsBrace(Sci[n].GetCharAt(caretPos)))
                bracePos1 := caretPos

            If (bracePos1 >= 0) {
                ; Find the matching brace
                bracePos2 := Sci[n].BraceMatch(bracePos1)
                If (bracePos2 = Invalid_Position)
                    Sci[n].BraceBadLight(bracePos1)
                Else
                    Sci[n].BraceHighlight(bracePos1, bracePos2)
            }
            Else {
                ; Turn off brace matching
                Sci[n].BraceHighlight(Invalid_Position, 999999999)
            }

        ; bm := Sci[n].BraceMatch(caretPos - 1, 0)

        ; If (bm != -1) {
        ;     Sci[n].BraceHighlight(caretPos - 1, bm)
        ; } Else {
        ;     Sci[n].BraceHighlight(-1, Sci[n].GetLength())
        ; }

        UpdateStatusBar()

    } Else If (obj.SCNCode == SCN_MODIFIED) {

        UpdateStatusBar()
        SetLineNumberWidth(n)

    } Else If (obj.SCNCode == SCN_SAVEPOINTREACHED) {

        SetDocumentStatus(n)

    } Else If (obj.SCNCode == SCN_SAVEPOINTLEFT) {

        SetDocumentStatus(n)

    } Else If (obj.SCNCode == SCN_CHARADDED) {

        If (g_AutoCEnabled) {
            AutoComplete(g_AutoCMinLength)
        }

        If (g_Calltips && (obj.ch == 40 || obj.ch == 44 || obj.ch == 32)) {
            WordPos := GetCurrentWord(Word, caretPos - 1)
            Calltip := GetCalltip(Word)
            If (Word != "If") {
                ShowCalltip(n, Calltip, WordPos[1])
            }
        }

        If (!AutoBrackets) {
            Return
        }

        PrevChar := Sci[n].GetCharAt(caretPos - 2)
        NextChar := Sci[n].GetCharAt(caretPos)

        ; Autoclose brackets ([{""}])
        If (obj.ch == 40 && NextChar != 41) { ; Parenthesis
            Sci[n].InsertText(caretPos, ")", 2)
        } Else If (obj.ch == 91 && NextChar != 93) { ; Brackets
            Sci[n].InsertText(caretPos, "]", 2)
        } Else If (obj.ch == 123 && NextChar != 125) { ; Braces
            Sci[n].GetTextRange([caretPos - 5, caretPos], PrevChars)
            If (RegExMatch(PrevChars, "\(\)\s?\n?")) {
                Sci[n].InsertText(caretPos, CRLF . Indent . CRLF . "}", 2)
                Sci[n].GoToPos(caretPos + 2 + TabSize)
            } Else {
                Sci[n].InsertText(caretPos, "}", 2)
            }
        } Else If (obj.ch == 34  ; Quotes
            && (NextChar == 0
            || NextChar == 9     ; Tab
            || NextChar == 32    ; Space
            || NextChar == 33    ; Exclamation mark
            || NextChar == 41    ; Close parenthesis
            || NextChar == 44    ; Comma
            || NextChar == 46    ; Period
            || NextChar == 58    ; Colon
            || NextChar == 59    ; Semicolon
            || NextChar == 63    ; Question mark
            || NextChar == 93    ; Right bracket
            || NextChar == 125)  ; Right brace
            && (PrevChar == 0
            || PrevChar == 9
            || PrevChar == 10    ; New line
            || PrevChar == 32
            || PrevChar == 40    ; Open parenthesis
            || PrevChar == 91    ; Left bracket
            || PrevChar == 123)) ; Left brace
        {
            Sci[n].InsertText(caretPos, """", 2)
        }
    } Else If (obj.SCNCode == SCN_AUTOCCOMPLETED) {

        Keyword := StrGet(obj.Text,, "UTF-8")

        If (g_AutoCWin32Const) {
            ConstValue := LookupConstant(Keyword)
            Sci[n].InsertText(caretPos, " := " . ConstValue, 2)
            Sci[n].GoToPos(caretPos + StrLen(" := " . ConstValue))
            g_AutoCWin32Const := False
        } Else {
            If (g_Calltips && Keyword != "GuiClose") {
                CallTip := GetCallTip(Keyword, True)
                ShowCalltip(n, CallTip, GetWordPos()[1])
            }
        }

    } Else If (obj.SCNCode == SCN_AUTOCCANCELLED) {

        g_AutoCWin32Const := False

    } Else If (obj.SCNCode == SCN_DWELLSTART) {

        If (g_Calltips) {
            If (obj.position != -1) {
                WordPos := GetCurrentWord(Word, obj.position)
                ShowCalltip(n, GetCalltip(Word, False), WordPos[1])
            }
        }

    } Else If (obj.SCNCode == SCN_DWELLEND) {

        Sci[n].CalltipCancel()

    } Else If (obj.SCNCode == SCN_CALLTIPCLICK) {

        ; The position field is set to 1 if the click is in an up arrow, 2 if in a down arrow, and 0 if elsewhere.
        If (obj.position == 0) {
            InsertCalltip()
            Return
        } Else If (obj.position == 1) {
            g_CalltipParamsIndex--
        } Else {
            g_CalltipParamsIndex++
        }

        If ((obj.position == 1 && g_CalltipParamsIndex > 1) 
        || (g_CalltipParams.Length() == g_CalltipParamsIndex)) {
            Arrow := 1 ; Up arrow
        } Else {
            Arrow := 2 ; Down arrow
        }

        WordStartPos := Sci[n].WordStartPosition(caretPos - 1, True)

        Sci[n].CalltipShow(WordStartPos, Chr(Arrow) . g_CalltipParams[g_CalltipParamsIndex], 2)

    } Else If (obj.SCNCode == SCN_ZOOM) {
        Sci[n].MarginLen := 0
        SetLineNumberWidth(n)
    }

    Return
}

ShowGoToLineDialog:
    Line := InputBoxEx("Line Number:", "", "Go to Line", "", "", "x94 w80 Number", 270,,, hAutoWnd, "", "") - 1
    If (!ErrorLevel) {
        ShowChildWindow(0)

        n := TabEx.GetSel()
        Sci[n].GrabFocus()
        Sci[n].GoToLine(Line) ; 0-based index

        LineCount := Sci[n].GetLineCount()
        VisCenterLine := Sci[n].LinesOnScreen() // 2
    
        If (VisCenterLine < (LineCount - Line)) {
            Sci[n].VerticalCentreCaret()
        } Else {
            Sci[n].ScrolltoEnd()
        }
    }
Return

ChangeEditorFont:
    FontName := Sci.FontName
    FontSize := Sci.FontSize
    If (ChooseFont(FontName, FontSize, "", "0x000000", 0, hAutoWnd)) {
        Loop % Sci.MaxIndex() {
            Sci[A_Index].MarginLen := 0
            SciSetStyle(A_Index, FontName, FontSize)
            ;Sci[A_Index].StyleSetFont(STYLE_DEFAULT, FontName, 2)
            ;Sci[A_Index].StyleSetSize(STYLE_DEFAULT, FontSize)
        }
        Sci.FontName := FontName
        Sci.FontSize := FontSize
    }
Return

ZoomIn:
    Sci[TabEx.GetSel()].ZoomIn()
Return

ZoomOut:
    Sci[TabEx.GetSel()].ZoomOut()
Return

ResetFontSize:
    Sci[TabEx.GetSel()].SetZoom(0)
Return

; Called from SCN_UPDATEUI, SCN_MODIFIED, TabHandler and SetStatusBar
UpdateStatusBar() {
    If (!g_GuiSB) {
        n := TabEx.GetSel()
        caretPos := Sci[n].GetCurrentPos()
        Line := Sci[n].LineFromPosition(caretPos) + 1
        Column := Sci[n].GetColumn(caretPos) + 1

        Gui Auto: Default
        SB_SetText(Line . ":" . Column, 2)

        If (Sci[n].GetReadOnly()) {
            SB_SetText("Read only", 3)
        } Else If (Sci[n].GetModify()) {
            SB_SetText("Modified", 3)
        } Else {
            SB_SetText("", 3)
        }
    }
}

; Called from SCN_SAVEPOINTREACHED, SCN_SAVEPOINTLEFT and NewWindow
SetDocumentStatus(n) {
    Gui Auto: Default
    n := TabEx.GetSel()

    If (Sci[n].GetReadOnly()) {
        If (!g_GuiSB) {
            SB_SetText("Read only", 3)
        }
    } Else If (Sci[n].GetModify()) {
        GuiControl -Redraw, %hTab%
        GuiControl Disable, %hTab%
        TabCaption := (Sci[n].FileName != "") ? Sci[n].FileName . " *" : "Untitled " . Sci[n].Number . " *"
        TabEx.SetText(n, TabCaption)
        GuiControl +Redraw, %hTab%
        GuiControl Enable, %hTab%

        If (!g_GuiSB) {
            SB_SetText("Modified", 3)
        }
    } Else {
        GuiControl -Redraw, %hTab%
        GuiControl Disable, %hTab%
        TabCaption := (Sci[n].FileName != "") ? Sci[n].FileName : "Untitled " . Sci[n].Number
        TabEx.SetText(n, TabCaption)
        GuiControl +Redraw, %hTab%
        GuiControl Enable, %hTab%

        If (!g_GuiSB) {
            SB_SetText("", 3)
        }
    }
}

InsertDateTime:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    FormatTime TimeString, D1    
    Sci[n].InsertText(CurrentPos, "" . TimeString, 2)
    Sci[n].GoToPos(CurrentPos + StrPut(TimeString, "UTF-8") - 1)
Return

; Show spaces, tabs and line breaks
ToggleSymbols:
    g_ShowSymbols := !g_ShowSymbols

    Loop % Sci.MaxIndex() {
        Sci[A_Index].2086(g_ShowSymbols ? 2 : 0) ; SCI_SETWHITESPACESIZE
        Sci[A_Index].SetViewWS(g_ShowSymbols)
        Sci[A_Index].SetViewEOL(g_ShowSymbols)
    }

    Menu AutoOptionsMenu, % g_ShowSymbols ? "Check" : "Uncheck", &Show Whitespaces
Return

ToggleComment:
    n := TabEx.GetSel()
    SelText := GetSelectedText()

    If (SelText == "") {
        SelText := GetCurrentLine()
        CurrPos := Sci[n].GetCurrentPos()
        LineNum := Sci[n].LineFromPosition(CurrPos)
        StartPos := Sci[n].PositionFromLine(LineNum) ; Start of the line
        EndPos := Sci[n].GetLineEndPosition(LineNum)
        Sci[n].SetSel(StartPos, EndPos) ; Select current line
        RestorePos := True ; Restore caret position
    } Else {
        RestorePos := False
    }

    Lines := ""
    Loop Parse, SelText, `n, `r
    {
        If (RegExMatch(A_LoopField, "^\s*\;")) {
            Line := RegExReplace(A_LoopField, "\;", "", "", 1)
        } Else If (A_LoopField == "") {
            Line := ""
        } Else {
            Line := ";" . A_LoopField
        }
        Lines .= Line . CRLF
    }

    Lines := RegExReplace(Lines, "`r`n$", "", "", 1)
    SetSelectedText(Lines)

    If (RestorePos) {
        Sci[n].GoToPos(CurrPos)
    }
Return

GetCurrentLine() {
    n := TabEx.GetSel()
    LineNum := Sci[n].LineFromPosition(Sci[n].GetCurrentPos())
    LineLen := Sci[n].LineLength(LineNum)
	VarSetCapacity(LineText, LineLen, 0)
    Sci[n].GetCurLine(LineLen + 1, LineText)
    Sci[n].GetCurLine(LineLen + 1, LineText)
    Return RTrim(LineText, CRLF)
}

DuplicateLine:
    Sci[TabEx.GetSel()].LineDuplicate()
Return

TransposeLine:
    Sci[TabEx.GetSel()].LineTranspose()    
Return

LoadXML(FileName) {
    Static x
    x := ComObjCreate("MSXML2.DOMDocument.6.0")
    x.async := False
    x.load(FileName)
    Return x
}

LoadAutoComplete(FileName) {
    Static XMLLoaded := False

    If (!XMLLoaded) {
        g_AutoCXMLObj := LoadXML(FileName)

        Keys := g_AutoCXMLObj.getElementsByTagName("key")
        For Key in Keys {
        	g_AutoCList .= key.getAttribute("name") . " "
        }

        g_AutoCList := RTrim(g_AutoCList, " ")

        XMLLoaded := True
    }
}

AutoComplete(MinLength := 3, Filter := "") {
    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()    

    WordStartPos := Sci[n].WordStartPosition(caretPos, True)
    LengthEntered := caretPos - WordStartPos
    WordFirstChar := Sci[n].GetCharAt(WordStartPos - 1)

    If (WordFirstChar == 35 || WordFirstChar == 46) { ; # .
        LengthEntered++
    }

    If ((LengthEntered >= MinLength) && !Sci[n].AutoCActive()) {
        Sci[n].AutoCShow(LengthEntered, "" . g_AutoCList, 2)
    }
}

AutoCompleteWin32() {
    Static Items

    If (!IsObject(g_AutoCWin32XMLObj)) {
        g_AutoCWin32XMLObj := LoadXML(A_ScriptDir . "\Tools\Windows.xml")
        Items := g_AutoCWin32XMLObj.getElementsByTagName("item")
    }

    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()
    WordStartPos := Sci[n].WordStartPosition(caretPos, True)
    LengthEntered := caretPos - WordStartPos
    Sci[n].GetTextRange([WordStartPos, caretPos], TempText)

    ConstList := ""
    For Item in Items {
        Const := Item.getAttribute("const")
        If (InStr(Const, TempText) == 1) {
            ConstList .= Const . " "
        }
    }

    If ((LengthEntered >= 0) && !Sci[n].AutoCActive()) {
        Sci[n].AutoCShow(LengthEntered, RTrim(ConstList), 2)
    }

    If (Sci[n].AutoCActive()) {
        g_AutoCWin32Const := True    
    }
}

GetCallTip(Keyword, Overload := True) {
    RegExMatch(" " . g_AutoCList . " ", "i) " . Keyword . " ", Keyword)
    Keyword := Trim(Keyword)
    Node := g_AutoCXMLObj.selectSingleNode("//key[@name=""" . Keyword . """]")
/*
    If (Keyword == "Hotkey" || Keyword == "Progress") {
        VarSetCapacity(LineText, 100)
        Sci[TabEx.GetSel()].GetCurLine(100, LineText)
        If (RegExMatch(LineText, "i)\s*Gui")) {
            Return
        }
    }
*/
    Params := Node.selectNodes("params")
    g_CalltipParams := []
    Loop % Params.length {
        Calltip := Params.item(A_Index - 1).text
        Separator := (SubStr(Calltip, 1, 1) != "(") ? " " : ""
        g_CalltipParams.Push(Keyword . Separator . Calltip)
    }

    If (Params.item(0).text != "") {
        Return (Overload && Params.length > 1) ? Chr(2) . g_CalltipParams[1] : g_CalltipParams[1]
    }
}

ShowCalltip(n, Calltip, StartPos) {
    If (CallTip != "") {
        Sci[n].CalltipShow(StartPos, CallTip, 2)
        Return g_CalltipParamsIndex := 1
    }
}

InsertCalltip() {
    n := TabEx.GetSel()
    If (Sci[n].AutoCActive()) {
        Sci[n].AutoCComplete()
    }
    
    EndPos := GetCurrentWord(Word)[2]
    GetCalltip(Word, False)
    Calltip := StrReplace(g_CalltipParams[g_CalltipParamsIndex], Word,,, 1)
    
    NextChar := Chr(Sci[n].GetCharAt(EndPos))
    If (NextChar == " " || NextChar == ",") {
        Sci[n].2645(EndPos, 1) ; SCI_DELETERANGE
    }
    
    Sci[n].InsertText(EndPos, Calltip, 2)
    Sci[n].WordRight()
    Sci[n].CalltipCancel()
}

GetCurrentWord(ByRef Word, Pos := -1) {
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    PrevChar := Chr(Sci[n].GetCharAt(CurrentPos - 1))
    If (PrevChar == " " || PrevChar == ",") {
        CurrentPos--
    }
    CurrentPos := (Pos == -1) ? CurrentPos : Pos
    WordStartPos := Sci[n].WordStartPosition(CurrentPos, True)
    PrevChar := Chr(Sci[n].GetCharAt(WordStartPos - 1))
    If (PrevChar == "#" || PrevChar == ".") {
        WordStartPos--
    }
    WordEndPos := Sci[n].WordEndPosition(CurrentPos, True)
    Sci[n].GetTextRange([WordStartPos, WordEndPos], Word)
    Return [WordStartPos, WordEndPos]
}

GetSelectedText() {
    n := TabEx.GetSel()
    Start := Sci[n].GetSelectionStart()
    End := Sci[n].GetSelectionEnd()
    Sci[n].GetTextRange([Start, End], SelText)
    Return SelText
}

SetSelectedText(Text) {
    Sci[TabEx.GetSel()].ReplaceSel("", Text, 2)
}

; SCI_WORDSTARTPOSITION(int pos, bool onlyWordCharacters) → int
GetWordPos() {
    n := TabEx.GetSel()
    Pos := Sci[n].GetCurrentPos()
    WordStartPos := Sci[n].WordStartPosition(Pos, True)
    PrevChar := Chr(Sci[n].GetCharAt(WordStartPos - 1))
    If (PrevChar == "#" || PrevChar == ".") {
        WordStartPos--
    }
    WordEndPos := Sci[n].WordEndPosition(Pos, True)
    Return [WordStartPos, WordEndPos]
}

MarkSelectedText:
    n := TabEx.GetSel()
    Sci[n].SetIndicatorCurrent(1)

    SelStart := Sci[n].GetSelectionStart()
    SelEnd := Sci[n].GetSelectionEnd()

    ; Unmark if marked
    If ((Sci[n].IndicatorAllOnFor(SelStart) & 2) == 2) {
        Sci[n].IndicatorClearRange(SelStart, SelEnd - SelStart)
        Return
    }

    Sci[n].IndicSetStyle(1, INDIC_ROUNDBOX)
    Sci[n].IndicSetFore(1, CvtClr(0x3FBBE3))
    Sci[n].IndicSetOutlineAlpha(1, 255) ; Opaque border
    Sci[n].IndicSetAlpha(1, 80)
    Sci[n].IndicatorFillRange(SelStart, SelEnd - SelStart)
    Sci[n].SetSel(-1, Sci[n].GetCurrentPos())
Return

ClearAllMarks:
    n := TabEx.GetSel()
    Sci[n].SetIndicatorCurrent(1)
    Sci[n].IndicatorClearRange(0, Sci[n].GetLength())
Return

GoToNextMark:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    Marks := GetMarks()

    LineCount := Sci[n].GetLineCount()
    VisCenterLine := Sci[n].LinesOnScreen() // 2

    Loop % Marks.Length() {
        If (Marks[A_Index] > CurrentPos) {
            Sci[n].GoToPos(Marks[A_Index])

            MarkLine := Sci[n].LineFromPosition(Marks[A_Index])

            If (VisCenterLine < (LineCount - MarkLine)) {
                Sci[n].VerticalCentreCaret()
            } Else {
                Sci[n].ScrolltoEnd()
            }

            Break
        }
    }
Return

GoToPreviousMark:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    Marks := GetMarks()
    Max := Marks.Length()

    Loop %Max% {
        Index := Max - A_Index + 1
        If (Marks[Index] < CurrentPos) {
            Sci[n].GoToPos(Marks[Index])
            Sci[n].VerticalCentreCaret()
            Break
        }
    }
Return

; SCI_INDICATORALLONFOR: Retrieve a bitmap value representing which indicators are non-zero at a position.
GetMarks() {
    n := TabEx.GetSel()
    StartPos := 0
    EndPos := 0
    Max := Sci[n].GetLength()
    Marks := []

    Loop {
        StartPos := Sci[n].IndicatorStart(1, EndPos)
        EndPos := Sci[n].IndicatorEnd(1, StartPos)

        If ((Sci[n].IndicatorAllOnFor(StartPos) & 2) == 2) {
            Marks.Push(EndPos)
        }
    } Until !(EndPos != 0 && EndPos < Max)

    Return Marks
}

ToggleHighlightActiveLine:
    g_HighlightActiveLine := !g_HighlightActiveLine

    ActiveLineColor := g_HighlightActiveLine ? 0xD8F3FF : 0xFFFFFF
    Loop % Sci.MaxIndex() {
        Sci[A_Index].SetCaretLineBack(CvtClr(ActiveLineColor))
    }

    Menu AutoOptionsMenu, % g_HighlightActiveLine ? "Check" : "Uncheck", Highlight &Active Line
Return

ToggleIndentGuides:
    g_IndentGuides := !g_IndentGuides

    IndentView := g_IndentGuides ? 3 : 0 ; 3 = SC_IV_LOOKBOTH

    Loop % Sci.MaxIndex() {
        Sci[A_Index].SetIndentationGuides(IndentView)
    }

    Menu AutoOptionsMenu, ToggleCheck, &Indentation Guides
Return

SetLineNumberWidth(n) {
    If (LineNumbers) {
        LineCount := Sci[n].GetLineCount()
        LineCountLen := StrLen(LineCount)
        If (LineCountLen < 2) {
            LineCountLen := 2
        }

        If (LineCountLen != Sci[n].MarginLen) {
            Sci[n].MarginLen := LineCountLen
    
            If (LineCount < 100) {
                String := "99"
            } Else {
                String := ""
                LineCountLen := StrLen(LineCount)
                Loop %LineCountLen% {
                    String .= "9"
                }
            }

            PixelWidth := Sci[n].TextWidth(STYLE_LINENUMBER, "" . String, 2) + 6
            Sci[n].SetMarginWidthN(0, PixelWidth)
        }
    } Else {
        Sci[n].SetMarginWidthN(0, 0)
        Sci[n].MarginLen := 0
    }
}

HighlightIdenticalText(String) {
    n := TabEx.GetSel()
    SelEnd := Sci[n].GetSelectionEnd()

    Sci[n].SetIndicatorCurrent(2)
    Sci[n].IndicSetStyle(2, 8) ; INDIC_STRAIGHTBOX
    Sci[n].IndicSetFore(2, CvtClr(0x3FBBE3))
    Sci[n].IndicSetOutlineAlpha(2, 80) ; Opaque border
    Sci[n].IndicSetAlpha(2, 80)

    TextLength := Sci[n].GetLength()
    Sci[n].SetTargetStart(0)
    Sci[n].SetTargetEnd(TextLength)
    StringLength := StrPut(String, "UTF-8") - 1

    While (Sci[n].SearchInTarget(StringLength, "" . String, 2) != -1) {
        TargetStart := Sci[n].GetTargetStart()
        TargetEnd := Sci[n].GetTargetEnd()
        If (TargetEnd != SelEnd) {
            Sci[n].IndicatorFillRange(TargetStart, TargetEnd - TargetStart)
        }

        Sci[n].SetTargetStart(TargetEnd)
        Sci[n].SetTargetEnd(TextLength)
    }
}

ToggleHighlightIdenticalText:
    g_HighlightIdenticalText := !g_HighlightIdenticalText
    Sci[n].SetIndicatorCurrent(2)
    Sci[n].IndicatorClearRange(0, Sci[n].GetLength())
    Menu AutoOptionsMenu, ToggleCheck, Highlight Identical Te&xt
Return

guest3456
Posts: 3453
Joined: 09 Oct 2013, 10:31

Re: AutoGUI - GUI Designer and Script Editor

18 Feb 2017, 12:01

Rorqual wrote: but the dllcall in Scintilla.ahk could not handle a negative integer value of -1 (which is the value of Invalid_Position). I believe the dllcall was from Pulover's Macro Creator, and I'm not sure why it doesn't handle negative ints. It even has a comment that says it DOES handle negative ints, but it doesn't. Perhaps someone else can tell us?

Here is the dllcall code:

Code: Select all

    ; The fast way to control Scintilla
    return DllCall(%hwnd%_df            ; DIRECT FUNCTION
                  ,"UInt" ,%hwnd%_dp    ; DIRECT POINTER
                  ,"UInt" ,!(msg+0) ? %msg% : msg
                  ,"Int"  ,inStr(wParam, "-") ? wParam : (%wParam%+0 ? %wParam% : wParam) ; handles negative ints
                  ,"Int"  ,%lParam%+0 ? %lParam% : lParam)
}
that DllCall code doesn't look right

doing %wParam% (and for lParam) does a double-dereference within an expression

so i have no idea why those ternaries are in there...

may also want to let Pulover know

Rorqual
Posts: 10
Joined: 14 Jan 2017, 13:23

Re: AutoGUI - GUI Designer and Script Editor

18 Feb 2017, 12:12

Fixed the dllcall, so that the lparam now handles negative ints too, the issue was that only the wparam did before - looks like Pulover was lazy in only implementing the one he needed at the time to handle negative ints :)
below are the two modified files

the DllCall is still ugly, I'm sure, as guest pointed out, it doesn't need all the %'s, but I don't want to risk screwing it up.

New functionality:
1) braces which don't have a matching brace are correctly highlighted to show they are broken/no match found, they are colored red.
Image
2) indentation guides, when enabled, also share the same highlighting as the matched braces, image below
Image

Code: Select all

; Title: Scintilla Wrapper for AHK

class scintilla {
    hwnd            := 0        ; Component Handle
    notify          := ""       ; Name of the function that will handle the window messages sent by the control

                                ; Messages which set this variables.
                                ; ---------------------------------------------------------------------------------------------------------------
    idFrom          := 0        ; The handle from which the notification was sent
    scnCode         := 0        ; The SCN_* notification code
    position        := 0        ; SCN_STYLENEEDED, SCN_DOUBLECLICK, SCN_MODIFIED, SCN_MARGINCLICK
                                ; SCN_NEEDSHOWN, SCN_DWELLSTART, SCN_DWELLEND, SCN_CALLTIPCLICK
                                ; SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK, SCN_HOTSPOTRELEASECLICK
                                ; SCN_INDICATORCLICK, SCN_INDICATORRELEASE
                                ; SCN_USERLISTSELECTION, SCN_AUTOCSELECTION

    ch              := 0        ; SCN_CHARADDED, SCN_KEY
    modifiers       := 0        ; SCN_KEY, SCN_DOUBLECLICK, SCN_HOTSPOTCLICK, SCN_HOTSPOTDOUBLECLICK
                                ; SCN_HOTSPOTRELEASECLICK, SCN_INDICATORCLICK, SCN_INDICATORRELEASE

    modType         := 0        ; SCN_MODIFIED
    text            := 0        ; SCN_MODIFIED, SCN_USERLISTSELECTION, SCN_AUTOCSELECTION, SCN_URIDROPPED
    length          := 0        ; SCN_MODIFIED
    linesAdded      := 0        ; SCN_MODIFIED
    macMessage      := 0        ; SCN_MACRORECORD
    macwParam       := 0        ; SCN_MACRORECORD
    maclParam       := 0        ; SCN_MACRORECORD
    line            := 0        ; SCN_MODIFIED
    foldLevelNow    := 0        ; SCN_MODIFIED
    foldLevelPrev   := 0        ; SCN_MODIFIED
    margin          := 0        ; SCN_MARGINCLICK
    listType        := 0        ; SCN_USERLISTSELECTION
    x               := 0        ; SCN_DWELLSTART, SCN_DWELLEND
    y               := 0        ; SCN_DWELLSTART, SCN_DWELLEND
    token           := 0        ; SCN_MODIFIED with SC_MOD_CONTAINER
    annotLinesAdded := 0        ; SCN_MODIFIED with SC_MOD_CHANGEANNOTATION
    updated         := false    ; SCN_UPDATEUI

    __new(params*) {
        If (params.MaxIndex()) {
            __SCI(this.hwnd := __Add(params*), this)
        } Else {
            Return this
        }
    }

    __call(msg, ByRef wParam := 0, ByRef lParam := 0, params*) {

        If (msg = "Add") {
            __SCI(this.hwnd := __Add(wParam, lParam, params*), this)
        } Else {
            If (wParam && !(wParam+0) && !isObject(wParam)) {
                VarSetCapacity(wParamA, StrPut(wParam, "UTF-8"))
                StrPut(wParam, &wParamA, "UTF-8")
                wParam := &wParamA
            }

            If (Params[1] == 2) {
                VarSetCapacity(lParamA, StrPut(lParam, "UTF-8"))
                StrPut(lParam, &lParamA, "UTF-8")
                lParam := &lParamA
            }

            /*
              Special Operations
              Due to the fact that some functions require the user to manually prepare bufferst to store text
              I decided to make most of those operations internally to have cleaner code later on.
            */

            (msg = "GetText") ? (VarSetCapacity(lParam, wParam * (a_isunicode ? 2 : 1)+8), lParam := &lParam, buf:=true) : null
            (msg = "GetLine") ? (VarSetCapacity(lParam, this.linelength(wParam)+1 * (a_isunicode ? 2 : 1)),lParam := &lParam, buf:=true) : null
	    (msg = "GetCurLine") ? (VarSetCapacity(lParam, this.linelength(wParam)+1 * (a_isunicode ? 2 : 1)), lParam := &lParam, buf:=true) : null
            (msg = "GetTextRange") ? (range:=abs(wParam.1 - wParam.2)+1, dSize :=  __sendEditor(this.hwnd, "GetLength")
                                     ,VarSetCapacity(lParam, range > dSize ? (dSize, wParam.2 := dSize) : range)
                                     ,VarSetCapacity(textRange, 12, 0)
                                     ,NumPut(wParam.1,textRange,0,"UInt")
                                     ,NumPut(wParam.2,textRange,4,"UInt")
                                     ,NumPut(&lParam,textRange,8,"UInt")
                                     ,blParam := &lParam, wParam := false,lParam := &textRange, buf:=true) : null

            res := __sendEditor(this.hwnd, msg, wParam, lParam)

            ; Retrieve Text from buffer
            ; I must switch lParam to another variable when using GetTextRange because lParam cant be overwriten
            ; It has the pointer to the TextRange Structure
            buf ? (lParam := StrGet((msg = "GetTextRange") ? blParam : &lParam, "UTF-8"), buf:=false) : null ; convert the text from ANSI
            return res
        }
    }
}

class sciCharRange {
    __new(_cMin := 0, _cMax := 0){
        this.cMin := _cMin
        this.cMax := _cMax
    }
}

class sciTextRange {
    __new(_chrg := 0, _pStr := 0) {
        If (!IsObject(_chrg)) {
            Msgbox % 0x0
                   , % "sciTextRange Object Error"
                   , % "The first parameter must match a sciCharRange object"
            Exit
        }

        this.chrg := _chrg ? _chrg : new sciCharRange
        this.pStr := _pStr
    }
}

class sciTextToFind {
    __new(_chrg=0, _text="", _found=0) {
        if (!isObject(_chrg) || !isObject(_found)) {
            Msgbox % 0x0
                   , % "sciTextToFind Object Error"
                   , % "The first and last parameters must match a sciCharRange object"
            Exit
        }

        this.chrg   := _chrg ? _chrg : new sciCharRange
        this.text   := _text
        this.found  := _found ? _found : new sciCharRange
    }
}

class sciRectangle {
    __new(_left=0, _top=0, _right=0, _bottom=0) {

        this.left    := _left
        this.top     := _top
        this.right   := _right
        this.bottom  := _bottom
    }
}

class sciRangeToFormat {
    __new(_hdc=0, _hdcTarget=0, _rc=0, _rcPage=0, _chrg=0) {
        this.hdc         := _hdc                                        ; The Surface ID we print to
        this.hdcTarget   := _hdcTarget                                  ; The Surface ID we use for measuring (may be same as hdc)
        this.rc          := _rc ? _rc : new sciRectangle                ; Rectangle in which to print
        this.rcPage      := _rcPage ? _rcPage : new sciRectangle        ; Physically printable page size
        this.chrg        := _chrg ? _chrg : new sciCharRange            ; Range of characters to print
    }
}

; | Internal Functions |

/*
    Function: __Add
    Creates a Scintilla component and adds it to the Parent GUI.

    This function initializes the Scintilla Component.
    See <http://www.scintilla.org/Steps.html> for more information on how to add the component to a GUI/Control.

    Parameters:
    __Add(hParent, [x, y, w, h, DllPath, Styles])

    hParent     -   Hwnd of the parent control who will host the Scintilla Component
    x           -   x position for the control (default 5)
    y           -   y position for the control (default 5)
    w           -   Width of the control (default 590)
    h           -   Height of the control (default 390)
    DllPath     -   Path to the SciLexer.dll file, if omitted the function looks for it in *a_scriptdir*.
    Styles      -   List of window style variable names separated by spaces.
                    The WS_ prefix for the variables is optional.
                    Full list of Style names can be found at
                    <http://msdn.microsoft.com/en-us/library/czada357.aspx>.

    Returns:
    HWND        -   Component handle.

    Examples:
    (start code)
    #include ..\SCI.ahk
    #singleinstance force

    ;---------------------
    ; This script adds a component with default values.
    ; If no path was specified when creating the object it expects scilexer.dll to be on the script's location.
    ; The default values are calculated to fit optimally on a 600x400 GUI/Control

    Gui +LastFound
    sci := new scintilla(WinExist())

    Gui, show, w600 h400
    return

    GuiClose:
        exitapp

    ;---------------------
    #include ..\SCI.ahk
    #singleinstance force

    ; Add multiple components.

    Gui +LastFound
    hwnd:=WinExist()

    sci1 := new scintilla(hwnd, 0, 0, 590, 190) ; you can put the parameters here
    sci2 := new scintilla

    sci2.add(hwnd, 0, 200, 590, 190) ; or you can use the add function like this

    Gui, show, w600 h400
    return

    GuiClose:
        exitapp

    ;---------------------
    #include ..\SCI.ahk
    #singleinstance force

    ; Here we add a component embedded in a tab.
    ; If the variables "x,w,h" are empty the default values are used.

    Gui, add, Tab2, HWNDhwndtab x0 y0 w600 h420 gtabHandler vtabLast,one|two

    sci := new scintilla
    sci.Add(hwndtab, x, 25, w, h, a_scriptdir "\scilexer.dll")

    Gui, show, w600 h420
    return

    ; This additional code is for hiding/showing the component depending on which tab is open
    ; In this example the Tab named "one" is the one that contains the control.
    ; If you switch the words "show" and "hide" the component will be shown when the tab called "two" is active.

    tabHandler:                                 ; Tab Handler for the Scintilla Control
    Gui, submit, Nohide
    action := tabLast = "one" ? "Show" : "Hide" ; decide which action to take
    Control,%action%,,, % "ahk_id " sci.hwnd
    return

    GuiClose:
        exitapp
    (end)
*/
__Add(hParent, x := 5, y := 5, w := 590, h := 390, DllPath := "SciLexer.dll", Style := 0x50010000, ExStyle := 0x200) {
    Static init := False

    If !(init) {
        If !(DllCall("LoadLibrary", "Str", DllPath)) {
            MsgBox 0x10
            , % StrSplit(A_ScriptName, ".")[1] . " - Error " . A_LastError
            , Failed to load library %DllPath%.
            Return
        }

        OnMessage(0x4E, "__sciNotify") ; WM_NOTIFY
        init := True
    }

    ;Gui %hParent%: Add, Custom, ClassScintilla hWndhSci x%x% y%y% w%w% h%h% %Style%
    hSci := DllCall("CreateWindowEx"
                 , "Uint" , ExStyle
                 , "Str"  , "Scintilla"
                 , "Str"  , ""
                 , "UInt" , Style
                 , "Int"  , x
                 , "Int"  , y
                 , "Int"  , w
                 , "Int"  , h
                 , "UInt" , hParent
                 , "UInt" , 0xC0DE
                 , "UInt" , 0
                 , "UInt" , 0, "UInt")

    __sendEditor(hSci) ; Initialize sendEditor function

    Return hSci
}

/*
    Function : __sendEditor
    Posts the messages used to modify the control's behaviour.

    *This is an internal function and it is not needed in normal situations. Please use the scintilla object to call all functions.
    They call this function automatically*

    Parameters:
    __sendEditor(hwnd, msg, [wParam, lParam])

    hwnd    -   The hwnd of the control that you want to operate on. Useful for when you have more than 1
                Scintilla components in the same script. The wrapper will remember the last used hwnd,
                so you can specify it once and only specify it again when you want to operate on a different
                component.
                *Note: This is converted internally by the wrapper from the object calling method. It is recommended that you dont use this function.*
    msg     -   The message to be posted, full list can be found here:
                <http://www.scintilla.org/ScintillaDoc.html>
    wParam  -   wParam for the message
    lParam  -   lParam for the message

    Returns:
    Status code of the DllCall performed.

    Examples:
    (Start Code)
    __sendEditor(hSci1, "SCI_SETMARGINWIDTHN",0,40)  ; Set the margin 0 to 40px on the first component.
    __sendEditor(0, "SCI_SETWRAPMODE",1,0)           ; Set wrap mode to true on the last used component.
    __sendEditor(hSci2, "SCI_SETMARGINWIDTHN",0,50)  ; Set the margin 0 to 50px on the second component.
    (End)
*/
__sendEditor(hwnd, msg=0, wParam=0, lParam=0){
    static

    hwnd := !hwnd ? oldhwnd : hwnd, oldhwnd := hwnd, msg := !(msg+0) ? "SCI_" msg : msg

    if !%hwnd%_df
	{
        SendMessage, SCI_GETDIRECTFUNCTION,0,0,,ahk_id %hwnd%
        %hwnd%_df := ErrorLevel
        SendMessage, SCI_GETDIRECTPOINTER,0,0,,ahk_id %hwnd%
        %hwnd%_dp := ErrorLevel
	}

    if !msg && !wParam && !lParam   ; called only with the hwnd param from SCI_Add
        return                      ; Exit because we did what we needed to do already.
        
    ;OutputDebug %msg%

    ; The fast way to control Scintilla
    return DllCall(%hwnd%_df            ; DIRECT FUNCTION
                  ,"UInt" ,%hwnd%_dp    ; DIRECT POINTER
                  ,"UInt" ,!(msg+0) ? %msg% : msg
                  ,"Int"  ,inStr(wParam, "-") ? wParam : (%wParam%+0 ? %wParam% : wParam) ; handles negative ints
                  ,"Int"  ,inStr(lParam, "-") ? lParam : (%lParam%+0 ? %lParam% : lParam)) ; handles negative ints
}

/*
    Function : __sciNotify
    This is the default function which will be called when the WM_NOTIFY message has been received. The message is tracked as soon as you
    add a new scintilla component.


    Parameters:
    __sciNotify(wParam, lParam, msg, hwnd)

    wParam  -   wParam for the message
    lParam  -   lParam for the message
    msg     -   The message which triggered this function
    hwnd    -   The hwnd of the control which sent the message

    Returns:
    This function sets some variables on the sciObject to which the component belongs to and procedes to call your user defined notify function
    which can be set in sciObj.notify.

    It will pass wParam, lParam, msg and hwnd to that function so make sure you define it that way.
    Returns nothing.

    Examples:
*/
__sciNotify(wParam, lParam, msg, hwnd){

    ; fix int for x64 bit systems
    __sciObj                 := __SCI(NumGet(lParam + 0))               ; Returns original object
    __sciObj.idFrom          := NumGet(lParam + a_Ptrsize * 1)
    __sciObj.scnCode         := NumGet(lParam + a_Ptrsize * 2)

    __sciObj.position        := NumGet(lParam + a_Ptrsize * 3)
    __sciObj.ch              := NumGet(lParam + a_Ptrsize * 4)
    __sciObj.modifiers       := NumGet(lParam + a_Ptrsize * 5)
    __sciObj.modType         := NumGet(lParam + a_Ptrsize * 6)
    __sciObj.text            := NumGet(lParam + a_Ptrsize * 7)
    __sciObj.length          := NumGet(lParam + a_Ptrsize * 8)
    __sciObj.linesAdded      := NumGet(lParam + a_Ptrsize * 9)

    __sciObj.macMessage      := NumGet(lParam + a_Ptrsize * 10)
    __sciObj.macwParam       := NumGet(lParam + a_Ptrsize * 11)
    __sciObj.maclParam       := NumGet(lParam + a_Ptrsize * 12)

    __sciObj.line            := NumGet(lParam + a_Ptrsize * 13)
    __sciObj.foldLevelNow    := NumGet(lParam + a_Ptrsize * 14)
    __sciObj.foldLevelPrev   := NumGet(lParam + a_Ptrsize * 15)
    __sciObj.margin          := NumGet(lParam + a_Ptrsize * 16)
    __sciObj.listType        := NumGet(lParam + a_Ptrsize * 17)
    __sciObj.x               := NumGet(lParam + a_Ptrsize * 18)
    __sciObj.y               := NumGet(lParam + a_Ptrsize * 19)

    __sciObj.token           := NumGet(lParam + a_Ptrsize * 20)
    __sciObj.annotLinesAdded := NumGet(lParam + a_Ptrsize * 21)
    __sciObj.updated         := NumGet(lParam + a_Ptrsize * 22)

    __sciObj.notify(wParam, lParam, msg, hwnd, __sciObj)                ; Call user defined Notify Function and passes object to it as last parameter
    return __sciObj := ""                                               ; free object
}

__isHexColor(hex, msg){
    if (RegexMatch(hex, "^0x[0-9a-fA-F]{6}$"))
        return true
    else
        return false
}

__SCI(var, val=""){
    static
/*
    if (RegExMatch(var,"i)[ `n-\.%,(\\\/=&^]")) ; Check if it is a valid variable name
        return
*/
	lvar := %var%, val ? %var% := val : null
    return lvar
}

; Global scintilla variables
{
global INVALID_POSITION:=-1, unused := 0 ; Some messages dont use one of their parameters. You can use this variable for them.

; Main Scintilla Functions
{
global SCI_ADDTEXT:=2001,SCI_ADDSTYLEDTEXT:=2002,SCI_INSERTTEXT:=2003,SCI_CLEARALL:=2004,SCI_CLEARDOCUMENTSTYLE:=2005,SCI_GETLENGTH:=2006
,SCI_GETCHARAT:=2007,SCI_GETCURRENTPOS:=2008,SCI_GETANCHOR:=2009,SCI_GETSTYLEAT:=2010,SCI_REDO:=2011,SCI_SETUNDOCOLLECTION:=2012
,SCI_SELECTALL:=2013,SCI_SETSAVEPOINT:=2014,SCI_GETSTYLEDTEXT:=2015,SCI_CANREDO:=2016,SCI_MARKERLINEFROMHANDLE:=2017
,SCI_MARKERDELETEHANDLE:=2018,SCI_GETUNDOCOLLECTION:=2019,SCI_GETVIEWWS:=2020,SCI_SETVIEWWS:=2021,SCI_POSITIONFROMPOINT:=2022
,SCI_POSITIONFROMPOINTCLOSE:=2023,SCI_GOTOLINE:=2024,SCI_GOTOPOS:=2025,SCI_SETANCHOR:=2026,SCI_GETCURLINE:=2027,SCI_GETENDSTYLED:=2028
,SCI_CONVERTEOLS:=2029,SCI_GETEOLMODE:=2030,SCI_SETEOLMODE:=2031,SCI_STARTSTYLING:=2032,SCI_SETSTYLING:=2033,SCI_GETBUFFEREDDRAW:=2034
,SCI_SETBUFFEREDDRAW:=2035,SCI_SETTABWIDTH:=2036,SCI_GETTABWIDTH:=2121,SCI_SETCODEPAGE:=2037,SCI_SETUSEPALETTE:=2039,SCI_MARKERDEFINE:=2040
,SCI_MARKERSETFORE:=2041,SCI_MARKERSETBACK:=2042,SCI_MARKERADD:=2043,SCI_MARKERDELETE:=2044,SCI_MARKERDELETEALL:=2045,SCI_MARKERGET:=2046
,SCI_MARKERNEXT:=2047,SCI_MARKERPREVIOUS:=2048,SCI_MARKERDEFINEPIXMAP:=2049,SCI_MARKERADDSET:=2466,SCI_MARKERSETALPHA:=2476
,SCI_SETMARGINTYPEN:=2240,SCI_GETMARGINTYPEN:=2241,SCI_SETMARGINWIDTHN:=2242,SCI_GETMARGINWIDTHN:=2243,SCI_SETMARGINMASKN:=2244
,SCI_GETMARGINMASKN:=2245,SCI_SETMARGINSENSITIVEN:=2246,SCI_GETMARGINSENSITIVEN:=2247,SCI_STYLECLEARALL:=2050,SCI_STYLESETFORE:=2051
,SCI_STYLESETBACK:=2052,SCI_STYLESETBOLD:=2053,SCI_STYLESETITALIC:=2054,SCI_STYLESETSIZE:=2055,SCI_STYLESETFONT:=2056
,SCI_STYLESETEOLFILLED:=2057,SCI_STYLEGETFORE:=2481,SCI_STYLEGETBACK:=2482,SCI_STYLEGETBOLD:=2483,SCI_STYLEGETITALIC:=2484
,SCI_STYLEGETSIZE:=2485,SCI_STYLEGETFONT:=2486,SCI_STYLEGETEOLFILLED:=2487,SCI_STYLEGETUNDERLINE:=2488,SCI_STYLEGETCASE:=2489
,SCI_STYLEGETCHARACTERSET:=2490,SCI_STYLEGETVISIBLE:=2491,SCI_STYLEGETCHANGEABLE:=2492,SCI_STYLEGETHOTSPOT:=2493,SCI_STYLERESETDEFAULT:=2058
,SCI_STYLESETUNDERLINE:=2059,SCI_STYLESETCASE:=2060,SCI_STYLESETCHARACTERSET:=2066,SCI_STYLESETHOTSPOT:=2409,SCI_SETSELFORE:=2067
,SCI_SETSELBACK:=2068,SCI_GETSELALPHA:=2477,SCI_SETSELALPHA:=2478,SCI_SETCARETFORE:=2069,SCI_ASSIGNCMDKEY:=2070,SCI_CLEARCMDKEY:=2071
,SCI_CLEARALLCMDKEYS:=2072,SCI_SETSTYLINGEX:=2073,SCI_STYLESETVISIBLE:=2074,SCI_GETCARETPERIOD:=2075,SCI_SETCARETPERIOD:=2076
,SCI_SETWORDCHARS:=2077,SCI_BEGINUNDOACTION:=2078,SCI_ENDUNDOACTION:=2079,SCI_INDICSETSTYLE:=2080,SCI_INDICGETSTYLE:=2081
,SCI_INDICSETFORE:=2082,SCI_INDICGETFORE:=2083,SCI_SETWHITESPACEFORE:=2084,SCI_SETWHITESPACEBACK:=2085,SCI_SETSTYLEBITS:=2090
,SCI_GETSTYLEBITS:=2091,SCI_SETLINESTATE:=2092,SCI_GETLINESTATE:=2093,SCI_GETMAXLINESTATE:=2094,SCI_GETCARETLINEVISIBLE:=2095
,SCI_SETCARETLINEVISIBLE:=2096,SCI_GETCARETLINEBACK:=2097,SCI_SETCARETLINEBACK:=2098,SCI_STYLESETCHANGEABLE:=2099,SCI_AUTOCSHOW:=2100
,SCI_AUTOCCANCEL:=2101,SCI_AUTOCACTIVE:=2102,SCI_AUTOCPOSSTART:=2103,SCI_AUTOCCOMPLETE:=2104,SCI_AUTOCSTOPS:=2105
,SCI_AUTOCSETSEPARATOR:=2106,SCI_AUTOCGETSEPARATOR:=2107,SCI_AUTOCSELECT:=2108,SCI_AUTOCSETCANCELATSTART:=2110
,SCI_AUTOCGETCANCELATSTART:=2111,SCI_AUTOCSETFILLUPS:=2112,SCI_AUTOCSETCHOOSESINGLE:=2113,SCI_AUTOCGETCHOOSESINGLE:=2114
,SCI_AUTOCSETIGNORECASE:=2115,SCI_AUTOCGETIGNORECASE:=2116,SCI_USERLISTSHOW:=2117,SCI_AUTOCSETAUTOHIDE:=2118,SCI_AUTOCGETAUTOHIDE:=2119
,SCI_AUTOCSETDROPRESTOFWORD:=2270,SCI_AUTOCGETDROPRESTOFWORD:=2271,SCI_REGISTERIMAGE:=2405,SCI_CLEARREGISTEREDIMAGES:=2408
,SCI_AUTOCGETTYPESEPARATOR:=2285,SCI_AUTOCSETTYPESEPARATOR:=2286,SCI_AUTOCSETMAXWIDTH:=2208,SCI_AUTOCGETMAXWIDTH:=2209
,SCI_AUTOCSETMAXHEIGHT:=2210,SCI_AUTOCGETMAXHEIGHT:=2211,SCI_SETINDENT:=2122,SCI_GETINDENT:=2123,SCI_SETUSETABS:=2124,SCI_GETUSETABS:=2125
,SCI_SETLINEINDENTATION:=2126,SCI_GETLINEINDENTATION:=2127,SCI_GETLINEINDENTPOSITION:=2128,SCI_GETCOLUMN:=2129,SCI_SETHSCROLLBAR:=2130
,SCI_GETHSCROLLBAR:=2131,SCI_SETINDENTATIONGUIDES:=2132,SCI_GETINDENTATIONGUIDES:=2133,SCI_SETHIGHLIGHTGUIDE:=2134
,SCI_GETHIGHLIGHTGUIDE:=2135,SCI_GETLINEENDPOSITION:=2136,SCI_GETCODEPAGE:=2137,SCI_GETCARETFORE:=2138,SCI_GETUSEPALETTE:=2139
,SCI_GETREADONLY:=2140,SCI_SETCURRENTPOS:=2141,SCI_SETSELECTIONSTART:=2142,SCI_GETSELECTIONSTART:=2143,SCI_SETSELECTIONEND:=2144
,SCI_GETSELECTIONEND:=2145,SCI_SETPRINTMAGNIFICATION:=2146,SCI_GETPRINTMAGNIFICATION:=2147,SCI_SETPRINTCOLORMODE:=2148
,SCI_GETPRINTCOLORMODE:=2149,SCI_FINDTEXT:=2150,SCI_FORMATRANGE:=2151,SCI_GETFIRSTVISIBLELINE:=2152,SCI_GETLINE:=2153
,SCI_GETLINECOUNT:=2154,SCI_SETMARGINLEFT:=2155,SCI_GETMARGINLEFT:=2156,SCI_SETMARGINRIGHT:=2157,SCI_GETMARGINRIGHT:=2158
,SCI_GETMODIFY:=2159,SCI_SETSEL:=2160,SCI_GETSELTEXT:=2161,SCI_GETTEXTRANGE:=2162,SCI_HIDESELECTION:=2163,SCI_POINTXFROMPOSITION:=2164
,SCI_POINTYFROMPOSITION:=2165,SCI_LINEFROMPOSITION:=2166,SCI_POSITIONFROMLINE:=2167,SCI_LINESCROLL:=2168,SCI_SCROLLCARET:=2169
,SCI_REPLACESEL:=2170,SCI_SETREADONLY:=2171,SCI_NULL:=2172,SCI_CANPASTE:=2173,SCI_CANUNDO:=2174,SCI_EMPTYUNDOBUFFER:=2175,SCI_UNDO:=2176
,SCI_CUT:=2177,SCI_COPY:=2178,SCI_PASTE:=2179,SCI_CLEAR:=2180,SCI_SETTEXT:=2181,SCI_GETTEXT:=2182,SCI_GETTEXTLENGTH:=2183
,SCI_GETDIRECTFUNCTION:=2184,SCI_GETDIRECTPOINTER:=2185,SCI_SETOVERTYPE:=2186,SCI_GETOVERTYPE:=2187,SCI_SETCARETWIDTH:=2188
,SCI_GETCARETWIDTH:=2189,SCI_SETTARGETSTART:=2190,SCI_GETTARGETSTART:=2191,SCI_SETTARGETEND:=2192,SCI_GETTARGETEND:=2193
,SCI_REPLACETARGET:=2194,SCI_REPLACETARGETRE:=2195,SCI_SEARCHINTARGET:=2197,SCI_SETSEARCHFLAGS:=2198,SCI_GETSEARCHFLAGS:=2199
,SCI_CALLTIPSHOW:=2200,SCI_CALLTIPCANCEL:=2201,SCI_CALLTIPACTIVE:=2202,SCI_CALLTIPPOSSTART:=2203,SCI_CALLTIPSETHLT:=2204
,SCI_CALLTIPSETBACK:=2205,SCI_CALLTIPSETFORE:=2206,SCI_CALLTIPSETFOREHLT:=2207,SCI_CALLTIPUSESTYLE:=2212,SCI_VISIBLEFROMDOCLINE:=2220
,SCI_DOCLINEFROMVISIBLE:=2221,SCI_WRAPCOUNT:=2235,SCI_SETFOLDLEVEL:=2222,SCI_GETFOLDLEVEL:=2223,SCI_GETLASTCHILD:=2224
,SCI_GETFOLDPARENT:=2225,SCI_SHOWLINES:=2226,SCI_HIDELINES:=2227,SCI_GETLINEVISIBLE:=2228,SCI_SETFOLDEXPANDED:=2229
,SCI_GETFOLDEXPANDED:=2230,SCI_TOGGLEFOLD:=2231,SCI_ENSUREVISIBLE:=2232,SCI_SETFOLDFLAGS:=2233,SCI_ENSUREVISIBLEENFORCEPOLICY:=2234
,SCI_SETTABINDENTS:=2260,SCI_GETTABINDENTS:=2261,SCI_SETBACKSPACEUNINDENTS:=2262,SCI_GETBACKSPACEUNINDENTS:=2263,SCI_SETMOUSEDWELLTIME:=2264
,SCI_GETMOUSEDWELLTIME:=2265,SCI_WORDSTARTPOSITION:=2266,SCI_WORDENDPOSITION:=2267,SCI_SETWRAPMODE:=2268,SCI_GETWRAPMODE:=2269
,SCI_SETWRAPVISUALFLAGS:=2460,SCI_GETWRAPVISUALFLAGS:=2461,SCI_SETWRAPVISUALFLAGSLOCATION:=2462,SCI_GETWRAPVISUALFLAGSLOCATION:=2463
,SCI_SETWRAPSTARTINDENT:=2464,SCI_GETWRAPSTARTINDENT:=2465,SCI_SETLAYOUTCACHE:=2272,SCI_GETLAYOUTCACHE:=2273,SCI_SETSCROLLWIDTH:=2274
,SCI_GETSCROLLWIDTH:=2275,SCI_TEXTWIDTH:=2276,SCI_SETENDATLASTLINE:=2277,SCI_GETENDATLASTLINE:=2278,SCI_TEXTHEIGHT:=2279
,SCI_SETVSCROLLBAR:=2280,SCI_GETVSCROLLBAR:=2281,SCI_APPENDTEXT:=2282,SCI_GETTWOPHASEDRAW:=2283,SCI_SETTWOPHASEDRAW:=2284
,SCI_TARGETFROMSELECTION:=2287,SCI_LINESJOIN:=2288,SCI_LINESSPLIT:=2289,SCI_SETFOLDMARGINCOLOR:=2290,SCI_SETFOLDMARGINHICOLOR:=2291
,SCI_ZOOMIN:=2333,SCI_ZOOMOUT:=2334,SCI_MOVECARETINSIDEVIEW:=2401,SCI_LINELENGTH:=2350,SCI_BRACEHIGHLIGHT:=2351,SCI_BRACEBADLIGHT:=2352
,SCI_BRACEMATCH:=2353,SCI_GETVIEWEOL:=2355,SCI_SETVIEWEOL:=2356,SCI_GETDOCPOINTER:=2357,SCI_SETDOCPOINTER:=2358,SCI_SETMODEVENTMASK:=2359
,SCI_GETEDGECOLUMN:=2360,SCI_SETEDGECOLUMN:=2361,SCI_GETEDGEMODE:=2362,SCI_SETEDGEMODE:=2363,SCI_GETEDGECOLOR:=2364,SCI_SETEDGECOLOR:=2365
,SCI_SEARCHANCHOR:=2366,SCI_SEARCHNEXT:=2367,SCI_SEARCHPREV:=2368,SCI_LINESONSCREEN:=2370,SCI_USEPOPUP:=2371,SCI_SELECTIONISRECTANGLE:=2372
,SCI_SETZOOM:=2373,SCI_GETZOOM:=2374,SCI_CREATEDOCUMENT:=2375,SCI_ADDREFDOCUMENT:=2376,SCI_RELEASEDOCUMENT:=2377,SCI_GETMODEVENTMASK:=2378
,SCI_SETFOCUS:=2380,SCI_GETFOCUS:=2381,SCI_SETSTATUS:=2382,SCI_GETSTATUS:=2383,SCI_SETMOUSEDOWNCAPTURES:=2384,SCI_GETMOUSEDOWNCAPTURES:=2385
,SCI_SETCURSOR:=2386,SCI_GETCURSOR:=2387,SCI_SETCONTROLCHARSYMBOL:=2388,SCI_GETCONTROLCHARSYMBOL:=2389,SCI_SETVISIBLEPOLICY:=2394
,SCI_SETXOFFSET:=2397,SCI_GETXOFFSET:=2398,SCI_CHOOSECARETX:=2399,SCI_GRABFOCUS:=2400,SCI_SETXCARETPOLICY:=2402,SCI_SETYCARETPOLICY:=2403
,SCI_SETPRINTWRAPMODE:=2406,SCI_GETPRINTWRAPMODE:=2407,SCI_SETHOTSPOTACTIVEFORE:=2410,SCI_SETHOTSPOTACTIVEBACK:=2411
,SCI_SETHOTSPOTACTIVEUNDERLINE:=2412,SCI_SETHOTSPOTSINGLELINE:=2421,SCI_POSITIONBEFORE:=2417,SCI_POSITIONAFTER:=2418
,SCI_COPYRANGE:=2419,SCI_COPYTEXT:=2420,SCI_SETSELECTIONMODE:=2422,SCI_GETSELECTIONMODE:=2423,SCI_GETLINESELSTARTPOSITION:=2424
,SCI_GETLINESELENDPOSITION:=2425,SCI_SETWHITESPACECHARS:=2443,SCI_SETCHARSDEFAULT:=2444,SCI_AUTOCGETCURRENT:=2445,SCI_ALLOCATE:=2446
,SCI_TARGETASUTF8:=2447,SCI_SETLENGTHFORENCODE:=2448,SCI_ENCODEDFROMUTF8:=2449,SCI_FINDCOLUMN:=2456,SCI_GETCARETSTICKY:=2457
,SCI_SETCARETSTICKY:=2458,SCI_TOGGLECARETSTICKY:=2459,SCI_SETPASTECONVERTENDINGS:=2467,SCI_GETPASTECONVERTENDINGS:=2468
,SCI_SETCARETLINEBACKALPHA:=2470,SCI_GETCARETLINEBACKALPHA:=2471,SCI_STARTRECORD:=3001,SCI_STOPRECORD:=3002,SCI_SETLEXER:=4001
,SCI_GETLEXER:=4002,SCI_COLORISE:=4003,SCI_SETPROPERTY:=4004,SCI_SETKEYWORDS:=4005,SCI_SETLEXERLANGUAGE:=4006,SCI_LOADLEXERLIBRARY:=4007
,SCI_GETPROPERTY:=4008,SCI_GETPROPERTYEXPANDED:=4009,SCI_GETPROPERTYINT:=4010,SCI_GETSTYLEBITSNEEDED:=4011, SCI_SETEXTRAASCENT := 2525, SCI_SETINDICATORCURRENT := 2500, SCI_INDICATORCLEARRANGE := 2505, SCI_INDICSETOUTLINEALPHA := 2558, SCI_INDICSETALPHA := 2523, SCI_INDICATORFILLRANGE := 2504, SCI_INDICATORSTART := 2508, SCI_INDICATOREND := 2509, SCI_INDICATORALLONFOR := 2506, SCI_AUTOCSETORDER := 2660, SCI_SETCARETLINEVISIBLEALWAYS := 2655
}

; Styles, Markers and Indicators
{
global MARKER_MAX:=31,STYLE_DEFAULT:=32,STYLE_LINENUMBER:=33,STYLE_BRACELIGHT:=34,STYLE_BRACEBAD:=35,STYLE_CONTROLCHAR:=36
,STYLE_INDENTGUIDE:=37,STYLE_CALLTIP:=38,STYLE_LASTPREDEFINED:=39,STYLE_MAX:=127,INDIC_MAX:=7,INDIC_PLAIN:=0,INDIC_SQUIGGLE:=1,INDIC_TT:=2
,INDIC_DIAGONAL:=3,INDIC_STRIKE:=4,INDIC_HIDDEN:=5,INDIC_BOX:=6,INDIC_ROUNDBOX:=7,INDIC0_MASK:=0x20,INDIC1_MASK:=0x40,INDIC2_MASK:=0x80
,INDICS_MASK:=0xE0,SCI_START:=2000,SCI_OPTIONAL_START:=3000,SCI_LEXER_START:=4000,SCWS_INVISIBLE:=0,SCWS_VISIBLEALWAYS:=1
,SCWS_VISIBLEAFTERINDENT:=2,SC_EOL_CRLF:=0,SC_EOL_CR:=1,SC_EOL_LF:=2,SC_CP_UTF8:=65001,SC_CP_DBCS:=1,SC_MARK_CIRCLE:=0,SC_MARK_ROUNDRECT:=1
,SC_MARK_ARROW:=2,SC_MARK_SMALLRECT:=3,SC_MARK_SHORTARROW:=4,SC_MARK_EMPTY:=5,SC_MARK_ARROWDOWN:=6,SC_MARK_MINUS:=7,SC_MARK_PLUS:=8
,SC_MARK_VLINE:=9,SC_MARK_LCORNER:=10,SC_MARK_TCORNER:=11,SC_MARK_BOXPLUS:=12,SC_MARK_BOXPLUSCONNECTED:=13,SC_MARK_BOXMINUS:=14
,SC_MARK_BOXMINUSCONNECTED:=15,SC_MARK_LCORNERCURVE:=16,SC_MARK_TCORNERCURVE:=17,SC_MARK_CIRCLEPLUS:=18,SC_MARK_CIRCLEPLUSCONNECTED:=19
,SC_MARK_CIRCLEMINUS:=20,SC_MARK_CIRCLEMINUSCONNECTED:=21,SC_MARK_BACKGROUND:=22,SC_MARK_DOTDOTDOT:=23,SC_MARK_ARROWS:=24
,SC_MARK_PIXMAP:=25,SC_MARK_FULLRECT:=26,SC_MARK_CHARACTER:=10000,SC_MARKNUM_FOLDEREND:=25,SC_MARKNUM_FOLDEROPENMID:=26
,SC_MARKNUM_FOLDERMIDTAIL:=27,SC_MARKNUM_FOLDERTAIL:=28,SC_MARKNUM_FOLDERSUB:=29,SC_MARKNUM_FOLDER:=30,SC_MARKNUM_FOLDEROPEN:=31
,SC_MASK_FOLDERS:=0xFE000000,SC_MARGIN_SYMBOL:=0,SC_MARGIN_NUMBER:=1
}

; Character Sets and Printing
{
global SC_CHARSET_ANSI:=0,SC_CHARSET_DEFAULT:=1,SC_CHARSET_BALTIC:=186
,SC_CHARSET_CHINESEBIG5:=136,SC_CHARSET_EASTEUROPE:=238,SC_CHARSET_GB2312:=134,SC_CHARSET_GREEK:=161,SC_CHARSET_HANGUL:=129
,SC_CHARSET_MAC:=77,SC_CHARSET_OEM:=255,SC_CHARSET_RUSSIAN:=204,SC_CHARSET_CYRILLIC:=1251,SC_CHARSET_SHIFTJIS:=128
,SC_CHARSET_SYMBOL:=2,SC_CHARSET_TURKISH:=162,SC_CHARSET_JOHAB:=130,SC_CHARSET_HEBREW:=177,SC_CHARSET_ARABIC:=178,SC_CHARSET_VIETNAMESE:=163
,SC_CHARSET_THAI:=222,SC_CHARSET_8859_15:=1000, SC_CASE_MIXED:=0,SC_CASE_UPPER:=1,SC_CASE_LOWER:=2,SC_PRINT_NORMAL:=0,SC_PRINT_INVERTLIGHT:=1
,SC_PRINT_BLACKONWHITE:=2,SC_PRINT_COLORONWHITE:=3,SC_PRINT_COLORONWHITEDEFAULTBG:=4
}

; Search Flags
{
global SCFIND_WHOLEWORD:=2,SCFIND_MATCHCASE:=4
,SCFIND_WORDSTART:=0x00100000,SCFIND_REGEXP:=0x00200000,SCFIND_POSIX:=0x00400000
}

; Folding
{
global SC_FOLDLEVELBASE:=0x400,SC_FOLDLEVELWHITEFLAG:=0x1000
,SC_FOLDLEVELHEADERFLAG:=0x2000,SC_FOLDLEVELBOXHEADERFLAG:=0x4000,SC_FOLDLEVELBOXFOOTERFLAG:=0x8000,SC_FOLDLEVELCONTRACTED:=0x10000
,SC_FOLDLEVELUNINDENT:=0x20000,SC_FOLDLEVELNUMBERMASK:=0x0FFF,SC_FOLDFLAG_LINEBEFORE_EXPANDED:=0x0002,SC_FOLDFLAG_LINEBEFORE_CONTRACTED:=0x0004
,SC_FOLDFLAG_LINEAFTER_EXPANDED:=0x0008,SC_FOLDFLAG_LINEAFTER_CONTRACTED:=0x0010,SC_FOLDFLAG_LEVELNUMBERS:=0x0040,SC_FOLDFLAG_BOX:=0x0001
}

; Keys
{
global SCMOD_NORM:=0, SCMOD_SHIFT:=1,SCMOD_CTRL:=2,SCMOD_ALT:=4, SCK_DOWN:=300,SCK_UP:=301,SCK_LEFT:=302,SCK_RIGHT:=303,SCK_HOME:=304,SCK_END:=305
,SCK_PRIOR:=306,SCK_NEXT:=307,SCK_DELETE:=308,SCK_INSERT:=309,SCK_ESCAPE:=7,SCK_BACK:=8,SCK_TAB:=9,SCK_RETURN:=13,SCK_ADD:=310,SCK_SUBTRACT:=311
,SCK_DIVIDE:=312
}

; Lexing
{
global SCLEX_CONTAINER:=0,SCLEX_NULL:=1,SCLEX_PYTHON:=2,SCLEX_CPP:=3,SCLEX_HTML:=4,SCLEX_XML:=5,SCLEX_PERL:=6,SCLEX_SQL:=7,SCLEX_VB:=8
,SCLEX_PROPERTIES:=9,SCLEX_ERRORLIST:=10,SCLEX_MAKEFILE:=11,SCLEX_BATCH:=12,SCLEX_XCODE:=13,SCLEX_LATEX:=14,SCLEX_LUA:=15,SCLEX_DIFF:=16
,SCLEX_CONF:=17,SCLEX_PASCAL:=18,SCLEX_AVE:=19,SCLEX_ADA:=20,SCLEX_LISP:=21,SCLEX_RUBY:=22,SCLEX_EIFFEL:=23,SCLEX_EIFFELKW:=24
,SCLEX_TCL:=25,SCLEX_NNCRONTAB:=26,SCLEX_BULLANT:=27,SCLEX_VBSCRIPT:=28,SCLEX_BAAN:=31,SCLEX_MATLAB:=32,SCLEX_SCRIPTOL:=33
,SCLEX_ASM:=34,SCLEX_CPPNOCASE:=35,SCLEX_FORTRAN:=36,SCLEX_F77:=37,SCLEX_CSS:=38,SCLEX_POV:=39,SCLEX_LOUT:=40,SCLEX_ESCRIPT:=41
,SCLEX_PS:=42,SCLEX_NSIS:=43,SCLEX_MMIXAL:=44,SCLEX_CLW:=45,SCLEX_CLWNOCASE:=46,SCLEX_LOT:=47,SCLEX_YAML:=48,SCLEX_TEX:=49
,SCLEX_METAPOST:=50,SCLEX_POWERBASIC:=51,SCLEX_FORTH:=52,SCLEX_ERLANG:=53,SCLEX_OCTAVE:=54,SCLEX_MSSQL:=55,SCLEX_VERILOG:=56,SCLEX_KIX:=57
,SCLEX_GUI4CLI:=58,SCLEX_SPECMAN:=59,SCLEX_AU3:=60,SCLEX_APDL:=61,SCLEX_BASH:=62,SCLEX_ASN1:=63,SCLEX_VHDL:=64,SCLEX_CAML:=65
,SCLEX_BLITZBASIC:=66,SCLEX_PUREBASIC:=67,SCLEX_HASKELL:=68,SCLEX_PHPSCRIPT:=69,SCLEX_TADS3:=70,SCLEX_REBOL:=71,SCLEX_SMALLTALK:=72
,SCLEX_FLAGSHIP:=73,SCLEX_CSOUND:=74,SCLEX_FREEBASIC:=75,SCLEX_INNOSETUP:=76,SCLEX_OPAL:=77,SCLEX_SPICE:=78,SCLEX_D:=79,SCLEX_CMAKE:=80
,SCLEX_GAP:=81,SCLEX_PLM:=82,SCLEX_PROGRESS:=83,SCLEX_ABAQUS:=84,SCLEX_ASYMPTOTE:=85,SCLEX_R:=86,SCLEX_MAGIK:=87,SCLEX_POWERSHELL:=88
,SCLEX_MYSQL:=89,SCLEX_PO:=90,SCLEX_TAL:=91,SCLEX_COBOL:=92,SCLEX_TACL:=93,SCLEX_SORCUS:=94,SCLEX_POWERPRO:=95,SCLEX_NIMROD:=96,SCLEX_SML:=97
,SCLEX_MARKDOWN:=98,SCLEX_TXT2TAGS:=99,SCLEX_A68K:=100,SCLEX_MODULA:=101,SCLEX_COFFEESCRIPT:=102,SCLEX_TCMD:=103,SCLEX_AVS:=104,SCLEX_ECL:=105
,SCLEX_OSCRIPT:=106,SCLEX_VISUALPROLOG:=107,SCLEX_LITERATEHASKELL:=108,SCLEX_AHKL:=109
,SCE_AHKL_NEUTRAL:=0,SCE_AHKL_IDENTIFIER:=1,SCE_AHKL_COMMENTDOC:=2,SCE_AHKL_COMMENTLINE:=3,SCE_AHKL_COMMENTBLOCK:=4,SCE_AHKL_COMMENTKEYWORD:=5
,SCE_AHKL_STRING:=6,SCE_AHKL_STRINGOPTS:=7,SCE_AHKL_STRINGBLOCK:=8,SCE_AHKL_STRINGCOMMENT:=9,SCE_AHKL_LABEL:=10,SCE_AHKL_HOTKEY:=11
,SCE_AHKL_HOTSTRING:=12,SCE_AHKL_HOTSTRINGOPT:=13,SCE_AHKL_HEXNUMBER:=14,SCE_AHKL_DECNUMBER:=15,SCE_AHKL_VAR:=16,SCE_AHKL_VARREF:=17
,SCE_AHKL_OBJECT:=18,SCE_AHKL_USERFUNCTION:=19,SCE_AHKL_DIRECTIVE:=20,SCE_AHKL_COMMAND:=21,SCE_AHKL_PARAM:=22,SCE_AHKL_CONTROLFLOW:=23
,SCE_AHKL_BUILTINFUNCTION:=24,SCE_AHKL_BUILTINVAR:=25,SCE_AHKL_KEY:=26,SCE_AHKL_USERDEFINED1:=27,SCE_AHKL_USERDEFINED2:=28,SCE_AHKL_ESCAPESEQ:=30
,SCE_AHKL_ERROR:=31,AHKL_LIST_DIRECTIVES:=0,AHKL_LIST_COMMANDS:=1,AHKL_LIST_PARAMETERS:=2,AHKL_LIST_CONTROLFLOW:=3,AHKL_LIST_FUNCTIONS:=4
,AHKL_LIST_VARIABLES:=5,AHKL_LIST_KEYS:=6,AHKL_LIST_USERDEFINED1:=7,AHKL_LIST_USERDEFINED2:=8,SCLEX_AUTOMATIC=1000
}

; Notifications
{
global SCEN_CHANGE:=768,SCEN_SETFOCUS:=512,SCEN_KILLFOCUS:=256, SCN_STYLENEEDED:=2000,SCN_CHARADDED:=2001
,SCN_SAVEPOINTREACHED:=2002,SCN_SAVEPOINTLEFT:=2003,SCN_MODIFYATTEMPTRO:=2004,SCN_DOUBLECLICK:=2006,SCN_UPDATEUI:=2007
,SCN_MODIFIED:=2008,SCN_MACRORECORD:=2009,SCN_MARGINCLICK:=2010,SCN_NEEDSHOWN:=2011,SCN_PAINTED:=2013,SCN_USERLISTSELECTION:=2014
,SCN_URIDROPPED:=2015,SCN_DWELLSTART:=2016,SCN_DWELLEND:=2017,SCN_ZOOM:=2018,SCN_HOTSPOTCLICK:=2019,SCN_HOTSPOTDOUBLECLICK:=2020
, SCN_CALLTIPCLICK := 2021, SCN_AUTOCSELECTION := 2022, SCN_AUTOCCOMPLETED := 2030, SCN_AUTOCCANCELLED := 2025
}

; Other
{
global SCI_LINEDOWN:=2300,SCI_LINEDOWNEXTEND:=2301,SCI_LINEDOWNRECTEXTEND:=2426
,SCI_LINESCROLLDOWN:=2342,SCI_LINEUP:=2302,SCI_LINEUPEXTEND:=2303,SCI_LINEUPRECTEXTEND:=2427,SCI_LINESCROLLUP:=2343,SCI_PARADOWN:=2413
,SCI_PARADOWNEXTEND:=2414,SCI_PARAUP:=2415,SCI_PARAUPEXTEND:=2416,SCI_CHARLEFT:=2304,SCI_CHARLEFTEXTEND:=2305,SCI_CHARLEFTRECTEXTEND:=2428
,SCI_CHARRIGHT:=2306,SCI_CHARRIGHTEXTEND:=2307,SCI_CHARRIGHTRECTEXTEND:=2429,SCI_WORDLEFT:=2308,SCI_WORDLEFTEXTEND:=2309,SCI_WORDRIGHT:=2310
,SCI_WORDRIGHTEXTEND:=2311,SCI_WORDLEFTEND:=2439,SCI_WORDLEFTENDEXTEND:=2440,SCI_WORDRIGHTEND:=2441,SCI_WORDRIGHTENDEXTEND:=2442
,SCI_WORDPARTLEFT:=2390,SCI_WORDPARTLEFTEXTEND:=2391,SCI_WORDPARTRIGHT:=2392,SCI_WORDPARTRIGHTEXTEND:=2393,SCI_HOME:=2312
,SCI_HOMEEXTEND:=2313,SCI_HOMERECTEXTEND:=2430,SCI_HOMEDISPLAY:=2345,SCI_HOMEDISPLAYEXTEND:=2346,SCI_HOMEWRAP:=2349
,SCI_HOMEWRAPEXTEND:=2450,SCI_VCHOME:=2331,SCI_VCHOMEEXTEND:=2332,SCI_VCHOMERECTEXTEND:=2431,SCI_VCHOMEWRAP:=2453,SCI_VCHOMEWRAPEXTEND:=2454
,SCI_LINEEND:=2314,SCI_LINEENDEXTEND:=2315,SCI_LINEENDRECTEXTEND:=2432,SCI_LINEENDDISPLAY:=2347,SCI_LINEENDDISPLAYEXTEND:=2348
,SCI_LINEENDWRAP:=2451,SCI_LINEENDWRAPEXTEND:=2452,SCI_DOCUMENTSTART:=2316,SCI_DOCUMENTSTARTEXTEND:=2317,SCI_DOCUMENTEND:=2318
,SCI_DOCUMENTENDEXTEND:=2319,SCI_PAGEUP:=2320,SCI_PAGEUPEXTEND:=2321,SCI_PAGEUPRECTEXTEND:=2433,SCI_PAGEDOWN:=2322,SCI_PAGEDOWNEXTEND:=2323
,SCI_PAGEDOWNRECTEXTEND:=2434,SCI_STUTTEREDPAGEUP:=2435,SCI_STUTTEREDPAGEUPEXTEND:=2436,SCI_STUTTEREDPAGEDOWN:=2437
,SCI_STUTTEREDPAGEDOWNEXTEND:=2438,SCI_DELETEBACK:=2326,SCI_DELETEBACKNOTLINE:=2344,SCI_DELWORDLEFT:=2335,SCI_DELWORDRIGHT:=2336
,SCI_DELLINELEFT:=2395,SCI_DELLINERIGHT:=2396,SCI_LINEDELETE:=2338,SCI_LINECUT:=2337,SCI_LINECOPY:=2455,SCI_LINETRANSPOSE:=2339
,SCI_LINEDUPLICATE:=2404,SCI_LOWERCASE:=2340,SCI_UPPERCASE:=2341,SCI_CANCEL:=2325,SCI_EDITTOGGLEOVERTYPE:=2324,SCI_NEWLINE:=2329
,SCI_FORMFEED:=2330,SCI_TAB:=2327,SCI_BACKTAB:=2328,SCI_SELECTIONDUPLICATE:=2469,SCI_SCROLLTOSTART:=2628,SCI_SCROLLTOEND:=2629
,SCI_DELWORDRIGHTEND:=2518,SCI_VERTICALCENTRECARET:=2619,SCI_MOVESELECTEDLINESUP:=2620,SCI_MOVESELECTEDLINESDOWN:=2621
,SC_TIME_FOREVER:=10000000,SC_WRAP_NONE:=0,SC_WRAP_WORD:=1,SC_WRAP_CHAR:=2,SC_WRAPVISUALFLAG_NONE:=0x0000,SC_WRAPVISUALFLAG_END:=0x0001
,SC_WRAPVISUALFLAG_START:=0x0002,SC_WRAPVISUALFLAG_MARGIN:=0x0004, SC_WRAPVISUALFLAGLOC_DEFAULT:=0x0000,SC_WRAPVISUALFLAGLOC_END_BY_TEXT:=0x0001
,SC_WRAPVISUALFLAGLOC_START_BY_TEXT:=0x0002,SC_CACHE_NONE:=0,SC_CACHE_CARET:=1,SC_CACHE_PAGE:=2,SC_CACHE_DOCUMENT:=3,EDGE_NONE:=0,EDGE_LINE:=1
,EDGE_BACKGROUND:=2,SC_CURSORNORMAL:=-1,SC_CURSORWAIT:=4,VISIBLE_SLOP:=0x01,VISIBLE_STRICT:=0x04,CARET_SLOP:=0x01,CARET_STRICT:=0x04
,CARET_JUMPS:=0x10,CARET_EVEN:=0x08,SC_SEL_STREAM:=0,SC_SEL_RECTANGLE:=1,SC_SEL_LINES:=2,SC_ALPHA_TRANSPARENT:=0,SC_ALPHA_OPAQUE:=255
,SC_ALPHA_NOALPHA:=256,KEYWORDSET_MAX:=8,SC_MOD_INSERTTEXT:=0x1,SC_MOD_DELETETEXT:=0x2,SC_MOD_CHANGESTYLE:=0x4,SC_MOD_CHANGEFOLD:=0x8
,SC_PERFORMED_USER:=0x10,SC_PERFORMED_UNDO:=0x20,SC_PERFORMED_REDO:=0x40,SC_MULTISTEPUNDOREDO:=0x80,SC_LASTSTEPINUNDOREDO:=0x100
,SC_MOD_CHANGEMARKER:=0x200,SC_MOD_BEFOREINSERT:=0x400,SC_MOD_BEFOREDELETE:=0x800,SC_MULTILINEUNDOREDO:=0x1000,SC_MODEVENTMASKALL:=0x1FFF
,SC_WEIGHT_NORMAL:=400, SC_WEIGHT_SEMIBOLD:=600, SC_WEIGHT_BOLD:=700
}

}

Code: Select all

SetScintilla(n) { 
    Sci[n].SetLexer(200) ; SCLEX_AHKL
    Sci[n].SetCodePage(65001)
    Sci[n].SetWrapMode(WordWrap)

    ; Indentation
    Sci[n].SetIndent(TabSize)
    Sci[n].SetTabWidth(TabSize)
    Sci[n].SetUseTabs(True) ; Indent with spaces
    Sci[n].SetIndentationGuides(g_IndentGuides ? 3 : 0)

    Sci[n].MarginLen := 0
    SciSetStyle(n, Sci.FontName, Sci.FontSize)    
    Sci[n].Notify := "OnWM_NOTIFY"
    Sci[n].SetExtraAscent(2) ; Increase space between lines

    ; Autocomplete settings
    Sci[n].AutoCSetIgnoreCase(True)
    Sci[n].AutoCSetMaxHeight(g_AutoCMaxItems)
    Sci[n].AutoCSetOrder(1) ; SC_ORDER_PERFORMSORT

    ; Calltip settings
    Sci[n].CalltipSetFore(CvtClr(0x000000))
    Sci[n].CalltipSetBack(CvtClr(0xFFFFDD))
    Sci[n].SetMouseDwellTime(1000) ; Hover time

    Sci[n].AssignCmdKey(SCK_END, SCI_LINEENDWRAP)
    Sci[n].AssignCmdKey(SCK_HOME, SCI_HOMEWRAP)

    If (g_ShowSymbols) {
        g_ShowSymbols := False
        GoSub ToggleSymbols
    }
}

IsBrace(n) {
    ; Return true for the (,),[,],{,},<,> character codes
    if n in 40,41,91,93,123,125,60,62
        return true
    else
        return false
}

SciSetStyle(n, FontName := "Lucida Console", FontSize := 10) {
    Sci[n].StyleSetFont(STYLE_DEFAULT, FontName, 2)
    Sci[n].StyleSetSize(STYLE_DEFAULT, FontSize)

    Sci[n].StyleSetBack(STYLE_DEFAULT, CvtClr(0xFAFAFA))
    Sci[n].StyleClearAll() ; This message sets all styles to have the same attributes as STYLE_DEFAULT.

    ; Active line background color
    Sci[n].SetCaretLineBack(CvtClr(g_HighlightActiveLine ? 0xD8F3FF : 0xFFFFFF))
    Sci[n].SetCaretLineVisible(True)
    Sci[n].SetCaretLineVisibleAlways(1)

    ; Margin settings
    Sci[n].SetMarginTypeN(0, 1)
    SetLineNumberWidth(n)
    Sci[n].SetMarginLeft(0, 2) ; Left padding
    Sci[n].SetMarginWidthN(1, 2) ; Line number right margin
    Sci[n].StyleSetFore(33, CvtClr(0xCFD2CA)) ; Margin foreground color
    Sci[n].StyleSetBack(33, CvtClr(0xFFFFFF)) ; Margin background color

    ; Matching braces
    Sci[n].StyleSetFore(STYLE_BRACELIGHT, CvtClr(0x000000))
    Sci[n].StyleSetBack(STYLE_BRACELIGHT, CvtClr(0xFFFF00))
    Sci[n].StyleSetBold(STYLE_BRACELIGHT, True)
    Sci[n].StyleSetFore(STYLE_BRACEBAD, CvtClr(0xFF0000))

    ; Selection
    Sci[n].SetSelFore(1, CvtClr(0xFFFFFF))
    Sci[n].SetSelBack(1, CvtClr(0x3399FF))

    If (SyntaxHighlighting) {
        ; AHK syntax elements
        Sci[n].StyleSetFore(SCE_AHKL_IDENTIFIER     , CvtClr(0x000000))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTDOC     , CvtClr(0x008888))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTLINE    , CvtClr(0x969896))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTBLOCK   , CvtClr(0x969896))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTKEYWORD , CvtClr(0xA50000))
        Sci[n].StyleSetFore(SCE_AHKL_STRING         , CvtClr(0x183691))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGOPTS     , CvtClr(0x0000EE))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGBLOCK    , CvtClr(0x183691))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGCOMMENT  , CvtClr(0xFF0000))
        Sci[n].StyleSetFore(SCE_AHKL_LABEL          , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_HOTKEY         , CvtClr(0x00AADD))
        Sci[n].StyleSetFore(SCE_AHKL_HOTSTRING      , CvtClr(0x00BBBB))
        Sci[n].StyleSetFore(SCE_AHKL_HOTSTRINGOPT   , CvtClr(0x990099))
        Sci[n].StyleSetFore(SCE_AHKL_HEXNUMBER      , CvtClr(0x880088))
        Sci[n].StyleSetFore(SCE_AHKL_DECNUMBER      , CvtClr(0x606870))
        Sci[n].StyleSetFore(SCE_AHKL_VAR            , CvtClr(0x9F1F6F))
        Sci[n].StyleSetFore(SCE_AHKL_VARREF         , CvtClr(0x990055))
        Sci[n].StyleSetFore(SCE_AHKL_OBJECT         , CvtClr(0x008888))
        Sci[n].StyleSetFore(SCE_AHKL_USERFUNCTION   , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_DIRECTIVE      , CvtClr(0x0000CF))
        Sci[n].StyleSetFore(SCE_AHKL_COMMAND        , CvtClr(0x0080C0))
        Sci[n].StyleSetFore(SCE_AHKL_PARAM          , CvtClr(0x0080C0))
        Sci[n].StyleSetFore(SCE_AHKL_CONTROLFLOW    , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_BUILTINFUNCTION, CvtClr(0x0F707F))
        Sci[n].StyleSetFore(SCE_AHKL_BUILTINVAR     , CvtClr(0x9F1F6F))
        Sci[n].StyleSetFore(SCE_AHKL_KEY            , CvtClr(0xA2A2A2))
        ;Sci[n].StyleSetFore(SCE_AHKL_USERDEFINED1   , CvtClr(0x000000))
        ;Sci[n].StyleSetFore(SCE_AHKL_USERDEFINED2   , CvtClr(0x000000))
        Sci[n].StyleSetFore(SCE_AHKL_ESCAPESEQ      , CvtClr(0x660000))
        ;Sci[n].StyleSetFore(SCE_AHKL_ERROR          , 0xFF0000)

        ; Keywords
        Sci[n].SetKeywords(0, Keywords.Directives, 2)
        Sci[n].SetKeywords(1, Keywords.Commands, 2)
        Sci[n].SetKeywords(2, Keywords.Parameters, 2)
        Sci[n].SetKeywords(3, Keywords.ControlFlow, 2)
        Sci[n].SetKeywords(4, Keywords.Functions, 2)
        Sci[n].SetKeywords(5, Keywords.BuiltinVariables, 2)
        Sci[n].SetKeywords(6, Keywords.Keys, 2)
        ;Sci[n].SetKeywords(7, Keywords.UserDefined1, 2)
        ;Sci[n].SetKeywords(8, Keywords.UserDefined2, 2)
    }
}

NewTab:
    NewTab()
Return

NewTab() {
    Static TabCounter := 1
    TabCounter++
    TabIndex := TabEx.GetCount() + 1
    Sci[TabIndex] := New Scintilla
    x := (DesignMode) ? 169 : 7
    Sci[TabIndex].Add(hAutoWnd, x, 60, 1576, 1420, SciLexer, 0x50010000, 0)
    SetScintilla(TabIndex)
    TabEx.SetIcon(TabEx.Add("Untitled " . TabCounter), 1)
    TabEx.SetSel(TabIndex)
    GoSub AutoSize
    Sci[TabIndex].Number := TabCounter ; Untitled number
    Return TabIndex
}

NewFromTemplate:
    n := TabEx.GetSel()
    If (n == g_GuiTab || Sci[n].GetModify() || Sci[n].FileName != "") {
        n := NewTab()    
    }
    
    Template := A_WinDir . "\ShellNew\Template.ahk"

    If (FileExist(Template) && !GetKeyState("Shift", "P")) {
        FileRead Template, %Template%
    } Else {
        Template := 
        (LTrim
            "#NoEnv
            #Warn
            #SingleInstance Force
            SetWorkingDir %A_ScriptDir%
            SendMode Input
            SetBatchLines -1"
        )
        Template .= CRLF
    }

    Sci[n].SetText("", Template . CRLF, 2)
    Sci[n].GoToPos(10000)
Return

DuplicateTab:
    n := TabEx.GetSel()
    nLen := Sci[n].GetText(Sci[n].GetLength() + 1, SciText)
    Sci[n].GetText(nLen + 1, SciText)
    Sci[NewTab()].SetText("", SciText, 2)
Return

CloseTab:
    CloseTab(TabEx.GetSel())
Return

CloseTabN:
    CloseTab(g_TabIndex)
Return

CloseTab(TabIndex) {
    If (Sci[TabIndex].GetModify()) {
        TabEx.SetSel(TabIndex)
        TabCaption := TabEx.GetText(TabIndex)
        Gui Auto: +OwnDialogs
        MsgBox 0x33, %TabCaption%, The file was modified. Do you want to save it?
        IfMsgBox Yes, {
            If (!Save()) {
                Return
            }
        } Else IfMsgBox Cancel, {
            Return
        }
    }

    If (TabIndex == g_GuiTab) {
        Gui %Child%: Destroy
        g_GuiTab := 0
        g_GuiSB := False
        SetStatusBar()
    }

    If (TabEx.GetCount() > 1) {
        SendMessage 0x1308, % TabIndex - 1, 0,, ahk_id %hTab% ; TCM_DELETEITEM
        DestroyWindow(Sci[TabIndex].hWnd)
        Sci.Remove(TabIndex)
        If (TabIndex > 1) {
            TabIndex -= 1    
        }
    } Else {
        ClearFile(1)
    }

    TabEx.SetSel(TabIndex)
}

ClearFile(n) {
    Sci[n].FullFileName := ""
    Sci[n].FileName := ""
    Sci[n].Modified := ""
    Sci[n].ClearAll()
    Sci[n].SetSavePoint()
    TabEx.SetIcon(n, 1)
}

ToggleReadOnly() {
    ToggleReadOnly:
    n := TabEx.GetSel()
    ReadOnly := !Sci[n].GetReadOnly()
    sci[n].SetReadOnly(ReadOnly)
    Menu AutoOptionsMenu, ToggleCheck, &Read Only
    SendMessage TB_CHECKBUTTON, 2170, ReadOnly,, ahk_id %hEditorTB%
    If (WinActive("ahk_id" . hAutoWnd)) {
        If (ReadOnly) {
            SB_SetText("Read only", 3)
        } Else {
            If (Sci[n].GetModify()) {
                SB_SetText("Modified", 3)
            } Else {
                SB_SetText("", 3)
            }
        }
    }
    Return
}

ToggleWordWrap() {
    n := TabEx.GetSel()
    WordWrap := !Sci[n].GetWrapMode()
    Sci[n].SetWrapMode(WordWrap)
    Menu AutoOptionsMenu, ToggleCheck, &Wrap Long Lines ; &Word Wrap
    SendMessage TB_CHECKBUTTON, 2160, WrapMode,, ahk_id %hEditorTB%
}

ToggleLineNumbers:
    LineNumbers := !LineNumbers

    Loop % Sci.MaxIndex() {
        SetLineNumberWidth(A_Index)
    }

    Menu AutoOptionsMenu, ToggleCheck, &Line Numbering
Return

ToggleSyntaxHighlighting:
    SyntaxHighlighting := !SyntaxHighlighting

    If (SyntaxHighlighting) {
        Loop % Sci.Length() {
            SciSetStyle(A_Index, Sci.FontName, Sci.FontSize)
        }
    } Else {
        Loop % Sci.Length() {
            Sci[A_Index].StyleClearAll()
            Sci[A_Index].StyleSetFore(33, CvtClr(0xCFD2CA)) ; Margin foreground color
            Sci[A_Index].StyleSetBack(33, CvtClr(0xFFFFFF)) ; Margin background color
        }
    }

    Menu AutoOptionsMenu, ToggleCheck, Syntax &Highlighting
    SendMessage TB_CHECKBUTTON, 2180, %SyntaxHighlighting%,, ahk_id %hEditorTB%
Return

ToggleAutoComplete:
    g_AutoCEnabled := !g_AutoCEnabled
    Menu AutoOptionsMenu, ToggleCheck, &Code Completion ; &Autocompletion
Return

ToggleCalltips:
    g_Calltips := !g_Calltips
    Menu AutoOptionsMenu, ToggleCheck, Code &ToolTips ; &Calltips
Return

ToggleAutoBrackets:
    AutoBrackets := !AutoBrackets
    Menu AutoOptionsMenu, ToggleCheck, Autoclose &Brackets
Return

Undo:
    Sci[TabEx.GetSel()].Undo()
Return

Redo:
    Sci[TabEx.GetSel()].Redo()
Return

Cut:
    Sci[TabEx.GetSel()].Cut()
Return

Copy:
    Sci[TabEx.GetSel()].Copy()
Return

Paste:
    Sci[TabEx.GetSel()].Paste()
Return

Clear:
    Sci[TabEx.GetSel()].Clear()
Return

SelectAll:
    Sci[TabEx.GetSel()].SelectAll()
Return

Lowercase:
    Sci[TabEx.GetSel()].LowerCase()
Return

Uppercase:
    Sci[TabEx.GetSel()].UpperCase()
Return

TitleCase:
    n := TabEx.GetSel()
    Start := Sci[n].GetSelectionStart()
    End := Sci[n].GetSelectionEnd()
    Sci[n].GetTextRange([Start, End], Selection)
    StringUpper Selection, Selection, T
    Sci[n].ReplaceSel("", Selection, 2)
    Sci[n].SetSel(Start, End)
Return

OnWM_NOTIFY(wParam, lParam, msg, hWnd, obj) {
    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()

    If (obj.SCNCode == SCN_UPDATEUI) {
        ; The updated field is set to the bit set of things changed since the previous notification.
        ; SC_UPDATE_CONTENT 	0x01 	Contents, styling or markers have been changed.
        ; SC_UPDATE_SELECTION 	0x02 	Selection has been changed.
        ; SC_UPDATE_V_SCROLL 	0x04 	Scrolled vertically.
        ; SC_UPDATE_H_SCROLL 	0x08 	Scrolled horizontally.

        If (obj.updated < 4 && g_HighlightIdenticalText) {
            Sci[n].SetIndicatorCurrent(2)
            Sci[n].IndicatorClearRange(0, Sci[n].GetLength())

            WordStartPos := Sci[n].WordStartPosition(caretPos, True)
            WordEndPos := Sci[n].WordEndPosition(caretPos, True)
            SelStart := Sci[n].GetSelectionStart()
            SelEnd := Sci[n].GetSelectionEnd()
            If (SelStart != SelEnd && WordStartPos == SelStart && WordEndPos == SelEnd) {
                HighlightIdenticalText(GetSelectedText())
            }
        }
        ; Brace Matching
        ; Has the caret changed position?
        If (lastCaretPos != caretPos) {
            lastCaretPos := caretPos
            bracePos1 := -1
            bracePos2 := -1
        }
            ; Is there a brace to the left or right?
            If (caretPos > 0 && IsBrace(Sci[n].GetCharAt(caretPos - 1)))
            {
                bracePos1 := (caretPos -1)
            }
            Else If (IsBrace(Sci[n].GetCharAt(caretPos)))
                bracePos1 := caretPos

            If (bracePos1 >= 0) {
                ; Find the matching brace
                bracePos2 := Sci[n].BraceMatch(bracePos1)
                If (bracePos2 = Invalid_Position) {
                    Sci[n].BraceBadLight(bracePos1)
                    Sci[n].SetHighlightGuide(0)
                }
                Else {
                    Sci[n].BraceHighlight(bracePos1, bracePos2)
                    Sci[n].SetHighlightGuide(Sci[n].GetColumn(bracePos1))
                }
            }
            Else {
                ; Turn off brace matching
                Sci[n].BraceHighlight(Invalid_Position, Invalid_Position)
                Sci[n].SetHighlightGuide(0)
            }

        ; bm := Sci[n].BraceMatch(caretPos - 1, 0)

        ; If (bm != -1) {
        ;     Sci[n].BraceHighlight(caretPos - 1, bm)
        ; } Else {
        ;     Sci[n].BraceHighlight(-1, Sci[n].GetLength())
        ; }

        UpdateStatusBar()

    } Else If (obj.SCNCode == SCN_MODIFIED) {

        UpdateStatusBar()
        SetLineNumberWidth(n)

    } Else If (obj.SCNCode == SCN_SAVEPOINTREACHED) {

        SetDocumentStatus(n)

    } Else If (obj.SCNCode == SCN_SAVEPOINTLEFT) {

        SetDocumentStatus(n)

    } Else If (obj.SCNCode == SCN_CHARADDED) {

        If (g_AutoCEnabled) {
            AutoComplete(g_AutoCMinLength)
        }

        If (g_Calltips && (obj.ch == 40 || obj.ch == 44 || obj.ch == 32)) {
            WordPos := GetCurrentWord(Word, caretPos - 1)
            Calltip := GetCalltip(Word)
            If (Word != "If") {
                ShowCalltip(n, Calltip, WordPos[1])
            }
        }

        If (!AutoBrackets) {
            Return
        }

        PrevChar := Sci[n].GetCharAt(caretPos - 2)
        NextChar := Sci[n].GetCharAt(caretPos)

        ; Autoclose brackets ([{""}])
        If (obj.ch == 40 && NextChar != 41) { ; Parenthesis
            Sci[n].InsertText(caretPos, ")", 2)
        } Else If (obj.ch == 91 && NextChar != 93) { ; Brackets
            Sci[n].InsertText(caretPos, "]", 2)
        } Else If (obj.ch == 123 && NextChar != 125) { ; Braces
            Sci[n].GetTextRange([caretPos - 5, caretPos], PrevChars)
            If (RegExMatch(PrevChars, "\(\)\s?\n?")) {
                Sci[n].InsertText(caretPos, CRLF . Indent . CRLF . "}", 2)
                Sci[n].GoToPos(caretPos + 2 + TabSize)
            } Else {
                Sci[n].InsertText(caretPos, "}", 2)
            }
        } Else If (obj.ch == 34  ; Quotes
            && (NextChar == 0
            || NextChar == 9     ; Tab
            || NextChar == 32    ; Space
            || NextChar == 33    ; Exclamation mark
            || NextChar == 41    ; Close parenthesis
            || NextChar == 44    ; Comma
            || NextChar == 46    ; Period
            || NextChar == 58    ; Colon
            || NextChar == 59    ; Semicolon
            || NextChar == 63    ; Question mark
            || NextChar == 93    ; Right bracket
            || NextChar == 125)  ; Right brace
            && (PrevChar == 0
            || PrevChar == 9
            || PrevChar == 10    ; New line
            || PrevChar == 32
            || PrevChar == 40    ; Open parenthesis
            || PrevChar == 91    ; Left bracket
            || PrevChar == 123)) ; Left brace
        {
            Sci[n].InsertText(caretPos, """", 2)
        }
    } Else If (obj.SCNCode == SCN_AUTOCCOMPLETED) {

        Keyword := StrGet(obj.Text,, "UTF-8")

        If (g_AutoCWin32Const) {
            ConstValue := LookupConstant(Keyword)
            Sci[n].InsertText(caretPos, " := " . ConstValue, 2)
            Sci[n].GoToPos(caretPos + StrLen(" := " . ConstValue))
            g_AutoCWin32Const := False
        } Else {
            If (g_Calltips && Keyword != "GuiClose") {
                CallTip := GetCallTip(Keyword, True)
                ShowCalltip(n, CallTip, GetWordPos()[1])
            }
        }

    } Else If (obj.SCNCode == SCN_AUTOCCANCELLED) {

        g_AutoCWin32Const := False

    } Else If (obj.SCNCode == SCN_DWELLSTART) {

        If (g_Calltips) {
            If (obj.position != -1) {
                WordPos := GetCurrentWord(Word, obj.position)
                ShowCalltip(n, GetCalltip(Word, False), WordPos[1])
            }
        }

    } Else If (obj.SCNCode == SCN_DWELLEND) {

        Sci[n].CalltipCancel()

    } Else If (obj.SCNCode == SCN_CALLTIPCLICK) {

        ; The position field is set to 1 if the click is in an up arrow, 2 if in a down arrow, and 0 if elsewhere.
        If (obj.position == 0) {
            InsertCalltip()
            Return
        } Else If (obj.position == 1) {
            g_CalltipParamsIndex--
        } Else {
            g_CalltipParamsIndex++
        }

        If ((obj.position == 1 && g_CalltipParamsIndex > 1) 
        || (g_CalltipParams.Length() == g_CalltipParamsIndex)) {
            Arrow := 1 ; Up arrow
        } Else {
            Arrow := 2 ; Down arrow
        }

        WordStartPos := Sci[n].WordStartPosition(caretPos - 1, True)

        Sci[n].CalltipShow(WordStartPos, Chr(Arrow) . g_CalltipParams[g_CalltipParamsIndex], 2)

    } Else If (obj.SCNCode == SCN_ZOOM) {
        Sci[n].MarginLen := 0
        SetLineNumberWidth(n)
    }

    Return
}

ShowGoToLineDialog:
    Line := InputBoxEx("Line Number:", "", "Go to Line", "", "", "x94 w80 Number", 270,,, hAutoWnd, "", "") - 1
    If (!ErrorLevel) {
        ShowChildWindow(0)

        n := TabEx.GetSel()
        Sci[n].GrabFocus()
        Sci[n].GoToLine(Line) ; 0-based index

        LineCount := Sci[n].GetLineCount()
        VisCenterLine := Sci[n].LinesOnScreen() // 2
    
        If (VisCenterLine < (LineCount - Line)) {
            Sci[n].VerticalCentreCaret()
        } Else {
            Sci[n].ScrolltoEnd()
        }
    }
Return

ChangeEditorFont:
    FontName := Sci.FontName
    FontSize := Sci.FontSize
    If (ChooseFont(FontName, FontSize, "", "0x000000", 0, hAutoWnd)) {
        Loop % Sci.MaxIndex() {
            Sci[A_Index].MarginLen := 0
            SciSetStyle(A_Index, FontName, FontSize)
            ;Sci[A_Index].StyleSetFont(STYLE_DEFAULT, FontName, 2)
            ;Sci[A_Index].StyleSetSize(STYLE_DEFAULT, FontSize)
        }
        Sci.FontName := FontName
        Sci.FontSize := FontSize
    }
Return

ZoomIn:
    Sci[TabEx.GetSel()].ZoomIn()
Return

ZoomOut:
    Sci[TabEx.GetSel()].ZoomOut()
Return

ResetFontSize:
    Sci[TabEx.GetSel()].SetZoom(0)
Return

; Called from SCN_UPDATEUI, SCN_MODIFIED, TabHandler and SetStatusBar
UpdateStatusBar() {
    If (!g_GuiSB) {
        n := TabEx.GetSel()
        caretPos := Sci[n].GetCurrentPos()
        Line := Sci[n].LineFromPosition(caretPos) + 1
        Column := Sci[n].GetColumn(caretPos) + 1

        Gui Auto: Default
        SB_SetText(Line . ":" . Column, 2)

        If (Sci[n].GetReadOnly()) {
            SB_SetText("Read only", 3)
        } Else If (Sci[n].GetModify()) {
            SB_SetText("Modified", 3)
        } Else {
            SB_SetText("", 3)
        }
    }
}

; Called from SCN_SAVEPOINTREACHED, SCN_SAVEPOINTLEFT and NewWindow
SetDocumentStatus(n) {
    Gui Auto: Default
    n := TabEx.GetSel()

    If (Sci[n].GetReadOnly()) {
        If (!g_GuiSB) {
            SB_SetText("Read only", 3)
        }
    } Else If (Sci[n].GetModify()) {
        GuiControl -Redraw, %hTab%
        GuiControl Disable, %hTab%
        TabCaption := (Sci[n].FileName != "") ? Sci[n].FileName . " *" : "Untitled " . Sci[n].Number . " *"
        TabEx.SetText(n, TabCaption)
        GuiControl +Redraw, %hTab%
        GuiControl Enable, %hTab%

        If (!g_GuiSB) {
            SB_SetText("Modified", 3)
        }
    } Else {
        GuiControl -Redraw, %hTab%
        GuiControl Disable, %hTab%
        TabCaption := (Sci[n].FileName != "") ? Sci[n].FileName : "Untitled " . Sci[n].Number
        TabEx.SetText(n, TabCaption)
        GuiControl +Redraw, %hTab%
        GuiControl Enable, %hTab%

        If (!g_GuiSB) {
            SB_SetText("", 3)
        }
    }
}

InsertDateTime:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    FormatTime TimeString, D1    
    Sci[n].InsertText(CurrentPos, "" . TimeString, 2)
    Sci[n].GoToPos(CurrentPos + StrPut(TimeString, "UTF-8") - 1)
Return

; Show spaces, tabs and line breaks
ToggleSymbols:
    g_ShowSymbols := !g_ShowSymbols

    Loop % Sci.MaxIndex() {
        Sci[A_Index].2086(g_ShowSymbols ? 2 : 0) ; SCI_SETWHITESPACESIZE
        Sci[A_Index].SetViewWS(g_ShowSymbols)
        Sci[A_Index].SetViewEOL(g_ShowSymbols)
    }

    Menu AutoOptionsMenu, % g_ShowSymbols ? "Check" : "Uncheck", &Show Whitespaces
Return

ToggleComment:
    n := TabEx.GetSel()
    SelText := GetSelectedText()

    If (SelText == "") {
        SelText := GetCurrentLine()
        CurrPos := Sci[n].GetCurrentPos()
        LineNum := Sci[n].LineFromPosition(CurrPos)
        StartPos := Sci[n].PositionFromLine(LineNum) ; Start of the line
        EndPos := Sci[n].GetLineEndPosition(LineNum)
        Sci[n].SetSel(StartPos, EndPos) ; Select current line
        RestorePos := True ; Restore caret position
    } Else {
        RestorePos := False
    }

    Lines := ""
    Loop Parse, SelText, `n, `r
    {
        If (RegExMatch(A_LoopField, "^\s*\;")) {
            Line := RegExReplace(A_LoopField, "\;", "", "", 1)
        } Else If (A_LoopField == "") {
            Line := ""
        } Else {
            Line := ";" . A_LoopField
        }
        Lines .= Line . CRLF
    }

    Lines := RegExReplace(Lines, "`r`n$", "", "", 1)
    SetSelectedText(Lines)

    If (RestorePos) {
        Sci[n].GoToPos(CurrPos)
    }
Return

GetCurrentLine() {
    n := TabEx.GetSel()
    LineNum := Sci[n].LineFromPosition(Sci[n].GetCurrentPos())
    LineLen := Sci[n].LineLength(LineNum)
	VarSetCapacity(LineText, LineLen, 0)
    Sci[n].GetCurLine(LineLen + 1, LineText)
    Sci[n].GetCurLine(LineLen + 1, LineText)
    Return RTrim(LineText, CRLF)
}

DuplicateLine:
    Sci[TabEx.GetSel()].LineDuplicate()
Return

TransposeLine:
    Sci[TabEx.GetSel()].LineTranspose()    
Return

LoadXML(FileName) {
    Static x
    x := ComObjCreate("MSXML2.DOMDocument.6.0")
    x.async := False
    x.load(FileName)
    Return x
}

LoadAutoComplete(FileName) {
    Static XMLLoaded := False

    If (!XMLLoaded) {
        g_AutoCXMLObj := LoadXML(FileName)

        Keys := g_AutoCXMLObj.getElementsByTagName("key")
        For Key in Keys {
        	g_AutoCList .= key.getAttribute("name") . " "
        }

        g_AutoCList := RTrim(g_AutoCList, " ")

        XMLLoaded := True
    }
}

AutoComplete(MinLength := 3, Filter := "") {
    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()    

    WordStartPos := Sci[n].WordStartPosition(caretPos, True)
    LengthEntered := caretPos - WordStartPos
    WordFirstChar := Sci[n].GetCharAt(WordStartPos - 1)

    If (WordFirstChar == 35 || WordFirstChar == 46) { ; # .
        LengthEntered++
    }

    If ((LengthEntered >= MinLength) && !Sci[n].AutoCActive()) {
        Sci[n].AutoCShow(LengthEntered, "" . g_AutoCList, 2)
    }
}

AutoCompleteWin32() {
    Static Items

    If (!IsObject(g_AutoCWin32XMLObj)) {
        g_AutoCWin32XMLObj := LoadXML(A_ScriptDir . "\Tools\Windows.xml")
        Items := g_AutoCWin32XMLObj.getElementsByTagName("item")
    }

    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()
    WordStartPos := Sci[n].WordStartPosition(caretPos, True)
    LengthEntered := caretPos - WordStartPos
    Sci[n].GetTextRange([WordStartPos, caretPos], TempText)

    ConstList := ""
    For Item in Items {
        Const := Item.getAttribute("const")
        If (InStr(Const, TempText) == 1) {
            ConstList .= Const . " "
        }
    }

    If ((LengthEntered >= 0) && !Sci[n].AutoCActive()) {
        Sci[n].AutoCShow(LengthEntered, RTrim(ConstList), 2)
    }

    If (Sci[n].AutoCActive()) {
        g_AutoCWin32Const := True    
    }
}

GetCallTip(Keyword, Overload := True) {
    RegExMatch(" " . g_AutoCList . " ", "i) " . Keyword . " ", Keyword)
    Keyword := Trim(Keyword)
    Node := g_AutoCXMLObj.selectSingleNode("//key[@name=""" . Keyword . """]")
/*
    If (Keyword == "Hotkey" || Keyword == "Progress") {
        VarSetCapacity(LineText, 100)
        Sci[TabEx.GetSel()].GetCurLine(100, LineText)
        If (RegExMatch(LineText, "i)\s*Gui")) {
            Return
        }
    }
*/
    Params := Node.selectNodes("params")
    g_CalltipParams := []
    Loop % Params.length {
        Calltip := Params.item(A_Index - 1).text
        Separator := (SubStr(Calltip, 1, 1) != "(") ? " " : ""
        g_CalltipParams.Push(Keyword . Separator . Calltip)
    }

    If (Params.item(0).text != "") {
        Return (Overload && Params.length > 1) ? Chr(2) . g_CalltipParams[1] : g_CalltipParams[1]
    }
}

ShowCalltip(n, Calltip, StartPos) {
    If (CallTip != "") {
        Sci[n].CalltipShow(StartPos, CallTip, 2)
        Return g_CalltipParamsIndex := 1
    }
}

InsertCalltip() {
    n := TabEx.GetSel()
    If (Sci[n].AutoCActive()) {
        Sci[n].AutoCComplete()
    }
    
    EndPos := GetCurrentWord(Word)[2]
    GetCalltip(Word, False)
    Calltip := StrReplace(g_CalltipParams[g_CalltipParamsIndex], Word,,, 1)
    
    NextChar := Chr(Sci[n].GetCharAt(EndPos))
    If (NextChar == " " || NextChar == ",") {
        Sci[n].2645(EndPos, 1) ; SCI_DELETERANGE
    }
    
    Sci[n].InsertText(EndPos, Calltip, 2)
    Sci[n].WordRight()
    Sci[n].CalltipCancel()
}

GetCurrentWord(ByRef Word, Pos := -1) {
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    PrevChar := Chr(Sci[n].GetCharAt(CurrentPos - 1))
    If (PrevChar == " " || PrevChar == ",") {
        CurrentPos--
    }
    CurrentPos := (Pos == -1) ? CurrentPos : Pos
    WordStartPos := Sci[n].WordStartPosition(CurrentPos, True)
    PrevChar := Chr(Sci[n].GetCharAt(WordStartPos - 1))
    If (PrevChar == "#" || PrevChar == ".") {
        WordStartPos--
    }
    WordEndPos := Sci[n].WordEndPosition(CurrentPos, True)
    Sci[n].GetTextRange([WordStartPos, WordEndPos], Word)
    Return [WordStartPos, WordEndPos]
}

GetSelectedText() {
    n := TabEx.GetSel()
    Start := Sci[n].GetSelectionStart()
    End := Sci[n].GetSelectionEnd()
    Sci[n].GetTextRange([Start, End], SelText)
    Return SelText
}

SetSelectedText(Text) {
    Sci[TabEx.GetSel()].ReplaceSel("", Text, 2)
}

; SCI_WORDSTARTPOSITION(int pos, bool onlyWordCharacters) → int
GetWordPos() {
    n := TabEx.GetSel()
    Pos := Sci[n].GetCurrentPos()
    WordStartPos := Sci[n].WordStartPosition(Pos, True)
    PrevChar := Chr(Sci[n].GetCharAt(WordStartPos - 1))
    If (PrevChar == "#" || PrevChar == ".") {
        WordStartPos--
    }
    WordEndPos := Sci[n].WordEndPosition(Pos, True)
    Return [WordStartPos, WordEndPos]
}

MarkSelectedText:
    n := TabEx.GetSel()
    Sci[n].SetIndicatorCurrent(1)

    SelStart := Sci[n].GetSelectionStart()
    SelEnd := Sci[n].GetSelectionEnd()

    ; Unmark if marked
    If ((Sci[n].IndicatorAllOnFor(SelStart) & 2) == 2) {
        Sci[n].IndicatorClearRange(SelStart, SelEnd - SelStart)
        Return
    }

    Sci[n].IndicSetStyle(1, INDIC_ROUNDBOX)
    Sci[n].IndicSetFore(1, CvtClr(0x3FBBE3))
    Sci[n].IndicSetOutlineAlpha(1, 255) ; Opaque border
    Sci[n].IndicSetAlpha(1, 80)
    Sci[n].IndicatorFillRange(SelStart, SelEnd - SelStart)
    Sci[n].SetSel(-1, Sci[n].GetCurrentPos())
Return

ClearAllMarks:
    n := TabEx.GetSel()
    Sci[n].SetIndicatorCurrent(1)
    Sci[n].IndicatorClearRange(0, Sci[n].GetLength())
Return

GoToNextMark:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    Marks := GetMarks()

    LineCount := Sci[n].GetLineCount()
    VisCenterLine := Sci[n].LinesOnScreen() // 2

    Loop % Marks.Length() {
        If (Marks[A_Index] > CurrentPos) {
            Sci[n].GoToPos(Marks[A_Index])

            MarkLine := Sci[n].LineFromPosition(Marks[A_Index])

            If (VisCenterLine < (LineCount - MarkLine)) {
                Sci[n].VerticalCentreCaret()
            } Else {
                Sci[n].ScrolltoEnd()
            }

            Break
        }
    }
Return

GoToPreviousMark:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    Marks := GetMarks()
    Max := Marks.Length()

    Loop %Max% {
        Index := Max - A_Index + 1
        If (Marks[Index] < CurrentPos) {
            Sci[n].GoToPos(Marks[Index])
            Sci[n].VerticalCentreCaret()
            Break
        }
    }
Return

; SCI_INDICATORALLONFOR: Retrieve a bitmap value representing which indicators are non-zero at a position.
GetMarks() {
    n := TabEx.GetSel()
    StartPos := 0
    EndPos := 0
    Max := Sci[n].GetLength()
    Marks := []

    Loop {
        StartPos := Sci[n].IndicatorStart(1, EndPos)
        EndPos := Sci[n].IndicatorEnd(1, StartPos)

        If ((Sci[n].IndicatorAllOnFor(StartPos) & 2) == 2) {
            Marks.Push(EndPos)
        }
    } Until !(EndPos != 0 && EndPos < Max)

    Return Marks
}

ToggleHighlightActiveLine:
    g_HighlightActiveLine := !g_HighlightActiveLine

    ActiveLineColor := g_HighlightActiveLine ? 0xD8F3FF : 0xFFFFFF
    Loop % Sci.MaxIndex() {
        Sci[A_Index].SetCaretLineBack(CvtClr(ActiveLineColor))
    }

    Menu AutoOptionsMenu, % g_HighlightActiveLine ? "Check" : "Uncheck", Highlight &Active Line
Return

ToggleIndentGuides:
    g_IndentGuides := !g_IndentGuides

    IndentView := g_IndentGuides ? 3 : 0 ; 3 = SC_IV_LOOKBOTH

    Loop % Sci.MaxIndex() {
        Sci[A_Index].SetIndentationGuides(IndentView)
    }

    Menu AutoOptionsMenu, ToggleCheck, &Indentation Guides
Return

SetLineNumberWidth(n) {
    If (LineNumbers) {
        LineCount := Sci[n].GetLineCount()
        LineCountLen := StrLen(LineCount)
        If (LineCountLen < 2) {
            LineCountLen := 2
        }

        If (LineCountLen != Sci[n].MarginLen) {
            Sci[n].MarginLen := LineCountLen
    
            If (LineCount < 100) {
                String := "99"
            } Else {
                String := ""
                LineCountLen := StrLen(LineCount)
                Loop %LineCountLen% {
                    String .= "9"
                }
            }

            PixelWidth := Sci[n].TextWidth(STYLE_LINENUMBER, "" . String, 2) + 6
            Sci[n].SetMarginWidthN(0, PixelWidth)
        }
    } Else {
        Sci[n].SetMarginWidthN(0, 0)
        Sci[n].MarginLen := 0
    }
}

HighlightIdenticalText(String) {
    n := TabEx.GetSel()
    SelEnd := Sci[n].GetSelectionEnd()

    Sci[n].SetIndicatorCurrent(2)
    Sci[n].IndicSetStyle(2, 8) ; INDIC_STRAIGHTBOX
    Sci[n].IndicSetFore(2, CvtClr(0x3FBBE3))
    Sci[n].IndicSetOutlineAlpha(2, 80) ; Opaque border
    Sci[n].IndicSetAlpha(2, 80)

    TextLength := Sci[n].GetLength()
    Sci[n].SetTargetStart(0)
    Sci[n].SetTargetEnd(TextLength)
    StringLength := StrPut(String, "UTF-8") - 1

    While (Sci[n].SearchInTarget(StringLength, "" . String, 2) != -1) {
        TargetStart := Sci[n].GetTargetStart()
        TargetEnd := Sci[n].GetTargetEnd()
        If (TargetEnd != SelEnd) {
            Sci[n].IndicatorFillRange(TargetStart, TargetEnd - TargetStart)
        }

        Sci[n].SetTargetStart(TargetEnd)
        Sci[n].SetTargetEnd(TextLength)
    }
}

ToggleHighlightIdenticalText:
    g_HighlightIdenticalText := !g_HighlightIdenticalText
    Sci[n].SetIndicatorCurrent(2)
    Sci[n].IndicatorClearRange(0, Sci[n].GetLength())
    Menu AutoOptionsMenu, ToggleCheck, Highlight Identical Te&xt
Return

Rorqual
Posts: 10
Joined: 14 Jan 2017, 13:23

Re: AutoGUI - GUI Designer and Script Editor

18 Feb 2017, 15:47

I added code folding to the autogui editor

it works by clicking the + and - boxes only for now, hotkeys aren't yet added, nor menu items for fold all/expand all yet, just to get this started..

Image

Code: Select all

SetScintilla(n) { 
    Sci[n].SetLexer(200) ; SCLEX_AHKL
    Sci[n].SetWrapMode(WordWrap)
    Sci[n].SetCodePage(65001)

    ; Code Folding
    Sci[n].SetProperty("fold", "1")
    Sci[n].SetProperty("fold.compact", "1")

    ; Indentation
    Sci[n].SetIndent(TabSize)
    Sci[n].SetTabWidth(TabSize)
    Sci[n].SetUseTabs(True) ; Indent with spaces
    Sci[n].SetIndentationGuides(g_IndentGuides ? 3 : 0)

    Sci[n].MarginLen := 0
    SciSetStyle(n, Sci.FontName, Sci.FontSize)    
    Sci[n].Notify := "OnWM_NOTIFY"
    Sci[n].SetExtraAscent(2) ; Increase space between lines

    ; Autocomplete settings
    Sci[n].AutoCSetIgnoreCase(True)
    Sci[n].AutoCSetMaxHeight(g_AutoCMaxItems)
    Sci[n].AutoCSetOrder(1) ; SC_ORDER_PERFORMSORT

    ; Calltip settings
    Sci[n].CalltipSetFore(CvtClr(0x000000))
    Sci[n].CalltipSetBack(CvtClr(0xFFFFDD))
    Sci[n].SetMouseDwellTime(1000) ; Hover time

    Sci[n].AssignCmdKey(SCK_END, SCI_LINEENDWRAP)
    Sci[n].AssignCmdKey(SCK_HOME, SCI_HOMEWRAP)

    If (g_ShowSymbols) {
        g_ShowSymbols := False
        GoSub ToggleSymbols
    }
}

IsBrace(n) {
    ; Return true for the (,),[,],{,},<,> character codes
    if n in 40,41,91,93,123,125,60,62
        return true
    else
        return false
}

SciSetStyle(n, FontName := "Lucida Console", FontSize := 10) {
    Sci[n].StyleSetFont(STYLE_DEFAULT, FontName, 2)
    Sci[n].StyleSetSize(STYLE_DEFAULT, FontSize)

    Sci[n].StyleSetBack(STYLE_DEFAULT, CvtClr(0xFAFAFA))
    Sci[n].StyleClearAll() ; This message sets all styles to have the same attributes as STYLE_DEFAULT.

    ; Active line background color
    Sci[n].SetCaretLineBack(CvtClr(g_HighlightActiveLine ? 0xD8F3FF : 0xFFFFFF))
    Sci[n].SetCaretLineVisible(True)
    Sci[n].SetCaretLineVisibleAlways(1)

    ; Margin settings
    ; Sci[n].SetMarginTypeN(0, 1)
    ; SetLineNumberWidth(n)
    ; Sci[n].SetMarginLeft(0, 2) ; Left padding
    ; Sci[n].SetMarginWidthN(1, 2) ; Line number right margin
    ; Sci[n].StyleSetFore(33, CvtClr(0xCFD2CA)) ; Margin foreground color
    ; Sci[n].StyleSetBack(33, CvtClr(0xFFFFFF)) ; Margin background color

    Sci[n].StyleClearAll()
    Sci[n].StyleSetSize(32, 9) ; Font settings
    Sci[n].SetMarginWidthN(0, 40) ; Line number
    Sci[n].SetMarginWidthN(1, 20) ; Foldemargin
    ;Sci[n].StyleSetFore(33, CvtClr(0xCBCBAB)) ; Foreground color
    ;Sci[n].StyleSetBack(33, CvtClr(0x333333)) ; Background color
    Sci[n].SetMarginMaskN(1, SC_MASK_FOLDERS) ; Show folding symbols
    Sci[n].SetMarginSensitiveN(1, true) ; Catch Margin click notifications
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDER, SC_MARK_BOXPLUS)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDER, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDER, 0x000000)
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDEROPEN, SC_MARK_BOXMINUS)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDEROPEN, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDEROPEN, 0x000000)
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDERSUB, SC_MARK_VLINE)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDERSUB, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDERSUB, 0x000000)
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDERTAIL, SC_MARK_LCORNER)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDERTAIL, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDERTAIL, 0x000000)
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDEREND, SC_MARK_BOXPLUSCONNECTED)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDEREND, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDEREND, 0x000000)
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDEROPENMID, SC_MARK_BOXMINUSCONNECTED)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDEROPENMID, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDEROPENMID, 0x000000)
    Sci[n].MarkerDefine(SC_MARKNUM_FOLDERMIDTAIL, SC_MARK_TCORNER)
    Sci[n].MarkerSetFore(SC_MARKNUM_FOLDERMIDTAIL, 0xFFFFFF)
    Sci[n].MarkerSetBack(SC_MARKNUM_FOLDERMIDTAIL, 0x000000)

    ; Matching braces
    Sci[n].StyleSetFore(STYLE_BRACELIGHT, CvtClr(0x000000))
    Sci[n].StyleSetBack(STYLE_BRACELIGHT, CvtClr(0xFFFF00))
    Sci[n].StyleSetBold(STYLE_BRACELIGHT, True)
    Sci[n].StyleSetFore(STYLE_BRACEBAD, CvtClr(0xFF0000))

    ; Selection
    Sci[n].SetSelFore(1, CvtClr(0xFFFFFF))
    Sci[n].SetSelBack(1, CvtClr(0x3399FF))

    If (SyntaxHighlighting) {
        ; AHK syntax elements
        Sci[n].StyleSetFore(SCE_AHKL_IDENTIFIER     , CvtClr(0x000000))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTDOC     , CvtClr(0x008888))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTLINE    , CvtClr(0x969896))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTBLOCK   , CvtClr(0x969896))
        Sci[n].StyleSetFore(SCE_AHKL_COMMENTKEYWORD , CvtClr(0xA50000))
        Sci[n].StyleSetFore(SCE_AHKL_STRING         , CvtClr(0x183691))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGOPTS     , CvtClr(0x0000EE))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGBLOCK    , CvtClr(0x183691))
        Sci[n].StyleSetFore(SCE_AHKL_STRINGCOMMENT  , CvtClr(0xFF0000))
        Sci[n].StyleSetFore(SCE_AHKL_LABEL          , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_HOTKEY         , CvtClr(0x00AADD))
        Sci[n].StyleSetFore(SCE_AHKL_HOTSTRING      , CvtClr(0x00BBBB))
        Sci[n].StyleSetFore(SCE_AHKL_HOTSTRINGOPT   , CvtClr(0x990099))
        Sci[n].StyleSetFore(SCE_AHKL_HEXNUMBER      , CvtClr(0x880088))
        Sci[n].StyleSetFore(SCE_AHKL_DECNUMBER      , CvtClr(0x606870))
        Sci[n].StyleSetFore(SCE_AHKL_VAR            , CvtClr(0x9F1F6F))
        Sci[n].StyleSetFore(SCE_AHKL_VARREF         , CvtClr(0x990055))
        Sci[n].StyleSetFore(SCE_AHKL_OBJECT         , CvtClr(0x008888))
        Sci[n].StyleSetFore(SCE_AHKL_USERFUNCTION   , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_DIRECTIVE      , CvtClr(0x0000CF))
        Sci[n].StyleSetFore(SCE_AHKL_COMMAND        , CvtClr(0x0080C0))
        Sci[n].StyleSetFore(SCE_AHKL_PARAM          , CvtClr(0x0080C0))
        Sci[n].StyleSetFore(SCE_AHKL_CONTROLFLOW    , CvtClr(0x0000DD))
        Sci[n].StyleSetFore(SCE_AHKL_BUILTINFUNCTION, CvtClr(0x0F707F))
        Sci[n].StyleSetFore(SCE_AHKL_BUILTINVAR     , CvtClr(0x9F1F6F))
        Sci[n].StyleSetFore(SCE_AHKL_KEY            , CvtClr(0xA2A2A2))
        ;Sci[n].StyleSetFore(SCE_AHKL_USERDEFINED1   , CvtClr(0x000000))
        ;Sci[n].StyleSetFore(SCE_AHKL_USERDEFINED2   , CvtClr(0x000000))
        Sci[n].StyleSetFore(SCE_AHKL_ESCAPESEQ      , CvtClr(0x660000))
        ;Sci[n].StyleSetFore(SCE_AHKL_ERROR          , 0xFF0000)

        ; Keywords
        Sci[n].SetKeywords(0, Keywords.Directives, 2)
        Sci[n].SetKeywords(1, Keywords.Commands, 2)
        Sci[n].SetKeywords(2, Keywords.Parameters, 2)
        Sci[n].SetKeywords(3, Keywords.ControlFlow, 2)
        Sci[n].SetKeywords(4, Keywords.Functions, 2)
        Sci[n].SetKeywords(5, Keywords.BuiltinVariables, 2)
        Sci[n].SetKeywords(6, Keywords.Keys, 2)
        ;Sci[n].SetKeywords(7, Keywords.UserDefined1, 2)
        ;Sci[n].SetKeywords(8, Keywords.UserDefined2, 2)
    }
}

NewTab:
    NewTab()
Return

NewTab() {
    Static TabCounter := 1
    TabCounter++
    TabIndex := TabEx.GetCount() + 1
    Sci[TabIndex] := New Scintilla
    x := (DesignMode) ? 169 : 7
    Sci[TabIndex].Add(hAutoWnd, x, 60, 1576, 1420, SciLexer, 0x50010000, 0)
    SetScintilla(TabIndex)
    TabEx.SetIcon(TabEx.Add("Untitled " . TabCounter), 1)
    TabEx.SetSel(TabIndex)
    GoSub AutoSize
    Sci[TabIndex].Number := TabCounter ; Untitled number
    Return TabIndex
}

NewFromTemplate:
    n := TabEx.GetSel()
    If (n == g_GuiTab || Sci[n].GetModify() || Sci[n].FileName != "") {
        n := NewTab()    
    }
    
    Template := A_WinDir . "\ShellNew\Template.ahk"

    If (FileExist(Template) && !GetKeyState("Shift", "P")) {
        FileRead Template, %Template%
    } Else {
        Template := 
        (LTrim
            "#NoEnv
            #Warn
            #SingleInstance Force
            SetWorkingDir %A_ScriptDir%
            SendMode Input
            SetBatchLines -1"
        )
        Template .= CRLF
    }

    Sci[n].SetText("", Template . CRLF, 2)
    Sci[n].GoToPos(10000)
Return

DuplicateTab:
    n := TabEx.GetSel()
    nLen := Sci[n].GetText(Sci[n].GetLength() + 1, SciText)
    Sci[n].GetText(nLen + 1, SciText)
    Sci[NewTab()].SetText("", SciText, 2)
Return

CloseTab:
    CloseTab(TabEx.GetSel())
Return

CloseTabN:
    CloseTab(g_TabIndex)
Return

CloseTab(TabIndex) {
    If (Sci[TabIndex].GetModify()) {
        TabEx.SetSel(TabIndex)
        TabCaption := TabEx.GetText(TabIndex)
        Gui Auto: +OwnDialogs
        MsgBox 0x33, %TabCaption%, The file was modified. Do you want to save it?
        IfMsgBox Yes, {
            If (!Save()) {
                Return
            }
        } Else IfMsgBox Cancel, {
            Return
        }
    }

    If (TabIndex == g_GuiTab) {
        Gui %Child%: Destroy
        g_GuiTab := 0
        g_GuiSB := False
        SetStatusBar()
    }

    If (TabEx.GetCount() > 1) {
        SendMessage 0x1308, % TabIndex - 1, 0,, ahk_id %hTab% ; TCM_DELETEITEM
        DestroyWindow(Sci[TabIndex].hWnd)
        Sci.Remove(TabIndex)
        If (TabIndex > 1) {
            TabIndex -= 1    
        }
    } Else {
        ClearFile(1)
    }

    TabEx.SetSel(TabIndex)
}

ClearFile(n) {
    Sci[n].FullFileName := ""
    Sci[n].FileName := ""
    Sci[n].Modified := ""
    Sci[n].ClearAll()
    Sci[n].SetSavePoint()
    TabEx.SetIcon(n, 1)
}

ToggleReadOnly() {
    ToggleReadOnly:
    n := TabEx.GetSel()
    ReadOnly := !Sci[n].GetReadOnly()
    sci[n].SetReadOnly(ReadOnly)
    Menu AutoOptionsMenu, ToggleCheck, &Read Only
    SendMessage TB_CHECKBUTTON, 2170, ReadOnly,, ahk_id %hEditorTB%
    If (WinActive("ahk_id" . hAutoWnd)) {
        If (ReadOnly) {
            SB_SetText("Read only", 3)
        } Else {
            If (Sci[n].GetModify()) {
                SB_SetText("Modified", 3)
            } Else {
                SB_SetText("", 3)
            }
        }
    }
    Return
}

ToggleWordWrap() {
    n := TabEx.GetSel()
    WordWrap := !Sci[n].GetWrapMode()
    Sci[n].SetWrapMode(WordWrap)
    Menu AutoOptionsMenu, ToggleCheck, &Wrap Long Lines ; &Word Wrap
    SendMessage TB_CHECKBUTTON, 2160, WrapMode,, ahk_id %hEditorTB%
}

ToggleLineNumbers:
    LineNumbers := !LineNumbers

    Loop % Sci.MaxIndex() {
        SetLineNumberWidth(A_Index)
    }

    Menu AutoOptionsMenu, ToggleCheck, &Line Numbering
Return

ToggleSyntaxHighlighting:
    SyntaxHighlighting := !SyntaxHighlighting

    If (SyntaxHighlighting) {
        Loop % Sci.Length() {
            SciSetStyle(A_Index, Sci.FontName, Sci.FontSize)
        }
    } Else {
        Loop % Sci.Length() {
            Sci[A_Index].StyleClearAll()
            Sci[A_Index].StyleSetFore(33, CvtClr(0xCFD2CA)) ; Margin foreground color
            Sci[A_Index].StyleSetBack(33, CvtClr(0xFFFFFF)) ; Margin background color
        }
    }

    Menu AutoOptionsMenu, ToggleCheck, Syntax &Highlighting
    SendMessage TB_CHECKBUTTON, 2180, %SyntaxHighlighting%,, ahk_id %hEditorTB%
Return

ToggleAutoComplete:
    g_AutoCEnabled := !g_AutoCEnabled
    Menu AutoOptionsMenu, ToggleCheck, &Code Completion ; &Autocompletion
Return

ToggleCalltips:
    g_Calltips := !g_Calltips
    Menu AutoOptionsMenu, ToggleCheck, Code &ToolTips ; &Calltips
Return

ToggleAutoBrackets:
    AutoBrackets := !AutoBrackets
    Menu AutoOptionsMenu, ToggleCheck, Autoclose &Brackets
Return

Undo:
    Sci[TabEx.GetSel()].Undo()
Return

Redo:
    Sci[TabEx.GetSel()].Redo()
Return

Cut:
    Sci[TabEx.GetSel()].Cut()
Return

Copy:
    Sci[TabEx.GetSel()].Copy()
Return

Paste:
    Sci[TabEx.GetSel()].Paste()
Return

Clear:
    Sci[TabEx.GetSel()].Clear()
Return

SelectAll:
    Sci[TabEx.GetSel()].SelectAll()
Return

Lowercase:
    Sci[TabEx.GetSel()].LowerCase()
Return

Uppercase:
    Sci[TabEx.GetSel()].UpperCase()
Return

TitleCase:
    n := TabEx.GetSel()
    Start := Sci[n].GetSelectionStart()
    End := Sci[n].GetSelectionEnd()
    Sci[n].GetTextRange([Start, End], Selection)
    StringUpper Selection, Selection, T
    Sci[n].ReplaceSel("", Selection, 2)
    Sci[n].SetSel(Start, End)
Return

OnWM_NOTIFY(wParam, lParam, msg, hWnd, obj) {
    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()

    If (obj.SCNCode == SCN_UPDATEUI) {
        ; The updated field is set to the bit set of things changed since the previous notification.
        ; SC_UPDATE_CONTENT 	0x01 	Contents, styling or markers have been changed.
        ; SC_UPDATE_SELECTION 	0x02 	Selection has been changed.
        ; SC_UPDATE_V_SCROLL 	0x04 	Scrolled vertically.
        ; SC_UPDATE_H_SCROLL 	0x08 	Scrolled horizontally.

        If (obj.updated < 4 && g_HighlightIdenticalText) {
            Sci[n].SetIndicatorCurrent(2)
            Sci[n].IndicatorClearRange(0, Sci[n].GetLength())

            WordStartPos := Sci[n].WordStartPosition(caretPos, True)
            WordEndPos := Sci[n].WordEndPosition(caretPos, True)
            SelStart := Sci[n].GetSelectionStart()
            SelEnd := Sci[n].GetSelectionEnd()
            If (SelStart != SelEnd && WordStartPos == SelStart && WordEndPos == SelEnd) {
                HighlightIdenticalText(GetSelectedText())
            }
        }
        ; Brace Matching
        ; Has the caret changed position?
        If (lastCaretPos != caretPos) {
            lastCaretPos := caretPos
            bracePos1 := -1
            bracePos2 := -1
        }
            ; Is there a brace to the left or right?
            If (caretPos > 0 && IsBrace(Sci[n].GetCharAt(caretPos - 1)))
            {
                bracePos1 := (caretPos -1)
            }
            Else If (IsBrace(Sci[n].GetCharAt(caretPos)))
                bracePos1 := caretPos

            If (bracePos1 >= 0) {
                ; Find the matching brace
                bracePos2 := Sci[n].BraceMatch(bracePos1)
                If (bracePos2 = Invalid_Position) {
                    Sci[n].BraceBadLight(bracePos1)
                    Sci[n].SetHighlightGuide(0)
                }
                Else {
                    Sci[n].BraceHighlight(bracePos1, bracePos2)
                    Sci[n].SetHighlightGuide(Sci[n].GetColumn(bracePos1))
                }
            }
            Else {
                ; Turn off brace matching
                Sci[n].BraceHighlight(Invalid_Position, Invalid_Position)
                Sci[n].SetHighlightGuide(0)
            }

        ; bm := Sci[n].BraceMatch(caretPos - 1, 0)

        ; If (bm != -1) {
        ;     Sci[n].BraceHighlight(caretPos - 1, bm)
        ; } Else {
        ;     Sci[n].BraceHighlight(-1, Sci[n].GetLength())
        ; }

        UpdateStatusBar()

    } Else If (obj.SCNCode == SCN_MODIFIED) {

        UpdateStatusBar()
        SetLineNumberWidth(n)

    } Else If (obj.SCNCode == SCN_SAVEPOINTREACHED) {

        SetDocumentStatus(n)

    } Else If (obj.SCNCode == SCN_SAVEPOINTLEFT) {

        SetDocumentStatus(n)

    } Else If (obj.SCNCode == SCN_CHARADDED) {

        If (g_AutoCEnabled) {
            AutoComplete(g_AutoCMinLength)
        }

        If (g_Calltips && (obj.ch == 40 || obj.ch == 44 || obj.ch == 32)) {
            WordPos := GetCurrentWord(Word, caretPos - 1)
            Calltip := GetCalltip(Word)
            If (Word != "If") {
                ShowCalltip(n, Calltip, WordPos[1])
            }
        }

        If (!AutoBrackets) {
            Return
        }

        PrevChar := Sci[n].GetCharAt(caretPos - 2)
        NextChar := Sci[n].GetCharAt(caretPos)

        ; Autoclose brackets ([{""}])
        If (obj.ch == 40 && NextChar != 41) { ; Parenthesis
            Sci[n].InsertText(caretPos, ")", 2)
        } Else If (obj.ch == 91 && NextChar != 93) { ; Brackets
            Sci[n].InsertText(caretPos, "]", 2)
        } Else If (obj.ch == 123 && NextChar != 125) { ; Braces
            Sci[n].GetTextRange([caretPos - 5, caretPos], PrevChars)
            If (RegExMatch(PrevChars, "\(\)\s?\n?")) {
                Sci[n].InsertText(caretPos, CRLF . Indent . CRLF . "}", 2)
                Sci[n].GoToPos(caretPos + 2 + TabSize)
            } Else {
                Sci[n].InsertText(caretPos, "}", 2)
            }
        } Else If (obj.ch == 34  ; Quotes
            && (NextChar == 0
            || NextChar == 9     ; Tab
            || NextChar == 32    ; Space
            || NextChar == 33    ; Exclamation mark
            || NextChar == 41    ; Close parenthesis
            || NextChar == 44    ; Comma
            || NextChar == 46    ; Period
            || NextChar == 58    ; Colon
            || NextChar == 59    ; Semicolon
            || NextChar == 63    ; Question mark
            || NextChar == 93    ; Right bracket
            || NextChar == 125)  ; Right brace
            && (PrevChar == 0
            || PrevChar == 9
            || PrevChar == 10    ; New line
            || PrevChar == 32
            || PrevChar == 40    ; Open parenthesis
            || PrevChar == 91    ; Left bracket
            || PrevChar == 123)) ; Left brace
        {
            Sci[n].InsertText(caretPos, """", 2)
        }
    } Else If (obj.SCNCode == SCN_AUTOCCOMPLETED) {

        Keyword := StrGet(obj.Text,, "UTF-8")

        If (g_AutoCWin32Const) {
            ConstValue := LookupConstant(Keyword)
            Sci[n].InsertText(caretPos, " := " . ConstValue, 2)
            Sci[n].GoToPos(caretPos + StrLen(" := " . ConstValue))
            g_AutoCWin32Const := False
        } Else {
            If (g_Calltips && Keyword != "GuiClose") {
                CallTip := GetCallTip(Keyword, True)
                ShowCalltip(n, CallTip, GetWordPos()[1])
            }
        }

    } Else If (obj.SCNCode == SCN_AUTOCCANCELLED) {

        g_AutoCWin32Const := False

    } Else If (obj.SCNCode == SCN_DWELLSTART) {

        If (g_Calltips) {
            If (obj.position != -1) {
                WordPos := GetCurrentWord(Word, obj.position)
                ShowCalltip(n, GetCalltip(Word, False), WordPos[1])
            }
        }

    } Else If (obj.SCNCode == SCN_DWELLEND) {

        Sci[n].CalltipCancel()

    } Else If (obj.SCNCode == SCN_CALLTIPCLICK) {

        ; The position field is set to 1 if the click is in an up arrow, 2 if in a down arrow, and 0 if elsewhere.
        If (obj.position == 0) {
            InsertCalltip()
            Return
        } Else If (obj.position == 1) {
            g_CalltipParamsIndex--
        } Else {
            g_CalltipParamsIndex++
        }

        If ((obj.position == 1 && g_CalltipParamsIndex > 1) 
        || (g_CalltipParams.Length() == g_CalltipParamsIndex)) {
            Arrow := 1 ; Up arrow
        } Else {
            Arrow := 2 ; Down arrow
        }

        WordStartPos := Sci[n].WordStartPosition(caretPos - 1, True)

        Sci[n].CalltipShow(WordStartPos, Chr(Arrow) . g_CalltipParams[g_CalltipParamsIndex], 2)

    } Else If (obj.SCNCode == SCN_ZOOM) {
        Sci[n].MarginLen := 0
        SetLineNumberWidth(n)
    } Else If (obj.SCNCode == SCN_MARGINCLICK) {
         Sci[n].TOGGLEFOLD(Sci[n].LINEFROMPOSITION(obj.position)) ; Get the line the margin click was made on and toggle folding
    }

    Return
}

ShowGoToLineDialog:
    Line := InputBoxEx("Line Number:", "", "Go to Line", "", "", "x94 w80 Number", 270,,, hAutoWnd, "", "") - 1
    If (!ErrorLevel) {
        ShowChildWindow(0)

        n := TabEx.GetSel()
        Sci[n].GrabFocus()
        Sci[n].GoToLine(Line) ; 0-based index

        LineCount := Sci[n].GetLineCount()
        VisCenterLine := Sci[n].LinesOnScreen() // 2
    
        If (VisCenterLine < (LineCount - Line)) {
            Sci[n].VerticalCentreCaret()
        } Else {
            Sci[n].ScrolltoEnd()
        }
    }
Return

ChangeEditorFont:
    FontName := Sci.FontName
    FontSize := Sci.FontSize
    If (ChooseFont(FontName, FontSize, "", "0x000000", 0, hAutoWnd)) {
        Loop % Sci.MaxIndex() {
            Sci[A_Index].MarginLen := 0
            SciSetStyle(A_Index, FontName, FontSize)
            ;Sci[A_Index].StyleSetFont(STYLE_DEFAULT, FontName, 2)
            ;Sci[A_Index].StyleSetSize(STYLE_DEFAULT, FontSize)
        }
        Sci.FontName := FontName
        Sci.FontSize := FontSize
    }
Return

ZoomIn:
    Sci[TabEx.GetSel()].ZoomIn()
Return

ZoomOut:
    Sci[TabEx.GetSel()].ZoomOut()
Return

ResetFontSize:
    Sci[TabEx.GetSel()].SetZoom(0)
Return

; Called from SCN_UPDATEUI, SCN_MODIFIED, TabHandler and SetStatusBar
UpdateStatusBar() {
    If (!g_GuiSB) {
        n := TabEx.GetSel()
        caretPos := Sci[n].GetCurrentPos()
        Line := Sci[n].LineFromPosition(caretPos) + 1
        Column := Sci[n].GetColumn(caretPos) + 1

        Gui Auto: Default
        SB_SetText(Line . ":" . Column, 2)

        If (Sci[n].GetReadOnly()) {
            SB_SetText("Read only", 3)
        } Else If (Sci[n].GetModify()) {
            SB_SetText("Modified", 3)
        } Else {
            SB_SetText("", 3)
        }
    }
}

; Called from SCN_SAVEPOINTREACHED, SCN_SAVEPOINTLEFT and NewWindow
SetDocumentStatus(n) {
    Gui Auto: Default
    n := TabEx.GetSel()

    If (Sci[n].GetReadOnly()) {
        If (!g_GuiSB) {
            SB_SetText("Read only", 3)
        }
    } Else If (Sci[n].GetModify()) {
        GuiControl -Redraw, %hTab%
        GuiControl Disable, %hTab%
        TabCaption := (Sci[n].FileName != "") ? Sci[n].FileName . " *" : "Untitled " . Sci[n].Number . " *"
        TabEx.SetText(n, TabCaption)
        GuiControl +Redraw, %hTab%
        GuiControl Enable, %hTab%

        If (!g_GuiSB) {
            SB_SetText("Modified", 3)
        }
    } Else {
        GuiControl -Redraw, %hTab%
        GuiControl Disable, %hTab%
        TabCaption := (Sci[n].FileName != "") ? Sci[n].FileName : "Untitled " . Sci[n].Number
        TabEx.SetText(n, TabCaption)
        GuiControl +Redraw, %hTab%
        GuiControl Enable, %hTab%

        If (!g_GuiSB) {
            SB_SetText("", 3)
        }
    }
}

InsertDateTime:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    FormatTime TimeString, D1    
    Sci[n].InsertText(CurrentPos, "" . TimeString, 2)
    Sci[n].GoToPos(CurrentPos + StrPut(TimeString, "UTF-8") - 1)
Return

; Show spaces, tabs and line breaks
ToggleSymbols:
    g_ShowSymbols := !g_ShowSymbols

    Loop % Sci.MaxIndex() {
        Sci[A_Index].2086(g_ShowSymbols ? 2 : 0) ; SCI_SETWHITESPACESIZE
        Sci[A_Index].SetViewWS(g_ShowSymbols)
        Sci[A_Index].SetViewEOL(g_ShowSymbols)
    }

    Menu AutoOptionsMenu, % g_ShowSymbols ? "Check" : "Uncheck", &Show Whitespaces
Return

ToggleComment:
    n := TabEx.GetSel()
    SelText := GetSelectedText()

    If (SelText == "") {
        SelText := GetCurrentLine()
        CurrPos := Sci[n].GetCurrentPos()
        LineNum := Sci[n].LineFromPosition(CurrPos)
        StartPos := Sci[n].PositionFromLine(LineNum) ; Start of the line
        EndPos := Sci[n].GetLineEndPosition(LineNum)
        Sci[n].SetSel(StartPos, EndPos) ; Select current line
        RestorePos := True ; Restore caret position
    } Else {
        RestorePos := False
    }

    Lines := ""
    Loop Parse, SelText, `n, `r
    {
        If (RegExMatch(A_LoopField, "^\s*\;")) {
            Line := RegExReplace(A_LoopField, "\;", "", "", 1)
        } Else If (A_LoopField == "") {
            Line := ""
        } Else {
            Line := ";" . A_LoopField
        }
        Lines .= Line . CRLF
    }

    Lines := RegExReplace(Lines, "`r`n$", "", "", 1)
    SetSelectedText(Lines)

    If (RestorePos) {
        Sci[n].GoToPos(CurrPos)
    }
Return

GetCurrentLine() {
    n := TabEx.GetSel()
    LineNum := Sci[n].LineFromPosition(Sci[n].GetCurrentPos())
    LineLen := Sci[n].LineLength(LineNum)
	VarSetCapacity(LineText, LineLen, 0)
    Sci[n].GetCurLine(LineLen + 1, LineText)
    Sci[n].GetCurLine(LineLen + 1, LineText)
    Return RTrim(LineText, CRLF)
}

DuplicateLine:
    Sci[TabEx.GetSel()].LineDuplicate()
Return

TransposeLine:
    Sci[TabEx.GetSel()].LineTranspose()    
Return

LoadXML(FileName) {
    Static x
    x := ComObjCreate("MSXML2.DOMDocument.6.0")
    x.async := False
    x.load(FileName)
    Return x
}

LoadAutoComplete(FileName) {
    Static XMLLoaded := False

    If (!XMLLoaded) {
        g_AutoCXMLObj := LoadXML(FileName)

        Keys := g_AutoCXMLObj.getElementsByTagName("key")
        For Key in Keys {
        	g_AutoCList .= key.getAttribute("name") . " "
        }

        g_AutoCList := RTrim(g_AutoCList, " ")

        XMLLoaded := True
    }
}

AutoComplete(MinLength := 3, Filter := "") {
    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()    

    WordStartPos := Sci[n].WordStartPosition(caretPos, True)
    LengthEntered := caretPos - WordStartPos
    WordFirstChar := Sci[n].GetCharAt(WordStartPos - 1)

    If (WordFirstChar == 35 || WordFirstChar == 46) { ; # .
        LengthEntered++
    }

    If ((LengthEntered >= MinLength) && !Sci[n].AutoCActive()) {
        Sci[n].AutoCShow(LengthEntered, "" . g_AutoCList, 2)
    }
}

AutoCompleteWin32() {
    Static Items

    If (!IsObject(g_AutoCWin32XMLObj)) {
        g_AutoCWin32XMLObj := LoadXML(A_ScriptDir . "\Tools\Windows.xml")
        Items := g_AutoCWin32XMLObj.getElementsByTagName("item")
    }

    n := TabEx.GetSel()
    caretPos := Sci[n].GetCurrentPos()
    WordStartPos := Sci[n].WordStartPosition(caretPos, True)
    LengthEntered := caretPos - WordStartPos
    Sci[n].GetTextRange([WordStartPos, caretPos], TempText)

    ConstList := ""
    For Item in Items {
        Const := Item.getAttribute("const")
        If (InStr(Const, TempText) == 1) {
            ConstList .= Const . " "
        }
    }

    If ((LengthEntered >= 0) && !Sci[n].AutoCActive()) {
        Sci[n].AutoCShow(LengthEntered, RTrim(ConstList), 2)
    }

    If (Sci[n].AutoCActive()) {
        g_AutoCWin32Const := True    
    }
}

GetCallTip(Keyword, Overload := True) {
    RegExMatch(" " . g_AutoCList . " ", "i) " . Keyword . " ", Keyword)
    Keyword := Trim(Keyword)
    Node := g_AutoCXMLObj.selectSingleNode("//key[@name=""" . Keyword . """]")
/*
    If (Keyword == "Hotkey" || Keyword == "Progress") {
        VarSetCapacity(LineText, 100)
        Sci[TabEx.GetSel()].GetCurLine(100, LineText)
        If (RegExMatch(LineText, "i)\s*Gui")) {
            Return
        }
    }
*/
    Params := Node.selectNodes("params")
    g_CalltipParams := []
    Loop % Params.length {
        Calltip := Params.item(A_Index - 1).text
        Separator := (SubStr(Calltip, 1, 1) != "(") ? " " : ""
        g_CalltipParams.Push(Keyword . Separator . Calltip)
    }

    If (Params.item(0).text != "") {
        Return (Overload && Params.length > 1) ? Chr(2) . g_CalltipParams[1] : g_CalltipParams[1]
    }
}

ShowCalltip(n, Calltip, StartPos) {
    If (CallTip != "") {
        Sci[n].CalltipShow(StartPos, CallTip, 2)
        Return g_CalltipParamsIndex := 1
    }
}

InsertCalltip() {
    n := TabEx.GetSel()
    If (Sci[n].AutoCActive()) {
        Sci[n].AutoCComplete()
    }
    
    EndPos := GetCurrentWord(Word)[2]
    GetCalltip(Word, False)
    Calltip := StrReplace(g_CalltipParams[g_CalltipParamsIndex], Word,,, 1)
    
    NextChar := Chr(Sci[n].GetCharAt(EndPos))
    If (NextChar == " " || NextChar == ",") {
        Sci[n].2645(EndPos, 1) ; SCI_DELETERANGE
    }
    
    Sci[n].InsertText(EndPos, Calltip, 2)
    Sci[n].WordRight()
    Sci[n].CalltipCancel()
}

GetCurrentWord(ByRef Word, Pos := -1) {
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    PrevChar := Chr(Sci[n].GetCharAt(CurrentPos - 1))
    If (PrevChar == " " || PrevChar == ",") {
        CurrentPos--
    }
    CurrentPos := (Pos == -1) ? CurrentPos : Pos
    WordStartPos := Sci[n].WordStartPosition(CurrentPos, True)
    PrevChar := Chr(Sci[n].GetCharAt(WordStartPos - 1))
    If (PrevChar == "#" || PrevChar == ".") {
        WordStartPos--
    }
    WordEndPos := Sci[n].WordEndPosition(CurrentPos, True)
    Sci[n].GetTextRange([WordStartPos, WordEndPos], Word)
    Return [WordStartPos, WordEndPos]
}

GetSelectedText() {
    n := TabEx.GetSel()
    Start := Sci[n].GetSelectionStart()
    End := Sci[n].GetSelectionEnd()
    Sci[n].GetTextRange([Start, End], SelText)
    Return SelText
}

SetSelectedText(Text) {
    Sci[TabEx.GetSel()].ReplaceSel("", Text, 2)
}

; SCI_WORDSTARTPOSITION(int pos, bool onlyWordCharacters) → int
GetWordPos() {
    n := TabEx.GetSel()
    Pos := Sci[n].GetCurrentPos()
    WordStartPos := Sci[n].WordStartPosition(Pos, True)
    PrevChar := Chr(Sci[n].GetCharAt(WordStartPos - 1))
    If (PrevChar == "#" || PrevChar == ".") {
        WordStartPos--
    }
    WordEndPos := Sci[n].WordEndPosition(Pos, True)
    Return [WordStartPos, WordEndPos]
}

MarkSelectedText:
    n := TabEx.GetSel()
    Sci[n].SetIndicatorCurrent(1)

    SelStart := Sci[n].GetSelectionStart()
    SelEnd := Sci[n].GetSelectionEnd()

    ; Unmark if marked
    If ((Sci[n].IndicatorAllOnFor(SelStart) & 2) == 2) {
        Sci[n].IndicatorClearRange(SelStart, SelEnd - SelStart)
        Return
    }

    Sci[n].IndicSetStyle(1, INDIC_ROUNDBOX)
    Sci[n].IndicSetFore(1, CvtClr(0x3FBBE3))
    Sci[n].IndicSetOutlineAlpha(1, 255) ; Opaque border
    Sci[n].IndicSetAlpha(1, 80)
    Sci[n].IndicatorFillRange(SelStart, SelEnd - SelStart)
    Sci[n].SetSel(-1, Sci[n].GetCurrentPos())
Return

ClearAllMarks:
    n := TabEx.GetSel()
    Sci[n].SetIndicatorCurrent(1)
    Sci[n].IndicatorClearRange(0, Sci[n].GetLength())
Return

GoToNextMark:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    Marks := GetMarks()

    LineCount := Sci[n].GetLineCount()
    VisCenterLine := Sci[n].LinesOnScreen() // 2

    Loop % Marks.Length() {
        If (Marks[A_Index] > CurrentPos) {
            Sci[n].GoToPos(Marks[A_Index])

            MarkLine := Sci[n].LineFromPosition(Marks[A_Index])

            If (VisCenterLine < (LineCount - MarkLine)) {
                Sci[n].VerticalCentreCaret()
            } Else {
                Sci[n].ScrolltoEnd()
            }

            Break
        }
    }
Return

GoToPreviousMark:
    n := TabEx.GetSel()
    CurrentPos := Sci[n].GetCurrentPos()
    Marks := GetMarks()
    Max := Marks.Length()

    Loop %Max% {
        Index := Max - A_Index + 1
        If (Marks[Index] < CurrentPos) {
            Sci[n].GoToPos(Marks[Index])
            Sci[n].VerticalCentreCaret()
            Break
        }
    }
Return

; SCI_INDICATORALLONFOR: Retrieve a bitmap value representing which indicators are non-zero at a position.
GetMarks() {
    n := TabEx.GetSel()
    StartPos := 0
    EndPos := 0
    Max := Sci[n].GetLength()
    Marks := []

    Loop {
        StartPos := Sci[n].IndicatorStart(1, EndPos)
        EndPos := Sci[n].IndicatorEnd(1, StartPos)

        If ((Sci[n].IndicatorAllOnFor(StartPos) & 2) == 2) {
            Marks.Push(EndPos)
        }
    } Until !(EndPos != 0 && EndPos < Max)

    Return Marks
}

ToggleHighlightActiveLine:
    g_HighlightActiveLine := !g_HighlightActiveLine

    ActiveLineColor := g_HighlightActiveLine ? 0xD8F3FF : 0xFFFFFF
    Loop % Sci.MaxIndex() {
        Sci[A_Index].SetCaretLineBack(CvtClr(ActiveLineColor))
    }

    Menu AutoOptionsMenu, % g_HighlightActiveLine ? "Check" : "Uncheck", Highlight &Active Line
Return

ToggleIndentGuides:
    g_IndentGuides := !g_IndentGuides

    IndentView := g_IndentGuides ? 3 : 0 ; 3 = SC_IV_LOOKBOTH

    Loop % Sci.MaxIndex() {
        Sci[A_Index].SetIndentationGuides(IndentView)
    }

    Menu AutoOptionsMenu, ToggleCheck, &Indentation Guides
Return

SetLineNumberWidth(n) {
    If (LineNumbers) {
        LineCount := Sci[n].GetLineCount()
        LineCountLen := StrLen(LineCount)
        If (LineCountLen < 2) {
            LineCountLen := 2
        }

        If (LineCountLen != Sci[n].MarginLen) {
            Sci[n].MarginLen := LineCountLen
    
            If (LineCount < 100) {
                String := "99"
            } Else {
                String := ""
                LineCountLen := StrLen(LineCount)
                Loop %LineCountLen% {
                    String .= "9"
                }
            }

            PixelWidth := Sci[n].TextWidth(STYLE_LINENUMBER, "" . String, 2) + 6
            Sci[n].SetMarginWidthN(0, PixelWidth)
        }
    } Else {
        Sci[n].SetMarginWidthN(0, 0)
        Sci[n].MarginLen := 0
    }
}

HighlightIdenticalText(String) {
    n := TabEx.GetSel()
    SelEnd := Sci[n].GetSelectionEnd()

    Sci[n].SetIndicatorCurrent(2)
    Sci[n].IndicSetStyle(2, 8) ; INDIC_STRAIGHTBOX
    Sci[n].IndicSetFore(2, CvtClr(0x3FBBE3))
    Sci[n].IndicSetOutlineAlpha(2, 80) ; Opaque border
    Sci[n].IndicSetAlpha(2, 80)

    TextLength := Sci[n].GetLength()
    Sci[n].SetTargetStart(0)
    Sci[n].SetTargetEnd(TextLength)
    StringLength := StrPut(String, "UTF-8") - 1

    While (Sci[n].SearchInTarget(StringLength, "" . String, 2) != -1) {
        TargetStart := Sci[n].GetTargetStart()
        TargetEnd := Sci[n].GetTargetEnd()
        If (TargetEnd != SelEnd) {
            Sci[n].IndicatorFillRange(TargetStart, TargetEnd - TargetStart)
        }

        Sci[n].SetTargetStart(TargetEnd)
        Sci[n].SetTargetEnd(TextLength)
    }
}

ToggleHighlightIdenticalText:
    g_HighlightIdenticalText := !g_HighlightIdenticalText
    Sci[n].SetIndicatorCurrent(2)
    Sci[n].IndicatorClearRange(0, Sci[n].GetLength())
    Menu AutoOptionsMenu, ToggleCheck, Highlight Identical Te&xt
Return

User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: AutoGUI - GUI Designer and Script Editor

27 Feb 2017, 19:38

Thanks for the code and suggestions, Rorqual. A new version of AutoGUI will be released as soon as I finish some tests.
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: AutoGUI - GUI Designer and Script Editor

07 Apr 2017, 22:20

Version 1.3.4:
- Code folding (credits to Rorqual)
- Import GUI: support for tabs (credits to RazorHalo)
- Minor bug fixes

Code folding is disabled by default. To enable it, go to the Options menu and check Code Folding.

:arrow: Download
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: AutoGUI - GUI Designer and Script Editor

13 Apr 2017, 08:25

Version 1.3.5:
- Automatic indentation
- Indentation settings
- Minor bug fixes

A recent screenshot of AutoGUI.
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: AutoGUI - GUI Designer and Script Editor

19 Apr 2017, 18:01

Version 1.4.0:
- File menu > Open Included File. Thanks to Coco for EnumIncludes.
- File menu > Load/Save Session.
- Tools menu > Add/Remove Tools.

Image

:arrow: Download
User avatar
Soft
Posts: 174
Joined: 07 Jan 2015, 13:18
Location: Seoul
Contact:

Re: AutoGUI - GUI Designer and Script Editor

21 Apr 2017, 07:26

impressive, btw why dont you use github? It would be the easier way for pushing updates
AutoHotkey & AutoHotkey_H v1.1.22.07
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: AutoGUI - GUI Designer and Script Editor

21 Apr 2017, 21:26

Soft wrote:impressive, btw why dont you use github? It would be the easier way for pushing updates
+1
Image Image Image Image Image
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Asmodeus
Posts: 57
Joined: 19 Oct 2015, 15:53

Re: AutoGUI - GUI Designer and Script Editor

26 Apr 2017, 17:30

things I miss / or need refinement:

tab sorting by drag & drop
comment out function of selected text in Edit Menu
code completion for second parameter
Image

highlight current parameter
Image
grey out unavailable commands (eg. Clear all Marks, in case there are no marks)
single instance mode, maybe as an option (allow only one AutoGUI instance)
option to save and load last session automatically
duplicate line shortcut

cheers
User avatar
Alguimist
Posts: 428
Joined: 05 Oct 2015, 16:41
Contact:

Re: AutoGUI - GUI Designer and Script Editor

26 Apr 2017, 19:33

Thanks for your suggestions, Asmodeus. The keyboard shortcut to duplicate a line is Ctrl + Down arrow.

Return to “Old Topics”

Who is online

Users browsing this forum: No registered users and 7 guests