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-3271: Add more Git actions to context menu #3618

Merged
merged 8 commits into from
Jan 10, 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 @@ -758,6 +758,24 @@ void commit(DevMachine devMachine,
*/
Promise<Revision> commit(DevMachine devMachine, Path project, String message, Path[] files, boolean amend);

/**
* Performs commit changes from index to repository.
*
* @param devMachine
* current machine
* @param project
* project (root of GIT repository)
* @param message
* commit log message
* @param all
* automatically stage files that have been modified and deleted
* @param files
* the list of files that are committed, ignoring the index
* @param amend
* indicates that previous commit must be overwritten
*/
Promise<Revision> commit(DevMachine devMachine, Path project, String message, boolean all, Path[] files, boolean amend);
Copy link
Contributor

@vparfonov vparfonov Jan 10, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we need Path[] files if you added all options ? If all will be true what need to set to the files?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all parameter means add to index all changes and files parameter defines what files to commit. all can be true and files parameter can contain items, this will happen when user would call commit operation on selected items and would select Add all changes except of new files check box.
We have separate issue: #3614 to improve this window where add to index action will be performed automaticaly because user will have an ability to chose all changed files directly in the window.


/**
* Get repository options.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,11 @@ public void commit(final DevMachine devMachine,

@Override
public Promise<Revision> commit(DevMachine devMachine, Path project, String message, Path[] files, boolean amend) {
return commit(devMachine, project, message, false, files, amend);
}

@Override
public Promise<Revision> commit(DevMachine devMachine, Path project, String message, boolean all, Path[] files, boolean amend) {
List<String> paths = new ArrayList<>(files.length);

for (Path file : files) {
Expand All @@ -349,7 +353,7 @@ public Promise<Revision> commit(DevMachine devMachine, Path project, String mess
CommitRequest commitRequest = dtoFactory.createDto(CommitRequest.class)
.withMessage(message)
.withAmend(amend)
.withAll(false)
.withAll(all)
.withFiles(paths);
String url = devMachine.getWsAgentBaseUrl() + COMMIT + "?projectPath=" + project;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,9 @@ protected void onUpdate(Node model) {
}

protected void onRemove(Node model) {
selectionStorage.remove(model);
if(selectionStorage.remove(model)) {
fireSelectionChange();
}
}

public List<Node> getSelectedNodes() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,23 @@ public GitExtension(GitResources resources,
actionManager.registerAction("gitCompareWithRevision", compareWithRevisionAction);
compareGroup.add(compareWithRevisionAction);

DefaultActionGroup gitCompareContextMenuGroup = new DefaultActionGroup("Git", true, actionManager);
actionManager.registerAction("gitCompareContextMenu", gitCompareContextMenuGroup);
gitCompareContextMenuGroup.add(compareWithLatestAction);
gitCompareContextMenuGroup.add(compareWithBranchAction);
gitCompareContextMenuGroup.add(compareWithRevisionAction);

DefaultActionGroup mainContextMenuGroup = (DefaultActionGroup)actionManager.getAction("resourceOperation");
mainContextMenuGroup.add(gitCompareContextMenuGroup);
DefaultActionGroup gitContextMenuGroup = new DefaultActionGroup("Git", true, actionManager);
actionManager.registerAction("gitCompareContextMenu", gitContextMenuGroup);
gitContextMenuGroup.add(addToIndexAction);
gitContextMenuGroup.add(removeFromIndexAction);
gitContextMenuGroup.add(resetFilesAction);
gitContextMenuGroup.add(commitAction);
gitContextMenuGroup.addSeparator();
gitContextMenuGroup.add(compareWithLatestAction);
gitContextMenuGroup.add(compareWithBranchAction);
gitContextMenuGroup.add(compareWithRevisionAction);

DefaultActionGroup projectExplorerContextMenuGroup = (DefaultActionGroup)actionManager.getAction("resourceOperation");
projectExplorerContextMenuGroup.add(gitContextMenuGroup);

DefaultActionGroup editorContextMenuGroup = (DefaultActionGroup)actionManager.getAction("editorContextMenu");
editorContextMenuGroup.addSeparator();
editorContextMenuGroup.add(gitContextMenuGroup);

keyBinding.getGlobal().addKey(new KeyBuilder().action().alt().charCode('d').build(), "gitCompareWithLatest");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
package org.eclipse.che.ide.ext.git.client;

import com.google.gwt.i18n.client.Messages;
import com.google.gwt.safehtml.shared.SafeHtml;

/** @author Evgen Vidolob */
public interface GitLocalizationConstant extends Messages {
Expand Down Expand Up @@ -95,6 +94,9 @@ public interface GitLocalizationConstant extends Messages {
@Key("messages.nothingAddToIndex")
String nothingAddToIndex();

@Key("messages.nothingAddToIndexMultiSelect")
String nothingAddToIndexMultiSelect();

@Key("messages.add_failed")
String addFailed();

Expand Down Expand Up @@ -294,21 +296,24 @@ public interface GitLocalizationConstant extends Messages {
@Key("view.add_to_index.all_changes")
String addToIndexAllChanges();

@Key("view.add_to_index.multiple")
String addToIndexMultiple();
@Key("view.add_to_index.multiselect")
String addToIndexMultiSelect();

@Key("view.add_to_index.folder")
SafeHtml addToIndexFolder(String folder);
String addToIndexFolder(String folder);

@Key("view.add_to_index.file")
SafeHtml addToIndexFile(String file);
String addToIndexFile(String file);

@Key("view.add_to_index.update_field_title")
String addToIndexUpdateFieldTitle();

@Key("view.add_to_index.title")
String addToIndexTitle();

@Key("view.add_to_index.command_name")
String addToIndexCommandName();

// Branch
@Key("view.branch.create_new")
String branchCreateNew();
Expand Down Expand Up @@ -348,13 +353,13 @@ public interface GitLocalizationConstant extends Messages {
String commitTitle();

@Key("view.commit.all_field_title")
String commitAllFieldTitle();
String commitAddAllFieldTitle();

@Key("view.commit.selection_field_title")
String commitSelectionFieldTitle();

@Key("view.commit.onlyselection_field_title")
String commitOnlySelectionFieldTitle();
@Key("view.commit.all_project_field_title")
String commitAllFieldTitle();

@Key("view.commit.amend_field_title")
String commitAmendFieldTitle();
Expand Down Expand Up @@ -413,10 +418,10 @@ public interface GitLocalizationConstant extends Messages {
String removeFromIndexOnly();

@Key("view.remove_from_index.folder")
SafeHtml removeFromIndexFolder(String folder);
String removeFromIndexFolder(String folder);

@Key("view.remove_from_index.file")
SafeHtml removeFromIndexFile(String file);
String removeFromIndexFile(String file);

@Key("view.remove_from_index.title")
String removeFromIndexTitle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,129 @@
import com.google.inject.Inject;
import com.google.inject.Singleton;

import org.eclipse.che.api.git.shared.Status;
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.action.ActionEvent;
import org.eclipse.che.ide.api.app.AppContext;
import org.eclipse.che.ide.api.resources.Project;
import org.eclipse.che.ide.api.git.GitServiceClient;
import org.eclipse.che.ide.api.machine.DevMachine;
import org.eclipse.che.ide.api.notification.NotificationManager;
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.add.AddToIndexPresenter;
import org.eclipse.che.ide.FontAwesome;
import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole;
import org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsoleFactory;
import org.eclipse.che.ide.extension.machine.client.processes.panel.ProcessesPanelPresenter;
import org.eclipse.che.ide.resource.Path;

import java.util.List;

import static com.google.common.base.Preconditions.checkState;
import static org.eclipse.che.ide.api.notification.StatusNotification.DisplayMode.FLOAT_MODE;
import static org.eclipse.che.ide.api.notification.StatusNotification.Status.FAIL;

/**
* @author Andrey Plotnikov
* @author Vlad Zhukovskyi
* @author Igor Vinokur
**/
@Singleton
public class AddToIndexAction extends GitAction {
private final AddToIndexPresenter presenter;

private final AddToIndexPresenter presenter;
private final GitLocalizationConstant constant;
private final GitOutputConsoleFactory gitOutputConsoleFactory;
private final ProcessesPanelPresenter consolesPanelPresenter;
private final GitServiceClient service;
private final NotificationManager notificationManager;

@Inject
public AddToIndexAction(AddToIndexPresenter presenter,
AppContext appContext,
GitLocalizationConstant constant) {
GitLocalizationConstant constant,
GitOutputConsoleFactory gitOutputConsoleFactory,
ProcessesPanelPresenter consolesPanelPresenter,
GitServiceClient service,
NotificationManager notificationManager) {
super(constant.addToIndexTitle(), constant.addToIndexTitle(), FontAwesome.PLUS, appContext);
this.presenter = presenter;
this.constant = constant;
this.gitOutputConsoleFactory = gitOutputConsoleFactory;
this.consolesPanelPresenter = consolesPanelPresenter;
this.service = service;
this.notificationManager = notificationManager;
}

/** {@inheritDoc} */
@Override
public void actionPerformed(ActionEvent e) {
final Project project = appContext.getRootProject();
final Resource[] resources = appContext.getResources();
checkState(resources != null);
final DevMachine devMachine = appContext.getDevMachine();
final GitOutputConsole console = gitOutputConsoleFactory.create(constant.addToIndexCommandName());
consolesPanelPresenter.addCommandOutput(devMachine.getId(), console);
service.getStatus(devMachine, appContext.getRootProject().getLocation())
.then(new Operation<Status>() {
@Override
public void apply(Status status) throws OperationException {
if (containsInSelected(status.getUntracked())) {
presenter.showDialog();
} else if (containsInSelected(status.getModified())) {
addToIndex(console);
} else {
String message = resources.length > 1 ? constant.nothingAddToIndexMultiSelect() : constant.nothingAddToIndex();
console.print(message);
notificationManager.notify(message);
}
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError error) throws OperationException {
console.printError(constant.statusFailed());
notificationManager.notify(constant.statusFailed(), FAIL, FLOAT_MODE);
}
});
}

checkState(project != null, "Null project occurred");
private void addToIndex(final GitOutputConsole console) {
Resource[] resources = appContext.getResources();
Path[] paths = new Path[resources.length];
for (int i = 0; i < resources.length; i++) {
Path path = resources[i].getLocation().removeFirstSegments(1);
paths[i] = path.segmentCount() == 0 ? Path.EMPTY : path;
}
service.add(appContext.getDevMachine(), appContext.getRootProject().getLocation(), false, paths)
.then(new Operation<Void>() {
@Override
public void apply(Void arg) throws OperationException {
console.print(constant.addSuccess());
notificationManager.notify(constant.addSuccess());
}
})
.catchError(new Operation<PromiseError>() {
@Override
public void apply(PromiseError arg) throws OperationException {
console.printError(constant.addFailed());
notificationManager.notify(constant.addFailed(), FAIL, FLOAT_MODE);
}
});
}

presenter.showDialog(project);
private boolean containsInSelected(List<String> items) {
for (String item : items) {
for (Resource selectedItem : appContext.getResources()) {
String selectedItemPath = selectedItem.getLocation()
.removeFirstSegments(appContext.getRootProject().getLocation().segmentCount())
.toString();
if (item.startsWith(selectedItemPath)) {
return true;
}
}
}
return false;
}
}
Loading