Example usage for com.intellij.openapi.vfs VirtualFileWrapper getVirtualFile

List of usage examples for com.intellij.openapi.vfs VirtualFileWrapper getVirtualFile

Introduction

In this page you can find the example usage for com.intellij.openapi.vfs VirtualFileWrapper getVirtualFile.

Prototype

@Nullable
public VirtualFile getVirtualFile() 

Source Link

Document

Refreshes LocalFileSystem and looks for VirtualFile

Usage

From source file:com.android.tools.idea.ddms.screenshot.ScreenshotViewer.java

License:Apache License

@Override
protected void doOKAction() {
    FileSaverDescriptor descriptor = new FileSaverDescriptor(
            AndroidBundle.message("android.ddms.screenshot.save.title"), "", SdkConstants.EXT_PNG);
    FileSaverDialog saveFileDialog = FileChooserFactory.getInstance().createSaveFileDialog(descriptor,
            myProject);/* w  w w .ja  va  2  s  .  c o m*/
    VirtualFile baseDir = ourLastSavedFolder != null ? ourLastSavedFolder : myProject.getBaseDir();
    VirtualFileWrapper fileWrapper = saveFileDialog.save(baseDir, getDefaultFileName());
    if (fileWrapper == null) {
        return;
    }

    myScreenshotFile = fileWrapper.getFile();
    try {
        ImageIO.write(myDisplayedImageRef.get(), SdkConstants.EXT_PNG, myScreenshotFile);
    } catch (IOException e) {
        Messages.showErrorDialog(myProject, AndroidBundle.message("android.ddms.screenshot.save.error", e),
                AndroidBundle.message("android.ddms.actions.screenshot"));
        return;
    }

    VirtualFile virtualFile = fileWrapper.getVirtualFile();
    if (virtualFile != null) {
        //noinspection AssignmentToStaticFieldFromInstanceMethod
        ourLastSavedFolder = virtualFile.getParent();
    }

    super.doOKAction();
}