Jump to content

External editor in edit control - Solved


Recommended Posts

Is there any way to link an edit control to an external editor (I use TextPad), similar to the "It's All Text!" extension in FireFox? The intent is to be able to click a button on the GUI which would transfer the text to the external editor, where it could be edited with all the additional functionality of the editor, then when complete, saved in the external editor, returning the edited text back to the edit control.

Chris

Edited by ChrisJakarta
Link to comment
Share on other sites

Try using Run() to call your editor, store the text to a variable, write the variable to your editor and put something like

While 1
If Not WinExists("TextPad") Then
$file = FileOpen("filename") ;filename you saved it to
GuiCtrlSetData($idofedit,FileRead($file))
EndIf
WEnd
Link to comment
Share on other sites

dbzfanatic,

Thanks for the idea. From this seed, I offer the following solution, based upon the Editbox example:

; External Editor
;
; Author:         Chris Green
;
; Based on EditBox example by:
; Author:         "SlimShady"
;

;Include constants, etc
#include <GUIConstantsEx.au3>
#include <Constants.au3>
#include <File.au3>
#include <ButtonConstants.au3>

Opt('MustDeclareVars', 1)

_Main()

Func ExtEdit($edit_id)

    Local $file, $text, $tfname, $tfpath, $szDrive, $szDir, $szFName, $szExt, $title
    Dim $tfar[5]

    $text = GuiCtrlRead($edit_id)
    $tfpath = _TempFile("","",".txt")
    $tfar = _PathSplit($tfpath,$szDrive, $szDir, $szFName, $szExt)
    $tfname = $tfar[3] & $tfar[4]
    $file = FileOpen($tfpath,2)
    If $file = -1 Then
        MsgBox(0, "Error", "Unable to open file.")
        Exit
    EndIf
    FileWrite($file,$text)
    FileClose($file)
    ShellExecute($tfpath)
    Sleep(1000)
    $title = WinGetTitle("[active]") 
    WinWaitClose($title)
    $file = FileOpen($tfpath,0)
    $text = FileRead($file)
    GUICtrlSetBkColor($edit_id, $COLOR_YELLOW)
    WinActivate("New GUI")
    GuiCtrlSetData($edit_id,$text)
    Sleep(1000)
    GUICtrlSetBkColor($edit_id, $CLR_NONE)
    FileClose($file)
    FileDelete($tfpath)
    
EndFunc   ;==>ExtEdit

Func _Main()

    ;Initialize variables
    Local $GUIWidth = 300, $GUIHeight = 250
    Local $Edit_1, $OK_Btn, $Cancel_Btn, $Edit_Btn, $msg

    #forceref $Edit_1

    ;Create window
    GUICreate("New GUI", $GUIWidth, $GUIHeight)

    ;Create an edit box with no text in it
    $Edit_1 = GUICtrlCreateEdit("", 10, 10, 280, 190)

    ;Create an "OK" button
    $OK_Btn = GUICtrlCreateButton("OK", 40, 210, 70, 25)

    ;Create a "CANCEL" button
    $Cancel_Btn = GUICtrlCreateButton("Cancel", 200, 210, 70, 25)

    ;Create a "EDIT" button
    $Edit_Btn = GUICtrlCreateButton("Edit", 120, 210, 70, 25)
    ;Show window/Make the window visible
    GUISetState(@SW_SHOW)

    ;Loop until:
    ;- user presses Esc
    ;- user presses Alt+F4
    ;- user clicks the close button
    ;- user clicks the Cancel button
    While 1
        ;After every loop check if the user clicked something in the GUI window
        $msg = GUIGetMsg()

        Select

            ;Check if user clicked on the close button
            Case $msg = $GUI_EVENT_CLOSE
                ;Destroy the GUI including the controls
                GUIDelete()
                ;Exit the script
                Exit

                ;Check if user clicked on the "OK" button
            Case $msg = $OK_Btn
                MsgBox(64, "New GUI", GuiCtrlRead($Edit_1))

                ;Check if user clicked on the "CANCEL" button
            Case $msg = $Cancel_Btn
                Exit

            Case $msg = $Edit_Btn
                ExtEdit($Edit_1)
                
        EndSelect

    WEnd
EndFunc   ;==>_Main

Hopefully this might be useful to others. It should be generic for any text editor that is associated with the '.txt' extension.

Chris

Edited by ChrisJakarta
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...