Overriding the default context menu within FIleChooser Widget

Is there a way to customize/override the default right click/context menu within a Gtk::FileChooser widget ?
Currently by default, we get a menu with the follwing options,

  • Open File
  • Open with File Manager
  • Copy Location
  • Add to Bookmarks

Is there a way to bypass these ?

DJ

What are you trying to accomplish?

Thanks for the revert.

Thing is, in our application we do not want the user to open a filemanager from within file chooser. However, the context menu option defeats this. Also, we want to introduce few other things under this context menu.

Basically, we want to customize the entire conext menu for the requirement in hand.

DJ

But what are you trying to do with this? What options are you looking to add? I’m asking because this might be a case of the XY problem.

This is more with respect to the programming with Gtkmm. We are not sure what we should do to make sure the user’s can’t access the local data directly. In a application scenario, we do not wants the users to access the local files over a filer manager and can be acheived with usual OS hardening methos, but this specific option in the file chooser widget in gtkmm defeats this when it allows the user to open a file manager from within its context menu while inside the file chooser.

Hope i an clear !!

No, you simply can’t do that.

You should not be using FileChooserWidget directly: you should use the GtkFileChooserNative object to run the native dialog of the platform. When running under Linux, the native dialog can be run by a separate process as part of the sandboxing mechanism, which means you can’t just inject your own code into it.

Adding random menu items to a standard file selector is not a great UI: it violates the principle of least astonishment; it makes those options undiscoverable; and it creates a behavioural difference between your app and any other app in the system. I strongly encourage you to rethink your approach.

Thanks for your reply.

Adding new items to a standard menu is not a good idea and i totally agree. But here we are talking about a specialized application where the user doesn’t have access to any other application. The primary intent here is to totally remove the right click menu from within the file chooser so that user cannot open the file browser and access everything.

Let me look into your suggestion. I will revert soon.

DJ

Remove the file manager from the system, or ship a modified version of GTK.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.