@@ -160,6 +160,7 @@ FileDialog::FileDialog(const bool standalone_window, const FileDialog_Type type,
160160 m_hover_animation = 0 .0f ;
161161 m_is_renaming = false ;
162162 m_rename_request_focus = false ;
163+ m_rename_select_pending = false ;
163164 m_rename_item_id = UINT32_MAX;
164165 m_context_menu_id = 0 ;
165166}
@@ -291,6 +292,8 @@ void FileDialog::ShowOverwriteDialog(string* directory, string* file_path)
291292 ImGui::SetNextWindowSize (ImVec2 (420 , 0 ), ImGuiCond_Appearing);
292293 ImGui::PushStyleVar (ImGuiStyleVar_WindowPadding, ImVec2 (16 , 16 ));
293294 ImGui::PushStyleVar (ImGuiStyleVar_WindowRounding, 8 .0f );
295+ // suppress the dim overlay that imgui draws behind modal popups so the rest of the editor stays visible
296+ ImGui::PushStyleColor (ImGuiCol_ModalWindowDimBg, ImVec4 (0 , 0 , 0 , 0 ));
294297
295298 if (ImGui::BeginPopupModal (" ##overwrite_dialog" , nullptr , ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoTitleBar))
296299 {
@@ -337,6 +340,7 @@ void FileDialog::ShowOverwriteDialog(string* directory, string* file_path)
337340 ImGui::EndPopup ();
338341 }
339342
343+ ImGui::PopStyleColor ();
340344 ImGui::PopStyleVar (2 );
341345}
342346
@@ -766,13 +770,17 @@ void FileDialog::RenderGridView()
766770
767771 ImGui::PushID (static_cast <int >(i));
768772
773+ // wrap the whole cell in a group so the rename input text (if any) cannot
774+ // become the trailing item that SameLine() snaps to, which would break tiling
775+ ImGui::BeginGroup ();
776+
769777 ImVec2 screen_pos = ImGui::GetCursorScreenPos ();
770778
771779 // card dimensions
772780 ImVec2 card_min = screen_pos;
773781 ImVec2 card_max = ImVec2 (screen_pos.x + item_width - 4 , screen_pos.y + item_height - 4 );
774782
775- // invisible button for interaction - this is the only item we submit
783+ // invisible button for interaction
776784 ImGui::InvisibleButton (" ##card" , ImVec2 (item_width - 4 , item_height - 4 ));
777785 bool is_hovered = ImGui::IsItemHovered ();
778786 bool is_selected = (m_selected_item_id == item.GetId ());
@@ -919,6 +927,8 @@ void FileDialog::RenderGridView()
919927 ItemClick (&item);
920928 ItemContextMenu (&item);
921929
930+ ImGui::EndGroup ();
931+
922932 ImGui::PopID ();
923933
924934 // layout: new row when columns are full
@@ -1170,9 +1180,8 @@ void FileDialog::ItemDrag(FileDialogItem* item)
11701180 m_was_dragging = true ;
11711181 const auto set_payload = [this ](const ImGuiSp::DragPayloadType type, const string& path_full, const string& path_relative)
11721182 {
1173- m_drag_drop_payload.type = type;
1174- m_drag_drop_payload.data = path_full.c_str ();
1175- m_drag_drop_payload.path_relative = path_relative.c_str ();
1183+ m_drag_drop_payload.type = type;
1184+ m_drag_drop_payload.set_paths (path_full.c_str (), path_relative.c_str ());
11761185 ImGuiSp::create_drag_drop_payload (m_drag_drop_payload);
11771186 };
11781187
@@ -1227,10 +1236,11 @@ void FileDialog::ItemContextMenu(FileDialogItem* item)
12271236
12281237 if (ImGui::MenuItem (" Rename" ))
12291238 {
1230- m_is_renaming = true ;
1231- m_rename_request_focus = true ;
1232- m_rename_buffer = item->GetLabel ();
1233- m_rename_item_id = item->GetId ();
1239+ m_is_renaming = true ;
1240+ m_rename_request_focus = true ;
1241+ m_rename_select_pending = true ;
1242+ m_rename_buffer = item->GetLabel ();
1243+ m_rename_item_id = item->GetId ();
12341244 }
12351245
12361246 if (FileSystem::IsEngineLuaFile (item->GetPath ()))
@@ -1288,10 +1298,11 @@ void FileDialog::DialogUpdateFromDirectory(const string& file_path)
12881298
12891299 lock_guard<mutex> lock (m_mutex_items);
12901300 m_items.clear ();
1291- m_selected_item_id = UINT32_MAX;
1292- m_is_renaming = false ;
1293- m_rename_request_focus = false ;
1294- m_rename_item_id = UINT32_MAX;
1301+ m_selected_item_id = UINT32_MAX;
1302+ m_is_renaming = false ;
1303+ m_rename_request_focus = false ;
1304+ m_rename_select_pending = false ;
1305+ m_rename_item_id = UINT32_MAX;
12951306
12961307 // directories first
12971308 auto directories = FileSystem::GetDirectoriesInDirectory (file_path);
@@ -1420,8 +1431,32 @@ void FileDialog::RenameItemInline(FileDialogItem* item, float width)
14201431 ImGui::PushStyleVar (ImGuiStyleVar_FramePadding, ImVec2 (4 , 2 ));
14211432 ImGui::SetNextItemWidth (width);
14221433
1423- const ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll;
1424- const bool committed = ImGui::InputText (" ##rename_inline" , &m_rename_buffer, flags);
1434+ // on first activation, select only the stem (filename without the extension)
1435+ // so the user does not accidentally type over the dot extension
1436+ auto select_stem_callback = [](ImGuiInputTextCallbackData* data) -> int
1437+ {
1438+ bool * pending = static_cast <bool *>(data->UserData );
1439+ if (pending && *pending)
1440+ {
1441+ int stem_len = data->BufTextLen ;
1442+ for (int i = data->BufTextLen - 1 ; i > 0 ; --i)
1443+ {
1444+ if (data->Buf [i] == ' .' )
1445+ {
1446+ stem_len = i;
1447+ break ;
1448+ }
1449+ }
1450+ data->SelectionStart = 0 ;
1451+ data->SelectionEnd = stem_len;
1452+ data->CursorPos = stem_len;
1453+ *pending = false ;
1454+ }
1455+ return 0 ;
1456+ };
1457+
1458+ const ImGuiInputTextFlags flags = ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackAlways;
1459+ const bool committed = ImGui::InputText (" ##rename_inline" , &m_rename_buffer, flags, select_stem_callback, &m_rename_select_pending);
14251460 const bool deactivated = ImGui::IsItemDeactivated ();
14261461 const bool escape_pressed = ImGui::IsKeyPressed (ImGuiKey_Escape);
14271462
0 commit comments