mirror of https://gitee.com/makejava/EasyCode.git
兼容至2017.1并修复对比代码未自动格式化问题
This commit is contained in:
parent
eac2f33e43
commit
1ec88794ec
|
@ -7,8 +7,10 @@ import com.intellij.openapi.module.Module;
|
|||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.util.ReflectionUtil;
|
||||
import com.sjhy.plugin.config.Settings;
|
||||
import com.sjhy.plugin.constants.MsgValue;
|
||||
import com.sjhy.plugin.entity.Callback;
|
||||
import com.sjhy.plugin.entity.SaveFile;
|
||||
import com.sjhy.plugin.entity.TableInfo;
|
||||
|
@ -66,6 +68,11 @@ public class CodeGenerateServiceImpl implements CodeGenerateService {
|
|||
TableInfo selectedTableInfo = tableInfoService.getTableInfoAndConfig(cacheDataUtils.getSelectDbTable());
|
||||
// 获取所有选中的表信息
|
||||
List<TableInfo> tableInfoList = tableInfoService.getTableInfoAndConfig(cacheDataUtils.getDbTableList());
|
||||
// 校验选中表的保存路径是否正确
|
||||
if (StringUtils.isEmpty(selectedTableInfo.getSavePath())) {
|
||||
Messages.showInfoMessage(selectedTableInfo.getObj().getName() + "表配置信息不正确,请尝试重新配置", MsgValue.TITLE_INFO);
|
||||
return;
|
||||
}
|
||||
// 将未配置的表进行配置覆盖
|
||||
tableInfoList.forEach(tableInfo -> {
|
||||
if (StringUtils.isEmpty(tableInfo.getSavePath())) {
|
||||
|
|
|
@ -4,10 +4,15 @@ import com.intellij.diff.DiffContentFactory;
|
|||
import com.intellij.diff.DiffDialogHints;
|
||||
import com.intellij.diff.DiffManager;
|
||||
import com.intellij.diff.DiffRequestFactory;
|
||||
import com.intellij.diff.actions.impl.MutableDiffRequestChain;
|
||||
//import com.intellij.diff.actions.impl.MutableDiffRequestChain;
|
||||
import com.intellij.diff.chains.DiffRequestChain;
|
||||
import com.intellij.diff.contents.DiffContent;
|
||||
import com.intellij.diff.requests.DiffRequest;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
/**
|
||||
* @author makejava
|
||||
|
@ -24,18 +29,33 @@ public class CompareFileUtils {
|
|||
* @param rightFile 右边的文件
|
||||
*/
|
||||
public static void showCompareWindow(Project project, VirtualFile leftFile, VirtualFile rightFile) {
|
||||
DiffContentFactory contentFactory = DiffContentFactory.getInstance();
|
||||
DiffRequestFactory requestFactory = DiffRequestFactory.getInstance();
|
||||
|
||||
DiffContent leftContent = contentFactory.create(project, leftFile);
|
||||
DiffContent rightContent = contentFactory.create(project, rightFile);
|
||||
try {
|
||||
Class<?> cls = Class.forName("com.intellij.diff.actions.impl.MutableDiffRequestChain");
|
||||
// 新版支持
|
||||
DiffContentFactory contentFactory = DiffContentFactory.getInstance();
|
||||
DiffRequestFactory requestFactory = DiffRequestFactory.getInstance();
|
||||
|
||||
MutableDiffRequestChain chain = new MutableDiffRequestChain(leftContent, rightContent);
|
||||
DiffContent leftContent = contentFactory.create(project, leftFile);
|
||||
DiffContent rightContent = contentFactory.create(project, rightFile);
|
||||
|
||||
chain.setWindowTitle(requestFactory.getTitle(leftFile, rightFile));
|
||||
chain.setTitle1(requestFactory.getContentTitle(leftFile));
|
||||
chain.setTitle2(requestFactory.getContentTitle(rightFile));
|
||||
DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.MODAL);
|
||||
DiffRequestChain chain = (DiffRequestChain) cls.getConstructor(DiffContent.class, DiffContent.class).newInstance(leftContent, rightContent);
|
||||
// MutableDiffRequestChain chain = new MutableDiffRequestChain(leftContent, rightContent);
|
||||
|
||||
cls.getMethod("setWindowTitle", String.class).invoke(chain, requestFactory.getTitle(leftFile, rightFile));
|
||||
cls.getMethod("setTitle1", String.class).invoke(chain, requestFactory.getContentTitle(leftFile));
|
||||
cls.getMethod("setTitle2", String.class).invoke(chain, requestFactory.getContentTitle(rightFile));
|
||||
// chain.setWindowTitle(requestFactory.getTitle(leftFile, rightFile));
|
||||
// chain.setTitle1(requestFactory.getContentTitle(leftFile));
|
||||
// chain.setTitle2(requestFactory.getContentTitle(rightFile));
|
||||
DiffManager.getInstance().showDiff(project, chain, DiffDialogHints.MODAL);
|
||||
} catch (ClassNotFoundException e) {
|
||||
// 旧版兼容
|
||||
DiffRequest diffRequest = DiffRequestFactory.getInstance().createFromFiles(project, leftFile, rightFile);
|
||||
DiffManager.getInstance().showDiff(project, diffRequest, DiffDialogHints.MODAL);
|
||||
} catch (IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
ExceptionUtil.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.intellij.psi.PsiDirectory;
|
|||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.testFramework.LightVirtualFile;
|
||||
import com.intellij.util.ExceptionUtil;
|
||||
import com.sjhy.plugin.constants.MsgValue;
|
||||
import com.sjhy.plugin.entity.SaveFile;
|
||||
|
@ -98,7 +99,7 @@ public class FileUtils {
|
|||
LOG.assertTrue(dir != null);
|
||||
return psiManager.findDirectory(dir);
|
||||
} catch (IOException e) {
|
||||
LOG.error("path {} error", saveFile.getPath());
|
||||
LOG.error("path " + saveFile.getPath() + " error");
|
||||
ExceptionUtil.rethrow(e);
|
||||
return null;
|
||||
}
|
||||
|
@ -125,7 +126,19 @@ public class FileUtils {
|
|||
case Messages.NO:
|
||||
// 对比代码时也格式化代码
|
||||
if (saveFile.isReformat()) {
|
||||
reformatFile(saveFile.getProject(), Collections.singletonList(PsiManager.getInstance(saveFile.getProject()).findFile(saveFile.getVirtualFile())));
|
||||
// 保留旧文件内容,用新文件覆盖旧文件执行格式化,然后再还原旧文件内容
|
||||
String oldText = oldFile.getText();
|
||||
WriteCommandAction.runWriteCommandAction(saveFile.getProject(), () -> psiDocumentManager.getDocument(oldFile).setText(saveFile.getFile().getText()));
|
||||
// 提交所有改动,并非VCS中的提交文件
|
||||
PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
|
||||
reformatFile(saveFile.getProject(), Collections.singletonList(oldFile));
|
||||
// 提交所有改动,并非VCS中的提交文件
|
||||
PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
|
||||
String newText = oldFile.getText();
|
||||
WriteCommandAction.runWriteCommandAction(saveFile.getProject(), () -> psiDocumentManager.getDocument(oldFile).setText(oldText));
|
||||
// 提交所有改动,并非VCS中的提交文件
|
||||
PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
|
||||
saveFile.setVirtualFile(new LightVirtualFile(saveFile.getFile().getName(), saveFile.getFile().getFileType(), newText));
|
||||
}
|
||||
CompareFileUtils.showCompareWindow(saveFile.getProject(), fileDocumentManager.getFile(psiDocumentManager.getDocument(oldFile)), saveFile.getVirtualFile());
|
||||
return;
|
||||
|
@ -150,6 +163,8 @@ public class FileUtils {
|
|||
if (saveFile.isReformat()) {
|
||||
reformatFile(saveFile.getProject(), Collections.singletonList(finalFile));
|
||||
}
|
||||
// 提交所有改动,并非VCS中的提交文件
|
||||
PsiDocumentManager.getInstance(saveFile.getProject()).commitAllDocuments();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -163,7 +178,7 @@ public class FileUtils {
|
|||
if (CollectionUtil.isEmpty(psiFileList)) {
|
||||
return;
|
||||
}
|
||||
// 提交所有改动,并非CVS中的提交文件
|
||||
// 提交所有改动,并非VCS中的提交文件
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
// 尝试对文件进行格式化处理
|
||||
AbstractLayoutCodeProcessor processor = new ReformatCodeProcessor(project, psiFileList.toArray(new PsiFile[0]), null, false);
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.sjhy.plugin.tool;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
@ -91,7 +89,7 @@ public class NameUtils {
|
|||
* @return 类名
|
||||
*/
|
||||
public String getClsNameByFullName(String fullName) {
|
||||
return fullName.substring(fullName.lastIndexOf('.') + 1, fullName.length());
|
||||
return fullName.substring(fullName.lastIndexOf('.') + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -133,7 +131,7 @@ public class NameUtils {
|
|||
*/
|
||||
public String append(Object... objects) {
|
||||
|
||||
if (ArrayUtils.isEmpty(objects)) {
|
||||
if (objects == null || objects.length == 0) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
|
|
@ -109,6 +109,17 @@ public class GlobalConfigSettingPanel implements Configurable {
|
|||
return "Global Config";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topic in the help file which is shown when help for the configurable is requested.
|
||||
*
|
||||
* @return the help topic, or {@code null} if no help is available
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主面板对象
|
||||
*
|
||||
|
|
|
@ -315,6 +315,17 @@ public class MainSetting implements Configurable, Configurable.Composite {
|
|||
return "Easy Code";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topic in the help file which is shown when help for the configurable is requested.
|
||||
*
|
||||
* @return the help topic, or {@code null} if no help is available
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更多配置
|
||||
*
|
||||
|
|
|
@ -62,6 +62,17 @@ public class TableSettingPanel extends AbstractTableGroupPanel<ColumnConfigGroup
|
|||
return "Table Editor Config";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topic in the help file which is shown when help for the configurable is requested.
|
||||
*
|
||||
* @return the help topic, or {@code null} if no help is available
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
|
|
|
@ -139,6 +139,17 @@ public class TemplateSettingPanel implements Configurable {
|
|||
return "Template Setting";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topic in the help file which is shown when help for the configurable is requested.
|
||||
*
|
||||
* @return the help topic, or {@code null} if no help is available
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取主面板对象
|
||||
*
|
||||
|
|
|
@ -187,6 +187,17 @@ public class TypeMapperSetting implements Configurable {
|
|||
return "Type Mapper";
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the topic in the help file which is shown when help for the configurable is requested.
|
||||
*
|
||||
* @return the help topic, or {@code null} if no help is available
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public String getHelpTopic() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JComponent createComponent() {
|
||||
|
|
|
@ -119,6 +119,11 @@ public class TemplateEditor {
|
|||
|
||||
// 添加修改事件
|
||||
editor.getDocument().addDocumentListener(new DocumentListener() {
|
||||
@Override
|
||||
public void beforeDocumentChange(DocumentEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void documentChanged(@NotNull DocumentEvent event) {
|
||||
String text = editor.getDocument().getText();
|
||||
|
|
|
@ -151,7 +151,7 @@
|
|||
]]></change-notes>
|
||||
|
||||
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
|
||||
<idea-version since-build="172"/>
|
||||
<idea-version since-build="171.3780.107"/>
|
||||
|
||||
<!-- please see http://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
|
||||
on how to target different products -->
|
||||
|
|
Loading…
Reference in New Issue