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


Java SelectionModel.getSelectedText方法代码示例

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


在下文中一共展示了SelectionModel.getSelectedText方法的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: 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

示例8: 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

示例9: 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

示例10: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    final MCSettingsProvider settings = MCSettingsProvider.getInstance(e.getProject());
    final Editor editor = e.getData(LangDataKeys.EDITOR);
    if (editor == null)
        return;

    final SelectionModel selectionModel = editor.getSelectionModel();
    String selectedText;

    if (selectionModel.hasSelection()) {
        selectedText = selectionModel.getSelectedText();
    }
    else {
        selectionModel.selectLineAtCaret();
        if (selectionModel.hasSelection()) {
            selectedText = selectionModel.getSelectedText();
            selectionModel.removeSelection();
        }
        else { return; }
    }

    MayaCommInterface maya = new MayaCommInterface(settings.getHost(), settings.getPort());
    maya.connectMayaLog();
    maya.sendCodeToMaya(selectedText);
}
 
开发者ID:cmcpasserby,项目名称:MayaCharm,代码行数:27,代码来源:SendSelectionAction.java

示例11: alignText

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
public void alignText(Editor editor) {
  String regex = Messages.showInputDialog(editor.getContentComponent(), "Enter regex to align with:", "Front End Alignment", null);
  SelectionModel selectionModel = editor.getSelectionModel();
  if(selectionModel.getSelectedText() != null) {
    Document document      = editor.getDocument();
    final int startOffset  = document.getLineStartOffset(document.getLineNumber(selectionModel.getSelectionStart()));
    final int endOffset    = document.getLineEndOffset(document.getLineNumber(selectionModel.getSelectionEnd()));
    final String text      = document.getText(new TextRange(startOffset, endOffset));
    final Editor editorArg = editor;

    final String newText   = (new RegexTextAligner(text, regex)).alignText();

    ApplicationManager.getApplication().runWriteAction(new Runnable() {
      @Override
      public void run() {
        editorArg.getDocument().replaceString(startOffset, endOffset, newText);
      }
    });
  }
}
 
开发者ID:jmulieri,项目名称:front-end-alignment,代码行数:21,代码来源:FrontEndAlignment.java

示例12: executeMyWriteActionPerCaret

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
protected void executeMyWriteActionPerCaret(Editor editor, Caret caret, DataContext dataContext, T additionalParam) {
final SelectionModel selectionModel = editor.getSelectionModel();
String selectedText = selectionModel.getSelectedText();

if (selectedText == null) {
	selectSomethingUnderCaret(editor, dataContext, selectionModel);
	selectedText = selectionModel.getSelectedText();

	if (selectedText == null) {
		return;
	}
}

String s = transformSelection(editor, dataContext, selectedText, additionalParam);
s = s.replace("\r\n", "\n");
s = s.replace("\r", "\n");
      editor.getDocument().replaceString(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd(), s);
  }
 
开发者ID:krasa,项目名称:StringManipulation,代码行数:19,代码来源:AbstractStringManipAction.java

示例13: actionPerformed

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
@Override
public final void actionPerformed(@NotNull AnActionEvent event) {

  final Project project = event.getProject();
  if (project == null) {
    return;
  }
  Editor editor = FileEditorManager.getInstance(project).getSelectedTextEditor();
  if (editor == null) {
    return;
  }
  final Document document = editor.getDocument();

  selectText(editor);

  SelectionModel selectionModel = editor.getSelectionModel();
  boolean word = isWord(document, selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
  String selectedText = selectionModel.getSelectedText();
  if (selectedText == null) {
    selectedText = "";
  }
  String updatedText = updateSelection(selectedText, word);

  updateDocument(project, document, selectionModel, updatedText);
}
 
开发者ID:asciidoctor,项目名称:asciidoctor-intellij-plugin,代码行数:26,代码来源:FormatAsciiDocAction.java

示例14: handleNoUsageTargets

import com.intellij.openapi.editor.SelectionModel; //导入方法依赖的package包/类
private static void handleNoUsageTargets(PsiFile file,
                                         @Nonnull Editor editor,
                                         SelectionModel selectionModel,
                                         @Nonnull 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:consulo,项目名称:consulo,代码行数:18,代码来源:HighlightUsagesHandler.java

示例15: getSelectedText

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


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