mitchcurtis / slate

Pixel Art Editor
GNU General Public License v3.0
1.07k stars 103 forks source link

Non-native recent file menu not closing when clicking different menu items #128

Closed mitchcurtis closed 5 years ago

mitchcurtis commented 5 years ago

On Ubuntu, clicking on a menu item in the recent files list will not close the menu as it should. This only happens if you click on a menu item for a project that's not currently open; if you click the menu item for a project that is currently open, the menu will close as expected.

Can be reproduced with all platforms when commenting out the +nativemenubar selector.

mitchcurtis commented 5 years ago

Happens with Qt 5.12.3 as well.

Couldn't reproduce it with a minimal example:

import QtQuick 2.12
import QtQuick.Controls 2.12

ApplicationWindow {
    visible: true
    width: 640
    height: 480

    function doStuff() {
        print("doing stuff")
    }

    menuBar: MenuBar {
        Menu {
            id: fileMenu
            title: qsTr("File")

            // Usually we'd set a NoFocus policy on controls so that we
            // can be sure that shortcuts are only activated when the canvas
            // has focus (i.e. no popups are open), but doing so on MenuItems
            // would prevent them from being navigable with the arrow keys.
            // Instead, we just force focus on the canvas when a menu closes.
            onClosed: canvas.forceActiveFocus()

            MenuItem {
                objectName: "newMenuButton"
                text: qsTr("New")
            }

            MenuSeparator {}

            Menu {
                id: recentFilesSubMenu
                objectName: "recentFilesSubMenu"
                title: qsTr("Recent Files")
                // This can use LayoutGroup if it's ever implemented: https://bugreports.qt.io/browse/QTBUG-44078
                width: 400
                enabled: recentFilesInstantiator.count > 0

                onClosed: canvas.forceActiveFocus()

                Instantiator {
                    id: recentFilesInstantiator
                    objectName: "recentFilesInstantiator"
                    model: 10
                    delegate: MenuItem {
                        // We should elide on the right when it's possible without losing the styling:
                        // https://bugreports.qt.io/browse/QTBUG-70961
                        objectName: text + "MenuItem"
                        text: "Item"
                        onTriggered: doStuff()
                    }

                    onObjectAdded: recentFilesSubMenu.insertItem(index, object)
                    onObjectRemoved: recentFilesSubMenu.removeItem(object)
                }

                MenuSeparator {}

                MenuItem {
                    objectName: "clearRecentFilesMenuItem"
                    //: Empty the list of recent files in the File menu.
                    text: qsTr("Clear Recent Files")
                }
            }

            MenuItem {
                objectName: "openMenuItem"
                text: qsTr("Open")
                onTriggered: doStuff()
            }

            MenuSeparator {}

            MenuItem {
                objectName: "showLocationMenuItem"
                //: Opens the project directory in the file explorer.
                text: qsTr("Show Location")
            }

            MenuSeparator {}

            MenuItem {
                objectName: "saveMenuItem"
                text: qsTr("Save")
            }

            MenuItem {
                objectName: "saveAsMenuItem"
                text: qsTr("Save As")
            }

            MenuItem {
                id: exportMenuItem
                //: Exports the project as a single image.
                objectName: "exportMenuItem"
                text: qsTr("Export")
            }

            MenuItem {
                objectName: "autoExportMenuItem"
                //: Enables automatic exporting of the project as a single image each time the project is saved.
                text: qsTr("Auto Export")
                checkable: true
            }

            MenuSeparator {}

            MenuItem {
                objectName: "closeMenuItem"
                text: qsTr("Close")
            }

            MenuSeparator {}

            MenuItem {
                objectName: "revertMenuItem"
                //: Loads the last saved version of the project, losing any unsaved changes.
                text: qsTr("Revert")
            }

            MenuSeparator {}

            MenuItem {
                objectName: "quitMenuItem"
                text: qsTr("Quit Slate")
            }
        }
    }

    Item {
        id: canvas
    }
}