Skip to content

Add Native File Chooser Dialog integration for Nemo and XDG Desktop Portals#3786

Open
Twilight0 wants to merge 3 commits into
linuxmint:masterfrom
Twilight0:feature/native-file-picker
Open

Add Native File Chooser Dialog integration for Nemo and XDG Desktop Portals#3786
Twilight0 wants to merge 3 commits into
linuxmint:masterfrom
Twilight0:feature/native-file-picker

Conversation

@Twilight0

Copy link
Copy Markdown

Overview & Rationale

Currently, Cinnamon environments running sandboxed Flatpaks or host applications rely on basic or external file chooser portals. These defaults lack visual coherence with the rest of the Cinnamon desktop and Nemo.

This Pull Request implements a custom, fully-featured native file chooser dialog for Nemo, exported over D-Bus via the org.Nemo.FileChooser service. When paired with the accompanying changes in xdg-desktop-portal-xapp, this allows all application file-picking requests (from GitKraken, Web Browsers, Flatpaks, etc.) to use a premium, native-feeling Nemo file selection interface.


Features Implemented

1. Unified Multi-Pane Layout

  • Places Sidebar: Integrates the standard Places sidebar (GtkPlacesSidebar), ensuring user bookmarks, network mounts, removable media, and recent paths are instantly accessible.
  • Main Browser Stack: A dynamic layout supporting three view modes:
    • Grid View (Icons): High-fidelity layout with custom large icons.
    • List View (Columns): Standard layout showing file details.
    • Compact View: Horizontal icon flow for rapid list traversal.
  • Dynamic Preview Pane: A sidebar on the right displaying real-time previews for selected files, including:
    • Image/video metadata (dimensions, size).
    • High-quality thumbnail previews retrieved asynchronously via the Freedesktop.org thumbnail cache specifications.

2. Directory Selection (SELECT_FOLDER / GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER)

  • Targeted Folder Listings: When operating in directory-selection mode, files are automatically hidden from the main browser list so users see and navigate only folders.
  • Action Button Label: The main accept action dynamically switches its label to _Select rather than _Open.
  • Hierarchical Fallback Selection: If a user is inside their target directory (e.g. /home/user/Projects/nemo) and clicks Select without highlighting a specific sub-folder, the dialog correctly falls back and returns the URI of the current folder.

3. Navigation & Context Enhancements

  • Up Button: Placed on the header bar to navigate to the parent folder. Its sensitivity is dynamically calculated (disabled at the system root /).
  • Interactive Location Bar: Switches between a clickable breadcrumb path and a text entry box via the edit button or Ctrl+L shortcut. Supports Escape to return to breadcrumbs.
  • Create Folder Modal: A dedicated button on the header and options in the context menu to create folders instantly.
  • Header Sorting (List View): Columns (Name, Size, Type, Date Modified) support clicking to sort. Folders are always grouped before files. Sorting is paused during list loads to avoid UI freezes.
  • Column Customization: Right-clicking the List View header exposes a context menu to toggle the visibility of the Size, Type, and Date Modified columns.
  • Context Menus: Right-clicking the file browser area provides options to toggle hidden files, customize sorting options, refresh the directory, copy locations, and create folders.
  • Keyboard Shortcuts: Fully maps Ctrl+H to toggle hidden files and Ctrl+L to edit the location path text.

4. D-Bus Daemon Integration

  • Updated the org.Nemo.FileChooser D-Bus XML specification to support folder selection:
    • OpenFile method signature updated to (sasbbs) to accept the directory boolean.
  • Fixed the dialog response matching in nemo-file-chooser-dbus.c to accept both GTK_RESPONSE_ACCEPT (-3) and GTK_RESPONSE_OK (-5), resolving empty return values when using the Glade-defined ok_button.

Testing Verification

  1. D-Bus Interface: Invoked using custom Python test scripts calling the desktop portal.
  2. Directory Picking: Verified directory selection returns the correct path structure to the calling process.
  3. Application Test: Verified GitKraken (host Electron app) successfully uses this dialog to open local repositories via the portal.

- Registered and implemented D-Bus interface org.Nemo.FileChooser to bridge XDG Desktop Portal file choosing requests.
- Added custom GTK 3 nemo-file-chooser-dialog using a premium, multi-pane UI layout:
  * Left panel: Places sidebar showing system bookmarks, mounts, and recent paths.
  * Center panel: Dynamic GtkStack supporting Grid View, List View, and Compact View modes.
  * Right panel: Interactive preview pane detailing metadata and showing visual thumbnails.
- Added dedicated header bar action buttons:
  * Create Folder button (symbolic icon folder-new-symbolic) placed next to navigation.
  * Toggle Location Entry button (symbolic icon document-edit-symbolic) to switch path navigation bar into a text path entry.
  * Up button (symbolic icon go-up-symbolic) placed between forward button and create folder button.
- Integrated Ctrl+L shortcut to toggle path text entry mode and escape key to close it.
- Implemented folder creation modal triggered via both the header button and context menu.
- Kept the path entry input text dynamically synchronized with current directories during sidebar, back/forward, or list navigation.
- Managed Up button sensitivity dynamically based on the existence of a parent directory (disabled at root folder /).
- Implemented support for directory selection mode (SELECT_FOLDER):
  * Added boolean directory input argument to OpenFile D-Bus method signature.
  * Dynamically changes the dialog's acceptance button label to '_Select' in folder selection mode.
  * Filters out non-directory files to display only folders inside directory listings in SELECT_FOLDER mode.
  * Implemented fallback returns to choose the current directory if accept is triggered without choosing subfolders.
- Implemented high-quality cached video (mp4) and image thumbnail lookup by querying the Freedesktop.org thumbnail path schema asynchronously.
- Optimized zooming layout by linking Ctrl+Scroll events (supporting smooth scroll wheel inputs) to re-evaluate list store icons and adjust spacing in all view modes.
- Added explicit tooltips on hover for layout toggle buttons and preserved standard scrolling.
- Integrated clickable header sorting (Name, Size, Type, Modified) in List View:
  * Uses a custom comparison function ensuring folders are always clustered first (matching upstream Nemo behaviour).
  * Added Type (description lookup) and Modified (date/timestamp) columns.
  * Temporarily suspends sorting during directory enumeration to optimize batch inserts and prevent lag.
- Enhanced List View column usability:
  * Made columns resizable by user dragging.
  * Created a right-click context menu on headers to toggle visibility of Size, Type, and Modified columns.
- Implemented files area background right-click context menu:
  * Provides a check item for toggling hidden files (starts with dot '.').
  * Provides a Sort By submenu containing radio options for Name, Size, Type, and Date Modified.
  * Includes Create Folder, Show in File Manager, Copy Location, Refresh, and Properties actions.
  * Connected Ctrl+H shortcut to toggle display of hidden files on keyboard input.
The ok_button in nemo-file-chooser-dialog.glade is configured with a response ID of -5 (GTK_RESPONSE_OK) instead of -3 (GTK_RESPONSE_ACCEPT). Update the open and save dialog response handlers in nemo-file-chooser-dbus.c to accept both GTK_RESPONSE_ACCEPT and GTK_RESPONSE_OK, ensuring that selected URIs/paths are properly returned to the portal caller when the dialog is accepted.
Allows D-Bus activation of Nemo (running in background via --no-default-window) when a client application calls the org.Nemo.FileChooser interface, removing manual daemon startup requirements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant