首页 \ 问答 \ 有没有办法使默认的NSDragOperation Move仍然允许复制?(Is there a way to make the default NSDragOperation Move and still allow Copy?)

有没有办法使默认的NSDragOperation Move仍然允许复制?(Is there a way to make the default NSDragOperation Move and still allow Copy?)

在某些应用程序(例如GarageBand)中,初始拖动操作为“移动”,如果在拖动时按下Option键,则支持“复制”。 我尝试了几件事,但没有取得任何成功。 如果在操作掩码中指定了.Copy,则它始终成为默认操作。 这可能吗?

    func draggingSession(session: NSDraggingSession, sourceOperationMaskForDraggingContext context: NSDraggingContext) -> NSDragOperation {
    if context == NSDraggingContext.OutsideApplication
    {
        return .None
    }
    else
    {
        return [.Move,.Copy]
    }
}

In some applications (GarageBand for example) the initial drag operation is Move, and Copy is supported if you press the Option key while dragging. I have tried several things but have not had any success. If .Copy is specified in the operation mask it always becomes the default operation. Is this possible?

    func draggingSession(session: NSDraggingSession, sourceOperationMaskForDraggingContext context: NSDraggingContext) -> NSDragOperation {
    if context == NSDraggingContext.OutsideApplication
    {
        return .None
    }
    else
    {
        return [.Move,.Copy]
    }
}

原文:https://stackoverflow.com/questions/38030202
更新时间:2022-01-17 13:01

最满意答案

如果您尝试将食物添加到课程中,则应使用“拥有”关系,例如:

public class Course {
    private Food food;

    public Course(Food food) {
        this.food = food;
    }

    public Course() {

    }

    public Food getFood() {
        return this.food;
    }

    public void setFood(Food food) {
        this.food = food;
    }
}

我也不会使用StarterFood扩展一个Course,因为extends是for和“ 是一个 ”关系,我称之为StarterCourse,然后在构造函数中为该课程添加默认食物。

public class StarterCourse extends Course {

    public StarterCourse(Food food) {
        // here call the super classes constructor
        // add items via the Course constructor
        super(food);
    }
}

然后在你的主类中测试它试试这个:

public class Main() {
    public static void main() {
        // First create new Food object
        Food food = new Food(); 
        // Create a new StarterCourse and add the Food object to it
        StarterCourse starterCourse = new StarterCourse(food);
    }
}

If your trying to add a Food to a Course, you should use a "has a" relationship for example:

public class Course {
    private Food food;

    public Course(Food food) {
        this.food = food;
    }

    public Course() {

    }

    public Food getFood() {
        return this.food;
    }

    public void setFood(Food food) {
        this.food = food;
    }
}

I also wouldn't use StarterFood to extend a Course, because extends is for and "is a" relationship, I would call it StarterCourse and then add a default food for that course in the constructor.

public class StarterCourse extends Course {

    public StarterCourse(Food food) {
        // here call the super classes constructor
        // add items via the Course constructor
        super(food);
    }
}

Then in your main class to test it out try this:

public class Main() {
    public static void main() {
        // First create new Food object
        Food food = new Food(); 
        // Create a new StarterCourse and add the Food object to it
        StarterCourse starterCourse = new StarterCourse(food);
    }
}

相关问答

更多
  • 问题是, 每次找到一个没有相同ID的条目时,你都会在列表中添加一个新条目...你的add调用是在你的循环中,而不应该是。 基本上,你应该有类似的东西: public void checkEntity(Entity entity) { for (Entity candidate : entities) { if (candidate.getID() == entity.getID()) { candidate.setXPos(entity.getXPos()); ...
  • 谢谢Zoran Regvart! 虽然你没有真正提供答案,但是你通过看到我自己的愚蠢错误帮助我到达那里! 我已将SwipeCardUtil类添加到项目中错误的util文件夹中! 通过将它从客户端util文件夹移动到服务器端util文件夹,我能够编译项目并继续我的工作。 谢谢你睁开眼睛! Thank you Zoran Regvart ! Although you didn't really provide an answer, you helped me get there by seeing my own ...
  • 如果您尝试将食物添加到课程中,则应使用“拥有”关系,例如: public class Course { private Food food; public Course(Food food) { this.food = food; } public Course() { } public Food getFood() { return this.food; } public void setFood(F ...
  • @kjeraska 我猜你正在尝试解析Java项目中的json文件。 JSONParser jsonParser = new JSONParser(); Object jsonData = jsonParser.parse(new FileReader("users/user/desktop/settingspanel.json")); JSONObject json = (JSONObject) jsonData; System.out.println(json.get("keyInYou ...
  • 你检查了路线文件吗? 它包含控制器/操作的路径? 服务器启动没有任何错误? 在我看来路线文件中有错误,你能添加你的配置和你看到的完整错误信息吗? 编辑(添加路线后): mm我担心你的问题是Windows(我上面的评论明显回答,我知道)。 我在Play Google小组中看到了一些与Windows相关的问题。 由于Scala支持在某种程度上仍然有点“实验性”,我只相信你踩到了一个bug。 我会和Play团队一起创建一张票。 did you check the routes file? It contains ...
  • 您对[SITE_COUNTRY_ID]和[SITE_NAME]的组合有唯一约束。 您正尝试插入一行,其中SITE_NAME为“TEST30042015SITEREQUEST”,SITE_COUNTRY_ID为114 要么 您试图以违反此约束的方式更新现有行。 You have a unique constraint on the combination of [SITE_COUNTRY_ID] and [SITE_NAME]. You are trying to insert a row with a SI ...
  • 你可以在没有循环的情况下完成。 假设ArrayList已包含5个元素: oldestElement = latestTransactions.remove(0); // this will remove the element at the 0 index // and decrement the index of all the others 然后 latestTransactions.add(newElemen ...
  • 解决问题的一种可能方法是在processInputData(..)返回学生 private static Student processInputData(String data) { // the same code return currentStudent; } 并在while循环中 while (input != null) { studentQueue.add(processInputData(input)); input = reader.readLine ...
  • 浏览按钮尝试根据当前超类文本框中的内容进行自动匹配。 删除java.lang.Object并输入Act(例如),然后单击Browse并查看您获得的内容。 ;-) 顺便说一句 - 我假设你正在使用Eclipse? 如果是这样,请确认并且有人会重新提出问题,因为它更像是Eclipse使用问题,而不是Android特定问题。 The browse button tries to do an auto-match based on what is currently in the Superclass text b ...
  • List flightOffers明确定义了您可以添加到列表中的什么: FlightOffer实例。 flightOffers.add(new BaseOffer()); 因此无法工作,因为BaseOffer 不是 FlightOffer 。 那么,为什么hotelOffers.add(new BaseOffer()); 工作? 因为您在Hotel hotelObject = new Hotel();使用原始类型Hotel禁用了泛型类型检查Hotel hotelOb ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)