Java Code Examples for com.intellij.openapi.project.Project#isDisposed()

The following examples show how to use com.intellij.openapi.project.Project#isDisposed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CreateFromTemplateGroup.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void update(@Nonnull AnActionEvent event) {
  Project project = event.getData(CommonDataKeys.PROJECT);
  Presentation presentation = event.getPresentation();
  if(project != null && !project.isDisposed()) {
    FileTemplate[] allTemplates = FileTemplateManager.getInstance(project).getAllTemplates();
    for (FileTemplate template : allTemplates) {
      if (canCreateFromTemplate(event, template)) {
        presentation.setEnabled(true);
        return;
      }
    }
  }
  presentation.setEnabled(false);
}
 
Example 2
Source File: BreadcrumbsInitializingActivity.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public void runActivity(@Nonnull Project project) {
  if (project.isDefault() || ApplicationManager.getApplication().isUnitTestMode() || project.isDisposed()) {
    return;
  }

  MessageBusConnection connection = project.getMessageBus().connect();
  connection.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new MyFileEditorManagerListener());
  connection.subscribe(FileTypeManager.TOPIC, new FileTypeListener() {
    @Override
    public void fileTypesChanged(@Nonnull FileTypeEvent event) {
      reinitBreadcrumbsInAllEditors(project);
    }
  });

  VirtualFileManager.getInstance().addVirtualFileListener(new MyVirtualFileListener(project), project);
  connection.subscribe(UISettingsListener.TOPIC, uiSettings -> reinitBreadcrumbsInAllEditors(project));

  UIUtil.invokeLaterIfNeeded(() -> reinitBreadcrumbsInAllEditors(project));
}
 
Example 3
Source File: ProjectStorageUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private UnableToSaveProjectNotification(@Nonnull final Project project, final Collection<File> readOnlyFiles) {
  super("Project Settings", "Could not save project!", buildMessage(), NotificationType.ERROR, new NotificationListener() {
    @Override
    public void hyperlinkUpdate(@Nonnull Notification notification, @Nonnull HyperlinkEvent event) {
      final UnableToSaveProjectNotification unableToSaveProjectNotification = (UnableToSaveProjectNotification)notification;
      final Project _project = unableToSaveProjectNotification.getProject();
      notification.expire();

      if (_project != null && !_project.isDisposed()) {
        _project.save();
      }
    }
  });

  myProject = project;
  myFileNames = ContainerUtil.map(readOnlyFiles, File::getPath);
}
 
Example 4
Source File: SettingsImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
public int getTabSize(Project project) {
  if (myTabSize != null) return myTabSize;
  if (myCachedTabSize != null) return myCachedTabSize;
  int tabSize;
  if (project == null || project.isDisposed()) {
    tabSize = CodeStyleSettingsManager.getSettings(null).getTabSize(null);
  }
  else {
    PsiFile file = getPsiFile(project);
    if (myEditor != null && myEditor.isViewer()) {
      FileType fileType = file != null ? file.getFileType() : null;
      tabSize = CodeStyleSettingsManager.getSettings(project).getIndentOptions(fileType).TAB_SIZE;
    }
    else {
      tabSize = CodeStyleSettingsManager.getSettings(project).getIndentOptionsByFile(file).TAB_SIZE;
    }
  }
  myCachedTabSize = Integer.valueOf(tabSize);
  return tabSize;
}
 
Example 5
Source File: BlazeNdkSupportEnabler.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static void doRebuildSymbols(Project project) {
  if (project.isDisposed()) {
    return;
  }
  // Notifying BuildSettingsChangeTracker in unitTestMode will leads to a dead lock.
  // See b/23087433 for more information.
  if (!ApplicationManager.getApplication().isUnitTestMode()) {
    OCWorkspaceEventImpl event =
        new OCWorkspaceEventImpl(
            /* resolveConfigurationsChanged= */ false,
            /* sourceFilesChanged= */ false,
            /* compilerSettingsChanged= */ true);
    ((OCWorkspaceModificationTrackersImpl)
            OCWorkspace.getInstance(project).getModificationTrackers())
        .fireWorkspaceChanged(event);
  }
}
 
Example 6
Source File: BaseApplication.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@Override
public void saveAll() {
  if (myDoNotSave) return;

  FileDocumentManager.getInstance().saveAllDocuments();

  Project[] openProjects = ProjectManager.getInstance().getOpenProjects();
  for (Project openProject : openProjects) {
    if (openProject.isDisposed()) {
      // debug for https://github.com/consulo/consulo/issues/296
      LOG.error("Project is disposed: " + openProject.getName() + ", isInitialized: " + openProject.isInitialized());
      continue;
    }

    ProjectEx project = (ProjectEx)openProject;
    project.save();
  }

  saveSettings();
}
 
Example 7
Source File: IdeFocusManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
static IdeFocusManager getInstanceSafe(@Nullable Project project) {
  if (project != null && !project.isDisposed() && project.isInitialized()) {
    return getInstance(project);
  }
  return null;
}
 
Example 8
Source File: FlutterSdk.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the Flutter SDK for a project that has a possibly broken "Dart SDK" project library.
 * <p>
 * (This can happen for a newly-cloned Flutter SDK where the Dart SDK is not cached yet.)
 */
@Nullable
public static FlutterSdk getIncomplete(@NotNull final Project project) {
  if (project.isDisposed()) {
    return null;
  }
  final Library lib = getDartSdkLibrary(project);
  if (lib == null) {
    return null;
  }
  return getFlutterFromDartSdkLibrary(lib);
}
 
Example 9
Source File: CodeStyle.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * Updates document's indent options from indent options providers.
 * <p><b>Note:</b> Calling this method directly when there is an editor associated with the document may cause the editor work
 * incorrectly. To keep consistency with the editor call {@code EditorEx.reinitSettings()} instead.
 *
 * @param project  The project of the document.
 * @param document The document to update indent options for.
 */
public static void updateDocumentIndentOptions(@Nonnull Project project, @Nonnull Document document) {
  if (!project.isDisposed()) {
    PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
    if (documentManager != null) {
      PsiFile file = documentManager.getPsiFile(document);
      if (file != null) {
        CommonCodeStyleSettings.IndentOptions indentOptions = getSettings(file).getIndentOptionsByFile(file, null, true, null);
        indentOptions.associateWithDocument(document);
      }
    }
  }
}
 
Example 10
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static Collection<PsiElement> getPsiElementsAt(Point point, Editor editor) {
  if (editor.isDisposed()) {
    return Collections.emptySet();
  }

  Project project = editor.getProject();
  if (project == null || project.isDisposed()) {
    return Collections.emptySet();
  }

  final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
  final Document document = editor.getDocument();
  PsiFile psiFile = documentManager.getPsiFile(document);
  if (psiFile == null || psiFile instanceof PsiCompiledElement || !psiFile.isValid()) {
    return Collections.emptySet();
  }

  final Set<PsiElement> elements = Collections.newSetFromMap(ContainerUtil.createWeakMap());
  final int offset = editor.logicalPositionToOffset(editor.xyToLogicalPosition(point));
  if (documentManager.isCommitted(document)) {
    ContainerUtil.addIfNotNull(elements, InjectedLanguageUtil.findElementAtNoCommit(psiFile, offset));
  }
  for (PsiFile file : psiFile.getViewProvider().getAllFiles()) {
    ContainerUtil.addIfNotNull(elements, file.findElementAt(offset));
  }

  return elements;
}
 
Example 11
Source File: ImageOrColorPreviewManager.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void registerListeners(final Editor editor) {
  if (editor.isOneLineMode()) {
    return;
  }

  Project project = editor.getProject();
  if (project == null || project.isDisposed()) {
    return;
  }

  PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
  if (psiFile == null || psiFile instanceof PsiCompiledElement || !isSupportedFile(psiFile)) {
    return;
  }

  editor.addEditorMouseMotionListener(this);

  KeyListener keyListener = new KeyAdapter() {
    @Override
    public void keyPressed(KeyEvent e) {
      if (e.getKeyCode() == KeyEvent.VK_SHIFT && !editor.isOneLineMode()) {
        PointerInfo pointerInfo = MouseInfo.getPointerInfo();
        if (pointerInfo != null) {
          Point location = pointerInfo.getLocation();
          SwingUtilities.convertPointFromScreen(location, editor.getContentComponent());
          alarm.cancelAllRequests();
          alarm.addRequest(new PreviewRequest(location, editor, true), 100);
        }
      }
    }
  };
  editor.getContentComponent().addKeyListener(keyListener);

  EDITOR_LISTENER_ADDED.set(editor, keyListener);
}
 
Example 12
Source File: CrudUtils.java    From crud-intellij-plugin with Apache License 2.0 5 votes vote down vote up
public static void runWhenInitialized(final Project project, final Runnable r) {
    if (project.isDisposed()) {
        return;
    }
    if (isNoBackgroundMode()) {
        r.run();
        return;
    }
    if (!project.isInitialized()) {
        StartupManager.getInstance(project).registerPostStartupActivity(DisposeAwareRunnable.create(r, project));
        return;
    }
    runDumbAware(project, r);
}
 
Example 13
Source File: FlutterSdk.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Returns the Flutter SDK for a project that has a possibly broken "Dart SDK" project library.
 * <p>
 * (This can happen for a newly-cloned Flutter SDK where the Dart SDK is not cached yet.)
 */
@Nullable
public static FlutterSdk getIncomplete(@NotNull final Project project) {
  if (project.isDisposed()) {
    return null;
  }
  final Library lib = getDartSdkLibrary(project);
  if (lib == null) {
    return null;
  }
  return getFlutterFromDartSdkLibrary(lib);
}
 
Example 14
Source File: DvcsStatusWidget.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public ListPopup getPopupStep() {
  Project project = getProject();
  if (project == null || project.isDisposed()) return null;
  T repository = guessCurrentRepository(project);
  if (repository == null) return null;

  return getPopup(project, repository);
}
 
Example 15
Source File: FlowInPlaceRenamer.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void finish() {
    ourRenamersStack.pop();
    if (this.myHighlighters != null) {
        Project project = this.myEditor.getProject();
        if (project != null && !project.isDisposed()) {
            HighlightManager highlightManager = HighlightManager.getInstance(project);
            Iterator var3 = this.myHighlighters.iterator();

            while (var3.hasNext()) {
                RangeHighlighter highlighter = (RangeHighlighter) var3.next();
                highlightManager.removeSegmentHighlighter(this.myEditor, highlighter);
            }
        }
    }
}
 
Example 16
Source File: ForwardAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void update(AnActionEvent e){
  Presentation presentation = e.getPresentation();
  Project project = e.getData(CommonDataKeys.PROJECT);
  if (project == null || project.isDisposed()) {
    presentation.setEnabled(false);
    return;
  }
  presentation.setEnabled(IdeDocumentHistory.getInstance(project).isForwardAvailable());
}
 
Example 17
Source File: FlutterModuleUtils.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * If no files are open, show lib/main.dart for the given PubRoot.
 */
public static void autoShowMain(@NotNull Project project, @NotNull PubRoot root) {
  if (project.isDisposed()) return;

  final VirtualFile main = root.getFileToOpen();
  if (main == null) return;

  DumbService.getInstance(project).runWhenSmart(() -> {
    final FileEditorManager manager = FileEditorManager.getInstance(project);
    if (manager.getAllEditors().length == 0) {
      manager.openFile(main, true);
    }
  });
}
 
Example 18
Source File: BuildFileFormatOnSaveHandler.java    From intellij with Apache License 2.0 4 votes vote down vote up
private static boolean isProjectValid(Project project) {
  return project.isInitialized() && !project.isDisposed();
}
 
Example 19
Source File: CommunicatorCommand.java    From CppTools with Apache License 2.0 4 votes vote down vote up
public void post(Project project) {
  if (project.isDisposed()) {
    return;
  }
  Communicator.getInstance(project).sendCommand(this);
}
 
Example 20
Source File: ExternalSystemTaskId.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static String getProjectId(@Nonnull Project project) {
  return project.isDisposed() ? project.getName() : project.getName() + ":" + project.getLocationHash();
}