0

enter image description here

I want to remove Copy, Duplicate operation from document browser's context menu action In my code for class FileProviderItem modify property capabilities

class FileProviderItem: NSObject, NSFileProviderItem {

    var capabilities: NSFileProviderItemCapabilities {
        return allowsReading
    }
}

By using above code i can remove Move,Delete operation from document browser's context menu action.

Is there any way to remove Copy, Duplicate operation from document browser's context menu action?

jignesh Vadadoriya
  • 3,244
  • 3
  • 18
  • 29
  • If the file can be read it can be copied ( and pasted to another location). The only way to disable copy would be to disable reading (but that would defeat the purpose). If the container can be written to and the file can be read then the file can be duplicated. Disable writes to the container would disable Duplicate, but again that might not be what you want. There seems to be no other way to control these actions – Dale Apr 16 '18 at 21:22

1 Answers1

0

Just to also post what I said to you in the comments, this behavior is defined by the file provider extension UI. When adding the file provider extension to the application, it adds two targets in your apps targets. If you don't want this type of functionality, then simply just remove the file provider extension UI target from your project.

Here's an excerpt from Apple on the File Provider Extension UI:

Use the File Provider UI extension to add custom actions to your File Provider extension. These actions appear if the user long presses an item while browsing your file provider's content. When the user selects your action, the system displays your custom user interface, where the user completes the action. After the user is finished, you must explicitly cancel or complete the action.

https://developer.apple.com/documentation/fileproviderui

Example of how to delete file provider UI

Asleepace
  • 3,466
  • 2
  • 23
  • 36
  • Thanks @Asleepace ,In my project i want to remove only this Copy and Duplicate Action from context menu. if i remove FileProviderUI Targets then rest of all action are remove which i don't want – jignesh Vadadoriya Feb 21 '18 at 06:01
  • I don’t know too much about the file provider UI but hopefully your answer is in there, good luck! – Asleepace Feb 21 '18 at 06:26
  • 1
    From playing around I found out that the "Duplicate" action can be removed by not allowing write operations on the parent folder. This is expected, but not optimal – nfls Feb 22 '18 at 15:27
  • 1
    I also found out that custom actions are described in Info.plist NSExtentionFileProviderActions key, and can be disabled by changing the respective predicate. Maybe the Copy and Duplicate can also be changed this way? Refer: https://developer.apple.com/documentation/fileproviderui/adding_actions – nfls Feb 22 '18 at 16:15