[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-commits ] SF.net SVN: jedit: [12959] jEdit/trunk
From:       ezust () users ! sourceforge ! net
Date:       2008-06-28 19:27:42
Message-ID: E1KCg5G-00049P-Hp () sc8-pr-svn4 ! sourceforge ! net
[Download RAW message or body]

Revision: 12959
          http://jedit.svn.sourceforge.net/jedit/?rev=12959&view=rev
Author:   ezust
Date:     2008-06-28 12:27:42 -0700 (Sat, 28 Jun 2008)

Log Message:
-----------
Made the DynamicContextMenuService take a textarea.
Incorporated Dale's GUIUTiltiies suggestions.
Updated the context menu whenever it is requested.

Modified Paths:
--------------
    jEdit/trunk/doc/users-guide/text-edit.xml
    jEdit/trunk/org/gjt/sp/jedit/EditPane.java
    jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java
    jEdit/trunk/org/gjt/sp/jedit/gui/DynamicContextMenuService.java
    jEdit/trunk/org/gjt/sp/jedit/textarea/JEditTextArea.java

Modified: jEdit/trunk/doc/users-guide/text-edit.xml
===================================================================
--- jEdit/trunk/doc/users-guide/text-edit.xml	2008-06-28 15:57:16 UTC (rev 12958)
+++ jEdit/trunk/doc/users-guide/text-edit.xml	2008-06-28 19:27:42 UTC (rev 12959)
@@ -19,7 +19,7 @@
         <keycap>UP</keycap> and <keycap>DOWN</keycap> keys move the caret in the
         respective direction, and the <keycap>PAGE_UP</keycap> and
         <keycap>PAGE_DOWN</keycap> keys move the caret up and down one
-        screenful, respectively.</para>
+        screen-full, respectively.</para>
 
         <para>When pressed once, the <keycap>HOME</keycap> key moves the caret
         to the first non-whitespace character of the current screen line.

Modified: jEdit/trunk/org/gjt/sp/jedit/EditPane.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/EditPane.java	2008-06-28 15:57:16 UTC (rev 12958)
+++ jEdit/trunk/org/gjt/sp/jedit/EditPane.java	2008-06-28 19:27:42 UTC (rev 12959)
@@ -42,7 +42,6 @@
 import org.gjt.sp.jedit.bufferset.BufferSet;
 import org.gjt.sp.jedit.bufferset.BufferSetListener;
 import org.gjt.sp.jedit.gui.BufferSwitcher;
-import org.gjt.sp.jedit.gui.DynamicContextMenuService;
 import org.gjt.sp.jedit.gui.StatusBar;
 import org.gjt.sp.jedit.io.VFSManager;
 import org.gjt.sp.jedit.msg.BufferChanging;
@@ -947,7 +946,7 @@
 			"view.electricBorders",0));
 
 		// Set up the right-click popup menu
-		JPopupMenu popup = GUIUtilities.loadPopupMenu("view.context");
+		JPopupMenu popup = GUIUtilities.loadPopupMenu("view.context", getTextArea());
 		
 		JMenuItem customize = new JMenuItem(jEdit.getProperty(
 			"view.context.customize"));

Modified: jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java	2008-06-28 15:57:16 UTC (rev \
                12958)
+++ jEdit/trunk/org/gjt/sp/jedit/GUIUtilities.java	2008-06-28 19:27:42 UTC (rev \
12959) @@ -23,7 +23,9 @@
 package org.gjt.sp.jedit;
 
 //{{{ Imports
+
 import org.gjt.sp.jedit.browser.VFSFileChooserDialog;
+import org.gjt.sp.jedit.gui.DynamicContextMenuService;
 import org.gjt.sp.jedit.gui.EnhancedButton;
 import org.gjt.sp.jedit.gui.FloatingWindowContainer;
 import org.gjt.sp.jedit.gui.SplashScreen;
@@ -32,18 +34,43 @@
 import org.gjt.sp.jedit.menu.EnhancedMenu;
 import org.gjt.sp.jedit.menu.EnhancedMenuItem;
 import org.gjt.sp.jedit.syntax.SyntaxStyle;
+import org.gjt.sp.jedit.textarea.TextArea;
 import org.gjt.sp.jedit.textarea.TextAreaMouseHandler;
 import org.gjt.sp.util.Log;
 import org.gjt.sp.util.SyntaxUtilities;
 
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
+
 import java.net.URL;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
 import java.util.List;
-//}}}
+import java.util.Map;
+import java.util.StringTokenizer;
 
+import javax.swing.Icon;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JMenu;
+import javax.swing.JMenuBar;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSplitPane;
+import javax.swing.JToolBar;
+import javax.swing.ListSelectionModel;
+import javax.swing.SwingUtilities;
+
+
+import java.awt.*;
+import java.awt.event.*;
+
 /**
  * Various GUI functions.<p>
  *
@@ -262,7 +289,18 @@
 	//{{{ loadPopupMenu() method
 	/**
 	 * Creates a popup menu.
+	 * @param name The menu name
+	 * @since jEdit 2.6pre2
+	 */
+	public static JPopupMenu loadPopupMenu(String name, TextArea textArea)
+	{
+		return loadPopupMenu(jEdit.getActionContext(), name, textArea);
+	} //}}}
 
+	//{{{ loadPopupMenu() method
+	/**
+	 * Creates a popup menu.
+
 	 * @param name The menu name
 	 * @since jEdit 2.6pre2
 	 */
@@ -283,6 +321,23 @@
 	 */
 	public static JPopupMenu loadPopupMenu(ActionContext context, String name)
 	{
+		return loadPopupMenu(context, name, null);
+	}
+
+	//{{{ loadPopupMenu() method
+	/**
+	 * Creates a popup menu.
+
+	 * @param context An action context; either
+	 * <code>jEdit.getActionContext()</code> or
+	 * <code>VFSBrowser.getActionContext()</code>.
+	 * @param name The menu name
+	 * @param editPane the EditPane holding the TextArea wanting to show the
+	 * popup. If not null, include context menu items defined by services.
+	 * @since jEdit 4.3pre15
+	 */
+	public static JPopupMenu loadPopupMenu(ActionContext context, String name, TextArea \
textArea) +	{
 		JPopupMenu menu = new JPopupMenu();
 
 		String menuItems = jEdit.getProperty(name);
@@ -298,9 +353,51 @@
 					menu.add(loadMenuItem(context,menuItemName,false));
 			}
 		}
+		// load menu items defined by services
+		if (textArea != null)
+		{
+			List<JMenuItem> list = GUIUtilities.getServiceContextMenuItems(textArea);
+			if (list.size() > 0)
+			{
+				menu.addSeparator();
+			}
+			for (JMenuItem mi : list)
+			{
+				menu.add(mi);
+			}
+		}
 
 		return menu;
 	} //}}}
+	//{{{ addServiceContextMenuItems() method
+	/**
+	 * @return a list of menu items defined by services.
+	 *
+	 * @param editPane the EditPane desiring to display these menu items
+	 * @since jEdit 4.3pre15
+	 */
+	public static List<JMenuItem> getServiceContextMenuItems(TextArea textArea) {
+		List<JMenuItem> list = new ArrayList<JMenuItem>();
+		final String serviceClassName =  DynamicContextMenuService.class.getName();
+		String[] menuServiceList = ServiceManager.getServiceNames(serviceClassName);
+		for (String menuServiceName : menuServiceList)
+		{
+			if (menuServiceName != null && menuServiceName.trim().length() > 0)
+			{
+				DynamicContextMenuService dcms = (DynamicContextMenuService) (
+						ServiceManager.getService(serviceClassName, menuServiceName));
+				if (dcms != null)
+				{
+					JMenuItem mi = dcms.createMenu(textArea);
+					if (mi != null)
+					{
+						list.add(mi);
+					}
+				}
+			}
+		}
+		return list;
+	} //}}}
 
 	//{{{ loadMenuItem() method
 	/**

Modified: jEdit/trunk/org/gjt/sp/jedit/gui/DynamicContextMenuService.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/gui/DynamicContextMenuService.java	2008-06-28 \
                15:57:16 UTC (rev 12958)
+++ jEdit/trunk/org/gjt/sp/jedit/gui/DynamicContextMenuService.java	2008-06-28 \
19:27:42 UTC (rev 12959) @@ -13,7 +13,7 @@
 abstract public class DynamicContextMenuService {
 	/**
 	 * 
-	 * @param pane the editPane where the context menu was requested.
+	 * @param pane the TextArea where the context menu was requested.
 	 * 	   Use this to determine the location of the caret, or the edit mode of the \
                buffer, etc.
 	 * @return a dynamic menu item (or JMenu) dependent on state of pane
 	 *         or null if there is no appropriate action to be added at this time

Modified: jEdit/trunk/org/gjt/sp/jedit/textarea/JEditTextArea.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/textarea/JEditTextArea.java	2008-06-28 15:57:16 UTC \
                (rev 12958)
+++ jEdit/trunk/org/gjt/sp/jedit/textarea/JEditTextArea.java	2008-06-28 19:27:42 UTC \
(rev 12959) @@ -25,16 +25,13 @@
 
 //{{{ Imports
 import java.awt.AWTEvent;
-import java.awt.Component;
+
 import java.awt.Point;
 import java.awt.event.MouseEvent;
-import java.util.Vector;
-
-import javax.swing.JMenuItem;
 import javax.swing.JPopupMenu;
 
 import org.gjt.sp.jedit.*;
-import org.gjt.sp.jedit.gui.DynamicContextMenuService;
+
 import org.gjt.sp.jedit.msg.PositionChanging;
 
 /**
@@ -455,7 +452,7 @@
 	//{{{ Instance variables
 	private View view;
 	private JPopupMenu popup;
-	private JPopupMenu dynamicPopup;
+
 	private boolean popupEnabled;
 	//}}}
 	//}}}
@@ -509,31 +506,13 @@
 	 */
 	public void handlePopupTrigger(MouseEvent evt)
 	{
-		dynamicPopup = new JPopupMenu();
-		
-		/* Add dynamic context menus if any services are offered */
-		final String serviceName =  DynamicContextMenuService.class.getName();
-		String[] dclist = ServiceManager.getServiceNames(serviceName);
-		for (String dc: dclist) {
-			DynamicContextMenuService dcms = (DynamicContextMenuService) (
-					ServiceManager.getService(serviceName, dc));
-			JMenuItem item = dcms.createMenu(this);
-			// Q: Can we make it insert at the top instead? 
-			if (item != null) dynamicPopup.add(item);
-		}
-		
-		for (Component c: popup.getComponents()) {
-			if (c instanceof JMenuItem) {
-				JMenuItem mi = (JMenuItem)c;
-				dynamicPopup.add(mi);
-			}
-		}
-		
-		
-		if(dynamicPopup.isVisible())
-			dynamicPopup.setVisible(false);
+			
+		if(popup.isVisible())
+			popup.setVisible(false);
 		else
 		{
+			// Rebuild popup menu every time the menu is requested.
+			popup = GUIUtilities.loadPopupMenu("view.context", this);
 			int x = evt.getX();
 			int y = evt.getY();
 
@@ -543,7 +522,7 @@
 
 			if(getSelectionCount() == 0 || multi)
 				moveCaretPosition(dragStart,false);
-			GUIUtilities.showPopupMenu(dynamicPopup,painter,x,y);
+			GUIUtilities.showPopupMenu(popup,painter,x,y);
 		}
 	} //}}}
 


This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic