Java Code Examples for org.eclipse.ui.console.TextConsoleViewer#getDocument()

The following examples show how to use org.eclipse.ui.console.TextConsoleViewer#getDocument() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BackwardUpListHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.SexpBaseBackwardHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(final TextConsoleViewer viewer, final IConsoleView activePart, ExecutionEvent event) {

	IDocument doc = viewer.getDocument();
	boolean isBackup = getUniversalCount() > 0;  	// normal direction
	ITextSelection selection = (ITextSelection) viewer.getSelectionProvider().getSelection();
	try {
		int offset = doTransform(doc, selection, viewer.getTextWidget().getCaretOffset(),isBackup);
		if (offset == NO_OFFSET) {
			unbalanced(activePart,false);
		} else {
			endTransform(viewer, offset, selection, new TextSelection(null,offset,offset - selection.getOffset()));
		}
	} catch (BadLocationException e) {}
	return null;
}
 
Example 2
Source File: SexpBaseBackwardHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {

	IDocument document = viewer.getDocument();
	ITextSelection currentSelection = (ITextSelection)viewer.getSelectionProvider().getSelection();
	ITextSelection selection = null;
	try {
		selection = getNextSexp(document, currentSelection);
		if (selection == null) {
			selection = currentSelection;
			unbalanced(activePart,true);
			return null;
		} else {
			return endTransform(viewer, selection.getOffset(), currentSelection, selection);
		}
	} catch (BadLocationException e) {
	}
	return null;
}
 
Example 3
Source File: SexpBaseForwardHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, org.eclipse.ui.console.IConsoleView, org.eclipse.core.commands.ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {

	IDocument document = viewer.getDocument();
	ITextSelection currentSelection = (ITextSelection)viewer.getSelectionProvider().getSelection();
	ITextSelection selection = new TextSelection(document, viewer.getTextWidget().getCaretOffset(), 0);
	try {
		selection = getNextSexp(document, selection);
		if (selection == null) {
			selection = currentSelection;
			unbalanced(activePart,true);
			return null;
		} else {
			return endTransform(viewer, selection.getOffset() + selection.getLength(), currentSelection, selection);
		}
	} catch (BadLocationException e) {
	}
	return null;
}
 
Example 4
Source File: ConsoleCmdHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
	 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, IConsoleView, ExecutionEvent)
	 */
	public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
		IDocument doc = viewer.getDocument();
		int action = -1;
		try {
			StyledText st = viewer.getTextWidget();
			action = getDispatchId(getId(event, viewer));
			if (action > -1) {
				// set up for kill ring
				doc.addDocumentListener(KillRing.getInstance());
//  			setUpUndo(viewer);
				st.invokeAction(action);
			}
		} finally {
			// remove kill ring behavior
			if (action > -1) {
				doc.removeDocumentListener(KillRing.getInstance());
			}
			KillRing.getInstance().setKill(null, false);
		}
		return null;
	}
 
Example 5
Source File: ConsoleCopyCutHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
@Override
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	Object result = null;
	IDocument doc = viewer.getDocument();
	try {
		IWorkbenchPartSite site = activePart.getSite();
		if (site != null) {
			IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
			if (doc != null && service != null) {
				doc.addDocumentListener(KillRing.getInstance());
				String cmdId = getId(event, viewer);
				if (cmdId != null) {
					result = service.executeCommand(cmdId, null);
				}
			}
		}
	} catch (CommandException e) {
		// Shouldn't happen as the Command id will be null or valid
		e.printStackTrace();
	} finally {
		if (doc != null) {
			doc.removeDocumentListener(KillRing.getInstance());
		}
		// clear kill command flag
		KillRing.getInstance().setKill(null, false);
	}
	
	MarkUtils.clearConsoleMark(viewer);
	return result;
}
 
Example 6
Source File: KillLineHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * When called from a console context, will use ST.CUT
 * 
 * @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer,
 *      IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	if (viewer.isEditable()) {
		IDocument doc = viewer.getDocument();
		StyledText st = viewer.getTextWidget();
		int offset = st.getCaretOffset();
		try {
			IRegion info = doc.getLineInformationOfOffset(offset);
			int noffset = info.getOffset() + info.getLength();
			if (offset == noffset) {
				int line = doc.getLineOfOffset(offset);
				if (++line < doc.getNumberOfLines()) {
					noffset = doc.getLineOffset(line);
					if (noffset == doc.getLength()) {
						noffset = offset;
					}
				}
			}
			if (offset != noffset) {
				st.redraw();
				st.setSelection(offset, noffset);
				KillRing.getInstance().setKill(CUT_LINE_TO_END, false);
				return super.consoleDispatch(viewer, activePart, event);
			}
			viewer.refresh();
		} catch (BadLocationException e) {
		}
	}
	return null;
}
 
Example 7
Source File: BrowseKillRingHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Navigate up or down the ring entry by entry
 * 
 * @param viewer the viewer on the console
 * @param dir FORWARD or BACKWARD
 */
private void browseRing(TextConsoleViewer viewer, int dir) {
	IDocument doc = viewer.getDocument(); 
	StyledText st = viewer.getTextWidget();
	if (doc != null && st != null) {
		int lines = doc.getNumberOfLines();
		int off = st.getCaretOffset();
		
		try {
			int l = doc.getLineOfOffset(off);
			KilledText okill = offsetHash.get(doc.getLineOffset(l));
			KilledText nkill = null;
			int noff = -1;
			while ((l = l+dir) > -1 && l < lines){
				off = doc.getLineOffset(l);
				KilledText tkill = offsetHash.get(off);
				if (nkill == null) {
					if (tkill != null && tkill != okill) {
						nkill = offsetHash.get(off);
						noff = off;
						if (dir == FORWARD) {
							break;
						}
					}
				} else {
					if (tkill != null && tkill != nkill){
						break;
					} else {
						noff = off;
					}
				}
			}
			if (noff > -1) {
				st.setCaretOffset(noff);
				viewer.revealRange(noff, 0);
			}
		}catch (BadLocationException e) {
		}
	}
}
 
Example 8
Source File: BrowseKillRingHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/** 
 * Get the line offset of the cursor
 * 
 * @param viewer the console viewer
 * @return the line offset
 */
private int getLineOffset(TextConsoleViewer viewer) {
	int result = -1;
	IDocument doc = viewer.getDocument(); 
	StyledText st = viewer.getTextWidget();
	if (doc != null && st != null) {
		int off = st.getCaretOffset();
		try {
			IRegion info = doc.getLineInformationOfOffset(off);
			result = info.getOffset();
		}catch (BadLocationException e) {
		}
	}
	return result;
}
 
Example 9
Source File: DownListHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.SexpBaseForwardHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(final TextConsoleViewer viewer, final IConsoleView activePart, ExecutionEvent event) {

	IDocument doc = viewer.getDocument();
	ITextSelection currentSelection = (ITextSelection) viewer.getSelectionProvider().getSelection();
	ITextSelection selection = downList(doc, currentSelection);
	if (selection == null) {
		unbalanced(activePart,false);
	} else {
		endTransform(viewer,selection.getOffset() + selection.getLength(), currentSelection, selection);
	}
	return null;
}