Document-based-like application + updating fields/menus/etc when switching document? - objective-c

I have an application with multiple documents opened at once (as different tabs), but not implemented the Cocoa way, with NSDocument etc
So, let's say, that application is a text editor : e.g. an NSTextView in each document/tab and a menu (in the MainMenu) with options (on/off) related to that particular document.
Scenarios :
The user clicks a menu item (option) and the option is applied to the
current tab
Now, the user switches tab and the options (of the menu) should be update according to current document's settings
How should I go about that in the most Cocoa-friendly way?
(I certainly CAN do it; though I'm interested in what could be a more efficient way (and my definitely isn't))

You can implement validateUserInterfaceItem: on NSDocument. Menu and toolbar items call it to check if they should be enabled or not. Read about Implementing Validation in general and Enabling Menu Items specifically.

Related

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.

Menu bar button panels in Cocoa?

When I click on buttons in the menu bar (such as "About Program") when the program is running a new window pops up displaying information. How do I edit the windows associated with the buttons?
In Interface builder I manage to load "Main Menu" which allows me to customize the menu bar, but it doesn't allow me to work with the windows associated with the buttons. How would I edit these windows?
Mac OSX Snow Leopard, Xcode 3.2.6
EDIT: I am not specifically asking for steps for the "About Panel". I am looking for a general procedure for editing panels associated with buttons in the menu bar. In addition to the "About" panel I would also want to work with panels such as the "Help" panel. The "About" panel was just an example.
The standard About panel isn't in your nib; it's generated within the framework.
You can change the text of the panel by writing a Credits.rtf or Credits.html file and including that in your app bundle. (You may already have Credits.rtf supplied by the project template. If so, you should just edit that.)
If you want to make more radical changes, you'll need to create your own panel and change your About menu item to show it instead.
As far as a general procedure...no, there's no single procedure that would let you customize any standard panel in the same way. They all have their own mechanisms (e.g. some can display more panes when plug-in components are installed; some provide APIs to hide or show certain parts; some, like the About box, use bundle filename conventions to decide what to do).
For the Help panel specifically...you can't change anything about it except the web page (i.e. the help content). The toolbar, etc. is all handled by Apple. I suggest looking at this documentation for more, which also links to other important documents:
https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OnlineHelp/Concepts/ComprehenHelp.html%23//apple_ref/doc/uid/20000017-BBCCFHAC

How can I organize the "Window" menu?

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.

Squeak System Browser Questions

I am using (a school modified version of) the "Squeak By Example" (SBE) image for a OOP/OOD class. However, my System Browser is missing a few features that appear in SBE. I assume there are some configuration options that can get them back for me, but I can't find them yet.
My questions are:
1) How do I get the buttons back? In the bottom pane there should be a bunch of button (browse, senders, implementors, versions, ..., source). My buttons are missing.
2) How do I get the small workspace area above the buttons to appear? There is supposed to be an area that I can type in, below the top panes, and above the buttons, but it doesn't appear.
Thanks in advance!
Robert
Edit - I did fool around in the Preferences Browser and tried a lot of settings. I managed to make the buttons come back and then later got that small (unknown name) workspace pane back, but I have no idea how. I have tried to systematically turn stuff off again to find out what setting(s) controlled what, but I was unable to determine what controlled either problem. So even though I have it working, I would like some squeak/smalltalk knowledgeable person to let me know how to control these as it might help me learn...
"In the bottom pane there should be a bunch of button (browse, senders, implementors, versions, ..., source). " -- switch on the optionalButtons preference in the preferences browser.
The "area that I can type in, below the top panes, and above the buttons, but it doesn't appear" sounds like the annotation pane - this gives you summary information about the method you're currently viewing, and it's controlled by the annotationPanes preference. Alternatively you may be referring to the Mercury Panel which is used for fast navigation to other classes and methods; this is (of course :-) controlled by the mercuryPanel preference.
If you've been messing around, you may also find that you now have an incorrect system browser selected. Squeak has a choice of browsers which can act as the System Browser. You can choose between them by clicking the menu button on the System Browser and selecting "Choose new default Browser". Open a new browser window to see what effect this has had.
You may also want to try a Pharo image which has everything configured the way you want by default.
Do you have access to the Preferences Browser? It should be in the main system menu. You can alter all sorts of things via this browser, including which buttons appear in teh system browser?

Eclipse RCP : Perspective switcher window dialog sort problem

In my application, when I select File->Open Perspective->Other it opens a dialog listing out all perspectives. My problem is that I want those perspectives to appear in a defined order (which they are not in this default perspective switcher).
This is the same dialog that pops up on clicking an icon displayed to the extreme left before anything else on the perspective bar.
There are a few implementations like this that discuss how to disable perspective bar and make our own custom perspective switcher. General approach is to first disable perspective bar by altering ApplicationWorkbenchWindowAdvisor.java as shown below.
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
configurer.setShowPerspectiveBar(false);
}
But problem is that this also hides the entire perspective switcher (including perspective buttons that i need which i have arranged in a specific order).
So, is there a way to still have the perspective buttons displayed on the perspective bar and alter the order of the perspectives that are displayed in the default dialog(that opens on File->Open Perspective->Other)?
AFAIK, perspectives and views are always ordered according to their names, grouped by their categories. Maybe you can file an enhancement request for this at Eclipse Bugzilla.