mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-113775 External System: new 'Refresh external project' action for single module refresh
This commit is contained in:
@@ -34,6 +34,8 @@ tool.window.title.tasks=tasks
|
||||
# Action.
|
||||
action.refresh.all.projects.text=Refresh all {0} projects
|
||||
action.refresh.all.projects.description=Force refresh all linked {0} projects
|
||||
action.refresh.project.text=Refresh {0} project
|
||||
action.refresh.project.description=Force refresh selected linked {0} project
|
||||
action.attach.external.project.text=Attach {0} project
|
||||
action.attach.external.project.description=Attach {0} project to the current ide project
|
||||
action.detach.external.project.text=Detach {0} project
|
||||
|
||||
+2
-54
@@ -59,13 +59,13 @@ public class DetachExternalProjectAction extends AnAction implements DumbAware {
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
MyInfo info = getProcessingInfo(e.getDataContext());
|
||||
ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext());
|
||||
e.getPresentation().setEnabled(info.externalProject != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
MyInfo info = getProcessingInfo(e.getDataContext());
|
||||
ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext());
|
||||
if (info.settings == null || info.localSettings == null || info.externalProject == null || info.ideProject == null
|
||||
|| info.externalSystemId == null)
|
||||
{
|
||||
@@ -108,56 +108,4 @@ public class DetachExternalProjectAction extends AnAction implements DumbAware {
|
||||
ExternalSystemUtil.ruleOrphanModules(orphanModules, info.ideProject, info.externalSystemId);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static MyInfo getProcessingInfo(@NotNull DataContext context) {
|
||||
ExternalProjectPojo externalProject = ExternalSystemDataKeys.SELECTED_PROJECT.getData(context);
|
||||
if (externalProject == null) {
|
||||
return MyInfo.EMPTY;
|
||||
}
|
||||
|
||||
ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(context);
|
||||
if (externalSystemId == null) {
|
||||
return MyInfo.EMPTY;
|
||||
}
|
||||
|
||||
Project ideProject = PlatformDataKeys.PROJECT.getData(context);
|
||||
if (ideProject == null) {
|
||||
return MyInfo.EMPTY;
|
||||
}
|
||||
|
||||
AbstractExternalSystemSettings<?, ?, ?> settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId);
|
||||
ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath());
|
||||
AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId);
|
||||
|
||||
return new MyInfo(externalProjectSettings == null ? null : settings,
|
||||
localSettings == null ? null : localSettings,
|
||||
externalProjectSettings == null ? null : externalProject,
|
||||
ideProject,
|
||||
externalSystemId);
|
||||
}
|
||||
|
||||
private static class MyInfo {
|
||||
|
||||
public static final MyInfo EMPTY = new MyInfo(null, null, null, null, null);
|
||||
|
||||
@Nullable public final AbstractExternalSystemSettings<?, ?, ?> settings;
|
||||
@Nullable public final AbstractExternalSystemLocalSettings localSettings;
|
||||
@Nullable public final ExternalProjectPojo externalProject;
|
||||
@Nullable public final Project ideProject;
|
||||
@Nullable public final ProjectSystemId externalSystemId;
|
||||
|
||||
MyInfo(@Nullable AbstractExternalSystemSettings<?, ?, ?> settings,
|
||||
@Nullable AbstractExternalSystemLocalSettings localSettings,
|
||||
@Nullable ExternalProjectPojo externalProject,
|
||||
@Nullable Project ideProject,
|
||||
@Nullable ProjectSystemId externalSystemId)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.localSettings = localSettings;
|
||||
this.externalProject = externalProject;
|
||||
this.ideProject = ideProject;
|
||||
this.externalSystemId = externalSystemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.externalSystem.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
|
||||
import com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo;
|
||||
import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemLocalSettings;
|
||||
import com.intellij.openapi.externalSystem.settings.AbstractExternalSystemSettings;
|
||||
import com.intellij.openapi.externalSystem.settings.ExternalProjectSettings;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author Vladislav.Soroka
|
||||
* @since 9/18/13
|
||||
*/
|
||||
public class ExternalActionUtil {
|
||||
@NotNull
|
||||
public static MyInfo getProcessingInfo(@NotNull DataContext context) {
|
||||
ExternalProjectPojo externalProject = ExternalSystemDataKeys.SELECTED_PROJECT.getData(context);
|
||||
if (externalProject == null) {
|
||||
return MyInfo.EMPTY;
|
||||
}
|
||||
|
||||
ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(context);
|
||||
if (externalSystemId == null) {
|
||||
return MyInfo.EMPTY;
|
||||
}
|
||||
|
||||
Project ideProject = PlatformDataKeys.PROJECT.getData(context);
|
||||
if (ideProject == null) {
|
||||
return MyInfo.EMPTY;
|
||||
}
|
||||
|
||||
AbstractExternalSystemSettings<?, ?, ?> settings = ExternalSystemApiUtil.getSettings(ideProject, externalSystemId);
|
||||
ExternalProjectSettings externalProjectSettings = settings.getLinkedProjectSettings(externalProject.getPath());
|
||||
AbstractExternalSystemLocalSettings localSettings = ExternalSystemApiUtil.getLocalSettings(ideProject, externalSystemId);
|
||||
|
||||
return new MyInfo(externalProjectSettings == null ? null : settings,
|
||||
localSettings == null ? null : localSettings,
|
||||
externalProjectSettings == null ? null : externalProject,
|
||||
ideProject,
|
||||
externalSystemId);
|
||||
}
|
||||
|
||||
public static class MyInfo {
|
||||
|
||||
public static final MyInfo EMPTY = new MyInfo(null, null, null, null, null);
|
||||
|
||||
@Nullable public final AbstractExternalSystemSettings<?, ?, ?> settings;
|
||||
@Nullable public final AbstractExternalSystemLocalSettings localSettings;
|
||||
@Nullable public final ExternalProjectPojo externalProject;
|
||||
@Nullable public final Project ideProject;
|
||||
@Nullable public final ProjectSystemId externalSystemId;
|
||||
|
||||
MyInfo(@Nullable AbstractExternalSystemSettings<?, ?, ?> settings,
|
||||
@Nullable AbstractExternalSystemLocalSettings localSettings,
|
||||
@Nullable ExternalProjectPojo externalProject,
|
||||
@Nullable Project ideProject,
|
||||
@Nullable ProjectSystemId externalSystemId)
|
||||
{
|
||||
this.settings = settings;
|
||||
this.localSettings = localSettings;
|
||||
this.externalProject = externalProject;
|
||||
this.ideProject = ideProject;
|
||||
this.externalSystemId = externalSystemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -1,9 +1,6 @@
|
||||
package com.intellij.openapi.externalSystem.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
|
||||
import com.intellij.openapi.externalSystem.model.project.ExternalProjectPojo;
|
||||
@@ -48,7 +45,7 @@ public class OpenExternalConfigAction extends AnAction implements DumbAware {
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-2
@@ -2,6 +2,7 @@ package com.intellij.openapi.externalSystem.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
|
||||
@@ -39,7 +40,7 @@ public class RefreshAllExternalProjectsAction extends AnAction implements DumbAw
|
||||
e.getPresentation().setText(ExternalSystemBundle.message("action.refresh.all.projects.text", name));
|
||||
e.getPresentation().setDescription(ExternalSystemBundle.message("action.refresh.all.projects.description", name));
|
||||
|
||||
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
@@ -56,7 +57,7 @@ public class RefreshAllExternalProjectsAction extends AnAction implements DumbAw
|
||||
return;
|
||||
}
|
||||
|
||||
Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
|
||||
Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
package com.intellij.openapi.externalSystem.action;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.externalSystem.model.DataNode;
|
||||
import com.intellij.openapi.externalSystem.model.ExternalSystemDataKeys;
|
||||
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
|
||||
import com.intellij.openapi.externalSystem.model.project.ProjectData;
|
||||
import com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskType;
|
||||
import com.intellij.openapi.externalSystem.service.internal.ExternalSystemProcessingManager;
|
||||
import com.intellij.openapi.externalSystem.service.project.ExternalProjectRefreshCallback;
|
||||
import com.intellij.openapi.externalSystem.service.project.manage.ProjectDataManager;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemApiUtil;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemBundle;
|
||||
import com.intellij.openapi.externalSystem.util.ExternalSystemUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.ex.ProjectRootManagerEx;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
/**
|
||||
* * Forces the ide to retrieve the most up-to-date info about the linked external project and updates project state if necessary
|
||||
* (e.g. imports missing libraries).
|
||||
*
|
||||
* @author Vladislav.Soroka
|
||||
* @since 9/18/13
|
||||
*/
|
||||
public class RefreshExternalProjectAction extends AnAction implements DumbAware, AnAction.TransparentUpdate {
|
||||
|
||||
public RefreshExternalProjectAction() {
|
||||
getTemplatePresentation().setText(ExternalSystemBundle.message("action.refresh.project.text", "external"));
|
||||
getTemplatePresentation().setDescription(ExternalSystemBundle.message("action.refresh.project.description", "external"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext());
|
||||
e.getPresentation().setEnabled(info.externalProject != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
ExternalActionUtil.MyInfo info = ExternalActionUtil.getProcessingInfo(e.getDataContext());
|
||||
if (info.settings == null || info.localSettings == null || info.externalProject == null || info.ideProject == null
|
||||
|| info.externalSystemId == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ProjectSystemId externalSystemId = ExternalSystemDataKeys.EXTERNAL_SYSTEM_ID.getData(e.getDataContext());
|
||||
if (externalSystemId == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Project project = CommonDataKeys.PROJECT.getData(e.getDataContext());
|
||||
if (project == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// We save all documents because there is a possible case that there is an external system config file changed inside the ide.
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
|
||||
final ProjectDataManager projectDataManager = ServiceManager.getService(ProjectDataManager.class);
|
||||
ExternalSystemUtil.refreshProject(
|
||||
project, externalSystemId, info.externalProject.getPath(),
|
||||
new ExternalProjectRefreshCallback() {
|
||||
@Override
|
||||
public void onSuccess(@Nullable final DataNode<ProjectData> externalProject) {
|
||||
if (externalProject == null) {
|
||||
return;
|
||||
}
|
||||
ExternalSystemApiUtil.executeProjectChangeAction(true, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ProjectRootManagerEx.getInstanceEx(project).mergeRootsChangesDuring(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
projectDataManager.importData(externalProject.getKey(), Collections.singleton(externalProject), project, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull String errorMessage, @Nullable String errorDetails) {
|
||||
}
|
||||
}, true, false);
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,16 @@
|
||||
<action id="ExternalSystem.RefreshAllProjects"
|
||||
class="com.intellij.openapi.externalSystem.action.RefreshAllExternalProjectsAction"
|
||||
icon="AllIcons.Actions.Refresh"/>
|
||||
<action id="ExternalSystem.RefreshProject"
|
||||
class="com.intellij.openapi.externalSystem.action.RefreshExternalProjectAction"
|
||||
icon="AllIcons.Actions.Refresh">
|
||||
<keyboard-shortcut first-keystroke="F5" keymap="$default"/>
|
||||
</action>
|
||||
<action id="ExternalSystem.AttachProject"
|
||||
class="com.intellij.openapi.externalSystem.action.AttachExternalProjectAction"/>
|
||||
<action id="ExternalSystem.DetachProject"
|
||||
class="com.intellij.openapi.externalSystem.action.DetachExternalProjectAction"/>
|
||||
class="com.intellij.openapi.externalSystem.action.DetachExternalProjectAction"
|
||||
use-shortcut-of="$Delete"/>
|
||||
<action id="ExternalSystem.OpenConfig"
|
||||
class="com.intellij.openapi.externalSystem.action.OpenExternalConfigAction"
|
||||
use-shortcut-of="EditSource"/>
|
||||
@@ -23,6 +29,7 @@
|
||||
<!--Context menu action-->
|
||||
<group id="ExternalSystem.Tree.Context" popup="true">
|
||||
<reference ref="ExternalSystem.OpenConfig"/>
|
||||
<reference id="ExternalSystem.RefreshProject"/>
|
||||
<reference ref="ExternalSystem.DetachProject"/>
|
||||
<separator/>
|
||||
<reference ref="RunContextGroup"/>
|
||||
|
||||
Reference in New Issue
Block a user