|
From: <no...@so...> - 2000-12-22 14:02:11
|
Bug #126610, was updated on 2000-Dec-21 08:17
Here is a current snapshot of the bug.
Project: jEdit
Category: editor core
Status: Open
Resolution: None
Bug Group: normal bug
Priority: 5
Submitted by: jgellene
Assigned to : nobody
Summary: Tool bar -- user macros fail even when title is displayed
Details: jEDit 3.0pre5
Bug #126248 (now closed) reports that a macro named "make"
has its first letter truncated when the user attempts to add it to the tool bar. This bug is reported fixed. When a macro from a sub-directory is added (like "Console_Plugin/Run_jmk", for example), the macro title is not truncated, but the button nevertheless does not operate. This is because "play-macro" is not included in the "actions" data file contained in actions.xml. There is a further problem because play-macro now appears appear to be the only action which has an implicit parameter (the name of the macro, (for example, "play-macro@Console_Plugin/Run_jmk"), and the xml structure of EditActions does not permit parameters.
I assume this is a different problem than the truncation of the macro title described in the earlier bug. I didn't see changes in the GJT files.
To fix this second problem, perhaps you should define a new xml item type, but this could trigger a lot of redesign. Since I wanted my macros on the toolbar (who wouldn't?), I came up with the following three-part solution:
////////////////////////////////////////////////////////////////
(1) add the following item to actions.xml:
<ACTION NAME="play-macro">
<CODE>
BeanShell.runScript(view, MiscUtilities.concatPath(
MiscUtilities.constructPath(jEdit.getJEditHome(), "macros"),
"@@.bsh"), false);
</CODE>
</ACTION>
////////////////////////////////////////////////////////////////
// (2) add the following method to BeanShellAction:
public void replaceCode( String pattern, String replace)
{
int s = 0;
int e = 0;
StringBuffer result = new StringBuffer();
while ((e = code.indexOf(pattern, s)) != -1)
{
result.append(code.substring(s, e));
result.append(replace);
s = e+pattern.length();
}
result.append(code.substring(s));
code = result.toString();
Log.log(Log.DEBUG, BeanShellAction.class,
"replaceCode() results in code = " + code);
}
////////////////////////////////////////////////////////////////
// (3) call this new method in the MenuItemModel constructor as follows;
public MenuItemModel(String name)
{
this.name = name;
String actionName;
int index = name.indexOf('@');
if(index != -1)
{
arg = name.substring(index+1);
actionName = name.substring(0,index);
}
else
{
arg = null;
actionName = name;
// action = jEdit.getAction(name); // not needed; see next line
}
action = jEdit.getAction(actionName);
// here's where the action's BeanShell code gets changed based upon the macro name
if( action instanceof BeanShellAction && index != -1)
((BeanShellAction)action).replaceCode( "@@", arg);
label = jEdit.getProperty(name.concat(".label"));
if(label == null)
label = name;
index = label.indexOf('$');
if(index != -1 && label.length() - index > 1)
{
mnemonic = Character.toLowerCase(label.charAt(index + 1));
label = label.substring(0,index).concat(label.substring(++index));
}
else
mnemonic = '\0';
// stuff for createButton():
String iconName = jEdit.getProperty(name + ".icon");
if(iconName != null)
{
icon = GUIUtilities.loadIcon(iconName);
toolTip = label;
String shortcut = jEdit.getProperty(name + ".shortcut");
if(shortcut != null)
toolTip = toolTip + " (" + shortcut + ")";
}
}
It works, although I'm not sure whether it introduces and design complications in other areas.
Follow-Ups:
Date: 2000-Dec-22 06:02
By: jgellene
Comment:
Sorry, this doesn't quite do it. I tested it by creating only one macro button. It creates only one version of a "play-macro" action, so subsequent macro buttons invoke the macro assigned to the first button. The real solution should involve a change to the ActionListHandler class that creates multiple "play-macro" actions when needed. I'll give this a try and post a revised set of changes later today.
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=126610&group_id=588
|