Skip to content

Commit

Permalink
CHE-4596: close the editor if file was removed (#4911)
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Svydenko committed Apr 26, 2017
1 parent 2391754 commit cf79132
Showing 1 changed file with 21 additions and 1 deletion.
Expand Up @@ -16,6 +16,8 @@
import org.eclipse.che.api.project.shared.dto.event.FileStateUpdateDto;
import org.eclipse.che.api.project.shared.dto.event.FileWatcherEventType;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.editor.EditorAgent;
import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.resources.ExternalResourceDelta;
Expand All @@ -25,7 +27,9 @@
import org.eclipse.che.ide.util.loging.Log;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import java.util.List;

import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.SUCCESS;
Expand All @@ -44,14 +48,19 @@ public class EditorFileStatusNotificationOperation implements JsonRpcRequestBiOp

private final EventBus eventBus;
private final DeletedFilesController deletedFilesController;
private final Provider<EditorAgent> editorAgentProvider;
private final AppContext appContext;

private NotificationManager notificationManager;

@Inject
public EditorFileStatusNotificationOperation(EventBus eventBus, DeletedFilesController deletedFilesController, AppContext appContext) {
public EditorFileStatusNotificationOperation(EventBus eventBus,
DeletedFilesController deletedFilesController,
Provider<EditorAgent> editorAgentProvider,
AppContext appContext) {
this.eventBus = eventBus;
this.deletedFilesController = deletedFilesController;
this.editorAgentProvider = editorAgentProvider;
this.appContext = appContext;
}

Expand Down Expand Up @@ -88,10 +97,21 @@ public void apply(String endpointId, FileStateUpdateDto params) {
appContext.getWorkspaceRoot().synchronize(new ExternalResourceDelta(path, path, REMOVED));
if (notificationManager != null && !deletedFilesController.remove(stringPath)) {
notificationManager.notify("External operation", "File '" + name + "' is removed", SUCCESS, EMERGE_MODE);
closeOpenedEditor(path);
}

break;
}
}
}

private void closeOpenedEditor(Path path) {
final EditorAgent editorAgent = editorAgentProvider.get();
final List<EditorPartPresenter> openedEditors = editorAgent.getOpenedEditors();
for (EditorPartPresenter openEditor : openedEditors) {
if (openEditor.getEditorInput().getFile().getLocation().equals(path)) {
editorAgent.closeEditor(openEditor);
}
}
}
}

0 comments on commit cf79132

Please sign in to comment.