How to add a menuitem in Nautilus context menu.

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 could 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 could use gnome_vfs-get_local_path_from_uri (nautilus_file_get_uri (file)) to get the actuall file name.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

To submit your comment, click the image below where it asks you to...
Clickcha - The One-Click Captcha