btzy / nativefiledialog-extended

Cross platform (Windows, Mac, Linux) native file dialog library with C and C++ bindings, based on mlabbe/nativefiledialog.
zlib License
598 stars 89 forks source link

Portal: Support defaultPath for OpenDialog, OpenDialogMultiple, and PickFolder #108

Closed btzy closed 1 year ago

btzy commented 1 year ago

The current_folder key will be supported by the OpenFile() portal soon in PR https://github.com/flatpak/xdg-desktop-portal/pull/1045 (issue https://github.com/flatpak/xdg-desktop-portal/issues/796). This PR makes NFDe set the current_folder key appropriately. On systems with an old version of xdg-desktop-portal installed, the new key will be ignored and we will get the old behaviour (of opening some default folder).

Resolves #66.

Test:

$ dbus-monitor "interface=org.freedesktop.portal.FileChooser"
method call time=1688143949.180253 sender=:1.233 -> destination=org.freedesktop.portal.Desktop serial=3 path=/org/freedesktop/portal/desktop; interface=org.freedesktop.portal.FileChooser; member=OpenFile
   string ""
   string "Open File"
   array [
      dict entry(
         string "handle_token"
         variant             string "GBIMGKOKDJGNMEHNPNNHCFINIDAOAFBLOBMHCGPHAPMHNAHBJPPHGALLOKDHJKFI"
      )
      dict entry(
         string "filters"
         variant             array [
               struct {
                  string "Source code (c, cpp, cc)"
                  array [
                     struct {
                        uint32 0
                        string "*.c"
                     }
                     struct {
                        uint32 0
                        string "*.cpp"
                     }
                     struct {
                        uint32 0
                        string "*.cc"
                     }
                  ]
               }
               struct {
                  string "Headers (h, hpp)"
                  array [
                     struct {
                        uint32 0
                        string "*.h"
                     }
                     struct {
                        uint32 0
                        string "*.hpp"
                     }
                  ]
               }
               struct {
                  string "All files"
                  array [
                     struct {
                        uint32 0
                        string "*"
                     }
                  ]
               }
            ]
      )
      dict entry(
         string "current_filter"
         variant             struct {
               string "Source code (c, cpp, cc)"
               array [
                  struct {
                     uint32 0
                     string "*.c"
                  }
                  struct {
                     uint32 0
                     string "*.cpp"
                  }
                  struct {
                     uint32 0
                     string "*.cc"
                  }
               ]
            }
      )
      dict entry(
         string "current_folder"
         variant             array of bytes "/usr" + \0
      )
   ]