 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
vlcek
Joined: 19 Feb 2007 Posts: 323 Location: Czech Republic
|
Posted: Thu Feb 21, 2008 4:00 pm Post subject: Insert to selected line |
|
|
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%
(
©
)
Return
reg:
gui, submit, nohide
GuiControlGet, MainEdit
GuiControl,,Mainedit,%Mainedit%
(
®
)
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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Tue Feb 26, 2008 5:10 am Post subject: |
|
|
| 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 |
|
 |
engunneer
Joined: 30 Aug 2005 Posts: 6847 Location: Pacific Northwest, US
|
Posted: Tue Feb 26, 2008 7:01 pm Post subject: |
|
|
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 |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 323 Location: Czech Republic
|
Posted: Sun Mar 02, 2008 7:06 am Post subject: |
|
|
| 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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Sun Mar 02, 2008 7:16 am Post subject: |
|
|
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  |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 323 Location: Czech Republic
|
Posted: Sun Mar 02, 2008 7:28 am Post subject: |
|
|
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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Sun Mar 02, 2008 7:31 am Post subject: |
|
|
| it doesn't show a menu here, so what's the actual code for insertion? |
|
| Back to top |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 323 Location: Czech Republic
|
Posted: Sun Mar 02, 2008 7:41 am Post subject: |
|
|
Stop please. I rewrite all to send example: send <a href=""></a>. _________________ Thanks. |
|
| Back to top |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Sun Mar 02, 2008 7:42 am Post subject: |
|
|
GOOD call for help  |
|
| Back to top |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Sun Mar 02, 2008 8:05 am Post subject: |
|
|
ah, finally, I was able to understand 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 |
|
 |
vlcek
Joined: 19 Feb 2007 Posts: 323 Location: Czech Republic
|
Posted: Sun Mar 02, 2008 9:29 am Post subject: |
|
|
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 |
|
 |
wOxxOm
Joined: 09 Feb 2006 Posts: 319
|
Posted: Sun Mar 02, 2008 9:42 am Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|