From 3c3dcd9eb7e00f6c36897c0e77a8ab699b5240f3 Mon Sep 17 00:00:00 2001 From: Mykola Nikishov Date: Sun, 4 Oct 2009 02:02:45 +0300 Subject: 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 Bug: https://bugs.eclipse.org/291283 Signed-off-by: Mykola Nikishov Change-Id: I13a286001c27739b1b6aebfe564c115de4ab368e --- org.eclipse.egit.ui/plugin.properties | 3 ++ org.eclipse.egit.ui/plugin.xml | 15 +++++++ .../commands/ProjectNameParameterValues.java | 41 +++++++++++++++++ .../commands/ShareSingleProjectCommand.java | 51 ++++++++++++++++++++++ 4 files changed, 110 insertions(+) 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 989dbb927a..2fdbb24017 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 ae9f0835c8..f3099cdbe6 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -385,4 +385,19 @@ + + + + + + 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 0000000000..ae0e6b9c1a --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/commands/ProjectNameParameterValues.java @@ -0,0 +1,41 @@ +/******************************************************************************* + * Copyright (C) 2009, Mykola Nikishov + * + * 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 paramValues = new HashMap(); + 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 0000000000..5dbdf8523b --- /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 + * + * 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; + } + +} -- cgit v1.2.3