From 033f5e76de0995a64e9226e4e72a5823582e3309 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 25 Mar 2016 15:52:33 +0100 Subject: [PATCH] Now reopens folder and files from last session if starting juci without parameters. Related to issue mentioned in #170 --- src/juci.cc | 17 +++++++++++++++++ src/window.cc | 13 +++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/juci.cc b/src/juci.cc index 14e95a1..6cb92e8 100644 --- a/src/juci.cc +++ b/src/juci.cc @@ -44,6 +44,23 @@ int Application::on_command_line(const Glib::RefPtr void Application::on_activate() { add_window(Window::get()); Window::get().show(); + + if(directories.empty() && files.empty()) { + try { + boost::property_tree::ptree pt; + boost::property_tree::read_json((Config::get().juci_home_path()/"last_session.json").string(), pt); + auto folder=pt.get("folder"); + if(!folder.empty()) + directories.emplace_back(folder); + for(auto &v: pt.get_child("files")) { + std::string file=v.second.data(); + if(!file.empty()) + files.emplace_back(file); + } + } + catch(const std::exception &e) {} + } + bool first_directory=true; for(auto &directory: directories) { if(first_directory) { diff --git a/src/window.cc b/src/window.cc index 2adcea4..e1d7389 100644 --- a/src/window.cc +++ b/src/window.cc @@ -803,6 +803,19 @@ bool Window::on_key_press_event(GdkEventKey *event) { } bool Window::on_delete_event(GdkEventAny *event) { + try { + boost::property_tree::ptree pt_root, pt_files; + pt_root.put("folder", Directories::get().path.string()); + for(int c=0;cfile_path.string()); + pt_files.push_back(std::make_pair("", pt_child)); + } + pt_root.add_child("files", pt_files); + boost::property_tree::write_json((Config::get().juci_home_path()/"last_session.json").string(), pt_root); + } + catch(const std::exception &) {} + auto size=notebook.size(); for(int c=0;c