vcs: Convert "RearrangeBeforeCheckinHandler" to kotlin

GitOrigin-RevId: 4a122431e3a778b2794a192f150484caa33e0614
This commit is contained in:
Konstantin Kolosovsky
2019-07-02 06:52:16 +03:00
committed by intellij-monorepo-bot
parent 40304da22a
commit 2297d52fe6
2 changed files with 40 additions and 72 deletions
@@ -1,55 +1,52 @@
// 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;
// Copyright 2000-2019 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;
import com.intellij.codeInsight.actions.RearrangeCodeProcessor;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.DumbService;
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 org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.intellij.codeInsight.CodeInsightBundle
import com.intellij.codeInsight.actions.RearrangeCodeProcessor
import com.intellij.openapi.fileEditor.FileDocumentManager
import com.intellij.openapi.project.DumbService
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.CommitContext
import com.intellij.openapi.vcs.changes.ui.BooleanCommitOption
import com.intellij.openapi.vcs.checkin.CheckinHandlerUtil.getPsiFiles
import com.intellij.openapi.vcs.ui.RefreshableOnComponent
public class RearrangeBeforeCheckinHandler extends CheckinHandler implements CheckinMetaHandler {
public static final String COMMAND_NAME = CodeInsightBundle.message("process.rearrange.code.before.commit");
open class RearrangeCheckinHandlerFactory : CheckinHandlerFactory() {
override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler =
RearrangeBeforeCheckinHandler(panel.project, panel)
}
private final Project myProject;
private final CheckinProjectPanel myPanel;
open class RearrangeBeforeCheckinHandler(
private val project: Project,
private val panel: CheckinProjectPanel
) : CheckinHandler(),
CheckinMetaHandler {
public RearrangeBeforeCheckinHandler(@NotNull Project project, @NotNull CheckinProjectPanel panel) {
myProject = project;
myPanel = panel;
}
private val settings get() = VcsConfiguration.getInstance(project)
@Override
@Nullable
public RefreshableOnComponent getBeforeCheckinConfigurationPanel() {
return new BooleanCommitOption(myPanel, VcsBundle.message("checkbox.checkin.options.rearrange.code"), true,
() -> getSettings().REARRANGE_BEFORE_PROJECT_COMMIT,
value -> getSettings().REARRANGE_BEFORE_PROJECT_COMMIT = value);
}
override fun getBeforeCheckinConfigurationPanel(): RefreshableOnComponent =
BooleanCommitOption(panel, VcsBundle.message("checkbox.checkin.options.rearrange.code"), true,
settings::REARRANGE_BEFORE_PROJECT_COMMIT)
private VcsConfiguration getSettings() {
return VcsConfiguration.getInstance(myProject);
}
override fun runCheckinHandlers(runnable: Runnable) {
val saveAndContinue = {
FileDocumentManager.getInstance().saveAllDocuments()
runnable.run()
}
@Override
public void runCheckinHandlers(@NotNull final Runnable finishAction) {
final Runnable performCheckoutAction = () -> {
FileDocumentManager.getInstance().saveAllDocuments();
finishAction.run();
};
if (VcsConfiguration.getInstance(myProject).REARRANGE_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(myProject)) {
new RearrangeCodeProcessor(myProject, CheckinHandlerUtil.getPsiFiles(myProject, myPanel.getVirtualFiles()), COMMAND_NAME,
performCheckoutAction, true).run();
if (settings.REARRANGE_BEFORE_PROJECT_COMMIT && !DumbService.isDumb(project)) {
RearrangeCodeProcessor(project, getPsiFiles(project, panel.virtualFiles), COMMAND_NAME, saveAndContinue, true).run()
}
else {
performCheckoutAction.run();
saveAndContinue() // TODO just runnable.run()?
}
}
companion object {
@JvmField
val COMMAND_NAME: String = CodeInsightBundle.message("process.rearrange.code.before.commit")
}
}
@@ -1,29 +0,0 @@
/*
* Copyright 2000-2014 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.vcs.checkin;
import com.intellij.openapi.vcs.CheckinProjectPanel;
import com.intellij.openapi.vcs.changes.CommitContext;
import org.jetbrains.annotations.NotNull;
public class RearrangeCheckinHandlerFactory extends CheckinHandlerFactory {
@Override
@NotNull
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull CommitContext commitContext) {
return new RearrangeBeforeCheckinHandler(panel.getProject(), panel);
}
}