This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Kate External Tools scripts on toolbar or on other menus.

Tags: kate, katepart, scripting kate, katepart, scripting kate, katepart, scripting
(comma "," separated)
f1r3br4nd
Registered Member
Posts
16
Karma
0
First of all, a tip to fellow Kate users-- even though the UI doesn't let you edit the menus, you can edit $HOME/.kde/share/apps/kate/kateui.rc and $HOME/.kde/share/apps/katepart/katepartui.rc. They are XML files and it seems that they define menus, and plugins can then add to those menus by specifying the same names. You can, for instance, force the enormous Tools menu to get broken up into sub-menus by nesting additional blocks inside it that enclose commands you don't want to be at the top level.

Code: Select all
<Menu group="original_group" name="original_name">
 <text>Human-readable menu name</text>
 <Menu group="original_group" name="NAME_YOU_MADE_UP">
  <text>HUMAN READABLE NAME YOU MADE UP"</text>
  <Action group="original_group" name="original_action_name1"/>
  <Action group="original_group" name="original_action_name2"/>
  <Action group="original_group" name="original_action_name3"/>
  <!-- ...and so on -->
 </Menu>
</Menu>


...surprising that I couldn't find the above documented anyplace.

And now, here's my question. I figured out how to bury stuff in the Tools menu, but now I want to *un*bury a script I made via the External Tools plugin. Instead of having it be in "Tools"->"External Tools" I want it to be linked either to a button on the toolbar or at the top of the "Sessions" menu (because this script happens to be a workaround for Kate forgetting its session settings). Does anybody have any idea how I could do that?

Either that, or perhaps someone knows a better workaround that doesn't involve scripting for Kate sometimes overwriting a .katesession file with default values without being asked to do so?
f1r3br4nd
Registered Member
Posts
16
Karma
0
Got it! Kate gave up its secret when I assigned a keyboard shortcut to the script I created. Apparently the internal name for the script is:

"externaltool_ScriptNameWithoutSpaces"

...and it only gets explicitly added to the ui.rc if it's somehow different from all the other scripts, such as having a keyboard shortcut.

So going with the dummy code conventions I posted before, if you want to add this script to the menu "original_name" in kateui.rc, you edit $HOME/.kde/share/apps/kate/plugins/kateexternaltools/ui.rc

You will see some menu declarations enclosed in top-level <Menu> </Menu> tags which are in turn enclosed in <MenuBar> </MenuBar> tags. Copy and paste the declaration for "original_name" inside those menu tags (being careful not to nest them inside on of the menu declarations of course) and delete all the tags inside "original_name" except the <text></text> tag. It should look like this...

Code: Select all
<!DOCTYPE kpartgui>
<gui version="2" name="kateexternaltools" library="kateexternaltoolsplugin">
<MenuBar>
<Menu>
  <Menu name="tools">
   <text>&amp;Tools</text>
   <Action name="tools_external"/>
  </Menu>
  <!-- don't mess with whatever above stuff was already there -->
  <Menu name="original_name">
   <text>Human-readable menu name</text>
  </Menu>
<Menu>
</MenuBar>
</gui>


Now inside the "original_name" tags, insert the following:

Code: Select all
<Action name="externaltool_ScriptNameWithoutSpaces"/>


So in the end, your kateexternaltools/ui.rc files looks like this:


Code: Select all
<!DOCTYPE kpartgui>
<gui version="2" name="kateexternaltools" library="kateexternaltoolsplugin">
<MenuBar>
<Menu>
  <Menu name="tools">
   <text>&amp;Tools</text>
   <Action name="tools_external"/>
  </Menu>
  <!-- don't mess with whatever above stuff was already there -->
  <Menu name="original_name">
   <text>Human-readable menu name</text>
   <Action name="externaltool_ScriptNameWithoutSpaces"/>
  </Menu>
<Menu>
</MenuBar>
</gui>


You can add stuff to the toolbar by copying the outer set of the tags for the toolbar you want from kateui.rc, pasting those inside the <gui></gui> tags (but outside the <MenuBar></MenuBar> tags), and then again pasting the Action just like you did for the menu. It will probably look something like this...

Code: Select all
 <gui>
 <MenuBar>
  <!-- all the stuff discussed above -->
 </MenuBar>
 <ToolBar noMerge="1" name="mainToolBar">
    <text>Main Toolbar</text>
    <Action name="externaltool_ScriptNameWithoutSpaces"/>
 </ToolBar>
 </gui>


In other words, it looks like whatever is enclosed in the same hierarchy of tags as defined in kateui.rc and katepart.rc will get added to the corresponding menu or toolbar.

One last thing, at the end of my ui.rc file, just before </gui>, there are these lines:

Code: Select all
 <ActionProperties scheme="Default">
  <Action shortcut="Ctrl+Shift+S" name="externaltool_ScriptNameWithoutSpaces"/>
 </ActionProperties>


I'm sure it's necessary to define the keyboard shortcut, but if you don't want a keyboard shortcut, I think you don't have to include it, but I'm not sure.

Anyway, hope this is useful to someone, and saves them a lot of trial-and-error that went into figuring it out. Have fun!
User avatar
bcooksley
Administrator
Posts
19765
Karma
87
OS
The above is known as KDE's XMLGUI framework, and is documented on KDE Techbase ( apart from the Kate specific components )


KDE Sysadmin
[img]content/bcooksley_sig.png[/img]


Bookmarks



Who is online

Registered users: Bing [Bot], Evergrowing, Google [Bot]