Skip to content

Commit 118fb00

Browse files
committed
add substitution variable for line_number #212 and ...
... add substitutions for selected text #219 Signed-off-by: Andre Bossert <anb0s@anbos.de>
1 parent 8a8b5f0 commit 118fb00

File tree

14 files changed

+205
-26
lines changed

14 files changed

+205
-26
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ The following platform, shell combinations and tools are supported as selections
127127
- Finder
128128

129129
**All OS**
130+
- Open with / Edit
131+
- Eclipse - Full Path : line number
130132
- Copy to clipboard:
131133
- Full Path
132134
- Full Path Unix (@Windows)
@@ -162,6 +164,12 @@ The following substitution variables are available for building the command:
162164
- ```${easyshell:resource_basename}``` = name of file without extension
163165
- ```${easyshell:resource_extension}``` = extension of file name (without '.')
164166
- ```${easyshell:resource_path}``` = relative path to workspace of file or directory
167+
- ```${easyshell:resource_line_number}``` = line number (within view or editor)
168+
- ```${easyshell:selected_text_start_line}``` = selected text start line (within view or editor), it's equal to ${easyshell:resource_line_number}
169+
- ```${easyshell:selected_text_end_line}``` = selected text end line (within view or editor)
170+
- ```${easyshell:selected_text_length}``` = selected text length (within view or editor)
171+
- ```${easyshell:selected_text_offset}``` = selected text offset (within view or editor)
172+
- ```${easyshell:selected_text}``` = selected text (within view or editor)
165173
- ```${easyshell:container_loc}``` = absolute path of file directory or directory itself
166174
- ```${easyshell:container_name}``` = name of file directory or directory itself
167175
- ```${easyshell:container_path}``` = relative path to workspace of file directory or directory itself

plugin/images/edit.png

481 Bytes
Loading

plugin/src/de/anbos/eclipse/easyshell/plugin/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public interface Constants {
2525
public static final String IMAGE_NONE = "none";
2626
public static final String IMAGE_DEFAULT = "default";
2727
public static final String IMAGE_OPEN = "open";
28+
public static final String IMAGE_EDIT = "edit";
2829
public static final String IMAGE_RUN = "run";
2930
public static final String IMAGE_EXPLORE = "explore";
3031
public static final String IMAGE_CLIPBOARD = "clipboard";

plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/All.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

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

16+
import java.util.ArrayList;
17+
import java.util.List;
18+
1619
import org.eclipse.core.commands.AbstractHandler;
1720
import org.eclipse.core.commands.ExecutionEvent;
1821
import org.eclipse.core.commands.ExecutionException;
@@ -76,13 +79,13 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
7679
return null;
7780
}
7881

79-
public MenuDataList getMenuDataList(Category category) {
80-
MenuDataList menuDataList = MenuDataStore.instance().getEnabledCommandMenuDataListByCategory(category);
82+
public MenuDataList getMenuDataList(List<Category> categories) {
83+
MenuDataList menuDataList = MenuDataStore.instance().getEnabledCommandMenuDataListByCategories(categories);
8184
return menuDataList;
8285
}
8386

8487
public MenuDataList getMenuDataList(ResourceType resTypeWanted) {
85-
MenuDataList menuDataList = getMenuDataList(getCategory());
88+
MenuDataList menuDataList = getMenuDataList(getCategories());
8689
MenuDataList menuDataListSupported = new MenuDataList();
8790
for (MenuData menuData : menuDataList) {
8891
ResourceType resTypeSupported;
@@ -103,6 +106,12 @@ public Category getCategory() {
103106
return Category.categoryUnknown;
104107
}
105108

109+
public List<Category> getCategories() {
110+
List<Category> list = new ArrayList<Category>();
111+
list.add(getCategory());
112+
return list;
113+
}
114+
106115
public String getTitle() {
107116
String postfix = getCategory() == Category.categoryUnknown ? "" : " - " + getCategory().getName();
108117
return Activator.getResourceString("easyshell.plugin.name") + postfix;

plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/Open.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

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

16+
import java.util.ArrayList;
17+
import java.util.List;
18+
1619
import de.anbos.eclipse.easyshell.plugin.types.Category;
1720

1821
public class Open extends AllSingle {
@@ -22,4 +25,12 @@ public Category getCategory() {
2225
return Category.categoryOpen;
2326
}
2427

28+
@Override
29+
public List<Category> getCategories() {
30+
List<Category> list = new ArrayList<Category>();
31+
list.add(getCategory());
32+
list.add(Category.categoryEdit);
33+
return list;
34+
}
35+
2536
}

plugin/src/de/anbos/eclipse/easyshell/plugin/misc/ResourceUtils.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,11 @@ static public ISelection getResourceSelection(Object obj) {
6161
}
6262
if (editor != null) {
6363
ITextSelection sel = (ITextSelection)editor.getSelectionProvider().getSelection();
64-
String text = sel.getText();
65-
selection = getSelectionFromText(resource, text);
64+
//String text = sel.getText();
65+
//selection = getSelectionFromText(resource, text);
66+
if (resource != null) {
67+
resource.setTextSelection(sel);
68+
}
6669
}
6770
} else if (obj instanceof IWorkbenchPart) {
6871
try {
@@ -79,7 +82,7 @@ static public ISelection getResourceSelection(Object obj) {
7982
return selection;
8083
}
8184

82-
private static ISelection getSelectionFromText(Resource partFile, String text) {
85+
static public ISelection getSelectionFromText(Resource partFile, String text) {
8386
ISelection selection = null;
8487
if (text != null && !text.isEmpty()) {
8588
String lines[] = text.split("\\r?\\n");

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/CommandDataDefaultCollectionAllOS.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class CommandDataDefaultCollectionAllOS {
2626

2727
static public void addCommandsAll(CommandDataList list) {
2828
addCommandsConsole(list);
29+
addCommandsEditor(list);
2930
addCommandsFileBrowser(list);
3031
addCommandsClipboard(list);
3132
}
@@ -54,6 +55,13 @@ private static void addCommandsConsole(CommandDataList list) {
5455
"pwsh -command \"Start-Process pwsh -Verb RunAs -ArgumentList '-NoExit', '-Command', 'cd ${easyshell:container_loc} ; ./${easyshell:resource_name}'\""));
5556
}
5657

58+
private static void addCommandsEditor(CommandDataList list) {
59+
OS os = Utils.getOS();
60+
// Eclipse Editor
61+
list.add(new CommandData("dc8dd567-6ac0-49ec-8fcd-ed61e677ea3d", PresetType.presetPlugin, os, "Eclipse", ResourceType.resourceTypeFile, false, null, Category.categoryEdit, CommandType.commandTypeExecute, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
62+
"eclipse -name Eclipse --launcher.openFile ${easyshell:resource_loc}:${easyshell:resource_line_number}"));
63+
}
64+
5765
private static void addCommandsFileBrowser(CommandDataList list) {
5866
OS os = Utils.getOS();
5967
String cmdPrefix = "";
@@ -92,6 +100,25 @@ private static void addCommandsClipboard(CommandDataList list) {
92100
// Clipboard - Qualified Name with quotes
93101
list.add(new CommandData("cd32fa5a-34d7-4551-8bd0-3aae0dc444d0", PresetType.presetPlugin, os, "\"Qualified Name\"", ResourceType.resourceTypeFileOrDirectory, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerDisabled,
94102
"\"${easyshell:qualified_name}\"${easyshell:line_separator}"));
103+
// Clipboard - Full Path with line number = selected text start line
104+
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,
105+
"${easyshell:resource_loc}:${easyshell:resource_line_number}"));
106+
// Clipboard - Full Path with selected text end line
107+
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,
108+
"${easyshell:resource_loc}:${easyshell:selected_text_end_line}"));
109+
// Clipboard - Full Path with with selected text start and end line
110+
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,
111+
"${easyshell:resource_loc}:${easyshell:selected_text_start_line}:${easyshell:selected_text_end_line}"));
112+
// Clipboard - selected text length
113+
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,
114+
"${easyshell:selected_text_length}"));
115+
// Clipboard - selected text offset
116+
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,
117+
"${easyshell:selected_text_offset}"));
118+
// Clipboard - selected text
119+
list.add(new CommandData("93442258-28b7-4297-9611-34733fa76161", PresetType.presetPlugin, os, "Selected text", ResourceType.resourceTypeFile, false, null, Category.categoryClipboard, CommandType.commandTypeClipboard, CommandTokenizer.commandTokenizerSpacesAndQuotesSkip,
120+
"${easyshell:selected_text}"));
121+
95122
// Clipboard - Variables Test
96123
String varTestString = "";
97124
for(int i=Variable.getFirstIndex();i<Variable.values().length;i++) {

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuData.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,11 @@ public void setNameTypeFromCategory(Category category) {
289289
case categoryOpen:
290290
setNameType(MenuNameType.menuNameTypeOpenHere);
291291
break;
292+
case categoryEdit:
293+
setNameType(MenuNameType.menuNameTypeOpenWith);
294+
break;
292295
case categoryRun:
293-
setNameType(MenuNameType.menuNameTypeGeneric2);
296+
setNameType(MenuNameType.menuNameTypeRunWith);
294297
break;
295298
case categoryExplore:
296299
setNameType(MenuNameType.menuNameTypeShowIn);

plugin/src/de/anbos/eclipse/easyshell/plugin/preferences/MenuDataStore.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

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

16+
import java.util.ArrayList;
1617
import java.util.Iterator;
18+
import java.util.List;
1719

1820
import org.eclipse.jface.preference.IPreferenceStore;
1921
import org.eclipse.jface.util.IPropertyChangeListener;
@@ -60,13 +62,13 @@ public MenuData[] getCommandMenuDataArray() {
6062
return allArray;
6163
}
6264

63-
public MenuDataList getEnabledCommandMenuDataListByCategory(Category category) {
65+
public MenuDataList getEnabledCommandMenuDataListByCategories(List<Category> categories) {
6466
MenuDataList checkedItems = new MenuDataList();
6567
Iterator<MenuData> dataIterator = getDataList().iterator();
6668
while(dataIterator.hasNext()) {
6769
MenuData data = (MenuData)dataIterator.next();
6870
try {
69-
if(data.isEnabled() && (category == Category.categoryUnknown || data.getCommandData().getCategory() == category)) {
71+
if(data.isEnabled() && (categories.contains(Category.categoryUnknown) || categories.contains(data.getCommandData().getCategory()))) {
7072
checkedItems.add(data);
7173
}
7274
} catch (UnknownCommandID e) {
@@ -77,7 +79,9 @@ public MenuDataList getEnabledCommandMenuDataListByCategory(Category category) {
7779
}
7880

7981
public MenuDataList getEnabledCommandMenuDataList() {
80-
return getEnabledCommandMenuDataListByCategory(Category.categoryUnknown);
82+
List<Category> list = new ArrayList<Category>();
83+
list.add(Category.categoryUnknown);
84+
return getEnabledCommandMenuDataListByCategories(list);
8185
}
8286

8387
public MenuData[] getEnabledCommandMenuDataArray() {

plugin/src/de/anbos/eclipse/easyshell/plugin/types/Category.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ public enum Category {
2727
categoryRun(2, "Run", Constants.IMAGE_RUN),
2828
categoryExplore(3, "Explore", Constants.IMAGE_EXPLORE),
2929
categoryClipboard(4, "Clipboard", Constants.IMAGE_CLIPBOARD),
30-
categoryUser(5, "User", Constants.IMAGE_USER);
30+
categoryUser(5, "User", Constants.IMAGE_USER),
31+
categoryEdit(6, "Edit", Constants.IMAGE_EDIT);
3132
// attributes
3233
private final int id;
3334
private final String name;

0 commit comments

Comments
 (0)