Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-4596: close the editor if file was removed #4911

Merged
merged 2 commits into from
Apr 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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);
}
}
}
}