Example usage for com.intellij.openapi.ui DialogWrapperPeer HAVE_INITIAL_SELECTION

List of usage examples for com.intellij.openapi.ui DialogWrapperPeer HAVE_INITIAL_SELECTION

Introduction

In this page you can find the example usage for com.intellij.openapi.ui DialogWrapperPeer HAVE_INITIAL_SELECTION.

Prototype

Object HAVE_INITIAL_SELECTION

To view the source code for com.intellij.openapi.ui DialogWrapperPeer HAVE_INITIAL_SELECTION.

Click Source Link

Usage

From source file:com.intellij.ide.fileTemplates.ui.CreateFromTemplatePanel.java

License:Apache License

private static void setPredefinedSelectionFor(final JTextField field, final TextRange selectionRange) {
    field.select(selectionRange.getStartOffset(), selectionRange.getEndOffset());
    field.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
}

From source file:com.intellij.refactoring.copy.CopyFilesOrDirectoriesDialog.java

License:Apache License

public CopyFilesOrDirectoriesDialog(PsiElement[] elements, PsiDirectory defaultTargetDirectory, Project project,
        boolean doClone) {
    super(project, true);
    myProject = project;/*from w w  w .ja v a 2  s. co m*/
    myShowDirectoryField = !doClone;
    myShowNewNameField = elements.length == 1;

    if (doClone && elements.length != 1) {
        throw new IllegalArgumentException("wrong number of elements to clone: " + elements.length);
    }

    setTitle(RefactoringBundle.message(doClone ? "copy.files.clone.title" : "copy.files.copy.title"));
    init();

    if (elements.length == 1) {
        String text;
        if (elements[0] instanceof PsiFile) {
            PsiFile file = (PsiFile) elements[0];
            String url = shortenPath(file.getVirtualFile());
            text = RefactoringBundle.message(doClone ? "copy.files.clone.file.0" : "copy.files.copy.file.0",
                    url);
            final String fileName = file.getName();
            myNewNameField.setText(fileName);
            final int dotIdx = fileName.lastIndexOf(".");
            if (dotIdx > -1) {
                myNewNameField.select(0, dotIdx);
                myNewNameField.putClientProperty(DialogWrapperPeer.HAVE_INITIAL_SELECTION, true);
            }
            myFileCopy = true;
        } else {
            PsiDirectory directory = (PsiDirectory) elements[0];
            String url = shortenPath(directory.getVirtualFile());
            text = RefactoringBundle
                    .message(doClone ? "copy.files.clone.directory.0" : "copy.files.copy.directory.0", url);
            myNewNameField.setText(directory.getName());
        }
        myInformationLabel.setText(text);
    } else {
        setMultipleElementCopyLabel(elements);
    }

    boolean allBinary = true;
    for (PsiElement element : elements) {
        if (!(element.getContainingFile() instanceof PsiBinaryFile)) {
            allBinary = false;
            break;
        }
    }
    if (allBinary) {
        myOpenFilesInEditor.setVisible(false);
    }
    if (myShowDirectoryField) {
        String targetPath = defaultTargetDirectory == null ? ""
                : defaultTargetDirectory.getVirtualFile().getPresentableUrl();
        myTargetDirectoryField.getChildComponent().setText(targetPath);
    }
    validateOKButton();
}