Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jul 20, 2024
2 parents 6e596d1 + 3c44831 commit c767da4
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
6 changes: 6 additions & 0 deletions docs/CODING_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,5 +156,11 @@ targetting macOS 10.9, some notes are added about this:
* You can use `<atomic>`, `<thread>`, `<mutex>`, and `<condition_variable>`
* Prefer `using T = ...;` instead of `typedef ... T`
* Use `[[fallthrough]]` if needed
* Use `= {}` only to specify a default argument value of an
user-defined type in a function declaration, e.g.
`void func(const std::string& s = {}) { ... }`.
In other cases (e.g. a member variable of an user-defined type)
it's not required or we prefer to use the explicit value
for built-in types (`int m_var = 0;`).
* We use gcc 9.2 or clang 9.0 on Linux, so check the features available in
https://en.cppreference.com/w/cpp/compiler_support
5 changes: 3 additions & 2 deletions src/app/match_words.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2017 David Capello
//
// This program is distributed under the terms of
Expand All @@ -18,12 +19,12 @@ namespace app {

class MatchWords {
public:
MatchWords(const std::string& search) {
MatchWords(const std::string& search = {}) {
base::split_string(base::string_to_lower(search),
m_parts, " ");
}

bool operator()(const std::string& item) {
bool operator()(const std::string& item) const {
std::string lowerItem = base::string_to_lower(item);
std::size_t matches = 0;

Expand Down
17 changes: 3 additions & 14 deletions src/app/ui/context_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@
#include "app/ui/expr_entry.h"
#include "app/ui/icon_button.h"
#include "app/ui/keyboard_shortcuts.h"
#include "app/ui/layer_frame_comboboxes.h"
#include "app/ui/sampling_selector.h"
#include "app/ui/selection_mode_field.h"
#include "app/ui/skin/skin_theme.h"
#include "app/ui_context.h"
#include "base/fs.h"
#include "base/pi.h"
#include "base/scoped_value.h"
#include "doc/brush.h"
Expand Down Expand Up @@ -1738,19 +1738,8 @@ class ContextBar::SliceFields : public HBox {
void fillSlices() {
m_combobox.deleteAllItems();
if (m_doc && m_doc->sprite()) {
MatchWords match(m_filter);

std::vector<doc::Slice*> slices;
for (auto slice : m_doc->sprite()->slices()) {
if (match(slice->name()))
slices.push_back(slice);
}
std::sort(slices.begin(), slices.end(),
[](const doc::Slice* a, const doc::Slice* b){
return (base::compare_filenames(a->name(), b->name()) < 0);
});

for (auto slice : slices) {
for (auto* slice : sort_slices_by_name(m_doc->sprite()->slices(),
MatchWords(m_filter))) {
Item* item = new Item(slice);
m_combobox.addItem(item);
}
Expand Down
32 changes: 22 additions & 10 deletions src/app/ui/layer_frame_comboboxes.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -13,17 +13,19 @@

#include "app/doc.h"
#include "app/i18n/strings.h"
#include "app/match_words.h"
#include "app/restore_visible_layers.h"
#include "app/site.h"
#include "base/fs.h"
#include "doc/anidir.h"
#include "doc/frames_sequence.h"
#include "doc/layer.h"
#include "doc/playback.h"
#include "doc/selected_frames.h"
#include "doc/selected_layers.h"
#include "doc/slice.h"
#include "doc/sprite.h"
#include "doc/tag.h"
#include "doc/playback.h"
#include "ui/combobox.h"

namespace app {
Expand Down Expand Up @@ -84,17 +86,11 @@ void fill_area_combobox(const doc::Sprite* sprite, ui::ComboBox* area, const std
if (defArea == kSelectedCanvas)
area->setSelectedItemIndex(i);

std::vector<doc::Slice*> sliceList;
for (auto* slice : sprite->slices()) {
for (auto* slice : sort_slices_by_name(sprite->slices(),
MatchWords())) {
if (slice->name().empty())
continue;

sliceList.push_back(slice);
}
std::sort(sliceList.begin(),
sliceList.end(),
[](doc::Slice* a, doc::Slice* b) { return a->name() < b->name(); });
for (auto* slice : sliceList) {
i = area->addItem(new SliceListItem(slice));
if (defArea == slice->name())
area->setSelectedItemIndex(i);
Expand Down Expand Up @@ -320,4 +316,20 @@ doc::Tag* calculate_selected_frames(const Site& site,
return tag;
}

std::vector<doc::Slice*> sort_slices_by_name(const doc::Slices& slices,
const MatchWords& match)
{
std::vector<doc::Slice*> result;
for (auto* slice : slices) {
if (match(slice->name()))
result.push_back(slice);
}
std::sort(result.begin(),
result.end(),
[](const doc::Slice* a, const doc::Slice* b) {
return (base::compare_filenames(a->name(), b->name()) < 0);
});
return result;
}

} // namespace app
8 changes: 7 additions & 1 deletion src/app/ui/layer_frame_comboboxes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -13,13 +13,15 @@
#include "ui/listitem.h"

#include <string>
#include <vector>

namespace doc {
class Layer;
class SelectedFrames;
class FramesSequence;
class SelectedLayers;
class Slice;
class Slices;
class Sprite;
class Tag;
}
Expand All @@ -29,6 +31,7 @@ namespace ui {
}

namespace app {
class MatchWords;
class RestoreVisibleLayers;
class Site;

Expand Down Expand Up @@ -85,6 +88,9 @@ namespace app {
const std::string& framesValue,
doc::SelectedFrames& selFrames);

std::vector<doc::Slice*> sort_slices_by_name(const doc::Slices& slices,
const MatchWords& match);

} // namespace app

#endif

0 comments on commit c767da4

Please sign in to comment.