Skip to content

Commit

Permalink
CHE-3609: Create visual Git history window instead of old one (#3799)
Browse files Browse the repository at this point in the history
  • Loading branch information
Igor Vinokur authored Feb 8, 2017
1 parent c9d700b commit da8c419
Show file tree
Hide file tree
Showing 20 changed files with 741 additions and 930 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,9 @@ private AsyncRequest diff(Path project,
}
params.append("&noRenames=").append(noRenames);
params.append("&renameLimit=").append(renameLimit);
params.append("&commitA=").append(commitA);
if (commitA != null) {
params.append("&commitA=").append(commitA);
}
if (commitB != null) {
params.append("&commitB=").append(commitB);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public GitExtension(GitResources resources,
gitContextMenuGroup.add(removeFromIndexAction);
gitContextMenuGroup.add(resetFilesAction);
gitContextMenuGroup.add(commitAction);
gitContextMenuGroup.add(historyAction);
gitContextMenuGroup.addSeparator();
gitContextMenuGroup.add(compareWithLatestAction);
gitContextMenuGroup.add(compareWithBranchAction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status;
import org.eclipse.che.ide.ext.git.client.compare.changedList.ChangedListPresenter;
import org.eclipse.che.ide.api.dialogs.DialogFactory;

import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -105,7 +106,9 @@ public void apply(String diff) throws OperationException {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
comparePresenter.show(file.get(), defineStatus(changedFiles[0].substring(0, 1)), REVISION);
comparePresenter.showCompareWithLatest(file.get(),
defineStatus(changedFiles[0].substring(0, 1)),
REVISION);
}
}
});
Expand All @@ -114,7 +117,7 @@ public void apply(Optional<File> file) throws OperationException {
for (String item : changedFiles) {
items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
}
changedListPresenter.show(items, REVISION, project);
changedListPresenter.show(items, REVISION, null, project);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@

import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant;
import org.eclipse.che.ide.ext.git.client.history.HistoryPresenter;
import org.eclipse.che.ide.FontAwesome;

import static com.google.common.base.Preconditions.checkState;
import org.eclipse.che.ide.ext.git.client.history.HistoryPresenter;

/**
* @author Andrey Plotnikov
Expand All @@ -42,10 +39,6 @@ public HistoryAction(Provider<HistoryPresenter> presenterProvider,
/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
final Project project = appContext.getRootProject();

checkState(project != null, "Null project occurred");

presenterProvider.get().showDialog(project);
presenterProvider.get().show();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
import com.google.inject.Singleton;
import com.google.web.bindery.event.shared.EventBus;

import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.api.event.FileContentUpdateEvent;
import org.eclipse.che.ide.api.git.GitServiceClient;
import org.eclipse.che.api.git.shared.ShowFileContentResponse;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.api.promises.client.Operation;
import org.eclipse.che.api.promises.client.OperationException;
import org.eclipse.che.api.promises.client.PromiseError;
import org.eclipse.che.ide.api.machine.DevMachine;
import org.eclipse.che.ide.api.notification.NotificationManager;
import org.eclipse.che.ide.api.resources.Container;
import org.eclipse.che.ide.api.resources.File;
Expand Down Expand Up @@ -55,9 +57,10 @@ public class ComparePresenter implements CompareView.ActionDelegate {
private final GitLocalizationConstant locale;
private final NotificationManager notificationManager;

private File comparedFile;
private String revision;
private String localContent;
private File comparedFile;
private String revision;
private String localContent;
private boolean compareWithLatest;

@Inject
public ComparePresenter(AppContext appContext,
Expand Down Expand Up @@ -87,9 +90,10 @@ public ComparePresenter(AppContext appContext,
* @param revision
* hash of revision or branch
*/
public void show(final File file, final Status status, final String revision) {
public void showCompareWithLatest(final File file, final Status status, final String revision) {
this.comparedFile = file;
this.revision = revision;
this.compareWithLatest = true;

if (status.equals(ADDED)) {
showCompare("");
Expand All @@ -110,7 +114,8 @@ public void show(final File file, final Status status, final String revision) {
@Override
public void apply(ShowFileContentResponse content) throws OperationException {
view.setTitle(file.getLocation().toString());
view.show(content.getContent(), "", revision, file.getLocation().toString());
view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
view.show(content.getContent(), "", file.getLocation().toString(), false);
}
})
.catchError(new Operation<PromiseError>() {
Expand All @@ -120,7 +125,6 @@ public void apply(PromiseError error) throws OperationException {
}
});
} else {

service.showFileContent(appContext.getDevMachine(), project.get().getLocation(), relPath, revision)
.then(new Operation<ShowFileContentResponse>() {
@Override
Expand All @@ -137,10 +141,88 @@ public void apply(PromiseError error) throws OperationException {
}
}

/** {@inheritDoc} */
/**
*
* @param file
* path of the file
* @param status
* status of the file
* @param revisionA
* hash of the first revision or branch.
* If it is set to {@code null}, compare with empty repository state will be performed
* @param revisionB
* hash of the second revision or branch.
* If it is set to {@code null}, compare with latest repository state will be performed
*/
public void showCompareBetweenRevisions(final Path file,
final Status status,
@Nullable final String revisionA,
@Nullable final String revisionB) {
this.compareWithLatest = false;

final DevMachine devMachine = appContext.getDevMachine();
final Path projectLocation = appContext.getRootProject().getLocation();

view.setTitle(file.toString());
if (status == Status.ADDED) {
service.showFileContent(devMachine, projectLocation, file, revisionB)
.then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(),
revisionA == null ? "" : revisionA + locale.compareReadOnlyTitle());
view.show("", response.getContent(), file.toString(), true);
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else if (status == Status.DELETED) {
service.showFileContent(devMachine, projectLocation, file, revisionA)
.then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse response) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(), revisionA + locale.compareReadOnlyTitle());
view.show(response.getContent(), "", file.toString(), true);
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
} else {
service.showFileContent(devMachine, projectLocation, file, revisionA)
.then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(final ShowFileContentResponse contentAResponse) throws OperationException {
service.showFileContent(devMachine, projectLocation, file, revisionB)
.then(new Operation<ShowFileContentResponse>() {
@Override
public void apply(ShowFileContentResponse contentBResponse) throws OperationException {
view.setColumnTitles(revisionB + locale.compareReadOnlyTitle(),
revisionA + locale.compareReadOnlyTitle());
view.show(contentAResponse.getContent(), contentBResponse.getContent(), file.toString(), true);
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
notificationManager.notify(error.getMessage(), FAIL, NOT_EMERGE_MODE);
}
});
}
});
}
}

@Override
public void onClose(final String newContent) {
if (this.localContent == null || newContent.equals(localContent)) {
if (!compareWithLatest || this.localContent == null || newContent.equals(localContent)) {
view.hide();
return;
}
Expand Down Expand Up @@ -180,9 +262,10 @@ private void showCompare(final String remoteContent) {
@Override
public void apply(String local) throws OperationException {
localContent = local;
final String path = comparedFile.getLocation().toString();
final String path = comparedFile.getLocation().removeFirstSegments(1).toString();
view.setTitle(path);
view.show(remoteContent, localContent, revision, path);
view.setColumnTitles(locale.compareYourVersionTitle(), revision + locale.compareReadOnlyTitle());
view.show(remoteContent, localContent, path, false);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ interface CompareView extends View<CompareView.ActionDelegate> {
*/
void setTitle(String title);

/**
* Set left and right column titles.
*
* @param leftTitle
* title for the left column
* @param rightTitle
* title for the right column
*/
void setColumnTitles(String leftTitle, String rightTitle);

/** Hide compare window. */
void hide();

Expand All @@ -40,17 +50,19 @@ interface CompareView extends View<CompareView.ActionDelegate> {
* content from specified revision or branch
* @param newContent
* content of current file
* @param revision
* revision or branch which is getting part in comparing
* @param file
* changed file name with its full path
* @param readOnly
* read only state of the right column
*/
void show(String oldContent, String newContent, String revision, String file);
void show(String oldContent, String newContent, String file, boolean readOnly);

interface ActionDelegate {
/** Performs some actions in response to user's closing the window.
/**
* Performs some actions in response to user's closing the window.
*
* @param newContent new content of compare widget
* @param newContent
* new content of compare widget
*/
void onClose(String newContent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ interface PreviewViewImplUiBinder extends UiBinder<Widget, CompareViewImpl> {
@UiField
SimplePanel comparePanel;
@UiField
Label revision;
Label leftTitle;
@UiField
Label rightTitle;

@UiField(provided = true)
final GitLocalizationConstant locale;
Expand Down Expand Up @@ -96,7 +98,6 @@ public void onClick(ClickEvent event) {
comparePanel.getElement().setId(Document.get().createUniqueId());
}

/** {@inheritDoc} */
@Override
public void setDelegate(ActionDelegate delegate) {
this.delegate = delegate;
Expand All @@ -112,26 +113,29 @@ public void onContentReceived(String content) {
});
}

/** {@inheritDoc} */
@Override
public void show(String oldContent, String newContent, String revision, String file) {
public void setColumnTitles(String leftTitle, String rightTitle) {
this.leftTitle.setText(leftTitle);
this.rightTitle.setText(rightTitle);
}

@Override
public void show(String oldContent, String newContent, String fileName, boolean readOnly) {
dockPanel.setSize(String.valueOf((com.google.gwt.user.client.Window.getClientWidth() / 100) * 95) + "px",
String.valueOf((com.google.gwt.user.client.Window.getClientHeight() / 100) * 90) + "px");

super.show();

this.revision.setText(revision + locale.compareReadOnlyTitle());

FileOptions newFile = compareFactory.createFieOptions();
newFile.setReadOnly(false);
newFile.setReadOnly(readOnly);

FileOptions oldFile = compareFactory.createFieOptions();
oldFile.setReadOnly(true);

newFile.setContent(newContent);
newFile.setName(file);
newFile.setName(fileName);
oldFile.setContent(oldContent);
oldFile.setName(file);
oldFile.setName(fileName);

CompareConfig compareConfig = compareFactory.createCompareConfig();
compareConfig.setNewFile(newFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
<g:north size="15">
<g:HorizontalPanel width="100%">
<g:cell width="50%" horizontalAlignment="ALIGN_CENTER">
<g:Label text="{locale.compareYourVersionTitle}"/>
<g:Label ui:field="leftTitle"/>
</g:cell>
<g:cell width="50%" horizontalAlignment="ALIGN_CENTER">
<g:Label ui:field="revision"/>
<g:Label ui:field="rightTitle"/>
</g:cell>
</g:HorizontalPanel>
</g:north>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@
public class BranchListPresenter implements BranchListView.ActionDelegate {
public static final String BRANCH_LIST_COMMAND_NAME = "Git list of branches";

private final ComparePresenter comparePresenter;
private final ChangedListPresenter changedListPresenter;
private final GitOutputConsoleFactory gitOutputConsoleFactory;
private final ProcessesPanelPresenter consolesPanelPresenter;
private final BranchListView view;
private final DialogFactory dialogFactory;
private final GitServiceClient service;
private final GitLocalizationConstant locale;
private final AppContext appContext;
private final NotificationManager notificationManager;
private final ComparePresenter comparePresenter;
private final ChangedListPresenter changedListPresenter;
private final GitOutputConsoleFactory gitOutputConsoleFactory;
private final ProcessesPanelPresenter consolesPanelPresenter;
private final BranchListView view;
private final DialogFactory dialogFactory;
private final GitServiceClient service;
private final GitLocalizationConstant locale;
private final AppContext appContext;
private final NotificationManager notificationManager;

private Branch selectedBranch;
private Project project;
Expand Down Expand Up @@ -141,9 +141,9 @@ public void apply(String diff) throws OperationException {
@Override
public void apply(Optional<File> file) throws OperationException {
if (file.isPresent()) {
comparePresenter.show(file.get(),
defineStatus(changedFiles[0].substring(0, 1)),
selectedBranch.getName());
comparePresenter.showCompareWithLatest(file.get(),
defineStatus(changedFiles[0].substring(0, 1)),
selectedBranch.getName());
}
}
});
Expand All @@ -152,7 +152,7 @@ public void apply(Optional<File> file) throws OperationException {
for (String item : changedFiles) {
items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
}
changedListPresenter.show(items, selectedBranch.getName(), project);
changedListPresenter.show(items, selectedBranch.getName(), null, project);
}
}
}
Expand Down
Loading

0 comments on commit da8c419

Please sign in to comment.