Skip to content

Commit

Permalink
[fix]:添加tips按钮 修复超链接无法点击
Browse files Browse the repository at this point in the history
  • Loading branch information
darksheep committed Jun 11, 2023
1 parent 07e9657 commit 635bc6e
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "com.darksheep"
version = "2023-0605"
version = "2023-0611"

repositories {
/*上述代码将阿里云Maven仓库设置为优先级最高,
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/darksheep/sheepnote/CodeNoteAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
String selectedText = editor.getSelectionModel().getSelectedText();
// 如果没有选中代码,弹出提示
if (StringUtil.isEmpty(selectedText)) {
Messages.showMessageDialog("请先选中要做笔记的代码!", "提示", Messages.getInformationIcon());
Messages.showMessageDialog("Please select code to make note for", "notice", Messages.getInformationIcon());
return;
}

Expand All @@ -55,11 +55,11 @@ public void actionPerformed(@NotNull AnActionEvent e) {
// 创建一个 DialogBuilder 对象
DialogBuilder dialogBuilder = new DialogBuilder(e.getProject());
// 设置 Dialog 的标题
dialogBuilder.setTitle("代码笔记");
dialogBuilder.setTitle("code note");
// 设置 Dialog 的内容
dialogBuilder.setCenterPanel(createNotePanel(selectedText, dialogBuilder,startLine,filePath));
// 添加确认按钮
dialogBuilder.addOkAction().setText("保存");
dialogBuilder.addOkAction().setText("save");
// 添加取消按钮
dialogBuilder.addCancelAction();
// 显示 Dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.darksheep.sheepnote.data.NoteData;
import com.intellij.ide.DataManager;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.editor.Document;
Expand All @@ -20,14 +19,11 @@
import com.intellij.openapi.fileTypes.SyntaxHighlighter;
import com.intellij.openapi.fileTypes.SyntaxHighlighterFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.HyperlinkLabel;
import com.intellij.ui.ScrollPaneFactory;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import java.awt.*;
Expand All @@ -49,8 +45,6 @@ public class NoteDetailPanel extends JPanel{

private Project currentProject;

private JScrollPane scrollPane;

private GridBagConstraints gbc = new GridBagConstraints();

public NoteDetailPanel() {
Expand Down Expand Up @@ -83,6 +77,7 @@ public NoteDetailPanel() {
// File path + line number
filePathLabel = new HyperlinkLabel();
filePathLabel.addHyperlinkListener(e -> {
Project currentProject = CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(this));
if (currentProject == null || noteData == null) {
return;
}
Expand Down Expand Up @@ -112,7 +107,7 @@ public NoteDetailPanel() {

// Selected code
codeEditor = createCodeEditor();
scrollPane = ScrollPaneFactory.createScrollPane(codeEditor.getComponent(), true);
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(codeEditor.getComponent(), true);
add(scrollPane, gbc);
}

Expand All @@ -125,13 +120,14 @@ private Editor createCodeEditor() {
editor.getSettings().setLineNumbersShown(true);
editor.getSettings().setIndentGuidesShown(false);

ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
/* ProjectManager.getInstance().addProjectManagerListener(new ProjectManagerListener() {
@Override
public void projectClosed(@NotNull Project project) {
if(codeEditor!=null){
//会导致非新窗口 打开项目时 绿色
*//* if(codeEditor!=null){
EditorFactory.getInstance().releaseEditor(codeEditor);
codeEditor = null;
}
}*//*
ProjectManagerListener.super.projectClosed(project);
}
Expand All @@ -140,7 +136,7 @@ public void projectOpened(@NotNull Project project) {
currentProject = project;
ProjectManagerListener.super.projectOpened(project);
}
});
});*/
return editor;
}

Expand All @@ -150,13 +146,13 @@ private Document createDocument() {
return document;
}
private void setEditorContent(String content) {
if(codeEditor == null){
/* if(codeEditor == null){
remove(scrollPane);
codeEditor = createCodeEditor();
scrollPane = ScrollPaneFactory.createScrollPane(codeEditor.getComponent(), true);
add(scrollPane, gbc);
}
}*/
if (codeEditor != null) {
/**
* 设置 文本必须在ApplicationManager.getApplication().runWriteAction中设置 否则会报错
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
import com.darksheep.sheepnote.data.NoteData;
import com.darksheep.sheepnote.editor.failtest.NoteDataHandler;
import com.darksheep.sheepnote.editor.utils.EditorHelper;
import com.darksheep.sheepnote.icon.PluginIcons;
import com.darksheep.sheepnote.toolWindow.divider.CustomSplitPaneUI;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.DumbAwareAction;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogBuilder;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.components.JBLabel;
import com.intellij.ui.components.JBList;
import com.intellij.ui.content.Content;
import com.intellij.util.messages.MessageBus;
Expand All @@ -22,6 +28,8 @@
import java.util.Date;
import java.util.List;

import static com.intellij.analysis.JvmAnalysisBundle.message;

public class NoteListToolWindowFactory implements ToolWindowFactory {

public static final String TOOL_WINDOW_ID = "sheepNote";
Expand Down Expand Up @@ -69,9 +77,40 @@ public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindo
mainPanel.setResizeWeight(0.5);
mainPanel.setUI(new CustomSplitPaneUI());

toolWindow.setTitleActions(List.of(
initTipsAction()
));

Content toolsWindowContent = toolWindow.getContentManager().getFactory().createContent(mainPanel, "", false);
toolWindow.getContentManager().addContent(toolsWindowContent);
}
@NotNull
private DumbAwareAction initTipsAction() {
return new DumbAwareAction("about and tips", "", AllIcons.Actions.IntentionBulb) {
@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
DialogBuilder dialogBuilder = new DialogBuilder(anActionEvent.getProject());
// 设置 Dialog 的标题
dialogBuilder.setTitle("About and Tips");
JPanel panel = new JPanel(new BorderLayout());
String details ="<ul style=\"font-size:14px\">\n" +
" <li><strong>this plugin github Repository:</strong> <a href='https://github.com/darkSheep404/sheepNote'><span>https://github.com/darkSheep404/sheepNote</span></a></li>\n" +
" <li><span>please feel free to <strong>PR/Issue</strong> this repository for any <strong>question and bugs</strong></span></li>\n" +
" <li><span>if this note do helps to you ,please feel free to <strong>a star to this repo</strong></span></a></li> \n" +
" </ul>";
JBLabel label = new JBLabel("<html>" + details + "</html>");
//设置可复制
label.setCopyable(true);
panel.add(label, BorderLayout.CENTER);
// 设置 Dialog 的内容
dialogBuilder.setCenterPanel(panel);
// 添加取消按钮
dialogBuilder.addCancelAction();
// 显示 Dialog
dialogBuilder.show();
}
};
}

/**
* 模糊搜索笔记列表中 noteTitle 与输入文本匹配的笔记
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.darksheep.sheepnote.ui.dialog;

public class TipsDialog {
}

0 comments on commit 635bc6e

Please sign in to comment.