From 58caac133771daf9093fcb2767d5b73c59ab9499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 8 Feb 2018 09:45:22 +0100 Subject: [PATCH 1/6] notebook tabs shows first uncommon subdirectory if filename is the same --- src/notebook.cc | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index 882462ca..e2e81aef 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -195,20 +195,41 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i } }; source_views.back()->update_tab_label=[this](Source::View *view) { - std::string title=view->file_path.filename().string(); - if(view->get_buffer()->get_modified()) - title+='*'; - else - title+=' '; + const auto update_label = [&](size_t index, const std::string &prepend){ + const auto current_view = source_views[index]; + auto title = prepend+current_view->file_path.filename().string(); + if(current_view->get_buffer()->get_modified()) + title+='*'; + else + title+=' '; + auto &tab_label=tab_labels.at(index); + tab_label->label.set_text(title); + tab_label->set_tooltip_text(filesystem::get_short_path(current_view->file_path).string()); + }; + const auto file_name=view->file_path.filename(); + std::string prepend_current_view; for(size_t c=0;clabel.set_text(title); - tab_label->set_tooltip_text(filesystem::get_short_path(view->file_path).string()); - update_status(view); - return; + update_label(c, prepend_current_view); + continue; + } + if (source_views[c]->file_path.filename() == file_name) { + int diff=0; + const auto parent_path1=view->file_path.parent_path(); + const auto parent_path2=source_views[c]->file_path.parent_path(); + auto it1=parent_path1.rbegin(); + auto it2=parent_path2.rbegin(); + while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) { + ++it1; + ++it2; + ++diff; + } + if(prepend_current_view.empty()) + prepend_current_view=it1->string()+(diff>0?"/.../":"/"); + update_label(c, it2->string()+(diff>0?"/.../":"/")); } } + update_status(view); }; source_views.back()->update_status_diagnostics=[this](Source::View* view) { if(get_current_view()==view) { From adb56bc5d6664613def18ee000a9f9ee51edb0d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 13 Feb 2018 22:42:43 +0100 Subject: [PATCH 2/6] update on open and close with x --- src/notebook.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/notebook.cc b/src/notebook.cc index e2e81aef..48563026 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -314,7 +314,10 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i if(index!=static_cast(-1)) close(index); })); - + + if(source_view->update_tab_label) + 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([this, source_view]() { if(source_view->update_tab_label) @@ -527,6 +530,10 @@ bool Notebook::close(size_t index) { hboxes.erase(hboxes.begin()+index); tab_labels.erase(tab_labels.begin()+index); } + for(auto view: get_views()) { // Update all view tabs in case one clicks cross to close a buffer + if(view->update_tab_label) + view->update_tab_label(view); + } return true; } From a7c2b33b203c5ef62b893c3e4a9a7d1f1d9eb113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Tue, 20 Feb 2018 22:38:42 +0100 Subject: [PATCH 3/6] fix prepend on current index, also format --- src/notebook.cc | 46 ++++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index 48563026..c4dd4c13 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -194,41 +194,43 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i status_branch.set_text(""); } }; - source_views.back()->update_tab_label=[this](Source::View *view) { - const auto update_label = [&](size_t index, const std::string &prepend){ + source_views.back()->update_tab_label = [this](Source::View *view) { + const auto update_label = [&](size_t index, const std::string &prepend) { const auto current_view = source_views[index]; - auto title = prepend+current_view->file_path.filename().string(); - if(current_view->get_buffer()->get_modified()) - title+='*'; + auto title = prepend + current_view->file_path.filename().string(); + if (current_view->get_buffer()->get_modified()) + title += '*'; else - title+=' '; - auto &tab_label=tab_labels.at(index); + title += ' '; + auto &tab_label = tab_labels.at(index); tab_label->label.set_text(title); tab_label->set_tooltip_text(filesystem::get_short_path(current_view->file_path).string()); }; - const auto file_name=view->file_path.filename(); + const auto file_name = view->file_path.filename(); std::string prepend_current_view; - for(size_t c=0;cfile_path.filename() == file_name) { - int diff=0; - const auto parent_path1=view->file_path.parent_path(); - const auto parent_path2=source_views[c]->file_path.parent_path(); - auto it1=parent_path1.rbegin(); - auto it2=parent_path2.rbegin(); + int diff = 0; + const auto parent_path1 = view->file_path.parent_path(); + const auto parent_path2 = source_views[c]->file_path.parent_path(); + auto it1 = parent_path1.rbegin(); + auto it2 = parent_path2.rbegin(); while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) { - ++it1; - ++it2; - ++diff; + ++it1; + ++it2; + ++diff; } - if(prepend_current_view.empty()) - prepend_current_view=it1->string()+(diff>0?"/.../":"/"); - update_label(c, it2->string()+(diff>0?"/.../":"/")); + if (prepend_current_view.empty()) + prepend_current_view = it1->string() + (diff > 0 ? "/.../" : "/"); + update_label(c, it2->string() + (diff > 0 ? "/.../" : "/")); } } + update_label(current_view_index, prepend_current_view); update_status(view); }; source_views.back()->update_status_diagnostics=[this](Source::View* view) { From 8534ee234316fbe700c75ae16850b4c59e1a4b17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Wed, 4 Apr 2018 18:10:06 +0200 Subject: [PATCH 4/6] only add star on update --- src/notebook.cc | 30 +++++++++++++++++------------- src/source.h | 1 + 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index c4dd4c13..d50bdb44 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -194,16 +194,21 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i status_branch.set_text(""); } }; + source_views.back()->update_modified = [this](Source::View *view) { + const auto view_index = get_index(view); + auto &label = tab_labels.at(view_index)->label; + const auto tab_title = label.get_text(); + const auto title = view->get_buffer()->get_modified() ? tab_title + '*' : tab_title.substr(0, tab_title.size() - 1); + label.set_text(title); + }; source_views.back()->update_tab_label = [this](Source::View *view) { const auto update_label = [&](size_t index, const std::string &prepend) { const auto current_view = source_views[index]; auto title = prepend + current_view->file_path.filename().string(); - if (current_view->get_buffer()->get_modified()) - title += '*'; - else - title += ' '; auto &tab_label = tab_labels.at(index); tab_label->label.set_text(title); + if (current_view->update_modified && current_view->get_buffer()->get_modified()) + current_view->update_modified(current_view); tab_label->set_tooltip_text(filesystem::get_short_path(current_view->file_path).string()); }; const auto file_name = view->file_path.filename(); @@ -318,14 +323,13 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i })); if(source_view->update_tab_label) - 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([this, source_view]() { - if(source_view->update_tab_label) - source_view->update_tab_label(source_view); - }); + source_view->update_tab_label(source_view); + source_view->get_buffer()->signal_modified_changed().connect([source_view]() { + if (source_view->update_modified) + source_view->update_modified(source_view); + }); + //Cursor history auto update_cursor_locations=[this, source_view](const Gtk::TextBuffer::iterator &iter) { bool mark_moved=false; @@ -532,8 +536,8 @@ bool Notebook::close(size_t index) { hboxes.erase(hboxes.begin()+index); tab_labels.erase(tab_labels.begin()+index); } - for(auto view: get_views()) { // Update all view tabs in case one clicks cross to close a buffer - if(view->update_tab_label) + for (auto view : get_views()) { + if (view->update_tab_label) view->update_tab_label(view); } return true; diff --git a/src/source.h b/src/source.h index 1bca74b6..d43722ec 100644 --- a/src/source.h +++ b/src/source.h @@ -100,6 +100,7 @@ namespace Source { void hide_dialogs() override; std::function update_tab_label; + std::function update_modified; std::function update_status_location; std::function update_status_file_path; std::function update_status_diagnostics; From df0b0a546106bf7d10238828c78ee14923320b2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 5 Apr 2018 15:47:29 +0200 Subject: [PATCH 5/6] fixes for ubuntu 16 --- src/notebook.cc | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index d50bdb44..213f1b36 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -223,11 +223,13 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i int diff = 0; const auto parent_path1 = view->file_path.parent_path(); const auto parent_path2 = source_views[c]->file_path.parent_path(); - auto it1 = parent_path1.rbegin(); - auto it2 = parent_path2.rbegin(); - while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) { - ++it1; - ++it2; + auto it1 = parent_path1.end(); + const auto it1_end = parent_path1.begin(); + auto it2 = parent_path2.end(); + const auto it2_end = parent_path2.begin(); + while (it1 != it1_end && it2 != it2_end && *it1 == *it2) { + --it1; + --it2; ++diff; } if (prepend_current_view.empty()) From 3530f3c231790763e887efe362aed5f26f3fa5b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Lien=20Sell=C3=A6g?= Date: Thu, 5 Apr 2018 15:47:48 +0200 Subject: [PATCH 6/6] use epsilon char --- src/notebook.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index 213f1b36..4870f0c2 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -233,8 +233,8 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i ++diff; } if (prepend_current_view.empty()) - prepend_current_view = it1->string() + (diff > 0 ? "/.../" : "/"); - update_label(c, it2->string() + (diff > 0 ? "/.../" : "/")); + prepend_current_view = it1->string() + (diff > 0 ? "/…/" : "/"); + update_label(c, it2->string() + (diff > 0 ? "/…/" : "/")); } } update_label(current_view_index, prepend_current_view);