[prev in list] [next in list] [prev in thread] [next in thread]
List: jedit-devel
Subject: Re: [ jEdit-devel ] how to move the insertion point to the start of a file?
From: Alan Ezust <alan.ezust () gmail ! com>
Date: 2019-12-08 22:26:30
Message-ID: CALy5K9q+EWd+9iny98hZOKTbHE8na+0vbQz00LsWW0fZkr7+Ow () mail ! gmail ! com
[Download RAW message or body]
[Attachment #2 (multipart/alternative)]
I think the buffer.insertFile() can sometimes take longer and the function
returns immediately, so if you try to move to a position before the thing
is loaded, that would give you the effect of things not working.
I am not sure of the "best practice" for this, but I look at how other
people did it and that usually gives me a way to make things do what I want.
(MarkerSetsPlugin.java:430)
if (buffer.isLoaded())
{
moveCaret.run();
}
else
{
buffer.addBufferListener(new BufferAdapter() {
@Override
public void bufferLoaded(JEditBuffer buffer) {
SwingUtilities.invokeLater(moveCaret);
}
});
}
}
So you create a Runnable that runs "later" and you use
SwingUtilities.invokeLater() to run it, and only after the Buffer is loaded.
This is an EBMessage.
On Sun, Dec 8, 2019 at 9:30 AM Eric Le Lay <dev@elelay.fr> wrote:
> Hi Conal,
>
> the Templates plugin should do what you want. Strangely it doesn't work
> for me now (NullPointerException), but it should. It has the #caret
> directive to specify where the cursor should go after insertion.
> See the XML plugin for how to install your templates.
>
> By the way, your code works fine for me when run as a beanshell macro
> (attached).
>
> Cheers,
>
> Le Wed, 4 Dec 2019 23:01:21 +1000,
> Conal Tuohy <conal.tuohy@gmail.com> a écrit :
>
> > I have written a plugin for TEI XML encoding, which (among other
> > things) can create a new TEI XML file based on a template. I create a
> > new Buffer and insert the contents of the template file into it. This
> > leaves the cursor at the end of the file. I'd like to move the cursor
> > back up to the top (or alternatively I'd like to insert the text into
> > the buffer and leave the cursor at the start).
> >
> > Can anyone suggest what I'm doing wrong in the example? The bottom two
> > lines are my unsuccessful attempts to jump to the start of the buffer.
> >
> > BTW the static methods "debug" and "error" of the TEI class are just
> > utility methods which write to the activity log.
> >
> > Thanks!
> >
> > Conal
> >
> >
> > TEI.debug("Creating from template file", "'" + templateFileName +
> > "'");
> > > TEI.debug("View", view);
> > > Buffer buffer = jEdit.newFile(view.getEditPane(),
> > > System.getProperty("user.home"));
> > > view.showBuffer(buffer);
> > > buffer.setMode("xml");
> > > boolean inserted = buffer.insertFile(view, templateFileName);
> > > if (!inserted) {
> > > TEI.error("Failed to insert template file", templateFileName);
> > > }
> > > // neither of these lines seems to do anything
> > > view.getEditPane().getTextArea().goToBufferStart(false);
> > > view.getEditPane().getTextArea().setCaretPosition(0);
> >
> >
>
> --
> -----------------------------------------------
> jEdit Developers' List
> jEdit-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/jedit-devel
>
[Attachment #5 (text/html)]
<div dir="ltr"><div>I think the buffer.insertFile() can sometimes take longer and the \
function returns immediately, so if you try to move to a position before the thing is \
loaded, that would give you the effect of things not working.</div><div>I am not sure \
of the "best practice" for this, but I look at how other people did it and \
that usually gives me a way to make things do what I \
want.</div><div><br></div><div>(MarkerSetsPlugin.java:430)<br></div><div> if \
(buffer.isLoaded())<br> {<br> moveCaret.run();<br> }<br> else<br> {<br> buffer.addBufferListener(new \
BufferAdapter() {<br> @Override<br> public void bufferLoaded(JEditBuffer \
buffer) {<br> SwingUtilities.invokeLater(moveCaret);<br> }<br> });<br> }<br> }</div><div><br></div><div>So \
you create a Runnable that runs "later" and you use \
SwingUtilities.invokeLater() to run it, and only after the Buffer is \
loaded.</div><div>This is an \
EBMessage.</div><div><br></div><div><br></div><div><br></div></div><br><div \
class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Dec 8, 2019 at 9:30 AM \
Eric Le Lay <<a href="mailto:dev@elelay.fr">dev@elelay.fr</a>> \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Conal,<br> <br>
the Templates plugin should do what you want. Strangely it doesn't work<br>
for me now (NullPointerException), but it should. It has the #caret<br>
directive to specify where the cursor should go after insertion.<br>
See the XML plugin for how to install your templates.<br>
<br>
By the way, your code works fine for me when run as a beanshell macro<br>
(attached).<br>
<br>
Cheers,<br>
<br>
Le Wed, 4 Dec 2019 23:01:21 +1000,<br>
Conal Tuohy <<a href="mailto:conal.tuohy@gmail.com" \
target="_blank">conal.tuohy@gmail.com</a>> a écrit :<br> <br>
> I have written a plugin for TEI XML encoding, which (among other<br>
> things) can create a new TEI XML file based on a template. I create a<br>
> new Buffer and insert the contents of the template file into it. This<br>
> leaves the cursor at the end of the file. I'd like to move the cursor<br>
> back up to the top (or alternatively I'd like to insert the text into<br>
> the buffer and leave the cursor at the start).<br>
> <br>
> Can anyone suggest what I'm doing wrong in the example? The bottom two<br>
> lines are my unsuccessful attempts to jump to the start of the buffer.<br>
> <br>
> BTW the static methods "debug" and "error" of the TEI class \
are just<br> > utility methods which write to the activity log.<br>
> <br>
> Thanks!<br>
> <br>
> Conal<br>
> <br>
> <br>
> TEI.debug("Creating from template file", "'" + \
templateFileName +<br> > "'");<br>
> > TEI.debug("View", view);<br>
> > Buffer buffer = jEdit.newFile(view.getEditPane(),<br>
> > System.getProperty("user.home"));<br>
> > view.showBuffer(buffer);<br>
> > buffer.setMode("xml");<br>
> > boolean inserted = buffer.insertFile(view, templateFileName);<br>
> > if (!inserted) {<br>
> > TEI.error("Failed to insert template file", \
templateFileName);<br> > > }<br>
> > // neither of these lines seems to do anything<br>
> > view.getEditPane().getTextArea().goToBufferStart(false);<br>
> > view.getEditPane().getTextArea().setCaretPosition(0); <br>
> <br>
> <br>
<br>
-- <br>
-----------------------------------------------<br>
jEdit Developers' List<br>
<a href="mailto:jEdit-devel@lists.sourceforge.net" \
target="_blank">jEdit-devel@lists.sourceforge.net</a><br> <a \
href="https://lists.sourceforge.net/lists/listinfo/jedit-devel" rel="noreferrer" \
target="_blank">https://lists.sourceforge.net/lists/listinfo/jedit-devel</a><br> \
</blockquote></div>
--
-----------------------------------------------
jEdit Developers' List
jEdit-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic