Skip to content

Commit fe005f3

Browse files
authored
Add git changes markers to the editor (eclipse-che#6054)
1 parent c364856 commit fe005f3

40 files changed

Lines changed: 1543 additions & 177 deletions

File tree

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/gutter/Gutter.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,20 @@ public interface Gutter {
2323
*/
2424
void addGutterItem(int line, String gutterId, Element element);
2525

26+
/**
27+
* Adds a gutter item.
28+
*
29+
* @param lineStart the first line of the item
30+
* @param lineEnd the last line of the item
31+
* @param gutterId the gutter identifier
32+
* @param element the (DOM) element to add
33+
*/
34+
default void addGutterItem(int lineStart, int lineEnd, String gutterId, Element element) {
35+
for (int i = lineStart; i <= lineEnd; i++) {
36+
addGutterItem(i, gutterId, element);
37+
}
38+
}
39+
2640
/**
2741
* Adds a gutter item.
2842
*

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/editor/gutter/Gutters.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ private Gutters() {}
1717
/** Logical identifer for the breakpoints gutter. */
1818
public static final String BREAKPOINTS_GUTTER = "breakpoints";
1919

20+
/** Logical identifer for the vcs change markers gutter. */
21+
public static final String VCS_CHANGE_MARKERS_GUTTER = "vcsChangeMarkersGutter";
22+
2023
/** Logical identifer for the line number gutter. */
2124
public static final String LINE_NUMBERS_GUTTER = "lineNumbers";
2225

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClient.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.eclipse.che.api.git.shared.BranchListMode;
1717
import org.eclipse.che.api.git.shared.CheckoutRequest;
1818
import org.eclipse.che.api.git.shared.DiffType;
19+
import org.eclipse.che.api.git.shared.EditedRegion;
1920
import org.eclipse.che.api.git.shared.LogResponse;
2021
import org.eclipse.che.api.git.shared.MergeResult;
2122
import org.eclipse.che.api.git.shared.PullResponse;
@@ -286,6 +287,14 @@ Promise<String> diff(
286287
String commitA,
287288
boolean cached);
288289

290+
/**
291+
* Get list of edited regions (insertions, modifications, removals) of the file.
292+
*
293+
* @param project project (root of GIT repository)
294+
* @param filePath path to the file
295+
*/
296+
Promise<List<EditedRegion>> getEditedRegions(Path project, Path filePath);
297+
289298
/**
290299
* Get the file content from specified revision or branch.
291300
*

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/git/GitServiceClientImpl.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.eclipse.che.api.git.shared.CloneRequest;
3333
import org.eclipse.che.api.git.shared.CommitRequest;
3434
import org.eclipse.che.api.git.shared.DiffType;
35+
import org.eclipse.che.api.git.shared.EditedRegion;
3536
import org.eclipse.che.api.git.shared.FetchRequest;
3637
import org.eclipse.che.api.git.shared.LogResponse;
3738
import org.eclipse.che.api.git.shared.MergeRequest;
@@ -76,6 +77,7 @@ public class GitServiceClientImpl implements GitServiceClient {
7677
private static final String COMMIT = "/git/commit";
7778
private static final String CONFIG = "/git/config";
7879
private static final String DIFF = "/git/diff";
80+
private static final String EDITS = "/git/edits";
7981
private static final String FETCH = "/git/fetch";
8082
private static final String INIT = "/git/init";
8183
private static final String LOG = "/git/log";
@@ -440,6 +442,20 @@ public Promise<String> diff(
440442
.send(new StringUnmarshaller());
441443
}
442444

445+
@Override
446+
public Promise<List<EditedRegion>> getEditedRegions(Path project, Path filePath) {
447+
String url =
448+
getWsAgentBaseUrl()
449+
+ EDITS
450+
+ "?projectPath="
451+
+ encodePath(project)
452+
+ "&filePath="
453+
+ encodePath(filePath);
454+
return asyncRequestFactory
455+
.createGetRequest(url)
456+
.send(dtoUnmarshallerFactory.newListUnmarshaller(EditedRegion.class));
457+
}
458+
443459
private AsyncRequest diff(
444460
Path project,
445461
List<String> fileFilter,

ide/che-core-ide-api/src/main/java/org/eclipse/che/ide/api/theme/Theme.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,12 @@ public interface Theme {
15501550

15511551
String vcsStatusUntrackedColor();
15521552

1553+
String vcsChangeMarkerInsertionColor();
1554+
1555+
String vcsChangeMarkerModificationColor();
1556+
1557+
String vcsChangeMarkerDeletionColor();
1558+
15531559
String editorPreferenceCategoryBackgroundColor();
15541560

15551561
/**
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.ide.api.vcs;
12+
13+
/** Indicates that the editor can handle VCS change markers. */
14+
public interface HasVcsChangeMarkerRender {
15+
16+
/** Returns an instance of {@link VcsChangeMarkerRender}. */
17+
VcsChangeMarkerRender getVcsChangeMarkersRender();
18+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.ide.api.vcs;
12+
13+
import org.eclipse.che.api.git.shared.EditedRegionType;
14+
15+
/** Component that handles VCS change markers. */
16+
public interface VcsChangeMarkerRender {
17+
18+
/**
19+
* Add change marker to the gutter on the given lines.
20+
*
21+
* @param lineStart the first line number of the marker
22+
* @param lineEnd the last line number of the marker
23+
* @param type type of the marker e.g. insertion, modification, deletion
24+
*/
25+
void addChangeMarker(int lineStart, int lineEnd, EditedRegionType type);
26+
27+
/** Clear all VCS change markers in the gutter. */
28+
void clearAllChangeMarkers();
29+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2012-2017 Red Hat, Inc.
3+
* All rights reserved. This program and the accompanying materials
4+
* are made available under the terms of the Eclipse Public License v1.0
5+
* which accompanies this distribution, and is available at
6+
* http://www.eclipse.org/legal/epl-v10.html
7+
*
8+
* Contributors:
9+
* Red Hat, Inc. - initial API and implementation
10+
*/
11+
package org.eclipse.che.ide.api.vcs;
12+
13+
import org.eclipse.che.ide.api.editor.gutter.Gutter;
14+
15+
/**
16+
* Factory for {@link VcsChangeMarkerRender} instances.
17+
*
18+
* @author Igor Vinokur
19+
*/
20+
public interface VcsChangeMarkerRenderFactory {
21+
/**
22+
* Creates an instance of {@link VcsChangeMarkerRender}.
23+
*
24+
* @param hasGutter the gutter manager
25+
*/
26+
VcsChangeMarkerRender create(Gutter hasGutter);
27+
}

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/editor/EditorAgentImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ public void onEditorOpened(EditorPartPresenter editor) {
345345
removeFromOpeningFilesList(file.getLocation(), editorPartStack);
346346

347347
openEditorCallback.onEditorOpened(editor);
348+
349+
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
348350
}
349351

350352
@Override
@@ -381,7 +383,6 @@ private void finalizeInit(
381383
}
382384

383385
eventBus.fireEvent(FileEvent.createFileOpenedEvent(file));
384-
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
385386
}
386387
});
387388
}
@@ -742,6 +743,8 @@ public void onEditorOpened(EditorPartPresenter editor) {
742743

743744
promiseCallback.onSuccess(null);
744745
openEditorCallback.onEditorOpened(editor);
746+
747+
eventBus.fireEvent(new EditorOpenedEvent(file, editor));
745748
}
746749

747750
@Override

ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/theme/DarkTheme.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,21 @@ public String vcsStatusUntrackedColor() {
16321632
return "#e0b91d";
16331633
}
16341634

1635+
@Override
1636+
public String vcsChangeMarkerInsertionColor() {
1637+
return "rgba(114, 173, 66, 0.65)";
1638+
}
1639+
1640+
@Override
1641+
public String vcsChangeMarkerModificationColor() {
1642+
return "rgba(224, 185, 29, 0.65)";
1643+
}
1644+
1645+
@Override
1646+
public String vcsChangeMarkerDeletionColor() {
1647+
return "#bfc6ce";
1648+
}
1649+
16351650
@Override
16361651
public String editorPreferenceCategoryBackgroundColor() {
16371652
return "rgba(215, 215, 215, 0.10)";

0 commit comments

Comments
 (0)