forked from eclipse-che/che
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CHE-3570. Add ability to turn on/off autosave mode for editor content
Signed-off-by: Roman Nikitenko <rnikitenko@codenvy.com>
- Loading branch information
1 parent
c33b208
commit 1c7818f
Showing
89 changed files
with
3,096 additions
and
477 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/autosave/AutoSaveMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.api.editor.autosave; | ||
|
||
import org.eclipse.che.ide.api.editor.document.UseDocumentHandle; | ||
import org.eclipse.che.ide.api.editor.events.DocumentChangeHandler; | ||
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; | ||
|
||
/** | ||
* Editor content auto save functionality. | ||
* | ||
* @author Roman Nikitenko | ||
*/ | ||
public interface AutoSaveMode extends DocumentChangeHandler, UseDocumentHandle { | ||
|
||
/** | ||
* Installs auto save mode on the given editor. | ||
*/ | ||
void install(TextEditor editor); | ||
|
||
/** | ||
* Removes auto save mode from editor. | ||
*/ | ||
void uninstall(); | ||
|
||
/** | ||
* Suspends auto save mode for editor content. | ||
*/ | ||
void suspend(); | ||
|
||
/** | ||
* Resumes auto save mode for editor content and sets mode corresponding to 'Enable Autosave' option in editor preferences. | ||
*/ | ||
void resume(); | ||
|
||
/** | ||
* Return true if auto save mode is activated, false otherwise. | ||
*/ | ||
boolean isActivated(); | ||
|
||
enum Mode { | ||
/** | ||
* The state when auto save mode of editor content is turned on. | ||
* Corresponds to the case when the 'Enable Autosave' option in editor preferences is enabled. | ||
*/ | ||
ACTIVATED, | ||
|
||
/** Corresponds to the state when auto save mode is suspended for processing some operations (java refactoring, for example) */ | ||
SUSPENDED, | ||
|
||
/** | ||
* The state when auto save mode of editor content is turned off. | ||
* Corresponds to the case when the 'Enable Autosave' option in editor preferences is disabled. | ||
*/ | ||
DEACTIVATED | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
...re-ide-api/src/main/java/org/eclipse/che/ide/api/editor/reconciler/DefaultReconciler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2017 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.api.editor.reconciler; | ||
|
||
import com.google.inject.assistedinject.Assisted; | ||
import com.google.inject.assistedinject.AssistedInject; | ||
|
||
import org.eclipse.che.ide.api.editor.document.Document; | ||
import org.eclipse.che.ide.api.editor.document.DocumentHandle; | ||
import org.eclipse.che.ide.api.editor.events.DocumentChangeEvent; | ||
import org.eclipse.che.ide.api.editor.partition.DocumentPartitioner; | ||
import org.eclipse.che.ide.api.editor.texteditor.TextEditor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* Default implementation of {@link Reconciler}. | ||
* | ||
* @author Roman Nikitenko | ||
*/ | ||
public class DefaultReconciler implements Reconciler { | ||
|
||
private final String partition; | ||
private final DocumentPartitioner partitioner; | ||
private final Map<String, ReconcilingStrategy> strategies; | ||
|
||
private DocumentHandle documentHandle; | ||
private TextEditor editor; | ||
|
||
|
||
@AssistedInject | ||
public DefaultReconciler(@Assisted final String partition, | ||
@Assisted final DocumentPartitioner partitioner) { | ||
this.partition = partition; | ||
this.partitioner = partitioner; | ||
strategies = new HashMap<>(); | ||
} | ||
|
||
@Override | ||
public void install(TextEditor editor) { | ||
this.editor = editor; | ||
reconcilerDocumentChanged(); | ||
} | ||
|
||
@Override | ||
public void uninstall() { | ||
strategies.values().forEach(ReconcilingStrategy::closeReconciler); | ||
} | ||
|
||
@Override | ||
public ReconcilingStrategy getReconcilingStrategy(final String contentType) { | ||
return strategies.get(contentType); | ||
} | ||
|
||
@Override | ||
public void addReconcilingStrategy(final String contentType, final ReconcilingStrategy strategy) { | ||
strategies.put(contentType, strategy); | ||
} | ||
|
||
@Override | ||
public String getDocumentPartitioning() { | ||
return partition; | ||
} | ||
|
||
@Override | ||
public void onDocumentChange(final DocumentChangeEvent event) { | ||
} | ||
|
||
@Override | ||
public DocumentHandle getDocumentHandle() { | ||
return this.documentHandle; | ||
} | ||
|
||
@Override | ||
public void setDocumentHandle(final DocumentHandle handle) { | ||
this.documentHandle = handle; | ||
} | ||
|
||
/** | ||
* Returns the input document of the text view this reconciler is installed on. | ||
* | ||
* @return the reconciler document | ||
*/ | ||
protected Document getDocument() { | ||
return documentHandle.getDocument(); | ||
} | ||
|
||
private void reconcilerDocumentChanged() { | ||
strategies.keySet().forEach(key -> { | ||
ReconcilingStrategy reconcilingStrategy = strategies.get(key); | ||
reconcilingStrategy.setDocument(documentHandle.getDocument()); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.