Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[egit-dev] [PATCH] Share a single project using Quick Access

Implements sharing a single project using Quick Access with a keyboard
from the almost any place of the workspace:
- activate Quick Access (which is bound to Ctrl+3 by default)
- typing SWG (which means 'share with Git') will provide user with a list
  of all currently open projects not connected to any team provider
- 'Configure Git Repository' dialog with a selected project would be
  presented to user

Signed-off-by: Mykola Nikishov <mn@xxxxxxxxx>
Change-Id: I13a286001c27739b1b6aebfe564c115de4ab368e
---
 org.eclipse.egit.ui/plugin.properties              |    3 +
 org.eclipse.egit.ui/plugin.xml                     |   15 ++++++
 .../commands/ProjectNameParameterValues.java       |   42 ++++++++++++++++
 .../commands/ShareSingleProjectCommand.java        |   51 ++++++++++++++++++++
 4 files changed, 111 insertions(+), 0 deletions(-)
 create mode 100644 org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ProjectNameParameterValues.java
 create mode 100644 org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ShareSingleProjectCommand.java

diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 989dbb9..2fdbb24 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -77,3 +77,6 @@ GitPreferences_name=Git
 GitPreferences_HistoryPreferencePage_name=History
 GitPreferences_WindowCachePreferencePage_name=Window Cache
 GitPreferences_DecoratorPreferencePage_name=Label Decorations
+
+ShareProjectCommand_name=Share with Git
+ShareProjectCommand_desc=Share the project using Git
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index ae9f083..f3099cd 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -385,4 +385,19 @@
 		</action>
       </actionSet>
    </extension>
+   <extension
+         point="org.eclipse.ui.commands">
+      <command
+            defaultHandler="org.eclipse.egit.ui.internal.commands.ShareSingleProjectCommand"
+            description="%ShareProjectCommand_desc"
+            id="org.eclipse.egit.ui.command.shareProject"
+            name="%ShareProjectCommand_name">
+         <commandParameter
+               id="org.eclipse.egit.ui.command.projectNameParameter"
+               name="Project"
+               optional="false"
+               values="org.eclipse.egit.ui.internal.commands.ProjectNameParameterValues">
+         </commandParameter>
+      </command>
+   </extension>
 </plugin>
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ProjectNameParameterValues.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ProjectNameParameterValues.java
new file mode 100644
index 0000000..4969523
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ProjectNameParameterValues.java
@@ -0,0 +1,42 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Mykola Nikishov <mn@xxxxxxxxx>
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commands;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.commands.IParameterValues;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.team.core.RepositoryProvider;
+
+/**
+ * Provides list of accessible and non-shared projects' names for the Share
+ * Project command.
+ * 
+ * @since 0.6.0
+ */
+public class ProjectNameParameterValues implements IParameterValues {
+
+	public Map getParameterValues() {
+		IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+		IProject[] projects = root.getProjects();
+		Map<String, String> paramValues = new HashMap<String, String>();
+		for (IProject project : projects) {
+			final boolean notAlreadyShared = RepositoryProvider
+					.getProvider(project) == null;
+			if (project.isAccessible() && notAlreadyShared) {
+				paramValues.put(project.getName(), project.getName());
+			}
+		}
+		return paramValues;
+	}
+
+}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ShareSingleProjectCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ShareSingleProjectCommand.java
new file mode 100644
index 0000000..c5e7b49
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ShareSingleProjectCommand.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (C) 2009, Mykola Nikishov <mn@xxxxxxxxx>
+ *
+ * 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
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.egit.ui.internal.sharing.SharingWizard;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.team.internal.ui.wizards.ConfigureProjectWizard;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Provides a handler for the Share Project command. This can then be bound to
+ * whatever keybinding the user prefers.
+ * 
+ * @since 0.6.0
+ */
+public class ShareSingleProjectCommand extends AbstractHandler {
+
+	private static final String PROJECT_NAME_PARAMETER = "org.eclipse.egit.ui.command.projectNameParameter"; //$NON-NLS-1$
+
+	/**
+	 * Invokes 'Configure Git Repository' dialog to share given project.
+	 * 
+	 * @see org.eclipse.core.commands.AbstractHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+	 */
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		final String projectName = event.getParameter(PROJECT_NAME_PARAMETER);
+		final IProject projectToShare = ResourcesPlugin.getWorkspace()
+				.getRoot().getProject(projectName);
+		IWorkbench workbench = HandlerUtil.getActiveWorkbenchWindow(event)
+				.getWorkbench();
+
+		final SharingWizard wizard = new SharingWizard();
+		wizard.init(workbench, projectToShare);
+		final Shell shell = HandlerUtil.getActiveShell(event);
+		ConfigureProjectWizard.openWizard(shell, wizard);
+		return null;
+	}
+
+}
-- 
1.6.4.3



Back to the top