use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class ProfileUIUtils method openEditorAndSelect.
/**
* Open a file in the Editor at the specified offset, highlighting the given length
*
* @param path : Absolute path pointing to the file which will be opened.
* @param line - line number to select, 0 to not select a line
* @param project - current project object
* @throws BadLocationException - Line number not valid in file
* @throws PartInitException if the editor could not be initialized
* @throws CoreException if the proxy cannot be initialized
* @since 3.1
*/
public static void openEditorAndSelect(String path, int line, IProject project) throws PartInitException, BadLocationException, CoreException {
IWorkbenchPage activePage = ProfileUIPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage();
IRemoteFileProxy proxy = null;
proxy = RemoteProxyManager.getInstance().getFileProxy(project);
IFileStore file = proxy.getResource(path);
if (file.fetchInfo().exists()) {
IEditorPart editor = IDE.openEditorOnFileStore(activePage, file);
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
if (line > 0) {
IDocumentProvider provider = textEditor.getDocumentProvider();
IDocument document = provider.getDocument(textEditor.getEditorInput());
// zero-indexed
int start = document.getLineOffset(line - 1);
textEditor.selectAndReveal(start, 0);
}
}
}
}
use of org.eclipse.ui.texteditor.IDocumentProvider in project linuxtools by eclipse.
the class SpecfileEditorToggleCommentActionDelegate method execute.
@Override
public Object execute(ExecutionEvent event) {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
ITextEditor specfileEditor = editor.getAdapter(ITextEditor.class);
IDocumentProvider dp = specfileEditor.getDocumentProvider();
IDocument document = dp.getDocument(specfileEditor.getEditorInput());
ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
if (currentSelection instanceof ITextSelection) {
ITextSelection selection = (ITextSelection) currentSelection;
// $NON-NLS-1$
String selectedContent = "";
try {
int begin = document.getLineOffset(selection.getStartLine());
StringBuilder sb = new StringBuilder(document.get().substring(0, begin));
String content = document.get().substring(begin, selection.getOffset() + selection.getLength());
if (linesContentCommentChar(content)) {
if (selection.getStartLine() == selection.getEndLine()) {
selectedContent = ISpecfileSpecialSymbols.COMMENT_START + content;
} else {
// $NON-NLS-1$ //$NON-NLS-2$
selectedContent = ISpecfileSpecialSymbols.COMMENT_START + content.replaceAll("\n", "\n#");
}
} else {
selectedContent = // $NON-NLS-1$
content.replaceFirst(ISpecfileSpecialSymbols.COMMENT_START, "").replaceAll("\n#", // $NON-NLS-1$ //$NON-NLS-2$
"\n");
}
sb.append(selectedContent);
sb.append(document.get().substring(selection.getOffset() + selection.getLength(), document.get().length()));
document.set(sb.toString());
specfileEditor.setHighlightRange(selection.getOffset(), selection.getLength(), true);
} catch (BadLocationException e) {
SpecfileLog.logError(e);
}
}
return null;
}
Aggregations