helper.java
来自「CakePHP的Eclipse插件」· Java 代码 · 共 49 行
JAVA
49 行
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 + =
减小字号Ctrl + -
显示快捷键?