Sunaj Posted December 30, 2008 Posted December 30, 2008 FuncHighlightRelease 0.1 (first release)Important Notes: This script is meant to automatically convert the comment line appended to any Function in AutoIt into calltips that are added into the "au3.user.calltips.api" (calltips) file as well as the "au3.UserUdfs.properties" (highlighting) in the AutoIt dir. The program needs to be compiled in order to work in its current incarnation. Have fun and remember to read important warnings in code below. This script makes my life easier.. hope it can do the same for a few other coders out there. If anyone updates this thing I'll be around to update this post accordingly.expandcollapse popup; WARNING 1, do backup any existing "au3.user.calltips.api" & "au3.UserUdfs.properties" files BEFORE USING ; ; WARNING 2, this prog needs to be compiled before it can be used successfully, it will write its path into ; the "..\AutoIt3\SciTE\Properties\au3.properties" file - if you need to uninstall FuncHighlight, or ; change the location of its exe file you'll need to manually edit this file correspondingly. Changes to the ; path of the exe could be automatically corrected but I can't be bothered currently since I'm using the exe ; from the same location always. ; ; Also, this version is meant to work with - ONLY 1 - UserUDF file, if you have so many private user made ; UDFs on your comp. that you need to work with several files this proggie needs a bit of updating in the ; "WriteContent()" area. Please post your code if you manage to do so efficiently. ; ; Simply add a comment line like so: "Func WhateverFunc ; this will be my new calltip" to a Function to have ; FuncHighlight add both highlighting and calltips to it. ; ; Authored by Sunaj ; ; Version 0.1 - (first release) #include <Array.au3> $Au3_install_dir = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt","InstallDir") $File_au3_properties = FileRead($Au3_install_dir & "\SciTE\Properties\au3.properties") $Script_to_work_on = "" $Number_of_funcs = "" Dim $aFunctions[1] Dim $aComments[1] If UBound($CmdLine) > 1 Then ; Ubound($CmdLine) > 1 $Script_to_work_on = $CmdLine[1] ConsoleWrite("FuncHighlight 0.1" & @CRLF) ConsoleWrite("----------------->" & @CRLF) ConsoleWrite("Reading Func's and their Calltips from: " & $Script_to_work_on & @CRLF) Endif If Installed() Then If GetContent() Then CleanContent() WriteContent() CopyContent() ConsoleWrite('Successfully read ' & $Script_to_work_on & ' and updated the "au3.user.calltips.api" & "au3.UserUdfs.properties" accordingly.' & @CRLF) ConsoleWrite("Please restart SciTE to see new highlighting and calltips." & @CRLF) ConsoleWrite("----------------->" & @CRLF) Else ConsoleWrite("FuncHighlight 0.1" & @CRLF) ConsoleWrite("----------------->" & @CRLF) ConsoleWrite("No functions to highlight was found in: " & $Script_to_work_on & @CRLF) ConsoleWrite("----------------->" & @CRLF) EndIf Else Install() End() EndIf Func GetContent() $content = FileRead($Script_to_work_on) ; FileRead(@ScriptFullPath) ; for debug purposes $start = 1 $number_of_funcs = "" ; in case a Func is on first line of script If StringInStr($content,"Func",2,1,$start) <> 0 Then $start = StringInStr($content,"Func",2,1,$start) + 2 $end = StringInStr($content,@CRLF,2,1,$start) $line = StringMid($content,$start+5,$end - $start-5) If StringInStr($line,";") Then ConsoleWrite("ADDED: " & $line & @CRLF) $end_func_position = StringInStr($line,")") $start_comment_position = StringInStr($line,";") + 1 _ArrayAdd($aFunctions,StringMid($line,1,$end_func_position)) _ArrayAdd($aComments,StringMid($line,$start_comment_position)) $number_of_funcs += 1 EndIf $start = $end EndIf ; get all Funcs and see if they should be put in Calltips..etc While StringInStr($content,@CRLF & "Func",2,1,$start) <> 0 $start = StringInStr($content,@CRLF & "Func",2,1,$start) + 2 $end = StringInStr($content,@CRLF,2,1,$start) $line = StringMid($content,$start+5,$end - $start-5) If StringInStr($line,";") Then ConsoleWrite("$line: " & $line & @CRLF) $end_func_position = StringInStr($line,")") $start_comment_position = StringInStr($line,";") + 1 _ArrayAdd($aFunctions,StringMid($line,1,$end_func_position)) _ArrayAdd($aComments,StringMid($line,$start_comment_position)) $number_of_funcs += 1 EndIf $start = $end WEnd If $number_of_funcs = "" Then Return "" Else Return 1 EndIf EndFunc Func CleanContent() For $i = 1 To Ubound($aFunctions)-1 $aFunctions[$i] = StringStripWS($aFunctions[$i],8) $aFunctions[$i] = StringReplace($aFunctions[$i],"$"," ") $aFunctions[$i] = StringReplace($aFunctions[$i],"("," (") $aFunctions[$i] = StringReplace($aFunctions[$i],")"," )") $aFunctions[$i] = StringReplace($aFunctions[$i],",",", ") Next For $i = 1 To Ubound($aComments)-1 $aComments[$i] = StringReplace($aComments[$i],";","") $aComments[$i] = StringStripWS($aComments[$i],7) $aComments[$i] = " " & $aComments[$i] Next EndFunc Func WriteContent() $calltips_content = "" ; FileRead(@ScriptDir & "\au3.user.calltips.api") $userudf_content = "au3.keywords.user.udfs=" ; FileRead(@ScriptDir & "\au3.UserUdfs.properties") For $i = 1 To $Number_of_funcs $end_func_position = StringInStr($aFunctions[$i],"(") -1 $clean_for_highlight = StringMid($aFunctions[$i],1,$end_func_position) If StringInStr($userudf_content,$clean_for_highlight,2) == 0 Then $userudf_content = $userudf_content & StringLower($clean_for_highlight) EndIf If StringInStr($calltips_content,$aFunctions[$i],2) == 0 Then ; new string to be added $calltips_content = $calltips_content & @CRLF & $aFunctions[$i] & $aComments[$i] ElseIf StringInStr($calltips_content,$clean_for_highlight) <> 0 Then ; string already there $start_position = StringInStr($calltips_content,$clean_for_highlight) $end_position = StringInStr($calltips_content,@CRLF,2,1,$start_position) $string_from_calltips = StringMid($calltips_content,$start_position,$end_position-$start_position) If $string_from_calltips <> $aFunctions[$i] & $aComments[$i] Then $calltips_content = StringReplace($calltips_content,$string_from_calltips,$aFunctions[$i] & $aComments[$i],1,2) EndIf EndIf Next If StringInStr(StringLeft($calltips_content,2),@CRLF) Then $calltips_content = StringMid($calltips_content,3) ; bit quirky behavior, StringMid starts at 1 EndIf $calltips_handle = FileOpen(@ScriptDir & "\au3.user.calltips.api",10) FileWrite($calltips_handle,$calltips_content) FileClose($calltips_handle) $userudf_handle = FileOpen(@ScriptDir & "\au3.UserUdfs.properties",10) FileWrite($userudf_handle,$userudf_content) FileClose($userudf_handle) EndFunc Func CopyContent() $ok1 = FileCopy(@ScriptDir & "\au3.user.calltips.api", $Au3_install_dir & "\SciTE\api\",9) If $ok1 == 0 Then MsgBox(48,"FuncHighlighter error","Failed to copy au3.user.calltips.api => 'C:\Program Files\AutoIt3\SciTE\api\'") End() EndIf $ok2 = FileCopy(@ScriptDir & "\au3.UserUdfs.properties", $Au3_install_dir & "\SciTE\Properties\",9) If $ok2 == 0 Then MsgBox(48,"FuncHighlighter error","Failed to copy au3.UserUdfs.properties => 'C:\Program Files\AutoIt3\SciTE\Properties\'") End() EndIf Return 1 EndFunc Func Installed() If @error == 1 Or @error == 2 Then MsgBox(48,"FuncHighlighter error","Failed to read au3.properties, is AutoIt installed?") End() EndIf $result = StringInStr($File_au3_properties,"FuncHighlight, add highlight and calltips",2) If $result Then Return 1 Else Return "" EndIf EndFunc Func Install() $old_result = "" For $i = 5 To 45 ; assuming there'll be no less than 5 menu items and no more than 45 in the SciTE AU3 Tools menu $result = StringInStr($File_au3_properties,"command." & $i & ".$") If $result == 0 Then $string_to_append = @CRLF & @CRLF & "#x " & $i & " FuncHighlight, add highlight and calltips" & @CRLF & _ "command.name." & $i & ".$(au3)=FuncHighlight, add highlight and calltips" & @CRLF & _ "command.shortcut." & $i & ".$(au3)=Ctrl+Shift+C" & @CRLF & _ 'command.' & $i & '.$(au3)="' & StringReplace(@ScriptFullPath,".au3",".exe") & '"' & ' "$(FilePath)"' $file_handle = FileOpen($Au3_install_dir & "\SciTE\Properties\au3.properties",1) $test = FileWrite($file_handle,$string_to_append) If $test == 1 Then MsgBox(48,"FuncHighlighter installed","Success, after restarting SciTE you can invoke via Tools menu") EndIf FileClose($file_handle) ExitLoop EndIf Next EndFunc Func End() Exit EndFunc [list=1][*]Generic way to detect full path to default browser, List/ListView Events Using GuiRegisterMsg (detect doubleclick and much more)[*]Using dllcall for full control over fileopendialog, Make DirMove act somewhat normally (by circumventing it...)[*]Avoid problems with "&" (chr(38)) in code, Change desktop maximized area/workspace (fx to make deskbar type app)[*]Change focus behavior when buttons are clicked to work closer to 'standard windows' app[*](Context) Menus With Timed Tooltips, Fast Loops & Operators in AU3[*]Clipboard UDF, A clipboard change notification udf[/list]
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