Skip to content

Commit

Permalink
1. 优化标签节点选中时的背景颜色
Browse files Browse the repository at this point in the history
2. 分组支持添加描述信息
  • Loading branch information
Nonoas committed May 3, 2024
1 parent 6c9c109 commit c90cace
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 90 deletions.
12 changes: 5 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.jetbrains.intellij' version '1.13.3'
id 'java'
id 'org.jetbrains.intellij' version '1.13.3'
}

group 'indi.bookmarkx'
Expand Down Expand Up @@ -29,13 +29,11 @@ intellij {

patchPluginXml {
sinceBuild = '231.0'
changeNotes = """
1.添加行尾显示标签概要<br>
"""

changeNotes = "1. 分组支持添加描述<br>" +
"2. 分组支持重命名<br>" +
"3. 优化树节点样式显示<br>"
}


tasks.named('initializeIntelliJPlugin') {
enabled = false
}
Expand All @@ -47,4 +45,4 @@ tasks.withType(JavaCompile).configureEach {

test {
useJUnitPlatform()
}
}
5 changes: 3 additions & 2 deletions src/main/java/indi/bookmarkx/BookmarksManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import indi.bookmarkx.common.I18N;
import indi.bookmarkx.common.data.BookmarkArrayListTable;
import indi.bookmarkx.ui.dialog.BookmarkCreatorDialog;
import indi.bookmarkx.model.BookmarkConverter;
Expand Down Expand Up @@ -79,7 +80,7 @@ public void createBookRemark(Project project, Editor editor, VirtualFile file) {
}
final BookmarkNodeModel finalBookmarkNodeModel = bookmarkNodeModel;
final boolean addFlag = add;
new BookmarkCreatorDialog(project)
new BookmarkCreatorDialog(project, I18N.get("bookmark.create.title"))
.defaultName(defaultName)
.defaultDesc(defaultDesc)
.showAndCallback((name, desc) -> {
Expand All @@ -88,7 +89,7 @@ public void createBookRemark(Project project, Editor editor, VirtualFile file) {
bookmarkArrayListTable.insert(finalBookmarkNodeModel);
if (addFlag) {
submitCreateBookRemark(finalBookmarkNodeModel, editor);
}else {
} else {
if (!Objects.isNull(toolWindowRootPanel)) {
BookmarkTree tree = toolWindowRootPanel.tree();
BookmarkTreeNode nodeByModel = tree.getNodeByModel(finalBookmarkNodeModel);
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/indi/bookmarkx/common/BaseColors.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ public class BaseColors {

public static final Color PURPLE = new Color(128, 0, 255, 60);

public static final Color TRANSPARENT = new Color(0, 0, 0, 0);


}
8 changes: 6 additions & 2 deletions src/main/java/indi/bookmarkx/common/data/ArrayListTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import indi.bookmarkx.common.data.index.SimpleColumnIndex;

import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.function.Function;

/**
Expand All @@ -26,7 +30,7 @@ protected void addColumIndex(Function<T, Object> function) {
dataList.forEach(data -> {
try {
saveHunt(data, function, (SimpleColumnIndex<Set<T>>) index);
}catch (Exception e) {
}catch (Exception ignored) {

}
});
Expand Down
28 changes: 17 additions & 11 deletions src/main/java/indi/bookmarkx/ui/dialog/BookmarkCreatorDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ public class BookmarkCreatorDialog extends DialogWrapper {

private Project project;


public BookmarkCreatorDialog(Project project) {
public BookmarkCreatorDialog(Project project, String title) {
super(true);
setTitle("输入书签信息");
this.project = project;
init();
initSelf(project, title);
}

@Override
protected void init() {
super.init();
private void initSelf(Project project, String title) {
setTitle(title);
this.project = project;
init();
}

public BookmarkCreatorDialog defaultName(String name) {
Expand All @@ -51,11 +49,19 @@ public BookmarkCreatorDialog defaultDesc(String desc) {
return this;
}

public BookmarkCreatorDialog namePrompt(String name) {
this.tfName.setPlaceholder(name);
return this;
}

public BookmarkCreatorDialog descPrompt(String name) {
this.tfDesc.setPlaceholder(name);
return this;
}

@Override
protected JComponent createCenterPanel() {

tfName.setPlaceholder("输入展示在标签上的文本");
tfDesc.setPlaceholder("输入对标签的详细描述");
tfDesc.setOneLineMode(false);
tfDesc.setBorder(JBUI.Borders.empty());

Expand Down Expand Up @@ -85,7 +91,7 @@ public void documentChanged(@NotNull DocumentEvent event) {
constraints.insets = JBUI.insets(5);

// 第一行第一列
JLabel lbName = new JLabel("标签");
JLabel lbName = new JLabel("名称");
constraints.gridx = 0;
constraints.gridy = 0;
constraints.weightx = 0;
Expand Down
17 changes: 7 additions & 10 deletions src/main/java/indi/bookmarkx/ui/pannel/BookmarkTipPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import com.intellij.util.ui.HtmlPanel;
import com.intellij.util.ui.JBUI;
import indi.bookmarkx.model.AbstractTreeNodeModel;
import indi.bookmarkx.model.BookmarkNodeModel;
import indi.bookmarkx.utils.HtmlUtil;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;

import javax.swing.*;
import javax.swing.JScrollPane;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.BorderLayout;
import java.awt.Dimension;

/**
* 用于展示标签树节点的描述信息
Expand Down Expand Up @@ -42,15 +42,12 @@ protected static class TipHtmlPanel extends HtmlPanel {
private final String TITLE_TAG = "h3";
private final String DESC_TAG = "";

public TipHtmlPanel(@NotNull AbstractTreeNodeModel abstractTreeNodeModel) {
public TipHtmlPanel(@NotNull AbstractTreeNodeModel nodeModel) {
StringBuilder sb = new StringBuilder();
String name = HtmlUtil.wrapText(TITLE_TAG, abstractTreeNodeModel.getName());
String name = HtmlUtil.wrapText(TITLE_TAG, nodeModel.getName());
sb.append(name);
if (abstractTreeNodeModel.isBookmark()) {
BookmarkNodeModel model = (BookmarkNodeModel) abstractTreeNodeModel;
String desc = StringUtils.isNotBlank(model.getDesc()) ? model.getDesc() : "no description";
sb.append(desc);
}
String desc = StringUtils.isNotBlank(nodeModel.getDesc()) ? nodeModel.getDesc() : "no description";
sb.append(desc);
setBody(sb.toString());
Border borderWithPadding = JBUI.Borders.empty(0, 10, 10, 10);
setBorder(borderWithPadding);
Expand Down
71 changes: 71 additions & 0 deletions src/main/java/indi/bookmarkx/ui/tree/BmkTreeCellRenderer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package indi.bookmarkx.ui.tree;


import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.ui.UIUtil;
import indi.bookmarkx.common.BaseColors;

import javax.swing.Icon;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.Color;
import java.awt.Component;

/**
* 标签树节点渲染
*
* @author Nonoas
* @version 1.0
* @date 2024/5/2
* @since 1.2.1
*/
public class BmkTreeCellRenderer extends DefaultTreeCellRenderer {

public BmkTreeCellRenderer() {
// ReflectionUtil.setField(DefaultTreeCellRenderer.class, this, Boolean.TYPE, "fillBackground", false);
}

@Override
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean isLeaf,
int row,
boolean hasFocus) {

setColor(selected, hasFocus);

super.getTreeCellRendererComponent(tree, value, selected, expanded, isLeaf, row, hasFocus);

BookmarkTreeNode node = (BookmarkTreeNode) value;
Icon icon = null;
if (0 == row) {
// if is root node
icon = AllIcons.Nodes.Module;
} else if (row > 0) {
icon = node.isBookmark()
? IconLoader.findIcon("icons/bookmark.svg")
: AllIcons.Nodes.Folder;
}
setIcon(icon);
return this;
}

/**
* This method fix the difference of background color between the icon and text in the hover state
*/
private void setColor(boolean selected, boolean hasFocus) {
this.setBorderSelectionColor(null);
this.setBackgroundSelectionColor(null);
this.setBackgroundNonSelectionColor(null);
this.setBackground(UIUtil.getTreeBackground(selected, hasFocus));
this.setForeground(UIUtil.getTreeForeground(selected, hasFocus));
}

@Override
public Color getBorderSelectionColor() {
return BaseColors.TRANSPARENT;
}
}
Loading

0 comments on commit c90cace

Please sign in to comment.