oXygene Editor Events

Oxygen general issues.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

[1. Java frame created from the Java code of an Author extension] I see that your JF extension action (the Java class JFrameOperation) just creates a new JFrame() and displays it. You should set as parent of this frame the object that is returned by authorAccess.getWorkspaceAccess().getParentFrame() so that your frame is displayed on top of the Oxygen window.

[2. Windows native frame created from a DLL library loaded in the Java code of an Author extension] I tried to test the Delphi form displayed from the 3 Author extension actions but I get the error Fail to load Dll. I think your Author actions cannot load the xFunction.dll library that you sent me and probably I need to install Delphi on my computer for installing some Delphi DLL files. For example your library xFunction.dll needs vcltest3.dll which does not come with Windows (it is not a standard Windows DLL) but it is included in Delphi. I started the download of Delphi 7 but the download server that hosts BorlandDelphi7.zip is very slow (30 - 50 KB/s). I hope the download will finish today.

Did you look at the Java source code of class WinFileChooser that I sent and that can be used for calling a native dialog from an Author extension action? You can use the same Java code when you call your DLL for creating the Delphi form so that it is displayed on top of the Oxygen window. There are many programmer comments in the Java source code of WinFileChooser class so you should understand what is done there. Did you look at the code from method WinFileChooser.doShowDialog()? You should follow that model for calling the native code from your DLL. The C code from WinFileChooserNativeHelper.cpp is an example of code called from Java (called from WinFileChooser.doShowDialog() that I mentioned) that uses Win32 functions for displaying a Windows dialog on top of the Oxygen Java window. I expect the same standard Win32 functions can be called from Delphi code for creating Windows dialogs or windows, for example GetForegroundWindow(), CommDlgExtendedError(), GetOpenFileNameW().


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hi Sorin.
Your example works only because it is about dialog, the modal window which does not allow doing anything untill it is closed.
In our case after showing the window we must return execution to the host application - oxygene.
Imagine that we always show the word under cursor in a separate window. This window is always visible and we do not need to close it.
So after showing the window you click a word in the editor and it immediately gets displayed in the window. Then click another and the window changes to display the next word.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

It was an example of displaying a dialog created in other language (the C language) from the Java code of an Author extension. I think you can modify that Java code and use it in an Author extension: remove (do not create) the empty Java dialog that is used for ignoring user input in the Oxygen window which makes the C dialog modal. This should allow user events (keyboard and mouse) both in the Oxygen window and the other window (in your case created with Delphi code).


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hi Sorin.

We have solved the problem with Dll using javax.swing.Timer.

Regards,
Max
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

We've found out the following:

See attached video.
http://www.mediafire.com/?sharekey=88ef ... f6e8ebb871

Description:

Please, open <Oxygen/>. Open a doc.

Step 1.

Press "Mo" button (The editor shows Dll Form in Modal Mode).
Move the Form in front of the Oxygen window. Repainting is working fine.

Step 2.
Press "Color Lines". Oxygen highlights document text.
Press "Mo" button (The editor shows Dll Form in Modal Mode again).
Move the Form in front of the Oxygen window. Repainting is working fine.

Step 3.
Highlighting already exsists.
Click on the word in the middle of the text.
Press "Mo" button (The editor shows Dll Form in Modal Mode again).
Move the Form in front of the Oxygen window. Repainting is not working correctly.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

Do the menus or the editor of Oxygen window work correctly after step 3 when the repaint does not work? If they do not work can I reproduce the problem with your DLL files formtest.dll and xFunction.dll? What do I have to install? Now I get the error Fail to load Dll.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

Thank you very much for your support and help. We decided to leave the problem as is until we would find necessary information.

Menus and the editor window after step 3 work fine. Unfortunately you could not repeat the problem with the package I've sent.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Max wrote:Menus and the editor window after step 3 work fine. Unfortunately you could not repeat the problem with the package I've sent.
In that case the "dialogs" that remain on screen after step 3 of your video could be caused by incorrect disposing/closing the dialog in the DLL code. I think a "dialog" is only an area that was not repainted by Windows, it is not a real dialog that can receive input, for example for pressing the OK dialog. If the repaint should be done but would not be done by the Oxygen window then the menus and the editor panel of the Oxygen window should not work, because the repainting and the input to menus or editor is done on the same execution thread.

For example does a menu that drops down repaint a "dialog" that remained on screen after step 3 in the same area where that menu drops down?


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

Now we have 2 solutions for displaying the Form from DLL in Modal Mode and
1 solution for Normal mode ( Form.Show ) using javax.swing.Timer.

The solution for Normal mode ( Form.Show ) using javax.swing.Timer. is accepted and approved.

For Modal mode we accepted a temporary solution (Solution A).


Solution A:

Java, event-dispatching thread:

Code: Select all

xFunction dllShowModal = new xFunction("formtest","void ShowModal()");
dllShowModal.invoke();
Delphi:

Code: Select all

ShowModal()
begin
Form1 := TForm1.Create(nil);
Form1.ShowModal();
Form1.Free;
Form1 := nil;
end;
or

Code: Select all

ShowModal()
begin
MessageBox( ...' Some text' ...)
end;
Description:
Delphi function is called from event-dispatching thread and creates, shows in Modal Mode and destroys the Form and after this
the control is returned to event-dispatching thread.

Disadvantages:
In case you click in the middle of the text the repainting of Oxygen becomes incorrect (See video #1).

Video #1 , to__Sorin4.avi :
http://www.mediafire.com/?sharekey=88ef ... f6e8ebb871


Solution B:

Java, event-dispatching thread is waiting for JDialog, Worker thread is waiting for Dll Form:

Code: Select all


final dialog = new JDialog((Frame)focusedWindow, "", true);
.....
Thread worker = new Thread("Win32 File Chooser Worker") {
public void run() {
...
xFunction dllShowModal = new xFunction("formtest","void ShowModal()");
dllShowModal.invoke();
dialog.setVisible(false);
}
}
....

if (SwingUtilities.isEventDispatchThread()) {
worker.start();
dialog .setVisible(true);
} else {
worker.run();
}
Delphi:

Code: Select all

ShowModal()
begin
Form1 := TForm1.Create(nil);
Form1.ShowModal();
Form1.Free;
Form1 := nil;
end;
or

Code: Select all

ShowModal()
begin
MessageBox( ...' Some text' ...)
end;
Description:
Event-dispatching thread creates JDialog and Worker thread and then goes to Modal Loop while JDialog is dispalyed.
Delphi function is called from Worker thread and creates, shows in Modal Mode, destroys the Form and
closes the JDialog and then Worker thread dies.
Event-dispatching thread continues to work.

Disadvantages:
No disadvantages if the Form would be destroyed after closing (See video #2).

Video #2 , to__Sorin4b.avi :
http://www.mediafire.com/?sharekey=88ef ... f6e8ebb871

-------------------------------------------------------------------------------------------------------------------------------------------------------------

We need another solution - solution C by reason of:

Form from Dll contains more over 300 controls and after the Form has been created the initialization of these 300 controls by data from the file would take 3-4 sec. That's why recreating of the Form is not desired.

We have an attempt to realize:

The Form works correctly if it is created in Event-dispatching thread (Solution A) and so
we can display the Form many times without destroying it, i.e.

In Solution A we replace Delphi section:

Code: Select all

ShowModal()
begin
Form1 := TForm1.Create(nil);
Form1.ShowModal();
Form1.Free;
Form1 := nil;
end;
with:

Code: Select all

ShowModal()
begin
if not Assigned(Form1) then Form1 := TForm1.Create(nil);
Form1.ShowModal;
end;
But the incorrect repainting remains like in video #1 because the control is in DLL.

If the Form is created in woker thread (Solution B), then the Form must be destroyed, otherwise it wouldn't be desplayed in the second time. ( See video #3)
The Form is damaged after the first completion of Woker thread.
Now we are collecting the information why it happens.

Video #3 , to__Sorin4c.avi :
http://www.mediafire.com/?sharekey=88ef ... f6e8ebb871

Eventually Solution A is more advantageous even to the prejudice of Oxygen repainting.
Solution B is costly because it recreates the Form.

Regards,
Max
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

We open the document with the help of:

Code: Select all

authorAccess.getWorkspaceAccess().open(URLtoDoc))
How to close the opened document?

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Max wrote:We open the document with the help of:

Code: Select all

authorAccess.getWorkspaceAccess().open(URLtoDoc))
How to close the opened document?
The user will close the document. If an extension will close the document it will be unexpected for the user. What is the interaction with the user if you want to close the document from an extension? How do you decide when the document is closed?


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hi Sorin,

Imagine we need to create a report on a document.
We have the filename of the document and now need to get it's text.
With this purpose we open the document, read it's content and close it. Everything is done automatically, best if user never notices that.
So we either need a way of closing the document programmatically or be able to fetch it's content without opening it.

thankx!

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Max wrote:Everything is done automatically, best if user never notices that.
So we either need a way of closing the document programmatically or be able to fetch it's content without opening it.
Why do you want to use authorAccess.getWorkspaceAccess().open(URLtoDoc) for opening the file? That method opens the file in Oxygen. If you want to read from the file and close the file automatically you should open it as a normal file, read the data from the file and call the close() method on the opened file.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

We'll need only plaintext with all xml tags skipped.
so if we use a simple parser which strips off text between "<" and ">", can you guarantee it gets us pure document text?
because if we open the doc in Oxygenem then we automatically get the plaintext.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

I understand that you want to use authorAccess.getWorkspaceAccess().open(URLtoDoc) for avoiding parsing the file as XML document. If you use authorAccess.getWorkspaceAccess().open(URLtoDoc) that will open the file in an editor panel in Oxygen. That means you cannot close the editor panel automatically without a user action for closing the document or other user action that ends with closing the document. For the user it is like a bug in Oxygen: the document is closed without the user doing that. In your case I think the users see the action as a document that is also opened without the user doing that. So I recommend opening the file as a File object in Java (or reading the file content from a URL) without opening it as a document in an editor panel in Oxygen.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Yes, we can open the doc as java file but it's content will contain the XML code, while we need plain text.
E.g. the XML file will list "<para>This is text</para>", and we only need "This is text".
So far we need to either parse it with DOM (which is slow) or manually create a parser which will strip off the xml tags. How difficult this manual parser is supposed to be? Or it can be something trivial which copies chars untill it meets "<", thin skips chars until it meets ">" then starts to copy chars again etc.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Yes you can handle the XML tags in your code and read only the characters that are not between '<' and '>'. Other option is using an XML parser.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

We need to process the event of pressing the button (when the user is starting to type the text).
What is the best solution for realizing it?

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

What button do you mean? The button of an Author mode toolbar that starts your extension action? You process that event in the method doOperation of your AuthorOperation implementation.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Sorry, I'm mistaken.
I meant not a button, but a key. We need to process the event of key pressing.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Add an Author listener with a call authorAccess.getDocumentController().addAuthorListener(AuthorListener) and process the events received by the listener in the calls beforeContentInsert() or contentInserted() or beforeContentDelete() or contentDeleted().


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

Is there a way to cancel insertion or deletion of a text fragment?
Can I do it in events beforeContentInsert() and beforeContentDelete() ?

Regards,
Max
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

And how to get an access to AuthorAccess from the event handler beforeContentDelete()?
We need to remove highlighting from an edited word.

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

You can cancel insertion or deletion using ro.sync.ecss.extensions.api.AuthorDocumentFilter. You have an authorAccess object in the AuthorOperation that will set your AuthorDocumentFilter.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

We select a word in the first document and run Author extension. Author extension opens a new document and inserts this word with the help of authorAccess.getDocumentController().insertText(). But the word is inserted in the first document. How to set Focus to the second document? After this we call the Save command. And the editor saves the first document. But when we open the first doc after saving it turns to be blank. Can't we save a doc without any editing operations?

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

Every Author document has an authorAccess object. When an extension action is called for a document the authorAccess of that document is passed as parameter to AuthorOperation.doOperation(). If you want to modify a second document in the extension of the first document you can open it as any other file from disk, modify and save it and after that open the saved file (the second document) in Author calling authorAccess.getWorkspaceAccess().open() in the extension action of the first document.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

We have such a fragment:

1 <Commands>
2 <cmd>text of command... </cmd>
3 <cmd>|text of command... </cmd>
4 <cmd>text of command... </cmd>
5 <cmd>text of command... </cmd>
6 <cmd>text of command... </cmd>
7 </Commands>

| - it's a cursor

How can we disable deleting the node <cmd> on the 3rd line while pressing Backspace?
(We have one condition: The quantity of commands(<cmd>) should be the same after editing)
Desirable behavior: the cursor shall move to the left from <сmd> without deleting the tag.

3 |<cmd>text of command... </cmd>

What Event handler is it better to use to realize all this?

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Hello,

You cannot do that in a custom extension. We already implemented it for the next version of Oxygen. I will send you a download URL for an Oxygen build that contains that.


Regards,
Sorin
Max
Posts: 55
Joined: Tue Jun 09, 2009 4:47 pm

Re: oXygene Editor Events

Post by Max »

Hello Sorin,

We run Author extension.
Author extension highlights words and copies a part of words into a massive of words aWords which is declared as Static.
After closing the doc we open another one and run Author extension. The massive aWordsis not empty. We need to clear the massive aWords. Is there any event rising on doc closing, in event handler of which we can clear the massive aWords?

the 2nd question:
We open a doc, run Author extension, which highlights words. We add CaretListener, AuthorListener (beforeContentInsert, beforeContentDelete). We need to remove underline highlightning of the edited word.
How can we get an access to AuthorEditorAccess for calling getHighlighter() from the event handler of the caret movement or inserting/removing a text?

the 3rd question:
In which order are event handlers called when BackSpace key pressing?

Regards,
Max
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: oXygene Editor Events

Post by sorin_ristache »

Max wrote:Author extension highlights words and copies a part of words into a massive of words aWords which is declared as Static.
After closing the doc we open another one and run Author extension. The massive aWordsis not empty. We need to clear the massive aWords. Is there any event rising on doc closing, in event handler of which we can clear the massive aWords?
There is no special event for opening or closing the Author document. For the second document the authorAccess object received as parameter in doOperation() is not the same authorAccess object received in doOperation() for the first document. If you want to store and reuse some text from the first document in the same extension action called on the second document you must compare the two authorAccess objects.
Max wrote:We open a doc, run Author extension, which highlights words. We add CaretListener, AuthorListener (beforeContentInsert, beforeContentDelete). We need to remove underline highlightning of the edited word.
How can we get an access to AuthorEditorAccess for calling getHighlighter() from the event handler of the caret movement or inserting/removing a text?
Do you mean javax.swing.event.CaretListener or ro.sync.ecss.extensions.api.AuthorCaretListener? If you set an AuthorCaretListener object by calling authorAccess.getEditorAccess().addAuthorCaretListener() you use authorAccess.getEditorAccess() for getting access to the ro.sync.ecss.extensions.api.access.AuthorEditorAccess object.
Max wrote:In which order are event handlers called when BackSpace key pressing?
AuthorListener.beforeContentDelete() / AuthorListener.beforeAuthorNodeNameChange() is called first and AuthorListener.contentDeleted() / AuthorListener.authorNodeNameChanged() is called second.


Regards,
Sorin
Post Reply