| 
      
      
      From: <her...@us...> - 2006-09-25 14:50:54
       | 
| Revision: 7125
          http://svn.sourceforge.net/jedit/?rev=7125&view=rev
Author:   hertzhaft
Date:     2006-09-25 07:50:26 -0700 (Mon, 25 Sep 2006)
Log Message:
-----------
bug fix for [1032850]; code refactoring, reformatting and beautifying; rewrote the text insert routine in InsertTextCommand.java and got rid of the one in XTree.java
Modified Paths:
--------------
    plugins/XInsert/trunk/RELEASE.txt
    plugins/XInsert/trunk/XInsert.props
    plugins/XInsert/trunk/build.xml
    plugins/XInsert/trunk/src/Command.java
    plugins/XInsert/trunk/src/CommandQueue.java
    plugins/XInsert/trunk/src/InputDialog.java
    plugins/XInsert/trunk/src/InsertTextCommand.java
    plugins/XInsert/trunk/src/RunJavaCommand.java
    plugins/XInsert/trunk/src/ScriptContext.java
    plugins/XInsert/trunk/src/ShowDialogCommand.java
    plugins/XInsert/trunk/src/SubVariableCommand.java
    plugins/XInsert/trunk/src/Utilities.java
    plugins/XInsert/trunk/src/XInsertOptionPane.java
    plugins/XInsert/trunk/src/XInsertReader.java
    plugins/XInsert/trunk/src/XScripter.java
    plugins/XInsert/trunk/src/XTree.java
    plugins/XInsert/trunk/src/XTreeItem.java
    plugins/XInsert/trunk/src/XTreeNode.java
    plugins/XInsert/trunk/src/XTreeObject.java
Modified: plugins/XInsert/trunk/RELEASE.txt
===================================================================
--- plugins/XInsert/trunk/RELEASE.txt	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/RELEASE.txt	2006-09-25 14:50:26 UTC (rev 7125)
@@ -1,15 +1,15 @@
-XInsert 2.1
+XInsert 2.2
 
 Requirements:
 	* jdk 1.2
 	* jEdit 4.1
 
 Announcement:
-	Release 2.1 - added reference entries
+	Release 2.2 - bug fixes and code reformatting
 
 Source:
 	https://svn.sourceforge.net/svnroot/jedit/plugins/XInsert/
-	tag: tags/release-2_1
+	tag: tags/release-2_2
 
 Short Description:
 	Insert text clips and execute macros and scripts from a dockable tree. 
Modified: plugins/XInsert/trunk/XInsert.props
===================================================================
--- plugins/XInsert/trunk/XInsert.props	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/XInsert.props	2006-09-25 14:50:26 UTC (rev 7125)
@@ -1,6 +1,6 @@
 plugin.XInsertPlugin.name=XInsert
 plugin.XInsertPlugin.author=Romain Guy and Dominic Stolerman
-plugin.XInsertPlugin.version=2.1
+plugin.XInsertPlugin.version=2.2
 plugin.XInsertPlugin.docs=xinsert.html
 plugin.XInsertPlugin.depend.0=jedit 04.00.01.00
 plugin.XInsertPlugin.depend.1=jdk 1.2
Modified: plugins/XInsert/trunk/build.xml
===================================================================
--- plugins/XInsert/trunk/build.xml	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/build.xml	2006-09-25 14:50:26 UTC (rev 7125)
@@ -24,5 +24,8 @@
 		<filename name="xml/*.insert.xml"/>
 	  </or>
 	</selector>
+	
+	<!-- we have no doc/users-guide.xml -->
+	<target name="docs-xsltproc" />
 
 </project>
Modified: plugins/XInsert/trunk/src/Command.java
===================================================================
--- plugins/XInsert/trunk/src/Command.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/Command.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -23,8 +23,7 @@
 *@author Dominic Stolerman
 */
 
-public interface Command
-{
+public interface Command {
 	public void run(ScriptContext sc);
 }
 
Modified: plugins/XInsert/trunk/src/CommandQueue.java
===================================================================
--- plugins/XInsert/trunk/src/CommandQueue.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/CommandQueue.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -21,60 +21,52 @@
 
 import java.util.Vector;
 import java.util.Enumeration;
+import org.gjt.sp.util.Log;
 
 
-public class CommandQueue
-{
-  public CommandQueue()
-  {
-    qu = new Vector();
+public class CommandQueue {
+  public CommandQueue() {
+    queue = new Vector();
   }
   
   /**
    * Adds a command to th beginning of the queue;
    */
-  public synchronized void addFirst(Command c)
-  {
-    qu.insertElementAt(c, 0);
+  public synchronized void addFirst(Command cmd) {
+    queue.insertElementAt(cmd, 0);
     insertPos++;
   }
   
   /**
    * Adds commands to the end of the queue;
    */
-  public synchronized void add(Command c)
-  {
-    qu.insertElementAt(c, insertPos);
+  public synchronized void add(Command cmd) {
+    queue.insertElementAt(cmd, insertPos);
     insertPos++;
   }
   
   /**
    * Adds commands to the queue to be run after those added using {@link #add(Command)} and {@link #addFirst(Command)}.
    */
-  public synchronized void addLast(Command c)
-  {
-    qu.addElement(c);
+  public synchronized void addLast(Command cmd) {
+    queue.addElement(cmd);
   }
   
-  public int size()
-  {
-    return qu.size();
+  public int size() {
+    return queue.size();
   }
   
-  public synchronized void executeNext(ScriptContext sc)
-  {
-    ((Command)qu.remove(0)).run(sc);
+  public synchronized void executeNext(ScriptContext context) {
+    ((Command) queue.remove(0)).run(context);
   }
   
-  public void executeAll(ScriptContext sc)
-  {
-    while(qu.size() != 0)
-    {
-      executeNext(sc);
+  public void executeAll(ScriptContext context) {
+    while(queue.size() != 0) {
+      executeNext(context);
     }
   }
   
   private int insertPos = 0;
-  private Vector qu;
+  private Vector queue;
 }
 
Modified: plugins/XInsert/trunk/src/InputDialog.java
===================================================================
--- plugins/XInsert/trunk/src/InputDialog.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/InputDialog.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -1,238 +1,205 @@
-/*
- *
- * InputDialog.java
- * Copyright (C) 2001 Dominic Stolerman
- * dst...@je...
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
- 
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-
-public class InputDialog extends JDialog 
-{
-	public static final double MIN_WIDTH  = 290.0;
-	public static final double MIN_HEIGHT =  110.0;
-	
-	public InputDialog(Frame owner, String key, String message, String defValue)
-	{
-		super(owner, "Please input a value for " + key, true);
-		parent = owner;
-		init( key,  message,  defValue);
-	}
-	
-	public InputDialog(Frame owner, String key, String message, String defValue, String[] opts, boolean allowUser)
-	{
-		super(owner, "Please input a value for " + key, true);
-		parent = owner;
-		init( key,  message,  defValue,  opts,  allowUser);
-	}
-	
-	public InputDialog(Dialog owner, String key, String message, String defValue)
-	{
-		super(owner, "Please input a value for " + key, true);
-		parent = owner;
-		init( key,  message,  defValue);
-	}
-	
-	public InputDialog(Dialog owner, String key, String message, String defValue, String[] opts, boolean allowUser)
-	{
-		super(owner, "Please input a value for " + key, true);
-		parent = owner;
-		init( key, message, defValue, opts, allowUser);
-	}
-	
-	public String getValue()
-	{
-		return selected;
-	}
-	
-	public String showDialog()
-	{
-    pack();
-    setLocationRelativeTo(parent);
-    show();
-		return getValue();
-	}
-	
-	public Dimension getMinimumSize()
-	{
-		Dimension supMin = super.getMinimumSize();
-		return new Dimension((int)Math.max(supMin.getWidth(), MIN_WIDTH), 
-												 (int)Math.max(supMin.getHeight(), MIN_HEIGHT));
-	}
-	
-	public Dimension getPreferredSize()
-	{
-		Dimension supMin = super.getPreferredSize();
-		return new Dimension((int)Math.max(supMin.getWidth(), MIN_WIDTH), 
-												 (int)Math.max(supMin.getHeight(), MIN_HEIGHT));
-	}
-	
-	private void init(String key, String message, String defValue, String[] opts, boolean allowUser)
-	{
-    centPanel = new CentrePanel();
-		centPanel.addComboBox(opts, defValue, allowUser);
-		init(message);
-	}
-	
-	private void init(String key, String message, String defValue)
-	{
-		centPanel = new CentrePanel();
-		centPanel.addTextBox(defValue);
-		init(message);
-	}
-	
-	private void init(String message)
-	{
-		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
-		addWindowListener(new WindowAdapter() {
-			public void windowClosing(WindowEvent e)
-			{
-				okJB.doClick();
-			}
-		});
-		setResizable(false);
-		
-		panel = new JPanel();
-		GridBagLayout gb = new GridBagLayout();
-		GridBagConstraints c = new GridBagConstraints();
-		panel.setLayout(gb);
-		
-		c.gridx = 0;
-		c.fill = GridBagConstraints.HORIZONTAL;
-		c.weightx =  0.5;
-		c.weighty = 0.5;
-		
-		c.gridy = 0;
-		label = new JLabel(message);
-		label.setHorizontalAlignment(SwingConstants.LEFT);
-		gb.setConstraints(label, c);
-		panel.add(label);
-		
-		c.gridy = 1;
-		gb.setConstraints(centPanel, c);
-		panel.add(centPanel);
-		
-		
-		c.gridy = 2;
-		c.fill = GridBagConstraints.NONE;
-		c.anchor = GridBagConstraints.SOUTHEAST;
-		okJB = new JButton("OK");
-		getRootPane().setDefaultButton(okJB);
-		okJB.addActionListener(al);
-		gb.setConstraints(okJB, c);
-		panel.add(okJB);
-		
-		setContentPane(panel);
-		
-		//getRootPane().registerKeyboardAction(al, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
-	}
-	
-	ActionListener al = new ActionListener() {
-	public void actionPerformed(ActionEvent evt)
-	{
-		selected = centPanel.getValue();
-		setVisible(false);
-		dispose();
-	}
-	};
-		
-	
-	private JLabel label;
-	private JButton okJB;
-	private JPanel panel;
-	private CentrePanel centPanel;
-	String selected;
-	private Window parent;
-	
-	private class CentrePanel extends JPanel
-	{
-		public CentrePanel()
-		{
-			super();
-			setLayout(new BorderLayout());
-		}
-		
-		public void addTextBox(String defValue)
-		{
-			box = null;
-			add(text = new JTextField(defValue, 20), BorderLayout.CENTER);
-      if(defValue !=null)
-      {
-        text.setSelectionStart(0);
-        text.setSelectionEnd(defValue.length());
-      }
-			text.addActionListener(al);
-		}
-		
-		public void addComboBox(String[] opts, String defValue, boolean editable)
-		{
-      text = null;
-			add(box = new JComboBox(opts));
-			if(defValue != null)
-      {
-        boolean defValInc = false;
-        for(int i=0; i < opts.length; i++)
-        {
-          if(opts[i].equals(defValue))
-          {
-            box.setSelectedIndex(i);
-            defValInc = true;
-          }
-        }
-        if(!defValInc)
-        {
-          box.addItem(defValue);
-          box.setSelectedItem(defValue);
-        }
-      }
-			box.setEditable(editable);
-			// Needs to close dialog when enter pressed and popup is not visible:
-			/* This doesn't work - the action is never performed?
-			box.registerKeyboardAction(new ActionListener() {
-				public void actionPerformed(ActionEvent e)
-				{
-					al.actionPerformed(e);
-				} 
-			}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.SHIFT_MASK), WHEN_FOCUSED); */
-			
-			// to get round above problem - but only work when editable
-			box.addActionListener(new ActionListener() {
-				public void actionPerformed(ActionEvent e)
-				{
-						if(!box.isPopupVisible())
-							okJB.doClick();
-				}
-			});
-		}
-		
-		public String getValue()
-		{
-			if(box == null)
-				return text.getText();
-			else
-				return (String)box.getSelectedItem();
-		}
-		
-		private JTextField text;
-		private JComboBox box;
-	}
-	
-	
-	
-}
+/*
+ *
+ * InputDialog.java
+ * Copyright (C) 2001 Dominic Stolerman
+ * dst...@je...
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+ 
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class InputDialog extends JDialog 
+{
+	public static final double MIN_WIDTH  = 290.0;
+	public static final double MIN_HEIGHT =  110.0;
+	
+	public InputDialog(Frame owner, String key, String message, String defValue) {
+		super(owner, "Please input a value for " + key, true);
+		parent = owner;
+		init( key,  message,  defValue);
+		}
+	
+	public InputDialog(Frame owner, String key, String message, String defValue, String[] opts, boolean allowUser) {
+		super(owner, "Please input a value for " + key, true);
+		parent = owner;
+		init( key,  message,  defValue,  opts,  allowUser);
+		}
+	
+	public InputDialog(Dialog owner, String key, String message, String defValue) {
+		super(owner, "Please input a value for " + key, true);
+		parent = owner;
+		init( key,  message,  defValue);
+		}
+	
+	public InputDialog(Dialog owner, String key, String message, String defValue, String[] opts, boolean allowUser) {
+		super(owner, "Please choose a value for " + key, true);
+		parent = owner;
+		init( key, message, defValue, opts, allowUser);
+		}
+	
+	public String getValue() {
+		return selected;
+		}
+	
+	public String showDialog() {
+		pack();
+		setLocationRelativeTo(parent);
+		show();
+		return getValue();
+		}
+	
+	public Dimension getMinimumSize() {
+		Dimension supMin = super.getMinimumSize();
+		return new Dimension(
+			(int)Math.max(supMin.getWidth(), MIN_WIDTH),
+			(int)Math.max(supMin.getHeight(), MIN_HEIGHT)
+			);
+		}
+	
+	public Dimension getPreferredSize() {
+		Dimension supMin = super.getPreferredSize();
+		return new Dimension(
+			(int)Math.max(supMin.getWidth(), MIN_WIDTH),
+			(int)Math.max(supMin.getHeight(), MIN_HEIGHT)
+			);
+		}
+	
+	private void init(String key, String message, String defValue, String[] opts, boolean allowUser) {
+		centPanel = new CentrePanel();
+		centPanel.addComboBox(opts, defValue, allowUser);
+		init(message);
+		}
+	
+	private void init(String key, String message, String defValue) {
+		centPanel = new CentrePanel();
+		centPanel.addTextBox(defValue);
+		init(message);
+		}
+	
+	private void init(String message) {
+		setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
+		addWindowListener(
+			new WindowAdapter() {
+				public void windowClosing(WindowEvent e) {
+					okJB.doClick();
+					}
+				}
+			);
+		setResizable(false);
+		panel = new JPanel();
+		GridBagLayout gb = new GridBagLayout();
+		GridBagConstraints c = new GridBagConstraints();
+		panel.setLayout(gb);
+		c.gridx = 0;
+		c.fill = GridBagConstraints.HORIZONTAL;
+		c.weightx =  0.5;
+		c.weighty = 0.5;
+
+		c.gridy = 0;
+		label = new JLabel(message);
+		label.setHorizontalAlignment(SwingConstants.LEFT);
+		gb.setConstraints(label, c);
+		panel.add(label);
+
+		c.gridy = 1;
+		gb.setConstraints(centPanel, c);
+		panel.add(centPanel);
+
+		c.gridy = 2;
+		c.fill = GridBagConstraints.NONE;
+		c.anchor = GridBagConstraints.SOUTHEAST;
+		okJB = new JButton("OK");
+		getRootPane().setDefaultButton(okJB);
+		okJB.addActionListener(al);
+		gb.setConstraints(okJB, c);
+		panel.add(okJB);
+
+		setContentPane(panel);
+		//getRootPane().registerKeyboardAction(al, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
+		}
+
+	ActionListener al = new ActionListener() {
+		public void actionPerformed(ActionEvent evt) {
+			selected = centPanel.getValue();
+			setVisible(false);
+			dispose();
+			}
+		};
+
+	private JLabel label;
+	private JButton okJB;
+	private JPanel panel;
+	private CentrePanel centPanel;
+	private Window parent;
+
+	String selected;
+	
+	private class CentrePanel extends JPanel {
+		public CentrePanel() {
+			super();
+			setLayout(new BorderLayout());
+			}
+
+		public void addTextBox(String defValue)	{
+			box = null;
+			add(text = new JTextField(defValue, 20), BorderLayout.CENTER);
+			if(defValue !=null) {
+				text.setSelectionStart(0);
+				text.setSelectionEnd(defValue.length());
+				}
+			text.addActionListener(al);
+			}
+
+		public void addComboBox(String[] opts, String defValue, boolean editable) {
+			text = null;
+			add(box = new JComboBox(opts));
+			if(defValue != null) {
+				boolean defValInc = false;
+				for(int i=0; i < opts.length; i++) {
+					if(opts[i].equals(defValue)) {
+						box.setSelectedIndex(i);
+						defValInc = true;
+						}
+					}
+				if(!defValInc) {
+					box.addItem(defValue);
+					box.setSelectedItem(defValue);
+					}
+				}
+			box.setEditable(editable);
+ 			box.addActionListener(
+				new ActionListener() {
+					public void actionPerformed(ActionEvent e) {
+						selected = centPanel.getValue();
+						}
+					}
+				);
+		}
+		
+		public String getValue() {
+			if(box == null)
+				return text.getText();
+			else
+				return (String)box.getSelectedItem();
+			}
+		
+		private JTextField text;
+		private JComboBox box;
+	}
+}
+
Modified: plugins/XInsert/trunk/src/InsertTextCommand.java
===================================================================
--- plugins/XInsert/trunk/src/InsertTextCommand.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/InsertTextCommand.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -1,5 +1,4 @@
 /*
- *
  * InsertTextCommand.java
  * Copyright (C) 2001 Dominic Stolerman
  * dst...@je...
@@ -24,64 +23,130 @@
 *@author Dominic Stolerman
 */
 
-
 import org.gjt.sp.jedit.*;
 import org.gjt.sp.jedit.textarea.JEditTextArea;
-import javax.swing.text.BadLocationException;
+import org.gjt.sp.util.Log;
 
-public class InsertTextCommand extends java.lang.Object implements Command
-{
-  public static void insertText(String text, ScriptContext sc)
-  {
-    InsertTextCommand co = new InsertTextCommand(text);
-    co.run(sc);
-  }
+public class InsertTextCommand extends java.lang.Object implements Command {
 
+  public static void insertText(String text, ScriptContext context) {
+    InsertTextCommand cmd = new InsertTextCommand(text);
+    cmd.run(context);
+    }
+
   /* constructor */
-  public InsertTextCommand(String text)
-  {
+  public InsertTextCommand(String text) {
     this.text = text;
-  }
+    // this.src = MiscUtilities.escapesToChars(text);
+    this.src = text;
+    this.result = new StringBuffer(src.length());
+    this.i = 0;
+    }
 
-  public void run(ScriptContext sc)
-  {
-    View v = sc.getView();
-    Buffer b = v.getBuffer();
-    JEditTextArea textArea = v.getTextArea();
-    String t = MiscUtilities.escapesToChars(text);
-    StringBuffer buf = new StringBuffer(t.length());
-    String selected;
-    if(textArea.getSelectedText() != null)
-      selected = textArea.getSelectedText();
-      else selected = "";
-      char c;
-      for(int i=0; i<t.length(); i++)
-      {
-        c = t.charAt(i);
-        if(c == '|')
-        {
-          if(i < t.length() -1 && t.charAt(i + 1) == '|')
-          {
+  public void run(ScriptContext context) {
+    XTreeNode node = context.getNode();
+    View view = context.getView();
+    JEditTextArea textarea = view.getTextArea();
+    Buffer buffer = view.getBuffer();
+    int tabSize = buffer.getTabSize();
+
+    char c;
+    boolean braced;
+    int caretpos = -1;
+
+    for (i = 0; i < src.length(); i++) {
+      c = src.charAt(i);
+      switch(c) {
+      case '|':
+        // double '|'
+        if(nextCharIs('|')) {
             i++;
-            buf.append(c);
-          }
-          else
-          {
-            buf.append(selected);
-            charPos = i;
-          }
-        }
-        else
-          buf.append(c);
+            result.append(c);
+            }
+        // insert selection
+        else {
+            result.append(context.getSelection());
+            caretpos = result.length();
+            }
+        // pos = j;
+        break;
+      case '\\':
+        // new line
+        if(nextCharIs('n')) {
+           i++;
+           result.append('\n');
+           }
+        // tab
+        else if(nextCharIs('t')) {
+           i++;
+           if(jEdit.getBooleanProperty("buffer.noTabs", false))
+             for(int k = 0; k < tabSize; k++)
+               result.append(" ");
+           else
+             result.append("\t");
+             }
+        // escaped dollar sign
+        else if(nextCharIs('$')) {
+           i++;
+           result.append('$');
+           }
+        // escaped pipe
+        else if(nextCharIs('|')) {
+           i++;
+           result.append('|');
+           }
+        // escaped backslash
+        else if(nextCharIs('\\')) {
+           i++;
+           result.append(c);
+           }
+	    else
+           result.append(c);
+        break;
+        // insert variable
+      case '$':
+	        braced = nextCharIs('{');
+            // insertText ${varname}
+	        if(braced) i++;
+            i++;
+            int temp = i;
+            while(i < src.length() && Character.isLetterOrDigit(src.charAt(i)))
+              i++;
+            // Log.log(Log.DEBUG, this, "$ = " + src.substring(temp, i));
+            String val = XScripter.getSubstituteFor(view, src.substring(temp, i), node);
+            if(val == null)
+              result.append(src.substring(temp, i));
+            else
+              result.append(val);
+            if(!braced) i--;
+        break;
+      default:
+        result.append(c);
+        break;
       }
-      int pos = textArea.getCaretPosition();
-      b.insert(pos, buf.toString());
-      if(charPos != -1)
-        sc.getCommandQueue().addLast(new SetCursorPositionCommand(pos + charPos));
-      textArea.setCaretPosition(pos + buf.length());
-  }
+    }
+    if(jEdit.getBooleanProperty("xtree.carriage", false))
+      result.append('\n');
+    int caret = textarea.getCaretPosition();
+    int len = result.length();
+    if(len > 0) {
+      textarea.setSelectedText(result.toString());
+      // set caret to end of insert or last "|" position
+      textarea.setCaretPosition(caretpos > -1
+	      ? caret + caretpos
+	      : caret + len
+	      );
+      }
+    }
 
+  // enhances source readability
+  private boolean nextCharIs(char ch) {
+      return (i < src.length() - 1) && (src.charAt(i + 1) == ch);
+      }
+
+  private int i;
   private String text;
-  private int charPos = -1;
+  private String src;
+  private StringBuffer result;
 }
 
Modified: plugins/XInsert/trunk/src/RunJavaCommand.java
===================================================================
--- plugins/XInsert/trunk/src/RunJavaCommand.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/RunJavaCommand.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -27,27 +27,23 @@
  *
  * @author     Dominic Stolerman
  */
-public class RunJavaCommand extends Object implements Command
-{
+public class RunJavaCommand extends Object implements Command {
 
 	private final String command;
 
 
-	public RunJavaCommand(String command)
-	{
+	public RunJavaCommand(String command) {
 		this.command = command;
 	}
 
-	public void run(ScriptContext sc)
-	{
+	public void run(ScriptContext sc) {
 		View parent = sc.getView();
 		XTreeNode node = sc.getNode();
 		boolean stringArg = false;
 		String arg = "";
 		String cleanedCmd = command.substring(1, command.length() - 1).trim();
 		int bracket = cleanedCmd.indexOf("(");
-		if(bracket == -1)
-		{
+		if(bracket == -1) {
 			XScripter.doError(command, "\"(\" expected");
 			return;
 		}
@@ -56,46 +52,38 @@
 		int classEnds = cleanedCmd.lastIndexOf(".", bracket);
 		String clazzName = cleanedCmd.substring(0, classEnds);
 		String methodName = cleanedCmd.substring(classEnds + 1, bracket);
-		if(cleanedCmd.charAt(bracket + 1) != ')')
-		{
+		if(cleanedCmd.charAt(bracket + 1) != ')') {
 			stringArg = true;
 			String _arg = cleanedCmd.substring(bracket + 1, cleanedCmd.length());
-			if(_arg.startsWith("$"))
-			{
+			if(_arg.startsWith("$")) {
 				arg = XScripter.getSubstituteFor(parent, _arg.substring(1), node);
 			}
-			else
-			{
+			else {
 				arg = _arg;
 			}
 		}
-		try
-		{
+		try {
 			Class clazz = Class.forName(clazzName);
 			Method method = null;
 			System.out.println("ClassName=" + clazzName + "/" + clazz.getName() + " methodName=" + methodName);
 			
 			Object[] args = null; //Arguments for method
-			if(stringArg)
-			{
+			if(stringArg) {
 				method = clazz.getMethod(methodName, new Class[] {String.class});
 				//method = clazz.getMethod(methodName, new Class[] {Object.class, String.class});
 				args = new Object[1];
 				args[0] = arg;
 			}
-			else
-			{
+			else {
 				//method = clazz.getMethod(methodName, new Class[] {Object.class});
 				method = clazz.getMethod(methodName, null);
 			}
 			
 			Object obj = method.invoke(null, args);
-			if(obj == null)
-			{
+			if(obj == null) {
 				return;
 			}
-			else
-			{
+			else {
 				InsertTextCommand.insertText(obj.toString(), sc);
 			}
 			/*
@@ -116,26 +104,19 @@
 			 * System.out.println();
 			 * }
 			 
-			for(int i = 0; i < methods.length; i++)
-
-			{
-				if(methods[i].getName().equals(methodName))
-				{
+			for(int i = 0; i < methods.length; i++) {
+				if(methods[i].getName().equals(methodName)) {
 					Class[] parameterTypes = methods[i].getParameterTypes();
-					if(stringArg && parameterTypes.length == 2)
-					{
+					if(stringArg && parameterTypes.length == 2) {
 						if(parameterTypes[0].getName().equals(ScriptContext.class.getName()) && 
-								parameterTypes[1].getName().equals(String.class.getName()))
-						{
+								parameterTypes[1].getName().equals(String.class.getName())) {
 							method = methods[i];
 							args = new Object[]{sc, arg};
 							break;
 						}
 					}
-					else if(!stringArg && parameterTypes.length == 1)
-					{
-						if(parameterTypes[0].getName().equals(ScriptContext.class.getName()))
-						{
+					else if(!stringArg && parameterTypes.length == 1) {
+						if(parameterTypes[0].getName().equals(ScriptContext.class.getName())) {
 							method = methods[i];
 							args = new Object[]{sc};
 							break;
@@ -143,32 +124,26 @@
 					}
 				}
 			}
-			if(method != null)
-			{
-				for(int i = 0; i < args.length; i++)
-				{
+			if(method != null) {
+				for(int i = 0; i < args.length; i++) {
 					Log.log(Log.DEBUG, this, args[i].getClass().getName());
 				}
 				Object obj = method.invoke(null, args);
-				if(obj == null)
-				{
+				if(obj == null) {
 					return;
 				}
-				else
-				{
+				else {
 					InsertTextCommand.insertText(obj.toString(), sc);
 				}
 			}
-			else
-			{
+			else {
 				XScripter.doError(command, "Method not found");
 				return;
 			}
 			
 */
 		}
-		catch(Exception e)
-		{
+		catch(Exception e) {
 			XScripter.doError(command, e);
 		}
 	}
Modified: plugins/XInsert/trunk/src/ScriptContext.java
===================================================================
--- plugins/XInsert/trunk/src/ScriptContext.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/ScriptContext.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -18,6 +18,8 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  */ 
 import org.gjt.sp.jedit.View;
+import org.gjt.sp.jedit.textarea.JEditTextArea;
+import org.gjt.sp.util.Log;
 
 /**
  *
@@ -26,12 +28,16 @@
 public class ScriptContext extends Object {
 
   /** Creates new ScriptContext */
-  public ScriptContext(final View view, final XTreeNode node, final CommandQueue queue) 
-  {
+  public ScriptContext(final View view, final XTreeNode node, final CommandQueue queue) {
     this.view = view;
     this.node = node;
     this.queue = queue;
-  }
+    this.textarea = view.getTextArea();
+    String sel = textarea.getSelectedText();
+    this.selection = (sel == null)
+    	? ""
+	: sel;
+    }
 
   public View getView() {
     return view;
@@ -41,11 +47,17 @@
     return node;
   }
 
+  public String getSelection() {
+    return selection;
+  }
+
   public CommandQueue getCommandQueue() {
     return queue;
   }
   
+  private final String selection;
   private final View view;
+  private final JEditTextArea textarea;
   private final XTreeNode node;
   private final CommandQueue queue;
 
Modified: plugins/XInsert/trunk/src/ShowDialogCommand.java
===================================================================
--- plugins/XInsert/trunk/src/ShowDialogCommand.java	2006-09-25 13:34:25 UTC (rev 7124)
+++ plugins/XInsert/trunk/src/ShowDialogCommand.java	2006-09-25 14:50:26 UTC (rev 7125)
@@ -1,91 +1,94 @@
-/*
- *
- * ShowDialogCommand.java
- * Copyright (C) 2001 Dominic Stolerman
- * dst...@je...
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-
-import org.gjt.sp.jedit.View;
-
-/**
- *
- * @author  Dominic Stolerman
- */
-public class ShowDialogCommand extends Object implements Command
-{
-
-  /** Creates new ShowDialogCommand */
-  public ShowDialogCommand(String command)
-  {
-    this.command = command;
-  }
-
-  public void run(...
 
[truncated message content] | 
| 
      
      
      From: <her...@us...> - 2007-10-05 13:09:34
       | 
| Revision: 10811
          http://jedit.svn.sourceforge.net/jedit/?rev=10811&view=rev
Author:   hertzhaft
Date:     2007-10-05 06:09:26 -0700 (Fri, 05 Oct 2007)
Log Message:
-----------
Adapted to new release requirements; preparing release-2.2
Modified Paths:
--------------
    plugins/XInsert/trunk/XInsert.props
    plugins/XInsert/trunk/build.xml
Added Paths:
-----------
    plugins/XInsert/trunk/description.html
Modified: plugins/XInsert/trunk/XInsert.props
===================================================================
--- plugins/XInsert/trunk/XInsert.props	2007-10-04 23:49:16 UTC (rev 10810)
+++ plugins/XInsert/trunk/XInsert.props	2007-10-05 13:09:26 UTC (rev 10811)
@@ -1,24 +1,55 @@
+# {{{ header
+# :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1:
+#
+# XInsert.props - Properties file for the XInsert plugin
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+# }}}
+
+#{{{ general plugin properites
 plugin.XInsertPlugin.name=XInsert
 plugin.XInsertPlugin.author=Romain Guy and Dominic Stolerman
+plugin.XInsertPlugin.description=Insert text clips and execute macros and scripts from a dockable tree.
 plugin.XInsertPlugin.version=2.2
 plugin.XInsertPlugin.docs=xinsert.html
+plugin.XInsertPlugin.activate=defer
+plugin.XInsertPlugin.option-pane=xinsert
+# }}}
+
+#{{{ dependencies
 plugin.XInsertPlugin.depend.0=jedit 04.00.01.00
 plugin.XInsertPlugin.depend.1=jdk 1.2
-plugin.XInsertPlugin.activate=defer
-plugin.XInsertPlugin.option-pane=xinsert
+# }}}
+
+#{{{ labels
 XInsert.toggle.label=Toggle XInsert
 XInsert-to-front.label=Bring XInsert to front
 XInsert-focus.label=Focus XInsert
 XInsert-insert-selected.label=Insert selected item
+# }}}
 
-# Menu bar stuff
+#{{{ menu bar stuff
 plugin.XInsertPlugin.menu=XInsert.toggle
 plugin.XInsertPlugin.title=XInsert
 plugin.XInsertPlugin.label=XInsert
 XInsert.title=XInsert
 XInsert.label=XInsert
 XInsert.menu=XInsert.toggle
+# }}}
 
+#{{{ XInsert builtin categories
 xinsert.inserts.0=xinsert
 xinsert.inserts.1=htmltag
 xinsert.inserts.2=htmlchar
@@ -29,7 +60,9 @@
 xinsert.inserts.7=c
 xinsert.inserts.8=TeX
 xinsert.inserts.macros=macros
+# }}}
 
+#{{{ plugin options
 options.xinsert.label=XInsert
 options.xinsert.code=new XInsertOptionPane();
 options.xinsert.choose-directory=Choose Directory
@@ -50,15 +83,16 @@
 options.xinsert.click.one=Single Click
 options.xinsert.click.two=Double Click
 options.xinsert.click.change=Selection Changed
+# }}}
 
-
-# XTree panel
+#{{{ XTree panel
 xtree.expand.button=Expand
+xtree.collapse.button=Collapse
+xtree.reload.button=Reload
 #xtree.expand.mnemonic=E
-xtree.collapse.button=Collapse
 #xtree.collapse.mnemonic=C
-xtree.reload.button=Reload
 #xtree.reload.mnemonic=R
 xtree.carriage.label=Carriage Return
 xtree.execute.label=Execute Scripts
 xtree.loaded=XInsert file {0} successfully loaded
+# }}}
Modified: plugins/XInsert/trunk/build.xml
===================================================================
--- plugins/XInsert/trunk/build.xml	2007-10-04 23:49:16 UTC (rev 10810)
+++ plugins/XInsert/trunk/build.xml	2007-10-05 13:09:26 UTC (rev 10811)
@@ -14,6 +14,8 @@
 	<property file="build.properties"/>
 	<property file="../build.properties"/>
 
+	<property name="version" value="2.2" />
+
     <import file="${build.support}/plugin-build.xml" />
 
     <selector id="packageFiles">
Added: plugins/XInsert/trunk/description.html
===================================================================
--- plugins/XInsert/trunk/description.html	                        (rev 0)
+++ plugins/XInsert/trunk/description.html	2007-10-05 13:09:26 UTC (rev 10811)
@@ -0,0 +1,26 @@
+<html>
+<p>
+	XInsert will insert a section of code/text from a library into the current
+	buffer, using a hierarchically structured tree view. It is also able
+	to run scripts in a native format as well as BeanShell scripts and static
+	Java methods.
+</p>
+
+<p>
+	XInsert clips are inserted by double-clicking on the desired item in the
+	expanded branch, or by selecting it with the keyboard and pressing <Enter>
+	or <Space>. Two actions are provided that can be bound to keystroke
+	combinations: One sets the focus to the XInsert tree to provide easy
+	navigation without having to leave the keyboard; the other inserts the
+	currently selected item even when the XInsert window is not visible.
+</p>
+
+<p>
+	Clips are stored in a simple XML format. The place where the current
+	selection should go is indicated with a '|' (pipe) character. That way 
+	huge tag libraries can be built. In addition, XInsert provides 
+	comfortable access to jEdit's own Beanshell macros.
+</p>
+</html>
+
+ 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 | 
| 
      
      
      From: <her...@us...> - 2007-12-07 10:48:47
       | 
| Revision: 11200
          http://jedit.svn.sourceforge.net/jedit/?rev=11200&view=rev
Author:   hertzhaft
Date:     2007-12-07 02:48:26 -0800 (Fri, 07 Dec 2007)
Log Message:
-----------
Added new item type "action"
Modified Paths:
--------------
    plugins/XInsert/trunk/RELEASE.txt
    plugins/XInsert/trunk/XInsert.props
    plugins/XInsert/trunk/src/MacroCommand.java
    plugins/XInsert/trunk/src/XInsertHandler.java
    plugins/XInsert/trunk/src/XScripter.java
    plugins/XInsert/trunk/src/XTree.java
    plugins/XInsert/trunk/src/XTreeItem.java
    plugins/XInsert/trunk/xinsert.dtd
    plugins/XInsert/trunk/xinsert.html
Added Paths:
-----------
    plugins/XInsert/trunk/images/tree_leaf_action.gif
Modified: plugins/XInsert/trunk/RELEASE.txt
===================================================================
--- plugins/XInsert/trunk/RELEASE.txt	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/RELEASE.txt	2007-12-07 10:48:26 UTC (rev 11200)
@@ -1,15 +1,15 @@
-XInsert 2.2
+XInsert 2.4
 
 Requirements:
 	* jdk 1.2
 	* jEdit 4.1
 
 Announcement:
-	Release 2.2 - bug fixes and code reformatting
+	Release 2.4 - new features
 
 Source:
 	https://svn.sourceforge.net/svnroot/jedit/plugins/XInsert/
-	tag: tags/release-2_2
+	tag: tags/release-2_4
 
 Short Description:
 	Insert text clips and execute macros and scripts from a dockable tree. 
Modified: plugins/XInsert/trunk/XInsert.props
===================================================================
--- plugins/XInsert/trunk/XInsert.props	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/XInsert.props	2007-12-07 10:48:26 UTC (rev 11200)
@@ -22,7 +22,7 @@
 plugin.XInsertPlugin.name=XInsert
 plugin.XInsertPlugin.author=Romain Guy and Dominic Stolerman
 plugin.XInsertPlugin.description=Insert text clips and execute macros and scripts from a dockable tree.
-plugin.XInsertPlugin.version=2.2
+plugin.XInsertPlugin.version=2.4
 plugin.XInsertPlugin.docs=xinsert.html
 plugin.XInsertPlugin.activate=defer
 plugin.XInsertPlugin.option-pane=xinsert
Added: plugins/XInsert/trunk/images/tree_leaf_action.gif
===================================================================
(Binary files differ)
Property changes on: plugins/XInsert/trunk/images/tree_leaf_action.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream
Modified: plugins/XInsert/trunk/src/MacroCommand.java
===================================================================
--- plugins/XInsert/trunk/src/MacroCommand.java	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/src/MacroCommand.java	2007-12-07 10:48:26 UTC (rev 11200)
@@ -1,84 +1,40 @@
-/*
+/*
+ *
+ * MacroCommand.java
+ * Copyright (C) 2001 Dominic Stolerman
+ * dst...@je...
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+/**
+ *
+ * @author  Dominic Stolerman
+ */
 
- *
+public class MacroCommand extends Object implements Command {
 
- * MacroCommand.java
+/** Creates new MacroCommand */
+  public MacroCommand(String macro) {
+    this.macro = macro.substring(1);
+    }
 
- * Copyright (C) 2001 Dominic Stolerman
+  public void run(ScriptContext sc) {
+    XScripter.runMacro(sc.getView(), (String)sc.getNode().getUserObject(), macro);
+    }
 
- * dst...@je...
+  private final String macro;
 
- *
+}
 
- * This program is free software; you can redistribute it and/or
-
- * modify it under the terms of the GNU General Public License
-
- * as published by the Free Software Foundation; either version 2
-
- * of the License, or any later version.
-
- *
-
- * This program is distributed in the hope that it will be useful,
-
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
-
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-
- * GNU General Public License for more details.
-
- *
-
- * You should have received a copy of the GNU General Public License
-
- * along with this program; if not, write to the Free Software
-
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
-
- */
-
-
-
-
-
-/**
-
- *
-
- * @author  Dominic Stolerman
-
- */
-
-public class MacroCommand extends Object implements Command
-
-{
-
-
-
-  /** Creates new MacroCommand */
-
-  public MacroCommand(String macro) 
-
-  {
-
-    this.macro = macro.substring(1);
-
-  }
-
-
-
-  public void run(ScriptContext sc)
-
-  {
-
-    XScripter.runMacro(sc.getView(), (String)sc.getNode().getUserObject(), macro);
-
-  }
-
-  
-
-  private final String macro;
-
-}
-
Modified: plugins/XInsert/trunk/src/XInsertHandler.java
===================================================================
--- plugins/XInsert/trunk/src/XInsertHandler.java	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/src/XInsertHandler.java	2007-12-07 10:48:26 UTC (rev 11200)
@@ -51,7 +51,9 @@
       // new data type added here				
       else if(value.equalsIgnoreCase("NAMED_MACRO"))
         type = XTreeItem.NAMED_MACRO_TYPE;	
-      // new data type added: hertzhaft 				
+      // new data types added: hertzhaft 				
+      else if(value.equalsIgnoreCase("ACTION"))
+        type = XTreeItem.ACTION_TYPE;	
       else if(value.equalsIgnoreCase("REFERENCE"))
         type = XTreeItem.REFERENCE_TYPE;	
       else {
Modified: plugins/XInsert/trunk/src/XScripter.java
===================================================================
--- plugins/XInsert/trunk/src/XScripter.java	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/src/XScripter.java	2007-12-07 10:48:26 UTC (rev 11200)
@@ -23,6 +23,7 @@
 import org.gjt.sp.util.Log;
 import java.util.StringTokenizer;
 import javax.swing.JOptionPane;
+import javax.swing.SwingUtilities;
 import java.util.Vector;
 import java.util.Enumeration;
 import java.io.File;
@@ -43,11 +44,11 @@
 /**
  * @deprecated use getSubstituteFor(View, String, XtreeNode) instead as it does exactly the same
  */
-  public static String _getSubstituteFor(View parent, String in, XTreeNode node) {
-    return getSubstituteFor(parent, in, node);
+  public static String _getSubstituteFor(View view, String in, XTreeNode node) {
+    return getSubstituteFor(view, in, node);
     }
 
-  private static Command getCommand(View parent, XTreeNode node, String command) {
+  private static Command getCommand(View view, XTreeNode node, String command) {
     char c = command.charAt(0);
     if(c == '$') {
       // Substitute variable
@@ -75,13 +76,55 @@
       }
     }
 
-  public static void runMacro(View parent, String name, String macro) {
-    Log.log(Log.DEBUG, XScripter.class, "Running runMacro for name=" + name);
-    BeanShell.eval( parent, macro, false);
-    }
+//{{{ invokeAction method
+  /**
+  *  invokes an Action.
+  *
+  * @param  view    The view to run the script in.
+  * @param  name    The name of the node item
+  * @param  content The node content to be invoked as an action.
+  */
+  public static void invokeAction(View view, String name, String content) {
+    // borrowed from jedit/gui/ActionBar.java
+    Log.log(Log.DEBUG, XScripter.class, "Invoking action for item named = " + name);
+    final int repeatCount = 1; //  is it worthwhile to make this configurable?
+    final View v = view;
+    final EditAction action = (content == null ? null : jEdit.getAction(content));
+    if (action == null) {
+       if(content != null) 
+	   view.getStatus().setMessageAndClear(jEdit.getProperty("view.action.no-completions"));
+       }
+    SwingUtilities.invokeLater(new Runnable() {
+       public void run(){
+	   v.getInputHandler().setRepeatCount(repeatCount);
+           v.getInputHandler().invokeAction(action);
+           }
+       });
+    } //}}}
 
-  public static void runNamedMacro(View parent, String name, String path) {
-	Log.log(Log.DEBUG, XScripter.class, "Running runNamedMacro for item named " + name + ", path=" + path);
+//{{{ runMacro method
+  /**
+  *  runs the node content as a BeanShell macro.
+  *
+  * @param  view    The view to run the script in.
+  * @param  name    The name of the node item
+  * @param  macro   The node content to be evaluated as a macro
+  */
+  public static void runMacro(View view, String name, String macro) {
+    Log.log(Log.DEBUG, XScripter.class, "Running runMacro for item named = " + name);
+    BeanShell.eval(view, macro, false);
+    } //}}}
+
+//{{{ runNamedMacro method
+  /**
+  *  runs a named (existing) macro
+  *
+  * @param  view    The view to run the script in.
+  * @param  name    The name of the node item
+  * @param  path    The node content giving the internal name or full path of the macro.
+  */
+  public static void runNamedMacro(View view, String name, String path) {
+	Log.log(Log.DEBUG, XScripter.class, "Running runNamedMacro for item named = " + name + ", path=" + path);
 	// NOTE: old-style macro names
 	if(path.startsWith("play-macro@")) {
 		path = path.substring(11);
@@ -89,33 +132,34 @@
 	Macros.Macro macro = Macros.getMacro(path);
 	if(macro != null) {
 		// NOTE: this is the internal representation of a macro
-		macro.invoke(parent);
+		macro.invoke(view);
 		}
 	else {
 		// NOTE: this is the alternative representation: the macro's full path
 		File macroFile = new File(path);
 		if(macroFile.exists()) {
-			BeanShell.runScript(parent, path, true, false);
+			BeanShell.runScript(view, path, true, false);
 			}
 		else {
 			Log.log(Log.ERROR, XScripter.class,
 				"Could not find macro named " + path);
 			}
 		}
-  	}
+  	} //}}}
 
 
   /**
   *  searches for a variable recursivley through nodes for variable, returns
   *  the first it finds.
   *
-  * @param  parent  the view to be used for view specific variables
+  * @param  view    the view to be used for view specific variables
   * @param  key     the variable name
   * @param  node    the tree node from where to start the search
   * @return         the variable value or null if the variable is not found
   */
 
-  public static String getSubstituteFor(View parent, String key, XTreeNode node) {
+//{{{ getSubstituteFor method
+  public static String getSubstituteFor(View view, String key, XTreeNode node) {
 	XTreeNode parentNode = node;
 	String val = null;
 	do {
@@ -126,15 +170,20 @@
 	if(val == null && XInsertPlugin.containsVariable(key)) {
 		val = XInsertPlugin.getVariable(key);
 		}
-	if(val == null && parent != null) {
-		val = XInsertPlugin.getViewSpecificVariable(parent, key);
+	if(val == null && view != null) {
+		val = XInsertPlugin.getViewSpecificVariable(view, key);
 		}
 	return val == null ? null : MiscUtilities.escapesToChars(val);
-	}
+	} //}}}
 
   /**
   *  insert text.
   *
+  /**
+  *  invokes an Action.
+  *
+  * @param  view    The view to run the script in.
+  * @param  node    The node item
   * @param  text  The node content to be inserted.
   */
   public static void insertText(View view, String text, XTreeNode node) {
@@ -146,6 +195,7 @@
     buffer.endCompoundEdit();
     }
 
+//{{{ runXInsertScript method
   /**
   *  runs an XInsertScript.
   *
@@ -203,8 +253,9 @@
     finally {
       buffer.endCompoundEdit();
       }
-    }
+    } //}}}
 
+//{{{ findWordEnd method
   /**
   *  Finds the end of the word at position <code>pos</code> in <code>line</code>.
   *  <p>this is a slightly modified version of {@link org.gjt.sp.jedit.textarea.TextUtilities#findWordEnd(String, int, String)}</P>
@@ -225,8 +276,9 @@
         }
       }
     return wordEnd;
-    }
+    } //}}}
 
+//{{{ doError methods
 /**
   *  There was an error in executing the script
   *
@@ -235,7 +287,7 @@
   */
   public static void doError(String command, String message) {
     doError(command, message, null);
-    }
+    } 
 
 /**
   *  Logs an error which threw an exception
@@ -256,20 +308,21 @@
 
   public static void doError(String command, Exception ex) {
     doError(command, null, ex);
-    }
+    } //}}}
 
-  public static String showInputDialog(View parent, String key, String defValue) {
-    return showInputDialog(parent, "Please enter a value for \"" + key + "\"", key, defValue);
+//{{{ inputDialog methods
+  public static String showInputDialog(View view, String key, String defValue) {
+    return showInputDialog(view, "Please enter a value for \"" + key + "\"", key, defValue);
     }
 
-  public static String showInputDialog(View parent, String message, String key, String defValue) {
-    InputDialog id = new InputDialog(parent, key, message, defValue);
+  public static String showInputDialog(View view, String message, String key, String defValue) {
+    InputDialog id = new InputDialog(view, key, message, defValue);
     return id.showDialog();
     }
 
-  public static String showComboDialog(View parent, String message, String key, String[] opts, String defValue, boolean allowUser) {
-    InputDialog id = new InputDialog(parent, key, message, defValue, opts, allowUser);
+  public static String showComboDialog(View view, String message, String key, String[] opts, String defValue, boolean allowUser) {
+    InputDialog id = new InputDialog(view, key, message, defValue, opts, allowUser);
     return id.showDialog();
-    }
+    } //}}}
   }
 
Modified: plugins/XInsert/trunk/src/XTree.java
===================================================================
--- plugins/XInsert/trunk/src/XTree.java	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/src/XTree.java	2007-12-07 10:48:26 UTC (rev 11200)
@@ -326,7 +326,7 @@
       XScripter.insertText(view, data, node);
     else if(type == XTreeItem.MACRO_TYPE) {
       Log.log(Log.DEBUG, this, "Running Macro...");
-      XScripter.runMacro(view, (String)node.getUserObject(), data);
+      XScripter.runMacro(view, (String) node.getUserObject(), data);
       return;
       }
     else if(type == XTreeItem.XINSERT_SCRIPT_TYPE) {
@@ -334,10 +334,15 @@
       XScripter.runXInsertScript(view, data, node);
       }
     else if(type == XTreeItem.NAMED_MACRO_TYPE) {
-      Log.log(Log.DEBUG, this, "Running Named Macro...");
-      XScripter.runNamedMacro(view, (String)node.getUserObject(), data);
+      Log.log(Log.DEBUG, this, "Running Named Macro ...");
+      XScripter.runNamedMacro(view, (String) node.getUserObject(), data);
       return;
       }
+    else if(type == XTreeItem.ACTION_TYPE) {
+      Log.log(Log.DEBUG, this, "Invoking Action " + data + " ...");
+      XScripter.invokeAction(view, (String) node.getUserObject(), data);
+      return;
+      }
     else if(type == XTreeItem.REFERENCE_TYPE) {
       // new: lookup a referenced item by path [hertzhaft]
       Log.log(Log.DEBUG, this, "Resolving XInsert reference " + data + " ...");
@@ -388,6 +393,7 @@
   private static final ImageIcon macroLeaf = Utilities.getIcon("images/tree_leaf_macro.gif");
   private static final ImageIcon namedmacroLeaf = Utilities.getIcon("images/tree_leaf_namedmacro.gif");
   private static final ImageIcon referenceLeaf = Utilities.getIcon("images/tree_leaf_reference.gif");
+  private static final ImageIcon actionLeaf = Utilities.getIcon("images/tree_leaf_action.gif");
   private static final ImageIcon errorLeaf = Utilities.getIcon("images/tree_leaf_error.gif");
 
   class XTreeCellRenderer extends DefaultTreeCellRenderer {
@@ -424,6 +430,9 @@
             case XTreeItem.NAMED_MACRO_TYPE:
               leafIcon = namedmacroLeaf;
               break;
+            case XTreeItem.ACTION_TYPE:
+              leafIcon = actionLeaf;
+              break;
             case XTreeItem.REFERENCE_TYPE:
               leafIcon = referenceLeaf;
               break;
@@ -461,6 +470,8 @@
             return "Macro";
           else if(type == XTreeItem.XINSERT_SCRIPT_TYPE)
             return "Script";
+          else if(type == XTreeItem.ACTION_TYPE)
+            return "Action: " + content;
           else if(type == XTreeItem.NAMED_MACRO_TYPE)
             return "Named Macro";
           else if(type == XTreeItem.REFERENCE_TYPE)
Modified: plugins/XInsert/trunk/src/XTreeItem.java
===================================================================
--- plugins/XInsert/trunk/src/XTreeItem.java	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/src/XTreeItem.java	2007-12-07 10:48:26 UTC (rev 11200)
@@ -28,6 +28,7 @@
   public static final int XINSERT_SCRIPT_TYPE = 2;
   public static final int NAMED_MACRO_TYPE = 3;
   public static final int REFERENCE_TYPE = 4;
+  public static final int ACTION_TYPE = 5;
 
   private int type;
   private String content;
Modified: plugins/XInsert/trunk/xinsert.dtd
===================================================================
--- plugins/XInsert/trunk/xinsert.dtd	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/xinsert.dtd	2007-12-07 10:48:26 UTC (rev 11200)
@@ -7,9 +7,10 @@
 <!ELEMENT item (#PCDATA) >
   <!ATTLIST item
        name   CDATA #REQUIRED
-       type (text | macro | named_macro | xinsert_script | reference ) "text"
+       type (text | macro | named_macro | xinsert_script | action | reference ) "text"
+       mode   CDATA #IMPLIED
        abbrev CDATA #IMPLIED
-       mode   CDATA #IMPLIED
+       shortcut CDATA #IMPLIED
     >
 
 <!ELEMENT variable EMPTY >
Modified: plugins/XInsert/trunk/xinsert.html
===================================================================
--- plugins/XInsert/trunk/xinsert.html	2007-12-06 18:39:23 UTC (rev 11199)
+++ plugins/XInsert/trunk/xinsert.html	2007-12-07 10:48:26 UTC (rev 11200)
@@ -120,9 +120,7 @@
 <p>XInsert clips can be added in two ways: Either double click on
 the desired item in the expanded branch, or select the desired
 item in the tree and hit Enter or Space while the XInsert pane is
-focused.</p>
-
-<p>For convenience two actions were added that can be bound to keystroke
+focused. For convenience two actions were added that can be bound to keystroke
 combinations using the Utilities/Global Options/Shortcuts menu (A+F12).</p>
 
 <ul>
@@ -263,7 +261,7 @@
 substituted into the insert the closest variable tag in the tree
 hierachy is used.</p>
 
-<p>Item tags can be four types (specified with the type
+<p>Item tags can have one of five types (specified with the type
 attribute):</p>
 
 <dl compact>
@@ -283,6 +281,10 @@
 
 <dd>The content is treated as an <a href="#script">xinsert script</a>.</dd>
 
+<dt>action</dt>
+
+<dd>The content is treated as the name of a jEdit action.</dd>
+
 <dt>reference</dt>
 
 <dd>The content is a path to another entry in the XInsert tree. It is constructed by 
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |