@@ -194,16 +194,21 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
194194 status_branch.set_text (" " );
195195 }
196196 };
197+ source_views.back ()->update_modified = [this ](Source::View *view) {
198+ const auto view_index = get_index (view);
199+ auto &label = tab_labels.at (view_index)->label ;
200+ const auto tab_title = label.get_text ();
201+ const auto title = view->get_buffer ()->get_modified () ? tab_title + ' *' : tab_title.substr (0 , tab_title.size () - 1 );
202+ label.set_text (title);
203+ };
197204 source_views.back ()->update_tab_label = [this ](Source::View *view) {
198205 const auto update_label = [&](size_t index, const std::string &prepend) {
199206 const auto current_view = source_views[index];
200207 auto title = prepend + current_view->file_path .filename ().string ();
201- if (current_view->get_buffer ()->get_modified ())
202- title += ' *' ;
203- else
204- title += ' ' ;
205208 auto &tab_label = tab_labels.at (index);
206209 tab_label->label .set_text (title);
210+ if (current_view->update_modified && current_view->get_buffer ()->get_modified ())
211+ current_view->update_modified (current_view);
207212 tab_label->set_tooltip_text (filesystem::get_short_path (current_view->file_path ).string ());
208213 };
209214 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
318323 }));
319324
320325 if (source_view->update_tab_label )
321- source_view->update_tab_label (source_view);
322-
323- // Add star on tab label when the page is not saved:
324- source_view->get_buffer ()->signal_modified_changed ().connect ([this , source_view]() {
325- if (source_view->update_tab_label )
326- source_view->update_tab_label (source_view);
327- });
326+ source_view->update_tab_label (source_view);
328327
328+ source_view->get_buffer ()->signal_modified_changed ().connect ([source_view]() {
329+ if (source_view->update_modified )
330+ source_view->update_modified (source_view);
331+ });
332+
329333 // Cursor history
330334 auto update_cursor_locations=[this , source_view](const Gtk::TextBuffer::iterator &iter) {
331335 bool mark_moved=false ;
@@ -532,8 +536,8 @@ bool Notebook::close(size_t index) {
532536 hboxes.erase (hboxes.begin ()+index);
533537 tab_labels.erase (tab_labels.begin ()+index);
534538 }
535- for (auto view: get_views ()) { // Update all view tabs in case one clicks cross to close a buffer
536- if (view->update_tab_label )
539+ for (auto view : get_views ()) {
540+ if (view->update_tab_label )
537541 view->update_tab_label (view);
538542 }
539543 return true ;
0 commit comments