Skip to content

Commit

Permalink
v4.1.6版本更新
Browse files Browse the repository at this point in the history
  • Loading branch information
YangLang116 committed Aug 17, 2024
1 parent 6f4f6f8 commit 24d28dd
Show file tree
Hide file tree
Showing 46 changed files with 109 additions and 224 deletions.
82 changes: 5 additions & 77 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

###

## [4.1.6] - 2024-08-17

- `Base`: 修复 `modify PSI for non-committed Document`

## [4.1.5] - 2024-08-10

- `Flutter Resource`: 优化资源列表预览尺寸
Expand Down Expand Up @@ -54,80 +58,4 @@

## [3.0.6] - 2024-01-13

- `Base`: 代码优化

## [3.0.5] - 2023-12-24

- `Base`: 资源管理优化

## [3.0.4] - 2023-11-18

- `Dart Code`: 添加更多`LiveTemplate`片段

## [3.0.3] - 2023-10-09

- `Flutter Resource`: 上下文菜单新增删除功能
- `Flutter Resource`: 支持图片缺省展示
- `HttpMock`: 修复启动失败问题
- `Base`: 其他微小改动

## [3.0.2] - 2023-09-20

- `Dart Code`: 调整代码生成机制
- `Base`:
修改插件错误处理策略[(LogUtils)](https://github.com/YangLang116/iFlutter/blob/main/src/main/java/com/xtu/plugin/flutter/utils/LogUtils.java)
,将错误打印改为上报,所有上报的数据[(AdviceManager)](https://github.com/YangLang116/iFlutter/blob/main/src/main/java/com/xtu/plugin/flutter/advice/AdviceManager.java)
不涉及任何项目隐私,请放心使用

## [3.0.1] - 2023-09-08

- `Base`: 支持快速清除`Dart``YAML`文件中所有注释
- `Base`: Bug修复

## [3.0.0] - 2023-08-17

- `Base`: 优化插件性能 & Bug修复

## [2.2.7] - 2023-08-09

- `Flutter Resource`: 修复Bug
- `Suggestion & Feedback`: 调整错误上报方式

## [2.2.6] - 2023-08-07

- `Flutter Resource`: 更新窗口图标

## [2.2.5] - 2023-07-25

- `Flutter Resource`: Bug修复

## [2.2.4] - 2023-06-20

- `Suggestion & Feedback`: 新增错误与反馈渠道

## [2.2.3] - 2023-04-24

- `Flutter Resource`: 上下文菜单新增图片压缩功能

## [2.2.2] - 2023-04-23

- `Flutter Resource`: 上下文菜单新增图片路径拷贝功能
- `Base`: 一些其他小改动

## [2.2.1] - 2023-04-15

- `Flutter Resource`: 上下文菜单新增搜索功能

## [2.2.0] - 2023-04-13

- `Flutter Resource`: 新增图片资源管理窗口

## [2.1.4] - 2023-02-21

- `Upgrade`: 优化插件引导升级逻辑
- `Code`: 支持生成类构造器代码

## [2.1.3] - 2023-02-18

- `Code`: 优化 `fromJson``toJson` 代码生成逻辑
- `Covert Dependency To Local`: 兼容 Flutter 3.0
- `Base`: 代码优化
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -> https://plugins.jetbrains.com/docs/intellij/intellij-artifacts.html
pluginGroup=com.xtu.plugin
pluginName=iFlutter
pluginVersion=4.1.5
pluginVersion=4.1.6
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions.
pluginVerifierIdeVersions=2022.3.1
Expand Down
61 changes: 40 additions & 21 deletions src/main/java/com/xtu/plugin/flutter/base/utils/DartUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ public static boolean isBuiltInType(@NotNull DartReferenceExpression referenceEx
return FileUtils.isChildPath(flutterPath, dartFile.getPath());
}

//生成Dart类
//必须运行在EDT线程中
public static void createDartFile(@NotNull Project project,
@NotNull VirtualFile parentDir,
@NotNull String fileName,
@NotNull String fileContent) {
createDartFile(project, parentDir, fileName, fileContent, null);
}


public static void createDartFile(@NotNull Project project,
@NotNull VirtualFile parentDir,
@NotNull String fileName,
Expand All @@ -65,33 +71,46 @@ public static void createDartFile(@NotNull Project project,
Application application = ApplicationManager.getApplication();
application.assertIsDispatchThread();
WriteCommandAction.runWriteCommandAction(project, () -> {
FileTypeRegistry typeRegistry = FileTypeRegistry.getInstance();
FileType fileType = typeRegistry.getFileTypeByFileName(fileName);
PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);
PsiFile newFile = fileFactory.createFileFromText(fileName, fileType, fileContent);
CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
PsiFile formatFile = (PsiFile) styleManager.reformat(newFile);

PsiManager psiManager = PsiManager.getInstance(project);
PsiDirectory psiDir = psiManager.findDirectory(parentDir);
assert psiDir != null;
PsiFile resultFile;
PsiFile originFile = psiDir.findFile(fileName);
if (originFile == null) {
resultFile = psiDir.add(formatFile).getContainingFile();
} else {
resultFile = PsiUtils.replacePsiFile(originFile, formatFile);
}
PsiFile formatFile = createPsiFile(project, fileName, fileContent);
PsiFile resultFile = modifyPsiTree(project, parentDir, fileName, formatFile);
PsiUtils.saveDocument(project, resultFile);
if (listener != null) {
VirtualFile virtualFile = resultFile.getVirtualFile();
application.invokeLater(() -> listener.onCreated(virtualFile));
application.invokeLater(() -> listener.onFinish(virtualFile));
}
});
}


@NotNull
private static PsiFile createPsiFile(@NotNull Project project, @NotNull String fileName, @NotNull String fileContent) {
FileTypeRegistry typeRegistry = FileTypeRegistry.getInstance();
FileType fileType = typeRegistry.getFileTypeByFileName(fileName);
PsiFileFactory fileFactory = PsiFileFactory.getInstance(project);
PsiFile newFile = fileFactory.createFileFromText(fileName, fileType, fileContent);
CodeStyleManager styleManager = CodeStyleManager.getInstance(project);
return (PsiFile) styleManager.reformat(newFile);
}

@NotNull
private static PsiFile modifyPsiTree(@NotNull Project project,
@NotNull VirtualFile parentDir,
@NotNull String fileName,
@NotNull PsiFile formatFile) {
PsiManager psiManager = PsiManager.getInstance(project);
PsiDirectory psiDir = psiManager.findDirectory(parentDir);
assert psiDir != null;
PsiFile originFile = psiDir.findFile(fileName);
if (originFile == null) {
return psiDir.add(formatFile).getContainingFile();
} else {
return PsiUtils.replacePsiFile(originFile, formatFile);
}
}

public interface OnFileCreatedListener {

void onCreated(@NotNull VirtualFile virtualFile);
void onFinish(@NotNull VirtualFile virtualFile);

}
}
17 changes: 16 additions & 1 deletion src/main/java/com/xtu/plugin/flutter/base/utils/PsiUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.xtu.plugin.flutter.base.utils;

import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -47,7 +51,7 @@ public static <T> List<T> findChildren(@NotNull PsiElement parentPsi,
return resultList;
}

//替换psiFile.replace()处理,避免出现 `because "treeParent" is null`
@NotNull
public static PsiFile replacePsiFile(@NotNull PsiFile originFile, @NotNull PsiFile newFile) {
for (PsiElement oldEl : originFile.getChildren()) {
oldEl.delete();
Expand All @@ -57,4 +61,15 @@ public static PsiFile replacePsiFile(@NotNull PsiFile originFile, @NotNull PsiFi
}
return originFile;
}

public static void saveDocument(@NotNull Project project, @NotNull PsiFile file) {
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
Document document = psiDocumentManager.getDocument(file);
if (document != null) {
//sync psi - document
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
//sync psi - vfs
FileDocumentManager.getInstance().saveDocument(document);
}
}
}
22 changes: 7 additions & 15 deletions src/main/java/com/xtu/plugin/flutter/base/utils/PubSpecUtils.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.xtu.plugin.flutter.base.utils;

import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectUtil;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiTreeUtil;
Expand All @@ -24,6 +21,7 @@
import java.util.Map;


@SuppressWarnings("SpellCheckingInspection")
public class PubSpecUtils {

private static final String NODE_FLUTTER = "flutter";
Expand Down Expand Up @@ -206,20 +204,14 @@ public static void writeAssetList(@NotNull Project project,
YAMLSequence oldAssetSequence = getFlutterSequence(project, NODE_ASSET);
YAMLSequence oldFontSequence = getFlutterSequence(project, NODE_FONT);
YAMLElementGenerator elementGenerator = YAMLElementGenerator.getInstance(project);
//modify asset
if (modifyAsset(project, assetList, oldAssetSequence, elementGenerator)) return;
//modify font
if (modifyFont(project, fontList, oldFontSequence, elementGenerator)) return;
//modify asset and font
boolean assetModifyFail = modifyAsset(project, assetList, oldAssetSequence, elementGenerator);
boolean fontModifyFail = modifyFont(project, fontList, oldFontSequence, elementGenerator);
if (assetModifyFail && fontModifyFail) return;
//save document
YAMLFile rootPubspecFile = getRootPubSpecPsiFile(project);
assert rootPubspecFile != null;
PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project);
Document document = psiDocumentManager.getDocument(rootPubspecFile);
if (document != null) {
//sync psi - document
psiDocumentManager.doPostponedOperationsAndUnblockDocument(document);
//sync psi - vfs
FileDocumentManager.getInstance().saveDocument(document);
}
PsiUtils.saveDocument(project, rootPubspecFile);
//refresh UI
notifyPubSpecUpdate(project);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void generateFile(Project project, VirtualFile rDirectory,
.append("';\n");
}
fileStringBuilder.append("}\n");
DartUtils.createDartFile(project, rDirectory, FONT_FILE_NAME, fileStringBuilder.toString(), null);
DartUtils.createDartFile(project, rDirectory, FONT_FILE_NAME, fileStringBuilder.toString());
}

@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private String generateFile(@NotNull Project project, @NotNull VirtualFile rDire
}
fileStringBuilder.append("}\n");
String fileName = assetDirName.toLowerCase() + "_res.dart";
DartUtils.createDartFile(project, rDirectory, fileName, fileStringBuilder.toString(), null);
DartUtils.createDartFile(project, rDirectory, fileName, fileStringBuilder.toString());
return fileName;
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/resources/icons/code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions src/main/resources/icons/code_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/comment.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/comment_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions src/main/resources/icons/compress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions src/main/resources/icons/compress_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/copy_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/delete.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/delete_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/dependency.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion src/main/resources/icons/dependency_dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 24d28dd

Please sign in to comment.