-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #863 from reupen/inline-editing-implementation
Improve metadata saving logic in Item properties and Filter panel
- Loading branch information
Showing
19 changed files
with
197 additions
and
236 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "pch.h" | ||
|
||
#include "file_info_utils.h" | ||
|
||
namespace cui::helpers { | ||
|
||
namespace { | ||
|
||
std::string_view trim_string(std::string_view value) | ||
{ | ||
const auto start = value.find_first_not_of(' '); | ||
const auto end = value.find_last_not_of(' '); | ||
|
||
if (start > end || start == std::string_view::npos) | ||
return ""sv; | ||
|
||
return value.substr(start, end - start + 1); | ||
} | ||
|
||
} // namespace | ||
|
||
std::vector<std::string> split_meta_value(std::string_view value) | ||
{ | ||
std::vector<std::string> values; | ||
|
||
for (size_t offset{};;) { | ||
const size_t index = value.find(";"sv, offset); | ||
const auto substr = value.substr(offset, index - offset); | ||
const auto trimmed_substr = trim_string(substr); | ||
|
||
if (trimmed_substr.length() > 0) | ||
values.emplace_back(trimmed_substr); | ||
|
||
if (index == std::string_view::npos) | ||
break; | ||
|
||
offset = index + 1; | ||
} | ||
|
||
return values; | ||
} | ||
|
||
std::vector<std::string_view> get_meta_field_values(const file_info& info, std::string_view field) | ||
{ | ||
std::vector<std::string_view> values; | ||
|
||
for (const auto index : ranges::views::iota(size_t{}, info.meta_get_count_by_name(field.data()))) { | ||
values.emplace_back(info.meta_get(field.data(), index)); | ||
} | ||
|
||
return values; | ||
} | ||
|
||
bool SingleFieldFileInfoFilter::apply_filter(metadb_handle_ptr p_location, t_filestats p_stats, file_info& p_info) | ||
{ | ||
auto old_values = get_meta_field_values(p_info, m_field); | ||
std::vector<std::string_view> new_values; | ||
ranges::push_back(new_values, m_new_values); | ||
|
||
if (old_values == new_values) | ||
return false; | ||
|
||
p_info.meta_remove_field(m_field.data()); | ||
|
||
for (auto&& value : m_new_values) | ||
p_info.meta_add_ex(m_field.data(), m_field.length(), value.data(), value.length()); | ||
|
||
return true; | ||
} | ||
|
||
} // namespace cui::helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
namespace cui::helpers { | ||
|
||
std::vector<std::string> split_meta_value(std::string_view value); | ||
|
||
std::vector<std::string_view> get_meta_field_values(const file_info& info, std::string_view field); | ||
|
||
class SingleFieldFileInfoFilter : public file_info_filter { | ||
public: | ||
SingleFieldFileInfoFilter(std::string field, std::vector<std::string> new_values) | ||
: m_field(std::move(field)) | ||
, m_new_values(std::move(new_values)) | ||
{ | ||
} | ||
|
||
bool apply_filter(metadb_handle_ptr p_location, t_filestats p_stats, file_info& p_info) override; | ||
|
||
std::string m_field; | ||
std::vector<std::string> m_new_values; | ||
}; | ||
|
||
} // namespace cui::helpers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.