Skip to content

Commit

Permalink
Merge pull request #26 from Alireza-Moh/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
Alireza-Moh authored Feb 7, 2025
2 parents a80e403 + 2eeb612 commit d4f7cd3
Show file tree
Hide file tree
Showing 44 changed files with 1,061 additions and 390 deletions.
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "at.alirezamoh.whisperer-for-laravel"
version = "1.1.6"
version = "1.2.0"

repositories {
mavenCentral()
Expand Down Expand Up @@ -33,7 +33,7 @@ tasks {
}

patchPluginXml {
sinceBuild.set("232")
sinceBuild.set("241")
untilBuild.set("243.*")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import at.alirezamoh.whisperer_for_laravel.support.utils.DirectoryUtils;
import at.alirezamoh.whisperer_for_laravel.support.notification.Notify;
import at.alirezamoh.whisperer_for_laravel.support.utils.PluginUtils;
import at.alirezamoh.whisperer_for_laravel.support.utils.StrUtils;
import at.alirezamoh.whisperer_for_laravel.support.TemplateLoader;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.application.ApplicationManager;
Expand Down Expand Up @@ -61,7 +60,7 @@ public class GenerateHelperMethodsAction extends BaseAction {
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
project = anActionEvent.getProject();

if (PluginUtils.isLaravelFrameworkNotInstalled(project)) {
if (PluginUtils.shouldNotCompleteOrNavigate(project)) {
Notify.notifyWarning(project, "Laravel Framework is not installed");
return;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package at.alirezamoh.whisperer_for_laravel.actions;

import at.alirezamoh.whisperer_for_laravel.actions.views.InertiaPageView;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;

public class InertiaPageAction extends BaseAction {
@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
Project project = anActionEvent.getProject();
InertiaPageView inertiaPageView = new InertiaPageView(project);

if (inertiaPageView.showAndGet()) {
this.create(
inertiaPageView.getInertiaPageModel(),
"inertiaPage.ftl",
true,
project
);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ public class StartPluginAction extends DefaultActionGroup {
@Override
public void update(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project != null && !PluginUtils.isDumbMode(project)) {
if (!PluginUtils.isLaravelProject(project)) {
e.getPresentation().setEnabledAndVisible(false);
}
}

if (project == null) {
e.getPresentation().setEnabledAndVisible(false);
}
boolean isVisible =
project != null
&& !PluginUtils.isDumbMode(project)
&& PluginUtils.isLaravelProject(project);

e.getPresentation().setEnabledAndVisible(isVisible);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package at.alirezamoh.whisperer_for_laravel.actions.models;

import at.alirezamoh.whisperer_for_laravel.settings.SettingsState;

/**
* Model representing an inertia page
*/
public class InertiaPageModel extends BaseModel {
private String pageName;

private boolean withOptionsApi;

private boolean vue;

/**
* @param name The name of the inertia page
* @param unformattedModuleFullPath The unformatted module full path
* @param formattedModuleFullPath The formatted module full path
*/
public InertiaPageModel(
SettingsState settingsState,
String name,
String unformattedModuleFullPath,
String formattedModuleFullPath,
String defaultDestination,
boolean withOptionsApi,
String pageType
)
{
super(
settingsState,
name,
unformattedModuleFullPath,
formattedModuleFullPath,
defaultDestination,
"",
pageType,
""
);

this.pageName = getName();
this.withOptionsApi = withOptionsApi;
this.vue = pageType.equals(".vue");
}

@Override
public void setWithoutModuleSrc() {
this.withoutModuleSrcPath = true;
}

public String getPageName() {
return pageName;
}

public boolean isWithOptionsApi() {
return withOptionsApi;
}

public boolean isVue() {
return vue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public LaravelDbBuilder(List<Method> methods, SettingsState settingsState) {
this.slug = "";
this.name = "whisperer_for_laravel_base_db_query_builder";
this.extension = ".php";
this.destination = "/" + ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH;
this.destination = settingsState.getProjectDirectoryPath() + ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH;

if (settingsState.isProjectDirectoryEmpty()) {
this.filePath = ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH + this.name + ".php";
}
else {
this.filePath = ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH + settingsState.getProjectDirectoryPath() + "/" + this.name + ".php";
this.filePath = settingsState.getProjectDirectoryPath() + ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH + this.name + ".php";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public LaravelModelGeneration(String namespace, List<LaravelModel> laravelModels
this.slug = "";
this.name = "whisperer_for_laravel_models_" + shortUuid;
this.extension = ".php";
this.destination = "/" + ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH;
this.destination = settingsState.getProjectDirectoryPath() + ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH;

if (settingsState.isProjectDirectoryEmpty()) {
this.filePath = ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH + this.name + ".php";
}
else {
this.filePath = ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH + settingsState.getProjectDirectoryPath() + "/" + this.name + ".php";
this.filePath = settingsState.getProjectDirectoryPath() + ProjectDefaultPaths.WHISPERER_FOR_LARAVEL_DIR_PATH + this.name + ".php";
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package at.alirezamoh.whisperer_for_laravel.actions.views;

import at.alirezamoh.whisperer_for_laravel.actions.models.InertiaPageModel;
import at.alirezamoh.whisperer_for_laravel.packages.inertia.InertiaPageCollector;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.ValidationInfo;
import com.intellij.util.ui.JBUI;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.util.Objects;

public class InertiaPageView extends BaseDialog {
/**
* Text field for entering the inertia page name
*/
private JTextField inertiaPageNameTextField;

/**
* Select the destination path
*/
protected ComboBox<String> resourcePageDirectoryComboBox;

/**
* Select the page variant
*/
protected ComboBox<String> pageVariantComboBox;

/**
* Select the page type
*/
protected ComboBox<String> pageTypeComboBox;

/**
* @param project The current project
*/
public InertiaPageView(Project project) {
super(project);

setTitle("Create Inertia Page");
setSize(500, 200);
setResizable(false);
init();
}

/**
* Returns the Inertia page model representing an inertia page
* @return The inertia page model
*/
public InertiaPageModel getInertiaPageModel() {
return new InertiaPageModel(
projectSettingState,
inertiaPageNameTextField.getText(),
"",
"",
resourcePageDirectoryComboBox.getItem(),
Objects.equals(pageVariantComboBox.getItem(), "Options API"),
pageTypeComboBox.getItem()
);
}

/**
* Returns the focused component when the dialog opens
* @return The preferred focused component
*/
@Override
public @Nullable JComponent getPreferredFocusedComponent() {
return inertiaPageNameTextField;
}

/**
* Validates the dialog input
* @return Validation info if there are errors, null otherwise
*/
@Override
protected @Nullable ValidationInfo doValidate() {
String text = inertiaPageNameTextField.getText().trim();

if (text.isEmpty()) {
return new ValidationInfo("", inertiaPageNameTextField);
}
return null;
}

/**
* Creates the center panel of the dialog
* @return The center panel
*/
@Override
protected JComponent createCenterPanel() {
contentPane = new JPanel();
contentPane.setLayout(new GridBagLayout());

inertiaPageNameTextField = new JTextField();
resourcePageDirectoryComboBox = new ComboBox<>(InertiaPageCollector.getInertiaPaths(project).toArray(new String[0]));
pageVariantComboBox = new ComboBox<>(new String[]{"Options API", "Composition API"});
pageTypeComboBox = new ComboBox<>(new String[]{".vue", ".jsx"});

gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 1.0;

gbc.gridx = 0;
gbc.gridy = 0;

gbc.insets = JBUI.insetsLeft(3);
contentPane.add(new JLabel("Enter page name:"), gbc);
gbc.insets = JBUI.insetsLeft(0);
gbc.insets = JBUI.insetsBottom(15);
gbc.gridy++;
contentPane.add(inertiaPageNameTextField, gbc);
inertiaPageNameTextField.requestFocusInWindow();

gbc.gridy++;
gbc.insets = JBUI.insetsLeft(3);
contentPane.add(new JLabel("Page type:"), gbc);
gbc.insets = JBUI.insetsLeft(0);
gbc.insets = JBUI.insetsBottom(15);
gbc.gridy++;
contentPane.add(pageTypeComboBox, gbc);

gbc.gridy++;
gbc.insets = JBUI.insetsLeft(3);
contentPane.add(new JLabel("Page variant: (Ignore if it's not a Vue file)"), gbc);
gbc.insets = JBUI.insetsLeft(0);
gbc.insets = JBUI.insetsBottom(15);
gbc.gridy++;
contentPane.add(pageVariantComboBox, gbc);

gbc.gridy++;
this.gbc.insets = JBUI.insetsLeft(3);
this.contentPane.add(new JLabel("Page resource directory:"), this.gbc);
this.gbc.gridy++;
this.gbc.insets = JBUI.insetsLeft(0);
this.gbc.insets = JBUI.insetsBottom(15);
this.contentPane.add(resourcePageDirectoryComboBox, this.gbc);

return contentPane;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected void addCompletions(@NotNull CompletionParameters completionParameters
PsiElement element = completionParameters.getPosition();
Project project = element.getProject();

if (!PluginUtils.isLaravelProject(project) && PluginUtils.isLaravelFrameworkNotInstalled(project)) {
if (PluginUtils.shouldNotCompleteOrNavigate(project)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BladeXComponentGotoDeclarationHandler implements GotoDeclarationHan

Project project = sourceElement.getProject();

if (!PluginUtils.isLaravelProject(project) && PluginUtils.isLaravelFrameworkNotInstalled(project)) {
if (PluginUtils.shouldNotCompleteOrNavigate(project)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferen
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
Project project = psiElement.getProject();

if (!PluginUtils.isLaravelProject(project) && PluginUtils.isLaravelFrameworkNotInstalled(project)) {
if (PluginUtils.shouldNotCompleteOrNavigate(project)) {
return PsiReference.EMPTY_ARRAY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void registerReferenceProviders(@NotNull PsiReferenceRegistrar psiReferen
public PsiReference @NotNull [] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) {
Project project = psiElement.getProject();

if (!PluginUtils.isLaravelProject(project) && PluginUtils.isLaravelFrameworkNotInstalled(project)) {
if (PluginUtils.shouldNotCompleteOrNavigate(project)) {
return PsiReference.EMPTY_ARRAY;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.intellij.openapi.project.Project;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.indexing.FileBasedIndex;
import com.intellij.util.indexing.IdFilter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand Down Expand Up @@ -39,10 +40,14 @@ private void getKeysFromConfigIndex(@NotNull Project project, FileBasedIndex fil

return true;
},
GlobalSearchScope.projectScope(project)
GlobalSearchScope.projectScope(project),
IdFilter.getProjectIdFilter(project, false)
);
return true;
}, project);
},
GlobalSearchScope.projectScope(project),
IdFilter.getProjectIdFilter(project, false)
);
}

private void getVariantsFromServiceProviderIndex(@NotNull Project project, FileBasedIndex fileBasedIndex, List<LookupElementBuilder> variants) {
Expand Down Expand Up @@ -70,11 +75,15 @@ private void getVariantsFromServiceProviderIndex(@NotNull Project project, FileB

return true;
},
GlobalSearchScope.projectScope(project)
GlobalSearchScope.projectScope(project),
IdFilter.getProjectIdFilter(project, true)
);

return true;
}, project);
},
GlobalSearchScope.projectScope(project),
IdFilter.getProjectIdFilter(project, true)
);
}

private @NotNull String buildKeyValue(String value) {
Expand Down
Loading

0 comments on commit d4f7cd3

Please sign in to comment.