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

notebook tabs shows first uncommon subdirectory if filename is the same #365

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 54 additions & 18 deletions src/notebook.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,51 @@ 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) {
std::string title=view->file_path.filename().string();
if(view->get_buffer()->get_modified())
title+='*';
else
title+=' ';
for(size_t c=0;c<size();++c) {
if(source_views[c]==view) {
auto &tab_label=tab_labels.at(c);
tab_label->label.set_text(title);
tab_label->set_tooltip_text(filesystem::get_short_path(view->file_path).string());
update_status(view);
return;
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();
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();
std::string prepend_current_view;
size_t current_view_index = 0;
for (size_t c = 0; c < size(); ++c) {
if (source_views[c] == view) {
current_view_index = c;
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.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())
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) {
if(get_current_view()==view) {
Expand Down Expand Up @@ -293,13 +323,15 @@ void Notebook::open(const boost::filesystem::path &file_path_, size_t notebook_i
if(index!=static_cast<size_t>(-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)
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;
Expand Down Expand Up @@ -506,6 +538,10 @@ bool Notebook::close(size_t index) {
hboxes.erase(hboxes.begin()+index);
tab_labels.erase(tab_labels.begin()+index);
}
for (auto view : get_views()) {
if (view->update_tab_label)
view->update_tab_label(view);
}
return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ namespace Source {
void hide_dialogs() override;

std::function<void(View *view)> update_tab_label;
std::function<void(View *view)> update_modified;
std::function<void(View *view)> update_status_location;
std::function<void(View *view)> update_status_file_path;
std::function<void(View *view)> update_status_diagnostics;
Expand Down