Browse Source

Directory view: unknown files are now made italic even when not showing a git repository

merge-requests/413/head
eidheim 3 years ago
parent
commit
a7483981bf
  1. 140
      src/directories.cpp

140
src/directories.cpp

@ -715,21 +715,83 @@ void Directories::remove_path(const boost::filesystem::path &dir_path) {
}
}
void Directories::colorize_path(boost::filesystem::path dir_path_, bool include_parent_paths) {
auto dir_path = std::make_shared<boost::filesystem::path>(std::move(dir_path_));
auto it = directories.find(dir_path->string());
void Directories::colorize_path(boost::filesystem::path dir_path, bool include_parent_paths) {
auto it = directories.find(dir_path.string());
if(it == directories.end())
return;
boost::system::error_code ec;
if(!boost::filesystem::exists(*dir_path, ec)) {
if(!boost::filesystem::exists(dir_path, ec)) {
directories.erase(it);
return;
}
auto colorize = [this, dir_path = std::move(dir_path), include_parent_paths](const Git::Repository::Status &status = {}) {
auto it = directories.find(dir_path.string());
if(it == directories.end())
return;
auto normal_color = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_NORMAL);
Gdk::RGBA yellow;
yellow.set_rgba(1.0, 1.0, 0.2);
double factor = 0.5;
yellow.set_red(normal_color.get_red() + factor * (yellow.get_red() - normal_color.get_red()));
yellow.set_green(normal_color.get_green() + factor * (yellow.get_green() - normal_color.get_green()));
yellow.set_blue(normal_color.get_blue() + factor * (yellow.get_blue() - normal_color.get_blue()));
Gdk::RGBA green;
green.set_rgba(0.0, 1.0, 0.0);
factor = 0.4;
green.set_red(normal_color.get_red() + factor * (green.get_red() - normal_color.get_red()));
green.set_green(normal_color.get_green() + factor * (green.get_green() - normal_color.get_green()));
green.set_blue(normal_color.get_blue() + factor * (green.get_blue() - normal_color.get_blue()));
boost::system::error_code ec;
do {
Gtk::TreeNodeChildren children(it->second.row ? it->second.row.children() : tree_store->children());
if(!children)
return;
for(auto &child : children) {
auto name = Glib::Markup::escape_text(child.get_value(column_record.name));
auto path = child.get_value(column_record.path);
// Use canonical path to follow symbolic links
auto canonical_path = filesystem::get_canonical_path(path);
Gdk::RGBA *color;
if(status.modified.find(canonical_path.generic_string()) != status.modified.end())
color = &yellow;
else if(status.added.find(canonical_path.generic_string()) != status.added.end())
color = &green;
else
color = &normal_color;
std::stringstream ss;
ss << '#' << std::setfill('0') << std::hex;
ss << std::setw(2) << std::hex << (color->get_red_u() >> 8);
ss << std::setw(2) << std::hex << (color->get_green_u() >> 8);
ss << std::setw(2) << std::hex << (color->get_blue_u() >> 8);
child.set_value(column_record.markup, "<span foreground=\"" + ss.str() + "\">" + name + "</span>");
auto type = child.get_value(column_record.type);
if(type == PathType::unknown)
child.set_value(column_record.markup, "<i>" + child.get_value(column_record.markup) + "</i>");
}
if(!include_parent_paths)
break;
auto path = boost::filesystem::path(it->first);
if(boost::filesystem::exists(path / ".git", ec))
break;
if(path == path.root_directory())
break;
auto parent_path = boost::filesystem::path(it->first).parent_path();
it = directories.find(parent_path.string());
} while(it != directories.end());
};
if(it->second.repository) {
auto repository = it->second.repository;
thread_pool.push([this, dir_path, repository, include_parent_paths] {
thread_pool.push([this, repository = it->second.repository, colorize = std::move(colorize)] {
Git::Repository::Status status;
try {
status = repository->get_status();
@ -738,69 +800,11 @@ void Directories::colorize_path(boost::filesystem::path dir_path_, bool include_
Terminal::get().async_print(std::string("\e[31mError (git)\e[m: ") + e.what() + '\n', true);
}
dispatcher.post([this, dir_path, include_parent_paths, status = std::move(status)] {
auto it = directories.find(dir_path->string());
if(it == directories.end())
return;
auto normal_color = get_style_context()->get_color(Gtk::StateFlags::STATE_FLAG_NORMAL);
Gdk::RGBA yellow;
yellow.set_rgba(1.0, 1.0, 0.2);
double factor = 0.5;
yellow.set_red(normal_color.get_red() + factor * (yellow.get_red() - normal_color.get_red()));
yellow.set_green(normal_color.get_green() + factor * (yellow.get_green() - normal_color.get_green()));
yellow.set_blue(normal_color.get_blue() + factor * (yellow.get_blue() - normal_color.get_blue()));
Gdk::RGBA green;
green.set_rgba(0.0, 1.0, 0.0);
factor = 0.4;
green.set_red(normal_color.get_red() + factor * (green.get_red() - normal_color.get_red()));
green.set_green(normal_color.get_green() + factor * (green.get_green() - normal_color.get_green()));
green.set_blue(normal_color.get_blue() + factor * (green.get_blue() - normal_color.get_blue()));
boost::system::error_code ec;
do {
Gtk::TreeNodeChildren children(it->second.row ? it->second.row.children() : tree_store->children());
if(!children)
return;
for(auto &child : children) {
auto name = Glib::Markup::escape_text(child.get_value(column_record.name));
auto path = child.get_value(column_record.path);
// Use canonical path to follow symbolic links
auto canonical_path = filesystem::get_canonical_path(path);
Gdk::RGBA *color;
if(status.modified.find(canonical_path.generic_string()) != status.modified.end())
color = &yellow;
else if(status.added.find(canonical_path.generic_string()) != status.added.end())
color = &green;
else
color = &normal_color;
std::stringstream ss;
ss << '#' << std::setfill('0') << std::hex;
ss << std::setw(2) << std::hex << (color->get_red_u() >> 8);
ss << std::setw(2) << std::hex << (color->get_green_u() >> 8);
ss << std::setw(2) << std::hex << (color->get_blue_u() >> 8);
child.set_value(column_record.markup, "<span foreground=\"" + ss.str() + "\">" + name + "</span>");
auto type = child.get_value(column_record.type);
if(type == PathType::unknown)
child.set_value(column_record.markup, "<i>" + child.get_value(column_record.markup) + "</i>");
}
if(!include_parent_paths)
break;
auto path = boost::filesystem::path(it->first);
if(boost::filesystem::exists(path / ".git", ec))
break;
if(path == path.root_directory())
break;
auto parent_path = boost::filesystem::path(it->first).parent_path();
it = directories.find(parent_path.string());
} while(it != directories.end());
dispatcher.post([colorize = std::move(colorize), status = std::move(status)] {
colorize(status);
});
});
}
else
colorize();
}

Loading…
Cancel
Save