Andreik Posted July 14, 2009 Share Posted July 14, 2009 I want to create a BAT File Editor with Scintilla UDF. This is my script:expandcollapse popup#include <_SciLexer.au3> #Include <GuiStatusBar.au3> Global $PATH = "" Global $SBAR Global $EDIT Global $LIST $MAIN = GUICreate("BAT File Editor",700,440,-1,-1,0x16C80000) $MENU_FILE = GUICtrlCreateMenu("&File") $FNEW = GUICtrlCreateMenuItem("New",$MENU_FILE) $OPEN = GUICtrlCreateMenuItem("Open",$MENU_FILE) $SAVE = GUICtrlCreateMenuItem("Save",$MENU_FILE) $MENU_EDIT = GUICtrlCreateMenu("&Edit") $CUT = GUICtrlCreateMenuItem("Cut",$MENU_EDIT) $COPY = GUICtrlCreateMenuItem("Copy",$MENU_EDIT) $PASTE = GUICtrlCreateMenuItem("Paste",$MENU_EDIT) $UNDO = GUICtrlCreateMenuItem("Undo",$MENU_EDIT) $REDO = GUICtrlCreateMenuItem("Redo",$MENU_EDIT) $MENU_TEST = GUICtrlCreateMenu("&Test") $TEST = GUICtrlCreateMenuItem("Run Script",$MENU_TEST) $MENU_INFO = GUICtrlCreateMenu("&Info") $ABOUT = GUICtrlCreateMenuItem("About",$MENU_INFO) $EDIT = Sci_CreateEditor($MAIN,0,0,600,400) $LIST = GUICtrlCreateList("",605,5,90,400,BitOR(0x00100000,0x00200000)) $SBAR = _GUICtrlStatusBar_Create($MAIN) ListSetData() GUISetState(@SW_SHOW,$MAIN) While True $MSG = GUIGetMsg() Switch $MSG Case $FNEW Call("_FileNew_") Case $OPEN Call("_FileOpen_") Case $SAVE Call("_FileSave_") Case $CUT Sci_Cut($EDIT) Case $COPY Sci_Copy($EDIT) Case $PASTE Sci_Paste($EDIT) Case $UNDO Sci_Undo($EDIT) Case $REDO Sci_Redo($EDIT) Case $TEST Call("RunScriptTest") Case $ABOUT Call("About") Case $LIST Sci_InsertText($EDIT,Sci_GetCurrentPos($EDIT),GUICtrlRead($LIST)) Case -3 Call("Quit") EndSwitch Sleep(20) WEnd Func _FileNew_() $WARNING = MsgBox(0x4,"BAT File Editor","Are you sure?") If $WARNING = 6 Then Sci_DelLines($EDIT) $PATH = "" _GUICtrlStatusBar_SetText($SBAR,$PATH) EndIf EndFunc Func _FileOpen_() $PATH = FileOpenDialog("Open",@ScriptDir,"Batch File (*.BAT)",1) If Not @error Then $WARNING = MsgBox(0x4,"BAT File Editor","Are you sure?") If $WARNING = 6 Then Sci_DelLines($EDIT) Local $FILE = FileOpen($PATH,0) $DATA = FileRead($FILE) FileClose($FILE) Sci_AddLines($EDIT,$DATA,1) _GUICtrlStatusBar_SetText($SBAR,$PATH) EndIf EndIf EndFunc Func _FileSave_() If $PATH = "" Then $PATH = FileSaveDialog("Save",@ScriptDir,"Batch File (*.BAT)",16,"MyScript") If Not @error Then $TEXT = Sci_GetText($EDIT) $PATH &= ".BAT" Local $FILE = FileOpen($PATH,2) Local $DATA = FileWrite($FILE,$TEXT) FileClose($FILE) _GUICtrlStatusBar_SetText($SBAR,$PATH) EndIf Else $WARNING = MsgBox(0x4,"BAT File Editor","Are you sure?") If $WARNING = 6 Then $TEXT = Sci_GetText($EDIT) Local $FILE = FileOpen($PATH,2) Local $DATA = FileWrite($FILE,$TEXT) FileClose($FILE) EndIf EndIf EndFunc Func ListSetData() Local $LIST_DATA = "" Local $FILE = FileOpen(@ScriptDir & "\Functions.txt",0) Local $DATA = FileRead($FILE) FileClose($FILE) Local $KEY = StringSplit($DATA," ") If IsArray($KEY) Then For $INDEX = 1 To $KEY[0] $LIST_DATA &= $KEY[$INDEX] & "|" Next EndIf GUICtrlSetData($LIST,$LIST_DATA) EndFunc Func RunScriptTest() $TEXT = Sci_GetText($EDIT) Local $FILE = FileOpen(@TempDir & "\TestScript.BAT",2) Local $DATA = FileWrite($FILE,$TEXT) FileClose($FILE) RunWait(@TempDir & "\TestScript.BAT",@TempDir,@SW_SHOW) EndFunc Func About() MsgBox(0x40,"About","BAT File Editor" & @CRLF & "by __Andy__") EndFunc Func Quit() $WARNING = MsgBox(0x4,"BAT File Editor","Are you sure?") If $WARNING = 6 Then Exit EndFuncWork fine but I downloaded from here configs file but I don't know exactly how to use them with Scintilla for highlighted text and calltips.I work with new UDF by Kip. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Zedna Posted July 14, 2009 Share Posted July 14, 2009 I think you must call Sci_SetLexer($Sci, $iLexer) Look at another examples on the forum using Scite editor. Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Andreik Posted July 14, 2009 Author Share Posted July 14, 2009 I think you must call Sci_SetLexer($Sci, $iLexer) Look at another examples on the forum using Scite editor. Yes Zedna. I use already SendMessage($EDIT,$SCI_SETLEXER,$SCLEX_BATCH, 0).I have 2 files: one with functions and onw with other special words but nothing is highlighted. This is function that should do that. expandcollapse popupFunc InitEditor($Sci) SendMessage($Sci, $SCI_SETLEXER, $SCLEX_BATCH, 0) $bits = SendMessage($Sci, $SCI_GETSTYLEBITSNEEDED, 0, 0) SendMessage($Sci, $SCI_SETSTYLEBITS, $bits, 0) SendMessage($Sci, $SCI_SETTABWIDTH, 4, 0) SendMessage($Sci, $SCI_SETINDENTATIONGUIDES, True, 0) SendMessageString($Sci, $SCI_SETKEYWORDS, 0, FileRead(@ScriptDir & "\Functions.txt")) SendMessageString($Sci, $SCI_SETKEYWORDS, 1, FileRead(@ScriptDir & "\Special.txt")) SendMessage($Sci, $SCI_SETMARGINTYPEN, $MARGIN_SCRIPT_NUMBER, $SC_MARGIN_NUMBER) SendMessage($Sci, $SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_NUMBER, SendMessageString($Sci, $SCI_TEXTWIDTH, $STYLE_LINENUMBER, "_99999")) SendMessage($Sci, $SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_ICON, 16) SendMessage($Sci, $SCI_AUTOCSETSEPARATOR, Asc(@CR), 0) SendMessage($Sci, $SCI_AUTOCSETIGNORECASE, True, 0) SetStyle($Sci, $STYLE_DEFAULT, 0x000000, 0xFFFFFF, 10, "Courier New") SendMessage($Sci, $SCI_STYLECLEARALL, 0, 0) SetStyle($Sci, $STYLE_BRACEBAD, 0x009966, 0xFFFFFF, 0, "", 0, 1) SetStyle($Sci, $SCE_BAT_DEFAULT, 0x000000, 0xFFFFFF) SetStyle($Sci, $SCE_BAT_COMMENT, 0x339900, 0xFFFFFF) SetStyle($Sci, $SCE_BAT_WORD, 0xAA0000, 0xFFFFFF, 0, "", 1, 1) SetProperty($Sci, "fold", "1") SetProperty($Sci, "fold.compact", "1") SetProperty($Sci, "fold.comment", "1") SetProperty($Sci, "fold.preprocessor", "1") SendMessage($Sci, $SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_FOLD, 0); fold margin width=0 SendMessage($Sci, $SCI_SETMARGINTYPEN, $MARGIN_SCRIPT_FOLD, $SC_MARGIN_SYMBOL) SendMessage($Sci, $SCI_SETMARGINMASKN, $MARGIN_SCRIPT_FOLD, $SC_MASK_FOLDERS) SendMessage($Sci, $SCI_SETMARGINWIDTHN, $MARGIN_SCRIPT_FOLD, 20) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDER, $SC_MARK_ARROW) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEROPEN, $SC_MARK_ARROWDOWN) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEREND, $SC_MARK_ARROW) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERMIDTAIL, $SC_MARK_TCORNER) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDEROPENMID, $SC_MARK_ARROWDOWN) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERSUB, $SC_MARK_VLINE) SendMessage($Sci, $SCI_MARKERDEFINE, $SC_MARKNUM_FOLDERTAIL, $SC_MARK_LCORNER) SendMessage($Sci, $SCI_SETFOLDFLAGS, 16, 0) SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDER, 0xFFFFFF) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDERSUB, 0x808080) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDEREND, 0x808080) SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDEREND, 0xFFFFFF) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDERTAIL, 0x808080) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDERMIDTAIL, 0x808080) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDER, 0x808080) SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDEROPEN, 0xFFFFFF) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDEROPEN, 0x808080) SendMessage($Sci, $SCI_MARKERSETFORE, $SC_MARKNUM_FOLDEROPENMID, 0xFFFFFF) SendMessage($Sci, $SCI_MARKERSETBACK, $SC_MARKNUM_FOLDEROPENMID, 0x808080) SendMessage($Sci, $SCI_SETMARGINSENSITIVEN, $MARGIN_SCRIPT_FOLD, 1) SendMessage($Sci, $SCI_MARKERSETBACK, 0, 0x0000FF) GUIRegisterMsg(0x004E, "WM_NOTIFY") If @error Then Return 0 Else Return 1 EndIf EndFunc ;==>InitEditor When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now