From 6874b7e0130678c4d151eb8f3b38237e046f1694 Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 26 Feb 2021 14:10:01 -0500 Subject: [PATCH] Bug 341721: Add context menu item to change terminal name Change-Id: Idd41b58ad4f052c32d6a9c57303f1b9ef05aff7c --- .../control/ITerminalViewControl.java | 5 ++ .../view/ui/actions/RenameTerminalAction.java | 65 +++++++++++++++++++ .../tm/terminal/view/ui/nls/Messages.java | 5 ++ .../terminal/view/ui/nls/Messages.properties | 6 ++ .../view/ui/tabs/TabFolderMenuHandler.java | 9 +++ 5 files changed, 90 insertions(+) create mode 100644 terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/RenameTerminalAction.java 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 5b20b09d97d..6891cbcb1e4 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 @@ -166,4 +166,9 @@ public interface ITerminalViewControl { * @since 4.1 */ void removeMouseListener(ITerminalMouseListener listener); + + /** + * @since 5.1 + */ + void setTerminalTitle(String newTitle); } diff --git a/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/RenameTerminalAction.java b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/RenameTerminalAction.java new file mode 100644 index 00000000000..a9cf9a673e8 --- /dev/null +++ b/terminal/plugins/org.eclipse.tm.terminal.view.ui/src/org/eclipse/tm/terminal/view/ui/actions/RenameTerminalAction.java @@ -0,0 +1,65 @@ +/******************************************************************************* + * Copyright (c) 2021 Kichwa Coders Canada 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.tm.terminal.view.ui.actions; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.dialogs.InputDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.window.Window; +import org.eclipse.tm.internal.terminal.control.ITerminalViewControl; +import org.eclipse.tm.internal.terminal.control.actions.AbstractTerminalAction; +import org.eclipse.tm.terminal.view.ui.nls.Messages; +import org.eclipse.tm.terminal.view.ui.tabs.TabFolderManager; + +/** + * @since 4.8 + */ +public class RenameTerminalAction extends AbstractTerminalAction { + + /** + * Constructor. + * + * @param tabFolderManager The parent tab folder manager. Must not be null. + */ + public RenameTerminalAction(TabFolderManager tabFolderManager) { + super(RenameTerminalAction.class.getName()); + + Assert.isNotNull(tabFolderManager); + setupAction(Messages.RenameTerminalAction_menu, Messages.RenameTerminalAction_tooltip, (ImageDescriptor) null, + (ImageDescriptor) null, (ImageDescriptor) null, true); + } + + @Override + public void run() { + ITerminalViewControl target = getTarget(); + if (target == null) + return; + InputDialog inputDialog = new InputDialog(target.getControl().getShell(), // + Messages.RenameTerminalAction_inputdialog_title, // + Messages.RenameTerminalAction_inputdialog_prompt, // + Messages.RenameTerminalAction_inputdialog_defaulttext, // + null); + if (inputDialog.open() == Window.OK) { + String value = inputDialog.getValue(); + if (value != null) { + target.setTerminalTitle(value); + } + } + + } + + @Override + public void updateAction(boolean aboutToShow) { + setEnabled(aboutToShow && getTarget() != null); + } + +} 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 e6c28bf7b6c..6f96f5d05da 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 @@ -158,4 +158,9 @@ public static String getString(String key) { public static String ExternalExecutablesDialog_field_icon; public static String ExternalExecutablesDialog_field_translate; + public static String RenameTerminalAction_inputdialog_defaulttext; + public static String RenameTerminalAction_inputdialog_prompt; + public static String RenameTerminalAction_inputdialog_title; + public static String RenameTerminalAction_tooltip; + public static String RenameTerminalAction_menu; } 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 05f02561350..f3fc1d0e9fa 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 @@ -42,6 +42,12 @@ SelectEncodingAction_tooltip=Switch the Encoding of the active Terminal InvertColorsAction_menu=Inverted colors InvertColorsAction_tooltip=Invert the colors of the active Terminal +RenameTerminalAction_inputdialog_defaulttext= +RenameTerminalAction_inputdialog_prompt=Please enter a new name for the terminal +RenameTerminalAction_inputdialog_title=New name for terminal +RenameTerminalAction_menu=Rename Terminal +RenameTerminalAction_tooltip=Update the display name of this 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 451e0a17c6c..3a7ff1734a0 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 @@ -36,6 +36,7 @@ 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.RenameTerminalAction; 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; @@ -303,6 +304,14 @@ protected ITerminalViewControl getTarget() { return getActiveTerminalViewControl(); } }); + + // change the name of the terminal + add(new RenameTerminalAction(getParentView().getAdapter(TabFolderManager.class)) { + @Override + protected ITerminalViewControl getTarget() { + return getActiveTerminalViewControl(); + } + }); } /**