From 3b680c8d8e6f1af7a42addb8d4924096341e7235 Mon Sep 17 00:00:00 2001 From: Fabrizio Iannetti Date: Sat, 30 Jan 2021 12:43:57 +0100 Subject: [PATCH] Bug 570775: Add pop-up action to invert terminal colors on the fly New action to temporarily invert the terminal colors, the preference setting is not altered by this action. Only the active terminal is affected. Change-Id: Idc01163838539c2ba5699556951c1742bbf07ad6 Signed-off-by: Fabrizio Iannetti --- .../META-INF/MANIFEST.MF | 2 +- .../control/ITerminalViewControl.java | 7 ++- .../emulator/VT100TerminalControl.java | 7 ++- .../terminal/textcanvas/ILinelRenderer.java | 2 + .../terminal/textcanvas/StyleMap.java | 4 ++ .../terminal/textcanvas/TextCanvas.java | 4 ++ .../terminal/textcanvas/TextLineRenderer.java | 5 ++ .../META-INF/MANIFEST.MF | 2 +- .../about.properties | 4 +- .../view/ui/actions/InvertColorsAction.java | 55 +++++++++++++++++++ .../tm/terminal/view/ui/nls/Messages.java | 5 +- .../terminal/view/ui/nls/Messages.properties | 5 +- .../view/ui/tabs/TabFolderMenuHandler.java | 11 +++- 13 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/InvertColorsAction.java diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/META-INF/MANIFEST.MF b/terminal/plugins/org.eclipse.tm.terminal.control/META-INF/MANIFEST.MF index e9749de69dd..4279683d5a8 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/META-INF/MANIFEST.MF +++ b/terminal/plugins/org.eclipse.tm.terminal.control/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.tm.terminal.control; singleton:=true -Bundle-Version: 5.0.100.qualifier +Bundle-Version: 5.1.0.qualifier Bundle-Activator: org.eclipse.tm.internal.terminal.control.impl.TerminalPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java index 19eb2ef3386..5b20b09d97d 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/control/ITerminalViewControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2018 Wind River Systems, Inc. and others. + * Copyright (c) 2006, 2021 Wind River Systems, Inc. and others. * All rights reserved. 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 @@ -70,6 +70,11 @@ public interface ITerminalViewControl { void setInvertedColors(boolean invert); + /** + * @since 5.1 + */ + boolean isInvertedColors(); + Font getFont(); /** diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java index 6271c0d8733..2205ce34002 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/emulator/VT100TerminalControl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2018 Wind River Systems, Inc. and others. + * Copyright (c) 2003, 2021 Wind River Systems, Inc. and others. * All rights reserved. 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 @@ -1365,6 +1365,11 @@ public class VT100TerminalControl implements ITerminalControlForText, ITerminalC fCtlText.setInvertedColors(invert); } + @Override + public boolean isInvertedColors() { + return fCtlText.isInvertedColors(); + } + @Override public final void setConnectOnEnterIfClosed(boolean on) { connectOnEnterIfClosed = on; diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java index 8ef7c58cb89..a02b67fcfa9 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/ILinelRenderer.java @@ -50,6 +50,8 @@ public interface ILinelRenderer { void setInvertedColors(boolean invert); + boolean isInvertedColors(); + /** * @deprecated use {@link #getDefaultBackgroundColor(Device)} */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java index f2af6cbe4de..330070cdafb 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/StyleMap.java @@ -136,6 +136,10 @@ public class StyleMap { fInvertColors = invert; } + public boolean isInvertedColors() { + return fInvertColors; + } + public Font getFont(TerminalStyle style) { style = defaultIfNull(style); if (style.isBold()) { diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java index 493b8b17c88..449914c1f09 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextCanvas.java @@ -510,6 +510,10 @@ public class TextCanvas extends GridCanvas { redraw(); } + public boolean isInvertedColors() { + return fCellRenderer.isInvertedColors(); + } + /** * @return true if the cursor is enabled (blinking). By default the cursor is not enabled. */ diff --git a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java index d092bc6fc8b..884232b78dd 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java +++ b/terminal/plugins/org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/textcanvas/TextLineRenderer.java @@ -208,4 +208,9 @@ public class TextLineRenderer implements ILinelRenderer { fStyleMap.setInvertedColors(invert); } + + @Override + public boolean isInvertedColors() { + return fStyleMap.isInvertedColors(); + } } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/META-INF/MANIFEST.MF b/terminal/plugins/org.eclipse.tm.terminal.view.ui/META-INF/MANIFEST.MF index 6b7095da140..b6d072b9c77 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/META-INF/MANIFEST.MF +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.tm.terminal.view.ui;singleton:=true -Bundle-Version: 4.7.100.qualifier +Bundle-Version: 4.8.0.qualifier Bundle-Activator: org.eclipse.tm.terminal.view.ui.activator.UIPlugin Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.expressions;bundle-version="3.4.400", diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/about.properties b/terminal/plugins/org.eclipse.tm.terminal.view.ui/about.properties index a590a7abfc2..50a88bac4e2 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/about.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/about.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2018, 2020 Contributors to the Eclipse Foundation +# Copyright (c) 2018, 2021 Contributors to the Eclipse Foundation # # See the NOTICE file(s) distributed with this work for additional # information regarding copyright ownership. @@ -24,7 +24,7 @@ blurb=Terminal (Console) View\n\ Version: {featureVersion}\n\ Build id: {0}\n\ \n\ -Copyright (c) 2018, 2020 Contributors to the Eclipse Foundation +Copyright (c) 2018, 2021 Contributors to the Eclipse Foundation \n\ See the NOTICE file(s) distributed with this work for additional\n\ information regarding copyright ownership.\n\ diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/InvertColorsAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/InvertColorsAction.java new file mode 100644 index 00000000000..d729a495fba --- /dev/null +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/InvertColorsAction.java @@ -0,0 +1,55 @@ +/******************************************************************************* + * Copyright (c) 2021 Fabrizio Iannetti. + * + * 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.tm.terminal.view.ui.actions; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; +import org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction; +import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; +import org.eclipse.tm.terminal.view.ui.nls.Messages; +import org.eclipse.tm.terminal.view.ui.tabs.TabFolderManager; + +/** + * @since 4.8 + */ +public class InvertColorsAction extends AbstractTerminalAction { + + /** + * Constructor. + * + * @param tabFolderManager The parent tab folder manager. Must not be null. + */ + public InvertColorsAction(TabFolderManager tabFolderManager) { + super(null, SelectEncodingAction.class.getName(), IAction.AS_CHECK_BOX); + + Assert.isNotNull(tabFolderManager); + setupAction(Messages.InvertColorsAction_menu, Messages.InvertColorsAction_tooltip, (ImageDescriptor) null, + (ImageDescriptor) null, (ImageDescriptor) null, true); + } + + @Override + public void run() { + ITerminalViewControl target = getTarget(); + if (target == null) + return; + target.setInvertedColors(!target.isInvertedColors()); + } + + @Override + public void updateAction(boolean aboutToShow) { + setEnabled(aboutToShow && getTarget() != null && getTarget().getState() == TerminalState.CONNECTED); + setChecked(aboutToShow && getTarget() != null && getTarget().isInvertedColors()); + } + +} diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java index 84bbfc1e720..e6c28bf7b6c 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2021 Wind River Systems, Inc. and others. All rights reserved. * 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/ @@ -83,6 +83,9 @@ public class Messages extends NLS { public static String SelectEncodingAction_menu; public static String SelectEncodingAction_tooltip; + public static String InvertColorsAction_menu; + public static String InvertColorsAction_tooltip; + public static String ProcessSettingsPage_dialogTitle; public static String ProcessSettingsPage_processImagePathSelectorControl_label; public static String ProcessSettingsPage_processImagePathSelectorControl_button; diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties index e0ecf2bf134..05f02561350 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/nls/Messages.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2012, 2018 Wind River Systems, Inc. and others. All rights reserved. +# Copyright (c) 2012, 2021 Wind River Systems, Inc. and others. All rights reserved. # 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/ @@ -39,6 +39,9 @@ ToggleCommandFieldAction_toolTip=Toggle Command Input Field SelectEncodingAction_menu=Switch Encoding... SelectEncodingAction_tooltip=Switch the Encoding of the active Terminal +InvertColorsAction_menu=Inverted colors +InvertColorsAction_tooltip=Invert the colors of the active Terminal + ProcessSettingsPage_dialogTitle=Select Process Image ProcessSettingsPage_processImagePathSelectorControl_label=Image Path: ProcessSettingsPage_processImagePathSelectorControl_button=Browse diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java index e6ebfc659a3..451e0a17c6c 100644 --- a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/tabs/TabFolderMenuHandler.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2018 Wind River Systems, Inc. and others. All rights reserved. + * Copyright (c) 2011, 2021 Wind River Systems, Inc. and others. All rights reserved. * 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/ @@ -36,6 +36,7 @@ import org.eclipse.tm.internal.terminal.control.actions.TerminalActionPaste; import org.eclipse.tm.internal.terminal.control.actions.TerminalActionSelectAll; import org.eclipse.tm.internal.terminal.provisional.api.TerminalState; import org.eclipse.tm.terminal.view.core.interfaces.constants.ITerminalsConnectorConstants; +import org.eclipse.tm.terminal.view.ui.actions.InvertColorsAction; import org.eclipse.tm.terminal.view.ui.actions.SelectEncodingAction; import org.eclipse.tm.terminal.view.ui.interfaces.ITerminalsView; import org.eclipse.ui.IWorkbenchActionConstants; @@ -294,6 +295,14 @@ public class TabFolderMenuHandler extends PlatformObject { return getActiveTerminalViewControl(); } }); + + // Create and add the invert colors action + add(new InvertColorsAction(getParentView().getAdapter(TabFolderManager.class)) { + @Override + protected ITerminalViewControl getTarget() { + return getActiveTerminalViewControl(); + } + }); } /**