Skip to content

Commit

Permalink
ability to put the items in the main menu not in the "EasyShell"
Browse files Browse the repository at this point in the history
sub-menu #15

- fixes #15
- add preferences
- minor refactoring

Signed-off-by: Andre Bossert <[email protected]>
  • Loading branch information
anb0s committed Sep 27, 2020
1 parent 958a559 commit 99e6aac
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 55 deletions.
5 changes: 5 additions & 0 deletions plugin/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@
class="de.anbos.eclipse.easyshell.plugin.commands.DefineCommandsForResourceNavigator"
locationURI="popup:org.eclipse.ui.popup.any">
</menuContribution>
<menuContribution
allPopups="true"
class="de.anbos.eclipse.easyshell.plugin.commands.DefineCommandsForMainMenu"
locationURI="menu:org.eclipse.ui.main.menu">
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.preferencePages">
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/Activator.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import de.anbos.eclipse.easyshell.plugin.types.Category;
import de.anbos.eclipse.easyshell.plugin.types.Debug;
import de.anbos.eclipse.easyshell.plugin.types.OS;
import de.anbos.eclipse.easyshell.plugin.types.Tooltip;
import de.anbos.eclipse.easyshell.plugin.types.CheckBox;
import de.anbos.eclipse.easyshell.plugin.types.Version;

/**
Expand Down Expand Up @@ -201,7 +201,7 @@ public static void logWarning(String title, String msg, Exception e, boolean too

public static void logError(String title, String msg, Exception e, boolean tooltip) {
log(Status.ERROR, title != null ? title + ": " + msg : msg, e);
if (tooltip && (GeneralDataStore.instance().getData().getToolTipError() == Tooltip.tooltipYes)) {
if (tooltip && (GeneralDataStore.instance().getData().getToolTipError() == CheckBox.yes)) {
tooltipError(title, msg);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ easyshell.main.page.dialog.defaults.title=Restore defaults
easyshell.main.page.dialog.defaults.question=All your settings will be overwritten!\n\nYou can still use "Cancel" button afterwards for undo.\n\nDo you really want to restore default settings?
easyshell.main.page.dialog.migration.title=Migration
easyshell.main.page.dialog.migration.question=You have canceled the migration of settings from previous version.\n\nAll your settings will be written now and migration will be skipped completely!\n\nDo you really want to overwrite the migrated settings?
easyshell.main.page.dialog.restart.title=Restart Now?
easyshell.main.page.dialog.restart.question=The main menu visibility can only be changed after restart.\n\nContinue with restart?
easyshell.error.title.incompletedata=Missing or wrong parameters
easyshell.main.page.error.text.debug=Please choose a valid debug type

Expand All @@ -41,6 +43,12 @@ easyshell.main.page.label.button.tooltipclip=Show tooltips for "copy to clipboar
easyshell.main.page.label.button.tooltip.tooltipclip=Enable or disable "copy to clipboard" tooltips.
easyshell.main.page.label.button.tooltiperror=Show tooltips for "execution errors"
easyshell.main.page.label.button.tooltip.tooltiperror=Enable or disable "execution errors" tooltips.\n\nErrors will be still shown in "Error View".
easyshell.main.page.label.button.menuall=Show Menu
easyshell.main.page.label.button.tooltip.menuall=Enable or disable all menus.
easyshell.main.page.label.button.menupopup=Show Popup Menu
easyshell.main.page.label.button.tooltip.menupopup=Enable or disable popup menu.
easyshell.main.page.label.button.menumain=Show Main Menu
easyshell.main.page.label.button.tooltip.menumain=Enable or disable main menu.

easyshell.message.warning.migrated.yes=Migrated settings from previous version "{0}".\n\nPlease verify your settings!
easyshell.message.warning.migrated.no=NOT migrated settings from previous version "{0}".\n\nPlease verify applied default settings!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import de.anbos.eclipse.easyshell.plugin.types.CommandType;
import de.anbos.eclipse.easyshell.plugin.types.Quotes;
import de.anbos.eclipse.easyshell.plugin.types.ResourceType;
import de.anbos.eclipse.easyshell.plugin.types.Tooltip;
import de.anbos.eclipse.easyshell.plugin.types.CheckBox;
import de.anbos.eclipse.easyshell.plugin.types.CommandTokenizer;

public class ActionDelegate implements IObjectActionDelegate {
Expand Down Expand Up @@ -136,7 +136,7 @@ public void run(IAction action) {
// handling copy to clipboard
if ((commandType == CommandType.commandTypeClipboard) && (cmdAll != null) && (cmdAll.length() != 0)) {
Utils.copyToClipboard(cmdAll);
if (GeneralDataStore.instance().getData().getToolTipClipboard() == Tooltip.tooltipYes) {
if (GeneralDataStore.instance().getData().getToolTipClipboard() == CheckBox.yes) {
Activator.tooltipInfo(Activator.getResourceString("easyshell.message.copytoclipboard"), cmdAll);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@
import de.anbos.eclipse.easyshell.plugin.Constants;
import de.anbos.eclipse.easyshell.plugin.exceptions.UnknownCommandID;
import de.anbos.eclipse.easyshell.plugin.misc.Utils;
import de.anbos.eclipse.easyshell.plugin.preferences.GeneralDataStore;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuData;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuDataList;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuDataStore;

import de.anbos.eclipse.easyshell.plugin.types.CheckBox;
import de.anbos.eclipse.easyshell.plugin.types.ResourceType;

public class DefineCommands extends ExtensionContributionFactory {
Expand All @@ -42,6 +43,9 @@ public DefineCommands() {

@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
if (GeneralDataStore.instance().getData().getMenuPopup() != CheckBox.yes) {
return;
}
IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
boolean isResourceNavigator = false;
isResourceNavigator = activePart instanceof org.eclipse.ui.views.navigator.ResourceNavigator;
Expand All @@ -57,8 +61,15 @@ public boolean isForResourceNavigator() {
return false;
}

private void createContributionItemsForResType(ResourceType resType, IServiceLocator serviceLocator, IContributionRoot additions) {
MenuManager submenu = new MenuManager("EasyShell", Activator.getImageDescriptor(Constants.IMAGE_EASYSHELL), "de.anbos.eclipse.easyshell.plugin.menu");
public boolean showMenuImage() {
return true;
}

protected void createContributionItemsForResType(ResourceType resType, IServiceLocator serviceLocator, IContributionRoot additions) {
if (GeneralDataStore.instance().getData().getMenuAll() != CheckBox.yes) {
return;
}
MenuManager submenu = new MenuManager("EasyShell", showMenuImage() ? Activator.getImageDescriptor(Constants.IMAGE_EASYSHELL) : null, "de.anbos.eclipse.easyshell.plugin.menu");
MenuDataList items = MenuDataStore.instance().getEnabledCommandMenuDataList();
for (MenuData item : items) {
ResourceType resTypeSupported;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* Copyright (c) 2014-2020 Andre Bossert <[email protected]>.
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0
*
* SPDX-License-Identifier: EPL-2.0
*/

package de.anbos.eclipse.easyshell.plugin.commands;

import org.eclipse.ui.menus.IContributionRoot;
import org.eclipse.ui.services.IServiceLocator;

import de.anbos.eclipse.easyshell.plugin.preferences.GeneralDataStore;
import de.anbos.eclipse.easyshell.plugin.types.CheckBox;
import de.anbos.eclipse.easyshell.plugin.types.ResourceType;

public class DefineCommandsForMainMenu extends DefineCommands {

public DefineCommandsForMainMenu() {
}

@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
if (GeneralDataStore.instance().getData().getMenuMain() != CheckBox.yes) {
return;
}
createContributionItemsForResType(ResourceType.resourceTypeFileOrDirectory, serviceLocator, additions);
}

@Override
public boolean showMenuImage() {
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

public class DefineCommandsForResourceNavigator extends DefineCommands {

@Override
public boolean isForResourceNavigator() {
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/misc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import de.anbos.eclipse.easyshell.plugin.types.Category;
import de.anbos.eclipse.easyshell.plugin.types.LinuxDesktop;
import de.anbos.eclipse.easyshell.plugin.types.OS;
import de.anbos.eclipse.easyshell.plugin.types.Tooltip;
import de.anbos.eclipse.easyshell.plugin.types.CheckBox;

public class Utils {

Expand Down Expand Up @@ -218,7 +218,7 @@ public static void showToolTipError(Control control, String title, String messag
}

public static void showToolTip(Control control, int style, String title, String message) {
if (GeneralDataStore.instance().getData().getToolTipAll() != Tooltip.tooltipYes) {
if (GeneralDataStore.instance().getData().getToolTipAll() != CheckBox.yes) {
return;
}
if (control == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
import java.util.StringTokenizer;

import de.anbos.eclipse.easyshell.plugin.types.Debug;
import de.anbos.eclipse.easyshell.plugin.types.Tooltip;
import de.anbos.eclipse.easyshell.plugin.types.CheckBox;
import de.anbos.eclipse.easyshell.plugin.types.Version;

public class GeneralData {

private Debug debug = Debug.debugNo;
private Tooltip toolTipAll = Tooltip.tooltipYes;
private Tooltip toolTipClipboard = Tooltip.tooltipYes;
private Tooltip toolTipError = Tooltip.tooltipYes;

public GeneralData(Debug debug, Tooltip toolTipAll, Tooltip toolTipClipboard, Tooltip toolTipError) {
private CheckBox toolTipAll = CheckBox.yes;
private CheckBox toolTipClipboard = CheckBox.yes;
private CheckBox toolTipError = CheckBox.yes;
private CheckBox menuAll = CheckBox.yes;
private CheckBox menuPopup = CheckBox.yes;
private CheckBox menuMain = CheckBox.no;

public GeneralData(Debug debug, CheckBox toolTipAll, CheckBox toolTipClipboard, CheckBox toolTipError) {
setDebug(debug);
setToolTipAll(toolTipAll);
setToolTipClipboard(toolTipClipboard);
Expand All @@ -44,7 +47,10 @@ public boolean equals(Object object) {
if(data.getDebug() == this.getDebug() &&
data.getToolTipAll() == this.getToolTipAll() &&
data.getToolTipClipboard() == this.getToolTipClipboard() &&
data.getToolTipError() == this.getToolTipError()
data.getToolTipError() == this.getToolTipError() &&
data.getMenuAll() == this.getMenuAll() &&
data.getMenuPopup() == this.getMenuPopup() &&
data.getMenuMain() == this.getMenuMain()
)
{
return true;
Expand All @@ -63,9 +69,15 @@ public boolean deserialize(Version version, String value, StringTokenizer tokeni
setDebug(Debug.getFromEnum(tokenizer.nextToken()));
// tooltip
if (version.getId() >= Version.v2_1_002.getId()) {
setToolTipAll(Tooltip.getFromEnum(tokenizer.nextToken()));
setToolTipClipboard(Tooltip.getFromEnum(tokenizer.nextToken()));
setToolTipError(Tooltip.getFromEnum(tokenizer.nextToken()));
setToolTipAll(CheckBox.getFromEnum(tokenizer.nextToken()));
setToolTipClipboard(CheckBox.getFromEnum(tokenizer.nextToken()));
setToolTipError(CheckBox.getFromEnum(tokenizer.nextToken()));
}
// menu
if (version.getId() >= Version.v2_2_001.getId()) {
setMenuAll(CheckBox.getFromEnum(tokenizer.nextToken()));
setMenuPopup(CheckBox.getFromEnum(tokenizer.nextToken()));
setMenuMain(CheckBox.getFromEnum(tokenizer.nextToken()));
}
return true;
}
Expand All @@ -80,6 +92,9 @@ public String serialize(Version version, String delimiter) {
ret += getToolTipAll().toString() + delimiter;
ret += getToolTipClipboard().toString() + delimiter;
ret += getToolTipError().toString() + delimiter;
ret += getMenuAll().toString() + delimiter;
ret += getMenuPopup().toString() + delimiter;
ret += getMenuMain().toString() + delimiter;
return ret;
}

Expand All @@ -95,28 +110,52 @@ public void setDebug(Debug debug) {
this.debug = debug;
}

public Tooltip getToolTipAll() {
public CheckBox getToolTipAll() {
return toolTipAll;
}

public void setToolTipAll(Tooltip tooltip) {
public void setToolTipAll(CheckBox tooltip) {
this.toolTipAll = tooltip;
}

public Tooltip getToolTipClipboard() {
public CheckBox getToolTipClipboard() {
return toolTipClipboard;
}

public void setToolTipClipboard(Tooltip tooltip) {
public void setToolTipClipboard(CheckBox tooltip) {
this.toolTipClipboard = tooltip;
}

public Tooltip getToolTipError() {
public CheckBox getToolTipError() {
return toolTipError;
}

public void setToolTipError(Tooltip tooltip) {
public void setToolTipError(CheckBox tooltip) {
this.toolTipError = tooltip;
}

public CheckBox getMenuAll() {
return menuAll;
}

public void setMenuAll(CheckBox menu) {
this.menuAll = menu;
}

public CheckBox getMenuPopup() {
return menuPopup;
}

public void setMenuPopup(CheckBox menu) {
this.menuPopup = menu;
}

public CheckBox getMenuMain() {
return menuMain;
}

public void setMenuMain(CheckBox menu) {
this.menuMain = menu;
}

}
Loading

0 comments on commit 99e6aac

Please sign in to comment.