Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix various inline editing bugs in the playlist view #266

Merged
merged 3 commits into from
Dec 4, 2019
Merged
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
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Change log

## Development version

### Features

* When using in-line field editing in the playlist view, empty field values are no longer written to the file when saving changes. (If no field values are entered, the field is now removed from the file.) [[#266](https://github.com/reupen/columns_ui/pull/266)]

* In-line field editing in the playlist view is no longer sometimes blocked if a file with no loaded metadata is encountered. [[#266](https://github.com/reupen/columns_ui/pull/266)]

### Bug fixes

* A crash was fixed when using in-line field editing in the playlist view and setting a field to an empty string. [[#266](https://github.com/reupen/columns_ui/pull/266)]

* A crash was fixed when saving changes after using in-line field editing in the playlist view on more than two tracks with initially differing field values. [[#266](https://github.com/reupen/columns_ui/pull/266)]

## 1.3.0-beta.1

### Features
Expand Down
23 changes: 14 additions & 9 deletions foo_ui_columns/ng_playlist/ng_playlist_inline_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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)
if (start > end || start == std::string_view::npos)
return ""sv;

return value.substr(start, end - start + 1);
Expand Down Expand Up @@ -75,31 +75,31 @@ bool PlaylistView::notify_create_inline_edit(const pfc::list_base_const_t<t_size

m_edit_field = m_edit_fields[column];

bool matching = true;

for (t_size i = 0; i < indices_count; i++) {
if (!m_playlist_api->activeplaylist_get_item_handle(m_edit_handles[i], indices[i]))
return false;
}

metadb_info_container::ptr info_container;
if (!m_edit_handles[i]->get_info_ref(info_container))
return false;
bool matching = true;

auto& info = info_container->info();
for (t_size i = 0; i < indices_count; i++) {
metadb_info_container::ptr info_container = m_edit_handles[i]->get_info_ref();

auto& info = info_container->info();
auto item_values = get_info_field_values(info, m_edit_field.get_ptr());

if (i == 0) {
values = item_values;
} else if (item_values != values) {
p_text = "<multiple values>";
matching = false;
break;
}
}

if (matching) {
p_text = mmh::join<decltype(values)&, std::string_view, std::string>(values, "; "sv).c_str();
} else {
p_text = "<multiple values>";
}

try {
Expand All @@ -122,9 +122,14 @@ void PlaylistView::notify_save_inline_edit(const char* value)
for (;;) {
const size_t index = value_view.find(";"sv, offset);
const auto substr = value_view.substr(offset, index - offset);
values.emplace_back(trim_string(substr));
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;
}

Expand Down