Skip to content
This repository was archived by the owner on Jun 25, 2020. It is now read-only.

Commit ee6a084

Browse files
committed
notebook tabs shows first uncommon subdirectory if filename is the same
1 parent 889c844 commit ee6a084

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/notebook.cc

+31-10
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,41 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
195195
}
196196
};
197197
source_views.back()->update_tab_label=[this](Source::View *view) {
198-
std::string title=view->file_path.filename().string();
199-
if(view->get_buffer()->get_modified())
200-
title+='*';
201-
else
202-
title+=' ';
198+
const auto update_label = [&](size_t index, const std::string &prepend){
199+
const auto current_view = source_views[index];
200+
auto title = prepend+current_view->file_path.filename().string();
201+
if(current_view->get_buffer()->get_modified())
202+
title+='*';
203+
else
204+
title+=' ';
205+
auto &tab_label=tab_labels.at(index);
206+
tab_label->label.set_text(title);
207+
tab_label->set_tooltip_text(filesystem::get_short_path(current_view->file_path).string());
208+
};
209+
const auto file_name=view->file_path.filename();
210+
std::string prepend_current_view;
203211
for(size_t c=0;c<size();++c) {
204212
if(source_views[c]==view) {
205-
auto &tab_label=tab_labels.at(c);
206-
tab_label->label.set_text(title);
207-
tab_label->set_tooltip_text(filesystem::get_short_path(view->file_path).string());
208-
update_status(view);
209-
return;
213+
update_label(c, prepend_current_view);
214+
continue;
215+
}
216+
if (source_views[c]->file_path.filename() == file_name) {
217+
int diff=0;
218+
const auto parent_path1=view->file_path.parent_path();
219+
const auto parent_path2=source_views[c]->file_path.parent_path();
220+
auto it1=parent_path1.rbegin();
221+
auto it2=parent_path2.rbegin();
222+
while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) {
223+
++it1;
224+
++it2;
225+
++diff;
226+
}
227+
if(prepend_current_view.empty())
228+
prepend_current_view=it1->string()+(diff>0?"/.../":"/");
229+
update_label(c, it2->string()+(diff>0?"/.../":"/"));
210230
}
211231
}
232+
update_status(view);
212233
};
213234
source_views.back()->update_status_diagnostics=[this](Source::View* view) {
214235
if(get_current_view()==view) {

0 commit comments

Comments
 (0)