Skip to content

Commit

Permalink
fix #20 持久化时判断OpenFileDescriptor是否为空
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonoas committed Jun 25, 2024
1 parent ea144f4 commit 5a5c2bc
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/main/java/indi/bookmarkx/RootWindowFactory.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package indi.bookmarkx;

import com.intellij.openapi.project.DumbAware;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
Expand All @@ -13,7 +14,7 @@
import java.util.Arrays;


public class RootWindowFactory implements ToolWindowFactory {
public class RootWindowFactory implements ToolWindowFactory, DumbAware {

/**
* plugin.xml 文件中的 key 名
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ protected void addColumIndex(Function<T, Object> function) {
SimpleColumnIndex<Set<T>> index = new SimpleColumnIndex<>();
dataList.forEach(data -> {
try {
saveHunt(data, function, (SimpleColumnIndex<Set<T>>) index);
saveHunt(data, function, index);
}catch (Exception ignored) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private List<BookmarkNodeModel> treeToList(BookmarkTree bookmarkTree,List<Bookma
}
toList(bookmarkTreeNode, list);
return list;

}

private static void toList(BookmarkTreeNode node, List<BookmarkNodeModel> list) {
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/indi/bookmarkx/model/BookmarkConverter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package indi.bookmarkx.model;

import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
Expand All @@ -13,9 +14,11 @@
*/
public class BookmarkConverter {

private static final Logger log = Logger.getInstance(BookmarkConverter.class);

public static BookmarkPO convertToPO(AbstractTreeNodeModel model) {

if (model instanceof BookmarkNodeModel) {
if (model instanceof BookmarkNodeModel && model.isBookmark()) {
BookmarkNodeModel nodeModel = (BookmarkNodeModel) model;

BookmarkPO po = new BookmarkPO();
Expand All @@ -27,8 +30,13 @@ public static BookmarkPO convertToPO(AbstractTreeNodeModel model) {
po.setDesc(nodeModel.getDesc());
po.setBookmark(true);

VirtualFile file = nodeModel.getOpenFileDescriptor().getFile();
po.setVirtualFilePath(file.getPath());
OpenFileDescriptor fileDescriptor = nodeModel.getOpenFileDescriptor();
if (null != fileDescriptor) {
VirtualFile file = fileDescriptor.getFile();
po.setVirtualFilePath(file.getPath());
} else {
log.warn(String.format("%s指向的位置已不存在", nodeModel.getName()));
}
return po;
} else {
GroupNodeModel nodeModel = (GroupNodeModel) model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class TreeLoadTask extends Task.Backgroundable {
private DefaultTreeModel treeModel;

public TreeLoadTask(Project project, BookmarkTree tree) {
super(project, "Loading Tree Data");
super(project, "Loading tree data");
this.project = project;
this.tree = tree;
}
Expand Down

0 comments on commit 5a5c2bc

Please sign in to comment.