How to add a menuitem in Nautilus context menu.

Source: Internet
Author: User

1. In src/file-Manager/directory, add command section and menuitem section in nautilus-directory-view-ui.xml.

<Commands>
...
<Cmd name = "name convert"
_ Label = "name _ convert"
_ Tip = "convert the file name"/>
...
</Commands>

<Popup name = "selection" tearoff = "0">
....
<Placeholder name = "file actions" delimit = "TOP">
...
<Menuitem name = "name convert" verb = "name convert"/>
...
</Placeholder>
...
</Popup>

2. In fm-directory-view.c:

# Define fm_directory_view_command_name_convert "/commands/name convert"

In real_merge_menus () function, bonobouiverb verbs [] array, add the following item:
Bonobo_ui_verb ("name convert", name_convert_callback ),

You cocould use nautilus_bonobo_set_sensitive () or nautilus_bonobo_hidden () to show or hide this menuitem.

3. How to launch the corresponding program in callback function:

Gnomevfsmimeapplication * test;

Test = g_new0 (gnomevfsmimeapplication, 1 );
Test-> id = g_strdup ("test");
Test-> name = g_strdup ("this is a test");
Test-> command = g_strdup ("test");
Test-> expects_uris = gnome_vfs_mime_application_argument_type_paths;

File = nautilus_file (selection-> data );
Nautilus_launch_application (test, file, null );

G_free (test-> ID );
G_free (test-> name );
G_free (test-> name );
G_free (test );

You cocould use gnome_vfs-get_local_path_from_uri (nautilus_file_get_uri (File) to get the actuall file name.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.