Add button to refresh/reload the list of palettes (fix #4258)

This commit is contained in:
David Capello 2024-01-04 13:51:18 -03:00
parent 88e89b6c38
commit d6587fbf78
6 changed files with 71 additions and 18 deletions

View File

@ -1,8 +1,12 @@
<!-- Aseprite -->
<!-- Copyright (C) 2024 by Igara Studio S.A. -->
<!-- Copyright (C) 2014-2017 by David Capello -->
<gui>
<vbox id="palette_popup">
<search id="search" magnet="true" />
<hbox>
<search id="search" magnet="true" expansive="true" />
<button text="" id="refresh" style="refresh_button" />
</hbox>
<view id="view" expansive="true" />
<hbox>
<button id="load_pal" text="@.load" minwidth="80" magnet="true" />

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -23,6 +23,8 @@
#include "ui/box.h"
#include "ui/button.h"
#include "ui/fit_bounds.h"
#include "ui/keys.h"
#include "ui/message.h"
#include "ui/scale.h"
#include "ui/theme.h"
#include "ui/view.h"
@ -45,6 +47,7 @@ PalettePopup::PalettePopup()
m_paletteListBox.DoubleClickItem.connect([this]{ onLoadPal(); });
m_paletteListBox.FinishLoading.connect([this]{ onSearchChange(); });
m_popup->search()->Change.connect([this]{ onSearchChange(); });
m_popup->refresh()->Click.connect([this]{ onRefresh(); });
m_popup->loadPal()->Click.connect([this]{ onLoadPal(); });
m_popup->openFolder()->Click.connect([this]{ onOpenFolder(); });
@ -78,6 +81,25 @@ void PalettePopup::showPopup(ui::Display* display,
openWindowInForeground();
}
bool PalettePopup::onProcessMessage(ui::Message* msg)
{
switch (msg->type()) {
case kKeyDownMessage: {
KeyMessage* keyMsg = static_cast<KeyMessage*>(msg);
KeyScancode scancode = keyMsg->scancode();
bool refresh = (scancode == kKeyF5 ||
(msg->ctrlPressed() && scancode == kKeyR) ||
(msg->cmdPressed() && scancode == kKeyR));
if (refresh) {
onRefresh();
return true;
}
break;
}
}
return ui::PopupWindow::onProcessMessage(msg);
}
void PalettePopup::onPalChange(const doc::Palette* palette)
{
const bool state =
@ -112,6 +134,11 @@ void PalettePopup::onSearchChange()
m_popup->view()->layout();
}
void PalettePopup::onRefresh()
{
m_paletteListBox.reload();
}
void PalettePopup::onLoadPal()
{
const doc::Palette* palette = m_paletteListBox.selectedPalette();

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2021-2022 Igara Studio S.A.
// Copyright (C) 2021-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -31,8 +31,11 @@ namespace app {
const gfx::Rect& buttonPos);
protected:
bool onProcessMessage(ui::Message* msg) override;
void onPalChange(const doc::Palette* palette);
void onSearchChange();
void onRefresh();
void onLoadPal();
void onOpenFolder();

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2023 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2017 David Capello
//
// This program is distributed under the terms of
@ -126,10 +126,10 @@ PalettesListBox::PalettesListBox()
m_extPaletteChanges =
App::instance()->extensions().PalettesChange.connect(
[this]{ reload(); });
[this]{ markToReload(); });
m_extPresetsChanges =
App::instance()->PalettePresetsChange.connect(
[this]{ reload(); });
[this]{ markToReload(); });
}
const doc::Palette* PalettesListBox::selectedPalette()

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020-2022 Igara Studio S.A.
// Copyright (C) 2020-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -111,8 +111,6 @@ private:
ResourcesListBox::ResourcesListBox(ResourcesLoader* resourcesLoader)
: m_resourcesLoader(resourcesLoader)
, m_resourcesTimer(100)
, m_reload(false)
, m_loadingItem(nullptr)
{
m_resourcesTimer.Tick.connect([this]{ onTick(); });
}
@ -125,7 +123,24 @@ Resource* ResourcesListBox::selectedResource()
return nullptr;
}
void ResourcesListBox::markToReload()
{
deleteAllChildren();
m_reloadOnOpen = true;
}
void ResourcesListBox::reload()
{
deleteAllChildren();
ASSERT(m_resourcesLoader);
if (m_resourcesLoader) {
m_resourcesLoader->reload();
m_resourcesTimer.start();
}
}
void ResourcesListBox::deleteAllChildren()
{
auto children = this->children(); // Create a copy because we'll
// modify the list in the for()
@ -136,8 +151,6 @@ void ResourcesListBox::reload()
if (dynamic_cast<ResourceListItem*>(child))
delete child;
}
m_reload = true;
}
void ResourcesListBox::paintResource(Graphics* g, gfx::Rect& bounds, Resource* resource)
@ -157,12 +170,15 @@ bool ResourcesListBox::onProcessMessage(ui::Message* msg)
switch (msg->type()) {
case kOpenMessage: {
if (m_reload) {
m_reload = false;
m_resourcesLoader->reload();
if (m_reloadOnOpen) {
m_reloadOnOpen = false;
reload();
}
else {
// Start timer to fill the list box with the current resource
// loader state.
m_resourcesTimer.start();
}
m_resourcesTimer.start();
break;
}

View File

@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -42,6 +43,7 @@ class ResourceListItem : public ui::ListItem {
Resource* selectedResource();
void markToReload();
void reload();
obs::signal<void()> FinishLoading;
@ -57,6 +59,7 @@ class ResourceListItem : public ui::ListItem {
virtual void onResourceSizeHint(Resource* resource, gfx::Size& size) = 0;
private:
void deleteAllChildren();
void paintResource(ui::Graphics* g, gfx::Rect& bounds, Resource* resource);
gfx::Size resourceSizeHint(Resource* resource);
@ -65,10 +68,10 @@ class ResourceListItem : public ui::ListItem {
std::unique_ptr<ResourcesLoader> m_resourcesLoader;
ui::Timer m_resourcesTimer;
bool m_reload;
bool m_reloadOnOpen = false;
class LoadingItem;
LoadingItem* m_loadingItem;
LoadingItem* m_loadingItem = nullptr;
};
} // namespace app