how to disable the drag-n-drop in Nstextfield from finder

Discussion in 'Mac Programming' started by juliana42, May 19, 2009.

  1. juliana42 macrumors newbie

    May 19, 2009
    As we know, if Nstextfield gets the focus, we can simply drag a file or a folder from finder then drop in the textfield, the textfield will be filled with the path you dragged.
    but now I must disable this function to only allow the path of certain file types be dragged into the textfield, for example, the file suffix is .pdf. how should I do?

    at first, I want to find out whether this function is due to the drag and drop function in the textfield. so I add some code: unregisterdraggedtypes in the subclass from Nstextfield. but it still works on the function of drag and drop from finder. How can I disable it?

    any help will be appreciated!
  2. kainjow Moderator emeritus


    Jun 15, 2000
    My guess is you'll probably have to play with the field editor and provide an NSTextView subclass.
  3. juliana42 thread starter macrumors newbie

    May 19, 2009
    Yes, I think it can work with your method. Thank u very much.

    But then I found that when the textfield is not editable, it won't accept the dropped path from finder. So I made it into that once I drag-enter the small view which contains the textfield, I set the textfield to be uneditable. If the path is acceptable, I will set it into the textfield. When it drag-exit, the textfield will be set to editable.

    but this is just a workround. I still don't know how to prevent the function in the textfield.

Share This Page