本文整理汇总了Java中org.eclipse.ui.texteditor.ITextEditor.selectAndReveal方法的典型用法代码示例。如果您正苦于以下问题:Java ITextEditor.selectAndReveal方法的具体用法?Java ITextEditor.selectAndReveal怎么用?Java ITextEditor.selectAndReveal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.ui.texteditor.ITextEditor
的用法示例。
在下文中一共展示了ITextEditor.selectAndReveal方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
@Override
public void run() {
if (isEnabled()) {
try {
ITextEditor editor = (ITextEditor) IDE.openEditor(
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
segment.getParentFile(), EDITOR.SQL, true);
editor.setHighlightRange(segment.offset, segment.length, true);
editor.selectAndReveal(segment.offset, segment.length);
} catch (PartInitException e) {
Log.log(e);
ExceptionNotifier.notifyDefault(Messages.PgNavigatorActionProvider_failed_to_open_editor, e);
}
}
}
示例2: open
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
@Override
public void open() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
try {
ITextEditor editor = (ITextEditor) IDE.openEditor(
page, Paths.get(location).toUri(), EDITOR.SQL, true);
editor.selectAndReveal(region.getOffset(), region.getLength());
} catch (PartInitException ex) {
ExceptionNotifier.notifyDefault(
Messages.ProjectEditorDiffer_error_opening_script_editor, ex);
}
}
示例3: gotoLine
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
public static void gotoLine(ITextEditor textEditor, int line) throws BadLocationException {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
int start = document.getLineOffset(line);
textEditor.selectAndReveal(start, 0);
IWorkbenchPage page = textEditor.getSite().getPage();
page.activate(textEditor);
}
示例4: gotoLine
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
public static void gotoLine(ITextEditor textEditor, int line)
throws BadLocationException {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
int start = document.getLineOffset(line);
textEditor.selectAndReveal(start, 0);
IWorkbenchPage page = textEditor.getSite().getPage();
page.activate(textEditor);
}
示例5: jumpToSavedLocation
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
/**
* Attempts to jump to the location in a saved version
* of the module for the given model. It will jump to the location
* in a nested editor in the model editor for configuration if such
* a nested editor is already open. If a nested editor is not already
* open, it will not make the jump and will return false.
* Returns true if it successfully jumps to the location in the nested
* editor showing the saved module.
*
* @param location
* @return
*/
public static boolean jumpToSavedLocation(Location location, Model model)
{
IEditorPart editor = model.getAdapter(ModelEditor.class);
if (editor instanceof ModelEditor)
{
ModelEditor modelEditor = (ModelEditor) editor;
ITextEditor moduleEditor = modelEditor.getSavedModuleEditor(location.source());
if (moduleEditor != null)
{
try
{
IRegion jumpToRegion = AdapterFactory.locationToRegion(moduleEditor.getDocumentProvider()
.getDocument(moduleEditor.getEditorInput()), location);
// bring the model editor into focus
UIHelper.getActivePage().activate(modelEditor);
// set the nested module editor as the active page in the model editor
modelEditor.setActiveEditor(moduleEditor);
// highlight the appropriate text
moduleEditor.selectAndReveal(jumpToRegion.getOffset(), jumpToRegion.getLength());
return true;
} catch (BadLocationException e)
{
TLCUIActivator.getDefault().logError("Error converting location to region in saved module. The location is "
+ location, e);
}
}
}
return false;
}
示例6: scrollToPosition
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
private void scrollToPosition(ITextEditor textEditor, int position) {
if(textEditor != null) {
textEditor.selectAndReveal(position, 0);
textEditor.resetHighlightRange();
}
}
示例7: execute
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent arg0) {
// After the document has been edited (after cycling through snippets), disable cycling functionality.
if (changed_doc == true) {
changed_doc = false;
InputHandler.previous_length = 0;
InputHandler.previous_offset = 0;
return null;
}
try {
// Get the current active editor.
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
// If the current active editor is a text editor (i.e. not any other workbench component)
if ( part instanceof ITextEditor ) {
// Use text editor context to locate the document of the editor and get the input stream to that editor.
ITextEditor editor = (ITextEditor)part;
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument( editor.getEditorInput() );
int offset = InputHandler.previous_offset;
int length = InputHandler.previous_length;
if (offset + length > doc.getLength()) return null;
String text = doc.get(offset, length);
if (InputHandler.previous_search.contains(text)) {
int index = InputHandler.previous_search.indexOf(text);
index++;
if (index >= InputHandler.previous_search.size() || index < 0) index = 0;
// Replace old snippet with new snippet.
doc.replace(offset, length, InputHandler.previous_search.get(index));
InputHandler.previous_length = InputHandler.previous_search.get(index).length();
previous_index = index;
if (InputHandler.previous_offset + InputHandler.previous_length > doc.getLength()) return null;
editor.selectAndReveal(InputHandler.previous_offset + InputHandler.previous_length, 0);
return null;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
示例8: execute
import org.eclipse.ui.texteditor.ITextEditor; //导入方法依赖的package包/类
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ITextEditor current_editor = (ITextEditor)PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IDocument current_doc = current_editor.getDocumentProvider().getDocument(current_editor.getEditorInput());
if (!InputHandler.documents.contains(current_doc)) {
current_doc.addDocumentListener(InputHandler.qdl);
}
// Get the current active editor.
IWorkbenchPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
// If the current active editor is a text editor (i.e. not any other workbench component)
if ( part instanceof ITextEditor ) {
// Use text editor context to locate the document of the editor and get the input stream to that editor.
ITextEditor editor = (ITextEditor)part;
IDocumentProvider prov = editor.getDocumentProvider();
IDocument doc = prov.getDocument( editor.getEditorInput() );
// Get the current selection to query on.
ISelection sel = editor.getSelectionProvider().getSelection();
if (sel instanceof ITextSelection) {
ITextSelection textSelection = (ITextSelection)sel;
try {
// Get the line number we are currently on.
if (textSelection.equals(null)) return null;
int offset = textSelection.getOffset();
// Get the string on the current line and use that as the query line to be auto-completed.
if (offset > doc.getLength() || offset < 0) return null;
String text = doc.get(doc.getLineOffset(doc.getLineOfOffset(offset)), doc.getLineLength(doc.getLineOfOffset(offset)));
if (text.equals("") || text.equals(null)) return null;
boolean eol = false;
if (text.endsWith("\n")) eol = true;
String whitespace_before = text.substring(0, text.indexOf(text.trim()));
text = text.trim();
// Get the vector of URLS from the getPosts query.
Vector<String> results = Searcher.getThreads(text);
if (results.size() == 0) return null;
Vector<String> url = new Vector<String>();
for (int i=0; i<results.size(); i++) {
url.add(results.get(i));
}
// Get the accepted answer code snippet.
Vector<String> code = Searcher.getCodeSnippets(url);
if (code.size() == 0) return null;
Vector<String> fixed_code = fixSpacing(code,whitespace_before);
previous_search.clear();
previous_search = fixed_code;
previous_query = text;
// Find line length and offset to replace.
int line_num = doc.getLineOfOffset(offset);
int line_length = 0;
int line_offset = 0;
try {
line_length = doc.getLineLength(line_num);
line_offset = doc.getLineOffset(line_num);
if (eol) line_length -= 1;
} catch (BadLocationException e1) {
e1.printStackTrace();
}
// Replace the code snippet back into the document.
doc.replace(line_offset, line_length, fixed_code.get(0));
previous_offset = line_offset;
previous_length = fixed_code.get(0).length();
//Move cursor to the end of the inserted snippet.
editor.selectAndReveal(previous_offset + previous_length, 0);
doc.addDocumentListener(InputHandler.doclistener);
} catch (BadLocationException e) {
System.out.println("Error with getting input query.");
e.printStackTrace();
return null;
}
}
}
return null;
}