Skip to content

Commit

Permalink
Merge branch '231.later'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonoas committed Mar 24, 2024
2 parents 9805559 + 59d77aa commit c1816ba
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ patchPluginXml {

}


tasks.named('initializeIntelliJPlugin') {
enabled = false
}
Expand Down
66 changes: 66 additions & 0 deletions src/main/java/indi/bookmarkx/painter/LineEndPainter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package indi.bookmarkx.painter;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.EditorLinePainter;
import com.intellij.openapi.editor.LineExtensionInfo;
import com.intellij.openapi.editor.markup.TextAttributes;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.ui.JBColor;
import indi.bookmarkx.MyPersistent;
import indi.bookmarkx.common.data.BookmarkArrayListTable;
import indi.bookmarkx.model.BookmarkNodeModel;
import indi.bookmarkx.model.po.BookmarkPO;

import java.awt.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;

/**
* @author: codeleep
* @createTime: 2023/12/14 23:37
* @description:
*/
public class LineEndPainter extends EditorLinePainter {

private static final Logger LOG = Logger.getInstance(MyPersistent.class);

private BookmarkNodeModel bookmarkNodeModel;

private BookmarkArrayListTable bookmarkArrayListTable;

private Project project;

@Override
public Collection<LineExtensionInfo> getLineExtensions(Project project, VirtualFile virtualFile, int i) {
if (this.project != project || bookmarkArrayListTable == null) {
this.project = project;
bookmarkArrayListTable = BookmarkArrayListTable.getInstance(project);
}
List<LineExtensionInfo> result = new ArrayList<>();
try {
List<BookmarkNodeModel> onlyIndex = bookmarkArrayListTable.getOnlyIndex(virtualFile.getPath());
bookmarkNodeModel = LineEndPainter.findLine(onlyIndex, i);
if (bookmarkNodeModel == null) {
return null;
}
result.add(new LineExtensionInfo(String.format("// %s", bookmarkNodeModel.getName()), new TextAttributes(null, null, JBColor.GRAY, null, Font.PLAIN)));
return result;
} catch (Exception e) {
LOG.error("渲染行尾注释失败 path:"+virtualFile.getPath(), e);
}
return null;
}

public static BookmarkNodeModel findLine(List<BookmarkNodeModel> list, int i) {
if (list == null || list.isEmpty()){
return null;
}
Optional<BookmarkNodeModel> bookmarkNodeModel1 = list.stream().filter(bookmarkNodeModel -> bookmarkNodeModel.getOpenFileDescriptor().getLine() == i).findFirst();
return bookmarkNodeModel1.orElse(null);
}

}

85 changes: 85 additions & 0 deletions src/main/java/indi/bookmarkx/ui/pannel/ShowBookmarkTipPanel.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package indi.bookmarkx.ui.pannel;

import com.intellij.ui.EditorTextField;
import com.intellij.ui.components.JBPanel;
import com.intellij.ui.components.JBScrollPane;
import com.intellij.util.ui.JBDimension;
import com.intellij.util.ui.JBUI;
import indi.bookmarkx.model.AbstractTreeNodeModel;
import indi.bookmarkx.model.BookmarkNodeModel;
import org.jetbrains.annotations.NotNull;

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

/**
* @author: codeleep
* @createTime: 2024/03/21 11:49
* @description:
*/
public class ShowBookmarkTipPanel extends JBPanel {

private final EditorTextField tfName = new EditorTextField();
private final EditorTextField tfDesc = new EditorTextField();

public ShowBookmarkTipPanel(@NotNull AbstractTreeNodeModel abstractTreeNodeModel) {
tfName.setText(abstractTreeNodeModel.getName());
if (abstractTreeNodeModel.isBookmark()) {
tfDesc.setText(((BookmarkNodeModel)abstractTreeNodeModel).getDesc());
}
init(abstractTreeNodeModel);
}


private void init(@NotNull AbstractTreeNodeModel abstractTreeNodeModel) {
setLayout(new GridBagLayout());
tfName.setPlaceholder("输入展示在标签上的文本");
tfName.setEnabled(false);
tfDesc.setPlaceholder("输入对标签的详细描述");
tfDesc.setEnabled(false);
tfDesc.setOneLineMode(false);
tfDesc.setBorder(JBUI.Borders.empty());
// 创建 GridBagConstraints 对象
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.BOTH;
constraints.insets = JBUI.insets(5);

// 第一行第一列
JLabel lbName = new JLabel("标签");
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 0;
constraints.weighty = 0;
add(lbName, constraints);

// 第一行第二列
constraints.gridx = 1;
constraints.gridy = 0;
constraints.weightx = 1;
constraints.weighty = 0;
add(tfName, constraints);

if (abstractTreeNodeModel.isBookmark()) {
// 第二行第一列
JLabel lbDesc = new JLabel("描述");
constraints.gridx = 0;
constraints.gridy = 1;
constraints.weightx = 0;
constraints.weighty = 1;
add(lbDesc, constraints);

// 第二行第二列
JBScrollPane scrollPane = new JBScrollPane(tfDesc);
scrollPane.setPreferredSize(new JBDimension(400, 150));
scrollPane.setBorder(JBUI.Borders.empty());

constraints.gridx = 1;
constraints.gridy = 1;
constraints.weightx = 1;
constraints.weighty = 1;
add(scrollPane, constraints);
}

}

}

0 comments on commit c1816ba

Please sign in to comment.