Skip to content

Commit

Permalink
group enable desc and rename
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonoas committed May 2, 2024
1 parent 08e3f41 commit 3fc366a
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 63 deletions.
10 changes: 5 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group 'indi.bookmarkx'
version '1.2.0' // todo
version '1.2.1'

repositories {
mavenLocal()
Expand All @@ -26,12 +26,12 @@ intellij {
// version = '2023.1.3'
}

patchPluginXml { // todo
patchPluginXml {
sinceBuild = '210.0'
untilBuild = "233.*"
changeNotes = "1. 版本支持到 IDEA 2023.3.*<br>" +
"2. 支持行尾显示书签标题<br>" +
"3. 书签描述改用鼠标悬停方式显示"
changeNotes = "1. 分组支持添加描述" +
"2. 分组支持重命名" +
"3. 优化树节点样式显示"
}

tasks.named('initializeIntelliJPlugin') {
Expand Down
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import javax.swing.tree.DefaultTreeCellRenderer;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;

/**
* 标签树节点渲染
Expand All @@ -24,7 +23,7 @@
public class BmkTreeCellRenderer extends DefaultTreeCellRenderer {

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

@Override
Expand Down Expand Up @@ -69,9 +68,4 @@ private void setColor(boolean selected, boolean hasFocus) {
public Color getBorderSelectionColor() {
return BaseColors.TRANSPARENT;
}

@Override
public void paint(Graphics g) {
super.paint(g);
}
}
38 changes: 14 additions & 24 deletions src/main/java/indi/bookmarkx/ui/tree/BookmarkTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ private void initContextMenu() {
BookmarkTreeNode selectedNode = (BookmarkTreeNode) path.getLastPathComponent();
AbstractTreeNodeModel nodeModel = (AbstractTreeNodeModel) selectedNode.getUserObject();

new BookmarkCreatorDialog(project)
new BookmarkCreatorDialog(project, I18N.get("bookmark.create.title"))
.defaultName(nodeModel.getName())
.defaultDesc(nodeModel.getDesc())
.showAndCallback((name, desc) -> {
Expand Down Expand Up @@ -264,36 +264,26 @@ private void initContextMenu() {
return;
}

@SuppressWarnings("all")
InputValidatorEx validatorEx = inputString -> {
if (StringUtil.isBlank(inputString))
return I18N.get("groupNameNonNullMessage");
return null;
};

@SuppressWarnings("all")
String groupName = Messages.showInputDialog(
I18N.get("groupNameInputMessage"),
I18N.get("groupName"),
null,
null,
validatorEx
);

if (StringUtil.isBlank(groupName)) {
return;
}

BookmarkTreeNode parent;
if (selectedNode.isGroup()) {
parent = selectedNode;
} else {
parent = (BookmarkTreeNode) selectedNode.getParent();
}

// 新的分组节点
BookmarkTreeNode groupNode = new BookmarkTreeNode(new GroupNodeModel(groupName));
model.insertNodeInto(groupNode, parent, 0);
final GroupNodeModel groupNodeModel = new GroupNodeModel();

new BookmarkCreatorDialog(project, I18N.get("group.create.title"))
.showAndCallback((name, desc) -> {
groupNodeModel.setName(name);
groupNodeModel.setDesc(desc);

// 新的分组节点
BookmarkTreeNode groupNode = new BookmarkTreeNode(groupNodeModel);
model.insertNodeInto(groupNode, parent, 0);

BookmarkTree.this.model.nodeChanged(selectedNode);
});
};

imAddGroup.addActionListener(addGroupListener);
Expand Down
4 changes: 3 additions & 1 deletion src/main/resources/i18n/i18n_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ bookmark.notification.title=Bookmark-X Notification
bookmark.export.success=Bookmark export successful! File location: {0}
groupName=The group name
groupNameInputMessage=To add a name for the new grouping:
groupNameNonNullMessage=The group name cannot be empty
groupNameNonNullMessage=The group name cannot be empty
group.create.title=Enter the bookmark group information
bookmark.create.title=Enter the bookmark information
4 changes: 3 additions & 1 deletion src/main/resources/i18n/i18n_zh.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ bookmark.notification.title=Bookmark-X 通知
bookmark.export.success=书签导出成功!文件位置:{0}
groupName=分组名称
groupNameInputMessage=为新增的分组添加名称:
groupNameNonNullMessage=分组名称不能为空
groupNameNonNullMessage=分组名称不能为空
group.create.title=输入书签分组信息
bookmark.create.title=输入书签信息

0 comments on commit 3fc366a

Please sign in to comment.