Browse Source

fix prepend on current index, also format

merge-requests/365/head
Jørgen Lien Sellæg 8 years ago
parent
commit
a7c2b33b20
  1. 46
      src/notebook.cc

46
src/notebook.cc

@ -194,41 +194,43 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
status_branch.set_text(""); status_branch.set_text("");
} }
}; };
source_views.back()->update_tab_label=[this](Source::View *view) { source_views.back()->update_tab_label = [this](Source::View *view) {
const auto update_label = [&](size_t index, const std::string &prepend){ const auto update_label = [&](size_t index, const std::string &prepend) {
const auto current_view = source_views[index]; const auto current_view = source_views[index];
auto title = prepend+current_view->file_path.filename().string(); auto title = prepend + current_view->file_path.filename().string();
if(current_view->get_buffer()->get_modified()) if (current_view->get_buffer()->get_modified())
title+='*'; title += '*';
else else
title+=' '; title += ' ';
auto &tab_label=tab_labels.at(index); auto &tab_label = tab_labels.at(index);
tab_label->label.set_text(title); tab_label->label.set_text(title);
tab_label->set_tooltip_text(filesystem::get_short_path(current_view->file_path).string()); 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; std::string prepend_current_view;
for(size_t c=0;c<size();++c) { size_t current_view_index = 0;
if(source_views[c]==view) { for (size_t c = 0; c < size(); ++c) {
update_label(c, prepend_current_view); if (source_views[c] == view) {
current_view_index = c;
continue; continue;
} }
if (source_views[c]->file_path.filename() == file_name) { if (source_views[c]->file_path.filename() == file_name) {
int diff=0; int diff = 0;
const auto parent_path1=view->file_path.parent_path(); const auto parent_path1 = view->file_path.parent_path();
const auto parent_path2=source_views[c]->file_path.parent_path(); const auto parent_path2 = source_views[c]->file_path.parent_path();
auto it1=parent_path1.rbegin(); auto it1 = parent_path1.rbegin();
auto it2=parent_path2.rbegin(); auto it2 = parent_path2.rbegin();
while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) { while (it1 != parent_path1.rend() && it2 != parent_path2.rend() && *it1 == *it2) {
++it1; ++it1;
++it2; ++it2;
++diff; ++diff;
} }
if(prepend_current_view.empty()) if (prepend_current_view.empty())
prepend_current_view=it1->string()+(diff>0?"/.../":"/"); prepend_current_view = it1->string() + (diff > 0 ? "/.../" : "/");
update_label(c, it2->string()+(diff>0?"/.../":"/")); update_label(c, it2->string() + (diff > 0 ? "/.../" : "/"));
} }
} }
update_label(current_view_index, prepend_current_view);
update_status(view); update_status(view);
}; };
source_views.back()->update_status_diagnostics=[this](Source::View* view) { source_views.back()->update_status_diagnostics=[this](Source::View* view) {

Loading…
Cancel
Save