From a5b2f75bab0ee1c76ce87da658127f2b237b017d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Fri, 15 Jun 2018 00:25:27 +0200 Subject: [PATCH] WIP --- src/directories.cc | 10 ++++------ src/notebook.cc | 13 ++++++------- src/notebook.h | 4 ++++ src/source_base.cc | 2 -- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/directories.cc b/src/directories.cc index 7bd0979..76638ed 100644 --- a/src/directories.cc +++ b/src/directories.cc @@ -69,7 +69,7 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat Terminal::get().print("Error: could not move file: " + ec.message() + '\n', true); return false; } - + auto new_file_path = target_path; for(size_t c = 0; c < Notebook::get().size(); c++) { auto view = Notebook::get().get_view(c); if(is_directory) { @@ -77,7 +77,6 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat auto file_it = view->file_path.begin(); for(auto source_it = source_path.begin(); source_it != source_path.end(); source_it++) file_it++; - auto new_file_path = target_path; for(; file_it != view->file_path.end(); file_it++) new_file_path /= *file_it; view->rename(new_file_path); @@ -88,7 +87,7 @@ bool Directories::TreeStore::drag_data_received_vfunc(const TreeModel::Path &pat break; } } - + Notebook::get().update_labels(new_file_path); Directories::get().update(); Directories::get().on_save_file(target_path); directories.select(target_path); @@ -262,7 +261,7 @@ Directories::Directories() : Gtk::ListViewText(1) { update(); on_save_file(target_path); select(target_path); - + auto new_file_path = target_path; for(size_t c = 0; c < Notebook::get().size(); c++) { auto view = Notebook::get().get_view(c); if(is_directory) { @@ -270,7 +269,6 @@ Directories::Directories() : Gtk::ListViewText(1) { auto file_it = view->file_path.begin(); for(auto source_it = source_path.begin(); source_it != source_path.end(); source_it++) file_it++; - auto new_file_path = target_path; for(; file_it != view->file_path.end(); file_it++) new_file_path /= *file_it; view->rename(new_file_path); @@ -290,7 +288,7 @@ Directories::Directories() : Gtk::ListViewText(1) { Terminal::get().print("Warning: language for " + target_path.string() + " has changed. Please reopen the file\n"); } } - + Notebook::get().update_labels(new_file_path); EntryBox::get().hide(); }); diff --git a/src/notebook.cc b/src/notebook.cc index 51f40d7..adce5e4 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -270,7 +270,7 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i if(index != static_cast(-1)) close(index); })); - source_view->update_tab_label = [this](Source::BaseView *view) { + update_tab_label = [this](Source::BaseView *view) { std::string title = view->file_path.filename().string(); if(view->get_buffer()->get_modified()) title += '*'; @@ -285,12 +285,11 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i } } }; - source_view->update_tab_label(source_view); - - //Add star on tab label when the page is not saved: - source_view->get_buffer()->signal_modified_changed().connect([source_view]() { - if(source_view->update_tab_label) - source_view->update_tab_label(source_view); + update_tab_label(source_view); + source_view->get_buffer()->signal_modified_changed().connect([this, source_view]() { + if(update_tab_label) { + update_tab_label(source_view); + } }); //Cursor history diff --git a/src/notebook.h b/src/notebook.h index 2577ca0..b41b059 100644 --- a/src/notebook.h +++ b/src/notebook.h @@ -55,11 +55,15 @@ public: Gtk::Label status_diagnostics; Gtk::Label status_state; void update_status(Source::BaseView *view); + void update_labels(const boost::filesystem::path &path); void clear_status(); std::function on_change_page; std::function on_close_page; + std::function update_tab_label; + std::function update_modified; + /// Cursor history std::vector cursor_locations; size_t current_cursor_location = -1; diff --git a/src/source_base.cc b/src/source_base.cc index 9484e0f..76701ff 100644 --- a/src/source_base.cc +++ b/src/source_base.cc @@ -214,8 +214,6 @@ void Source::BaseView::rename(const boost::filesystem::path &path) { if(update_status_file_path) update_status_file_path(this); - if(update_tab_label) - update_tab_label(this); } void Source::BaseView::monitor_file() {