Pages: 1
Print
Author Topic: XMetaL 8: Is it possible to override Table menu commands?  (Read 7155 times)
paorear
Member

Posts: 29


« on: January 20, 2015, 08:23:19 PM »

I'm particularly trying to override the Table > Insert Caption command. Table_InsertCaption and Table_Insert_Caption macros don't seem to trap it.

Thank you!
Paul O'Rear
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #1 on: January 21, 2015, 01:48:21 PM »

There are no macro events that will override those menu options. I assume you are just guessing at names. Hopefully you did not see these listed somewhere?

You would need to remove the existing menu item and replace it with your own custom item that calls your own macro.
Logged
paorear
Member

Posts: 29


« Reply #2 on: January 21, 2015, 03:15:03 PM »

Hi Derek - no, I think I was basing that off of another thread where it was implying that you could override any of the default menu options with a macro by effectively using the same name. However, it was only showing File menu options. I was taking a guess at what an equivalent Table menu macro might be.

The Delete method appears to only apply to a CommandBar and not to a CommandBarControl. I tried changing the Visible property of any of the 18 CommandBarControls in the Table CommandBar, but it did not seem to have any effect. I was trying to do this on ApplicationOpenComplete - should that work?

Paul
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #3 on: January 22, 2015, 02:07:12 PM »

The menu override you are thinking of for File menu related actions isn't actually tied to the File menu, it is tied to the actions the File menu calls and is limited to a specific set (as documented in the Programmers Guide under "File operations"). There is no general menu-override functionality.

From the Programmers Guide (buried nicely inside the topic "When XMetaL starts or closes"):

Quote
The event macro On_Default_CommandBars_Complete is called after the workspace has been loaded and toolbars have been set up. If you want to make modifications to the menus and toolbars, you can do it here; however, you cannot affect the visibility of toolbars from this event. Instead, use the On_CommandBars_Activate or On_CommandBars_DeActivate events.

It says "can", and though it is true this isn't the only event you can do this it is the event you should use in almost all cases (and I can think of no reason to use another event).

You definitely can delete a CommandBarControl. Here's the example from the Programmers Guide:

Code:
// XMetaL Script Language JSCRIPT:
var cmdBars = Application.CommandBars;
var cmdBar = cmdBars.item("Standard");
// get the first button
var cmdBarControl = cmdBar.Controls.item(1);
cmdBarControl.Delete();// delete it from the command bar
Application.Alert("deleted command bar button");
cmdBar.Reset();// bring it back
« Last Edit: January 22, 2015, 02:52:51 PM by Derek Read » Logged
paorear
Member

Posts: 29


« Reply #4 on: January 22, 2015, 07:48:57 PM »

Thanks Derek - I tried your approach and found that I was able to delete some Table toolbar members that way, however, the Table menu options appear to be managed separately.

Through code I was able to iterate over the Table CommandBar and found 18 controls. Querying the DescriptionText for each I was able to find controls for the following:
1) Insert Table
2) raises an exception when accessing DescriptionText
3) Insert Row Above
4) Insert Row Below
5) Delete Row(s)
6) Insert Column Left
7) Insert Column Right
8) Delete Column
9) Move Row Up
10) Move Row Down
11) Move Column Left
12) Move Column Right
13) Merge Cell Right
14) Merge Cell Left
15) Merge Cell Up
16) Merge Cell Down
17) Split Cell into Rows
18) Split Cell into Columns

Note particularly that Insert Caption is not present, but also that the Table menu and Table toolbars each have items that are not in the other.

Should I conclude that it is not possible to delete or otherwise modify the Insert Caption menu item?

Note that control #2 throws an exception when trying to access its properties, but even if I try to delete #2, I see no change.

I've even begun looking at Windows API approaches to deal with this, but it's almost impossible to query much of anything from these Control Bars from the WinAPI as well. <sigh>

Paul O'Rear
Logged
paorear
Member

Posts: 29


« Reply #5 on: February 02, 2015, 12:46:41 PM »

I saw a reply to this in email, but it doesn't appear to be showing up in the forum. The text of the reply was:

Quote
What is your document type? I'm guessing you are trying to customize the DITA authoring functionality and not creating a customization for your own schema?

If it is DITA then you will have trouble doing this as our DITA authoring customization heavily customizes the built-in Table menu, it also provides custom dialogs for various types of Table editing specific to DITA (we have built-in support for CALS but all of the other types required custom dialogs), and it also customizes quite a few of the other standard menus.

If you want to try to make changes to these things (I cannot recommend that) you would need to start reading all the JScript code our developers have written, and possibly some code in XFT files as well. You would then need to make your changes in there directly, or (better) override the JScript prototype functions they have written (where those exist). Keep in mind that you would need to retest your changes with each release as this part of the system is considered "closed" and making changes to it is unsupported. In addition to not being documented, or supported by XMetaL Support, our developers do not try to keep any of this functionality backward compatible (as they do with our APIs for example).

If you are trying to fix something it would be best to submit a case to XMetaL Support describing the issue so that it can be addressed in a future release if it makes sense to do so.

If you are trying to add a feature it might be useful for other clients, and in that case it would also make sense to submit a case to XMetaL Support describing what you want to add so that it can be considered for a future release.

We are not using DITA and have our own schema, but we are reusing the same table tags which work well overall with the built-in tools. However, when a user selects Insert Caption (even though we have a <caption> element), XMetaL effectively inserts an invisible <caption> element and the cursor is placed before the first cell of the table. If the user types it appears as if nothing is happening. If you switch to Plain Text view, you see a <caption> element was indeed inserted and any typing that may have happened is getting into the value of the element. If you then switch back to Tags On view, the <caption> element appears. It's this generally bad user experience we're trying to address.

If instead of selecting Insert Caption from the table menu, a user simply inserts a <caption> element from the Element List all works as expected.

This is a somewhat specific scenario, but overall, it would be really useful to be able to enable/disable/remove menu items from any of the standard menus - this is something anyone extending or customizing XMetaL could benefit from. We've been able to add our own menu and do some nice stuff there, but have little control over any of the other menus.

Thank you!
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #6 on: February 02, 2015, 04:47:24 PM »

Keep in mind that this forum is not XMetaL Support (see: http://forums.xmetal.com/index.php/topic,384.0.html).

Enabling / disabling / removing menu items should be supported for all menu items. It sounds like you have added a menu item that is running a script that will insert the element you want inserted. So all of that is working as you expect?

Taking a guess, it sounds like you probably need to use the API formatGraphicTable(). Refer to the documentation for that API in the Programmers Guide.

If that doesn't help then it would be best to provide XMetaL Support with what you have built so they can have a look and try to help.
Logged
paorear
Member

Posts: 29


« Reply #7 on: February 02, 2015, 04:54:33 PM »

Thanks Derek - basically, I'm just looking for a programmatic means that would let me ideally override the standard Table->Insert Caption menu item and failing that a programmatic means to disable it.

I have not found any way via macro documentation or samples that would let me do either.

Paul
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #8 on: February 02, 2015, 07:15:32 PM »

I think what you have done will work, but that there's some issue with what you've done. Submit whatever that is (preferably a small sample) to XMetaL Support.

However, since you are modifying a table that is already probably rendered as a table I really think you will need to use formatGraphicTable() to trigger the re-rendering of the table. Give it a try. The Programmers Guide also explains why that can be necessary.
« Last Edit: February 02, 2015, 07:17:09 PM by Derek Read » Logged
paorear
Member

Posts: 29


« Reply #9 on: February 02, 2015, 07:25:55 PM »

- using formatGraphicTable sounds like it would be a great option. Unfortunately, there doesn't seem to be a way to trap basic document edit events or XMetaL Table menu events. In other words, there would be no obvious way to trigger my code to run when the standard XMetaL Table =>Insert Caption menu item is selected. Or am I missing something?

P.
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #10 on: February 02, 2015, 08:03:45 PM »

You have written code that removes the Table > Insert Caption item and replaces it with your own item that runs your own macro, correct? That's what you need to do to do if you want to do something special with that menu item that is different from what it already does. The resulting table model still needs to be CALS or HTML though.

My suggestion that you might need to use formatGraphicTable() would be inside the macro that is called when the user selects that menu item. Due to their complexity (the underlying XML structure does not match 1:1 with what you see on screen in a logical order) table rendering is handled separately from the rest of the rendering in a document. I guess its actually more complicated than that, but essentially the issue is that if you build and insert a table using script, or modify portions of an existing table using script, you sometimes need to tell XMetaL Author to re-render the entire table. If whatever your script is doing causes the table to render oddly then calling this API will get the whole thing to render again, and if it is valid XML and follows the particular table model, it should render correctly.
Logged
paorear
Member

Posts: 29


« Reply #11 on: February 02, 2015, 08:24:07 PM »

Quote
You have written code that removes the Table > Insert Caption item and replaces it with your own item that runs your own macro, correct? That's what you need to do to do if you want to do something special with that menu item that is different from what it already does. The resulting table model still needs to be CALS or HTML though.
No - I'm simply trying to find a way to make the default behavior work correctly. All the other standard Table menu items work fine for us and this one almost does except for the behavior I described earlier. If I could find a way to replace the standard menu item I would, but using the CommandBars approach only affects the Tables toolbar and not the menu. And there is no Insert Caption button in the toolbar either.

For example, my C# code that is similar to what you'd do in JavaScript looks like this:

var tblMenu = HostApplication.CommandBars["Table"]; // get the Table command-bar

var cmdTableInsertCaption = tblMenu.Controls.item[4];
cmdTableInsertCaption.Delete();

This successfully removes an item from the Table command bar, but has no effect on the menu. If you see earlier in our thread here, I tried iterating over the controls in the Table command bar to see what each one was and I listed them all out. Insert Caption isn't among them, and regardless, deleting items from this command bar has no effect on the menu no matter which control I delete. It only affects the toolbar.

Paul
Logged
Derek Read
Program Manager (XMetaL)
Administrator
Member

Posts: 2621



WWW
« Reply #12 on: February 05, 2015, 04:20:50 PM »

If the table is being properly recognized as CALS (or HTML) then everything should just work. So, I still don't know what might be causing the original issue. Rather than try to work around that issue by replacing menus it is likely best to try to see if we can fix it. If you can submit your customization, including the full schema, and a sample file to XMetaL Support they can have a look at it and try to figure out what's going on.
Logged
Pages: 1
Print
Jump to:  

email us