當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。