How can I organize the "Window" menu? - objective-c

I have a document based application. Every document can have multiple windows. Every window is automatically added to the "Window" menu. However, they are added in a more or less random and useless order. I would like the window titles to be organized according to the NSDocument they belong to, similar to how XCode or Photoshop do it.
How can I best do that? How can I prevent the default behaviour of AppKit to add all windows to this special menu, and where should I put the code that adds the menu items in the "correct" manner? I don't want to put handlers into every window controller!

It sure does seem like this is something Cocoa should do automatically. I don't know whether it does, but the first thing to check is whether the window controllers are properly connected to their documents. Does your document subclass's windowControllers property contain all the right objects?
If that's no good, then from NSWindow's reference it looks like the only way to prevent a window whose title has been set from being added to the Windows menu is -[NSWindow setExcludedFromWindowsMenu:]. It looks like you'll want to call that on all your windows, then set up an object (perhaps in the MainMenu nib) that takes care of all the windows' positions and grouping in the Windows menu (via NSApplication's methods). You may need to put in special disabled items and the like to get the grouping to look right. I would hope that windows could still be manually added even if you've previously asked them to be excluded.

Related

Remove tab-related functions from Window menu?

I'm customizing the menus in my Mac Catalyst app. I've added two items, as you can see in the following screen shot ("Set Window Size" and "Open Separate Document Viewer"). But I want to get rid of the default menu items that appear between these two items (the four tab-related functions).
In buildMenuWithBuilder, I can remove some items (child menus) like this:
[builder removeMenuForIdentifier:UIMenuMinimizeAndZoom];
But there is no defined identifier for the child menu containing the tab functions. More significantly, it doesn't yet exist when buildMenuWithBuilder runs. If I put this code at the end of that method...
UIMenu *test = [builder menuForIdentifier:UIMenuWindow];
NSArray *test2 = [test children];
...then test2 contains only two default menus, UIMenuMinimizeAndZoom and UIMenuBringAllToFront, plus my custom menus. So even if I had its identifier, I suspect removing it here would have no effect.
More oddly, it appears between my two custom menus, even though I'm adding those one after the other with insertChildMenu:atStartOfMenuForIdentifier:.
Finally, I noticed that when I open a second scene (in a new Mac window), these tab options disappear from the Window menu and don't come back. It seems that macOS is initially deciding these functions could be relevant to my app, but then when I open a scene, it decides they're not relevant and removes them. So I'm wondering if there is a way to tell macOS from the start not to include these menu items?
I thought this might be related to the NSWindow property tabbingMode, but setting my main window to NSWindowTabbingModeDisallowed makes no difference. My only Mac development experience is through Mac Catalyst, so I don't know what else to try.
I think if you disable tabs completely, they’ll go away. This is a bit of a hack because you need to call AppKit code, but an Apple engineer gave it to me:
Class _nswindow = NSClassFromString(#"NSWindow");
[_nswindow setAllowsAutomaticWindowTabbing:NO];

One custom toolbar for multiple layouts in FileMaker Pro

I have a complex Filemaker database with multiple tables and layouts. What I would like to do is to add a toolbar to each layout. This, of course in view of maintainability of my database solution.
Of course, I could create a nice row of buttons (for example in the header of the layout) and copy past this to each separate layout. However, this is not really a great solution from a maintenance pont of view (if you want to change something you need to do so multiple times).
So... is there another way?
I am looking for something similar to e.g., include in php:
<?php
include 'header.php';
?>
Is there such a thing?
Not really. It could be achieved, mostly, with a bit of extra work. There is nothing out of the box, although you might find some samples on the web.
The closest thing in FileMaker is button bar with styles. Even this will not auto-update by default across different layouts.
You can use a webviewer based on a global field.
Another solution for older versionsis to use a portal with records creating buttons and a script which will do staff depending in which row button is clicked.
I am using a Navigation Window which may be recalled by either a push button which should be on each layout (you have not to change it because it only recall the Navigation Window) and/or a Script (I use to put it at the first place, as CMD-1).
Of course, you need to manage that the Navigation Window has to be closed before the navigation and execution of the Script managed by your Toolbar while, at the other side, you may add every other navigation need ;-)
Best wishes
Carmine Iaciofano - Area

How to create a background only program that can show a window with text fields

I want to create a program that consists of just a menu in the status bar (no dock icon or menu bar) that, when the user clicks on menu items, opens a window that allows the user to enter text (NSTextField and NSTextView).
I can make the program background only by setting the "Application is background only" property to YES in my Info.plist file, however, when I do this and display a window, firstly the window always appears behind other windows, and secondly I can't type any text into it (text goes to whatever last had focus - usually a source file in Xcode!)
This is definitely not something as simple as the fields are not enabled. Simply changing the "background only" property to NO fixes the issue, but then I get a dock icon and menu bar which I don't want.
Is what I'm trying to do possible or is there something about the background only mode that means my application can never receive text?
If it is possible what do I need to do to fix this?
From the documentation for LSBackgroundOnly:
You can use this key to create faceless background apps. You should also use this key if your app uses higher-level frameworks that connect to the window server, but are not intended to be visible to users.
So when they say “background only”, they mean background only.
The key you want is LSUIElement. Xcode describes this as “Application is agent (UIElement)”.
I personally can't stand Xcode's default behavior of showing me descriptions of some of the keys' meanings. I recommend turning on “Show Raw Keys/Values”; then, Xcode will show you the real keys being used in the dictionary.

How to dynamically add fields to a NSView similar to iCal New Task popup?

I'm trying to implement a NSView which will host a 'choose file' attachment button. If the user chooses to add a file, the user will be given an option to add another one (and from the 'new set of dropdowns' the user will essentially be able to pick the kind of file they're attaching').
The closest match to this functionality is iCal's New Task editor where you select an alarm and then it gives you an option to add another alarm right underneath.
What is the right way of doing this (I'm new to Mac OS X development)? I originally thought I'd create a custom NSView with all the 'file options' and then if the user was to attach a file I'd dynamically add another NSView right below it (in a NSScrollView). However so many apps do something similar that I almost feel as if there's something else out there in the set of controls that I should be using.
Please can someone guide me to the right direction? Is 'NSForm' or NSPredicateEditor used for this sort of stuff? This is what I mean:
Neither NSForm nor NSPredicateEditor would be useful for what you want to do. I think your thoughts about how to do this by adding a custom view below the original view, is the right way to go. You don't necessarily have to do it in a scroll view, you could expand the size of the window like iCal does.

Cocoa Key Equivalent in Menu is not working

I have created a NSStatusItem and I have assigned two key equivalents within interface builder (Xcode 4.0). These are for the preference menu cmd-, and the quit option cmd-q. Both of these will work when the Menu is highlighted/open but will not work otherwise even if the application is the foremost. Any ideas on why this is happening or how I can change this?
The operating system passes key events that it doesn't handle to the front application, which compares them to any key equivalents in its main menu and current window. They are not compared to items in the status bar, and since the status bar is actually a different application, it won't matter that your application is in the foreground. When you have the menu open, it is the window in focus. This is why it works in those circumstances.
Since the status item is only active while the menu is open, you need to get the key equivalents using one of two other methods. The first, newer method is to use event taps. I have never used this, so I can't advise on how to set it up. The other, older option, is to use hot keys. This method may become unsupported in the future, but if you are interested I posted an example in this answer.
My guess: your NSMenu is not in the responder chain. If you can figure out how to get it in there, you can probably get this to work.