|
From: Dale A. <da...@da...> - 2019-12-11 14:15:21
|
What is the problem with the Templates plugin? It had a missing dependency
listed in its properties file, which was fixed in the release last month.
Is there something else not working? If so, would you open a ticket for it?
Alan's suggestion is right, you need to do the cursor move in the event
dispatch thread. Also, don't forget about these important tips for
manipulating Buffer data:
"This class is partially thread-safe, however you must pay attention to two
very important guidelines:
- Operations such as insert() and remove(), undo(), change Buffer data
in a writeLock(), and must be called from the AWT thread.
- When accessing the buffer from another thread, you must call
readLock() before and readUnLock() after, if you plan on performing more
than one read, to ensure that the buffer contents are not changed by the
AWT thread for the duration of the lock. Only methods whose descriptions
specify thread safety can be invoked from other threads."
Dale
On Wed, Dec 11, 2019 at 12:30 AM Conal Tuohy <con...@gm...> wrote:
> Yes the Templates plugin is indeed broken. I had a look at it and tried to
> see what was wrong with it. I decided I probably didn't have enough time in
> my current work contract to study it properly and fix it, so I decided just
> to implement the simple template functionality I needed in my own plugin. I
> don't actually need the Velocity templating system for my use case; I just
> need to be able to "clone" an existing file. I also have certain files (XML
> catalogs) mixed in with my template files, and I want to exclude those
> catalogs from the template menu. I'm quite happy with the result, except
> for this minor issue with the cursor, which I think Alan Ezust's suggestion
> may solve, anyway.
>
>
>
> On Mon, 9 Dec 2019 at 03:29, Eric Le Lay <de...@el...> 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 <con...@gm...> 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);
>> >
>> >
>>
>>
>
> --
> Conal Tuohy
> http://conaltuohy.com/
> @conal_tuohy
> +61-466-324297
> --
> -----------------------------------------------
> jEdit Developers' List
> jEd...@li...
> https://lists.sourceforge.net/lists/listinfo/jedit-devel
>
|