Form controls: Simple way to "Edit" a document

Oxygen general issues.
reinierk
Posts: 36
Joined: Tue Feb 21, 2012 8:22 pm
Location: Rotterdam, the Netherlands
Contact:

Form controls: Simple way to "Edit" a document

Post by reinierk »

Is there a simple way to add a Form Control to a DITA document that contains <image href="blah.svg" outputclass="osa/slide"/> tags to allow launching inkscape on the document contained in the @href attribute?
I already have an "External Tool" defined that can launch inkscape, but it doe not load the file.
Ideally there should be an "edit" button next to the image that launches inkscape with the .svg document loaded.
For now I have this in my custom CSS for the document:

Code: Select all

/*
* Form controls editing for image elements
*/
image[outputclass~="osa/slide"]:before {
content: "Slide: " oxy_editor(
type, urlChooser,
edit, "@href",
columns, 40);
background-color: yellow;
display: block;
}
This lets me select the external .svg file to be included in the document. The next step would be to add an "Edit" button next to it!
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Form controls: Simple way to "Edit" a document

Post by alex_jitianu »

Hi,

In order to add a button just change the CSS into something like:

Code: Select all


image[outputclass~="osa/slide"]:before {
content: "Slide: " oxy_editor(
type, urlChooser,
edit, "@href",
columns, 40)
"Edit: " oxy_editor(
type, button,
actionID, "my.edit.action");
background-color: yellow;
display: block;
}
A button will be added that will invoke an author action with "my.edit.action" ID. So the next step would be to create an author action with this ID. You can read about how to create a new author action here.
An action uses an author operation so you will have to create a custom author operation that when invoked will start the inkscape process. More information about how to create a custom operation can be found here and here.

This operation will be invoked in the context of the "image" element so you could either pass the value of the 'href' attribute to the operation as a parameter or you could just get it in the doOperation() method. The doOperation method should look something like this:

Code: Select all

 
/**
* @see ro.sync.ecss.extensions.api.AuthorOperation#doOperation(ro.sync.ecss.extensions.api.AuthorAccess, ro.sync.ecss.extensions.api.ArgumentsMap)
*/
public void doOperation(AuthorAccess authorAccess, ArgumentsMap args)
throws IllegalArgumentException, AuthorOperationException {
int caretOffset = authorAccess.getEditorAccess().getCaretOffset();
try {
AuthorNode nodeAtOffset = authorAccess.getDocumentController().getNodeAtOffset(caretOffset);
AttrValue attribute = ((AuthorElement) nodeAtOffset).getAttribute("href");

if (attribute != null) {
String hrefValue = attribute.getValue();
URL absoluteValue = null;
try {
absoluteValue = new URL(hrefValue);
} catch (MalformedURLException e) {
try {
absoluteValue = new URL(authorAccess.getEditorAccess().getEditorLocation(), hrefValue);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
}

if (absoluteValue != null) {
// If inkscape is associated with SVG files in the OS you could try:
authorAccess.getWorkspaceAccess().openInExternalApplication(absoluteValue, true);
// Otherwise build the command line to invoke inkscape something like:
String[] cmdarray = new String[] {"inkscape", absoluteValue.getFile()};
try {
Runtime.getRuntime().exec(cmdarray);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
} catch (BadLocationException e) {
e.printStackTrace();
}
}
Best regards,
Alex
reinierk
Posts: 36
Joined: Tue Feb 21, 2012 8:22 pm
Location: Rotterdam, the Netherlands
Contact:

Re: Form controls: Simple way to "Edit" a document

Post by reinierk »

Thanks Alex,

I was afraid it would end up with something like this... This is not really as "simple" as I would like it to be.... I will give it a try later when I have time to play.

It may be an idea for a next release, to make this easier (without java programming), to add an action that references and external command. I mean: maybe SyncRO can write a generic java wrapper-action that can be called with the name of an external command. That way an author can just call that action by clicking in the options box + a small piece of CSS...

Kind Regards,
Reinier.
Kind Regards,
Reinier Kleipool,
Course Materials editor,
Open Source Academy
http://www.OpenSourceAcademy.eu
alex_jitianu
Posts: 1008
Joined: Wed Nov 16, 2005 11:11 am

Re: Form controls: Simple way to "Edit" a document

Post by alex_jitianu »

Hi,

I agree that it's a bit of an overhead but this is not something that an author should do. A developer should implement this operation, update the framework to declare the action and the CSS to add the button. Then it should pack the framework and deliver it to the authors (perhaps through the add-ons system). An author will not have to do anything rather than installing the framework.

We though about implementing such an operation ourselves but we haven't come to a satisfying solution yet.

Best regards,
Alex
Post Reply