mirror of
https://github.com/aseprite/aseprite.git
synced 2025-01-01 18:00:26 +00:00
Add button to refresh/reload the list of palettes (fix #4258)
This commit is contained in:
parent
88e89b6c38
commit
d6587fbf78
@ -1,8 +1,12 @@
|
|||||||
<!-- Aseprite -->
|
<!-- Aseprite -->
|
||||||
|
<!-- Copyright (C) 2024 by Igara Studio S.A. -->
|
||||||
<!-- Copyright (C) 2014-2017 by David Capello -->
|
<!-- Copyright (C) 2014-2017 by David Capello -->
|
||||||
<gui>
|
<gui>
|
||||||
<vbox id="palette_popup">
|
<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" />
|
<view id="view" expansive="true" />
|
||||||
<hbox>
|
<hbox>
|
||||||
<button id="load_pal" text="@.load" minwidth="80" magnet="true" />
|
<button id="load_pal" text="@.load" minwidth="80" magnet="true" />
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2020-2022 Igara Studio S.A.
|
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -23,6 +23,8 @@
|
|||||||
#include "ui/box.h"
|
#include "ui/box.h"
|
||||||
#include "ui/button.h"
|
#include "ui/button.h"
|
||||||
#include "ui/fit_bounds.h"
|
#include "ui/fit_bounds.h"
|
||||||
|
#include "ui/keys.h"
|
||||||
|
#include "ui/message.h"
|
||||||
#include "ui/scale.h"
|
#include "ui/scale.h"
|
||||||
#include "ui/theme.h"
|
#include "ui/theme.h"
|
||||||
#include "ui/view.h"
|
#include "ui/view.h"
|
||||||
@ -45,6 +47,7 @@ PalettePopup::PalettePopup()
|
|||||||
m_paletteListBox.DoubleClickItem.connect([this]{ onLoadPal(); });
|
m_paletteListBox.DoubleClickItem.connect([this]{ onLoadPal(); });
|
||||||
m_paletteListBox.FinishLoading.connect([this]{ onSearchChange(); });
|
m_paletteListBox.FinishLoading.connect([this]{ onSearchChange(); });
|
||||||
m_popup->search()->Change.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->loadPal()->Click.connect([this]{ onLoadPal(); });
|
||||||
m_popup->openFolder()->Click.connect([this]{ onOpenFolder(); });
|
m_popup->openFolder()->Click.connect([this]{ onOpenFolder(); });
|
||||||
|
|
||||||
@ -78,6 +81,25 @@ void PalettePopup::showPopup(ui::Display* display,
|
|||||||
openWindowInForeground();
|
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)
|
void PalettePopup::onPalChange(const doc::Palette* palette)
|
||||||
{
|
{
|
||||||
const bool state =
|
const bool state =
|
||||||
@ -112,6 +134,11 @@ void PalettePopup::onSearchChange()
|
|||||||
m_popup->view()->layout();
|
m_popup->view()->layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PalettePopup::onRefresh()
|
||||||
|
{
|
||||||
|
m_paletteListBox.reload();
|
||||||
|
}
|
||||||
|
|
||||||
void PalettePopup::onLoadPal()
|
void PalettePopup::onLoadPal()
|
||||||
{
|
{
|
||||||
const doc::Palette* palette = m_paletteListBox.selectedPalette();
|
const doc::Palette* palette = m_paletteListBox.selectedPalette();
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2021-2022 Igara Studio S.A.
|
// Copyright (C) 2021-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2017 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -31,8 +31,11 @@ namespace app {
|
|||||||
const gfx::Rect& buttonPos);
|
const gfx::Rect& buttonPos);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
bool onProcessMessage(ui::Message* msg) override;
|
||||||
|
|
||||||
void onPalChange(const doc::Palette* palette);
|
void onPalChange(const doc::Palette* palette);
|
||||||
void onSearchChange();
|
void onSearchChange();
|
||||||
|
void onRefresh();
|
||||||
void onLoadPal();
|
void onLoadPal();
|
||||||
void onOpenFolder();
|
void onOpenFolder();
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2020-2023 Igara Studio S.A.
|
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2017 David Capello
|
// Copyright (C) 2001-2017 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -126,10 +126,10 @@ PalettesListBox::PalettesListBox()
|
|||||||
|
|
||||||
m_extPaletteChanges =
|
m_extPaletteChanges =
|
||||||
App::instance()->extensions().PalettesChange.connect(
|
App::instance()->extensions().PalettesChange.connect(
|
||||||
[this]{ reload(); });
|
[this]{ markToReload(); });
|
||||||
m_extPresetsChanges =
|
m_extPresetsChanges =
|
||||||
App::instance()->PalettePresetsChange.connect(
|
App::instance()->PalettePresetsChange.connect(
|
||||||
[this]{ reload(); });
|
[this]{ markToReload(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc::Palette* PalettesListBox::selectedPalette()
|
const doc::Palette* PalettesListBox::selectedPalette()
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
// Copyright (C) 2020-2022 Igara Studio S.A.
|
// Copyright (C) 2020-2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -111,8 +111,6 @@ private:
|
|||||||
ResourcesListBox::ResourcesListBox(ResourcesLoader* resourcesLoader)
|
ResourcesListBox::ResourcesListBox(ResourcesLoader* resourcesLoader)
|
||||||
: m_resourcesLoader(resourcesLoader)
|
: m_resourcesLoader(resourcesLoader)
|
||||||
, m_resourcesTimer(100)
|
, m_resourcesTimer(100)
|
||||||
, m_reload(false)
|
|
||||||
, m_loadingItem(nullptr)
|
|
||||||
{
|
{
|
||||||
m_resourcesTimer.Tick.connect([this]{ onTick(); });
|
m_resourcesTimer.Tick.connect([this]{ onTick(); });
|
||||||
}
|
}
|
||||||
@ -125,7 +123,24 @@ Resource* ResourcesListBox::selectedResource()
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourcesListBox::markToReload()
|
||||||
|
{
|
||||||
|
deleteAllChildren();
|
||||||
|
m_reloadOnOpen = true;
|
||||||
|
}
|
||||||
|
|
||||||
void ResourcesListBox::reload()
|
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
|
auto children = this->children(); // Create a copy because we'll
|
||||||
// modify the list in the for()
|
// modify the list in the for()
|
||||||
@ -136,8 +151,6 @@ void ResourcesListBox::reload()
|
|||||||
if (dynamic_cast<ResourceListItem*>(child))
|
if (dynamic_cast<ResourceListItem*>(child))
|
||||||
delete child;
|
delete child;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_reload = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResourcesListBox::paintResource(Graphics* g, gfx::Rect& bounds, Resource* resource)
|
void ResourcesListBox::paintResource(Graphics* g, gfx::Rect& bounds, Resource* resource)
|
||||||
@ -157,12 +170,15 @@ bool ResourcesListBox::onProcessMessage(ui::Message* msg)
|
|||||||
switch (msg->type()) {
|
switch (msg->type()) {
|
||||||
|
|
||||||
case kOpenMessage: {
|
case kOpenMessage: {
|
||||||
if (m_reload) {
|
if (m_reloadOnOpen) {
|
||||||
m_reload = false;
|
m_reloadOnOpen = false;
|
||||||
m_resourcesLoader->reload();
|
reload();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// Start timer to fill the list box with the current resource
|
||||||
|
// loader state.
|
||||||
|
m_resourcesTimer.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_resourcesTimer.start();
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Aseprite
|
// Aseprite
|
||||||
|
// Copyright (C) 2024 Igara Studio S.A.
|
||||||
// Copyright (C) 2001-2018 David Capello
|
// Copyright (C) 2001-2018 David Capello
|
||||||
//
|
//
|
||||||
// This program is distributed under the terms of
|
// This program is distributed under the terms of
|
||||||
@ -42,6 +43,7 @@ class ResourceListItem : public ui::ListItem {
|
|||||||
|
|
||||||
Resource* selectedResource();
|
Resource* selectedResource();
|
||||||
|
|
||||||
|
void markToReload();
|
||||||
void reload();
|
void reload();
|
||||||
|
|
||||||
obs::signal<void()> FinishLoading;
|
obs::signal<void()> FinishLoading;
|
||||||
@ -57,6 +59,7 @@ class ResourceListItem : public ui::ListItem {
|
|||||||
virtual void onResourceSizeHint(Resource* resource, gfx::Size& size) = 0;
|
virtual void onResourceSizeHint(Resource* resource, gfx::Size& size) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void deleteAllChildren();
|
||||||
void paintResource(ui::Graphics* g, gfx::Rect& bounds, Resource* resource);
|
void paintResource(ui::Graphics* g, gfx::Rect& bounds, Resource* resource);
|
||||||
gfx::Size resourceSizeHint(Resource* resource);
|
gfx::Size resourceSizeHint(Resource* resource);
|
||||||
|
|
||||||
@ -65,10 +68,10 @@ class ResourceListItem : public ui::ListItem {
|
|||||||
|
|
||||||
std::unique_ptr<ResourcesLoader> m_resourcesLoader;
|
std::unique_ptr<ResourcesLoader> m_resourcesLoader;
|
||||||
ui::Timer m_resourcesTimer;
|
ui::Timer m_resourcesTimer;
|
||||||
bool m_reload;
|
bool m_reloadOnOpen = false;
|
||||||
|
|
||||||
class LoadingItem;
|
class LoadingItem;
|
||||||
LoadingItem* m_loadingItem;
|
LoadingItem* m_loadingItem = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace app
|
} // namespace app
|
||||||
|
Loading…
Reference in New Issue
Block a user