Skip to content

Commit

Permalink
add substitution variable for line_number #212 and ...
Browse files Browse the repository at this point in the history
... add substitutions for selected text #219

Signed-off-by: Andre Bossert <anb0s@anbos.de>
  • Loading branch information
anb0s committed Mar 18, 2022
1 parent 48715c5 commit 40cc302
Show file tree
Hide file tree
Showing 14 changed files with 205 additions and 26 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ The following platform, shell combinations and tools are supported as selections
- Finder

**All OS**
- Open with / Edit
- Eclipse - Full Path : line number
- Copy to clipboard:
- Full Path
- Full Path Unix (@Windows)
Expand Down Expand Up @@ -162,6 +164,12 @@ The following substitution variables are available for building the command:
- ```${easyshell:resource_basename}``` = name of file without extension
- ```${easyshell:resource_extension}``` = extension of file name (without '.')
- ```${easyshell:resource_path}``` = relative path to workspace of file or directory
- ```${easyshell:resource_line_number}``` = line number (within view or editor)
- ```${easyshell:selected_text_start_line}``` = selected text start line (within view or editor), it's equal to ${easyshell:resource_line_number}
- ```${easyshell:selected_text_end_line}``` = selected text end line (within view or editor)
- ```${easyshell:selected_text_length}``` = selected text length (within view or editor)
- ```${easyshell:selected_text_offset}``` = selected text offset (within view or editor)
- ```${easyshell:selected_text}``` = selected text (within view or editor)
- ```${easyshell:container_loc}``` = absolute path of file directory or directory itself
- ```${easyshell:container_name}``` = name of file directory or directory itself
- ```${easyshell:container_path}``` = relative path to workspace of file directory or directory itself
Expand Down
Binary file added plugin/images/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public interface Constants {
public static final String IMAGE_NONE = "none";
public static final String IMAGE_DEFAULT = "default";
public static final String IMAGE_OPEN = "open";
public static final String IMAGE_EDIT = "edit";
public static final String IMAGE_RUN = "run";
public static final String IMAGE_EXPLORE = "explore";
public static final String IMAGE_CLIPBOARD = "clipboard";
Expand Down
15 changes: 12 additions & 3 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/All.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

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

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
Expand Down Expand Up @@ -76,13 +79,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
return null;
}

public MenuDataList getMenuDataList(Category category) {
MenuDataList menuDataList = MenuDataStore.instance().getEnabledCommandMenuDataListByCategory(category);
public MenuDataList getMenuDataList(List<Category> categories) {
MenuDataList menuDataList = MenuDataStore.instance().getEnabledCommandMenuDataListByCategories(categories);
return menuDataList;
}

public MenuDataList getMenuDataList(ResourceType resTypeWanted) {
MenuDataList menuDataList = getMenuDataList(getCategory());
MenuDataList menuDataList = getMenuDataList(getCategories());
MenuDataList menuDataListSupported = new MenuDataList();
for (MenuData menuData : menuDataList) {
ResourceType resTypeSupported;
Expand All @@ -103,6 +106,12 @@ public Category getCategory() {
return Category.categoryUnknown;
}

public List<Category> getCategories() {
List<Category> list = new ArrayList<Category>();
list.add(getCategory());
return list;
}

public String getTitle() {
String postfix = getCategory() == Category.categoryUnknown ? "" : " - " + getCategory().getName();
return Activator.getResourceString("easyshell.plugin.name") + postfix;
Expand Down
11 changes: 11 additions & 0 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/Open.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

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

import java.util.ArrayList;
import java.util.List;

import de.anbos.eclipse.easyshell.plugin.types.Category;

public class Open extends AllSingle {
Expand All @@ -22,4 +25,12 @@ public Category getCategory() {
return Category.categoryOpen;
}

@Override
public List<Category> getCategories() {
List<Category> list = new ArrayList<Category>();
list.add(getCategory());
list.add(Category.categoryEdit);
return list;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ static public ISelection getResourceSelection(Object obj) {
}
if (editor != null) {
ITextSelection sel = (ITextSelection)editor.getSelectionProvider().getSelection();
String text = sel.getText();
selection = getSelectionFromText(resource, text);
//String text = sel.getText();
//selection = getSelectionFromText(resource, text);
if (resource != null) {
resource.setTextSelection(sel);
}
}
} else if (obj instanceof IWorkbenchPart) {
try {
Expand All @@ -79,7 +82,7 @@ static public ISelection getResourceSelection(Object obj) {
return selection;
}

private static ISelection getSelectionFromText(Resource partFile, String text) {
static public ISelection getSelectionFromText(Resource partFile, String text) {
ISelection selection = null;
if (text != null && !text.isEmpty()) {
String lines[] = text.split("\\r?\\n");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class CommandDataDefaultCollectionAllOS {

static public void addCommandsAll(CommandDataList list) {
addCommandsConsole(list);
addCommandsEditor(list);
addCommandsFileBrowser(list);
addCommandsClipboard(list);
}
Expand Down Expand Up @@ -54,6 +55,13 @@ private static void addCommandsConsole(CommandDataList list) {
"pwsh -command \"Start-Process pwsh -Verb RunAs -ArgumentList '-NoExit', '-Command', 'cd ${easyshell:container_loc} ; ./${easyshell:resource_name}'\""));
}

private static void addCommandsEditor(CommandDataList list) {
OS os = Utils.getOS();
// Eclipse Editor
list.add(new CommandData("dc8dd567-6ac0-49ec-8fcd-ed61e677ea3d", PresetType.presetPlugin, os, "Eclipse", ResourceType.resourceTypeFile, false, null, Category.categoryEdit, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"eclipse -name Eclipse --launcher.openFile ${easyshell:resource_loc}:${easyshell:resource_line_number}"));
}

private static void addCommandsFileBrowser(CommandDataList list) {
OS os = Utils.getOS();
String cmdPrefix = "";
Expand Down Expand Up @@ -92,6 +100,25 @@ private static void addCommandsClipboard(CommandDataList list) {
// Clipboard - Qualified Name with quotes
list.add(new CommandData("cd32fa5a-34d7-4551-8bd0-3aae0dc444d0", PresetType.presetPlugin, os, "\"Qualified Name\"", ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerDisabled,
"\"${easyshell:qualified_name}\"${easyshell:line_separator}"));
// Clipboard - Full Path with line number = selected text start line
list.add(new CommandData("434dfc65-4efd-42e1-be5a-f108661e51a1", PresetType.presetPlugin, os, "Full Path : line number", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"${easyshell:resource_loc}:${easyshell:resource_line_number}"));
// Clipboard - Full Path with selected text end line
list.add(new CommandData("840831f3-fb2f-45f3-8db4-14007757d576", PresetType.presetPlugin, os, "Full Path : selected text end line", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"${easyshell:resource_loc}:${easyshell:selected_text_end_line}"));
// Clipboard - Full Path with with selected text start and end line
list.add(new CommandData("65f40ff6-e920-4bd4-96d9-33e0a6fb8725", PresetType.presetPlugin, os, "Full Path : selected text start line : end line", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"${easyshell:resource_loc}:${easyshell:selected_text_start_line}:${easyshell:selected_text_end_line}"));
// Clipboard - selected text length
list.add(new CommandData("74e122dc-64fa-4444-8f58-f4ab04ebc9e3", PresetType.presetPlugin, os, "Selected text length", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"${easyshell:selected_text_length}"));
// Clipboard - selected text offset
list.add(new CommandData("ab5cb337-60da-429c-a0a7-0b37071b6a50", PresetType.presetPlugin, os, "Selected text offset", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"${easyshell:selected_text_offset}"));
// Clipboard - selected text
list.add(new CommandData("93442258-28b7-4297-9611-34733fa76161", PresetType.presetPlugin, os, "Selected text", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
"${easyshell:selected_text}"));

// Clipboard - Variables Test
String varTestString = "";
for(int i=Variable.getFirstIndex();i<Variable.values().length;i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,11 @@ public void setNameTypeFromCategory(Category category) {
case categoryOpen:
setNameType(MenuNameType.menuNameTypeOpenHere);
break;
case categoryEdit:
setNameType(MenuNameType.menuNameTypeOpenWith);
break;
case categoryRun:
setNameType(MenuNameType.menuNameTypeGeneric2);
setNameType(MenuNameType.menuNameTypeRunWith);
break;
case categoryExplore:
setNameType(MenuNameType.menuNameTypeShowIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

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

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.util.IPropertyChangeListener;
Expand Down Expand Up @@ -60,13 +62,13 @@ public MenuData[] getCommandMenuDataArray() {
return allArray;
}

public MenuDataList getEnabledCommandMenuDataListByCategory(Category category) {
public MenuDataList getEnabledCommandMenuDataListByCategories(List<Category> categories) {
MenuDataList checkedItems = new MenuDataList();
Iterator<MenuData> dataIterator = getDataList().iterator();
while(dataIterator.hasNext()) {
MenuData data = (MenuData)dataIterator.next();
try {
if(data.isEnabled() && (category == Category.categoryUnknown || data.getCommandData().getCategory() == category)) {
if(data.isEnabled() && (categories.contains(Category.categoryUnknown) || categories.contains(data.getCommandData().getCategory()))) {
checkedItems.add(data);
}
} catch (UnknownCommandID e) {
Expand All @@ -77,7 +79,9 @@ public MenuDataList getEnabledCommandMenuDataListByCategory(Category category) {
}

public MenuDataList getEnabledCommandMenuDataList() {
return getEnabledCommandMenuDataListByCategory(Category.categoryUnknown);
List<Category> list = new ArrayList<Category>();
list.add(Category.categoryUnknown);
return getEnabledCommandMenuDataListByCategories(list);
}

public MenuData[] getEnabledCommandMenuDataArray() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public enum Category {
categoryRun(2, "Run", Constants.IMAGE_RUN),
categoryExplore(3, "Explore", Constants.IMAGE_EXPLORE),
categoryClipboard(4, "Clipboard", Constants.IMAGE_CLIPBOARD),
categoryUser(5, "User", Constants.IMAGE_USER);
categoryUser(5, "User", Constants.IMAGE_USER),
categoryEdit(6, "Edit", Constants.IMAGE_EDIT);
// attributes
private final int id;
private final String name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ public enum MenuNameType {
menuNameTypeUser( 0, "User defined", "${easyshell:command_name}"),
menuNameTypeDefaultApplication( 1, "Open with default application", "Open with default Application"),
menuNameTypeOpenHere( 2, "Open <name> Here", "Open ${easyshell:command_name} Here"),
menuNameTypeRunWith( 3, "Run with <name>", "Run with ${easyshell:command_name}"),
menuNameTypeShowIn( 4, "Show in <name>", "Show in ${easyshell:command_name}"),
menuNameTypeCopyToClipboard( 5, "Copy <name> to Clipboard", "Copy ${easyshell:command_name} to Clipboard"),
menuNameTypeGeneric1( 6, "<category>: <name>", "${easyshell:command_category}: ${easyshell:command_name}"),
menuNameTypeGeneric2( 7, "<category> with <name>", "${easyshell:command_category} with ${easyshell:command_name}"),
menuNameTypeOpenWith( 3, "Open with <name>", "Open with ${easyshell:command_name}"),
menuNameTypeRunWith( 4, "Run with <name>", "Run with ${easyshell:command_name}"),
menuNameTypeShowIn( 5, "Show in <name>", "Show in ${easyshell:command_name}"),
menuNameTypeCopyToClipboard( 6, "Copy <name> to Clipboard", "Copy ${easyshell:command_name} to Clipboard"),
menuNameTypeGeneric1( 7, "<category>: <name>", "${easyshell:command_category}: ${easyshell:command_name}"),
menuNameTypeGeneric2( 8, "<category> with <name>", "${easyshell:command_category} with ${easyshell:command_name}"),
menuNameTypeGeneric3( 9, "<category> with <os> <name>", "${easyshell:command_category} with ${easyshell:command_os} ${easyshell:command_name}");
// attributes
private final int id;
Expand Down
53 changes: 50 additions & 3 deletions plugin/src/de/anbos/eclipse/easyshell/plugin/types/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jface.text.ITextSelection;

import de.anbos.eclipse.easyshell.plugin.Activator;
import de.anbos.eclipse.easyshell.plugin.misc.ResourceUtils;
Expand All @@ -30,26 +31,29 @@ public class Resource {
// internal
private File file = null;
private IResource resource = null;
private ITextSelection textSelection = null;

// resolved
private String projectName = Activator.getResourceString("easyshell.plugin.name");

public Resource(Resource myRes) {
this.file = myRes.getFile();
this.resource = myRes.getResource();
this.textSelection = myRes.getTextSelection();
}

public Resource(File file, IResource resource) {
public Resource(File file, IResource resource, ITextSelection textSelection) {
this.file = file;
this.resource = resource;
this.textSelection = textSelection;
}

public Resource(File file) {
this(file, null);
this(file, null, null);
}

public Resource(IResource resource) {
this(resource.getLocation().toFile(), resource);
this(resource.getLocation().toFile(), resource, null);
}

public File getFile() {
Expand All @@ -60,6 +64,10 @@ public IResource getResource() {
return resource;
}

public ITextSelection getTextSelection() {
return textSelection;
}

public String getWindowsDrive() {
String loc = getResourceLocation();
if (loc != null) {
Expand Down Expand Up @@ -151,6 +159,41 @@ public String getResourcePath() {
return "";
}

public String getSelectedTextStartLine() {
if (textSelection != null) {
return String.valueOf(textSelection.getStartLine()+1);
}
return "";
}

public String getSelectedTextEndLine() {
if (textSelection != null) {
return String.valueOf(textSelection.getEndLine()+1);
}
return "";
}

public String getSelectedTextLength() {
if (textSelection != null) {
return String.valueOf(textSelection.getLength());
}
return "";
}

public String getSelectedTextOffset() {
if (textSelection != null) {
return String.valueOf(textSelection.getOffset());
}
return "";
}

public String getSelectedText() {
if (textSelection != null) {
return textSelection.getText();
}
return "";
}

public String getProjectLocation() {
if (resource != null) {
return resource.getProject().getLocation().toFile().toString();
Expand Down Expand Up @@ -282,4 +325,8 @@ public String getScriptBash(String parameter) {
return file != null && file.exists() ? file.getAbsolutePath() : "file does not exists";
}

public void setTextSelection(ITextSelection sel) {
textSelection = sel;
}

}
Loading

0 comments on commit 40cc302

Please sign in to comment.