Posts

Post not yet marked as solved
2 Replies
206 Views
Hi, Using purely swift programatically (no storyboard), I'm able to create an NSWindow like so: var window = NSWindow (contentRect: pInstruction.GetFrame (), styleMask: [.miniaturizable, .closable, .resizable, .titled], backing: .buffered, defer: false) window.title = "Some Title" window.contentViewController = MyViewController () let windowidentifier = NSUserInterfaceItemIdentifier ("WinID1") window.identifier = windowidentifier window.makeKeyAndOrderFront(nil) This works fine and I can see a window on screen. Later, when I want to access the window I can use a utility method: static func GetWindow(_ pWindowID: NSUserInterfaceItemIdentifier) -> NSWindow? { let windows = NSApp.windows for window in windows { if window.identifier == pWindowID { return window } } return nil } // Then I can call this function like so: let windowidentifier = NSUserInterfaceItemIdentifier ("WinID1") let window = GetWindow (windowidentifier) This also works fine. However, if I do window.setIsVisible(false) or window.orderOut (nil) to temporarily hide the window, then NSApp.windows returns an empty array and I'm not able to find the window object and my Utility method "GetWindow ()" doesn't work. Any suggestions on how I can find hidden windows?
Posted Last updated
.
Post not yet marked as solved
0 Replies
256 Views
Hi, I'm trying to drag an NSTextView from one NSView to another. I'm getting the right events, but the drag animation is not coming up. Subclassed TextView: class MyTextView:NSTextView, NSPasteboardItemDataProvider { func pasteboard(_ pasteboard: NSPasteboard?, item: NSPasteboardItem, provideDataForType type: NSPasteboard.PasteboardType) { NSLog ("Paste") } override func mouseDown(with theEvent: NSEvent) { let pasteboardItem = NSPasteboardItem() pasteboardItem.setDataProvider(self, forTypes: [.string]) let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem) draggingItem.setDraggingFrame(self.bounds, contents:.Publisher) beginDraggingSession(with: [draggingItem], event: theEvent, source: self) } override func draggingUpdated(_ sender: NSDraggingInfo) -> NSDragOperation { return NSDragOperation.copy } } Subclassed NSView to receive the drop event: class DropView:NSView { func EnableDrop () { // Registering for drag drop types registerForDraggedTypes([NSPasteboard.PasteboardType.string, NSPasteboard.PasteboardType.URL, NSPasteboard.PasteboardType.multipleTextSelection, NSPasteboard.PasteboardType.color]) } func shouldAllowDrag(_ draggingInfo: NSDraggingInfo) -> Bool { return true } override func draggingEntered(_ sender: NSDraggingInfo) -> NSDragOperation { // To show a copy tooltip during drop return NSDragOperation.copy } override func prepareForDragOperation(_ sender: NSDraggingInfo) -> Bool { return true } override func performDragOperation(_ draggingInfo: NSDraggingInfo) -> Bool { let draggedview = draggingInfo.draggingSource as! NSView NSLog ("Drop received") return true } } When I create my view in the ViewController, I do "myviewobj.EnableDrop()" to receive drop events. However as stated above, I'm not able to see the drag animation happening, however, I do get events for it.
Posted Last updated
.
Post marked as solved
1 Replies
297 Views
Hi, Does MacOS support the "Insert" key (Overwrite mode) in general and in an NSTextField? There are Articles that say this can be done using "Fn + Enter", "Fn + i" or "Shift + 0" but I'm unable to trigger the same https://discussions.apple.com/thread/8457698 https://discussions.apple.com/thread/5469511 Plugging in a Keyboard with a physical 'Insert' key also does nothing.
Posted Last updated
.
Post not yet marked as solved
0 Replies
230 Views
Hi, Is there a way to detect if a shortcut key is set as a system shortcut. Or list all the assigned system shortcuts in code. I want to have users set custom shortcut keys in my application (for app functionality), but would want to show them a warning that the shortcut is already a system shortcut. For eg, Cmd+Space is a system shortcut for Spotlight search and I wouldn't want the user to set it as a custom shortcut within the App. Thanks
Posted Last updated
.
Post not yet marked as solved
0 Replies
368 Views
Hi, I'm trying to figure out how we can detect if an NSView/UIView overlaps another one. This includes artefacts like NSButton/UIButton that inherits from NSView/UIView. The use case is that, if I drag around or resize a View and it covers/overlaps another one, I want to adjust the size of the view being overlapped. Thanks!
Posted Last updated
.
Post not yet marked as solved
2 Replies
542 Views
Hello, I have a standalone WatchOS project using SwiftUI for the interface. During the App's init (), I trigger a Swift function call, that does some background activity in a worker thread. By default, the SwiftUI View shows a single label with "Hello World". The result of the worker thread will require an arbitary View to be shown, for eg., I want to show a View with four Labels now. In my use case, the layout for the View, can only be calculated at runtime. Is there a way to arbitrarily manipulate a SwiftUI based View from Swift code at runtime? Thanks!
Posted Last updated
.
Post not yet marked as solved
0 Replies
361 Views
Hi, I have an NSGridView that contains a bunch of custom NSBox's. I want to implement drag drop for these boxes, where each box can be dragged into another box and they swap positions. The declaration of the custom box is like so: class CustomBox:NSBox, NSDraggingSource { override func mouseDown(with event: NSEvent) {                  let pasteboardItem = NSPasteboardItem()         pasteboardItem.setString(self.title, forType:.string)         let draggingItem = NSDraggingItem(pasteboardWriter: pasteboardItem)         draggingItem.setDraggingFrame(self.bounds, contents:self)         beginDraggingSession(with: [draggingItem], event: event, source: self)     }          func draggingSession(_ session: NSDraggingSession, sourceOperationMaskFor context: NSDraggingContext) -> NSDragOperation {         switch(context) {         case .withinApplication  : return .generic         default : return NSDragOperation()         }     } override func draggingExited(_ sender: NSDraggingInfo?) { // Get the Destination box here and call DoSwap() to swap the boxes } } From the NSDraggingInfo in draggingExited, I was not getting the destination box. However using let cell = self.window?.contentView?.hitTest(pSender!.draggingLocation) returns the reference to the Gridview rather than the NSBox (same scenario happens when using hitTest on the Gridview object after using convert to convert the coordinates). Is there a way to get the reference to the destination NSBox where the drop has happened? Thanks!
Posted Last updated
.
Post marked as solved
3 Replies
473 Views
Hi, I'm trying to create a Tabular experience where the user can select a row and a cell at the same time. To give a better understanding, consider the following image: Here, the user has selected the row containing "Data 1a, Data 2a, Data 3a, Data 4a". At the same time, their cursor is on the cell containing "Data 1a". When the user presses the Right arrow key, the row continues to be selected, but the cell selection should move to the cell containing "Data 2a". On the same front, when the user is on "Data 4a" and presses the right arrow key, the row selection moves to the next one(containing the 'b' suffixed data) while the cell containing "Data 1b" should get selected. How can this experience be achieved using NSTableView?
Posted Last updated
.
Post not yet marked as solved
1 Replies
480 Views
Hi, Wanted to understand the difference between the delegate methods "openFile" and "openFiles" used to open files with an application in MacOS. I've tried the following scenarios: Application Delegate with both openFile and openFiles methods present: Opening single file - In this case "openFiles" gets triggered with the file path in the filenames parameter array. "openFile" does not get called. Opening multiple files - In this case, again, "openFiles" gets triggered with the file paths of all the files in the filenames parameter array. "openFile" does not get called again. Application Delegate with only "openFile" delegate method present: Opening single file - In this case "openFile" gets triggered with the file path in the filename parameter. Opening multiple files - In this case "openFile" gets triggered multiple times with the file path in the "filename" parameter. The number of times it gets triggered depends on the number of files that were opened by the application and each time its triggered, it gets the path of the subsequent file. My observation was that, if "openFiles" was present in the delegate along with "openFile", the latter never gets called. Is this observation correct? Also, since "openFIle" delegate can still handle multiple file opens at the same time, albeit it is triggered multiple times, is it safe to just use "openFile" in the delegate file(ie. not use openFiles delegate at all)?
Posted Last updated
.
Post not yet marked as solved
4 Replies
1k Views
Hi, For some of my use cases, I'm extending an interface using a category. I am overriding some of the methods in the base Interface, but want to call the base interface method after I'm done with the workflow inside the category method. Essentially, doing something similar to a "super" call. While I was looking into how to achieve this, have found something called Method Swizzling( https://nshipster.com/method-swizzling/ , https://newrelic.com/blog/best-practices/right-way-to-swizzle), but this looks too 'hacky'. Is there a better way to achieve this?
Posted Last updated
.
Post not yet marked as solved
1 Replies
624 Views
When creating a UTI in UIKit for iOS and associating the UTI with the application(using CFBundleDocumentTypes), I've noticed the following behaviour: If the application is already running, on opening a file associated with the app, only the OpenUrl delegate method gets called When the app is in the terminated state, when an associated file is opened, it triggers  the “WillFinishLaunching”, “DidFinishLaunching” and then the “OpenUrl” delegate method In both cases we get the file or a list of files at the OpenUrl stage. This is unlike the AppKit behavior in Macos, where if files are dropped on the icon and the application is ‘launched’ – you get the file list BEFORE ‘DidFinishLaunching’, and files dropped on ‘running application’ is after DidFinishLaunching. Is this behavior engineered to be different or am I missing something here? Quoting a line from the UIKit OpenUrl page: This method is not called if your implementations return NO from both the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods. (If only one of the two methods is implemented, its return value determines whether this method is called.) Does this mean that we should access the URLs sent while opening the file before initializing the application(ie. in didFinishLaunchingWithOptions)
Posted Last updated
.
Post not yet marked as solved
1 Replies
846 Views
Hi, What would be the recommended UI flow when the user denies a permission that the app requires to function properly? Suppose, the app requires "Location" access and the User presses "Don't Allow" or if the User manually removes the Location Permissions from the Privacy Settings, is there a recommended way to deal with this? I'm aware of the programmatic way to check for a given permission using the App Tracking Transparency framework.
Posted Last updated
.
Post not yet marked as solved
1 Replies
730 Views
I'm trying to create an independent watchOS application(WatchKit) using Objective-C. In UIKit(iOS) its possible to create an app purely programatically without using any Interface builder files(storyboard or xib). Watchkit has its own programmatic controls like WKInterfaceLabel, but I was not able to use it independently without a storyboard file. Adding to this, there were no entries in the Info.Plist file for the Main storyboard file. Wanted to understand if it was possible to create a WatchOS application purely using code.
Posted Last updated
.