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