Hint user to configure keybindings from plugins.

This commit is contained in:
Martín Lucas Golini
2025-01-25 22:23:53 -03:00
parent d084c967ce
commit 337ac0f334
7 changed files with 65 additions and 14 deletions

View File

@@ -500,8 +500,8 @@ controls whether a new window is created or not.</string>
<string name="pattern">Pattern</string>
<string name="pick_widget">Pick Widget</string>
<string name="please_enter_file_url_ellipsis">Please enter the file URL...</string>
<string name="plugin_manager">Plugin Manager</string>
<string name="plugin_manager_open">Plugin Manager Open</string>
<string name="plugin_manager">Plugins Manager</string>
<string name="plugin_manager_open">Open Plugins Manager</string>
<string name="pluginsmodel_description">Description</string>
<string name="pluginsmodel_enabled">Enabled</string>
<string name="pluginsmodel_id">Id</string>

View File

@@ -190,7 +190,19 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider {
SettingsMenu* getSettingsMenu() const { return mSettings.get(); }
template <typename T> void registerUnlockedCommands( T& t ) {
t.setCommand( "keybindings", [this] { loadFileFromPath( mKeybindingsPath ); } );
t.setCommand( "keybindings", [this] {
loadFileFromPath( mKeybindingsPath );
if ( mNotificationCenter ) {
mNotificationCenter->addInteractiveNotification(
i18n( "keybindings_clarification",
"More keybindings can be set for each active plugin at the Plugins "
"Manager.\nBe aware that many of the core keybindings can be found "
"there." ),
i18n( "plugin_manager_open", "Open Plugins Manager" ),
[this] { runCommand( "plugin-manager-open" ); }, Seconds( 10 ) );
}
} );
t.setCommand( "debug-draw-boxes-toggle", [this] { debugDrawBoxesToggle(); } );
t.setCommand( "debug-draw-highlight-toggle", [this] { debugDrawHighlightToggle(); } );
t.setCommand( "debug-draw-debug-data", [this] { debugDrawData(); } );

View File

@@ -52,10 +52,7 @@ void NotificationCenter::addNotification( const String& text, const Time& delay,
Log::info( "Displayed notification:\n%s", text.toUtf8() );
};
if ( Engine::isRunninMainThread() )
action();
else
mLayout->runOnMainThread( action );
mLayout->ensureMainThread( action );
}
void NotificationCenter::addShowRequest( const String& uri, const String& actionText,
@@ -87,10 +84,48 @@ void NotificationCenter::addShowRequest( const String& uri, const String& action
lay->runAction( sequence );
};
if ( Engine::isRunninMainThread() )
action();
else
mLayout->runOnMainThread( action );
mLayout->ensureMainThread( 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 )]() {
static const auto layout = R"xml(
<vbox lw="mp" class="notification">
<TextView lw="mp" wordwrap="true" />
<hbox lg="right">
<PushButton />
</hbox>
</vbox>
)xml";
UILinearLayout* lay = mLayout->getUISceneNode()
->loadLayoutFromString( layout, mLayout )
->asType<UILinearLayout>();
UITextView* tv = lay->findByType( UI_TYPE_TEXTVIEW )->asType<UITextView>();
tv->setText( text );
tv->setTextSelection( allowCopy );
tv->on( Event::MouseClick, [allowCopy, lay]( const Event* event ) {
const MouseEvent* mouseEvent = static_cast<const MouseEvent*>( event );
if ( mouseEvent->getFlags() &
( 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* event ) {
if ( onInteraction )
onInteraction();
} );
Action* sequence = Actions::Sequence::New(
{ Actions::FadeIn::New( Seconds( 0.125 ) ), Actions::Delay::New( delay ),
Actions::FadeOut::New( Seconds( 0.125 ) ), Actions::Close::New() } );
lay->runAction( sequence );
};
mLayout->ensureMainThread( action );
}
} // namespace ecode

View File

@@ -15,6 +15,10 @@ class NotificationCenter {
void addShowRequest( const String& uri, const String& actionText,
const Time& delay = Seconds( 2.5 ) );
void addInteractiveNotification( String text, String actionText,
std::function<void()> onInteraction,
const Time& delay = Seconds( 7.5 ), bool allowCopy = false );
protected:
UILayout* mLayout{ nullptr };
PluginManager* mPluginManager{ nullptr };

View File

@@ -468,7 +468,7 @@ UIWindow* UIPluginManager::New( UISceneNode* sceneNode, PluginManager* manager,
id="plugin-manager-window"
lw="800dp" lh="400dp"
padding="8dp"
window-title="@string(plugin_manager, Plugin Manager)"
window-title="@string(plugin_manager, Plugins Manager)"
window-flags="default|maximize|shadow"
window-min-size="300dp 300dp">
<vbox lw="mp" lh="mp">

View File

@@ -1669,7 +1669,7 @@ UIMenu* SettingsMenu::createViewMenu() {
UIPopUpMenu* SettingsMenu::createToolsMenu() {
mToolsMenu = UIPopUpMenu::New();
mToolsMenu->add( i18n( "plugin_manager", "Plugin Manager" ), findIcon( "extensions" ) )
mToolsMenu->add( i18n( "plugin_manager", "Plugins Manager" ), findIcon( "extensions" ) )
->setId( "plugin-manager-open" );
mToolsMenu->addSeparator();

View File

@@ -118,7 +118,7 @@ static const auto LAYOUT = R"xml(
<button id="open-file" text="@string(open_a_file, Open a File)" />
<button id="recent-folders" text="@string(recent_folders_ellipsis, Recent Folders...)" />
<button id="recent-files" text="@string(recent_files_ellipsis, Recent Files...)" />
<button id="plugin-manager-open" text="@string(plugin_manager, Plugin Manager)" />
<button id="plugin-manager-open" text="@string(plugin_manager, Plugins Manager)" />
<button id="keybindings" text="@string(keybindings, Keybindings)" />
<widget class="separator" lw="mp" lh="32dp" />
<tv class="bold" text="@string(for_help_please_visit, For help, please visit:)" lg="center" />