Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoramywu2008-04-03 06:45:06 +0000
committeramywu2008-04-03 06:45:06 +0000
commit817060942beb6bfe4bb97b0fb3361457b23f5dee (patch)
tree0ed22384b96937005757cb9216443113833345b9 /bundles/org.eclipse.wst.css.ui/src
parentb73bdcb4557a9db8959063baab106b1e2b63dab1 (diff)
downloadwebtools.sourceediting-817060942beb6bfe4bb97b0fb3361457b23f5dee.tar.gz
webtools.sourceediting-817060942beb6bfe4bb97b0fb3361457b23f5dee.tar.xz
webtools.sourceediting-817060942beb6bfe4bb97b0fb3361457b23f5dee.zip
[224040] continuation of bug 212330, migrate sse menus
Diffstat (limited to 'bundles/org.eclipse.wst.css.ui/src')
-rw-r--r--bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/CleanupDocumentHandler.java120
-rw-r--r--bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectEnclosingHandler.java50
-rw-r--r--bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectNextHandler.java65
-rw-r--r--bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectPreviousHandler.java60
4 files changed, 295 insertions, 0 deletions
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/CleanupDocumentHandler.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/CleanupDocumentHandler.java
new file mode 100644
index 0000000000..a623b3ee18
--- /dev/null
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/CleanupDocumentHandler.java
@@ -0,0 +1,120 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.css.ui.internal.handlers;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.wst.css.core.internal.cleanup.CleanupProcessorCSS;
+import org.eclipse.wst.css.ui.internal.edit.ui.CleanupDialogCSS;
+import org.eclipse.wst.sse.core.StructuredModelManager;
+import org.eclipse.wst.sse.core.internal.cleanup.IStructuredCleanupProcessor;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.ui.internal.SSEUIMessages;
+
+public class CleanupDocumentHandler extends AbstractHandler implements IHandler {
+ private IStructuredCleanupProcessor fCleanupProcessor;
+
+ public void dispose() {
+ // nulling out just in case
+ fCleanupProcessor = null;
+ }
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
+ ITextEditor textEditor = null;
+ if (editorPart instanceof ITextEditor)
+ textEditor = (ITextEditor) editorPart;
+ else {
+ Object o = editorPart.getAdapter(ITextEditor.class);
+ if (o != null)
+ textEditor = (ITextEditor) o;
+ }
+
+ if (textEditor != null) {
+ final ITextEditor editor = textEditor;
+ Dialog cleanupDialog = new CleanupDialogCSS(editor.getSite().getShell());
+ if (cleanupDialog.open() == Window.OK) {
+ // setup runnable
+ Runnable runnable = new Runnable() {
+ public void run() {
+ IStructuredCleanupProcessor cleanupProcessor = getCleanupProcessor();
+ if (cleanupProcessor != null) {
+ IStructuredModel model = null;
+ try {
+ model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
+ if (model != null)
+ cleanupProcessor.cleanupModel(model);
+ }
+ finally {
+ if (model != null)
+ model.releaseFromEdit();
+ }
+ }
+ }
+ };
+
+ // TODO: make independent of 'model'.
+ IStructuredModel model = null;
+ try {
+ model = StructuredModelManager.getModelManager().getExistingModelForEdit(editor.getDocumentProvider().getDocument(editor.getEditorInput()));
+ if (model != null) {
+ // begin recording
+ ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
+ model.beginRecording(this, SSEUIMessages.Cleanup_Document_UI_, SSEUIMessages.Cleanup_Document_UI_, selection.getOffset(), selection.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ // tell the model that we are about to make a big
+ // model change
+ model.aboutToChangeModel();
+
+ // run
+ BusyIndicator.showWhile(editor.getEditorSite().getWorkbenchWindow().getShell().getDisplay(), runnable);
+ }
+ }
+ finally {
+ if (model != null) {
+ // tell the model that we are done with the big
+ // model
+ // change
+ model.changedModel();
+
+ // end recording
+ ITextSelection selection = (ITextSelection) editor.getSelectionProvider().getSelection();
+ model.endRecording(this, selection.getOffset(), selection.getLength());
+ model.releaseFromEdit();
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ // do nothing
+ }
+
+ IStructuredCleanupProcessor getCleanupProcessor() {
+ if (fCleanupProcessor == null)
+ fCleanupProcessor = new CleanupProcessorCSS();
+
+ return fCleanupProcessor;
+ }
+}
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectEnclosingHandler.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectEnclosingHandler.java
new file mode 100644
index 0000000000..ac19982754
--- /dev/null
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectEnclosingHandler.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.css.ui.internal.handlers;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.Region;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.handlers.AbstractStructuredSelectHandler;
+
+public class StructuredSelectEnclosingHandler extends AbstractStructuredSelectHandler {
+
+ protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
+ IndexedRegion indexedRegion = null;
+
+ indexedRegion = getIndexedRegion(document, textSelection.getOffset());
+
+ return indexedRegion;
+ }
+
+ protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
+ Region newRegion = null;
+ if (indexedRegion instanceof ICSSNode) {
+ ICSSNode cursorNode = (ICSSNode) indexedRegion;
+ Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
+ int currentOffset = textSelection.getOffset();
+ int currentEndOffset = currentOffset + textSelection.getLength();
+ if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
+ ICSSNode newNode = cursorNode.getParentNode();
+
+ if (newNode instanceof IndexedRegion) {
+ IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
+ newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
+ }
+ }
+ else
+ newRegion = cursorNodeRegion;
+ }
+ return newRegion;
+ }
+}
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectNextHandler.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectNextHandler.java
new file mode 100644
index 0000000000..bfccb26a81
--- /dev/null
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectNextHandler.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.css.ui.internal.handlers;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.Region;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.handlers.AbstractStructuredSelectHandler;
+
+public class StructuredSelectNextHandler extends AbstractStructuredSelectHandler {
+
+ protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
+ int offset = textSelection.getOffset() + textSelection.getLength() - 1;
+ if (offset < 0)
+ offset = 0;
+
+ IndexedRegion indexedRegion = null;
+
+ indexedRegion = getIndexedRegion(document, offset);
+
+ return indexedRegion;
+ }
+
+ protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
+ Region newRegion = null;
+
+ if (indexedRegion instanceof ICSSNode) {
+ ICSSNode cursorNode = (ICSSNode) indexedRegion;
+
+ Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
+ int currentOffset = textSelection.getOffset();
+ int currentEndOffset = currentOffset + textSelection.getLength();
+ if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
+ ICSSNode newNode = cursorNode.getNextSibling();
+ if (newNode == null) {
+ newNode = cursorNode.getParentNode();
+
+ if (newNode instanceof IndexedRegion) {
+ IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
+ newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
+ }
+ }
+ else {
+ if (newNode instanceof IndexedRegion) {
+ IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
+ newRegion = new Region(currentOffset, newIndexedRegion.getEndOffset() - currentOffset);
+ }
+ }
+ }
+ else
+ newRegion = cursorNodeRegion;
+ }
+ return newRegion;
+ }
+}
diff --git a/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectPreviousHandler.java b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectPreviousHandler.java
new file mode 100644
index 0000000000..5827a4f664
--- /dev/null
+++ b/bundles/org.eclipse.wst.css.ui/src/org/eclipse/wst/css/ui/internal/handlers/StructuredSelectPreviousHandler.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2008 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.wst.css.ui.internal.handlers;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.Region;
+import org.eclipse.wst.css.core.internal.provisional.document.ICSSNode;
+import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
+import org.eclipse.wst.sse.ui.internal.handlers.AbstractStructuredSelectHandler;
+
+public class StructuredSelectPreviousHandler extends AbstractStructuredSelectHandler {
+
+ protected IndexedRegion getCursorIndexedRegion(IDocument document, ITextSelection textSelection) {
+ IndexedRegion indexedRegion = null;
+
+ indexedRegion = getIndexedRegion(document, textSelection.getOffset());
+
+ return indexedRegion;
+ }
+
+ protected Region getNewSelectionRegion(IndexedRegion indexedRegion, ITextSelection textSelection) {
+ Region newRegion = null;
+ if (indexedRegion instanceof ICSSNode) {
+ ICSSNode cursorNode = (ICSSNode) indexedRegion;
+
+ Region cursorNodeRegion = new Region(indexedRegion.getStartOffset(), indexedRegion.getEndOffset() - indexedRegion.getStartOffset());
+ int currentOffset = textSelection.getOffset();
+ int currentEndOffset = currentOffset + textSelection.getLength();
+ if (cursorNodeRegion.getOffset() >= currentOffset && cursorNodeRegion.getOffset() <= currentEndOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() >= currentOffset && cursorNodeRegion.getOffset() + cursorNodeRegion.getLength() <= currentEndOffset) {
+ ICSSNode newNode = cursorNode.getPreviousSibling();
+ if (newNode == null) {
+ newNode = cursorNode.getParentNode();
+
+ if (newNode instanceof IndexedRegion) {
+ IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
+ newRegion = new Region(newIndexedRegion.getStartOffset(), newIndexedRegion.getEndOffset() - newIndexedRegion.getStartOffset());
+ }
+ }
+ else {
+ if (newNode instanceof IndexedRegion) {
+ IndexedRegion newIndexedRegion = (IndexedRegion) newNode;
+ newRegion = new Region(newIndexedRegion.getStartOffset(), currentEndOffset - newIndexedRegion.getStartOffset());
+ }
+ }
+ }
+ else
+ newRegion = cursorNodeRegion;
+ }
+ return newRegion;
+ }
+}

Back to the top