Skip to content
Nicky Weber edited this page Jun 23, 2014 · 3 revisions

Resource commands relate to operations on selected items in the file view, first tab, left panel.

The ResourceCommandController is a convenient way to execute commands selected in the file outlineview (It will ask the outlineview for selected resources). The AppDelegate keeps a configured(dependencies injected) instance of the ResourceCommandController.

The various ResourceCommands can be executed without the ResourceCommandController but the dependencies have to be injected manually. This way you can execute commands on resources without the dependency to the outline view, just set the resources array.

---

Steps to add a new operation for a resource

  1. Create a new class which conforms to the ResourceCommandProtocol
    Dependencies are meant to be injected(manually at the moment but there may be a day...) so add properties that reflect dependencies to other classes
  2. Implement the the required methods and properties
  3. Add a method to the ResourceCommandController, which accepts an (id)sender parameter
  4. Create an instance of your new command and inject dependencies If there is a dependency the ResourceCommandController cannot satisfy with members add that dependency as property to the command controller as well and inject the dep. Usually that is the AppDelegate configuring the command controller.

Steps to wire the new operation to the context menu

  1. Make the new command conform to the ResourceCommandContextMenuProtocol This will provide a way for the ResourceContextMenu to query a command for a name and figure out whether a command is valid for given resources
  2. Open ResourceContextMenu and have a look at -setupMenu The context menu is configured to set new menu items' targets to an instance of the ResourceCommandController. Add the menu with:
[self appendItemToMenuWithClass:[MyNewCommand class] addSeparator:NO action:@selector(myNewCommand:)];

Make sure the selector is the same as in the resource command controller's interface

Done.

Clone this wiki locally