From 7ae617d26448ca54755b93ea9aaf9b51c410a786 Mon Sep 17 00:00:00 2001 From: eidheim Date: Sun, 30 Apr 2023 08:58:24 +0200 Subject: [PATCH] Cleanup and corrections to Window::set_title() and its usages: title is now correctly set when opening juCi++ for the first time, and when closing a folder --- src/directories.cpp | 3 ++- src/window.cpp | 12 ++++-------- src/window.hpp | 3 ++- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/directories.cpp b/src/directories.cpp index 14c0a87..e7ae02b 100644 --- a/src/directories.cpp +++ b/src/directories.cpp @@ -426,6 +426,7 @@ void Directories::open(const boost::filesystem::path &dir_path) { pos += 2; } get_column(0)->set_title(title); + Window::get().set_title(path); for(auto &directory : directories) { if(directory.second.repository) @@ -434,7 +435,6 @@ void Directories::open(const boost::filesystem::path &dir_path) { directories.clear(); add_or_update_path(path, Gtk::TreeModel::Row(), true); - Window::get().set_title(path); if(auto view = Notebook::get().get_current_view()) view->update_status_file_path(view); @@ -447,6 +447,7 @@ void Directories::close(const boost::filesystem::path &dir_path) { tree_store->clear(); path.clear(); get_column(0)->set_title(""); + Window::get().set_title(); } else remove_path(dir_path); diff --git a/src/window.cpp b/src/window.cpp index 98f3466..1ab8e1e 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -23,7 +23,7 @@ Window::Window() { Gsv::init(); - set_title("juCi++"); + set_title(); get_style_context()->add_class("juci_window"); set_events(Gdk::POINTER_MOTION_MASK | Gdk::FOCUS_CHANGE_MASK | Gdk::SCROLL_MASK | Gdk::LEAVE_NOTIFY_MASK); @@ -172,13 +172,9 @@ Window::Window() { about.set_transient_for(*this); } -/// Sets the title to the filename part of the path passed -void Window::set_title(const boost::filesystem::path &p) { - const auto tmp = p.filename(); - if(tmp.empty()) { - return ApplicationWindow::set_title("juCi++"); - } - ApplicationWindow::set_title(tmp.string() + " – juCi++"); +void Window::set_title(const boost::filesystem::path &path) { + const auto filename = path.filename(); + ApplicationWindow::set_title(filename.empty() ? "juCi++" : filename.string() + " – juCi++"); } void Window::configure() { diff --git a/src/window.hpp b/src/window.hpp index a712375..731527a 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -15,7 +15,8 @@ public: void add_widgets(); void save_session(); void load_session(std::vector &directories, std::vector> &files, std::vector> &file_offsets, boost::filesystem::path ¤t_file, bool read_directories_and_files); - void set_title(const boost::filesystem::path &p); + /// Sets the title to the filename part of the path passed + void set_title(const boost::filesystem::path &path = {}); protected: bool on_key_press_event(GdkEventKey *event) override;