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-3570. Add ability to turn on/off autosave mode for editor content #5170

Merged
merged 1 commit into from
May 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.IsWidget;

import org.eclipse.che.ide.api.parts.AbstractPartPresenter;
import org.eclipse.che.ide.api.editor.EditorAgent.OpenEditorCallback;
import org.eclipse.che.ide.api.parts.AbstractPartPresenter;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public interface EditorAgent {
*
* @param callback
*/
void saveAll(AsyncCallback callback);
void saveAll(AsyncCallback<Void> callback);

/**
* Current active editor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ public interface EditorLocalizationConstants extends Messages {
@DefaultMessage("Soft Wrap")
String propertySoftWrap();

@DefaultMessage("Enable Autosave")
String propertyAutoSave();

@DefaultMessage("Autopair (Parentheses)")
String propertyAutoPairParentheses();

Expand Down
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.google.inject.Inject;

import org.eclipse.che.ide.api.editor.EditorProvider;
import org.eclipse.che.ide.api.editor.editorconfig.AutoSaveTextEditorConfiguration;
import org.eclipse.che.ide.api.editor.editorconfig.DefaultTextEditorConfiguration;
import org.eclipse.che.ide.api.editor.editorconfig.TextEditorConfiguration;
import org.eclipse.che.ide.api.editor.texteditor.TextEditor;
import org.eclipse.che.ide.util.loging.Log;
Expand All @@ -25,7 +25,7 @@
* implementation for the {@link #getId()} and {@link #getDescription()} methods.
* <p>The method {@link #getEditor()} returns {@link TextEditor}
* that is initialized by configuration returned by {@link #getEditorConfiguration()} method.
* <p>The method {@link #getEditorConfiguration()} returns {@link AutoSaveTextEditorConfiguration}
* <p>The method {@link #getEditorConfiguration()} returns {@link DefaultTextEditorConfiguration}
* instance and may be overridden in order to provide another configuration for the editor
* which is returned by {@link #getEditor()} method.
*
Expand All @@ -38,7 +38,7 @@ public abstract class AbstractTextEditorProvider implements EditorProvider {

/** Returns configuration for initializing an editor returned by {@link #getEditor()} method. */
protected TextEditorConfiguration getEditorConfiguration() {
return new AutoSaveTextEditorConfiguration();
return new DefaultTextEditorConfiguration();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/**
* @author Evgen Vidolob
*/
public class AutoSaveTextEditorConfiguration extends DefaultTextEditorConfiguration{
public class AutoSaveTextEditorConfiguration extends DefaultTextEditorConfiguration {

private ReconcilerWithAutoSave reconcilerWithAutoSave =
new ReconcilerWithAutoSave(DocumentPartitioner.DEFAULT_CONTENT_TYPE, getPartitioner());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,20 @@
import org.eclipse.che.ide.api.editor.partition.DocumentPartitioner;
import org.eclipse.che.ide.api.editor.partition.DocumentPositionMap;
import org.eclipse.che.ide.api.editor.quickfix.QuickAssistProcessor;
import org.eclipse.che.ide.api.editor.reconciler.DefaultReconciler;
import org.eclipse.che.ide.api.editor.reconciler.Reconciler;
import org.eclipse.che.ide.api.editor.signature.SignatureHelpProvider;

import java.util.Map;

import static org.eclipse.che.ide.api.editor.partition.DocumentPartitioner.DEFAULT_CONTENT_TYPE;

/**
* Default implementation of the {@link TextEditorConfiguration}.
*/
public class DefaultTextEditorConfiguration implements TextEditorConfiguration {

private DefaultReconciler reconciler;
private ConstantPartitioner partitioner;

@Override
Expand All @@ -47,15 +51,13 @@ public Map<String, CodeAssistProcessor> getContentAssistantProcessors() {

@Override
public Reconciler getReconciler() {
return null;
return reconciler == null ? reconciler = new DefaultReconciler(DEFAULT_CONTENT_TYPE, getPartitioner()) : reconciler;

}

@Override
public DocumentPartitioner getPartitioner() {
if(partitioner == null) {
partitioner = new ConstantPartitioner();
}
return partitioner;
return partitioner == null ? partitioner = new ConstantPartitioner() : partitioner;
}

@Override
Expand Down
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());
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import java.util.List;

/**
* Queue used by {@link ReconcilerWithAutoSave} to manage dirty regions. When a dirty region is inserted into the queue, the queue tries to fold it
* Queue used to manage dirty regions. When a dirty region is inserted into the queue, the queue tries to fold it
* into the neighboring dirty region.
*/
class DirtyRegionQueue {
public class DirtyRegionQueue {

/** The list of dirty regions. */
private final List<DirtyRegion> fDirtyRegions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
* A reconciling strategy is used by an reconciler to reconcile a model
* based on text of a particular content type.
*
* @author <a href="mailto:evidolob@exoplatform.com">Evgen Vidolob</a>
* @version $Id:
* @author Evgen Vidolob
*/
public interface ReconcilingStrategy {
/**
Expand All @@ -38,7 +37,7 @@ public interface ReconcilingStrategy {
* As a dirty region might span multiple content types, the segment of the
* dirty region which should be investigated is also provided to this
* reconciling strategy. The given regions refer to the document passed into
* the most recent call of {@link #setDocument(org.eclipse.che.ide.api.editor.document.Document)}.
* the most recent call of {@link #setDocument(Document)}.
*
* @param dirtyRegion
* the document region which has been changed
Expand All @@ -50,7 +49,7 @@ public interface ReconcilingStrategy {
/**
* Activates non-incremental reconciling. The reconciling strategy is just told
* that there are changes and that it should reconcile the given partition of the
* document most recently passed into {@link #setDocument(org.eclipse.che.ide.api.editor.document.Document)}.
* document most recently passed into {@link #setDocument(Document)}.
*
* @param partition
* the document partition to be reconciled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.che.ide.api.parts;

import com.google.gwt.event.dom.client.DoubleClickHandler;

import org.eclipse.che.ide.api.editor.EditorPartPresenter;
import org.eclipse.che.ide.api.mvp.View;
import org.eclipse.che.ide.api.parts.PartStackView.TabItem;
Expand Down Expand Up @@ -54,6 +52,14 @@ public interface EditorTab extends View<EditorTab.ActionDelegate>, TabItem {
*/
EditorPartPresenter getRelativeEditorPart();

/**
* Set unsaved data mark to editor tab item.
*
* @param hasUnsavedData
* true if tab should display 'unsaved data' mark, otherwise false
*/
void setUnsavedDataMark(boolean hasUnsavedData);

/**
* Set pin mark to editor tab item.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.google.common.base.Optional;

import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.resources.Project.ProjectRequest;
import org.eclipse.che.ide.api.resources.marker.Marker;
Expand Down Expand Up @@ -478,6 +479,7 @@ public interface Resource extends Comparable<Resource> {
* @return the bound instance of {@link Project} or null
* @since 5.1.0
*/
@Nullable
Project getProject();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.che.ide.api.resources;

import com.google.common.annotations.Beta;

import org.eclipse.che.api.promises.client.Promise;
import org.eclipse.che.ide.resource.Path;

Expand Down
Loading