diff --git a/java/compiler/impl/intellij.java.compiler.impl.iml b/java/compiler/impl/intellij.java.compiler.impl.iml
index 041bc5d5365f..1f856b8ed96a 100644
--- a/java/compiler/impl/intellij.java.compiler.impl.iml
+++ b/java/compiler/impl/intellij.java.compiler.impl.iml
@@ -29,6 +29,7 @@
+
diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/vcs/UnloadedModulesCompilationCheckinHandler.java b/java/compiler/impl/src/com/intellij/compiler/impl/vcs/UnloadedModulesCompilationCheckinHandler.java
index 40619d3d9d29..a7a67ba2fe68 100644
--- a/java/compiler/impl/src/com/intellij/compiler/impl/vcs/UnloadedModulesCompilationCheckinHandler.java
+++ b/java/compiler/impl/src/com/intellij/compiler/impl/vcs/UnloadedModulesCompilationCheckinHandler.java
@@ -1,4 +1,4 @@
-// Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.compiler.impl.vcs;
import com.intellij.CommonBundle;
@@ -19,6 +19,7 @@ import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.changes.CommitExecutor;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
@@ -26,15 +27,12 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowId;
import com.intellij.openapi.wm.ToolWindowManager;
-import com.intellij.ui.NonFocusableCheckBox;
import com.intellij.util.PairConsumer;
import com.intellij.util.containers.ContainerUtil;
-import com.intellij.util.ui.JBUI;
import com.intellij.xml.util.XmlStringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
@@ -58,33 +56,15 @@ public class UnloadedModulesCompilationCheckinHandler extends CheckinHandler {
return null;
}
- JCheckBox checkBox = new NonFocusableCheckBox(CompilerBundle.message("checkbox.text.compile.affected.unloaded.modules"));
- return new RefreshableOnComponent() {
- @Override
- public JComponent getComponent() {
- return JBUI.Panels.simplePanel().addToLeft(checkBox);
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_AFFECTED_UNLOADED_MODULES_BEFORE_COMMIT = checkBox.isSelected();
- }
-
- @Override
- public void restoreState() {
- checkBox.setSelected(CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_AFFECTED_UNLOADED_MODULES_BEFORE_COMMIT);
- }
- };
+ return new BooleanCommitOption(myCheckinPanel, CompilerBundle.message("checkbox.text.compile.affected.unloaded.modules"), false,
+ () -> getSettings().COMPILE_AFFECTED_UNLOADED_MODULES_BEFORE_COMMIT,
+ value -> getSettings().COMPILE_AFFECTED_UNLOADED_MODULES_BEFORE_COMMIT = value);
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer additionalDataConsumer) {
- if (!CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_AFFECTED_UNLOADED_MODULES_BEFORE_COMMIT
- || ModuleManager.getInstance(myProject).getUnloadedModuleDescriptions().isEmpty()) {
+ if (!getSettings().COMPILE_AFFECTED_UNLOADED_MODULES_BEFORE_COMMIT ||
+ ModuleManager.getInstance(myProject).getUnloadedModuleDescriptions().isEmpty()) {
return ReturnResult.COMMIT;
}
@@ -142,6 +122,11 @@ public class UnloadedModulesCompilationCheckinHandler extends CheckinHandler {
}
}
+ @NotNull
+ private CompilerWorkspaceConfiguration getSettings() {
+ return CompilerWorkspaceConfiguration.getInstance(myProject);
+ }
+
private enum BuildResult { SUCCESSFUL, FAILED, CANCELED }
public static class Factory extends CheckinHandlerFactory {
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt
new file mode 100644
index 000000000000..ed36af9953d4
--- /dev/null
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/ui/BooleanCommitOption.kt
@@ -0,0 +1,32 @@
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
+package com.intellij.openapi.vcs.changes.ui
+
+import com.intellij.openapi.vcs.CheckinProjectPanel
+import com.intellij.openapi.vcs.checkin.CheckinHandlerUtil
+import com.intellij.openapi.vcs.ui.RefreshableOnComponent
+import com.intellij.ui.NonFocusableCheckBox
+import java.util.function.Consumer
+import javax.swing.JComponent
+
+open class BooleanCommitOption(panel: CheckinProjectPanel,
+ text: String,
+ disableWhenDumb: Boolean,
+ private val getter: () -> Boolean,
+ private val setter: Consumer) : RefreshableOnComponent {
+ protected val checkBox = NonFocusableCheckBox(text).also {
+ if (disableWhenDumb) CheckinHandlerUtil.disableWhenDumb(panel.project, it, "Impossible until indices are up-to-date")
+ }
+
+ override fun refresh() {
+ }
+
+ override fun saveState() {
+ setter.accept(checkBox.isSelected)
+ }
+
+ override fun restoreState() {
+ checkBox.isSelected = getter()
+ }
+
+ override fun getComponent(): JComponent = checkBox
+}
\ No newline at end of file
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CheckinHandlerUtil.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CheckinHandlerUtil.java
index a04f98e002f8..03709085e9bd 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CheckinHandlerUtil.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CheckinHandlerUtil.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2016 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
import com.intellij.openapi.components.impl.stores.IProjectStore;
@@ -82,7 +68,7 @@ public class CheckinHandlerUtil {
return false;
}
- static void disableWhenDumb(@NotNull Project project, @NotNull JCheckBox checkBox, @NotNull String tooltip) {
+ public static void disableWhenDumb(@NotNull Project project, @NotNull JCheckBox checkBox, @NotNull String tooltip) {
boolean dumb = DumbService.isDumb(project);
checkBox.setEnabled(!dumb);
checkBox.setToolTipText(dumb ? tooltip : "");
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeAnalysisBeforeCheckinHandler.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeAnalysisBeforeCheckinHandler.java
index d0fdb635ea0a..d28af731b123 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeAnalysisBeforeCheckinHandler.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeAnalysisBeforeCheckinHandler.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
@@ -31,14 +17,12 @@ import com.intellij.openapi.vcs.CodeSmellDetector;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.changes.CommitExecutor;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
-import com.intellij.ui.NonFocusableCheckBox;
import com.intellij.util.PairConsumer;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
-import java.awt.*;
import java.util.List;
/**
@@ -62,30 +46,9 @@ public class CodeAnalysisBeforeCheckinHandler extends CheckinHandler {
@Override
@Nullable
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- final JCheckBox checkBox = new NonFocusableCheckBox(VcsBundle.message("before.checkin.standard.options.check.smells"));
- return new RefreshableOnComponent() {
- @Override
- public JComponent getComponent() {
- JPanel panel = new JPanel(new BorderLayout());
- panel.add(checkBox);
- CheckinHandlerUtil.disableWhenDumb(myProject, checkBox, "Code analysis is impossible until indices are up-to-date");
- return panel;
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- getSettings().CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT = checkBox.isSelected();
- }
-
- @Override
- public void restoreState() {
- checkBox.setSelected(getSettings().CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT);
- }
- };
+ return new BooleanCommitOption(myCheckinPanel, VcsBundle.message("before.checkin.standard.options.check.smells"), true,
+ () -> getSettings().CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT,
+ value -> getSettings().CHECK_CODE_SMELLS_BEFORE_PROJECT_COMMIT = value);
}
private VcsConfiguration getSettings() {
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeCleanupCheckinHandlerFactory.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeCleanupCheckinHandlerFactory.java
index e7ff13530570..35093a2cef87 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeCleanupCheckinHandlerFactory.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/CodeCleanupCheckinHandlerFactory.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
@@ -24,13 +10,11 @@ import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.changes.CommitContext;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.ui.NonFocusableCheckBox;
import org.jetbrains.annotations.NotNull;
-import javax.swing.*;
-import java.awt.*;
import java.util.List;
@@ -52,44 +36,24 @@ public class CodeCleanupCheckinHandlerFactory extends CheckinHandlerFactory {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- final JCheckBox cleanupCodeCb = new NonFocusableCheckBox(VcsBundle.message("before.checkin.cleanup.code"));
- return new RefreshableOnComponent() {
- @Override
- public JComponent getComponent() {
- final JPanel cbPanel = new JPanel(new BorderLayout());
- cbPanel.add(cleanupCodeCb, BorderLayout.WEST);
- CheckinHandlerUtil
- .disableWhenDumb(myProject, cleanupCodeCb, "Code analysis is impossible until indices are up-to-date");
- return cbPanel;
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- VcsConfiguration.getInstance(myProject).CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT = cleanupCodeCb.isSelected();
- }
-
- @Override
- public void restoreState() {
- cleanupCodeCb.setSelected(VcsConfiguration.getInstance(myProject).CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT);
- }
- };
+ return new BooleanCommitOption(myPanel, VcsBundle.message("before.checkin.cleanup.code"), true,
+ () -> getSettings().CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT,
+ value -> getSettings().CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT = value);
}
-
@Override
public void runCheckinHandlers(@NotNull Runnable runnable) {
- if (VcsConfiguration.getInstance(myProject).CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) {
-
+ if (getSettings().CHECK_CODE_CLEANUP_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) {
List filesToProcess = CheckinHandlerUtil.filterOutGeneratedAndExcludedFiles(myPanel.getVirtualFiles(), myProject);
GlobalInspectionContextBase.modalCodeCleanup(myProject, new AnalysisScope(myProject, filesToProcess), runnable);
-
} else {
runnable.run();
}
}
+
+ @NotNull
+ private VcsConfiguration getSettings() {
+ return VcsConfiguration.getInstance(myProject);
+ }
}
}
\ No newline at end of file
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java
index ae06fc4a0020..b5a99ac18601 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/OptimizeImportsBeforeCheckinHandler.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
@@ -24,14 +10,12 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.vfs.VirtualFile;
-import com.intellij.ui.NonFocusableCheckBox;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
-import java.awt.*;
import java.util.Collection;
public class OptimizeImportsBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler {
@@ -49,31 +33,9 @@ public class OptimizeImportsBeforeCheckinHandler extends CheckinHandler implemen
@Override
@Nullable
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- final JCheckBox optimizeBox = new NonFocusableCheckBox(VcsBundle.message("checkbox.checkin.options.optimize.imports"));
- CheckinHandlerUtil.disableWhenDumb(myProject, optimizeBox, "Impossible until indices are up-to-date");
- return new RefreshableOnComponent() {
- @Override
- public JComponent getComponent() {
- final JPanel panel = new JPanel(new GridLayout(1, 0));
- panel.add(optimizeBox);
- return panel;
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT = optimizeBox.isSelected();
- }
-
- @Override
- public void restoreState() {
- optimizeBox.setSelected(getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT);
- }
- };
-
+ return new BooleanCommitOption(myPanel, VcsBundle.message("checkbox.checkin.options.optimize.imports"), true,
+ () -> getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT,
+ value -> getSettings().OPTIMIZE_IMPORTS_BEFORE_PROJECT_COMMIT = value);
}
protected VcsConfiguration getSettings() {
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/RearrangeBeforeCheckinHandler.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/RearrangeBeforeCheckinHandler.java
index 6e2111f34bcb..a2116812543d 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/RearrangeBeforeCheckinHandler.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/RearrangeBeforeCheckinHandler.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
import com.intellij.codeInsight.CodeInsightBundle;
@@ -23,14 +9,11 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
-import com.intellij.ui.NonFocusableCheckBox;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
-import java.awt.*;
-
public class RearrangeBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler {
public static final String COMMAND_NAME = CodeInsightBundle.message("process.rearrange.code.before.commit");
@@ -45,30 +28,9 @@ public class RearrangeBeforeCheckinHandler extends CheckinHandler implements Che
@Override
@Nullable
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- final JCheckBox rearrangeBox = new NonFocusableCheckBox(VcsBundle.message("checkbox.checkin.options.rearrange.code"));
- CheckinHandlerUtil.disableWhenDumb(myProject, rearrangeBox, "Impossible until indices are up-to-date");
- return new RefreshableOnComponent() {
- @Override
- public JComponent getComponent() {
- final JPanel panel = new JPanel(new GridLayout(1, 0));
- panel.add(rearrangeBox);
- return panel;
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- getSettings().REARRANGE_BEFORE_PROJECT_COMMIT = rearrangeBox.isSelected();
- }
-
- @Override
- public void restoreState() {
- rearrangeBox.setSelected(getSettings().REARRANGE_BEFORE_PROJECT_COMMIT);
- }
- };
+ return new BooleanCommitOption(myPanel, VcsBundle.message("checkbox.checkin.options.rearrange.code"), true,
+ () -> getSettings().REARRANGE_BEFORE_PROJECT_COMMIT,
+ value -> getSettings().REARRANGE_BEFORE_PROJECT_COMMIT = value);
}
private VcsConfiguration getSettings() {
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java
index 579c137b959d..791d8d3dc249 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/ReformatBeforeCheckinHandler.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
@@ -23,15 +9,13 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.formatter.FormatterUtil;
-import com.intellij.ui.NonFocusableCheckBox;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
-import java.awt.*;
import java.util.Collection;
public class ReformatBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler {
@@ -46,31 +30,9 @@ public class ReformatBeforeCheckinHandler extends CheckinHandler implements Chec
@Override
@Nullable
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- final JCheckBox reformatBox = new NonFocusableCheckBox(VcsBundle.message("checkbox.checkin.options.reformat.code"));
- CheckinHandlerUtil.disableWhenDumb(myProject, reformatBox, "Impossible until indices are up-to-date");
- return new RefreshableOnComponent() {
- @Override
- public JComponent getComponent() {
- final JPanel panel = new JPanel(new GridLayout(1, 0));
- panel.add(reformatBox);
- return panel;
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- getSettings().REFORMAT_BEFORE_PROJECT_COMMIT = reformatBox.isSelected();
- }
-
- @Override
- public void restoreState() {
- reformatBox.setSelected(getSettings().REFORMAT_BEFORE_PROJECT_COMMIT);
- }
- };
-
+ return new BooleanCommitOption(myPanel, VcsBundle.message("checkbox.checkin.options.reformat.code"), true,
+ () -> getSettings().REFORMAT_BEFORE_PROJECT_COMMIT,
+ value -> getSettings().REFORMAT_BEFORE_PROJECT_COMMIT = value);
}
protected VcsConfiguration getSettings() {
diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java
index 919e856f99f8..a3038c4e3498 100644
--- a/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java
+++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/checkin/TodoCheckinHandler.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2016 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.openapi.vcs.checkin;
import com.intellij.ide.IdeBundle;
@@ -38,6 +24,7 @@ import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsConfiguration;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.CommitExecutor;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowManager;
@@ -77,12 +64,13 @@ public class TodoCheckinHandler extends CheckinHandler {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- JCheckBox checkBox = new JCheckBox(VcsBundle.message("before.checkin.new.todo.check", ""));
- return new RefreshableOnComponent() {
+ return new BooleanCommitOption(myCheckinProjectPanel, VcsBundle.message("before.checkin.new.todo.check", ""), true,
+ () -> myConfiguration.CHECK_NEW_TODO, value -> myConfiguration.CHECK_NEW_TODO = value) {
+ @NotNull
@Override
public JComponent getComponent() {
JPanel panel = new JPanel(new BorderLayout(4, 0));
- panel.add(checkBox, BorderLayout.WEST);
+ panel.add(getCheckBox(), BorderLayout.WEST);
setFilterText(myConfiguration.myTodoPanelSettings.todoFilterName);
if (myConfiguration.myTodoPanelSettings.todoFilterName != null) {
myTodoFilter = TodoConfiguration.getInstance().getTodoFilter(myConfiguration.myTodoPanelSettings.todoFilterName);
@@ -104,31 +92,16 @@ public class TodoCheckinHandler extends CheckinHandler {
}
}, null);
panel.add(linkLabel, BorderLayout.CENTER);
-
- CheckinHandlerUtil.disableWhenDumb(myProject, checkBox, "TODO check is impossible until indices are up-to-date");
return panel;
}
private void setFilterText(String filterName) {
if (filterName == null) {
- checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", IdeBundle.message("action.todo.show.all")));
- } else {
- checkBox.setText(VcsBundle.message("before.checkin.new.todo.check", "Filter: " + filterName));
+ getCheckBox().setText(VcsBundle.message("before.checkin.new.todo.check", IdeBundle.message("action.todo.show.all")));
+ }
+ else {
+ getCheckBox().setText(VcsBundle.message("before.checkin.new.todo.check", "Filter: " + filterName));
}
- }
-
- @Override
- public void refresh() {
- }
-
- @Override
- public void saveState() {
- myConfiguration.CHECK_NEW_TODO = checkBox.isSelected();
- }
-
- @Override
- public void restoreState() {
- checkBox.setSelected(myConfiguration.CHECK_NEW_TODO);
}
};
}
diff --git a/plugins/copyright/intellij.copyright.iml b/plugins/copyright/intellij.copyright.iml
index 8c739e000cf7..7201012b95d1 100644
--- a/plugins/copyright/intellij.copyright.iml
+++ b/plugins/copyright/intellij.copyright.iml
@@ -20,5 +20,6 @@
+
\ No newline at end of file
diff --git a/plugins/copyright/src/com/maddyhome/idea/copyright/actions/UpdateCopyrightCheckinHandlerFactory.java b/plugins/copyright/src/com/maddyhome/idea/copyright/actions/UpdateCopyrightCheckinHandlerFactory.java
index d3f090393ecc..b79c4a08c8a6 100644
--- a/plugins/copyright/src/com/maddyhome/idea/copyright/actions/UpdateCopyrightCheckinHandlerFactory.java
+++ b/plugins/copyright/src/com/maddyhome/idea/copyright/actions/UpdateCopyrightCheckinHandlerFactory.java
@@ -1,18 +1,4 @@
-/*
- * Copyright 2000-2015 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.
- */
+// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.maddyhome.idea.copyright.actions;
@@ -20,6 +6,7 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.changes.CommitContext;
import com.intellij.openapi.vcs.changes.CommitExecutor;
+import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption;
import com.intellij.openapi.vcs.checkin.CheckinHandler;
import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory;
import com.intellij.openapi.vcs.ui.RefreshableOnComponent;
@@ -28,11 +15,9 @@ import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.util.PairConsumer;
-import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
-import javax.swing.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -44,34 +29,24 @@ public class UpdateCopyrightCheckinHandlerFactory extends CheckinHandlerFactory
return new CheckinHandler() {
@Override
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
- final JCheckBox updateCopyrightCb = new JCheckBox("Update copyright");
- return new RefreshableOnComponent() {
- public JComponent getComponent() {
- return JBUI.Panels.simplePanel().addToLeft(updateCopyrightCb);
- }
-
- public void refresh() {
- }
-
- public void saveState() {
- UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT = updateCopyrightCb.isSelected();
- }
-
- public void restoreState() {
- updateCopyrightCb.setSelected(UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT);
- }
- };
+ return new BooleanCommitOption(panel, "Update copyright", false, () -> getSettings().UPDATE_COPYRIGHT,
+ value -> getSettings().UPDATE_COPYRIGHT = value);
}
@Override
public ReturnResult beforeCheckin(@Nullable CommitExecutor executor, PairConsumer additionalDataConsumer) {
- if (UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject()).UPDATE_COPYRIGHT) {
+ if (getSettings().UPDATE_COPYRIGHT) {
new UpdateCopyrightProcessor(panel.getProject(), null, getPsiFiles()).run();
FileDocumentManager.getInstance().saveAllDocuments();
}
return super.beforeCheckin();
}
+ @NotNull
+ private UpdateCopyrightCheckinHandlerState getSettings() {
+ return UpdateCopyrightCheckinHandlerState.getInstance(panel.getProject());
+ }
+
private PsiFile[] getPsiFiles() {
final Collection files = panel.getVirtualFiles();
final List psiFiles = new ArrayList<>();