예제 #1
0
        void RenderFile(string fileName, string fullPath, int index)
        {
            ImGui.PushId(fileName);

            if (ImGui.Selectable(fileName, selectedIndex == index))
            {
                selectedIndex = index;
                ImGui.CloseCurrentPopup();
            }

            if (ImGui.IsItemClicked(1))
            {
                ImGui.OpenPopup("file_popup");
            }
            if (ImGui.BeginPopup("file_popup"))
            {
                ImGui.BulletText(fileName);

                bool renameChosen = false;
                if (ImGui.MenuItem("Rename"))
                {
                    renameFileText = fileName;
                    renameChosen   = true;
                }

                if (ImGui.MenuItem("Delete"))
                {
                    EditorActions.DeleteFile(fullPath);
                }

                ImGui.EndPopup();

                if (renameChosen)
                {
                    ImGui.CloseCurrentPopup();
                    ImGui.OpenPopup("renamepop");
                }
            }

            if (ImGui.BeginPopup("renamepop"))
            {
                ImGui.BulletText("Rename:");
                ImGui.Separator();
                ImGui.InputText("##label", ref renameFileText);

                if (MonoApplication.instance.nativeApp.window.IsKeyTapped(KeyCode.Enter))
                {
                    EditorActions.RenameFile(fullPath, renameFileText);
                    ImGui.CloseCurrentPopup();
                }

                ImGui.EndPopup();
            }

            if (ImGui.BeginDragSource())
            {
                ImGui.SetDragAndDropPayload("file", fullPath);

                ImGui.Text(fileName);
                ImGui.EndDragAndDropSource();
            }
            if (ImGui.BeginDragAndDropTarget())
            {
                if (ImGui.AcceptDragAndDropPayload("file", out object payload))
                {
                    string draggedFile = (string)payload;

                    if (OnFileDragDropped != null)
                    {
                        OnFileDragDropped(draggedFile, fullPath);
                    }
                }
                ImGui.EndDragAndDropTarget();
            }
            ImGui.PopId();
        }