Skip to content

Commit

Permalink
Merge pull request #171 from xdev-software/2024.3
Browse files Browse the repository at this point in the history
Changes for 2024.3
  • Loading branch information
AB-xdev authored Nov 11, 2024
2 parents f436d4d + c211a45 commit b7da700
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 55 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
pluginGroup=software.xdev.saveactions
pluginName=Save Actions X
# SemVer format -> https://semver.org
pluginVersion=1.3.2-SNAPSHOT
pluginVersion=1.4.0-SNAPSHOT
# IntelliJ Platform Properties -> https://plugins.jetbrains.com/docs/intellij/tools-gradle-intellij-plugin.html#configuration-intellij-extension
platformType=IC
platformVersion=2024.2.3
platformSinceBuild=242
platformVersion=243.21565.23
platformSinceBuild=243
# Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
# Example: platformBundledPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformBundledPlugins=com.intellij.java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
Expand Down Expand Up @@ -43,12 +41,6 @@ public void beforeAllDocumentsSaving()
LOGGER.debug(
"[+] Start SaveActionsDocumentManagerListener#beforeAllDocumentsSaving, " + this.project.getName());

if(REQUIRES_PROJECT_LOAD_IGNORE_WORKAROUND && isInvokedFromProjectLoadBefore243())
{
LOGGER.debug("Ignoring due to PROJECT_LOAD_IGNORE_WORKAROUND");
return;
}

final List<Document> unsavedDocuments = Arrays.asList(FileDocumentManager.getInstance().getUnsavedDocuments());
if(!unsavedDocuments.isEmpty())
{
Expand Down Expand Up @@ -83,38 +75,4 @@ private synchronized void initPsiDocManager()
this.psiDocumentManager = PsiDocumentManager.getInstance(this.project);
}
}

// region PROJECT_LOAD_IGNORE_WORKAROUND
// https://github.com/xdev-software/intellij-plugin-save-actions/issues/145
private static final boolean REQUIRES_PROJECT_LOAD_IGNORE_WORKAROUND =
determineIfRequiresProjectLoadIgnoreWorkaround();

@SuppressWarnings("checkstyle:MagicNumber")
static boolean determineIfRequiresProjectLoadIgnoreWorkaround()
{
try
{
// Problem was fixed in 2024.3
return ApplicationInfo.getInstance().getBuild().getBaselineVersion() < 243;
}
catch(final Exception ex)
{
LOGGER.warn("Failed to determine IDE version", ex);
return false;
}
}

@SuppressWarnings("checkstyle:MagicNumber")
static boolean isInvokedFromProjectLoadBefore243()
{
// The invoking method ProjectSettingsTracker$submitSettingsFilesRefresh is usually at index 17 and 18
return Stream.of(Thread.currentThread().getStackTrace())
.map(StackTraceElement::getClassName)
.skip(16)
.limit(5)
.anyMatch(s -> s.startsWith(
"com.intellij.openapi.externalSystem.autoimport.ProjectSettingsTracker$submitSettingsFilesRefresh"));
}

// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
import com.intellij.debugger.impl.DebuggerSession;
import com.intellij.debugger.ui.HotSwapUI;
import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionUiKind;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.actionSystem.ex.ActionUtil;
import com.intellij.openapi.actionSystem.impl.SimpleDataContext;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.compiler.CompilerManager;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.project.Project;
Expand Down Expand Up @@ -83,8 +86,16 @@ public enum BuildProcessor implements Processor
.add(EDITOR, FileEditorManager.getInstance(project).getSelectedTextEditor())
.setParent(null)
.build();
AnActionEvent event = AnActionEvent.createFromAnAction(anAction, null, UNKNOWN, dataContext);
anAction.actionPerformed(event);
AnActionEvent event = AnActionEvent.createEvent(
dataContext,
anAction.getTemplatePresentation().clone(),
UNKNOWN,
ActionUiKind.NONE,
null);

// Run Action on EDT thread
ApplicationManager.getApplication().invokeLater(() ->
ActionUtil.performActionDumbAwareWithCallbacks(anAction, event));
}
})
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private TextFieldWithBrowseButton getPath(final String configurationPath)
field.getField().setEnabled(false);
field.getField().setText(configurationPath);
final TextFieldWithBrowseButton resultPath = new TextFieldWithBrowseButton(field.getField());
resultPath.addBrowseFolderListener(null, null, null, descriptor, TEXT_FIELD_WHOLE_TEXT);
resultPath.addBrowseFolderListener(null, descriptor, TEXT_FIELD_WHOLE_TEXT);
return resultPath;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.function.Consumer;

import com.intellij.openapi.actionSystem.ActionManager;
import com.intellij.openapi.actionSystem.ActionUiKind;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DataContext;
Expand All @@ -16,26 +17,31 @@

public interface ShortcutActionConstants
{

Consumer<CodeInsightTestFixture> SAVE_ACTION_SHORTCUT_MANAGER = (fixture) ->
Consumer<CodeInsightTestFixture> SAVE_ACTION_SHORTCUT_MANAGER = fixture ->
WriteCommandAction.writeCommandAction(fixture.getProject()).run(() -> runFixure(fixture));

static void runFixure(CodeInsightTestFixture fixture)
static void runFixure(final CodeInsightTestFixture fixture)
{
// set modification timestamp ++
fixture.getFile().clearCaches();

ActionManager actionManager = ActionManager.getInstance();
AnAction action = actionManager.getAction(ShortcutAction.class.getName());
final ActionManager actionManager = ActionManager.getInstance();
final AnAction action = actionManager.getAction(ShortcutAction.class.getName());

DataContext dataContext = SimpleDataContext.builder()
final DataContext dataContext = SimpleDataContext.builder()
.add(PROJECT, fixture.getProject())
.add(PSI_FILE, fixture.getFile())
.setParent(null)
.build();

// call plugin on document
AnActionEvent event = AnActionEvent.createFromAnAction(action, null, "save-actions", dataContext);
final AnActionEvent event = AnActionEvent.createEvent(
dataContext,
action.getTemplatePresentation().clone(),
"save-actions",
ActionUiKind.NONE,
null);

new ShortcutAction().actionPerformed(event);
}
}

0 comments on commit b7da700

Please sign in to comment.