From: <sh...@us...> - 2007-10-01 22:18:58
|
Revision: 10778 http://jedit.svn.sourceforge.net/jedit/?rev=10778&view=rev Author: shlomy Date: 2007-10-01 15:18:52 -0700 (Mon, 01 Oct 2007) Log Message: ----------- Implemented configurable tag text Modified Paths: -------------- plugins/CtagsSideKick/trunk/ctags/sidekick/ParsedData.java plugins/CtagsSideKick/trunk/ctags/sidekick/Plugin.java plugins/CtagsSideKick/trunk/ctags/sidekick/Tag.java plugins/CtagsSideKick/trunk/ctags/sidekick/options/ModeOptionsPane.java Added Paths: ----------- plugins/CtagsSideKick/trunk/ctags/sidekick/TextProviderManager.java plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/AttributeTextProvider.java plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ITextProvider.java plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ListTextProvider.java plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/NameAndSignatureTextProvider.java Modified: plugins/CtagsSideKick/trunk/ctags/sidekick/ParsedData.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/ParsedData.java 2007-09-30 21:02:19 UTC (rev 10777) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/ParsedData.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -28,6 +28,8 @@ import ctags.sidekick.filters.ITreeFilter; import ctags.sidekick.mappers.ITreeMapper; import ctags.sidekick.mappers.KindTreeMapper; +import ctags.sidekick.renderers.ITextProvider; +import ctags.sidekick.renderers.NameAndSignatureTextProvider; import ctags.sidekick.sorters.ITreeSorter; @@ -36,6 +38,7 @@ ITreeMapper mapper = null; ITreeSorter sorter = null; ITreeFilter filter = null; + ITextProvider textProvider = null; CtagsSideKickTreeNode tree = new CtagsSideKickTreeNode(); public ParsedData(Buffer buffer, String lang) @@ -46,12 +49,17 @@ mapper.setLang(lang); sorter = (ITreeSorter) SorterManager.getInstance().getProcessorForMode(mode); filter = (ITreeFilter) FilterManager.getInstance().getProcessorForMode(mode); + textProvider = (ITextProvider) TextProviderManager.getInstance().getProcessorForMode(mode); + if (textProvider == null) + textProvider = new NameAndSignatureTextProvider(); } void add(Tag tag) { if (filter != null && filter.pass(tag) == false) return; + if (textProvider != null) + tag.setTextProvider(textProvider); if (mapper == null) { tree.add(tag); Modified: plugins/CtagsSideKick/trunk/ctags/sidekick/Plugin.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/Plugin.java 2007-09-30 21:02:19 UTC (rev 10777) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/Plugin.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -30,6 +30,7 @@ MapperManager.getInstance().start(); SorterManager.getInstance().start(); FilterManager.getInstance().start(); + TextProviderManager.getInstance().start(); super.start(); } @@ -38,6 +39,7 @@ MapperManager.getInstance().stop(); SorterManager.getInstance().stop(); FilterManager.getInstance().stop(); + TextProviderManager.getInstance().stop(); super.stop(); } Modified: plugins/CtagsSideKick/trunk/ctags/sidekick/Tag.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/Tag.java 2007-09-30 21:02:19 UTC (rev 10777) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/Tag.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -25,11 +25,10 @@ import org.gjt.sp.jedit.Buffer; import org.gjt.sp.jedit.jEdit; +import sidekick.enhanced.SourceAsset; import ctags.sidekick.options.GeneralOptionPane; +import ctags.sidekick.renderers.ITextProvider; - -import sidekick.enhanced.SourceAsset; - public class Tag extends SourceAsset { static final String ICON_PREFIX = "icons."; @@ -41,7 +40,7 @@ String kind = null; static Hashtable<String, ImageIcon> icons = new Hashtable<String, ImageIcon>(); - + public Tag(final Buffer buffer, final Hashtable info) { super((String)info.get("k_tag"), @@ -80,6 +79,10 @@ setIcon(icon); } } + public void setTextProvider(ITextProvider provider) + { + setShortDescription(provider.getString(this)); + } public int getLine() { Added: plugins/CtagsSideKick/trunk/ctags/sidekick/TextProviderManager.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/TextProviderManager.java (rev 0) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/TextProviderManager.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -0,0 +1,40 @@ +package ctags.sidekick; + +import ctags.sidekick.renderers.AttributeTextProvider; +import ctags.sidekick.renderers.ListTextProvider; +import ctags.sidekick.renderers.NameAndSignatureTextProvider; + +public class TextProviderManager extends ObjectProcessorManager { + + static public final String PROVIDER_OPTION = "options.CtagsSideKick.textProvider"; + static public final String TYPE_NAME = "textProvider"; + static private TextProviderManager instance = null; + + static public TextProviderManager getInstance() { + if (instance == null) + instance = new TextProviderManager(); + return instance; + } + + @Override + protected ListObjectProcessor getListObjectProcessor() { + return new ListTextProvider(); + } + + @Override + protected String getProcessorOptionPath() { + return PROVIDER_OPTION; + } + + @Override + public String getProcessorTypeName() { + return TYPE_NAME; + } + + @Override + protected void registerBuiltProcessors() { + addProcessor(new AttributeTextProvider()); + addProcessor(new NameAndSignatureTextProvider()); + } + +} Modified: plugins/CtagsSideKick/trunk/ctags/sidekick/options/ModeOptionsPane.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/options/ModeOptionsPane.java 2007-09-30 21:02:19 UTC (rev 10777) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/options/ModeOptionsPane.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -14,6 +14,7 @@ import ctags.sidekick.FilterManager; import ctags.sidekick.MapperManager; import ctags.sidekick.SorterManager; +import ctags.sidekick.TextProviderManager; @SuppressWarnings("serial") public class ModeOptionsPane extends JPanel @@ -51,6 +52,11 @@ new ObjectProcessorListEditor(FilterManager.getInstance()); optionPanes.add(filterPane); subPanes.add(filterPane); + + ObjectProcessorListEditor textProviderPane = + new ObjectProcessorListEditor(TextProviderManager.getInstance()); + add(textProviderPane); + subPanes.add(textProviderPane); } public void modeSelected(String mode) { Added: plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/AttributeTextProvider.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/AttributeTextProvider.java (rev 0) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/AttributeTextProvider.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -0,0 +1,129 @@ +package ctags.sidekick.renderers; + +import javax.swing.BoxLayout; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; + +import ctags.sidekick.AbstractObjectEditor; +import ctags.sidekick.AbstractParameterizedObjectProcessor; +import ctags.sidekick.IObjectProcessor; +import ctags.sidekick.Tag; + +public class AttributeTextProvider extends AbstractParameterizedObjectProcessor + implements ITextProvider { + + private static final String SEPARATOR = "\\|\\|"; + public String attr; + public String prefix = ""; + public String suffix = ""; + public String missing = ""; + + static final String NAME = "Attribute"; + static final String DESCRIPTION = "Creates a tag string from an attribute " + + "value, with an optional prefix and suffix and an optional default value."; + + protected void parseParams(String params) { + if (params == null) { + attr = null; + return; + } + String [] parts = params.split(SEPARATOR); + attr = parts[0]; + prefix = parts[1]; + suffix = parts[2]; + if (parts.length > 3) + missing = parts[3]; + } + + public AttributeTextProvider() { + super(NAME, DESCRIPTION); + } + + public String toString() { + return NAME + "(\"" + prefix + ((attr==null) ? "" : attr) + suffix + + "\"" + + ((missing.length() > 0) ? ("|\"" + missing + "\"") : "") + ")"; + } + + public String getString(Tag tag) { + if (attr == null) + return tag.getName(); + String value = tag.getField(attr); + if (value == null) + return missing; + StringBuffer buf = new StringBuffer(); + buf.append(prefix); + buf.append(value); + buf.append(suffix); + return buf.toString(); + } + + public IObjectProcessor getClone() { + return new AttributeTextProvider(); + } + + public AbstractObjectEditor getEditor() { + return new Editor(); + } + + @SuppressWarnings("serial") + public class Editor extends AbstractObjectEditor { + + private JTextField name; + private JTextField prefix; + private JTextField suffix; + private JTextField missing; + + public Editor() { + super(AttributeTextProvider.this); + setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); + + JPanel p = new JPanel(); + p.setAlignmentX(LEFT_ALIGNMENT); + add(p); + p.add(new JLabel("Attribute:")); + name = new JTextField(20); + p.add(name); + p.setMaximumSize(p.getPreferredSize()); + + p = new JPanel(); + p.setAlignmentX(LEFT_ALIGNMENT); + add(p); + p.add(new JLabel("Prefix:")); + prefix = new JTextField(20); + p.add(prefix); + p.setMaximumSize(p.getPreferredSize()); + + p = new JPanel(); + p.setAlignmentX(LEFT_ALIGNMENT); + add(p); + p.add(new JLabel("Suffix:")); + suffix = new JTextField(20); + p.add(suffix); + p.setMaximumSize(p.getPreferredSize()); + + p = new JPanel(); + p.setAlignmentX(LEFT_ALIGNMENT); + add(p); + p.add(new JLabel("Default value:")); + missing = new JTextField(20); + p.add(missing); + p.setMaximumSize(p.getPreferredSize()); + } + + @Override + public void save() { + StringBuffer buf = new StringBuffer(name.getText()); + buf.append("||"); + buf.append(prefix.getText()); + buf.append("||"); + buf.append(suffix.getText()); + buf.append("||"); + buf.append(missing.getText()); + setParams(buf.toString()); + } + + } + +} Added: plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ITextProvider.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ITextProvider.java (rev 0) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ITextProvider.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -0,0 +1,8 @@ +package ctags.sidekick.renderers; + +import ctags.sidekick.IObjectProcessor; +import ctags.sidekick.Tag; + +public interface ITextProvider extends IObjectProcessor { + String getString(Tag tag); +} Added: plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ListTextProvider.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ListTextProvider.java (rev 0) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/ListTextProvider.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -0,0 +1,36 @@ +package ctags.sidekick.renderers; + +import java.util.Vector; + +import ctags.sidekick.IObjectProcessor; +import ctags.sidekick.ListObjectProcessor; +import ctags.sidekick.Tag; + +public class ListTextProvider extends ListObjectProcessor implements + ITextProvider { + + private static final String NAME = "Composite"; + private static final String DESCRIPTION = + "A list of tag text providers, each appending its own string."; + + public ListTextProvider() { + super(NAME, DESCRIPTION); + } + + public String getString(Tag tag) { + StringBuffer buf = new StringBuffer(); + Vector<IObjectProcessor> processors = getProcessors(); + if (processors.size() == 0) + processors.add(new NameAndSignatureTextProvider()); + for (int i = 0; i < processors.size(); i++) { + ITextProvider provider = (ITextProvider) processors.get(i); + buf.append(provider.getString(tag)); + } + return buf.toString(); + } + + public IObjectProcessor getClone() { + return new ListTextProvider(); + } + +} Added: plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/NameAndSignatureTextProvider.java =================================================================== --- plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/NameAndSignatureTextProvider.java (rev 0) +++ plugins/CtagsSideKick/trunk/ctags/sidekick/renderers/NameAndSignatureTextProvider.java 2007-10-01 22:18:52 UTC (rev 10778) @@ -0,0 +1,29 @@ +package ctags.sidekick.renderers; + +import ctags.sidekick.AbstractObjectProcessor; +import ctags.sidekick.IObjectProcessor; +import ctags.sidekick.Tag; + +public class NameAndSignatureTextProvider extends AbstractObjectProcessor + implements ITextProvider { + + static final String NAME = "Name and signature"; + static final String DESCRIPTION = "Tag name and signature (for functions)"; + + public NameAndSignatureTextProvider() { + super(NAME, DESCRIPTION); + } + + public String getString(Tag tag) { + String name = tag.getName(); + String signature = tag.getField("signature"); + if (signature != null && signature.length() > 0) + return name + signature; + return name; + } + + public IObjectProcessor getClone() { + return new NameAndSignatureTextProvider(); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |