Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.ui.editors')
-rw-r--r--org.eclipse.ui.editors/plugin.xml48
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextOperationActionHandler.java85
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseAllHandler.java22
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseHandler.java22
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandAllHandler.java22
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandHandler.java22
6 files changed, 221 insertions, 0 deletions
diff --git a/org.eclipse.ui.editors/plugin.xml b/org.eclipse.ui.editors/plugin.xml
index 3976749e1b8..3ba076fc1fc 100644
--- a/org.eclipse.ui.editors/plugin.xml
+++ b/org.eclipse.ui.editors/plugin.xml
@@ -167,6 +167,54 @@
commandId="org.eclipse.ui.edit.text.removeTrailingWhitespace"
class="org.eclipse.ui.internal.editors.text.RemoveTrailingWhitespaceHandler">
</handler>
+ <handler
+ commandId="org.eclipse.ui.edit.text.folding.collapse_all"
+ class="org.eclipse.ui.internal.editors.text.folding.CollapseAllHandler">
+ <enabledWhen>
+ <with
+ variable="activePart">
+ <adapt
+ type="org.eclipse.jface.text.ITextOperationTarget">
+ </adapt>
+ </with>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.ui.internal.editors.text.folding.CollapseAllHandler"
+ commandId="org.eclipse.ui.edit.text.folding.collapse_all">
+ <enabledWhen>
+ <with
+ variable="activePart">
+ <adapt
+ type="org.eclipse.jface.text.ITextOperationTarget">
+ </adapt>
+ </with>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.ui.internal.editors.text.folding.ExpandAllHandler"
+ commandId="org.eclipse.ui.edit.text.folding.expand_all">
+ <enabledWhen>
+ <with
+ variable="activePart">
+ <adapt
+ type="org.eclipse.jface.text.ITextOperationTarget">
+ </adapt>
+ </with>
+ </enabledWhen>
+ </handler>
+ <handler
+ class="org.eclipse.ui.internal.editors.text.folding.ExpandHandler"
+ commandId="org.eclipse.ui.edit.text.folding.expand">
+ <enabledWhen>
+ <with
+ variable="activePart">
+ <adapt
+ type="org.eclipse.jface.text.ITextOperationTarget">
+ </adapt>
+ </with>
+ </enabledWhen>
+ </handler>
</extension>
<extension
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextOperationActionHandler.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextOperationActionHandler.java
new file mode 100644
index 00000000000..b78b11a3325
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/TextOperationActionHandler.java
@@ -0,0 +1,85 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.ui.internal.editors.text;
+
+import org.eclipse.swt.custom.BusyIndicator;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+
+import org.eclipse.core.runtime.Status;
+
+import org.eclipse.jface.text.ITextOperationTarget;
+
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Abstract Handler to delegate to an operation of {@link ITextOperationTarget}.
+ */
+public abstract class TextOperationActionHandler extends AbstractHandler {
+
+ protected final int operationCode;
+
+ public TextOperationActionHandler(int operationCode) {
+ this.operationCode= operationCode;
+ }
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ if (operationCode < 0) {
+ return null;
+ }
+ IWorkbenchPart part= HandlerUtil.getActivePart(event);
+ ITextOperationTarget target= part.getAdapter(ITextOperationTarget.class);
+ if (target == null) {
+ return null;
+ }
+
+ IWorkbenchPartSite site= part.getSite();
+ Shell shell= site.getShell();
+ if (shell != null && !shell.isDisposed()) {
+ Display display= shell.getDisplay();
+ BusyIndicator.showWhile(display, () -> target.doOperation(operationCode));
+ return Status.OK_STATUS;
+ }
+ return null;
+ }
+
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ IWorkbench workbench= PlatformUI.getWorkbench();
+ if (workbench == null) {
+ setBaseEnabled(false);
+ return;
+ }
+ IWorkbenchWindow window= workbench.getActiveWorkbenchWindow();
+ if (window == null) {
+ setBaseEnabled(false);
+ return;
+ }
+ IWorkbenchPage page= window.getActivePage();
+ if (page == null) {
+ setBaseEnabled(false);
+ return;
+ }
+ IWorkbenchPart part= page.getActivePart();
+ setBaseEnabled(part != null && part.getAdapter(ITextOperationTarget.class) != null);
+ }
+}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseAllHandler.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseAllHandler.java
new file mode 100644
index 00000000000..7646a395640
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseAllHandler.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.ui.internal.editors.text.folding;
+
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+
+import org.eclipse.ui.internal.editors.text.TextOperationActionHandler;
+
+public class CollapseAllHandler extends TextOperationActionHandler {
+
+ public CollapseAllHandler() {
+ super(ProjectionViewer.COLLAPSE_ALL);
+ }
+}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseHandler.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseHandler.java
new file mode 100644
index 00000000000..a2fe6abcd26
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/CollapseHandler.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.ui.internal.editors.text.folding;
+
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+
+import org.eclipse.ui.internal.editors.text.TextOperationActionHandler;
+
+public class CollapseHandler extends TextOperationActionHandler {
+
+ public CollapseHandler() {
+ super(ProjectionViewer.COLLAPSE);
+ }
+}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandAllHandler.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandAllHandler.java
new file mode 100644
index 00000000000..f2c88dd9cff
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandAllHandler.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.ui.internal.editors.text.folding;
+
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+
+import org.eclipse.ui.internal.editors.text.TextOperationActionHandler;
+
+public class ExpandAllHandler extends TextOperationActionHandler {
+
+ public ExpandAllHandler() {
+ super(ProjectionViewer.EXPAND_ALL);
+ }
+}
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandHandler.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandHandler.java
new file mode 100644
index 00000000000..b2596c0b13b
--- /dev/null
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/text/folding/ExpandHandler.java
@@ -0,0 +1,22 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Red Hat Inc. and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.ui.internal.editors.text.folding;
+
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
+
+import org.eclipse.ui.internal.editors.text.TextOperationActionHandler;
+
+public class ExpandHandler extends TextOperationActionHandler {
+
+ public ExpandHandler() {
+ super(ProjectionViewer.EXPAND);
+ }
+}

Back to the top