This commit is contained in:
Krzosa Karol
2024-07-12 10:34:17 +02:00
parent bd97ecb9eb
commit 1ec217905d
5 changed files with 205 additions and 18 deletions

View File

@@ -1,5 +1,5 @@
/*
@todo: txt files
@todo: popup when error
@todo: read recursive
@todo: add option for user to control what files are read
@todo: pdf files
@@ -25,20 +25,24 @@
#include <SDL.h>
#include "glad.h"
struct FileLoadResult {
String filename;
String error;
};
Arena Perm;
Array<FileLoadResult> XFileLoadResults;
#include "config.cpp"
#include <pdfio.h>
#include "read_pdf.cpp"
#include "read_srt.cpp"
Arena Perm;
WorkQueue MainWorkQueue;
#include "loading_thread.cpp"
#include "searching_thread.cpp"
char SRTCommand[512] = "\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\" --start-time {time_in_seconds} {video}";
char PDFCommand[512];
char TXTCommand[512] = "subl.exe {file}";
struct ReplaceVar {
String replace;
String with;
@@ -160,6 +164,14 @@ void UISearchResults(Array<String> filenames) {
String args = ReplaceVars(scratch, replace_vars, TXTCommand);
Process process = RunEx(args);
if (!process.is_valid) XFileLoadResults.bounded_add({"", process.error_message});
} else if (item->kind == SourceKind_PDF) {
replace_vars.add({"file", Format(scratch, "\"%.*s\"", FmtString(item->filepath))});
replace_vars.add({"page", Format(scratch, "%d", item->pdf.page)});
String args = ReplaceVars(scratch, replace_vars, PDFCommand);
Process process = RunEx(args);
if (!process.is_valid) XFileLoadResults.bounded_add({"", process.error_message});
} else {
Assert(!"Invalid codepath");
}
}
ImGui::SameLine();
@@ -395,6 +407,9 @@ int main(int, char **) {
ImGui::InputText(".srt", SRTCommand, sizeof(SRTCommand));
ImGui::InputText(".pdf", PDFCommand, sizeof(PDFCommand));
ImGui::InputText(".txt", TXTCommand, sizeof(TXTCommand));
if (ImGui::Button("Save config")) {
SaveConfig();
}
} else {
if (show_loaded_files) {
UILoadedFiles();