AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Insert to selected line

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
vlcek



Joined: 19 Feb 2007
Posts: 323
Location: Czech Republic

PostPosted: Thu Feb 21, 2008 4:00 pm    Post subject: Insert to selected line Reply with quote

Hi all. This code insert selected item to last line in mainedit. I want. Item will insert to select line in mainedit.
My code:
Code:

Gui, -sysmenu
; Create the sub-menus for the menu bar:
setworkingdir %A_ScriptDir%
Menu, FileMenu, Add, new, FileNew
Menu, FileMenu, Add, &open ..., FileOpen
Menu, FileMenu, Add, &save, FileSave
Menu, FileMenu, Add, save as ..., FileSaveAs
menu,filemenu,add,test,tst
Menu, FileMenu, Add, e&xit, FileExit

menu,jmenu,add,embed,javasnd
menu,jmenu,add,button back,javaback
menu,jmenu,add,alert,javaalert
menu,addmenu,add,java,:jmenu
menu,strmenu,add,start html head,f2
menu,strmenu,add,html head end,f3
menu,addmenu,add,structure,:strmenu
menu,nmenu,add,title 1,ndp1
menu,nmenu,add,title 2,ndp2
menu,nmenu,add,title 3,ndp3
menu,nmenu,add,title 4,ndp4
;
menu,addmenu,add,titles,:nmenu
menu,spmenu,add,copyright,cp
menu,spmenu,add,reg letter,reg
;
menu,addmenu,add,special letters,:spmenu
menu,addmenu,add,new section,odstavec
Menu,addmenu,add,link,f1
menu,addmenu,add,bg sound,bg
Menu, HelpMenu, Add, &about, HelpAbout
; Create the menu bar by attaching the sub-menus to it:

Menu, MyMenuBar, Add, &file, :FileMenu
menu,mymenubar,add,add,:addmenu
Menu, MyMenuBar, Add, &help, :HelpMenu
menu,mymenubar,color,black
; Attach the menu bar to the window:

Gui, Menu, MyMenuBar
; Create the main Edit control and display the window:

Gui, +Resize
; Make the window resizable.
gui,color,000000
gui,font,timesnewroman
fileread, mainedit, %selectedfile%
Gui, Add, Edit, vMainEdit WantTab W600 R20

Gui, Show,, blank document

CurrentFileName =
; Indicate that there is no current file.

return

FileNew:
Msgbox, 52, question., Do you want to save changes and create blank document?
IfMsgbox, yes
{
gosub, filesave
reload
}
IfMsgbox, no
return
return

FileOpen:
$^o::

Gui +OwnDialogs
; Force the user to dismiss the FileSelectFile dialog before returning to the main window.
FileSelectFile, SelectedFileName, 3,, Open, html (*.html)|php (*.php)

if SelectedFileName =
; No file selected.

    return
Gosub FileRead
return

FileRead:
; Caller has set the variable SelectedFileName for us.

FileRead, MainEdit, %SelectedFileName%
; Read the file's contents into the variable.
if ErrorLevel

{
   
MsgBox Could not open "%SelectedFileName%".
   
return

}

GuiControl,, MainEdit, %MainEdit%
; Put the text into the control.

CurrentFileName = %SelectedFileName%
Gui, Show,, %CurrentFileName%   
; Show file name in title bar.

return

FileSave:
$^s::

if CurrentFileName =   
; No filename selected yet, so do Save-As instead.

   
Goto FileSaveAs

Gosub SaveCurrentFile

return


FileSaveAs:
$^!s::

FileSelectFile, SelectedFileName, S16,, Save, html (*.html)
if SelectedFileName = ; No file selected.
   return
StringRight,inputvar,ext,4
if (ext <> ".html")
   CurrentFileName = %SelectedFileName%.html
else
   CurrentFileName = %SelectedFileName%
Gosub SaveCurrentFile
return

SaveCurrentFile:
; Caller has ensured that CurrentFileName is not blank.
IfExist %CurrentFileName%
{
   
FileDelete %CurrentFileName%
   
if ErrorLevel
   
{
       
MsgBox The attempt to overwrite "%CurrentFileName%" failed.
       
return
   
}
}

GuiControlGet, MainEdit
; Retrieve the contents of the Edit control.

FileAppend, %MainEdit%, %CurrentFileName%
; Save the contents to the file.
; Upon success, Show file name in title bar (in case we were called by FileSaveAs):

Gui, Show,, %CurrentFileName%
return

HelpAbout:
MSgbox, 64, About., Html editor v1.0.
return

return

GuiDropFiles:
; Support drag & drop.

Loop, parse, A_GuiEvent, `n
{
    SelectedFileName = %A_LoopField%
; Get the first file only (in case there's more than one).

    break
}
Gosub FileRead
return

GuiSize:
if ErrorLevel = 1
; The window has been minimized.  No action needed.

    return
; Otherwise, the window has been resized or maximized.
;Resize the Edit control to match.;
NewWidth := A_GuiWidth - 20

NewHeight := A_GuiHeight - 20

GuiControl, Move, MainEdit, W%NewWidth% H%NewHeight%
return

FileExit:     
GuiClose:   ; User closed the window.
FileDelete, test.html
Msgbox, 52, pozor., Soubor nebyl od posledních změn uložen. Uložit?
IfMsgbox, yes
gosub, FileSave
exitapp
IfMsgbox, no
ExitApp
   return
tst:
f5::
FileDelete, test.html
      GuiControlGet, MainEdit  ; Retrieve the contents of the Edit control.
      FileAppend, %MainEdit%, test.html  ;
run, test.html
Ifexist %SelectedFileName%
run, %SelectedFilename%
return


hist:
run, dokumentace\changelog.txt
Return

f1:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<a href=""></a>
)
return

f2:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<html>
<head>
<meta name="description" content="">
<meta name="keywords" content="">
<meta http-equiv=Content-Type content="text/html; charset=windows-1250">
<title>titulek</title>
</head>
<body>

)
return
f3:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
</body>
</html>
)
Return
ndp1:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<h1></h1>

)
return
ndp2:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<h2></h2>

)

return
ndp3:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<h3></h3>

)
return
ndp4:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<h4></h4>

)
Return

bg:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<BGSOUND SRC="" LOOP="">

)
return
cp:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
&copy;

)
Return
reg:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
&reg;

)
return
odstavec:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
<P>

</P>
)
Return
doc:
F1::
run, dokumentace\index.html
Return
javasnd:
gui,submit,nohide
GuiControlGet, MainEdit
guicontrol,,mainedit,%mainedit%
(
<embed name="pisnicka" src="soubor.mid" hidden autostart="false">
<a href="javascript: document.pisnicka.play()">Start</a>
<a href="javascript: document.pisnicka.stop()">Stop</a>

)
return
javaback:
gui,submit,nohide
GuiControlGet, MainEdit
guicontrol,,mainedit,%mainedit%
(
<input type=button onclick="history.back()" value="Zpět">

)
return
javaalert:
gui,submit,nohide
GuiControlGet, MainEdit
guicontrol,,mainedit,%mainedit%
(
<script>
alert("text");
</script>

)
return

Can you help? Guicontrolget not working.
_________________
Thanks.
Back to top
View user's profile Send private message
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Tue Feb 26, 2008 5:10 am    Post subject: Reply with quote

eh, somewhat obscure description of the problem... maybe two screenshots of what is now and what it should be will clarify the problem
Back to top
View user's profile Send private message Send e-mail Visit poster's website
engunneer



Joined: 30 Aug 2005
Posts: 6847
Location: Pacific Northwest, US

PostPosted: Tue Feb 26, 2008 7:01 pm    Post subject: Reply with quote

He is asking to append text to the selected line instead of the end of the edit.

I don't know how to do it, though.
_________________
Unless otherwise noted, all code is untested.
Common Answers: 1.(Loops, Viruses, etc.) 2. Search 3.RTFM
Back to top
View user's profile Send private message Visit poster's website
vlcek



Joined: 19 Feb 2007
Posts: 323
Location: Czech Republic

PostPosted: Sun Mar 02, 2008 7:06 am    Post subject: Reply with quote

engunneer wrote:
He is asking to append text to the selected line instead of the end of the edit.

I don't know how to do it, though.

Yes.
_________________
Thanks.
Back to top
View user's profile Send private message
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Sun Mar 02, 2008 7:16 am    Post subject: Reply with quote

hey, don't you think that you must refer to the actual scope of code which you have trouble with? I'm a clever one yet have some mercy Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vlcek



Joined: 19 Feb 2007
Posts: 323
Location: Czech Republic

PostPosted: Sun Mar 02, 2008 7:28 am    Post subject: Reply with quote

I posted full editor code for try. When I select some action from insert menu, the text is in last line in mainedit.
_________________
Thanks.
Back to top
View user's profile Send private message
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Sun Mar 02, 2008 7:31 am    Post subject: Reply with quote

it doesn't show a menu here, so what's the actual code for insertion?
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vlcek



Joined: 19 Feb 2007
Posts: 323
Location: Czech Republic

PostPosted: Sun Mar 02, 2008 7:41 am    Post subject: Reply with quote

Stop please. I rewrite all to send example: send <a href=""></a>.
_________________
Thanks.
Back to top
View user's profile Send private message
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Sun Mar 02, 2008 7:42 am    Post subject: Reply with quote

GOOD call for help Smile
Back to top
View user's profile Send private message Send e-mail Visit poster's website
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Sun Mar 02, 2008 8:05 am    Post subject: Reply with quote

ah, finally, I was able to understand Smile IMO one line of GuiControl (or whatever) would be more than enough.

I really have almost no experience with Gui commands, yet you can use direct WinApi messaging of the Edit control:

Code:
newText=
(
<a href=""></a>
)
sendmessage,0x00C2,true,&newText,Edit1,A ;EM_REPLACESEL
Back to top
View user's profile Send private message Send e-mail Visit poster's website
vlcek



Joined: 19 Feb 2007
Posts: 323
Location: Czech Republic

PostPosted: Sun Mar 02, 2008 9:29 am    Post subject: Reply with quote

Thanks. But in insert html head, I need insert all tags to new line. In your code newtext=
(
html
head
edc
)
sendmessage etc
is all inserted to one line. The tag `r`n create not standart blank lines.
_________________
Thanks.
Back to top
View user's profile Send private message
wOxxOm



Joined: 09 Feb 2006
Posts: 319

PostPosted: Sun Mar 02, 2008 9:42 am    Post subject: Reply with quote

you should specify join with WinApi standard CRLF (`r`n) whereas AHK standard is `n only

Code:
newText=
( join`r`n
<embed name="pisnicka" src="soubor.mid" hidden autostart="false">
<a href="javascript: document.pisnicka.play()">Start</a>
<a href="javascript: document.pisnicka.stop()">Stop</a>
)
sendmessage,0x00C2,true,&newText,Edit1,A ;EM_REPLACESEL
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group