如何将 gtk 文件选择器按钮默认设置为用户的主文件夹
我的应用程序上有一个 gtk 文件选择器按钮,我正在使用 Mono Develop 用 c# 编写。我想将文件选择器的默认位置设置为用户的主目录,无论哪个用户正在运行它。
我尝试过 ~/ 快捷方式 - fchFolder1.SetCurrentFolder("~/"); - 但这没有用。我只是想知道 gtk 文件选择器是否使用一个值来引用用户主目录?谢谢
I've got a gtk file chooser button on my application I am writing in c# using Mono Develop. I would like to set the file chooser's default location to the users' home directory regardless of what user is running it.
I've tried the ~/ short cut - fchFolder1.SetCurrentFolder("~/"); - but this did not work. I was just wondering if there was a value that the gtk file chooser used to refer to the users home directory? Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 C 中,可以使用 g_get_home_dir() 查找用户的主目录,并将文件选择器的当前位置设置为该目录,但据我所知,该函数并未包含在 GTK# 中。有人在 GTK# 邮件中提出了同样的问题列出,答案是使用
In C, one would use
g_get_home_dir()
to find the user's home directory, and set the file chooser's current location to that, but as far as I can tell, that function isn't wrapped in GTK#. Someone asked the same question on the GTK# mailing list and the answer was to use在 Unix 中,您可以获取 HOME 环境变量或使用
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
。在 Windows 中,展开
%HOMEDRIVE%%HOMEPATH%
以获取“主”目录,或使用相同的GetFolderPath
调用来获取“我的文档”目录。关于 HOME 和 HOMEDRIVE+HOMEPATH 方法的讨论:获取C# 中的主目录?
In Unix, you can either get the HOME environment variable or use
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal)
.In Windows, expand
%HOMEDRIVE%%HOMEPATH%
to get the "home" directory, or use the sameGetFolderPath
call to get the "My Documents" directory.Discussion about the HOME and HOMEDRIVE+HOMEPATH approach: Getting the path of the home directory in C#?