Skip to content

Commit 22fecf2

Browse files
CHE-4998: Update modification stamp on open and on update document.
Signed-off-by: Aleksandr Andriienko <oandriie@redhat.com>
1 parent 8049320 commit 22fecf2

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/resources/ModificationTracker.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ public interface ModificationTracker {
3030
* @return modification tracker value
3131
*/
3232
String getModificationStamp();
33+
34+
/**
35+
* Update modification tracker value by content. Modification tracker is a value is changed by any modification of the content
36+
* of the file.
37+
*
38+
* @param content actual file content
39+
*/
40+
void updateModificationStamp(String content);
3341
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/resources/impl/FileImpl.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public String getNameWithoutExtension() {
110110
/** {@inheritDoc} */
111111
@Override
112112
public Promise<Void> updateContent(String content) {
113-
setModificationStamp(TextUtils.md5(content));
113+
updateModificationStamp(content);
114114

115115
return resourceManager.write(this, content);
116116
}
@@ -140,4 +140,9 @@ public void setModificationStamp(String modificationStamp) {
140140
public String getModificationStamp() {
141141
return modificationStamp;
142142
}
143+
144+
@Override
145+
public void updateModificationStamp(String content) {
146+
this.modificationStamp = TextUtils.md5(content);
147+
}
143148
}

ide/che-core-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionDocument.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import com.google.web.bindery.event.shared.HandlerRegistration;
1414

15+
import org.eclipse.che.ide.api.resources.File;
16+
import org.eclipse.che.ide.api.resources.VirtualFile;
1517
import org.eclipse.che.ide.editor.orion.client.jso.ModelChangedEventOverlay;
1618
import org.eclipse.che.ide.editor.orion.client.jso.OrionEditorOverlay;
1719
import org.eclipse.che.ide.editor.orion.client.jso.OrionPixelPositionOverlay;
@@ -197,6 +199,7 @@ public int pixelToOffset(PixelCoordinates coordinates) {
197199

198200
public void replace(int offset, int length, String text) {
199201
this.editorOverlay.getModel().setText(text, offset, offset + length);
202+
updateModificationTimeStamp();
200203
}
201204

202205
@Override
@@ -205,6 +208,14 @@ public void replace(int startLine, int startChar, int endLine, int endChar, Stri
205208
int lineStart = model.getLineStart(startLine);
206209
int lineEnd = model.getLineStart(endLine);
207210
editorOverlay.setText(text, lineStart + startChar, lineEnd + endChar);
211+
updateModificationTimeStamp();
212+
}
213+
214+
private void updateModificationTimeStamp() {
215+
VirtualFile file = this.getFile();
216+
if (file instanceof File) {
217+
((File)file).updateModificationStamp(editorOverlay.getText());
218+
}
208219
}
209220

210221
public int getContentsCharCount() {

ide/che-core-orion-editor/src/main/java/org/eclipse/che/ide/editor/orion/client/OrionEditorPresenter.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,13 @@ public void initialized(EditorWidget widget) {
10141014
editorView.setEditorWidget(editorWidget);
10151015

10161016
document = editorWidget.getDocument();
1017-
document.setFile(input.getFile());
1017+
final VirtualFile file = input.getFile();
1018+
document.setFile(file);
1019+
1020+
if (file instanceof File) {
1021+
((File)file).updateModificationStamp(content);
1022+
}
1023+
10181024
cursorModel = new OrionCursorModel(document);
10191025

10201026
editorWidget.setTabSize(configuration.getTabWidth());
@@ -1031,7 +1037,7 @@ public void initialized(EditorWidget widget) {
10311037
if (delayedFocus) {
10321038
editorWidget.refresh();
10331039
editorWidget.setFocus();
1034-
setSelection(new Selection<>(input.getFile()));
1040+
setSelection(new Selection<>(file));
10351041
delayedFocus = false;
10361042
}
10371043

wsagent/che-core-api-project/src/main/java/org/eclipse/che/api/vfs/impl/file/event/detectors/EditorFileTracker.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ private Consumer<String> getDeleteConsumer(String endpointId, String path) {
202202
@Override
203203
public void run() {
204204
if (!Files.exists(FileWatcherUtils.toNormalPath(root.toPath(), it))) {
205+
hashRegistry.remove(path + endpointId);
205206
FileStateUpdateDto params = newDto(FileStateUpdateDto.class).withPath(path).withType(DELETED);
206207
transmitter.newRequest()
207208
.endpointId(endpointId)

0 commit comments

Comments
 (0)