Example usage for com.intellij.openapi.wm IdeFrame getProject

List of usage examples for com.intellij.openapi.wm IdeFrame getProject

Introduction

In this page you can find the example usage for com.intellij.openapi.wm IdeFrame getProject.

Prototype

@Nullable
    Project getProject();

Source Link

Usage

From source file:com.intellij.ide.CommandLineProcessor.java

License:Apache License

@NotNull
private static Project findBestProject(VirtualFile virtualFile, Project[] projects) {
    for (Project aProject : projects) {
        if (ProjectRootManager.getInstance(aProject).getFileIndex().isInContent(virtualFile)) {
            return aProject;
        }//from ww w  .  j a v a2  s.  c o m
    }
    IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
    Project project = frame == null ? null : frame.getProject();
    return project != null ? project : projects[0];
}

From source file:com.intellij.unscramble.UnscrambleListener.java

License:Apache License

@Override
public void applicationActivated(final IdeFrame ideFrame) {
    final Runnable processClipboard = new Runnable() {
        @Override//  w  w w . j  a va 2s.c o m
        public void run() {
            final String clipboard = AnalyzeStacktraceUtil.getTextInClipboard();
            if (clipboard != null && clipboard.length() < MAX_STACKTRACE_SIZE
                    && !clipboard.equals(stacktrace)) {
                stacktrace = clipboard;
                final Project project = ideFrame.getProject();
                if (project != null && isStacktrace(stacktrace)) {
                    final UnscrambleDialog dialog = new UnscrambleDialog(project);
                    dialog.createNormalizeTextAction().actionPerformed(null);
                    dialog.doOKAction();
                }
            }
        }
    };

    if (Patches.SLOW_GETTING_CLIPBOARD_CONTENTS) {
        //IDEA's clipboard is synchronized with the system clipboard on frame activation so we need to postpone clipboard processing
        new Alarm().addRequest(processClipboard, 300);
    } else {
        processClipboard.run();
    }
}

From source file:com.microsoft.alm.plugin.idea.common.utils.IdeaHelper.java

License:Open Source License

/**
 * Find the project that is associated with the current open frame
 * Got this method from how Git gets the current project
 *
 * @return project based on repo//  w  ww.j a  v  a2s  .  c om
 */
public static Project getCurrentProject() {
    final IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
    return frame == null || frame.getProject() == null ? ProjectManager.getInstance().getDefaultProject()
            : frame.getProject();
}

From source file:io.flutter.project.FlutterProjectCreator.java

License:Open Source License

public void createProject() {
    IdeFrame frame = IdeFocusManager.getGlobalInstance().getLastFocusedFrame();
    final Project projectToClose = frame != null ? frame.getProject() : null;

    final File location = new File(FileUtil.toSystemDependentName(myModel.projectLocation().get()));
    if (!location.exists() && !location.mkdirs()) {
        String message = ActionsBundle.message("action.NewDirectoryProject.cannot.create.dir",
                location.getAbsolutePath());
        Messages.showErrorDialog(projectToClose, message,
                ActionsBundle.message("action.NewDirectoryProject.title"));
        return;/*from w w  w  . j a v a 2s . c o  m*/
    }
    final File baseFile = new File(location, myModel.projectName().get());
    //noinspection ResultOfMethodCallIgnored
    baseFile.mkdirs();
    final VirtualFile baseDir = ApplicationManager.getApplication().runWriteAction(
            (Computable<VirtualFile>) () -> LocalFileSystem.getInstance().refreshAndFindFileByIoFile(baseFile));
    if (baseDir == null) {
        LOG.error("Couldn't find '" + location + "' in VFS");
        return;
    }
    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);

    RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getPath());

    ProjectOpenedCallback callback = (project, module) -> ProgressManager.getInstance()
            .run(new Task.Modal(null, "Creating Flutter Project", false) {
                @Override
                public void run(@NotNull ProgressIndicator indicator) {
                    indicator.setIndeterminate(true);

                    // The IDE has already created some files. Flutter won't overwrite them, but we want the versions provided by Flutter.
                    deleteDirectoryContents(baseFile);

                    // Add an Android facet if needed by the project type.
                    if (myModel.projectType().getValue() != FlutterProjectType.PACKAGE) {
                        ModifiableFacetModel model = FacetManager.getInstance(module).createModifiableModel();
                        AndroidFacetType facetType = AndroidFacet.getFacetType();
                        AndroidFacet facet = facetType.createFacet(module, AndroidFacet.NAME,
                                facetType.createDefaultConfiguration(), null);
                        model.addFacet(facet);
                        configureFacet(facet, baseFile, "android");
                        File appLocation = new File(baseFile, "android");
                        //noinspection ResultOfMethodCallIgnored
                        appLocation.mkdirs();
                        AndroidFacet appFacet = facetType.createFacet(module, AndroidFacet.NAME,
                                facetType.createDefaultConfiguration(), null);
                        model.addFacet(appFacet);
                        configureFacet(appFacet, appLocation, "app");
                    }

                    FlutterSmallIDEProjectGenerator.generateProject(project, baseDir,
                            myModel.flutterSdk().get(), module, makeAdditionalSettings());

                    // Reload the project to use the configuration written by Flutter.
                    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
                    ConversionService.getInstance().convertSilently(baseDir.getPath(),
                            new MyConversionListener());
                    VfsUtil.markDirtyAndRefresh(false, true, true, baseDir);
                    reloadProjectNow(project);
                }
            });

    EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet
            .noneOf(PlatformProjectOpenProcessor.Option.class);
    PlatformProjectOpenProcessor.doOpenProject(baseDir, projectToClose, -1, callback, options);
    // The project was reloaded by the callback. Find the new Project object.
    Project newProject = FlutterUtils.findProject(baseDir.getPath());
    if (newProject != null) {
        StartupManager.getInstance(newProject)
                .registerPostStartupActivity(() -> ApplicationManager.getApplication().invokeLater(() -> {
                    disableUserConfig(newProject);
                    // We want to show the Project view, not the Android view since it doesn't make the Dart code visible.
                    ProjectView.getInstance(newProject).changeView(ProjectViewPane.ID);
                    //ProjectManager.getInstance().reloadProject(newProject);
                }, ModalityState.NON_MODAL));
    }
}

From source file:ru.scratch.ScratchListenClipboardAction.java

License:Apache License

private static Editor getSelectedEditor() {
    IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame();
    if (frame == null)
        return null;

    FileEditorManager instance = FileEditorManager.getInstance(frame.getProject());
    return instance.getSelectedTextEditor();
}