有没有办法使默认的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
最满意答案
如果您尝试将食物添加到课程中,则应使用“拥有”关系,例如:
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()); ...
-
将javax.smartcardio添加到项目时出现Java Build Error(Java Build Error when adding javax.smartcardio to project)[2022-12-26]
谢谢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 ...
-
将json添加到java项目(Adding json to java project)[2023-06-16]
@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 ...