org.eclipse.ui.console.IConsoleView Java Examples

The following examples show how to use org.eclipse.ui.console.IConsoleView. 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: MarkExchangeHandler.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Support exchange for simple mark on TextConsole
 * 
 * @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) {
	int mark = viewer.getMark();
	StyledText st = viewer.getTextWidget(); 
	if (mark != -1) {
		try {
			st.setRedraw(false);
			int offset = st.getCaretOffset();
			viewer.setMark(offset);
			st.setCaretOffset(mark);
			int len = offset - mark;
			viewer.setSelectedRange(offset, -len);
		} finally {
			st.setRedraw(true);
		}
	}
	return null;
}
 
Example #2
Source File: EmacsMovementHandler.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) {
	
	StyledText st = viewer.getTextWidget(); 
	String id = event.getCommand().getId(); 
	boolean isSelect =  isMarkEnabled(viewer,(ITextSelection)viewer.getSelection());
	int action = getDispatchId(id,isSelect);
	if (action > -1) {
		st.invokeAction(action);
	} else if ((id = getId(isSelect)) != null) {
		// support sexps 
		try {
			EmacsPlusUtils.executeCommand(id, null, activePart);
		} catch (Exception e) {
			e.printStackTrace();
		}			
	}
	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: 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 #5
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 #6
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 #7
Source File: ScriptConsole.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
public static Iterable<IConsoleView> iterConsoles() {
    List<IConsoleView> consoles = new ArrayList<>();
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null) {
        IWorkbenchPage page = window.getActivePage();
        if (page != null) {

            List<IViewPart> consoleParts = getConsoleParts(page, false);
            if (consoleParts.size() == 0) {
                consoleParts = getConsoleParts(page, true);
            }
            for (IViewPart iViewPart : consoleParts) {
                if (iViewPart instanceof IConsoleView) {
                    consoles.add((IConsoleView) iViewPart);
                }
            }
        }
    }
    return consoles;
}
 
Example #8
Source File: Console.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public void show() {
	
	Runnable runnable = new Runnable() {
		public void run() {
			// this should only be called from GUI thread
			IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
			if (window == null) {
				CppcheclipsePlugin.logError("Could not show console because there is no active workbench window");
				return;
			}
			IWorkbenchPage page = window.getActivePage();
			if (page == null) {
				CppcheclipsePlugin.logError("Could not show console because there is no active page");
				return;
			}
			try {
				IConsoleView view = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
				view.display(messageConsole);
			} catch (PartInitException e) {
				CppcheclipsePlugin.logError("Could not show console", e);
			}
			
		}
	};
	Display.getDefault().asyncExec(runnable);
}
 
Example #9
Source File: ResourceUtils.java    From LogViewer with Eclipse Public License 2.0 6 votes vote down vote up
public static IConsole getConsole(IWorkbenchPart part) {
      if(!(part instanceof IViewPart)){
          return null;
      }

      IViewPart vp =(IViewPart) part;
      if (vp instanceof PageBookView) {
          IPage page = ((PageBookView) vp).getCurrentPage();
          ITextViewer viewer = getViewer(page);
          if (viewer == null || viewer.getDocument() == null)
          	return null;
      }

      IConsole con = null;
  	try {
  		con = ((IConsoleView)part).getConsole();
  	} catch (Exception e) {

}

return con;
  }
 
Example #10
Source File: PyOpenLastConsoleHyperlink.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void run(IAction action) {
    for (IConsoleView c : ScriptConsole.iterConsoles()) {
        IConsole console = c.getConsole();
        if (console instanceof IOConsole) {
            IOConsole ioConsole = (IOConsole) console;
            processIOConsole(ioConsole);
            break;
        }
    }
}
 
Example #11
Source File: EmacsPlusConsole.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
    * @see org.eclipse.ui.console.IConsole#createPage(org.eclipse.ui.console.IConsoleView)
    */
public IPageBookViewPage createPage(IConsoleView view) {
   	IPageBookViewPage page = super.createPage(view);
       if (page instanceof TextConsolePage) {
       	myPage = (TextConsolePage)page;
       }
       return page;
   }
 
Example #12
Source File: XdsConsolePage.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public XdsConsolePage(TextConsole console, IConsoleView view) {
    super(console, view);

    fPropertyChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            String property = event.getProperty();
            if (property.equals(IConsoleConstants.P_CONSOLE_OUTPUT_COMPLETE)) {
                setReadOnly();
            }
        }
    };
    console.addPropertyChangeListener(fPropertyChangeListener);
}
 
Example #13
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;
}
 
Example #14
Source File: BaseYankHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * When called from a console context, use paste
 * 
 * @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) {

	StyledText st = viewer.getTextWidget();
	try {
		// set directly from the widget
		widgetEol = st.getLineDelimiter();
		paste(event,st,activePart.getConsole() instanceof IConsole);
	} finally {
		st.redraw();
		widgetEol = null;
	}
	
	return null;
}
 
Example #15
Source File: ConsoleActivateDebugContext.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void init(IPageBookViewPage page, IConsole console) {
    this.page = page;
    this.console = (PydevConsole) console;

    view = (IConsoleView) page.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW);
    DebugUITools.getDebugContextManager().getContextService(page.getSite().getWorkbenchWindow())
            .addDebugContextListener(this);
}
 
Example #16
Source File: RecenterHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	CS saveState = state;
	try {
		state = CS.C;
		StyledText st = viewer.getTextWidget();
		st.redraw();
		recenter(st);
	} finally {
		state = saveState;
	}
	return null;
}
 
Example #17
Source File: ScrollLockAction.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public ScrollLockAction(IConsoleView consoleView) {
	super(ConsoleMessages.ScrollLockAction_Name);
	fConsoleView = consoleView;
	
	setToolTipText(ConsoleMessages.ScrollLockAction_Tooltip);
	setImageDescriptor(LangImages.IMG_SCROLL_LOCK.getDescriptor());
	boolean checked = fConsoleView.getScrollLock();
	setChecked(checked);
}
 
Example #18
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 #19
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 #20
Source File: MarkSetHandler.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Support simple mark on TextConsole
 * 
 * @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
 */
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
	int offset = viewer.getTextWidget().getCaretOffset();
	viewer.setSelectedRange(offset, 0);
	viewer.setMark(offset);
	return null;
}
 
Example #21
Source File: EclipseStreamingTextWidget.java    From ice with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * (non-Javadoc)
 * 
 * @see IStreamingTextWidget#display()
 */
@Override
public void display() {

	// Must sync with the display thread
	Display.getDefault().asyncExec(new Runnable() {
		@Override
		public void run() {
			// Get the currently active page
			IWorkbenchPage page = PlatformUI.getWorkbench()
					.getActiveWorkbenchWindow().getActivePage();
			try {
				// Load the console view
				consoleView = (IConsoleView) page
						.showView(IConsoleConstants.ID_CONSOLE_VIEW);
				// Create the console instance that will be used to display
				// text from this widget.
				console = new MessageConsole("CLI", null);
				// Add the console to the console manager
				ConsolePlugin.getDefault().getConsoleManager()
						.addConsoles(new IConsole[] { console });
				// Show the console in the view
				consoleView.display(console);
				console.activate();
				// Get an output stream for the console
				msgStream = console.newMessageStream();
				msgStream.setActivateOnWrite(true);
				msgStream.println("Streaming output console activated.");
			} catch (PartInitException e) {
				// Complain
				logger.error("EclipseStreamingTextWidget Message: "
						+ "Unable to stream text!");
				logger.error(getClass().getName() + " Exception!", e);
			}

		}
	});

	return;
}
 
Example #22
Source File: EclipseUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Reveal the given console. If necessary, this will open the console view, bring it to the front, and reveal the
 * given console inside the console view.
 */
public static void revealConsole(IConsole console) {
	PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
		@Override
		public void run() {
			final IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
			try {
				final IConsoleView view = (IConsoleView) page.showView(IConsoleConstants.ID_CONSOLE_VIEW);
				view.display(console);
			} catch (PartInitException e) {
				// ignore
			}
		}
	});
}
 
Example #23
Source File: EmacsPlusCmdHandler.java    From e4macs with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
 */
@SuppressWarnings("unchecked")
public Object execute(ExecutionEvent event) throws ExecutionException {
	ITextEditor editor = getTextEditor(event);
	if (editor == null) { 
		if (isWindowCommand()) {
			Object result = checkExecute(event); 
			if (result == Check.Fail) {
				beep();
				result = null;
			}
			return result; 
		} else if (isConsoleCommand()) {
			// intercept and dispatch execution if console supported and used in a console view
			IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
			if (activePart != null && (activePart instanceof IConsoleView) && (activePart instanceof PageBookView)) {
				IPage textPage = ((PageBookView)activePart).getCurrentPage();
				if (textPage instanceof TextConsolePage) {
					return ((IConsoleDispatch)this).consoleDispatch(((TextConsolePage)textPage).getViewer(),(IConsoleView)activePart,event);
				}				
			}
		}
	}
	try {
		setThisEditor(editor);
		isEditable = getEditable();
		if (editor == null || isBlocked()) {
			beep();
			asyncShowMessage(editor, INEDITABLE_BUFFER, true);
			return null;
		}
		
		// Retrieve the universal-argument parameter value if passed 
		if (extractUniversalCount(event) != 1) {
			// check if we should dispatch a related command based on the universal argument
			String dispatchId = checkDispatchId(event.getCommand().getId());
			if (dispatchId != null) {
				// recurse on new id (inverse or arg value driven)
				return dispatchId(editor, dispatchId, getParams(event.getCommand(), event.getParameters()));
			}
		}
		
		setThisDocument(editor.getDocumentProvider().getDocument(editor.getEditorInput()));

		// Get the current selection
		ISelectionProvider selectionProvider = editor.getSelectionProvider();
		ITextSelection selection = (ITextSelection) selectionProvider.getSelection();
		preTransform(editor, selection);
		return transformWithCount(editor, getThisDocument(), selection, event);
		
	} finally {
		// normal commands clean up here
		if (isTransform()) {
			postExecute();
		}
	}
}
 
Example #24
Source File: CppStyleConsolePage.java    From CppStyle with MIT License 4 votes vote down vote up
public CppStyleConsolePage(CppStyleMessageConsole console, IConsoleView view) {
	super(console, view);
	this.console = console;
}
 
Example #25
Source File: ScriptConsolePage.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
public ScriptConsolePage(ScriptConsole console, IConsoleView view, SourceViewerConfiguration cfg) {
    super(console, view);

    this.cfg = cfg;
}
 
Example #26
Source File: CppStyleMessageConsole.java    From CppStyle with MIT License 4 votes vote down vote up
@Override
public IPageBookViewPage createPage(IConsoleView view) {
	page = new CppStyleConsolePage(this, view);
	return page;
}
 
Example #27
Source File: ScriptConsole.java    From Pydev with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates the actual page to be shown to the user.
 */
@Override
public IPageBookViewPage createPage(IConsoleView view) {
    page = new ScriptConsolePage(this, view, createSourceViewerConfiguration());
    return page;
}
 
Example #28
Source File: XdsConsole.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IPageBookViewPage createPage(IConsoleView view) {
    xdsConsolePage = new XdsConsolePage(this, view);
    return xdsConsolePage;
}
 
Example #29
Source File: ToolsConsole.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public IPageBookViewPage createPage(IConsoleView view) {
	return new ToolsConsolePage(this, view);
}
 
Example #30
Source File: ToolsConsolePage.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public ToolsConsolePage(TextConsole console, IConsoleView view) {
	super(console, view);
	
	setReadOnly();
}