From 5528ab4d26c359eb13c0cfc1e633d9522f363f38 Mon Sep 17 00:00:00 2001 From: ahrm Date: Mon, 19 Jul 2021 23:12:55 +0430 Subject: [PATCH] Add tutorial. --- pdf_viewer/config.cpp | 3 +++ pdf_viewer/main.cpp | 9 +++++++-- pdf_viewer/prefs.config | 3 +++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pdf_viewer/config.cpp b/pdf_viewer/config.cpp index f3d816a0b..ca7d37aa3 100644 --- a/pdf_viewer/config.cpp +++ b/pdf_viewer/config.cpp @@ -10,6 +10,7 @@ extern float MOVE_SCREEN_PERCENTAGE; extern float BACKGROUND_COLOR[3]; extern bool FLAT_TABLE_OF_CONTENTS; extern bool SHOULD_USE_MULTIPLE_MONITORS; +extern bool SHOULD_LOAD_TUTORIAL_WHEN_NO_OTHER_FILE; extern std::wstring LIBGEN_ADDRESS; extern std::wstring GOOGLE_SCHOLAR_ADDRESS; @@ -108,6 +109,8 @@ ConfigManager::ConfigManager(const std::filesystem::path& default_path, const st configs.push_back({ L"move_screen_percentage", &MOVE_SCREEN_PERCENTAGE, float_serializer, float_deserializer }); configs.push_back({ L"flat_toc", &FLAT_TABLE_OF_CONTENTS, bool_serializer, bool_deserializer }); configs.push_back({ L"should_use_multiple_monitors", &SHOULD_USE_MULTIPLE_MONITORS, bool_serializer, bool_deserializer }); + configs.push_back({ L"should_load_tutorial_when_no_other_file", &SHOULD_LOAD_TUTORIAL_WHEN_NO_OTHER_FILE, bool_serializer, bool_deserializer }); +//extern bool should_load_tutorial_when_no_other_file = false; std::wifstream default_infile(default_path); std::wifstream user_infile(user_path); diff --git a/pdf_viewer/main.cpp b/pdf_viewer/main.cpp index f98802f89..08a39089e 100644 --- a/pdf_viewer/main.cpp +++ b/pdf_viewer/main.cpp @@ -5,9 +5,9 @@ //todo: autocomplete in command window //todo: simplify word selection logic (also avoid inefficient extra insertions followed by clears in selected_characters) //todo: make it so that all commands that change document state (for example goto_offset_withing_page, goto_link, etc.) do not change the document -// state, instead they return a DocumentViewState object that is then applied using push_state and chnage_state functions +// state, instead they return a DocumentViewState object that is then applied using push_state and change_state functions // (chnage state should be a function that just applies the state without pushing it to history) -//todo: pdf live reload has some weird bugs. probably caused by inappropriate use of mupdf. +//todo: make tutorial file smaller #include #include @@ -94,6 +94,7 @@ extern bool FLAT_TABLE_OF_CONTENTS = false; extern bool SHOULD_USE_MULTIPLE_MONITORS = false; extern std::wstring LIBGEN_ADDRESS = L""; extern std::wstring GOOGLE_SCHOLAR_ADDRESS = L""; +extern bool SHOULD_LOAD_TUTORIAL_WHEN_NO_OTHER_FILE = false; extern std::filesystem::path last_path_file_absolute_location = ""; extern std::filesystem::path parent_path = ""; @@ -188,6 +189,10 @@ int main(int argc, char* args[]) { LAUNCHED_FROM_FILE_ICON = true; } + if ((file_path.size() == 0) && SHOULD_LOAD_TUTORIAL_WHEN_NO_OTHER_FILE) { + file_path = parent_path / "tutorial.pdf"; + } + DocumentManager document_manager(mupdf_context, db); QFileSystemWatcher pref_file_watcher; diff --git a/pdf_viewer/prefs.config b/pdf_viewer/prefs.config index 029f3d010..3d9f19be6 100644 --- a/pdf_viewer/prefs.config +++ b/pdf_viewer/prefs.config @@ -40,3 +40,6 @@ status_label_stylesheet background-color: black; color: white; borde flat_toc 0 # If it is 1, when launching the application if we detect multiple monitors, we automatically launch the helper window in second monitor should_use_multiple_monitors 0 + +# if the last opened document is empty, load the tutorial pdf instead +should_load_tutorial_when_no_other_file 1 \ No newline at end of file