mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[copyright] allow updating on save (IDEA-265711)
explanatory comments added GitOrigin-RevId: b8298c76d5b95c81ce56306f1851b478a6c34b85
This commit is contained in:
committed by
intellij-monorepo-bot
parent
8f07857901
commit
9e5da028c1
@@ -72,4 +72,6 @@ radio.location.in.file.before.package=Before package
|
||||
radio.location.in.file.before.root.tag=Before root tag
|
||||
radio.location.in.file.before.doctype=Before doctype
|
||||
settings.copyright.formatting.add.blank.line.before=Add blank line &before
|
||||
link.label.configure.copyright.settings=Configure copyright settings
|
||||
link.label.configure.copyright.settings=Configure...
|
||||
label.updates.existing.copyrights.e.g.changes.year.or.updated.notice=Updates existing copyrights e.g., changes year or updated notice
|
||||
label.no.copyright.configured=No copyright is configured
|
||||
+21
-6
@@ -3,6 +3,8 @@ package com.maddyhome.idea.copyright.actions;
|
||||
|
||||
import com.intellij.codeInsight.actions.onSave.ActionOnSaveInfoBase;
|
||||
import com.intellij.copyright.CopyrightBundle;
|
||||
import com.intellij.copyright.CopyrightManager;
|
||||
import com.intellij.ide.actionsOnSave.ActionOnSaveComment;
|
||||
import com.intellij.ide.actionsOnSave.ActionOnSaveContext;
|
||||
import com.intellij.ide.actionsOnSave.ActionOnSaveInfo;
|
||||
import com.intellij.ide.actionsOnSave.ActionOnSaveInfoProvider;
|
||||
@@ -13,28 +15,41 @@ import com.maddyhome.idea.copyright.ui.CopyrightProjectConfigurable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class CopyrightOnSaveInfoProvider extends ActionOnSaveInfoProvider {
|
||||
|
||||
public static final String UPDATE_COPYRIGHT_ON_SAVE = "update.copyright.on.save";
|
||||
public static final boolean UPDATE_COPYRIGHT_BY_DEFAULT = false;
|
||||
private static final String UPDATE_COPYRIGHT_ON_SAVE = "update.copyright.on.save";
|
||||
private static final boolean UPDATE_COPYRIGHT_BY_DEFAULT = false;
|
||||
|
||||
public static boolean isUpdateCopyrightOnSaveEnabled(@NotNull Project project) {
|
||||
return PropertiesComponent.getInstance(project).getBoolean(UPDATE_COPYRIGHT_ON_SAVE, UPDATE_COPYRIGHT_BY_DEFAULT);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected @NotNull Collection<? extends ActionOnSaveInfo> getActionOnSaveInfos(@NotNull ActionOnSaveContext context) {
|
||||
return Collections.singletonList(new ActionOnSaveInfoBase(context, CopyrightBundle.message("before.checkin.update.copyright"),
|
||||
UPDATE_COPYRIGHT_ON_SAVE, UPDATE_COPYRIGHT_BY_DEFAULT) {
|
||||
return List.of(new ActionOnSaveInfoBase(context, CopyrightBundle.message("before.checkin.update.copyright"), UPDATE_COPYRIGHT_ON_SAVE, UPDATE_COPYRIGHT_BY_DEFAULT) {
|
||||
@Override
|
||||
public @NotNull List<? extends ActionLink> getActionLinks() {
|
||||
return List.of(createGoToPageInSettingsLink(CopyrightBundle.message("link.label.configure.copyright.settings"),
|
||||
CopyrightProjectConfigurable.ID));
|
||||
}
|
||||
|
||||
private boolean hasCopyrights() {
|
||||
return CopyrightManager.getInstance(context.getProject()).hasAnyCopyrights();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaveActionApplicable() {
|
||||
return hasCopyrights();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionOnSaveComment getComment() {
|
||||
return ActionOnSaveComment.info(CopyrightBundle.message(hasCopyrights()
|
||||
? "label.updates.existing.copyrights.e.g.changes.year.or.updated.notice"
|
||||
: "label.no.copyright.configured"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -167,15 +167,15 @@ public final class UpdateCopyrightAction extends BaseAnalysisAction {
|
||||
public static class UpdateCopyrightTask extends Task.ConditionalModal {
|
||||
private final Map<PsiFile, Runnable> preparations = new LinkedHashMap<>();
|
||||
private @NotNull final AnalysisScope myScope;
|
||||
private boolean mySelected;
|
||||
private final boolean myAllowReplacement;
|
||||
|
||||
public UpdateCopyrightTask(@NotNull Project project,
|
||||
@NotNull AnalysisScope scope,
|
||||
boolean cbSelected,
|
||||
boolean allowReplacement,
|
||||
@NotNull PerformInBackgroundOption options) {
|
||||
super(project, CopyrightBundle.message("task.title.prepare.copyright"), true, options);
|
||||
myScope = scope;
|
||||
mySelected = cbSelected;
|
||||
myAllowReplacement = allowReplacement;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -189,7 +189,7 @@ public final class UpdateCopyrightAction extends BaseAnalysisAction {
|
||||
final Module module = ModuleUtilCore.findModuleForPsiElement(file);
|
||||
final UpdateCopyrightProcessor processor = new UpdateCopyrightProcessor(file.getProject(), module, file);
|
||||
|
||||
final Runnable runnable = processor.preprocessFile(file, mySelected);
|
||||
final Runnable runnable = processor.preprocessFile(file, myAllowReplacement);
|
||||
if (runnable != EmptyRunnable.getInstance()) {
|
||||
preparations.put(file, runnable);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user