如何访问/嵌入 Finder 功能?

发布于 2024-08-06 13:47:30 字数 155 浏览 1 评论 0原文

既然 Finder 本身就是 cocoa(假设该应用程序仅在雪豹中运行),是否可以将 Finder 功能嵌入到 cocoa 应用程序中?

我的意思是让文件浏览器窗格作为应用程序的一部分,实际上浏览文件系统本身(在另一个窗格中进行编辑),但无需编写 Finder 的所有功能。谢谢!

Is it possible to embed Finder functionality in a cocoa app, now that Finder is itself cocoa (assuming the app were to function only in snow leopard)?

What I mean is to have a file browser pane as part of the app, actually browsing the file system itself (to edit in another pane), but without writing all the functionality of the Finder. Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森林很绿却致人迷途 2024-08-13 13:47:30

Finder 本身只是一个应用程序。它不是一个组件库,也不是一个框架。虽然您无法在应用程序中“嵌入”Finder 功能,但您可以影响 Finder 功能并调用 Finder 功能。

首先,您可以将文件夹操作附加到文件夹。当用户对文件夹的内容执行某些操作时(例如,将文件放入其中),这些将触发。您可以在 Finder 中进行设置。您应该学习一点 AppleScript ,如果您想要与 Finder 交互。

其次,由于 Finder 支持 AppleEvents,因此您可以使用 AppleScript 影响 Finder。看看我的第一个AppleScript我的第一个 AppleScript 第二部分 了解如何来做到这一点。这里有更深入的信息,位于 AppleScript概述:使用 AppleScript 编写脚本。这里有一些更多 Finder 脚本

第三,还支持使用 Automator (Mac OS X 10.5) 开发 Finder 的方法,让用户只需单击按钮即可完成复杂的操作。从 Mac OS X 10.6(“Snow Leopard”)开始,您还可以在 Automator 中创建服务。查看 Mac OS X 10.6 中的 Automator 和 Finder 操作 了解后一种技术的介绍。

尽管 Finder 窗口本身不是可嵌入组件,但如果您确实想提供书写、打印、删除、复制等文件/文件夹以及从一个文件夹导航到另一个文件夹的功能,您可以在您的应用程序中开发一个简单的文件夹浏览器。应用。

只要您不将您的网站设置为模仿查找器或复制其所有功能(仅是我提到的基本功能),那么执行此操作应该不会是大量工作。

然而,您需要知道如何对 Macintosh 进行编程,而不仅仅是使用 AppleScript。通常的方法是学习 Objective-C 编程语言和 Cocoa 框架。您需要熟悉使用模型-视图-控制器架构编写应用程序。

您将创建一个名为 MyFile 之类的 NSObject 子类,以及一个名为 MyFolder 之类的集合类的子类。当应用程序创建浏览窗口时,每次应用程序激活(成为最前面的应用程序)时,您都会刷新浏览菜单的内容。

您可以在菜单栏中放置一个菜单,其中包含命令:打开、打印、删除、复制。当用户执行这些命令之一时,您的应用程序会自行执行适当的操作或将请求发送到 Finder。操作完全执行后,您将刷新当前显示的文件夹的浏览窗口,如果用户导航到其他文件夹,则刷新新显示的文件夹的浏览窗口。

如果您熟悉设计模式、面向对象编程和一般框架 - 请阅读 Cocoa 设计模式 将极大地加快您的学习速度。

您可以使用这些不同的技术来利用 Finder 的一些功能。当您仔细查看这些内容时,我建议您非常清楚这会给应用程序的用户带来什么好处。写下此功能的总体目标是什么,以及您希望支持哪些命令,将使您更容易选择开发它的路径。

用户始终可以通过单击按钮来单击 Finder 文件夹窗口,因为 Finder 始终处于运行状态。因此,请避免为了功能本身而简单地重复该功能。专注于您为用户提供的好处。确保您确实处理了用户从另一个应用程序更新您正在显示其内容的文件夹,然后切换回您的应用程序的情况。

The Finder itself is just an application. It is not a components library nor a framework. While you cannot "embed" Finder functionality in your application, you can influence Finder functionality and invoke Finder functionality.

First off, you can attach Folder Actions to folders. These will trigger when a user does something to the contents of a folder - for instance, they drop a file into it. You set this up in the Finder. You should to learn a little AppleScript, if interacting with the Finder is something you want to do.

Second, since the Finder supports AppleEvents, you can affect the Finder using AppleScript. Take a look at My First AppleScript and My First AppleScript Part II to see how to do this. Here is much more in-depth information, in AppleScript Overview: Scripting with AppleScript. Here is some More Finder Scripting.

Third, there is also support for developing ways for the Finder to do complex things for the user at the click of a button, using Automator (Mac OS X 10.5). You can also create a Service in Automator, beginning in Mac OS X 10.6 ("Snow Leopard"). Take a look at Automator and Finder Actions in Mac OS X 10.6 for an introduction to this latter technique.

Even though Finder windows themselves are not an embeddable component, if you really want to provide the ability to pen, Print, Delete, Duplicate, etc. Files/Folders, and navigate from Folder to Folder, you can develop a simple Folder browser in your application.

It should not be a huge amount of work to do this so long as you do not set your sites on mimicking the finder or duplicating all of its functionality, just the essential basics I have mentioned.

You would need to know how to program the Macintosh, however - not just use AppleScript. The normal way to do this would be to learn the Objective-C programming language and the Cocoa framework. You would need to get familiar with writing applications using a Model-View-Controller architecture.

You would create a subclass of NSObject named something like MyFile, and a subclass of a collection class named something like MyFolder. When the application creates the browsing Windows, and each time the application activates (becomes the frontmost application), you8 would refresh the contents of the browsing menu.

You could put a menu in your menu bar with commands in it: Open, Print, Delete, Duplicate. When the user does one of those commands, your application performs the appropriate actions itself or sends the request to the Finder. After the action has been completely carried out, then you refresh the browsing window for currently displayed Folder, or newly displayed Folder if the user navigated to a different Folder.

If you are familiar with design patterns, object-oriented programming, and frameworks in general - reading up on Cocoa Design Patterns will speed your learning curve immensely.

These are various techniques you can use to harness some of the power of the Finder. As you look these over, I suggest getting very clear in your mind just what benefit this brings to the user of your application. Writing down what the overall objective of this feature is, and what commands you wish to support, will make it easier to choose the path you take in developing it.

The user can always click on a Finder folder window at the click of a button, since Finder is always running. So avoid simply duplicating that functionality for its own sake. Focus on the benefit you are providing the user. Make sure that you do handle the situations where the user updates the Folder you are showing the contents of from another application and then switches back to your application.

世界和平 2024-08-13 13:47:30

不,他们并没有让 Finder 只是像 Preview 这样的框架的宿主。你还是得自己写这个。

No, they have not made Finder simply a host for a framework, like Preview. You still have to write this yourself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文