For this, save-and-sync handler API was extracted and used throughout the platform - including execution manager.
/*
- * Copyright 2000-2012 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package com.intellij.dvcs;
import com.intellij.ide.SaveAndSyncHandler;
-import com.intellij.ide.SaveAndSyncHandlerImpl;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.openapi.application.ApplicationManager;
@NotNull
@Override
public SaveAndSyncHandler getSaveAndSyncHandler() {
- return SaveAndSyncHandlerImpl.getInstance();
+ return SaveAndSyncHandler.getInstance();
}
@Override
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
import com.intellij.execution.ui.RunContentDescriptor;
import com.intellij.execution.ui.RunContentManager;
import com.intellij.execution.ui.RunContentManagerImpl;
+import com.intellij.ide.SaveAndSyncHandler;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.Trinity;
import com.intellij.openapi.util.text.StringUtil;
-import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.ui.docking.DockManager;
import com.intellij.util.Alarm;
import com.intellij.util.SmartList;
if (myProject.isDisposed()) return;
myProject.getMessageBus().syncPublisher(EXECUTION_TOPIC).processTerminated(myProfile, myProcessHandler);
- VirtualFileManager.getInstance().asyncRefresh(null);
+
+ SaveAndSyncHandler.getInstance().scheduleRefresh();
}
@Override
--- /dev/null
+/*
+ * Copyright 2000-2015 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.intellij.ide;
+
+import com.intellij.openapi.application.ApplicationManager;
+
+/**
+ * @author Kirill Likhodedov
+ */
+public abstract class SaveAndSyncHandler {
+ public static SaveAndSyncHandler getInstance() {
+ return ApplicationManager.getApplication().getComponent(SaveAndSyncHandler.class);
+ }
+
+ public abstract void saveProjectsAndDocuments();
+ public abstract void scheduleRefresh();
+ public abstract void refreshOpenFiles();
+
+ public abstract void blockSaveOnFrameDeactivation();
+ public abstract void unblockSaveOnFrameDeactivation();
+
+ public abstract void blockSyncOnFrameActivation();
+ public abstract void unblockSyncOnFrameActivation();
+}
+++ /dev/null
-/*
- * Copyright 2000-2012 JetBrains s.r.o.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.intellij.ide;
-
-/**
- * @author Kirill Likhodedov
- */
-public interface SaveAndSyncHandler {
-
- void blockSaveOnFrameDeactivation();
-
- void unblockSaveOnFrameDeactivation();
-
- void blockSyncOnFrameActivation();
-
- void unblockSyncOnFrameActivation();
-}
/*
- * Copyright 2000-2014 JetBrains s.r.o.
+ * Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* @author Anton Katilin
* @author Vladimir Kondratyev
*/
-public class SaveAndSyncHandlerImpl implements ApplicationComponent, SaveAndSyncHandler {
+public class SaveAndSyncHandlerImpl extends SaveAndSyncHandler implements ApplicationComponent {
private static final Logger LOG = Logger.getInstance(SaveAndSyncHandler.class);
private final Runnable myIdleListener;
private final PropertyChangeListener myGeneralSettingsListener;
+ private final GeneralSettings mySettings;
private final ProgressManager myProgressManager;
+ private final SingleAlarm myRefreshDelayAlarm;
private final AtomicInteger myBlockSaveOnFrameDeactivationCount = new AtomicInteger();
private final AtomicInteger myBlockSyncOnFrameActivationCount = new AtomicInteger();
- private final SingleAlarm myRefreshDelayAlarm = new SingleAlarm(new Runnable() {
- @Override
- public void run() {
- if (canSyncOrSave()) {
- refreshOpenFiles();
- }
- maybeRefresh(ModalityState.NON_MODAL);
- }
- }, 300);
+ private volatile long myRefreshSessionId = 0;
- private long myRefreshSessionId = 0;
-
- public static SaveAndSyncHandlerImpl getInstance() {
- return (SaveAndSyncHandlerImpl)ApplicationManager.getApplication().getComponent(SaveAndSyncHandler.class);
- }
-
- public SaveAndSyncHandlerImpl(@NotNull FrameStateManager frameStateManager,
- @NotNull final FileDocumentManager fileDocumentManager,
- @NotNull final GeneralSettings generalSettings,
- @NotNull ProgressManager progressManager) {
+ public SaveAndSyncHandlerImpl(@NotNull GeneralSettings generalSettings,
+ @NotNull ProgressManager progressManager,
+ @NotNull FrameStateManager frameStateManager,
+ @NotNull final FileDocumentManager fileDocumentManager) {
+ mySettings = generalSettings;
myProgressManager = progressManager;
myIdleListener = new Runnable() {
@Override
public void run() {
- if (generalSettings.isAutoSaveIfInactive() && canSyncOrSave()) {
+ if (mySettings.isAutoSaveIfInactive() && canSyncOrSave()) {
((FileDocumentManagerImpl)fileDocumentManager).saveAllDocuments(false);
}
}
};
-
- IdeEventQueue.getInstance().addIdleListener(myIdleListener, generalSettings.getInactiveTimeout() * 1000);
+ IdeEventQueue.getInstance().addIdleListener(myIdleListener, mySettings.getInactiveTimeout() * 1000);
myGeneralSettingsListener = new PropertyChangeListener() {
@Override
}
}
};
+ mySettings.addPropertyChangeListener(myGeneralSettingsListener);
- generalSettings.addPropertyChangeListener(myGeneralSettingsListener);
+ myRefreshDelayAlarm = new SingleAlarm(new Runnable() {
+ @Override
+ public void run() {
+ if (canSyncOrSave()) {
+ refreshOpenFiles();
+ }
+ maybeRefresh(ModalityState.NON_MODAL);
+ }
+ }, 300);
frameStateManager.addListener(new FrameStateListener() {
@Override
@Override
public void onFrameActivated() {
- if (ApplicationManager.getApplication().isDisposed() || !generalSettings.isSyncOnFrameActivation()) {
- return;
+ if (!ApplicationManager.getApplication().isDisposed() && mySettings.isSyncOnFrameActivation()) {
+ scheduleRefresh();
}
-
- LOG.debug("enter: refreshFiles()");
- myRefreshDelayAlarm.cancelAndRequest();
- LOG.debug("exit: refreshFiles()");
}
});
}
}
@Override
- public void initComponent() {
- }
+ public void initComponent() { }
@Override
public void disposeComponent() {
- GeneralSettings.getInstance().removePropertyChangeListener(myGeneralSettingsListener);
+ myRefreshDelayAlarm.cancel();
+ RefreshQueue.getInstance().cancelSession(myRefreshSessionId);
+ mySettings.removePropertyChangeListener(myGeneralSettingsListener);
IdeEventQueue.getInstance().removeIdleListener(myIdleListener);
}
return !LaterInvocator.isInModalContext() && !myProgressManager.hasModalProgressIndicator();
}
- // made public for tests
+ @Override
public void saveProjectsAndDocuments() {
- if (LOG.isDebugEnabled()) {
- LOG.debug("enter: save()");
- }
- if (ApplicationManager.getApplication().isDisposed()) return;
+ LOG.debug("enter: save()");
- if (myBlockSaveOnFrameDeactivationCount.get() == 0 && GeneralSettings.getInstance().isSaveOnFrameDeactivation()) {
+ if (!ApplicationManager.getApplication().isDisposed() &&
+ mySettings.isSaveOnFrameDeactivation() &&
+ myBlockSaveOnFrameDeactivationCount.get() == 0) {
FileDocumentManager.getInstance().saveAllDocuments();
- Project[] openProjects = ProjectManagerEx.getInstanceEx().getOpenProjects();
- for (Project project : openProjects) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("save project: " + project);
- }
+ for (Project project : ProjectManagerEx.getInstanceEx().getOpenProjects()) {
+ if (LOG.isDebugEnabled()) LOG.debug("saving project: " + project);
project.save();
}
- if (LOG.isDebugEnabled()) {
- LOG.debug("save application settings");
- }
+
+ LOG.debug("saving application settings");
ApplicationManagerEx.getApplicationEx().saveSettings();
- if (LOG.isDebugEnabled()) {
- LOG.debug("exit: save()");
- }
+
+ LOG.debug("exit: save()");
}
}
- public void maybeRefresh(@NotNull ModalityState modalityState) {
- if (myBlockSyncOnFrameActivationCount.get() == 0 && GeneralSettings.getInstance().isSyncOnFrameActivation()) {
- LOG.debug("VFS refresh started");
+ @Override
+ public void scheduleRefresh() {
+ myRefreshDelayAlarm.cancelAndRequest();
+ }
+ public void maybeRefresh(@NotNull ModalityState modalityState) {
+ if (myBlockSyncOnFrameActivationCount.get() == 0 && mySettings.isSyncOnFrameActivation()) {
RefreshQueue queue = RefreshQueue.getInstance();
queue.cancelSession(myRefreshSessionId);
session.addAllFiles(ManagingFS.getInstance().getLocalRoots());
myRefreshSessionId = session.getId();
session.launch();
-
- LOG.debug("VFS refresh finished");
}
}
- public static void refreshOpenFiles() {
+ @Override
+ public void refreshOpenFiles() {
List<VirtualFile> files = ContainerUtil.newArrayList();
+
for (Project project : ProjectManager.getInstance().getOpenProjects()) {
- VirtualFile[] projectFiles = FileEditorManager.getInstance(project).getSelectedFiles();
- for (VirtualFile file : projectFiles) {
+ for (VirtualFile file : FileEditorManager.getInstance(project).getSelectedFiles()) {
if (file instanceof NewVirtualFile) {
files.add(file);
}
*/
package com.intellij.ide.actions;
-import com.intellij.ide.SaveAndSyncHandlerImpl;
+import com.intellij.ide.SaveAndSyncHandler;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.fileEditor.FileDocumentManager;
@Override
public void actionPerformed(AnActionEvent e) {
FileDocumentManager.getInstance().saveAllDocuments();
-
- SaveAndSyncHandlerImpl.refreshOpenFiles();
-
+ SaveAndSyncHandler.getInstance().refreshOpenFiles();
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
}
}
import com.intellij.icons.AllIcons;
import com.intellij.ide.IdeEventQueue;
+import com.intellij.ide.SaveAndSyncHandler;
import com.intellij.ide.SaveAndSyncHandlerImpl;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.ide.util.treeView.NodeRenderer;
.subscribe(ApplicationActivationListener.TOPIC, new ApplicationActivationListener.Adapter() {
@Override
public void applicationActivated(IdeFrame ideFrame) {
- SaveAndSyncHandlerImpl.getInstance().maybeRefresh(ModalityState.current());
+ ((SaveAndSyncHandlerImpl)SaveAndSyncHandler.getInstance()).maybeRefresh(ModalityState.current());
}
});
import com.intellij.execution.RunContentExecutor;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.ProcessHandler;
-import com.intellij.ide.SaveAndSyncHandlerImpl;
import com.intellij.lang.Language;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.editor.colors.EditorColors;
-import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.fileEditor.FileEditor;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.openapi.vfs.VirtualFileManager;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.JBColor;
import com.intellij.util.ui.UIUtil;
getToolWindow(StudyToolWindowFactory.STUDY_TOOL_WINDOW));
}
- public static void synchronize() {
- FileDocumentManager.getInstance().saveAllDocuments();
- SaveAndSyncHandlerImpl.refreshOpenFiles();
- VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
- }
-
public static void deleteFile(@NotNull final VirtualFile file) {
try {
file.delete(StudyUtils.class);
import com.intellij.ui.tabs.impl.JBEditorTabs;
import com.intellij.util.PlatformIcons;
import com.jetbrains.edu.EduNames;
+import com.jetbrains.edu.EduUtils;
import com.jetbrains.edu.courseFormat.Task;
import com.jetbrains.edu.courseFormat.TaskFile;
import com.jetbrains.edu.learning.StudyTaskManager;
finally {
StudyUtils.closeSilently(printWriter);
}
- StudyUtils.synchronize();
+ EduUtils.synchronize();
}
private static UserTest createUserTest(@NotNull final VirtualFile testsDir,
File testInputFile = new File(userTest.getInput());
File testOutputFile = new File(userTest.getOutput());
if (testInputFile.delete() && testOutputFile.delete()) {
- StudyUtils.synchronize();
+ EduUtils.synchronize();
} else {
LOG.error("failed to delete user tests");
}
package com.jetbrains.edu;
-import com.intellij.ide.SaveAndSyncHandlerImpl;
+import com.intellij.ide.SaveAndSyncHandler;
import com.intellij.ide.projectView.actions.MarkRootActionBase;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.Presentation;
public static void synchronize() {
FileDocumentManager.getInstance().saveAllDocuments();
- SaveAndSyncHandlerImpl.refreshOpenFiles();
+ SaveAndSyncHandler.getInstance().refreshOpenFiles();
VirtualFileManager.getInstance().refreshWithoutFileWatcher(true);
}