Jump to content

Interaction with SciTE window - set property selection failed


Recommended Posts

I've made for me an script to save current file in SciTE with setting an time stamp inside this. It looks so:

#Region - TimeStamp
; 2011-04-21 14:17:49
#EndRegion

I've used Jos' function "SendSciTE_Command" and it works fine. But using commands to set property (i.e.: "property:SelectionstartLine=" & $line) takes no effect.

So i've solved by using "Send()" :unsure: - but i'm not happy with this.

Does anyone know, whats wrong by my attempt to set property ?

Here the script:

#cs  === to call from SciTE menu (SciTEUser.properties entry:) ===

#40 Save With Time Stamp
command.40.*.au3="$(autoit3dir)\autoit3.exe" "C:\SHARE\Code_AutoIt\TEST\SaveWithTimeStamp.au3"
command.name.40.*.au3=SaveWithTimeStamp
command.save.before.40.*.au3=1
command.is.filter.40.*.au3=1
command.shortcut.40.*.au3=Ctrl+Shift+Alt+T

#ce ==============================================================

Opt("WinSearchChildren", 1)
Global Const $WM_COPYDATA = 74, $IDM_SAVE = 106
Global $My_Hwnd, $Scite_hwnd, $My_Dec_Hwnd, $SciTECmd, $sReceive = ''
Local $sFile, $sSelection, $iLine

_StartUpSciTEInterface()

SendSciTE_Command($My_Hwnd, $Scite_hwnd, "goto:1,1")
SendSciTE_Command($My_Hwnd, $Scite_hwnd, "find:#Region - TimeStamp")
SendSciTE_Command($My_Hwnd, $Scite_hwnd, "askproperty:CurrentSelection") ; must be '#Region - TimeStamp' if always exists
$sSelection = StringRegExp($sReceive, '(?::\d+:macro:stringinfo:)(.*)', 1)
If @error Then Exit

If $sSelection[0] <> "#Region - TimeStamp" Then
    ; no '#Region - TimeStamp' in File, so write it at line 1
    ; if someting is selected in line 1, it will moved after stamp
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "insert:" & _
                    "#Region - TimeStamp\n" & _
                    "; " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "\n" & _
                    "#EndRegion\n\n" & $sSelection[0])
Else ; '#Region - TimeStamp' always exists
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "askproperty:SelectionstartLine")
    $iLine = StringRegExp($sReceive, '(?::\d+:macro:stringinfo:)(\d+)', 1) ; get the line where it was found
    If @error Then Exit

; All attempts to set selection takes no effect:

;~  SendSciTE_Command($My_Hwnd, $Scite_hwnd, "property:SelectionstartLine=" & $iLine[0] +1)     ; no effect
;~  SendSciTE_Command($My_Hwnd, $Scite_hwnd, "property:SelectionstartColumn=1")                 ; no effect
;~  SendSciTE_Command($My_Hwnd, $Scite_hwnd, "property:SelectionendColumn=19")                  ; no effect
;~  SendSciTE_Command($My_Hwnd, $Scite_hwnd, "property:SelectionendLine=" & $iLine[0] +1)       ; no effect

; So i take this way: Go in line with time stamp, write new stamp, select and delete old one with Send().
; It works - but i'm not happy with this.

    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "goto:" & $iLine[0] +1) ; line after #Region includes TimeStamp
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "insert:" & _
                    "; " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC)
    Send("{SHIFTDOWN}{END}{SHIFTUP}{DEL}") ; I don't like Send() solution.
EndIf

; save changes
SendSciTE_Command($My_Hwnd, $Scite_hwnd, "menucommand:" & $IDM_SAVE)

Func _StartUpSciTEInterface()
    $Scite_hwnd = WinGetHandle("DirectorExtension")
    $My_Hwnd = GUICreate("SciTE interface", 400, 600, 10, 10)
    $My_Dec_Hwnd = Dec(StringTrimLeft($My_Hwnd, 2))
    GUIRegisterMsg($WM_COPYDATA, "MY_WM_COPYDATA")
EndFunc

Func SendSciTE_Command($My_Hwnd, $Scite_hwnd, $sCmd)
    $sCmd = ":" & $My_Dec_Hwnd & ":" & $sCmd
ConsoleWrite('-->SendSciTE_Command >' & $sCmd & @LF)
    Local $CmdStruct = DllStructCreate('Char[' & StringLen($sCmd) + 1 & ']')
    DllStructSetData($CmdStruct, 1, $sCmd)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr')
    DllStructSetData($COPYDATA, 1, 1)
    DllStructSetData($COPYDATA, 2, StringLen($sCmd) + 1)
    DllStructSetData($COPYDATA, 3, DllStructGetPtr($CmdStruct))
    DllCall('User32.dll', 'None', 'SendMessage', 'HWnd', $Scite_hwnd, _
            'Int', $WM_COPYDATA, 'HWnd', $My_Hwnd, _
            'Ptr', DllStructGetPtr($COPYDATA))
EndFunc  ;==>SendSciTE_Command

Func MY_WM_COPYDATA($hWnd, $msg, $wParam, $lParam)
    Local $COPYDATA = DllStructCreate('Ptr;DWord;Ptr', $lParam)
    $SciTECmdLen = DllStructGetData($COPYDATA, 2)
    Local $CmdStruct = DllStructCreate('Char[255]', DllStructGetData($COPYDATA, 3))
    $SciTECmd = StringLeft(DllStructGetData($CmdStruct, 1), $SciTECmdLen)
    If StringInStr($SciTECmd, ":macro:stringinfo:", 1) Or _
        StringInStr($SciTECmd, ":filename:", 1) Then
        If $sReceive <> $SciTECmd Then $sReceive = $SciTECmd
    EndIf
ConsoleWrite('<--Receive' & $SciTECmd & @LF)
EndFunc  ;==>MY_WM_COPYDATA

#cs
askfilename:                                Return the name of the file being edited.
askproperty:<key>                           Return the value of a property.
close:                                      Close the current file.
closing:                                    Director is closing - SciTE closes if it was started by the director.
currentmacro:<string>                       Set the current macro to name.
cwd:                                        Change the working directory.
enumproperties:dyn|local|user|base|embed    Enumerate all the properties in the argument set.
exportashtml:<path>                         Save the document in HTML format as the indicated file.
exportasrtf:<path>                          Save the document in RTF format as the indicated file.
exportaspdf:<path>                          Save the document in PDF format as the indicated file.
exportaslatex:<path>                        Save the document in LaTeX format as the indicated file.
exportasxml:<path>                          Save the document in XML format as the indicated file.
extender:<command>                          Call the extension interface with the given command.
find:<string>                               Search for a string, select and show it.
focus:<timeStamp>                           On GTK+ bring this SciTE window to the front. The timeStamp is from the window manager and ensures that windows are only activated because of a user command. Has no effect on Windows as applications on Windows can only donate focus, not take focus.
goto:<lineNumber>[,<columnNumber>]          Move caret to a particular line and make it visible.
                                            If there is a column number then select the word at that column number or move the caret there if no word is present.
identity:<hwndDirector>                     Sets the director window handle to which SciTE sends messages. The argument is in decimal.
insert:<value>                              Display the value in the editor pane replacing the selection.
loadsession:<path>                          Load a session as given by the indicated file.
macrocommand:<command>                      Execute a macro command. See the SciTE source code for the syntax of the command argument.
macroenable:<enable>                        If enable, display menu commands in SciTE for recording and playing macros.
macrolist:<list>                            Display a list for the user to choose from.
menucommand:<cmd>                           Execute a menu command based on numeric ID.
open:<path>                                 Open the indicated file.
output:<value>                              Display the value in the output pane replacing the selection.
property:<key>=<value>                      Set a property to a value.
quit:                                       Shut down SciTE.
reloadproperties:                           Reload properties from files.
replaceall:<search>\000<replace>            Replace all instances of he search string in the document with the replace string.
saveas:<path>                               Save the document as the indicated file.
savesession:<path>                          Save a session as given by the indicated file.

The actions sent by SciTE are:
closed:<path>                               SciTE has closed the indicated file.
closing:                                    SciTE is closing.
dyn|local|user|base|embed:<key>=<value>     Set a property in a set to a value.
filename:<path>                             The file being edited is path. This is the reply to the askfilename: command.
identity:<hwndSciTEReceiving>               SciTE indicates to the director the window handle to which it should send messages. The argument is in decimal.
macro:getlist                               Retrieve the list of available macros which will be returned by the macrolist command.
macro:record:<details>                      Start recording a macro. See the SciTE source code for the syntax of the details argument.
macro:run:<macroName>                       Run the named macro.
macro:stoprecord                            Stop recording a macro.
opened:<path>                               SciTE has opened the indicated file.
switched:<path>                             SciTE has switched buffers to the indicated file.
saved:<path>                                SciTE has saved the indicated file.

PROPERTYS:
        FilePath                            full path of the current file
        FileDir                             directory of the current file without a trailing slash
        FileName                            base name of the current file
        FileExt                             extension of the current file
        FileNameExt                         $(FileName).$(FileExt)
        Language                            name of the lexer used for the current file
        SessionPath                         full path of the current session
        CurrentSelection                    value of the currently selected text
        CurrentWord                         value of word which the caret is within or near
        Replacements                        number of replacements made by last Replace command
        SelectionstartColumn                column where selection starts
        SelectionstartLine                  line where selection starts
        SelectionendColumn                  column where selection ends
        SelectionendLine                    line where selection ends
        CurrentMessage                      most recently selected output pane message
        SciteDefaultHome                    directory in which the Global Options file is found
        SciteUserHome                       directory in which the User Options file is found
        SciteDirectoryHome                  directory in which the Directory Options file is found
        APIPath                             list of full paths of API files from api.filepattern
        AbbrevPath                          full path of abbreviations file
#ce

Edited by BugFix

Best Regards BugFix  

Link to comment
Share on other sites

  • Developers

try:

If $sSelection[0] <> "#Region " & "- TimeStamp" Then
    ; no '#Region  - TimeStamp' in File, so write it at line 1
    ; if someting is selected in line 1, it will moved after stamp
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "insert:" & _
                    "#Region " & "- TimeStamp\n" & _
                    "; " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "\n" & _
                    "#EndRegion\n\n" & $sSelection[0])
Else ; '#Region  - TimeStamp' always exists
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "askproperty:SelectionstartLine")
    $iLine = StringRegExp($sReceive, '(?::\d+:macro:stringinfo:)(\d+)', 1) ; get the line where it was found
    If @error Then Exit
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "goto:" & $iLine[0]+1 & ",1")
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "extender:dostring editor:LineDelete()")    
    SendSciTE_Command($My_Hwnd, $Scite_hwnd, "insert:" & _
                    "; " & @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC & "\n")

EndIf

enjoy,

Jos

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Thanks Jos . u're the one. :unsure:

But where can i found more information about this? (like using "extender" and so on)

Is it also in the Scintilla documentation? I've not found something like this before.

Best Regards BugFix  

Link to comment
Share on other sites

  • Developers

Thanks Jos . u're the one. :unsure:

But where can i found more information about this? (like using "extender" and so on)

Is it also in the Scintilla documentation? I've not found something like this before.

I have looked for that as well but never found anything substantial. most of what I know is the "Search, trial and Error" method. :>

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • 3 years later...

How do i set a property for current session?

This is how i have been tried:

;First attempt
SendSciTE_Command("extender:dostring props['find.replace.regexp']='1'")

;Second...
SendSciTE_Command("property:find.replace.regexp=1")

But no effect, i want to set RegExp for search dialog.

Any ideas?

Edited by MrCreatoR

 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...