📄 gtkfilechooser.html
字号:
(<a class="link" href="GtkFileChooser.html" title="GtkFileChooser">GtkFileChooser</a> *chooser, const char *folder, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> **error);<ahref="/usr/share/gtk-doc/html/glib/glib-Singly-Linked-Lists.html#GSList">GSList</a>* <a class="link" href="GtkFileChooser.html#gtk-file-chooser-list-shortcut-folders">gtk_file_chooser_list_shortcut_folders</a> (<a class="link" href="GtkFileChooser.html" title="GtkFileChooser">GtkFileChooser</a> *chooser);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="GtkFileChooser.html#gtk-file-chooser-add-shortcut-folder-uri">gtk_file_chooser_add_shortcut_folder_uri</a> (<a class="link" href="GtkFileChooser.html" title="GtkFileChooser">GtkFileChooser</a> *chooser, const char *uri, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> **error);<ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="GtkFileChooser.html#gtk-file-chooser-remove-shortcut-folder-uri">gtk_file_chooser_remove_shortcut_folder_uri</a> (<a class="link" href="GtkFileChooser.html" title="GtkFileChooser">GtkFileChooser</a> *chooser, const char *uri, <ahref="/usr/share/gtk-doc/html/glib/glib-Error-Reporting.html#GError">GError</a> **error);<ahref="/usr/share/gtk-doc/html/glib/glib-Singly-Linked-Lists.html#GSList">GSList</a>* <a class="link" href="GtkFileChooser.html#gtk-file-chooser-list-shortcut-folder-uris">gtk_file_chooser_list_shortcut_folder_uris</a> (<a class="link" href="GtkFileChooser.html" title="GtkFileChooser">GtkFileChooser</a> *chooser);</pre></div><div class="refsect1" lang="en"><a name="id4011213"></a><h2>Object Hierarchy</h2><pre class="synopsis"> GInterface +----GtkFileChooser</pre></div><div class="refsect1" lang="en"><a name="id4011237"></a><h2>Prerequisites</h2><p>GtkFileChooser requires <ahref="/usr/share/gtk-doc/html/gobject/gobject-The-Base-Object-Type.html#GInitiallyUnowned">GInitiallyUnowned</a> and <a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a>.</p></div><div class="refsect1" lang="en"><a name="id4011267"></a><h2>Known Implementations</h2><p>GtkFileChooser is implemented by <a class="link" href="GtkFileChooserButton.html" title="GtkFileChooserButton">GtkFileChooserButton</a>, <a class="link" href="GtkFileChooserWidget.html" title="GtkFileChooserWidget">GtkFileChooserWidget</a> and <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog">GtkFileChooserDialog</a>.</p></div><div class="refsect1" lang="en"><a name="id4011305"></a><h2>Properties</h2><pre class="synopsis"> "<a class="link" href="GtkFileChooser.html#GtkFileChooser--action">action</a>" <a class="link" href="GtkFileChooser.html#GtkFileChooserAction">GtkFileChooserAction</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--do-overwrite-confirmation">do-overwrite-confirmation</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--extra-widget">extra-widget</a>" <a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--file-system-backend">file-system-backend</a>" <ahref="/usr/share/gtk-doc/html/gobject/gobject-Standard-Parameter-and-Value-Types.html#gchararray">gchararray</a> : Write / Construct Only "<a class="link" href="GtkFileChooser.html#GtkFileChooser--filter">filter</a>" <a class="link" href="gtk-gtkfilefilter.html#GtkFileFilter">GtkFileFilter</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--local-only">local-only</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--preview-widget">preview-widget</a>" <a class="link" href="GtkWidget.html" title="GtkWidget">GtkWidget</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--preview-widget-active">preview-widget-active</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--select-multiple">select-multiple</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--show-hidden">show-hidden</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write "<a class="link" href="GtkFileChooser.html#GtkFileChooser--use-preview-label">use-preview-label</a>" <ahref="/usr/share/gtk-doc/html/glib/glib-Basic-Types.html#gboolean">gboolean</a> : Read / Write</pre></div><div class="refsect1" lang="en"><a name="id4011513"></a><h2>Signals</h2><pre class="synopsis"> "<a class="link" href="GtkFileChooser.html#GtkFileChooser-confirm-overwrite">confirm-overwrite</a>" : Run Last "<a class="link" href="GtkFileChooser.html#GtkFileChooser-current-folder-changed">current-folder-changed</a>" : Run Last "<a class="link" href="GtkFileChooser.html#GtkFileChooser-file-activated">file-activated</a>" : Run Last "<a class="link" href="GtkFileChooser.html#GtkFileChooser-selection-changed">selection-changed</a>" : Run Last "<a class="link" href="GtkFileChooser.html#GtkFileChooser-update-preview">update-preview</a>" : Run Last</pre></div><div class="refsect1" lang="en"><a name="id4011585"></a><h2>Description</h2><p> <a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a> is an interface that can be implemented by file selection widgets. In GTK+, the main objects that implement this interface are <a class="link" href="GtkFileChooserWidget.html" title="GtkFileChooserWidget"><span class="type">GtkFileChooserWidget</span></a>, <a class="link" href="GtkFileChooserDialog.html" title="GtkFileChooserDialog"><span class="type">GtkFileChooserDialog</span></a>, and <a class="link" href="GtkFileChooserButton.html" title="GtkFileChooserButton"><span class="type">GtkFileChooserButton</span></a>. You do not need to write an object that implements the <a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a> interface unless you are trying to adapt an existing file selector to expose a standard programming interface. </p><p> <a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a> allows for shortcuts to various places in the filesystem. In the default implementation these are displayed in the left pane. It may be a bit confusing at first taht these shortcuts come from various sources and in various flavours, so lets explain the terminology here: </p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term">Bookmarks</span></p></td><td><p> are created by the user, by dragging folders from the right pane to the left pane, or by using the "Add". Bookmarks can be renamed and deleted by the user. </p></td></tr><tr><td><p><span class="term">Shortcuts</span></p></td><td><p> can be provided by the application or by the underlying filesystem abstraction (e.g. both the gnome-vfs and the Windows filesystems provide "Desktop" shortcuts). Shortcuts cannot be modified by the user. </p></td></tr><tr><td><p><span class="term">Volumes</span></p></td><td><p> are provided by the underlying filesystem abstraction. They are the "roots" of the filesystem. </p></td></tr></tbody></table></div><div class="refsect2" lang="en"><a name="gtkfilechooser-encodings"></a><h3>File Names and Encodings</h3><p> When the user is finished selecting files in a <a class="link" href="GtkFileChooser.html" title="GtkFileChooser"><span class="type">GtkFileChooser</span></a>, your program can get the selected names either as filenames or as URIs. For URIs, the normal escaping rules are applied if the URI contains non-ASCII characters. However, filenames are <span class="emphasis"><em>always</em></span> returned in the character set specified by the <code class="envar">G_FILENAME_ENCODING</code> environment variable. Please see the Glib documentation for more details about this variable. </p><div class="important" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Important</h3><p> This means that while you can pass the result of <a class="link" href="GtkFileChooser.html#gtk-file-chooser-get-filename"><code class="function">gtk_file_chooser_get_filename()</code></a> to <code class="function">open(2)</code> or <code class="function">fopen(3)</code>, you may not be able to directly set it as the text of a <a class="link" href="GtkLabel.html" title="GtkLabel"><span class="type">GtkLabel</span></a> widget unless you convert it first to UTF-8, which all GTK+ widgets expect. You should use <ahref="/usr/share/gtk-doc/html/glib/glib-Character-Set-Conversion.html#g-filename-to-utf8"><code class="function">g_filename_to_utf8()</code></a> to convert filenames into strings that can be passed to GTK+ widgets. </p></div></div><hr><div class="refsect2" lang="en"><a name="gtkfilechooser-preview"></a><h3>Adding a Preview Widget</h3><p> You can add a custom preview widget to a file chooser and then get notification about when the preview needs to be updated. To install a preview widget, use <a class="link" href="GtkFileChooser.html#gtk-file-chooser-set-preview-widget"><code class="function">gtk_file_chooser_set_preview_widget()</code></a>. Then, connect to the <a class="link" href="GtkFileChooser.html#GtkFileChooser-update-preview"><span class="type">"update-preview"</span></a> signal to get notified when you need to update the contents of the preview. </p><p> Your callback should use <a class="link" href="GtkFileChooser.html#gtk-file-chooser-get-preview-filename"><code class="function">gtk_file_chooser_get_preview_filename()</code></a> to see what needs previewing. Once you have generated the preview for the corresponding file, you must call <a class="link" href="GtkFileChooser.html#gtk-file-chooser-set-preview-widget-active"><code class="function">gtk_file_chooser_set_preview_widget_active()</code></a> with a boolean flag that indicates whether your callback could successfully generate a preview. </p><div class="example"><a name="example-gtkfilechooser-preview"></a><p class="title"><b>Example 30. Sample Usage</b></p><div class="example-contents"><pre class="programlisting">{ GtkImage *preview; ... preview = gtk_image_new (); gtk_file_chooser_set_preview_widget (my_file_chooser, preview); g_signal_connect (my_file_chooser, "update-preview", G_CALLBACK (update_preview_cb), preview);}static voidupdate_preview_cb (GtkFileChooser *file_chooser, gpointer data){ GtkWidget *preview; char *filename; GdkPixbuf *pixbuf; gboolean have_preview; preview = GTK_WIDGET (data); filename = gtk_file_chooser_get_preview_filename (file_chooser); pixbuf = gdk_pixbuf_new_from_file_at_size (filename, 128, 128, NULL); have_preview = (pixbuf != NULL); g_free (filename); gtk_image_set_from_pixbuf (GTK_IMAGE (preview), pixbuf); if (pixbuf) gobject_unref (pixbuf); gtk_file_chooser_set_preview_widget_active (file_chooser, have_preview);} </pre></div></div><br class="example-break"></div><hr><div class="refsect2" lang="en"><a name="gtkfilechooser-extra"></a><h3>Adding Extra Widgets</h3><p> You can add extra widgets to a file chooser to provide options that are not present in the default design. For example, you can add a toggle button to give the user the option to open a file in read-only mode. You can use <a class="link" href="GtkFileChooser.html#gtk-file-chooser-set-extra-widget"><code class="function">gtk_file_chooser_set_extra_widget()</code></a> to insert additional widgets in a file chooser. </p><div class="example"><a name="example-gtkfilechooser-extra"></a><p class="title"><b>Example 31. Sample Usage</b></p><div class="example-contents"><pre class="programlisting">{ GtkWidget *toggle;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -