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


Java SelectionModel类代码示例

本文整理汇总了Java中com.intellij.openapi.editor.SelectionModel的典型用法代码示例。如果您正苦于以下问题:Java SelectionModel类的具体用法?Java SelectionModel怎么用?Java SelectionModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getTranslation

import com.intellij.openapi.editor.SelectionModel; //导入依赖的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.SelectionModel; //导入依赖的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.SelectionModel; //导入依赖的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.SelectionModel; //导入依赖的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.SelectionModel; //导入依赖的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.SelectionModel; //导入依赖的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: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
    //获取编辑器
    Editor editor = e.getData(PlatformDataKeys.EDITOR);
    if (editor != null){
        SelectionModel model = editor.getSelectionModel();
        //获取选中文本
        String selectedText = model.getSelectedText().toString();
        if (selectedText!=null){
            selectedText = addBlanks(selectedText);
            try {
                getTranslation(selectedText);
            } catch (JSONException e1) {
                e1.printStackTrace();
            }
        }
    }
}
 
开发者ID:shicaiD,项目名称:DscTranslate,代码行数:19,代码来源:DscTranslate.java

示例8: getReplacementRunnable

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
protected Runnable getReplacementRunnable(final Document document, SelectionModel selectionModel) {
    final String selectedText = selectionModel.getSelectedText();
    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    final Address address = extractLonLatAndGetAddress(selectedText);
    Runnable replacementProcess = new Runnable() {
        @Override
        public void run() {
            if (address == null) {
                return;
            }
            document.replaceString(
                    start,
                    end,
                    address.toString());
        }
    };
    return replacementProcess;
}
 
开发者ID:dnltsk,项目名称:intellij-geocoding-plugin,代码行数:20,代码来源:LonLatToTextAction.java

示例9: getReplacementRunnable

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
@Override
@NotNull
protected Runnable getReplacementRunnable(final Document document, SelectionModel selectionModel) {
    final String selectedText = selectionModel.getSelectedText();
    final int start = selectionModel.getSelectionStart();
    final int end = selectionModel.getSelectionEnd();
    final LonLat lonLat = nominatimGeocoder.addressToLonLat(selectedText);
    return new Runnable() {
        @Override
        public void run() {
            if (lonLat == null) {
                return;
            }
            document.replaceString(
                    start,
                    end,
                    lonLatRenderer.renderLonLat(lonLat));

        }
    };
}
 
开发者ID:dnltsk,项目名称:intellij-geocoding-plugin,代码行数:22,代码来源:TextToLonLatAction.java

示例10: getContents

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
@NotNull
public DiffContent[] getContents() {
  if (myContents != null) return myContents;
  DiffContent clipboardContent = ClipboardVsValueContents.createClipboardContent();
  if (clipboardContent == null) clipboardContent = new SimpleContent("");
  myContents = new DiffContent[2];
  myContents[0] = clipboardContent;

  SelectionModel selectionModel = myEditor.getSelectionModel();
  if (selectionModel.hasSelection()) {
    TextRange range = new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
    boolean forceReadOnly = myEditor.isViewer();
    myContents[1] = new FragmentContent(DiffContent.fromDocument(getProject(), getDocument()),
                                        range, getProject(), getDocumentFile(getDocument()), forceReadOnly);
  }
  else {
    myContents [1] = DiffContent.fromDocument(getProject(), getDocument());
  }
  return myContents;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:CompareClipboardWithSelection.java

示例11: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
@Override
public void executeWriteAction(@NotNull Editor editor, Caret caret, DataContext dataContext) {
  final Document document = editor.getDocument();
  final int caretOffset = editor.getCaretModel().getOffset();
  if (caretOffset < 1) {
    return;
  }

  final SelectionModel selectionModel = editor.getSelectionModel();
  final CharSequence text = document.getCharsSequence();
  final char c = text.charAt(caretOffset - 1);
  if (!selectionModel.hasSelection() && StringUtil.isWhiteSpace(c)) {
    int startOffset = CharArrayUtil.shiftBackward(text, caretOffset - 2, "\t \n") + 1;
    document.deleteString(startOffset, caretOffset);
  }
  else {
    final EditorActionHandler handler = EditorActionManager.getInstance().getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
    handler.execute(editor, caret, dataContext);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:HungryBackspaceAction.java

示例12: executeWriteAction

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
@Override
public void executeWriteAction(final Editor editor, DataContext dataContext) {
  final SelectionModel selectionModel = editor.getSelectionModel();
  int changedLines = 0;
  if (selectionModel.hasSelection()) {
    changedLines = performAction(editor, new TextRange(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()));
  }
  else {
    changedLines += performAction(editor, new TextRange(0, editor.getDocument().getTextLength()));
  }
  if (changedLines == 0) {
    HintManager.getInstance().showInformationHint(editor, "All lines already have requested indentation");
  }
  else {
    HintManager.getInstance().showInformationHint(editor, "Changed indentation in " + changedLines + (changedLines == 1 ? " line" : " lines"));
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:ConvertIndentsActionBase.java

示例13: execute

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
@Override
public void execute(final Editor editor, final DataContext dataContext) {
  SelectionModel selectionModel = editor.getSelectionModel();
  if (!selectionModel.hasSelection()) {
    return;
  }

  final int start = selectionModel.getSelectionStart();
  final int end = selectionModel.getSelectionEnd();
  if (start >= end) {
    return;
  }
  KillRingUtil.copyToKillRing(editor, start, end, false);
  if (myRemove) {
    ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(editor.getDocument(),editor.getProject()) {
      @Override
      public void run() {
        editor.getDocument().deleteString(start, end);
      }
    });
  } 
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:KillRingSaveAction.java

示例14: handleNoUsageTargets

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
private static void handleNoUsageTargets(PsiFile file,
                                         @NotNull Editor editor,
                                         SelectionModel selectionModel,
                                         @NotNull Project project) {
  if (file.findElementAt(editor.getCaretModel().getOffset()) instanceof PsiWhiteSpace) return;
  selectionModel.selectWordAtCaret(false);
  String selection = selectionModel.getSelectedText();
  LOG.assertTrue(selection != null);
  for (int i = 0; i < selection.length(); i++) {
    if (!Character.isJavaIdentifierPart(selection.charAt(i))) {
      selectionModel.removeSelection();
    }
  }

  doRangeHighlighting(editor, project);
  selectionModel.removeSelection();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:HighlightUsagesHandler.java

示例15: getSelectedRanges

import com.intellij.openapi.editor.SelectionModel; //导入依赖的package包/类
protected static List<TextRange> getSelectedRanges(@NotNull SelectionModel selectionModel) {
  final List<TextRange> ranges = new SmartList<TextRange>();
  if (selectionModel.hasSelection()) {
    TextRange range = TextRange.create(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
    ranges.add(range);
  }
  else if (selectionModel.hasBlockSelection()) {
    int[] starts = selectionModel.getBlockSelectionStarts();
    int[] ends = selectionModel.getBlockSelectionEnds();
    for (int i = 0; i < starts.length; i++) {
      ranges.add(TextRange.create(starts[i], ends[i]));
    }
  }

  return ranges;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:AbstractLayoutCodeProcessor.java


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