Skip to content

Commit f699619

Browse files
committed
ecode: Fix issues when dropping folders and files into the application.
1 parent 39c9adf commit f699619

File tree

2 files changed

+93
-57
lines changed

2 files changed

+93
-57
lines changed

src/tools/ecode/ecode.cpp

Lines changed: 92 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,50 +1575,51 @@ std::map<KeyBindings::Shortcut, std::string> App::getDefaultKeybindings() {
15751575
std::map<KeyBindings::Shortcut, std::string> App::getLocalKeybindings() {
15761576
return {
15771577
{ { KEY_RETURN, KEYMOD_LALT | KEYMOD_LCTRL }, "fullscreen-toggle" },
1578-
{ { KEY_F3, KEYMOD_NONE }, "repeat-find" },
1579-
{ { KEY_F3, KEYMOD_SHIFT }, "find-prev" },
1580-
{ { KEY_F12, KEYMOD_NONE }, "console-toggle" },
1581-
{ { KEY_F, KeyMod::getDefaultModifier() }, "find-replace" },
1582-
{ { KEY_Q, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "close-app" },
1583-
{ { KEY_O, KeyMod::getDefaultModifier() }, "open-file" },
1584-
{ { KEY_W, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "download-file-web" },
1585-
{ { KEY_O, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-folder" },
1586-
{ { KEY_F11, KEYMOD_NONE }, "debug-widget-tree-view" },
1587-
{ { KEY_K, KeyMod::getDefaultModifier() }, "open-locatebar" },
1588-
{ { KEY_P, KeyMod::getDefaultModifier() }, "open-command-palette" },
1589-
{ { KEY_F, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-global-search" },
1590-
{ { KEY_L, KeyMod::getDefaultModifier() }, "go-to-line" },
1578+
{ { KEY_F3, KEYMOD_NONE }, "repeat-find" }, { { KEY_F3, KEYMOD_SHIFT }, "find-prev" },
1579+
{ { KEY_F12, KEYMOD_NONE }, "console-toggle" },
1580+
{ { KEY_F, KeyMod::getDefaultModifier() }, "find-replace" },
1581+
{ { KEY_Q, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "close-app" },
1582+
{ { KEY_O, KeyMod::getDefaultModifier() }, "open-file" },
1583+
{ { KEY_W, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "download-file-web" },
1584+
{ { KEY_O, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-folder" },
1585+
{ { KEY_F11, KEYMOD_NONE }, "debug-widget-tree-view" },
1586+
{ { KEY_K, KeyMod::getDefaultModifier() }, "open-locatebar" },
1587+
{ { KEY_P, KeyMod::getDefaultModifier() }, "open-command-palette" },
1588+
{ { KEY_F, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-global-search" },
1589+
{ { KEY_L, KeyMod::getDefaultModifier() }, "go-to-line" },
15911590
#if EE_PLATFORM == EE_PLATFORM_MACOS
1592-
{ { KEY_M, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "menu-toggle" },
1591+
{ { KEY_M, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "menu-toggle" },
15931592
#else
1594-
{ { KEY_M, KeyMod::getDefaultModifier() }, "menu-toggle" },
1593+
{ { KEY_M, KeyMod::getDefaultModifier() }, "menu-toggle" },
15951594
#endif
1596-
{ { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "save-all" },
1597-
{ { KEY_F9, KEYMOD_LALT }, "switch-side-panel" },
1598-
{ { KEY_J, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1599-
"terminal-split-left" },
1600-
{ { KEY_L, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1601-
"terminal-split-right" },
1602-
{ { KEY_I, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1603-
"terminal-split-top" },
1604-
{ { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1605-
"terminal-split-bottom" },
1606-
{ { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1607-
"terminal-split-swap" },
1608-
{ { KEY_T, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1609-
"reopen-closed-tab" },
1610-
{ { KEY_1, KEYMOD_LALT }, "toggle-status-locate-bar" },
1611-
{ { KEY_2, KEYMOD_LALT }, "toggle-status-global-search-bar" },
1612-
{ { KEY_3, KEYMOD_LALT }, "toggle-status-terminal" },
1613-
{ { KEY_4, KEYMOD_LALT }, "toggle-status-build-output" },
1614-
{ { KEY_5, KEYMOD_LALT }, "toggle-status-app-output" },
1615-
{ { KEY_B, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-start" },
1616-
{ { KEY_C, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-cancel" },
1617-
{ { KEY_F5, KEYMOD_NONE }, "project-build-and-run" },
1618-
{ { KEY_O, KEYMOD_LALT | KEYMOD_SHIFT }, "show-open-documents" },
1619-
{ { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-workspace-symbol-search" },
1620-
{ { KEY_P, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "open-document-symbol-search" },
1621-
{ { KEY_N, KEYMOD_SHIFT | KEYMOD_LALT }, "create-new-window" },
1595+
{ { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "save-all" },
1596+
{ { KEY_F9, KEYMOD_LALT }, "switch-side-panel" },
1597+
{ { KEY_J, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1598+
"terminal-split-left" },
1599+
{ { KEY_L, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1600+
"terminal-split-right" },
1601+
{ { KEY_I, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1602+
"terminal-split-top" },
1603+
{ { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1604+
"terminal-split-bottom" },
1605+
{ { KEY_S, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1606+
"terminal-split-swap" },
1607+
{ { KEY_T, KeyMod::getDefaultModifier() | KEYMOD_LALT | KEYMOD_SHIFT },
1608+
"reopen-closed-tab" },
1609+
{ { KEY_1, KEYMOD_LALT }, "toggle-status-locate-bar" },
1610+
{ { KEY_2, KEYMOD_LALT }, "toggle-status-global-search-bar" },
1611+
{ { KEY_3, KEYMOD_LALT }, "toggle-status-terminal" },
1612+
{ { KEY_4, KEYMOD_LALT }, "toggle-status-build-output" },
1613+
{ { KEY_5, KEYMOD_LALT }, "toggle-status-app-output" },
1614+
{ { KEY_B, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-start" },
1615+
{ { KEY_C, KeyMod::getDefaultModifier() | KEYMOD_SHIFT }, "project-build-cancel" },
1616+
{ { KEY_F5, KEYMOD_NONE }, "project-build-and-run" },
1617+
{ { KEY_O, KEYMOD_LALT | KEYMOD_SHIFT }, "show-open-documents" },
1618+
{ { KEY_K, KeyMod::getDefaultModifier() | KEYMOD_SHIFT },
1619+
"open-workspace-symbol-search" },
1620+
{ { KEY_P, KeyMod::getDefaultModifier() | KEYMOD_SHIFT },
1621+
"open-document-symbol-search" },
1622+
{ { KEY_N, KEYMOD_SHIFT | KEYMOD_LALT }, "create-new-window" },
16221623
};
16231624
}
16241625

@@ -1627,15 +1628,15 @@ std::map<KeyBindings::Shortcut, std::string> App::getLocalKeybindings() {
16271628
std::map<std::string, std::string> App::getMigrateKeybindings() {
16281629
return {
16291630
{ "fullscreen-toggle", "alt+return" }, { "switch-to-tab-1", "alt+1" },
1630-
{ "switch-to-tab-2", "alt+2" }, { "switch-to-tab-3", "alt+3" },
1631-
{ "switch-to-tab-4", "alt+4" }, { "switch-to-tab-5", "alt+5" },
1632-
{ "switch-to-tab-6", "alt+6" }, { "switch-to-tab-7", "alt+7" },
1633-
{ "switch-to-tab-8", "alt+8" }, { "switch-to-tab-9", "alt+9" },
1634-
{ "switch-to-last-tab", "alt+0" },
1631+
{ "switch-to-tab-2", "alt+2" }, { "switch-to-tab-3", "alt+3" },
1632+
{ "switch-to-tab-4", "alt+4" }, { "switch-to-tab-5", "alt+5" },
1633+
{ "switch-to-tab-6", "alt+6" }, { "switch-to-tab-7", "alt+7" },
1634+
{ "switch-to-tab-8", "alt+8" }, { "switch-to-tab-9", "alt+9" },
1635+
{ "switch-to-last-tab", "alt+0" },
16351636
#if EE_PLATFORM == EE_PLATFORM_MACOS
1636-
{ "menu-toggle", "mod+shift+m" },
1637+
{ "menu-toggle", "mod+shift+m" },
16371638
#endif
1638-
{ "lock-toggle", "mod+shift+l" },
1639+
{ "lock-toggle", "mod+shift+l" },
16391640
};
16401641
}
16411642

@@ -3206,15 +3207,49 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe
32063207
} );
32073208

32083209
mWindow->getInput()->pushCallback( [this]( InputEvent* event ) {
3209-
if ( event->Type == InputEvent::FileDropped ) {
3210-
std::string file( event->file.file );
3211-
3212-
if ( FileSystem::isDirectory( file ) )
3213-
loadFolder( file );
3214-
else
3215-
onFileDropped( file );
3216-
} else if ( event->Type == InputEvent::TextDropped ) {
3217-
onTextDropped( event->textdrop.text );
3210+
switch ( event->Type ) {
3211+
case InputEvent::FileDropped: {
3212+
std::string file( event->file.file );
3213+
mPathsToLoad.emplace_back( std::move( file ) );
3214+
break;
3215+
}
3216+
case InputEvent::TextDropped: {
3217+
onTextDropped( event->textdrop.text );
3218+
break;
3219+
}
3220+
case InputEvent::EventsSent: {
3221+
if ( mPathsToLoad.empty() )
3222+
break;
3223+
3224+
std::size_t dirCount = 0;
3225+
std::size_t lastDirIdx = std::numeric_limits<std::size_t>::max();
3226+
std::size_t idx = 0;
3227+
for ( const auto& file : mPathsToLoad ) {
3228+
if ( FileSystem::isDirectory( file ) ) {
3229+
dirCount++;
3230+
lastDirIdx = idx;
3231+
}
3232+
idx++;
3233+
}
3234+
3235+
bool onlyDirectories = dirCount == mPathsToLoad.size();
3236+
3237+
// If only directories has been dropped, just load the last directory dropped
3238+
if ( onlyDirectories ) {
3239+
loadFolder( mPathsToLoad[lastDirIdx] );
3240+
} else {
3241+
// Load only files even if there are directories
3242+
for ( const auto& file : mPathsToLoad ) {
3243+
if ( !FileSystem::isDirectory( file ) )
3244+
onFileDropped( file );
3245+
}
3246+
}
3247+
3248+
mPathsToLoad.clear();
3249+
break;
3250+
}
3251+
default:
3252+
break;
32183253
}
32193254
} );
32203255

src/tools/ecode/ecode.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ class App : public UICodeEditorSplitter::Client {
543543
UIMessageBox* mCloseMsgBox{ nullptr };
544544
UIMenuBar* mMenuBar{ nullptr };
545545
std::unique_ptr<SettingsActions> mSettingsActions;
546+
std::vector<std::string> mPathsToLoad;
546547

547548
void saveAllProcess();
548549

0 commit comments

Comments
 (0)