Add possibility to paste as new file from clipboard on Home tab

Feature request:
https://community.aseprite.org/t/pasting-on-home-screen/21476
This commit is contained in:
David Capello 2024-02-16 12:40:00 -03:00
parent a1b52fd64b
commit 9be7c66376
2 changed files with 84 additions and 2 deletions

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -25,6 +25,7 @@
#include "app/ui/workspace.h"
#include "app/ui/workspace_tabs.h"
#include "app/ui_context.h"
#include "app/util/clipboard.h"
#include "base/exception.h"
#include "fmt/format.h"
#include "ui/label.h"
@ -192,6 +193,71 @@ void HomeView::onWorkspaceViewSelected()
StatusBar::instance()->showDefaultText();
}
void HomeView::onNewInputPriority(InputChainElement* element,
const ui::Message* msg)
{
// Do nothing
}
bool HomeView::onCanCut(Context* ctx)
{
return false;
}
bool HomeView::onCanCopy(Context* ctx)
{
return false;
}
bool HomeView::onCanPaste(Context* ctx)
{
return (ctx->clipboard()->format() == ClipboardFormat::Image);
}
bool HomeView::onCanClear(Context* ctx)
{
return false;
}
bool HomeView::onCut(Context* ctx)
{
return false;
}
bool HomeView::onCopy(Context* ctx)
{
return false;
}
bool HomeView::onPaste(Context* ctx)
{
auto clipboard = ctx->clipboard();
if (clipboard->format() == ClipboardFormat::Image) {
// Create new sprite from the clipboard image.
Params params;
params.set("ui", "false");
params.set("fromClipboard", "true");
ctx->executeCommand(
Commands::instance()->byId(CommandId::NewFile()),
params);
return true;
}
else
return false;
}
bool HomeView::onClear(Context* ctx)
{
// Do nothing
return false;
}
void HomeView::onCancel(Context* ctx)
{
// Do nothing
}
void HomeView::onNewFile()
{
Command* command = Commands::instance()->byId(CommandId::NewFile());

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
@ -10,6 +10,7 @@
#pragma once
#include "app/check_update_delegate.h"
#include "app/ui/input_chain_element.h"
#include "app/ui/tabs.h"
#include "app/ui/workspace_view.h"
#include "ui/box.h"
@ -34,6 +35,7 @@ namespace app {
class HomeView : public app::gen::HomeView
, public TabView
, public WorkspaceView
, public app::InputChainElement
#ifdef ENABLE_UPDATER
, public CheckUpdateDelegate
#endif
@ -61,6 +63,20 @@ namespace app {
void onAfterRemoveView(Workspace* workspace) override;
void onTabPopup(Workspace* workspace) override;
void onWorkspaceViewSelected() override;
InputChainElement* onGetInputChainElement() override { return this; }
// InputChainElement impl
void onNewInputPriority(InputChainElement* element,
const ui::Message* msg) override;
bool onCanCut(Context* ctx) override;
bool onCanCopy(Context* ctx) override;
bool onCanPaste(Context* ctx) override;
bool onCanClear(Context* ctx) override;
bool onCut(Context* ctx) override;
bool onCopy(Context* ctx) override;
bool onPaste(Context* ctx) override;
bool onClear(Context* ctx) override;
void onCancel(Context* ctx) override;
protected:
void onResize(ui::ResizeEvent& ev) override;