Added "Open Folder" button to the take screenshot notification.

This commit is contained in:
Martín Lucas Golini
2026-08-11 17:51:31 -03:00
parent 6d00bba62d
commit 6ba7de31d5
7 changed files with 46 additions and 12 deletions
+8 -1
View File
@@ -2912,9 +2912,16 @@ void App::takeScreenshot() {
}
if ( mWindow->takeScreenshot( filepath, format ) ) {
std::vector<NotificationCenter::InteractiveAction> actions;
actions.reserve( 2 );
actions.emplace_back( NotificationCenter::InteractiveAction{
i18n( "open", "Open" ), [this, filepath] { openFileFromPath( filepath ); } } );
actions.emplace_back( NotificationCenter::InteractiveAction{
i18n( "open_screenshot_folder", "Open Folder" ),
[savePath] { Engine::instance()->openURI( savePath ); } } );
mNotificationCenter->addInteractiveNotification(
i18n( "screenshot_saved", "Screenshot saved:" ) + "\n" + filepath,
i18n( "open", "Open" ), [this, filepath] { openFileFromPath( filepath ); } );
std::move( actions ) );
} else {
errorMsgBox( i18n( "couldnt_save_screenshot", "Couldn't save the screenshot." ) );
}
+26 -11
View File
@@ -99,14 +99,21 @@ void NotificationCenter::addShowRequest( const String& uri, const String& action
void NotificationCenter::addInteractiveNotification( String text, String actionText,
std::function<void()> onInteraction,
const Time& delay, bool allowCopy ) {
auto action = [this, text = std::move( text ), actionText = std::move( actionText ), delay,
allowCopy, onInteraction = std::move( onInteraction )]() {
std::vector<InteractiveAction> actions;
actions.emplace_back(
InteractiveAction{ std::move( actionText ), std::move( onInteraction ) } );
addInteractiveNotification( std::move( text ), std::move( actions ), delay, allowCopy );
}
void NotificationCenter::addInteractiveNotification( String text,
std::vector<InteractiveAction> actions,
const Time& delay, bool allowCopy ) {
auto action = [this, text = std::move( text ), actions = std::move( actions ), delay,
allowCopy]() mutable {
static const auto layout = R"xml(
<vbox lw="mp" class="notification">
<TextView lw="mp" lh="wc" word-wrap="true" />
<hbox lg="right">
<PushButton />
</hbox>
<hbox id="actions" lg="right" />
</vbox>
)xml";
UILinearLayout* lay = mLayout->getUISceneNode()
@@ -121,12 +128,20 @@ void NotificationCenter::addInteractiveNotification( String text, String actionT
( allowCopy ? EE_BUTTON_MMASK : ( EE_BUTTON_LMASK | EE_BUTTON_RMASK ) ) )
lay->close();
} );
UIPushButton* pb = lay->findByType( UI_TYPE_PUSHBUTTON )->asType<UIPushButton>();
pb->setText( actionText );
pb->onClick( [actionText, onInteraction = std::move( onInteraction )]( const MouseEvent* ) {
if ( onInteraction )
onInteraction();
} );
UILayout* actionsLayout = lay->find<UILayout>( "actions" );
bool firstAction = true;
for ( auto& interactiveAction : actions ) {
UIPushButton* button = UIPushButton::New();
if ( !firstAction )
button->setLayoutMarginLeft( 4 );
button->setText( interactiveAction.text )->setParent( actionsLayout );
button->onClick(
[callback = std::move( interactiveAction.callback )]( const MouseEvent* ) {
if ( callback )
callback();
} );
firstAction = false;
}
Action* sequence = Actions::Sequence::New(
{ Actions::FadeIn::New( Seconds( 0.125 ) ), Actions::Delay::New( delay ),
Actions::FadeOut::New( Seconds( 0.125 ) ), Actions::Close::New() } );
+8
View File
@@ -7,6 +7,11 @@ namespace ecode {
class NotificationCenter {
public:
struct InteractiveAction {
String text;
std::function<void()> callback;
};
static NotificationCenter* instance();
NotificationCenter( UILayout* layout, PluginManager* pluginManager );
@@ -21,6 +26,9 @@ class NotificationCenter {
std::function<void()> onInteraction,
const Time& delay = Seconds( 7.5 ), bool allowCopy = false );
void addInteractiveNotification( String text, std::vector<InteractiveAction> actions,
const Time& delay = Seconds( 7.5 ), bool allowCopy = false );
protected:
UILayout* mLayout{ nullptr };
PluginManager* mPluginManager{ nullptr };