# A Simple Extension

Create an empty file with the following code:

## A Simple Extension

    import caja

    class SimpleMenuExtension(caja.MenuProvider):
    def __init__(self):
        pass

    def menu_activate_cb(self, menu, file):
        print "menu_activate_cb",file

    def get_file_items(self, window, files):
        if len(files) != 1:
            return

        file = files[0]

        item = caja.MenuItem(
            "SimpleMenuExtension::Show_File_Name",
            "Showing %s" % file.get_name(),
            "Showing %s" % file.get_name()
        )
        item.connect('activate', self.menu_activate_cb, file)

        return [item]

Save this file as TestExtension.py in the ~/.caja/python-extensions folder. You may need to create this folder. To run, open the terminal and type:

    $ caja -q
    $ caja --no-desktop

Once Caja starts, right-click on a file and you should see a new menu item, "Showing #filename#". It is as simple as that!

As mentioned above, in order to get loaded by Caja, a python extension must import the caja module, create a class derived from a caja *Provider, then create the methods that will be called by Caja when it requests information from its providers. In this case, when someone right-clicks on a file, Caja will ask all of its MenuProviders for additional menu items to show the user. When folders or files are clicked, the get_file_items method is called and a list of caja.MenuItems is expected.