Java Code Examples for com.intellij.codeInsight.template.impl.TemplateState#isFinished()
The following examples show how to use
com.intellij.codeInsight.template.impl.TemplateState#isFinished() .
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: TemplateLineStartEndHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override protected void doExecute(Editor editor, @Nullable Caret caret, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { final TextRange range = templateState.getCurrentVariableRange(); final int caretOffset = editor.getCaretModel().getOffset(); if (range != null && shouldStayInsideVariable(range, caretOffset)) { int selectionOffset = editor.getSelectionModel().getLeadSelectionOffset(); int offsetToMove = myIsHomeHandler ? range.getStartOffset() : range.getEndOffset(); LogicalPosition logicalPosition = editor.offsetToLogicalPosition(offsetToMove).leanForward(myIsHomeHandler); editor.getCaretModel().moveToLogicalPosition(logicalPosition); EditorModificationUtil.scrollToCaret(editor); if (myWithSelection) { editor.getSelectionModel().setSelection(selectionOffset, offsetToMove); } else { editor.getSelectionModel().removeSelection(); } return; } } myOriginalHandler.execute(editor, caret, dataContext); }
Example 2
Source File: EscapeHandler.java From consulo with Apache License 2.0 | 6 votes |
@Override public void execute(Editor editor, DataContext dataContext) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { SelectionModel selectionModel = editor.getSelectionModel(); LookupImpl lookup = (LookupImpl)LookupManager.getActiveLookup(editor); // the idea behind lookup checking is that if there is a preselected value in lookup // then user might want just to close lookup but not finish a template. // E.g. user wants to move to the next template segment by Tab without completion invocation. // If there is no selected value in completion that user definitely wants to finish template boolean lookupIsEmpty = lookup == null || lookup.getCurrentItem() == null; if (!selectionModel.hasSelection() && lookupIsEmpty) { CommandProcessor.getInstance().setCurrentCommandName(CodeInsightBundle.message("finish.template.command")); templateState.gotoEnd(true); return; } } if (myOriginalHandler.isEnabled(editor, dataContext)) { myOriginalHandler.execute(editor, dataContext); } }
Example 3
Source File: ShowIntentionsPass.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doCollectInformation(@Nonnull ProgressIndicator progress) { if (!ApplicationManager.getApplication().isHeadlessEnvironment() && !myEditor.getContentComponent().hasFocus()) return; TemplateState state = TemplateManagerImpl.getTemplateState(myEditor); if (state != null && !state.isFinished()) return; getActionsToShow(myEditor, myFile, myIntentionsInfo, myPassIdToShowIntentionsFor, myQueryIntentionActions); myCachedIntentions = IntentionsUI.getInstance(myProject).getCachedIntentions(myEditor, myFile); myActionsChanged = myCachedIntentions.wrapAndUpdateActions(myIntentionsInfo, false); }
Example 4
Source File: ShowIntentionsPass.java From consulo with Apache License 2.0 | 5 votes |
@Override public void doApplyInformationToEditor() { ApplicationManager.getApplication().assertIsDispatchThread(); CachedIntentions cachedIntentions = myCachedIntentions; boolean actionsChanged = myActionsChanged; TemplateState state = TemplateManagerImpl.getTemplateState(myEditor); if ((state == null || state.isFinished()) && cachedIntentions != null) { IntentionsInfo syncInfo = new IntentionsInfo(); getActionsToShowSync(myEditor, myFile, syncInfo, myPassIdToShowIntentionsFor); actionsChanged |= cachedIntentions.addActions(syncInfo); IntentionsUI.getInstance(myProject).update(cachedIntentions, actionsChanged); } }
Example 5
Source File: SelectAllHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public void execute(Editor editor, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { final TextRange range = templateState.getCurrentVariableRange(); final int caretOffset = editor.getCaretModel().getOffset(); if (range != null && range.getStartOffset() <= caretOffset && caretOffset <= range.getEndOffset()) { editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()); return; } } myOriginalHandler.execute(editor, dataContext); }
Example 6
Source File: TemplateLineStartEndHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override protected boolean isEnabledForCaret(@Nonnull Editor editor, @Nonnull Caret caret, DataContext dataContext) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { TextRange range = templateState.getCurrentVariableRange(); int caretOffset = editor.getCaretModel().getOffset(); if (range != null && range.containsOffset(caretOffset)) return true; } return myOriginalHandler.isEnabled(editor, caret, dataContext); }
Example 7
Source File: EscapeHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isEnabled(Editor editor, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { return true; } return myOriginalHandler.isEnabled(editor, dataContext); }
Example 8
Source File: ShowIntentionActionsHandler.java From consulo with Apache License 2.0 | 5 votes |
public void invoke(@Nonnull final Project project, @Nonnull Editor editor, @Nonnull PsiFile file, boolean showFeedbackOnEmptyMenu) { PsiDocumentManager.getInstance(project).commitAllDocuments(); if (editor instanceof EditorWindow) { editor = ((EditorWindow)editor).getDelegate(); file = InjectedLanguageManager.getInstance(file.getProject()).getTopLevelFile(file); } final LookupEx lookup = LookupManager.getActiveLookup(editor); if (lookup != null) { lookup.showElementActions(null); return; } final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project); letAutoImportComplete(editor, file, codeAnalyzer); ShowIntentionsPass.IntentionsInfo intentions = ShowIntentionsPass.getActionsToShow(editor, file, true); IntentionsUI.getInstance(project).hide(); if (HintManagerImpl.getInstanceImpl().performCurrentQuestionAction()) return; //intentions check isWritable before modification: if (!file.isWritable()) return; TemplateState state = TemplateManagerImpl.getTemplateState(editor); if (state != null && !state.isFinished()) { return; } editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE); Editor finalEditor = editor; PsiFile finalFile = file; showIntentionHint(project, finalEditor, finalFile, intentions, showFeedbackOnEmptyMenu); }
Example 9
Source File: EscapeHandler.java From consulo with Apache License 2.0 | 5 votes |
@Override public boolean isEnabled(Editor editor, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); if (templateState != null && !templateState.isFinished()) { return true; } else { return myOriginalHandler.isEnabled(editor, dataContext); } }
Example 10
Source File: CSharpIntroduceHandler.java From consulo-csharp with Apache License 2.0 | 4 votes |
@RequiredReadAction public void performAction(CSharpIntroduceOperation operation) { final PsiFile file = operation.getFile(); if(!CommonRefactoringUtil.checkReadOnlyStatus(file)) { return; } final Editor editor = operation.getEditor(); if(editor.getSettings().isVariableInplaceRenameEnabled()) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(operation.getEditor()); if(templateState != null && !templateState.isFinished()) { return; } } PsiElement element1 = null; PsiElement element2 = null; final SelectionModel selectionModel = editor.getSelectionModel(); if(selectionModel.hasSelection()) { element1 = file.findElementAt(selectionModel.getSelectionStart()); element2 = file.findElementAt(selectionModel.getSelectionEnd() - 1); if(element1 instanceof PsiWhiteSpace) { int startOffset = element1.getTextRange().getEndOffset(); element1 = file.findElementAt(startOffset); } if(element2 instanceof PsiWhiteSpace) { int endOffset = element2.getTextRange().getStartOffset(); element2 = file.findElementAt(endOffset - 1); } } else { if(smartIntroduce(operation)) { return; } final CaretModel caretModel = editor.getCaretModel(); final Document document = editor.getDocument(); int lineNumber = document.getLineNumber(caretModel.getOffset()); if((lineNumber >= 0) && (lineNumber < document.getLineCount())) { element1 = file.findElementAt(document.getLineStartOffset(lineNumber)); element2 = file.findElementAt(document.getLineEndOffset(lineNumber) - 1); } } final Project project = operation.getProject(); if(element1 == null || element2 == null) { showCannotPerformError(project, editor); return; } element1 = CSharpRefactoringUtil.getSelectedExpression(project, file, element1, element2); if(element1 == null) { showCannotPerformError(project, editor); return; } if(!checkIntroduceContext(file, editor, element1)) { return; } operation.setElement(element1); performActionOnElement(operation); }
Example 11
Source File: HaxeIntroduceHandler.java From intellij-haxe with Apache License 2.0 | 4 votes |
protected void performAction(HaxeIntroduceOperation operation) { final PsiFile file = operation.getFile(); if (!CommonRefactoringUtil.checkReadOnlyStatus(file)) { return; } final Editor editor = operation.getEditor(); if (editor.getSettings().isVariableInplaceRenameEnabled()) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(operation.getEditor()); if (templateState != null && !templateState.isFinished()) { return; } } PsiElement element1 = null; PsiElement element2 = null; final SelectionModel selectionModel = editor.getSelectionModel(); if (selectionModel.hasSelection()) { element1 = file.findElementAt(selectionModel.getSelectionStart()); element2 = file.findElementAt(selectionModel.getSelectionEnd() - 1); } else { if (smartIntroduce(operation)) { return; } final CaretModel caretModel = editor.getCaretModel(); final Document document = editor.getDocument(); int lineNumber = document.getLineNumber(caretModel.getOffset()); if ((lineNumber >= 0) && (lineNumber < document.getLineCount())) { element1 = file.findElementAt(document.getLineStartOffset(lineNumber)); element2 = file.findElementAt(document.getLineEndOffset(lineNumber) - 1); } } if (element1 instanceof PsiWhiteSpace) { int startOffset = element1.getTextRange().getEndOffset(); element1 = file.findElementAt(startOffset); } if (element2 instanceof PsiWhiteSpace) { int endOffset = element2.getTextRange().getStartOffset(); element2 = file.findElementAt(endOffset - 1); } final Project project = operation.getProject(); if (element1 == null || element2 == null) { showCannotPerformError(project, editor); return; } element1 = HaxeRefactoringUtil.getSelectedExpression(project, file, element1, element2); if (!isValidForExtraction(element1)) { showCannotPerformError(project, editor); return; } if (!checkIntroduceContext(file, editor, element1)) { return; } operation.setElement(element1); performActionOnElement(operation); }
Example 12
Source File: PreviousVariableAction.java From consulo with Apache License 2.0 | 4 votes |
@Override protected boolean isEnabledForCaret(@Nonnull Editor editor, @Nonnull Caret caret, DataContext dataContext) { final TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); return templateState != null && !templateState.isFinished(); }
Example 13
Source File: NextVariableAction.java From consulo with Apache License 2.0 | 4 votes |
@Override protected boolean isEnabledForCaret(@Nonnull Editor editor, @Nonnull Caret caret, DataContext dataContext) { TemplateState templateState = TemplateManagerImpl.getTemplateState(editor); return templateState != null && !templateState.isFinished() && templateState.isToProcessTab(); }