Example usage for com.intellij.openapi.fileChooser FileSystemTree getNewFileParent

List of usage examples for com.intellij.openapi.fileChooser FileSystemTree getNewFileParent

Introduction

In this page you can find the example usage for com.intellij.openapi.fileChooser FileSystemTree getNewFileParent.

Prototype

@Nullable
    VirtualFile getNewFileParent();

Source Link

Usage

From source file:intellijeval.toolwindow.NewFileAction.java

License:Apache License

protected void update(FileSystemTree fileSystemTree, AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    final FileType fileType = e.getData(FileChooserKeys.NEW_FILE_TYPE);
    if (fileType != null) {
        presentation.setVisible(true);/*from ww w.j  a va 2s.  c  o  m*/
        VirtualFile selectedFile = fileSystemTree.getNewFileParent();
        presentation.setEnabled(selectedFile != null && selectedFile.isDirectory());
        // FORK DIFF (got rid of layered "new" icon because it's ugly)
        presentation.setIcon(fileType.getIcon());
    } else {
        presentation.setVisible(false);
    }
}

From source file:intellijeval.toolwindow.NewFileAction.java

License:Apache License

private static void createNewFile(FileSystemTree fileSystemTree, final FileType fileType,
        final String initialContent) {
    final VirtualFile file = fileSystemTree.getNewFileParent();
    if (file == null || !file.isDirectory())
        return;/*from   w w w. j  ava  2s.c o  m*/

    String newFileName;
    while (true) {
        newFileName = Messages.showInputDialog(
                UIBundle.message("create.new.file.enter.new.file.name.prompt.text"),
                UIBundle.message("new.file.dialog.title"), Messages.getQuestionIcon());
        if (newFileName == null) {
            return;
        }
        if ("".equals(newFileName.trim())) {
            Messages.showMessageDialog(
                    UIBundle.message("create.new.file.file.name.cannot.be.empty.error.message"),
                    UIBundle.message("error.dialog.title"), Messages.getErrorIcon());
            continue;
        }
        Exception failReason = ((FileSystemTreeImpl) fileSystemTree).createNewFile(file, newFileName, fileType,
                initialContent);
        if (failReason != null) {
            Messages.showMessageDialog(
                    UIBundle.message("create.new.file.could.not.create.file.error.message", newFileName),
                    UIBundle.message("error.dialog.title"), Messages.getErrorIcon());
            continue;
        }
        return;
    }
}

From source file:liveplugin.toolwindow.CreateRootFileAction.java

License:Apache License

@Override
protected void update(FileSystemTree fileSystemTree, AnActionEvent e) {
    boolean isAtPluginRoot = false;
    VirtualFile parentFile = fileSystemTree.getNewFileParent();
    if (parentFile != null) {
        isAtPluginRoot = LivePluginAppComponent.pluginIdToPathMap()
                .containsValue(parentFile.getCanonicalPath());
    }/* w  ww  . j  a  va2  s  . com*/

    boolean fileDoesNotExist = false;
    if (isAtPluginRoot) {
        fileDoesNotExist = (parentFile.findChild(newFileName) == null);
    }

    Presentation presentation = e.getPresentation();
    presentation.setVisible(isAtPluginRoot && fileDoesNotExist);
    presentation.setEnabled(isAtPluginRoot && fileDoesNotExist);
    presentation.setIcon(fileType.getIcon());
}

From source file:liveplugin.toolwindow.CreateRootFileAction.java

License:Apache License

@Override
protected void actionPerformed(FileSystemTree fileSystemTree, AnActionEvent e) {
    VirtualFile parentFile = fileSystemTree.getNewFileParent();

    //noinspection ThrowableResultOfMethodCallIgnored
    Exception failReason = ((FileSystemTreeImpl) fileSystemTree).createNewFile(parentFile, newFileName,
            fileType, fileContent);/*w  w  w .j a  v a2  s.  c om*/
    if (failReason != null) {
        String message = UIBundle.message("create.new.file.could.not.create.file.error.message", newFileName);
        String title = UIBundle.message("error.dialog.title");
        Messages.showMessageDialog(message, title, Messages.getErrorIcon());
    }
}

From source file:liveplugin.toolwindow.NewFileAction.java

License:Apache License

protected void update(FileSystemTree fileSystemTree, AnActionEvent e) {
    Presentation presentation = e.getPresentation();
    presentation.setVisible(true);//from w w  w  . j  a  v a  2s.c  o m
    VirtualFile selectedFile = fileSystemTree.getNewFileParent();
    presentation.setEnabled(selectedFile != null);
    // FORK DIFF (got rid of layered "new" icon because it's ugly)
    presentation.setIcon(fileType != null ? fileType.getIcon() : null);
}