📄 helper.java
字号:
package org.xicabin.radcake.core.util;
import org.eclipse.core.resources.IFile;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbenchPage;
/**
* Helper function
*
* @author Darcy Young
*/
public abstract class Helper {
public static IFile getSelectedFile(IWorkbenchPage page) {
if (null == page)
return null;
IFile file = null;
ISelection selection = page.getSelection();
if (selection instanceof ITextSelection) {
IEditorInput editorInput = page.getActiveEditor().getEditorInput();
if (editorInput instanceof IFileEditorInput) {
file = ((IFileEditorInput) editorInput).getFile();
}
} else if (selection instanceof IStructuredSelection
&& !selection.isEmpty()) {
Object element = ((IStructuredSelection) selection)
.getFirstElement();
if (element instanceof IFile) {
file = (IFile) element;
}
}
return file;
}
public static String getSelectedText(IWorkbenchPage page) {
if (null == page)
return null;
String text = "";
ISelection selection = page.getSelection();
if (selection instanceof ITextSelection) {
text = ((ITextSelection) selection).getText();
}
return text;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -