bug 349328 - Reset and Checkout actions added
diff --git a/bundles/org.eclipse.orion.client.git/web/git/git-status2.js b/bundles/org.eclipse.orion.client.git/web/git/git-status2.js
index 7222d2a..63317e6 100644
--- a/bundles/org.eclipse.orion.client.git/web/git/git-status2.js
+++ b/bundles/org.eclipse.orion.client.git/web/git/git-status2.js
@@ -50,9 +50,10 @@
 		mGitCommands.createGitStatusCommands(serviceRegistry, commandService, explorer, "pageActions", "selectionTools", fileClient);
 
 		// define the command contributions - where things appear, first the groups
-		// commandService.addCommandGroup("pageActions", "eclipse.gitGroup", 100);
+		commandService.addCommandGroup("pageActions", "eclipse.gitGroup", 100);
 
 		// object contributions
+		commandService.registerCommandContribution("pageActions", "eclipse.orion.git.resetCommand", 100, "eclipse.gitGroup");
 		
 		// add commands specific for the page	
 		var viewAllCommand = new mCommands.Command({
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js b/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
index 3271442..38d2198 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/gitCommands.js
@@ -2297,7 +2297,6 @@
 				body.Message = data.parameters.valueFor("name");
 				
 				var progressService = serviceRegistry.getService("orion.page.message");
-				
 				progressService.createProgressMonitor(
 					serviceRegistry.getService("orion.git.provider").commitAll(item.CommitLocation, null, dojo.toJson(body)),
 					"Committing changes").deferred.then(
@@ -2310,10 +2309,111 @@
 				return true;
 			}
 		});	
-		
+
 		commandService.addCommand(commitCommand);
+
+		var resetCommand = new mCommands.Command({
+			name: "Reset",
+			tooltip: "Reset the branch, discarding all staged and unstaged changes",
+			imageClass: "git-sprite-refresh",
+			spriteClass: "gitCommandSprite",
+			id: "eclipse.orion.git.resetCommand",
+			callback: function(data) {
+				var item = data.items;
+				
+				var dialog = serviceRegistry.getService("orion.page.dialog");
+				dialog.confirm("All unstaged and staged changes in the working directory and index will be discarded and cannot be recovered.\n" +
+					"Are you sure you want to continue?",
+					function(doit) {
+						if (!doit) {
+							return;
+						}
+						var progressService = serviceRegistry.getService("orion.page.message");
+						progressService.createProgressMonitor(
+							serviceRegistry.getService("orion.git.provider").unstageAll(item.IndexLocation, "HARD"),
+							"Resetting local changes").deferred.then(
+							function(jsonData){
+								dojo.hitch(explorer, explorer.changedItem)(item);
+							}, displayErrorOnStatus
+						)						
+					}
+				);
+			},
+			
+			visibleWhen: function(item) {
+				// TODO Should check if there are any local changes
+				return /*(self.hasStaged || self.hasUnstaged)*/ true;
+			}
+		});
+
+		commandService.addCommand(resetCommand);
+
+		var checkoutCommand = new mCommands.Command({
+			name: "Checkout",
+			tooltip: "Checkout files, discarding all changes",
+			imageClass: "git-sprite-checkout",
+			spriteClass: "gitCommandSprite",
+			id: "eclipse.orion.git.checkoutCommand",
+			callback: function(data) {				
+				var item = data.items;
+				
+				var dialog = serviceRegistry.getService("orion.page.dialog");
+				dialog.confirm("Your changes to the selected files will be discarded and cannot be recovered.\n" +
+					"Are you sure you want to continue?",
+					function(doit) {
+						if (!doit) {
+							return;
+						}
+						var progressService = serviceRegistry.getService("orion.page.message");
+						progressService.createProgressMonitor(
+							serviceRegistry.getService("orion.git.provider").checkoutPath(item.object.CloneLocation, [item.object.path]),
+							"Resetting local changes").deferred.then(
+							function(jsonData){
+								dojo.hitch(explorer, explorer.changedItem)(item);
+							}, displayErrorOnStatus
+						)						
+					}
+				);
+				
+				
+			},
+			visibleWhen: function(item) {
+//				var return_value = (item.type === "unstagedItems" && self.hasUnstaged && self._unstagedContentRenderer.getSelected().length > 0);
+//				return return_value;
+				
+				return item.type === "fileItem" && !mGitUtil.isStaged(item.object);
+			}
+		});
+
+		commandService.addCommand(checkoutCommand);
+
+		var showPatchCommand = new mCommands.Command({
+			name: "Show Patch",
+			tooltip: "Show workspace changes as a patch",
+			imageClass: "git-sprite-diff",
+			spriteClass: "gitCommandSprite",
+			id: "eclipse.orion.git.showPatchCommand",
+			hrefCallback : function() {
+//				var url = self._curClone.DiffLocation + "?parts=diff";
+//				var selectedItems = self._unstagedContentRenderer.getSelected();
+//				for (var i = 0; i < selectedItems.length; i++) {
+//					url += "&Path=";
+//					url += selectedItems[i].modelItem.path;
+//				}
+//				return url;
+				return "http://elo";
+			},
+			visibleWhen: function(item) {
+//				var return_value = (item.type === "unstagedItems" && self.hasUnstaged && self._unstagedContentRenderer.getSelected().length > 0);
+//				return return_value;
+				
+				return false;
+			}
+		});
+		
+		commandService.addCommand(showPatchCommand);
 	};
 	
 }());
 return exports;	
-});
+});
\ No newline at end of file
diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js b/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js
index 73a517c..a9d2466 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/gitStatusExplorer.js
@@ -266,6 +266,7 @@
 											commitURI:groupData[j].Git.CommitLocation,

 											indexURI:groupData[j].Git.IndexLocation,

 											diffURI:groupData[j].Git.DiffLocation,

+											CloneLocation:this._model.items.CloneLocation,

 											conflicting:this._model.isConflict(renderType)

 						});

 					}

@@ -288,14 +289,18 @@
 			var tableNode = dojo.byId( 'table' );

 	

 			var titleWrapper = dojo.create( "div", {"class":"auxpaneHeading sectionWrapper toolComposite", "id":"unstagedSectionHeader"}, tableNode );

-			

-			dojo.create( "div", { id: "unstagedSectionTitle", "class":"layoutLeft", innerHTML: "Unstaged"}, titleWrapper );

-			dojo.create( "div", { id: "unstagedSectionActionsArea", "class":"layoutRight sectionActions"}, titleWrapper );

-			

+

 			var unstagedSortedChanges = this._sortBlock(this._model.interestedUnstagedGroup);

-						

-			//this.commandService.registerCommandContribution("unstagedSectionActionsArea", "eclipse.orion.git.addTag", 2000);

-			//this.commandService.renderCommands("tagSectionActionsArea", dojo.byId("tagSectionActionsArea"), commit, this, "button", false);

+			

+			dojo.create( "div", { id: "unstagedSectionTitle", "class":"layoutLeft", 

+				innerHTML: (unstagedSortedChanges.length > 0 ? "Unstaged" : "No Unstaged Changes")}, titleWrapper );

+			var actionsArea = dojo.create( "div", { id: "unstagedSectionActionsArea", "class":"layoutRight sectionActions"}, titleWrapper );

+

+			var commandService = this.registry.getService("orion.page.command");

+			commandService.registerCommandContribution("unstagedSectionActionsArea", "eclipse.orion.git.stageCommand", 100);

+			commandService.registerCommandContribution("unstagedSectionActionsArea", "eclipse.orion.git.checkoutCommand", 200);

+			commandService.registerCommandContribution("unstagedSectionActionsArea", "eclipse.orion.git.showPatchCommand", 300);

+			commandService.renderCommands("unstagedSectionActionsArea", actionsArea, status, this, "button");

 			

 			var content =

 				'<div class="sectionTable">' +

@@ -322,6 +327,7 @@
 

 			var commandService = this.registry.getService("orion.page.command");

 			commandService.registerCommandContribution("itemLevelCommands", "eclipse.orion.git.stageCommand", 100);

+			commandService.registerCommandContribution("itemLevelCommands", "eclipse.orion.git.checkoutCommand", 200);

 

 			var actionsArea = dojo.create( "div", {"id":"unstagedActionsArea", "class":"sectionTableItemActions" }, horizontalBox );

 			this.commandService.renderCommands(this.actionScopeId, actionsArea, {type: "fileItem", object: unstagedSortedChange}, this, "tool");

@@ -335,7 +341,10 @@
 

 			var titleWrapper = dojo.create( "div", {"class":"auxpaneHeading sectionWrapper toolComposite", "id":"stagedSectionHeader"}, tableNode );

 			

-			dojo.create( "div", { id: "stagedSectionTitle", "class":"layoutLeft", innerHTML: "Staged"}, titleWrapper );

+			var stagedSortedChanges = this._sortBlock(this._model.interestedStagedGroup);

+			

+			dojo.create( "div", { id: "stagedSectionTitle", "class":"layoutLeft", 

+				innerHTML: (stagedSortedChanges.length > 0 ? "Staged" : "No Staged Changes")}, titleWrapper );

 			var actionsArea = dojo.create( "div", { id: "stagedSectionActionsArea", "class":"layoutRight sectionActions"}, titleWrapper );

 			

 			var parentId = "stagedSectionHeader";

@@ -352,12 +361,10 @@
 			dojo.place( slideout, titleWrapper );

 			

 			var commandService = this.registry.getService("orion.page.command");

-			commandService.registerCommandContribution("stagedSectionActionsArea", "eclipse.orion.git.commitCommand", 100);

-			

-			this.commandService.renderCommands("stagedSectionActionsArea", actionsArea, status, this, "tool");

-			

-			var stagedSortedChanges = this._sortBlock(this._model.interestedStagedGroup);

-			

+			commandService.registerCommandContribution("stagedSectionActionsArea", "eclipse.orion.git.unstageCommand", 100);

+			commandService.registerCommandContribution("stagedSectionActionsArea", "eclipse.orion.git.commitCommand", 200);

+			commandService.renderCommands("stagedSectionActionsArea", actionsArea, status, this, "button");

+

 			var content =

 				'<div class="sectionTable">' +

 					'<div class="plugin-settings">' +

diff --git a/bundles/org.eclipse.orion.client.git/web/orion/git/util.js b/bundles/org.eclipse.orion.client.git/web/orion/git/util.js
index c807156..164e85a 100644
--- a/bundles/org.eclipse.orion.client.git/web/orion/git/util.js
+++ b/bundles/org.eclipse.orion.client.git/web/orion/git/util.js
@@ -33,8 +33,6 @@
 		"Conflicting":["gitImageSprite git-sprite-conflict-file", "Conflicting"]	
 	};
 	
-	
-
 	function isStaged(change){
 		for(var i = 0; i < interestedStagedGroup.length ; i++){
 			if(change.type === interestedStagedGroup[i]){