click-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From take...@apache.org
Subject svn commit: r730512 - in /incubator/click/trunk/tools/eclipse/net.sf.clickide: ./ src/net/sf/clickide/ src/net/sf/clickide/ui/actions/ src/net/sf/clickide/ui/editor/
Date Thu, 01 Jan 2009 05:59:51 GMT
Author: takezoe
Date: Wed Dec 31 21:59:51 2008
New Revision: 730512

URL: http://svn.apache.org/viewvc?rev=730512&view=rev
Log:
Toggle Comment Action

Added:
    incubator/click/trunk/tools/eclipse/net.sf.clickide/memo.txt
    incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/actions/ToggleCommentAction.java
    incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditorActionContributor.java
Modified:
    incubator/click/trunk/tools/eclipse/net.sf.clickide/plugin.xml
    incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.java
    incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.properties
    incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin_ja.properties
    incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditor.java

Added: incubator/click/trunk/tools/eclipse/net.sf.clickide/memo.txt
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/memo.txt?rev=730512&view=auto
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/memo.txt (added)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/memo.txt Wed Dec 31 21:59:51 2008
@@ -0,0 +1,5 @@
+ClickIDE Development Memo
+--
+2.1.1
+
+ * Toggle Comment action (CTRL + /) in the Template Editor.
\ No newline at end of file

Modified: incubator/click/trunk/tools/eclipse/net.sf.clickide/plugin.xml
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/plugin.xml?rev=730512&r1=730511&r2=730512&view=diff
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/plugin.xml (original)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/plugin.xml Wed Dec 31 21:59:51 2008
@@ -87,7 +87,7 @@
     </editor>
     <editor
           class="net.sf.clickide.ui.editor.TemplateEditor"
-          contributorClass="org.eclipse.wst.html.ui.internal.edit.ui.ActionContributorHTML"
+          contributorClass="net.sf.clickide.ui.editor.TemplateEditorActionContributor"
           default="true"
           extensions="htm"
           icon="icons/velocity.gif"

Modified: incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.java?rev=730512&r1=730511&r2=730512&view=diff
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.java
(original)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.java
Wed Dec 31 21:59:51 2008
@@ -90,6 +90,10 @@
 		configProviders.add(new DefaultClickConfigurationProvider());
 	}
 
+	public ResourceBundle getResourceBundle(){
+		return this.resource;
+	}
+
 	private static List loadContributedClasses(String extPointId, String elementName){
 		List result = new ArrayList();
 		try {

Modified: incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.properties
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.properties?rev=730512&r1=730511&r2=730512&view=diff
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.properties
(original)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin.properties
Wed Dec 31 21:59:51 2008
@@ -40,6 +40,7 @@
 action.add=&Add
 action.edit=&Edit
 action.remove=&Remove
+action.toggleComment=Toggle Comment
 
 # for wizards
 wizard.newPage.title=New Click Page

Modified: incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin_ja.properties
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin_ja.properties?rev=730512&r1=730511&r2=730512&view=diff
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin_ja.properties
(original)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ClickPlugin_ja.properties
Wed Dec 31 21:59:51 2008
@@ -40,6 +40,7 @@
 action.add=\u8ffd\u52a0(&A)
 action.edit=\u7de8\u96c6(&E)
 action.remove=\u524a\u9664(&R)
+action.toggleComment=\u30b3\u30e1\u30f3\u30c8\u306e\u5207\u308a\u66ff\u3048
 
 # for wizards
 wizard.newPage.title=\u65b0\u898fClick\u30da\u30fc\u30b8

Added: incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/actions/ToggleCommentAction.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/actions/ToggleCommentAction.java?rev=730512&view=auto
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/actions/ToggleCommentAction.java
(added)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/actions/ToggleCommentAction.java
Wed Dec 31 21:59:51 2008
@@ -0,0 +1,52 @@
+package net.sf.clickide.ui.actions;
+
+import net.sf.clickide.ClickPlugin;
+
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.texteditor.ITextEditor;
+
+/**
+ *
+ * @author Naoki Takezoe
+ */
+public class ToggleCommentAction extends Action {
+
+	private ITextEditor editor;
+
+	public ToggleCommentAction(ITextEditor editor) {
+		super(ClickPlugin.getString("action.toggleComment"));
+		this.editor = editor;
+		setId(ToggleCommentAction.class.getName());
+		setActionDefinitionId(ToggleCommentAction.class.getName());
+		setAccelerator(SWT.CTRL | '/');
+	}
+
+	public void run() {
+		ITextSelection sel = (ITextSelection) editor.getSelectionProvider().getSelection();
+		IDocument doc = editor.getDocumentProvider().getDocument(editor.getEditorInput());
+
+		try {
+			int offset = doc.getLineOffset(sel.getStartLine());
+			String text = doc.get(offset, sel.getLength() + (sel.getOffset() - offset));
+
+			if(text.startsWith("##")){
+				text = text.replaceAll("(^|\r\n|\r|\n)##", "$1");
+			} else {
+				text = "##" + text.replaceAll("(\r\n|\r|\n)", "$1##");
+				if(text.endsWith("##")){
+					text = text.substring(0, text.length() - 2);
+				}
+			}
+
+			doc.replace(offset, sel.getLength() + (sel.getOffset() - offset), text);
+
+		} catch (BadLocationException e) {
+			e.printStackTrace();
+		}
+	}
+
+}

Modified: incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditor.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditor.java?rev=730512&r1=730511&r2=730512&view=diff
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditor.java
(original)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditor.java
Wed Dec 31 21:59:51 2008
@@ -1,20 +1,22 @@
 package net.sf.clickide.ui.editor;
 
 import net.sf.clickide.core.validator.TemplateValidator;
+import net.sf.clickide.ui.actions.ToggleCommentAction;
 
 import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.action.IMenuManager;
 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.swt.widgets.Composite;
 import org.eclipse.ui.IEditorInput;
 import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
 import org.eclipse.wst.sse.ui.StructuredTextEditor;
 
 /**
  * The editor for page templates which uses Velocity.
  * <p>
- * This editor extends WTP HTML editor and provides 
+ * This editor extends WTP HTML editor and provides
  * some new features for Velocity.
- * 
+ *
  * <ul>
  *   <li>Code completion for Velocity directives and the $format object</li>
  *   <li>Velocity syntax validation by {@link TemplateValidator}</li>
@@ -22,33 +24,38 @@
  *   <li>Code completion for the Page public fields as variables</li>
  *   <li>TODO Code completion for the variables which declared by the #set directive</li>
  * </ul>
- * 
+ *
  * @author Naoki Takezoe
  */
 public class TemplateEditor extends StructuredTextEditor {
 
-	public void createPartControl(Composite parent) {
-//		setSourceViewerConfiguration(new TemplateEditorConfiguration());
-		super.createPartControl(parent);
+	protected void createActions() {
+		super.createActions();
+		setAction(ToggleCommentAction.class.getName(), new ToggleCommentAction(this));
+	}
+
+	protected void addContextMenuActions(IMenuManager menu){
+		super.addContextMenuActions(menu);
+		addAction(menu, ITextEditorActionConstants.GROUP_EDIT, ToggleCommentAction.class.getName());
 	}
 
 	protected void doSetInput(IEditorInput input) throws CoreException {
 		super.doSetInput(input);
-		
+
 		setSourceViewerConfiguration(new TemplateEditorConfiguration());
-		
+
 		TemplateEditorConfiguration config
 			= (TemplateEditorConfiguration)getSourceViewerConfiguration();
 		IContentAssistProcessor[] processors
 			= config.getContentAssistProcessors(null, null);
 		TemplateContentAssistProcessor processor
 			= (TemplateContentAssistProcessor)processors[0];
-		
+
 		if(input instanceof IFileEditorInput){
 			processor.setFile(((IFileEditorInput)input).getFile());
 		} else {
 			processor.setFile(null);
 		}
 	}
-	
+
 }

Added: incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditorActionContributor.java
URL: http://svn.apache.org/viewvc/incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditorActionContributor.java?rev=730512&view=auto
==============================================================================
--- incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditorActionContributor.java
(added)
+++ incubator/click/trunk/tools/eclipse/net.sf.clickide/src/net/sf/clickide/ui/editor/TemplateEditorActionContributor.java
Wed Dec 31 21:59:51 2008
@@ -0,0 +1,74 @@
+package net.sf.clickide.ui.editor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.clickide.ClickPlugin;
+import net.sf.clickide.ui.actions.ToggleCommentAction;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.swt.SWT;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.RetargetTextEditorAction;
+import org.eclipse.wst.html.ui.internal.edit.ui.ActionContributorHTML;
+
+public class TemplateEditorActionContributor extends ActionContributorHTML {
+
+	private List actionIds = new ArrayList();
+	private List actions = new ArrayList();
+
+	public TemplateEditorActionContributor(){
+		actionIds.add(ToggleCommentAction.class.getName());
+	}
+
+	public void setActiveEditor(IEditorPart part) {
+		super.setActiveEditor(part);
+		doSetActiveEditor(part);
+	}
+
+	private void doSetActiveEditor(IEditorPart part) {
+		ITextEditor textEditor= null;
+		if (part instanceof ITextEditor){
+			textEditor = (ITextEditor) part;
+		}
+		if(textEditor!=null){
+			for(int i=0;i<this.actions.size();i++){
+				RetargetTextEditorAction action = (RetargetTextEditorAction) actions.get(i);
+				IAction targetAction = textEditor.getAction((String) actionIds.get(i));
+				if(targetAction!=null){
+					action.setAccelerator(targetAction.getAccelerator());
+					action.setAction(targetAction);
+				} else {
+					action.setAccelerator(SWT.NULL);
+					action.setAction(null);
+				}
+			}
+		}
+	}
+
+	public void init(IActionBars bars) {
+		super.init(bars);
+
+		IMenuManager menuManager = bars.getMenuManager();
+		IMenuManager editMenu = menuManager.findMenuUsingPath("edit");
+		if(editMenu!=null){
+			editMenu.insertBefore("additions", new Separator("clickide"));
+
+			if (editMenu != null) {
+				for(int i=0;i<actionIds.size();i++){
+					RetargetTextEditorAction action = new RetargetTextEditorAction(
+							ClickPlugin.getDefault().getResourceBundle(), null);
+					this.actions.add(action);
+					editMenu.appendToGroup("clickide", action);
+				}
+			}
+		}
+	}
+
+
+
+}



Mime
View raw message