It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to make a dock bar which contains application's icons. If I click on any icon then that application should lunch and how can I hide that dock bar ?
I am new to cocoa and I have no idea about it .
so can any one give me basic idea to do it .
thanks in advance
There are several key elements here:
Like almost anything else on the screen, your Dock would have to be in a window. Presumably, you aren't imagining a window with the standard frame (title bar, stoplight, and resize handles), so you'd want a borderless window. It will have to be at a particular window level, namely this one.
Each icon would be a button to start with. You'd evolve this into custom views that are capable of bouncing, showing running state (as the Dock does with its LEDs), etc.
The Dock populates itself with three kinds of items: Running applications, bookmarked applications (those that stay in the Dock even when running), and bookmarked files (documents, folders, etc.). Applications go on the left side of the divider; bookmarked files and the Trash go on the right side.
Speaking of the Trash, if you want that, you'll need to use FSEvents to detect when any Trash becomes non-empty, NSWorkspace or an Apple Event to the Finder to open the Trash, and an Apple Event to the Finder to empty it.
When the user clicks on a bookmarked application that isn't running, you'll use NSWorkspace to launch that application.
For applications that are already running, you'll need to activate them (if not already active) or “reopen” them (if already active). I'd first try just launching them and seeing whether that Does the Right Thing in all three cases; if it doesn't, then you get to send Apple Events yourself when necessary.
Bookmarked folders can be perused in the Dock with one of three UIs: List (a menu), grid (a collection view), and “fan”. Menus are easy enough to make, but I'm not sure how to make one popover-styled. The grid UI would be a collection view in a HUD-styled popover. “Fan” is entirely custom, in a popover.
You'll need to detect when applications launch and terminate, in order to add them to your Dock (if not already there as bookmarks) and remove them from it (if they're not bookmarked then). NSWorkspace has notifications for this.
You probably can't get applications' custom Dock menus. That's all private stuff between Apple's Dock and AppKit.
Likewise, good luck implementing the “Assign to Desktop” menu items.
The other commands in each application's Dock menu correspond to NSRunningApplication methods.
You'll also want to handle drag and drop in your Dock-icon views, both to enable reordering and to handle the user dragging items off of the Dock to un-bookmark them. Remember to handle the case of un-bookmarking a running application (the Dock does un-bookmark it, but snaps the app back into place because it is still running). When un-bookmarking, play the poof effect when the user drops it.
When the user ⌘-drags any item out of the Dock, drag the file represented by that item. This doesn't work on the Finder (in Apple's Dock—you could do this if you want) or the Trash (it doesn't represent a single item). Do not remove the item from the Dock.
And, on the other end, you should highlight an icon when the user drags to it, if and only if the item represented by the icon can receive that drag.
When the user drags files to an application, highlight it if all of the files' types are among the application's document types. Complete the drag by using NSWorkspace to open the file URLs with that application.
When the user drags non-file URLs to an application, highlight it if all of the URLs' schemes are among the application's URL schemes. Complete the drag by using NSWorkspace to open the URLs with that application.
When the user drags content to an application, highlight it if the application has a service that can handle any of the content types on the drag pasteboard. Complete it by invoking that service. (I don't know of a public API to do this with a specific application—you'll need to just use the service name and hope for the best.)
When the user drags files to a folder, highlight it if the folder is writable or contains any folders. If the user hovers there for a certain amount of time, open the folder in the Finder (this feature is called spring-loaded folders). If the user drops the files on the folder in your Dock, complete the drag by moving or copying the files to the folder, or by creating aliases to them in the folder, depending on the state of the modifier keys.
The same goes for files to the Trash, but you'll need to determine the correct Trash for each file. If the file is within the Home folder, the correct Trash is the Home folder's Trash. Otherwise, it's the volume-level Trash of whatever volume the file is on.
When the user drags any volume(s) to the Trash, change its icon to an Eject icon (kEjectMediaIcon, used with iconForFileType:). Complete the drag by ejecting the volume(s). If the user completes the drag, cancels it, or drags away from the Trash, change the Trash's icon back.
Oh, and you'll need to handle dragging between items, including before and after the divider, to add items. This will overlap with the dragging to reorder that I mentioned above.
For auto-hiding, you'll need to have a 1-pt-tall/-wide borderless window, of the same width/height as the real Dock, at the edge of the screen that bears the Dock (ordinarily the first screen, if there are any). When the user mouses over this window, show the Dock (which should cover up the thin window). When the user moves the mouse outside of the Dock, hide it.
The Dock has a contextual menu containing various options on its divider.
Ideally, you should anticipate supporting theming at some point, since the Dock has at least two themes already (the default “glass” theme and the 2D HUD-style theme).
Let me know if I missed anything.
Related
I have a wide "dock" area at the bottom of the screen. I have placed a UIFocusGuide across the top of it. Depending on which element in the dock has focus, the system may or may not have a focus solution if the user swipes up.
How can I tell my focus guide to use the system-calculated new focus item if there is one, but if not, it should use the one configured in my setPreferredFocusEnvironments:
Alternatively, is there a way to determine where a "swipe up" will take the focus without actually doing it? As the focused element in the dock changes, I could check this and if it has no destination provided by the system, I can add one.
My dock is a view within a main view controller but preferredFocusEnvironments is never called when the user tries to move to a non-existent view from an element in the dock.
I am looking for a way to add several toolbar buttons to Finder, which, when clicked, perform certain actions.
My research shows that injecting code into Finder process is impossible on latest versions of macOS due to SIP, yet this would be the most seamless way for the user.
There is a possibility to add a toolbar item by creating a Finder Sync extension. However there are 2 problems:
There can be only one toolbar button per extension (I need several buttons)
The toolbar button will have a dropdown arrow (see an image below). I do not need to show a menu, however, and therefore this arrow makes the button misleading. It must be a simple plain button that matches the current system theme and performs an action upon click.
So this is what I don't need (because of the drop down arrow):
Update:
One of the ways to add a button, is drag and drop an .app bundle, holding Command key.
This approach has the following problems:
This button wouldn't match the other toolbar buttons look&feel, as the icon for such button is taken from the .app bundle (so it wouldn't switch based on macOS light/dark theme, for example)
It is impossible to add several toolbar buttons like that (as there needs to be one .app per 1 button). However, I need multiple buttons.
I am wondering if FinderSync allows creating "normal" (non menu) buttons
Is there a way to add a regular button to Finder's toolbar?
Please check out my Finder buttons:
https://github.com/lexrus/LTFinderButtons
Basically, I made every task a button app.
I'm trying Finder Sync Extension to do the same thing. All issues you found are true. Furthermore, there's problem #3:
You can not submit an app with Finder Sync Extension to the App Store.
Most Cocoa applications, provided they call NSWindow's -setRepresentedFilename:, will display a nice little proxy icon at the top-centre of their NSWindows.
Here's an example of the Preview app with a PDF document:
Xcode, somehow, manages to display 2 proxy icons - one for the project file and the other for the current document in the source display.
Does anyone know how they do that? window:shouldPopUpDocumentPathMenu: in NSWindowDelegate seems very close - you could probably position your custom path menus with this. But there doesn't seem to be anything that would allow you to actually display the two proxy icons themselves.
Any ideas?
Unfortunately Apple has access to APIs the rest of us don’t. Messing with the title bar is really hard.
The best I can suggest is making your window NOT have a standard title bar, and then placing the buttons yourself by calling [self standardWindowButton:X] for each of the close, resize, and miniaturize buttons you want. Then place your own document icon and title textField.
You’ll likely have to track when the window loses or gains key or main status and modify the buttons accordingly (Cocoa fetches new buttons each time this happens, not sure why). Whee! Good luck!
Idea is simple(stolen from Ubuntu): autohide Dock when you drag window toward it and begin to overlap it. Turn autohiding off and show Dock when window is moved out of area when Dock is located.
What API can be used to achieve that ?
update:
managing autohide possible from command line this way but it's horrible
defaults write com.apple.dock autohide -bool true
killall Dock
Well, when the Dock is configured to (always) stay visible, the Window Manager will simply refuse to position the window directly under the Dock. It prevents users from putting stuff to where they can't reach. (Not every user is a power user; not every user knows the Dock can be hidden and since the Dock has no click-throughs...)
The system will hide the Dock when the app goes fullscreen. But, again, the system takes care of it.
Aside from directly mucking around with the user's Dock preferences (never change a user's preference for a third-party app behind their back!) like you mentionned; it can't be done legitematly.
There's is no API to control the Dock... at best, you can only suggest a tile to represent your app when present on the Dock.
How can I make a sliding menu like (as an example) Sparrow's main email menu?
In the case of Sparrow:
It's a column of buttons that essentially slide to reveal a NSScrollView (with custom NSTableView?) with various folders inside (inbox, sent, etc). Clicking on a different account causes that account to slide up to the top and reveals the various folders inside.
How could I go about doing a menu similar to this?
There is some fairly cool Apple sample code here to deal with table views and animation (uses stuff that is generally only available as of Mac OS X 10.7 however):
https://developer.apple.com/library/mac/#samplecode/AnimatedTableView/Listings/ATPopupWindow_m.html%23//apple_ref/doc/uid/DTS40008863-ATPopupWindow_m-DontLinkElementID_26
Also, for basic window resize animation you can use the setFrame:display:animate: method of NSWindow.