当前位置: 首页>>代码示例>>Java>>正文


Java Editor.getSelectionModel方法代码示例

本文整理汇总了Java中com.intellij.openapi.editor.Editor.getSelectionModel方法的典型用法代码示例。如果您正苦于以下问题:Java Editor.getSelectionModel方法的具体用法?Java Editor.getSelectionModel怎么用?Java Editor.getSelectionModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.intellij.openapi.editor.Editor的用法示例。


在下文中一共展示了Editor.getSelectionModel方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTranslation

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private void getTranslation(AnActionEvent event) {
    Editor editor = event.getData(PlatformDataKeys.EDITOR);
    if (editor == null) {
        return;
    }
    SelectionModel model = editor.getSelectionModel();
    String selectedText = model.getSelectedText();
    if (TextUtils.isEmpty(selectedText)) {
        selectedText = getCurrentWords(editor);
        if (TextUtils.isEmpty(selectedText)) {
            return;
        }
    }
    String queryText = strip(addBlanks(selectedText));
    new Thread(new RequestRunnable(mTranslator, editor, queryText)).start();
}
 
开发者ID:a483210,项目名称:GoogleTranslation,代码行数:17,代码来源:GoogleTranslation.java

示例2: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor != null) {
        final SelectionModel selectionModel = editor.getSelectionModel();
        final ImportImpexHttpClient client = new ImportImpexHttpClient();
        final String selectedText = selectionModel.getSelectedText();
        if (StringUtils.isNotEmpty(selectedText)) {
            final HybrisHttpResult hybrisHttpResult = client.importImpex(selectedText);

            ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject());
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:15,代码来源:ImportImpexAction.java

示例3: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
public void actionPerformed( AnActionEvent e ) {
    Editor editor = ( Editor ) e.getDataContext().getData( "editor" );
    SelectionModel selectionModel = editor.getSelectionModel();
    if ( selectionModel != null ) {
        String selectedText = selectionModel.getSelectedText();
        if ( selectedText != null && selectedText.trim().length() > 0 ) {
            Project project = ( Project ) e.getDataContext().getData( DataConstants.PROJECT );
            String panelid = ( String ) project.getUserData( QuickNotes.KEY_PANELID );
            QuickNotesPanel quickNotesPanel = QuickNotesManager.getInstance().getQuickNotesPanel( panelid );
            if ( quickNotesPanel != null ) {
                FileDocumentManager manager = FileDocumentManager.getInstance();
                VirtualFile virtualFile = manager.getFile( editor.getDocument() );
                quickNotesPanel.addNewNote( "[File: " + virtualFile.getPath() + "]\n" + selectedText );
            }
        }
    }
}
 
开发者ID:jrana,项目名称:quicknotes,代码行数:18,代码来源:AddToQuickNotes.java

示例4: getTranslation

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private void getTranslation(AnActionEvent event) {
    Editor mEditor = event.getData(PlatformDataKeys.EDITOR);
    Project project = event.getData(PlatformDataKeys.PROJECT);
    String basePath = project.getBasePath();

    if (null == mEditor) {
        return;
    }
    SelectionModel model = mEditor.getSelectionModel();
    String selectedText = model.getSelectedText();
    if (TextUtils.isEmpty(selectedText)) {
        selectedText = getCurrentWords(mEditor);
        if (TextUtils.isEmpty(selectedText)) {
            return;
        }
    }
    String queryText = strip(addBlanks(selectedText));
    new Thread(new RequestRunnable(mEditor, queryText,basePath)).start();
}
 
开发者ID:BolexLiu,项目名称:ReciteWords,代码行数:20,代码来源:ReciteWords.java

示例5: getSelectedText

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Nullable
String getSelectedText(Editor editor) {
  SelectionModel selectionModel = editor.getSelectionModel();
  if(selectionModel.hasSelection()){
    return selectionModel.getSelectedText();
  }else {
    final ArrayList<TextRange> ranges = new ArrayList<>();
    final int offset = editor.getCaretModel().getOffset();
    SelectWordUtilCompat.addWordOrLexemeSelection(false, editor, offset, ranges, SelectWordUtilCompat.JAVASCRIPT_IDENTIFIER_PART_CONDITION);
    if(ranges.size()>0){
      return  editor.getDocument().getText(ranges.get(0));
    }else {
      return null;
    }
  }
}
 
开发者ID:dpzxsm,项目名称:ReactPropTypes-Plugin,代码行数:17,代码来源:CommonAction.java

示例6: handleNoUsageTargets

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
/**
     * {@link com.intellij.codeInsight.highlighting.HighlightUsagesHandler#handleNoUsageTargets(PsiFile,
     * Editor, SelectionModel, Project)}
     */
    private static void handleNoUsageTargets(PsiFile file, @NotNull Editor editor,
            @NotNull Project project) {
        if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) {
            return;
        }
        final SelectionModel selectionModel = editor.getSelectionModel();
        selectionModel.selectWordAtCaret(false);
        String selection = selectionModel.getSelectedText();
//        LOG.assertTrue(selection != null);
        if (selection != null) {
            for (int i = 0; i < selection.length(); i++) {
                if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
                    selectionModel.removeSelection();
                }
            }
            
            searchSelection(editor, project);
            selectionModel.removeSelection();
        }
    }
 
开发者ID:huoguangjin,项目名称:MultiHighlight,代码行数:25,代码来源:MultiHighlightHandler.java

示例7: getSelectedText

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
/**
 * Returns the selected text if there is any selection. If not return all based on parameter
 *
 * @param defaultToAll If no selection, then this decides whether to return all text
 */
String getSelectedText(boolean defaultToAll) {
    ConsoleView console = this.getConsole();
    Editor myEditor = console != null ? (Editor) CommonDataKeys.EDITOR.getData((DataProvider) console) : null;
    if (myEditor != null) {
        Document document = myEditor.getDocument();
        final SelectionModel selectionModel = myEditor.getSelectionModel();
        if (selectionModel.hasSelection()) {
            return selectionModel.getSelectedText();
        } else if (defaultToAll) {
            return document.getText();
        }
    }
    return null;
}
 
开发者ID:josesamuel,项目名称:logviewer,代码行数:20,代码来源:LogView.java

示例8: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor != null) {
        final SelectionModel selectionModel = editor.getSelectionModel();
        final FlexibleSearchHttpClient client = new FlexibleSearchHttpClient();
        final String selectedText = selectionModel.getSelectedText();
        if (StringUtils.isNotEmpty(selectedText)) {
            final HybrisHttpResult hybrisHttpResult = client.execute(selectedText);

            ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject());
        }
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:15,代码来源:ExecuteFlexibleSearchAction.java

示例9: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void actionPerformed(final AnActionEvent e) {
    final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
    if (editor != null) {
        final SelectionModel selectionModel = editor.getSelectionModel();
        final ValidateImpexHttpClient client = new ValidateImpexHttpClient();
        final HybrisHttpResult hybrisHttpResult = client.validateImpex(selectionModel.getSelectedText());

        ExecuteHybrisConsole.getInstance().show(hybrisHttpResult, e.getProject());
    }
}
 
开发者ID:AlexanderBartash,项目名称:hybris-integration-intellij-idea-plugin,代码行数:12,代码来源:ValidateImpexAction.java

示例10: addPlaceholder

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private void addPlaceholder(@NotNull CCState state) {
  Editor editor = state.getEditor();
  Project project = state.getProject();
  Document document = editor.getDocument();
  FileDocumentManager.getInstance().saveDocument(document);
  final SelectionModel model = editor.getSelectionModel();
  final int offset = model.hasSelection() ? model.getSelectionStart() : editor.getCaretModel().getOffset();
  TaskFile taskFile = state.getTaskFile();
  final Task task = state.getTaskFile().getTask();
  int subtaskIndex = task instanceof TaskWithSubtasks ? ((TaskWithSubtasks)task).getActiveSubtaskIndex() : 0;
  final AnswerPlaceholder answerPlaceholder = new AnswerPlaceholder();
  AnswerPlaceholderSubtaskInfo info = new AnswerPlaceholderSubtaskInfo();
  answerPlaceholder.getSubtaskInfos().put(subtaskIndex, info);
  int index = taskFile.getAnswerPlaceholders().size();
  answerPlaceholder.setIndex(index);
  answerPlaceholder.setTaskFile(taskFile);
  taskFile.sortAnswerPlaceholders();
  answerPlaceholder.setOffset(offset);
  answerPlaceholder.setUseLength(false);

  String defaultPlaceholderText = "type here";
  CCCreateAnswerPlaceholderDialog dlg = createDialog(project, answerPlaceholder);
  if (!dlg.showAndGet()) {
    return;
  }
  String answerPlaceholderText = dlg.getTaskText();
  answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
  answerPlaceholder.setTaskText(StringUtil.notNullize(answerPlaceholderText));
  answerPlaceholder.setLength(StringUtil.notNullize(answerPlaceholderText).length());
  answerPlaceholder.setHints(dlg.getHints());

  if (!model.hasSelection()) {
    DocumentUtil.writeInRunUndoTransparentAction(() -> document.insertString(offset, defaultPlaceholderText));
  }

  answerPlaceholder.setPossibleAnswer(model.hasSelection() ? model.getSelectedText() : defaultPlaceholderText);
  AddAction action = new AddAction(answerPlaceholder, taskFile, editor);
  EduUtils.runUndoableAction(project, "Add Answer Placeholder", action);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:40,代码来源:CCAddAnswerPlaceholder.java

示例11: canAddPlaceholder

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private static boolean canAddPlaceholder(@NotNull CCState state) {
  Editor editor = state.getEditor();
  SelectionModel selectionModel = editor.getSelectionModel();
  TaskFile taskFile = state.getTaskFile();
  if (selectionModel.hasSelection()) {
    int start = selectionModel.getSelectionStart();
    int end = selectionModel.getSelectionEnd();
    return !arePlaceholdersIntersect(taskFile, start, end);
  }
  int offset = editor.getCaretModel().getOffset();
  return StudyUtils.getAnswerPlaceholder(offset, taskFile.getAnswerPlaceholders()) == null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:13,代码来源:CCAddAnswerPlaceholder.java

示例12: actionPerformed

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
    //Get all the required data from data keys
    final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
    final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    //Access document, caret, and selection
    final Document document = editor.getDocument();
    final SelectionModel selectionModel = editor.getSelectionModel();

    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    //New instance of Runnable to make a replacement
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            //  return hex(random.randint(0, 2 ** 64) | 1 << 63)
            // from 0 to 64
            BigInteger rand = new BigInteger(64, new Random());
            rand = rand.or(new BigInteger("1").shiftLeft(63));
            String capnpId = rand.toString(16);
            document.setText( String.format("@0x%s; \n\n", capnpId) + document.getText());
        }
    };
    //Making the replacement
    WriteCommandAction.runWriteCommandAction(project, runnable);
    selectionModel.removeSelection();
}
 
开发者ID:xmonader,项目名称:sercapnp,代码行数:28,代码来源:GenerateCapnpID.java

示例13: searchSelection

import com.intellij.openapi.editor.Editor; //导入方法依赖的package包/类
private static void searchSelection(Editor editor, Project project) {
    final SelectionModel selectionModel = editor.getSelectionModel();
    if (!selectionModel.hasSelection()) {
        selectionModel.selectWordAtCaret(false);
    }
    
    final String text = selectionModel.getSelectedText();
    if (text == null) {
        return;
    }
    
    if (editor instanceof EditorWindow) {
        // highlightUsages selection in the whole editor, not injected fragment only
        editor = ((EditorWindow) editor).getDelegate();
    }
    
    EditorSearchSession oldSearch = EditorSearchSession.get(editor);
    if (oldSearch != null) {
        if (oldSearch.hasMatches()) {
            String oldText = oldSearch.getTextInField();
            if (!oldSearch.getFindModel().isRegularExpressions()) {
                oldText = StringUtil.escapeToRegexp(oldText);
                oldSearch.getFindModel().setRegularExpressions(true);
            }
            
            String newText = oldText + '|' + StringUtil.escapeToRegexp(text);
            oldSearch.setTextInField(newText);
            return;
        }
    }
    
    EditorSearchSession.start(editor, project).getFindModel().setRegularExpressions(false);
}
 
开发者ID:huoguangjin,项目名称:MultiHighlight,代码行数:34,代码来源:MultiHighlightHandler.java


注:本文中的com.intellij.openapi.editor.Editor.getSelectionModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。