public void insert(PotentialStep pStep) { Point point = getSourceViewer().getSelectedRange(); try { getInputDocument().replace(point.x, 0, pStep.fullStep() + "\n"); } catch (BadLocationException e) { Activator.logError("Failed to insert potential step", e); } }
public void insertAsTemplate(PotentialStep pStep) { IDocument document = getInputDocument(); Point point = getSourceViewer().getSelectedRange(); int lineNo = getSourceViewer().getTextWidget().getLineAtOffset(point.x); int lineOffset = getSourceViewer().getTextWidget().getOffsetAtLine(lineNo); Region replacementRegion = new Region(lineOffset, 0); TemplateContextType contextType = StoryContextType.getTemplateContextType(); TemplateContext templateContext = new DocumentTemplateContext( contextType, document, replacementRegion.getOffset(), replacementRegion.getLength()); String templateText = TemplateUtils.templatizeVariables(pStep.fullStep()) + "\n"; Template template = new Template( pStep.stepPattern, pStep.fullStep(), StoryContextType.STORY_CONTEXT_TYPE_ID, templateText, false); new TemplateProposal(template, templateContext, replacementRegion, null, 0) .apply(getSourceViewer(), (char) 0, SWT.CONTROL, replacementRegion.getOffset()); }