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

Add ability to switch between files in Git Diff widget #5965

Merged
merged 40 commits into from
Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2318d28
CHE-5892: Temporary state
mmorhun Aug 4, 2017
28ea7d4
CHE-5892: Use an object to hold git diff data
mmorhun Aug 7, 2017
5814596
CHE-5892: Draft solution.
mmorhun Aug 9, 2017
9f7d30c
Merge branch 'master' into CHE-5892
mmorhun Aug 9, 2017
88bc819
CHE-5892: Fix build and tests
mmorhun Aug 9, 2017
a3e2c7c
CHE-5892: Fix inverted comparation type
mmorhun Aug 9, 2017
e27895c
CHE-5892: Fix comparation between revisions
mmorhun Aug 10, 2017
72fb977
CHE-5892: Small refactor in ComparePresenter
mmorhun Aug 10, 2017
347b2e0
CHE-5892: Fix Save Changes button
mmorhun Aug 10, 2017
638153b
CHE-5892: Remove unnecessary imports
mmorhun Aug 10, 2017
9f18acd
CHE-5892: Small fixes
mmorhun Aug 10, 2017
3cd740e
CHE-5892: Rename ChangedItems
mmorhun Aug 11, 2017
f22b649
CHE-5892: Fix compare with deleted file bug.
mmorhun Aug 11, 2017
2f82bec
License format
mmorhun Aug 14, 2017
d148050
License Format
mmorhun Aug 14, 2017
5d8744a
CHE-5892: Add AlteredFiles test
mmorhun Aug 14, 2017
6f3ea37
CHE-5892: Code cleanup
mmorhun Aug 14, 2017
241dca7
CHE-5892: Add additional check in AlteredFiles constructor
mmorhun Aug 14, 2017
a1eac87
Merge branch 'master' into CHE-5892
mmorhun Aug 14, 2017
18ed447
Merge branch 'master' into CHE-5892
mmorhun Aug 14, 2017
5a6d745
CHE-5892: Fix constraint mistake
mmorhun Aug 14, 2017
e1bb8f4
CHE-5892: Generalize showCompareForCurrentFile in ComparePresenter. B…
mmorhun Aug 15, 2017
c50272a
CHE-5892: Code cleanup
mmorhun Aug 15, 2017
69715a6
CHE-5892: Code cleanup
mmorhun Aug 15, 2017
96fed94
CHE-5892: Add missing new line
mmorhun Aug 16, 2017
436dc59
CHE-5892: Code cleanup
mmorhun Aug 16, 2017
286339c
Apply new code style
mmorhun Aug 22, 2017
e5208f5
Merge master
mmorhun Aug 22, 2017
d121a3d
Fix build
mmorhun Aug 22, 2017
cd6f922
Add ability to align a button left
mmorhun Aug 23, 2017
89ad74e
CHE-5892: Add current diff number in the widget title
mmorhun Aug 23, 2017
65204e0
CHE-5892: Fix formatting
mmorhun Aug 23, 2017
c4c0cdf
Merge branch 'master' into CHE-5892
mmorhun Sep 4, 2017
bea914d
Draft. Move git diff widget from iframe to IDE
mmorhun Sep 6, 2017
21619ad
CHE-5892: Fix build
mmorhun Sep 6, 2017
eaa74c5
Prevent jumping to non-existing diff with hotkeys
mmorhun Sep 6, 2017
2a1147e
CHE-5892: Temporary state. Moving git diff grom iframe to IDE
mmorhun Sep 7, 2017
7195d82
Merge branch 'master' into CHE-5892
mmorhun Sep 7, 2017
e2b5c84
CHE-5892: Move git diff widget from iframe to IDE
mmorhun Sep 7, 2017
0bd2dd9
CHE-5892: code clean up
mmorhun Sep 8, 2017
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 @@ -167,7 +167,7 @@
@def dividerThickness 1px;
@def popupPadding 24px;
@def titlePaddingBottom 16px;
@def buttonSpacing 18px;
@def buttonSideSpacing 9px;
@def labelPaddingBottom 6px;
@def examplePaddingTop 4px;
@def formButtonPaddingTop 18px;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* 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:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.ui.button;

/**
* Describes button alignment in a horizontal container.
*
* @author Mykola Morhun
*/
public enum ButtonAlignment {
LEFT,
RIGHT
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.gwt.user.client.ui.Widget;
import elemental.js.dom.JsElement;
import org.eclipse.che.commons.annotation.Nullable;
import org.eclipse.che.ide.ui.button.ButtonAlignment;
import org.vectomatic.dom.svg.ui.SVGResource;

/**
Expand Down Expand Up @@ -154,20 +155,32 @@ public void setHideOnEscapeEnabled(boolean isEnabled) {
}

protected Button createButton(String title, String debugId, ClickHandler clickHandler) {
return createButton(title, debugId, clickHandler, ButtonAlignment.RIGHT);
}

protected Button createButton(
String title, String debugId, ClickHandler clickHandler, ButtonAlignment alignment) {
Button button = new Button();
button.setText(title);
button.ensureDebugId(debugId);
button.getElement().setId(debugId);
button.addStyleName(resources.windowCss().button());
addButtonAlignment(button, alignment);
button.addClickHandler(clickHandler);
//set default tab index
button.setTabIndex(0);
return button;
}

protected Button createPrimaryButton(String title, String debugId, ClickHandler clickHandler) {
return createPrimaryButton(title, debugId, clickHandler, ButtonAlignment.RIGHT);
}

protected Button createPrimaryButton(
String title, String debugId, ClickHandler clickHandler, ButtonAlignment alignment) {
Button button = createButton(title, debugId, clickHandler);
button.addStyleName(resources.windowCss().primaryButton());
addButtonAlignment(button, alignment);
//set default tab index
button.setTabIndex(0);
return button;
Expand Down Expand Up @@ -243,6 +256,17 @@ public void execute() {
}
}

private void addButtonAlignment(Button button, ButtonAlignment alignment) {
switch (alignment) {
case LEFT:
button.addStyleName(resources.windowCss().buttonAlignLeft());
break;
case RIGHT:
default:
button.addStyleName(resources.windowCss().buttonAlignRight());
}
}

/**
* Sets focus on the given element. If {@code elementToFocus} is {@code null}, no element will be
* given focus
Expand Down Expand Up @@ -343,6 +367,10 @@ public interface Css extends CssResource {

String button();

String buttonAlignLeft();

String buttonAlignRight();

String image();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
}

.alignBtn {
float: right;
margin-left: buttonSpacing;
margin-left: buttonSideSpacing;
margin-right: buttonSideSpacing;
}

.headerTitleWrapper {
Expand Down Expand Up @@ -151,7 +151,6 @@
}

.button, .primaryButton {
float: right;
height: buttonHeight;
line-height: buttonLineHeight;
min-width: buttonMinWidth;
Expand Down Expand Up @@ -194,6 +193,14 @@
opacity: 0.5;
}

.buttonAlignLeft {
float: left;
}

.buttonAlignRight {
float: right;
}

/* Blue button styles */
.primaryButton {
background: primaryButtonBackground;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
import org.eclipse.che.ide.ext.git.client.action.FetchAction;
import org.eclipse.che.ide.ext.git.client.action.HistoryAction;
import org.eclipse.che.ide.ext.git.client.action.InitRepositoryAction;
import org.eclipse.che.ide.ext.git.client.action.NextDiffAction;
import org.eclipse.che.ide.ext.git.client.action.PreviousDiffAction;
import org.eclipse.che.ide.ext.git.client.action.PullAction;
import org.eclipse.che.ide.ext.git.client.action.PushAction;
import org.eclipse.che.ide.ext.git.client.action.RemoveFromIndexAction;
Expand All @@ -57,6 +59,9 @@ public class GitExtension {
public static final String HISTORY_GROUP_MAIN_MENU = "GitHistoryGroup";
public static final String GIT_COMPARE_WITH_LATEST = "gitCompareWithLatest";

public static final String NEXT_DIFF_ACTION_ID = "nextDiff";
public static final String PREV_DIFF_ACTION_ID = "prevDiff";

@Inject
public GitExtension(
GitResources resources,
Expand All @@ -81,6 +86,8 @@ public GitExtension(
CompareWithLatestAction compareWithLatestAction,
CompareWithBranchAction compareWithBranchAction,
CompareWithRevisionAction compareWithRevisionAction,
NextDiffAction nextDiffAction,
PreviousDiffAction previousDiffAction,
KeyBindingAgent keyBinding,
AppContext appContext) {

Expand Down Expand Up @@ -180,8 +187,18 @@ public GitExtension(
editorContextMenuGroup.addSeparator();
editorContextMenuGroup.add(gitContextMenuGroup);

actionManager.registerAction(NEXT_DIFF_ACTION_ID, nextDiffAction);
actionManager.registerAction(PREV_DIFF_ACTION_ID, previousDiffAction);

keyBinding
.getGlobal()
.addKey(new KeyBuilder().action().alt().charCode('d').build(), GIT_COMPARE_WITH_LATEST);

keyBinding
.getGlobal()
.addKey(new KeyBuilder().alt().charCode('.').build(), NEXT_DIFF_ACTION_ID);
keyBinding
.getGlobal()
.addKey(new KeyBuilder().alt().charCode(',').build(), PREV_DIFF_ACTION_ID);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public interface GitLocalizationConstant extends Messages {
@Key("button.compare")
String buttonCompare();

@Key("button.save_changes")
String buttonSaveChanges();

@Key("button.next_diff")
String buttonNextDiff();

@Key("button.previous_diff")
String buttonPreviousDiff();

@Key("console.tooltip.clear")
String buttonClear();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,9 @@
import static org.eclipse.che.api.git.shared.DiffType.NAME_STATUS;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.NOT_EMERGE_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;
import static org.eclipse.che.ide.ext.git.client.compare.FileStatus.defineStatus;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.dialogs.DialogFactory;
Expand All @@ -29,8 +26,8 @@
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.resources.Resource;
import org.eclipse.che.ide.ext.git.client.GitLocalizationConstant;
import org.eclipse.che.ide.ext.git.client.compare.AlteredFiles;
import org.eclipse.che.ide.ext.git.client.compare.ComparePresenter;
import org.eclipse.che.ide.ext.git.client.compare.FileStatus.Status;
import org.eclipse.che.ide.ext.git.client.compare.changeslist.ChangesListPresenter;

/**
Expand Down Expand Up @@ -106,25 +103,13 @@ public void actionPerformed(ActionEvent e) {
null)
.show();
} else {
final String[] changedFiles = diff.split("\n");
if (changedFiles.length == 1) {
project
.getFile(changedFiles[0].substring(2))
.then(
file -> {
if (file.isPresent()) {
comparePresenter.showCompareWithLatest(
file.get(),
defineStatus(changedFiles[0].substring(0, 1)),
REVISION);
}
});
AlteredFiles alteredFiles = new AlteredFiles(project, diff);
if (alteredFiles.getFilesQuantity() == 1) {

comparePresenter.showCompareWithLatest(alteredFiles, null, REVISION);
} else {
Map<String, Status> items = new HashMap<>();
for (String item : changedFiles) {
items.put(item.substring(2, item.length()), defineStatus(item.substring(0, 1)));
}
changesListPresenter.show(items, REVISION, null, project);

changesListPresenter.show(alteredFiles, REVISION, null);
}
}
})
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* 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:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.ext.git.client.action;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.ext.git.client.compare.ComparePresenter;

/** @author Mykola Morhun */
@Singleton
public class NextDiffAction extends Action {

private final ComparePresenter comparePresenter;

@Inject
public NextDiffAction(ComparePresenter comparePresenter) {
this.comparePresenter = comparePresenter;
}

@Override
public void actionPerformed(ActionEvent e) {
if (comparePresenter.isShown()) {
comparePresenter.onNextDiffClicked();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (c) 2012-2017 Red Hat, Inc.
* 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:
* Red Hat, Inc. - initial API and implementation
*/
package org.eclipse.che.ide.ext.git.client.action;

import com.google.inject.Inject;
import com.google.inject.Singleton;
import org.eclipse.che.ide.api.action.Action;
import org.eclipse.che.ide.api.action.ActionEvent;
import org.eclipse.che.ide.ext.git.client.compare.ComparePresenter;

/** @author Mykola Morhun */
@Singleton
public class PreviousDiffAction extends Action {

private final ComparePresenter comparePresenter;

@Inject
public PreviousDiffAction(ComparePresenter comparePresenter) {
super(null, null);
this.comparePresenter = comparePresenter;
}

@Override
public void actionPerformed(ActionEvent e) {
if (comparePresenter.isShown()) {
comparePresenter.onPreviousDiffClicked();
}
}
}
Loading