#5 fixed ChatDto.writeToFile
This commit is contained in:
@@ -19,8 +19,9 @@ public class ChatListWidget extends JTree {
|
||||
public ChatListWidget(Consumer<ChatDto> clickedFunction) {
|
||||
super();
|
||||
this.clickHandler = clickedFunction;
|
||||
setRootVisible(true);
|
||||
GenericProject rootProject = new GenericProject(new File(ChatDto.PROJECT_DIR));
|
||||
setRootVisible(false);
|
||||
setShowsRootHandles(true);
|
||||
GenericProject rootProject = new GenericProject(new File(GenericProject.PROJECT_DIR), null);
|
||||
DefaultMutableTreeNode rootNode = buildTree(rootProject);
|
||||
setModel(new DefaultTreeModel(rootNode));
|
||||
addTreeSelectionListener(e -> {
|
||||
|
||||
@@ -187,9 +187,9 @@ public class ChatWindow extends JPanel {
|
||||
if (name == null || name.isBlank())
|
||||
return;
|
||||
chatDto.setName(name);
|
||||
chatDto.writeToFile();
|
||||
onFirstSave.run();
|
||||
}
|
||||
chatDto.writeToFile();
|
||||
}
|
||||
|
||||
public void focusInput() {
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.formdev.flatlaf.extras.FlatSVGIcon.ColorFilter;
|
||||
|
||||
import de.derpandaa.plinfa.aiprovider.OpenAiProvider;
|
||||
import de.derpandaa.plinfa.dto.ChatDto;
|
||||
import de.derpandaa.plinfa.projects.GenericProject;
|
||||
|
||||
public class PlinfaWindow extends JFrame {
|
||||
|
||||
@@ -132,7 +133,7 @@ public class PlinfaWindow extends JFrame {
|
||||
}
|
||||
|
||||
OpenAiProvider.API_KEY = props.getProperty("OPENAI_KEY");
|
||||
ChatDto.PROJECT_DIR = props.getProperty("PROJECT_DIR");
|
||||
GenericProject.PROJECT_DIR = props.getProperty("PROJECT_DIR");
|
||||
}
|
||||
|
||||
public static void noOutline(JComponent c) {
|
||||
|
||||
@@ -4,22 +4,30 @@ import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.derpandaa.plinfa.projects.GenericProject;
|
||||
import tools.jackson.core.JacksonException;
|
||||
import tools.jackson.core.type.TypeReference;
|
||||
import tools.jackson.databind.ObjectMapper;
|
||||
|
||||
public class ChatDto {
|
||||
|
||||
public static String PROJECT_DIR;
|
||||
|
||||
private String name;
|
||||
|
||||
private GenericProject parent;
|
||||
|
||||
List<MessageDto> messages;
|
||||
|
||||
private ChatDto(GenericProject parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public ChatDto() {
|
||||
this(null);
|
||||
messages = new ArrayList<MessageDto>();
|
||||
}
|
||||
|
||||
public ChatDto(File f) {
|
||||
public ChatDto(File f, GenericProject parent) {
|
||||
this(parent);
|
||||
loadFromFile(f);
|
||||
}
|
||||
|
||||
@@ -57,7 +65,7 @@ public class ChatDto {
|
||||
return;
|
||||
}
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
File f = new File(String.format("%s/%s.json", PROJECT_DIR, name));
|
||||
File f = new File(getPath());
|
||||
mapper.writeValue(f.getAbsoluteFile(), messages);
|
||||
}
|
||||
|
||||
@@ -65,4 +73,8 @@ public class ChatDto {
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
private String getPath() {
|
||||
return String.format("%s/%s.json", parent.getFullName(),name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,15 @@ import java.util.List;
|
||||
import de.derpandaa.plinfa.dto.ChatDto;
|
||||
|
||||
public class GenericProject {
|
||||
public static String PROJECT_DIR;
|
||||
private String name;
|
||||
private final GenericProject parent;
|
||||
private List<GenericProject> subProjects;
|
||||
private List<ChatDto> chats;
|
||||
|
||||
public GenericProject(File dir) {
|
||||
public GenericProject(File dir, GenericProject parent) {
|
||||
this.name = dir.getName();
|
||||
this.parent = parent;
|
||||
this.subProjects = new ArrayList<>();
|
||||
this.chats = new ArrayList<>();
|
||||
load(dir);
|
||||
@@ -25,9 +28,9 @@ public class GenericProject {
|
||||
|
||||
for (File f : files) {
|
||||
if (f.isDirectory()) {
|
||||
subProjects.add(new GenericProject(f));
|
||||
subProjects.add(new GenericProject(f, this));
|
||||
} else if (f.getName().endsWith(".json")) {
|
||||
chats.add(new ChatDto(f));
|
||||
chats.add(new ChatDto(f, this));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -36,6 +39,13 @@ public class GenericProject {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
if (parent == null) {
|
||||
return PROJECT_DIR;
|
||||
}
|
||||
return String.format("%s/%s/", parent.getFullName(), name);
|
||||
}
|
||||
|
||||
public List<GenericProject> getSubProjects() {
|
||||
return subProjects;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user