Java Code Examples for com.intellij.openapi.application.TransactionGuard#submitTransaction()

The following examples show how to use com.intellij.openapi.application.TransactionGuard#submitTransaction() . 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: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void initPre41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //registerComponents();
    Method method = ReflectionUtil.getDeclaredMethod(ProjectImpl.class, "registerComponents");
    assert (method != null);
    try {
      method.invoke(this);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    getStateStore().setPath(path, true, null);
    super.init(indicator);
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example 2
Source File: ExecutionPointHighlighter.java    From consulo with Apache License 2.0 6 votes vote down vote up
public void show(final @Nonnull XSourcePosition position, final boolean notTopFrame, @Nullable final GutterIconRenderer gutterIconRenderer) {
  updateRequested.set(false);
  TransactionGuard.submitTransaction(myProject, () -> {
    updateRequested.set(false);

    mySourcePosition = position;

    clearDescriptor();
    myOpenFileDescriptor = XSourcePositionImpl.createOpenFileDescriptor(myProject, position);
    if (!XDebuggerSettingManagerImpl.getInstanceImpl().getGeneralSettings().isScrollToCenter()) {
      myOpenFileDescriptor.setScrollType(notTopFrame ? ScrollType.CENTER : ScrollType.MAKE_VISIBLE);
    }
    //see IDEA-125645 and IDEA-63459
    //myOpenFileDescriptor.setUseCurrentWindow(true);

    myGutterIconRenderer = gutterIconRenderer;
    myNotTopFrame = notTopFrame;

    doShow(true);
  });
}
 
Example 3
Source File: RoutesManager.java    From railways with MIT License 6 votes vote down vote up
/**
 * Updates route list. The method starts task that call 'rake routes' and parses result after complete.
 * After routes are parsed, Routes panel is updated.
 *
 * @return True if update task is started, false if new task is not started because routes update is in progress.
 */
public boolean updateRouteList() {
    if (isUpdating())
        return false;

    setState(UPDATING);

    // Save all documents to make sure that requestMethods will be collected using actual files.
    TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> {
        FileDocumentManager.getInstance().saveAllDocuments();

        // Start background task.
        (new UpdateRoutesTask()).queue();
    });

    return true;
}
 
Example 4
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void init41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //ProjectManagerImpl.initProject(path, this, true, null, null);
    Method method = ReflectionUtil
      .getDeclaredMethod(ProjectManagerImpl.class, "initProject", Path.class, ProjectImpl.class, boolean.class, Project.class,
                         ProgressIndicator.class);
    assert (method != null);
    try {
      method.invoke(null, path, this, true, null, null);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example 5
Source File: BlazeCWorkspace.java    From intellij with Apache License 2.0 6 votes vote down vote up
/**
 * Notifies the workspace of changes in inputs to the resolve configuration. See {@link
 * com.jetbrains.cidr.lang.workspace.OCWorkspaceListener.OCWorkspaceEvent}.
 */
private void incModificationTrackers() {
  TransactionGuard.submitTransaction(
      project,
      () -> {
        if (project.isDisposed()) {
          return;
        }
        OCWorkspaceEventImpl event =
            new OCWorkspaceEventImpl(
                /* resolveConfigurationsChanged= */ true,
                /* sourceFilesChanged= */ true,
                /* compilerSettingsChanged= */ true);
        ((OCWorkspaceModificationTrackersImpl)
                OCWorkspace.getInstance(project).getModificationTrackers())
            .fireWorkspaceChanged(event);
      });
}
 
Example 6
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final AnAction action = ActionManager.getInstance().getAction("Flutter.ExtractWidget");
  if (action != null) {
    TransactionGuard.submitTransaction(project, () -> {
      final Editor editor = getCurrentEditor();
      if (editor == null) {
        // It is a race condition if we hit this. Gracefully assume
        // the action has just been canceled.
        return;
      }
      final JComponent editorComponent = editor.getComponent();
      final DataContext editorContext = DataManager.getInstance().getDataContext(editorComponent);
      final AnActionEvent editorEvent = AnActionEvent.createFromDataContext(ActionPlaces.UNKNOWN, null, editorContext);

      action.actionPerformed(editorEvent);
    });
  }
}
 
Example 7
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final AnAction action = ActionManager.getInstance().getAction("ExtractMethod");
  if (action != null) {
    final FlutterOutline outline = getWidgetOutline();
    if (outline != null) {
      TransactionGuard.submitTransaction(project, () -> {
        final Editor editor = getCurrentEditor();
        if (editor == null) {
          // It is a race condition if we hit this. Gracefully assume
          // the action has just been canceled.
          return;
        }
        final OutlineOffsetConverter converter = new OutlineOffsetConverter(project, activeFile.getValue());
        final int offset = converter.getConvertedOutlineOffset(outline);
        editor.getCaretModel().moveToOffset(offset);

        final JComponent editorComponent = editor.getComponent();
        final DataContext editorContext = DataManager.getInstance().getDataContext(editorComponent);
        final AnActionEvent editorEvent = AnActionEvent.createFromDataContext(ActionPlaces.UNKNOWN, null, editorContext);

        action.actionPerformed(editorEvent);
      });
    }
  }
}
 
Example 8
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final AnAction action = ActionManager.getInstance().getAction("Flutter.ExtractWidget");
  if (action != null) {
    TransactionGuard.submitTransaction(project, () -> {
      final Editor editor = getCurrentEditor();
      if (editor == null) {
        // It is a race condition if we hit this. Gracefully assume
        // the action has just been canceled.
        return;
      }
      final JComponent editorComponent = editor.getComponent();
      final DataContext editorContext = DataManager.getInstance().getDataContext(editorComponent);
      final AnActionEvent editorEvent = AnActionEvent.createFromDataContext(ActionPlaces.UNKNOWN, null, editorContext);

      action.actionPerformed(editorEvent);
    });
  }
}
 
Example 9
Source File: WidgetEditToolbar.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
  final AnAction action = ActionManager.getInstance().getAction("ExtractMethod");
  if (action != null) {
    final FlutterOutline outline = getWidgetOutline();
    if (outline != null) {
      TransactionGuard.submitTransaction(project, () -> {
        final Editor editor = getCurrentEditor();
        if (editor == null) {
          // It is a race condition if we hit this. Gracefully assume
          // the action has just been canceled.
          return;
        }
        final OutlineOffsetConverter converter = new OutlineOffsetConverter(project, activeFile.getValue());
        final int offset = converter.getConvertedOutlineOffset(outline);
        editor.getCaretModel().moveToOffset(offset);

        final JComponent editorComponent = editor.getComponent();
        final DataContext editorContext = DataManager.getInstance().getDataContext(editorComponent);
        final AnActionEvent editorEvent = AnActionEvent.createFromDataContext(ActionPlaces.UNKNOWN, null, editorContext);

        action.actionPerformed(editorEvent);
      });
    }
  }
}
 
Example 10
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void initPre41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //registerComponents();
    Method method = ReflectionUtil.getDeclaredMethod(ProjectImpl.class, "registerComponents");
    assert (method != null);
    try {
      method.invoke(this);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    getStateStore().setPath(path, true, null);
    super.init(indicator);
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example 11
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void init41(@Nullable ProgressIndicator indicator) {
  boolean finished = false;
  try {
    //ProjectManagerImpl.initProject(path, this, true, null, null);
    Method method = ReflectionUtil
      .getDeclaredMethod(ProjectManagerImpl.class, "initProject", Path.class, ProjectImpl.class, boolean.class, Project.class,
                         ProgressIndicator.class);
    assert (method != null);
    try {
      method.invoke(null, path, this, true, null, null);
    }
    catch (IllegalAccessException | InvocationTargetException e) {
      throw new RuntimeException(e);
    }
    finished = true;
  }
  finally {
    if (!finished) {
      TransactionGuard.submitTransaction(this, () -> WriteAction.run(() -> Disposer.dispose(this)));
    }
  }
}
 
Example 12
Source File: PrefetchIndexingTask.java    From intellij with Apache License 2.0 5 votes vote down vote up
public static Future<?> submitPrefetchingTaskAndWait(
    Project project, Future<?> task, String taskName) {
  TransactionGuard.submitTransaction(
      project,
      () -> DumbService.getInstance(project).queueTask(new PrefetchIndexingTask(task, taskName)));
  return task;
}
 
Example 13
Source File: EncodingProjectManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static Processor<VirtualFile> createChangeCharsetProcessor() {
  return file -> {
    if (!(file instanceof VirtualFileSystemEntry)) return false;
    Document cachedDocument = FileDocumentManager.getInstance().getCachedDocument(file);
    if (cachedDocument == null) return true;
    ProgressManager.progress("Reloading files...", file.getPresentableUrl());
    TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> clearAndReload(file));
    return true;
  };
}
 
Example 14
Source File: ActionMenuItem.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * We have to make this method public to allow BegMenuItemUI to invoke it.
 */
@Override
public void fireActionPerformed(final ActionEvent event) {
  TransactionGuard.submitTransaction(ApplicationManager.getApplication(), new Runnable() {
    @Override
    public void run() {
      ActionMenuItem.super.fireActionPerformed(event);
    }
  });
}
 
Example 15
Source File: ConsoleExecutionEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void focusGained(@Nonnull Editor editor) {
  myCurrentEditor = (EditorEx)editor;
  if (GeneralSettings.getInstance().isSaveOnFrameDeactivation()) {
    TransactionGuard.submitTransaction(ConsoleExecutionEditor.this, () -> FileDocumentManager.getInstance().saveAllDocuments()); // PY-12487
  }
}
 
Example 16
Source File: ShowUsagesAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void appendMoreUsages(Editor editor,
                              @Nonnull RelativePoint popupPosition,
                              @Nonnull FindUsagesHandler handler,
                              int maxUsages,
                              @Nonnull FindUsagesOptions options) {
  TransactionGuard.submitTransaction(handler.getProject(), () -> showElementUsages(editor, popupPosition, handler, maxUsages + getUsagesPageSize(), options));
}
 
Example 17
Source File: DesktopSaveAndSyncHandlerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Inject
public DesktopSaveAndSyncHandlerImpl(@Nonnull GeneralSettings generalSettings,
                                     @Nonnull ProgressManager progressManager,
                                     @Nonnull FrameStateManager frameStateManager,
                                     @Nonnull FileDocumentManager fileDocumentManager) {
  mySettings = generalSettings;
  myProgressManager = progressManager;

  myIdleListener = () -> {
    if (mySettings.isAutoSaveIfInactive() && canSyncOrSave()) {
      TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> ((FileDocumentManagerImpl)fileDocumentManager).saveAllDocuments(false));
    }
  };
  IdeEventQueue.getInstance().addIdleListener(myIdleListener, mySettings.getInactiveTimeout() * 1000);

  myGeneralSettingsListener = new PropertyChangeListener() {
    @Override
    public void propertyChange(@Nonnull PropertyChangeEvent e) {
      if (GeneralSettings.PROP_INACTIVE_TIMEOUT.equals(e.getPropertyName())) {
        IdeEventQueue eventQueue = IdeEventQueue.getInstance();
        eventQueue.removeIdleListener(myIdleListener);
        Integer timeout = (Integer)e.getNewValue();
        eventQueue.addIdleListener(myIdleListener, timeout.intValue() * 1000);
      }
    }
  };
  mySettings.addPropertyChangeListener(myGeneralSettingsListener);

  frameStateManager.addListener(new FrameStateListener() {
    @Override
    public void onFrameDeactivated() {
      LOG.debug("save(): enter");
      TransactionGuard.submitTransaction(ApplicationManager.getApplication(), () -> {
        if (canSyncOrSave()) {
          saveProjectsAndDocuments();
        }
        LOG.debug("save(): exit");
      });
    }

    @Override
    public void onFrameActivated() {
      if (!ApplicationManager.getApplication().isDisposed() && mySettings.isSyncOnFrameActivation()) {
        scheduleRefresh();
      }
    }
  });
}
 
Example 18
Source File: CompileStepBeforeRun.java    From consulo with Apache License 2.0 4 votes vote down vote up
static AsyncResult<Void> doMake(UIAccess uiAccess, final Project myProject, final RunConfiguration configuration, final boolean ignoreErrors) {
  if (!(configuration instanceof RunProfileWithCompileBeforeLaunchOption)) {
    return AsyncResult.rejected();
  }

  if (configuration instanceof RunConfigurationBase && ((RunConfigurationBase)configuration).excludeCompileBeforeLaunchOption()) {
    return AsyncResult.resolved();
  }

  final RunProfileWithCompileBeforeLaunchOption runConfiguration = (RunProfileWithCompileBeforeLaunchOption)configuration;
  AsyncResult<Void> result = AsyncResult.undefined();
  try {
    final CompileStatusNotification callback = (aborted, errors, warnings, compileContext) -> {
      if ((errors == 0 || ignoreErrors) && !aborted) {
        result.setDone();
      }
      else {
        result.setRejected();
      }
    };

    TransactionGuard.submitTransaction(myProject, () -> {
      CompileScope scope;
      final CompilerManager compilerManager = CompilerManager.getInstance(myProject);
      if (Comparing.equal(Boolean.TRUE.toString(), System.getProperty(MAKE_PROJECT_ON_RUN_KEY))) {
        // user explicitly requested whole-project make
        scope = compilerManager.createProjectCompileScope();
      }
      else {
        final Module[] modules = runConfiguration.getModules();
        if (modules.length > 0) {
          for (Module module : modules) {
            if (module == null) {
              LOG.error("RunConfiguration should not return null modules. Configuration=" + runConfiguration.getName() + "; class=" + runConfiguration.getClass().getName());
            }
          }
          scope = compilerManager.createModulesCompileScope(modules, true);
        }
        else {
          scope = compilerManager.createProjectCompileScope();
        }
      }

      if (!myProject.isDisposed()) {
        compilerManager.make(scope, callback);
      }
      else {
        result.setRejected();
      }
    });
  }
  catch (Exception e) {
    result.rejectWithThrowable(e);
  }

  return result;
}
 
Example 19
Source File: ShowAutoImportPass.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public void doApplyInformationToEditor() {
  TransactionGuard.submitTransaction(myProject, this::showImports);
}
 
Example 20
Source File: Transactions.java    From intellij with Apache License 2.0 4 votes vote down vote up
public static void submitTransaction(Disposable disposable, Runnable runnable) {
  TransactionGuard.submitTransaction(disposable, runnable);
}