From 403902b89a03fdb94040c1599d957c28fa60c1a3 Mon Sep 17 00:00:00 2001 From: Aleksey Pivovarov Date: Sat, 7 Sep 2013 19:40:35 +0400 Subject: [PATCH] Github: project-level settings --- plugins/github/src/META-INF/plugin.xml | 2 + .../ui/GithubCreatePullRequestDialog.java | 11 ++-- .../github/util/GithubProjectSettings.java | 57 +++++++++++++++++++ .../plugins/github/util/GithubSettings.java | 10 ---- 4 files changed, 66 insertions(+), 14 deletions(-) create mode 100644 plugins/github/src/org/jetbrains/plugins/github/util/GithubProjectSettings.java diff --git a/plugins/github/src/META-INF/plugin.xml b/plugins/github/src/META-INF/plugin.xml index 86240aa4e428..c448f7bc6d08 100644 --- a/plugins/github/src/META-INF/plugin.xml +++ b/plugins/github/src/META-INF/plugin.xml @@ -13,6 +13,8 @@ + diff --git a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreatePullRequestDialog.java b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreatePullRequestDialog.java index 528437e0dde2..bee11f79c11b 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreatePullRequestDialog.java +++ b/plugins/github/src/org/jetbrains/plugins/github/ui/GithubCreatePullRequestDialog.java @@ -23,6 +23,7 @@ import com.intellij.util.Consumer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; +import org.jetbrains.plugins.github.util.GithubProjectSettings; import org.jetbrains.plugins.github.util.GithubSettings; import javax.swing.*; @@ -33,8 +34,9 @@ import java.util.regex.Pattern; * @author Aleksey Pivovarov */ public class GithubCreatePullRequestDialog extends DialogWrapper { - private final GithubCreatePullRequestPanel myGithubCreatePullRequestPanel; - private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("[a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+"); + @NotNull private final GithubCreatePullRequestPanel myGithubCreatePullRequestPanel; + @NotNull private static final Pattern GITHUB_REPO_PATTERN = Pattern.compile("[a-zA-Z0-9_.-]+:[a-zA-Z0-9_.-]+"); + @NotNull private final Project myProject; public GithubCreatePullRequestDialog(@NotNull final Project project, @NotNull Collection branches, @@ -45,7 +47,8 @@ public class GithubCreatePullRequestDialog extends DialogWrapper { myGithubCreatePullRequestPanel.setBranches(branches); - String configBranch = GithubSettings.getInstance().getCreatePullRequestDefaultBranch(); + myProject = project; + String configBranch = GithubProjectSettings.getInstance(myProject).getCreatePullRequestDefaultBranch(); myGithubCreatePullRequestPanel.setSelectedBranch(configBranch != null ? configBranch : suggestedBranch); setTitle("Create Pull Request"); @@ -92,7 +95,7 @@ public class GithubCreatePullRequestDialog extends DialogWrapper { @Override protected void doOKAction() { super.doOKAction(); - GithubSettings.getInstance().setCreatePullRequestDefaultBranch(getTargetBranch()); + GithubProjectSettings.getInstance(myProject).setCreatePullRequestDefaultBranch(getTargetBranch()); } @Nullable diff --git a/plugins/github/src/org/jetbrains/plugins/github/util/GithubProjectSettings.java b/plugins/github/src/org/jetbrains/plugins/github/util/GithubProjectSettings.java new file mode 100644 index 000000000000..716da7479ff8 --- /dev/null +++ b/plugins/github/src/org/jetbrains/plugins/github/util/GithubProjectSettings.java @@ -0,0 +1,57 @@ +/* + * 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 org.jetbrains.plugins.github.util; + +import com.intellij.openapi.components.*; +import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * @author Aleksey Pivovarov + */ +@State( + name = "GithubProjectSettings", + storages = {@Storage( + file = StoragePathMacros.WORKSPACE_FILE )}) +public class GithubProjectSettings implements PersistentStateComponent { + private State myState = new State(); + + public State getState() { + return myState; + } + + public void loadState(State state) { + myState = state; + } + + public static class State { + @Nullable public String CREATE_PULL_REQUEST_DEFAULT_BRANCH = null; + } + + @Nullable + public String getCreatePullRequestDefaultBranch() { + return myState.CREATE_PULL_REQUEST_DEFAULT_BRANCH; + } + + public void setCreatePullRequestDefaultBranch(@NotNull String branch) { + myState.CREATE_PULL_REQUEST_DEFAULT_BRANCH = branch; + } + + public static GithubProjectSettings getInstance(@NotNull Project project) { + return ServiceManager.getService(project, GithubProjectSettings.class); + } +} diff --git a/plugins/github/src/org/jetbrains/plugins/github/util/GithubSettings.java b/plugins/github/src/org/jetbrains/plugins/github/util/GithubSettings.java index 4afb2a9672bd..9a3fc6a4b3aa 100644 --- a/plugins/github/src/org/jetbrains/plugins/github/util/GithubSettings.java +++ b/plugins/github/src/org/jetbrains/plugins/github/util/GithubSettings.java @@ -62,7 +62,6 @@ public class GithubSettings implements PersistentStateComponent TRUSTED_HOSTS = new ArrayList(); - @Nullable public String CREATE_PULL_REQUEST_DEFAULT_BRANCH = null; } public static GithubSettings getInstance() { @@ -121,11 +120,6 @@ public class GithubSettings implements PersistentStateComponent getTrustedHosts() { return myState.TRUSTED_HOSTS;