mirror of
https://github.com/aseprite/aseprite.git
synced 2025-04-09 18:44:46 +00:00
Drag recent items outside the list to remove them
This commit is contained in:
parent
0f150b249d
commit
84f540ab7f
@ -31,7 +31,15 @@ public:
|
|||||||
|
|
||||||
case ui::kSetCursorMessage:
|
case ui::kSetCursorMessage:
|
||||||
if (m_floatingOverlay) {
|
if (m_floatingOverlay) {
|
||||||
ui::set_mouse_cursor(ui::kMoveCursor);
|
const ui::MouseMessage* mouseMsg = static_cast<ui::MouseMessage*>(msg);
|
||||||
|
const gfx::Point mousePos = mouseMsg->position();
|
||||||
|
if (onCanDropItemsOutside() &&
|
||||||
|
!getParentBounds().contains(mousePos)) {
|
||||||
|
ui::set_mouse_cursor(ui::kForbiddenCursor);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui::set_mouse_cursor(ui::kMoveCursor);
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -64,12 +72,33 @@ public:
|
|||||||
|
|
||||||
if (m_floatingOverlay) {
|
if (m_floatingOverlay) {
|
||||||
m_floatingOverlay->moveOverlay(mousePos - m_floatingOffset);
|
m_floatingOverlay->moveOverlay(mousePos - m_floatingOffset);
|
||||||
onReorderWidgets(mousePos);
|
|
||||||
|
bool inside = true;
|
||||||
|
if (onCanDropItemsOutside()) {
|
||||||
|
inside = getParentBounds().contains(mousePos);
|
||||||
|
if (inside) {
|
||||||
|
if (this->hasFlags(ui::HIDDEN)) {
|
||||||
|
this->disableFlags(ui::HIDDEN);
|
||||||
|
layoutParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!this->hasFlags(ui::HIDDEN)) {
|
||||||
|
this->enableFlags(ui::HIDDEN);
|
||||||
|
layoutParent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onReorderWidgets(mousePos, inside);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case ui::kMouseUpMessage: {
|
case ui::kMouseUpMessage: {
|
||||||
|
const ui::MouseMessage* mouseMsg = static_cast<ui::MouseMessage*>(msg);
|
||||||
|
const gfx::Point mousePos = mouseMsg->position();
|
||||||
|
|
||||||
m_wasDragged = (this->hasCapture() && m_floatingOverlay);
|
m_wasDragged = (this->hasCapture() && m_floatingOverlay);
|
||||||
const bool result = Base::onProcessMessage(msg);
|
const bool result = Base::onProcessMessage(msg);
|
||||||
|
|
||||||
@ -77,7 +106,7 @@ public:
|
|||||||
if (m_floatingOverlay) {
|
if (m_floatingOverlay) {
|
||||||
destroyFloatingOverlay();
|
destroyFloatingOverlay();
|
||||||
ASSERT(!m_createFloatingOverlay);
|
ASSERT(!m_createFloatingOverlay);
|
||||||
onFinalDrop();
|
onFinalDrop(getParentBounds().contains(mousePos));
|
||||||
}
|
}
|
||||||
else if (m_createFloatingOverlay)
|
else if (m_createFloatingOverlay)
|
||||||
m_createFloatingOverlay = false;
|
m_createFloatingOverlay = false;
|
||||||
@ -134,22 +163,36 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size getFloatingOverlaySize() {
|
gfx::Size getFloatingOverlaySize() {
|
||||||
auto view = ui::View::getView(this);
|
auto view = ui::View::getView(this->parent());
|
||||||
if (!view)
|
|
||||||
view = ui::View::getView(this->parent());
|
|
||||||
if (view)
|
if (view)
|
||||||
return (view->viewportBounds().offset(view->viewScroll()) & this->bounds()).size();
|
return (view->viewportBounds().offset(view->viewScroll()) & this->bounds()).size();
|
||||||
else
|
else
|
||||||
return this->size();
|
return this->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gfx::Rect getParentBounds() {
|
||||||
|
auto view = ui::View::getView(this->parent());
|
||||||
|
if (view)
|
||||||
|
return view->viewportBounds();
|
||||||
|
else
|
||||||
|
return this->parent()->bounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void layoutParent() {
|
||||||
|
this->parent()->layout();
|
||||||
|
auto view = ui::View::getView(this->parent());
|
||||||
|
if (view)
|
||||||
|
return view->updateView();
|
||||||
|
}
|
||||||
|
|
||||||
void drawFloatingOverlay(ui::Graphics& g) {
|
void drawFloatingOverlay(ui::Graphics& g) {
|
||||||
ui::PaintEvent ev(this, &g);
|
ui::PaintEvent ev(this, &g);
|
||||||
this->onPaint(ev);
|
this->onPaint(ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void onReorderWidgets(const gfx::Point& mousePos) { }
|
virtual bool onCanDropItemsOutside() { return true; }
|
||||||
virtual void onFinalDrop() { }
|
virtual void onReorderWidgets(const gfx::Point& mousePos, bool inside) { }
|
||||||
|
virtual void onFinalDrop(bool inside) { }
|
||||||
|
|
||||||
// True if we should create the floating overlay after leaving the
|
// True if we should create the floating overlay after leaving the
|
||||||
// widget bounds.
|
// widget bounds.
|
||||||
|
@ -168,7 +168,7 @@ protected:
|
|||||||
static_cast<RecentListBox*>(parent())->onClick(m_fullpath);
|
static_cast<RecentListBox*>(parent())->onClick(m_fullpath);
|
||||||
}
|
}
|
||||||
|
|
||||||
void onReorderWidgets(const gfx::Point& mousePos) override {
|
void onReorderWidgets(const gfx::Point& mousePos, bool inside) override {
|
||||||
auto parent = this->parent();
|
auto parent = this->parent();
|
||||||
auto other = manager()->pick(mousePos);
|
auto other = manager()->pick(mousePos);
|
||||||
if (other && other != this && other->parent() == parent) {
|
if (other && other != this && other->parent() == parent) {
|
||||||
@ -177,21 +177,30 @@ protected:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void onFinalDrop() override {
|
void onFinalDrop(bool inside) override {
|
||||||
if (!wasDragged())
|
if (!wasDragged())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Pin all elements to keep the order
|
if (inside) {
|
||||||
const auto& children = parent()->children();
|
// Pin all elements to keep the order
|
||||||
for (auto it=children.rbegin(), end=children.rend(); it!=end; ++it) {
|
const auto& children = parent()->children();
|
||||||
if (this == *it) {
|
for (auto it=children.rbegin(), end=children.rend(); it!=end; ++it) {
|
||||||
for (; it!=end; ++it)
|
if (this == *it) {
|
||||||
static_cast<RecentFileItem*>(*it)->pin();
|
for (; it!=end; ++it)
|
||||||
break;
|
static_cast<RecentFileItem*>(*it)->pin();
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
setVisible(false);
|
||||||
|
parent()->layout();
|
||||||
|
}
|
||||||
|
|
||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
|
if (!inside)
|
||||||
|
deferDelete();
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -254,6 +263,8 @@ void RecentListBox::updateRecentListFromUIItems()
|
|||||||
base::paths recentPaths;
|
base::paths recentPaths;
|
||||||
for (auto item : children()) {
|
for (auto item : children()) {
|
||||||
auto fi = static_cast<RecentFileItem*>(item);
|
auto fi = static_cast<RecentFileItem*>(item);
|
||||||
|
if (fi->hasFlags(ui::HIDDEN))
|
||||||
|
continue;
|
||||||
if (fi->pinned())
|
if (fi->pinned())
|
||||||
pinnedPaths.push_back(fi->fullpath());
|
pinnedPaths.push_back(fi->fullpath());
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user