Commit 41b458fb authored by Timm Bäder's avatar Timm Bäder 🤔

Fix and improve various code samples

parent f716daa4
Pipeline #200869 failed with stages
in 29 minutes and 44 seconds
......@@ -730,7 +730,7 @@ gtk_dialog_new_empty (const char *title,
*
* Here’s a simple example:
* |[<!-- language="C" -->
* GtkWidget *main_app_window; // Window the dialog should show up on
* GtkWindow *main_app_window; // Window the dialog should show up on
* GtkWidget *dialog;
* GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
* dialog = gtk_dialog_new_with_buttons ("My dialog",
......
......@@ -85,10 +85,12 @@ static guint signals[LAST_SIGNAL] = { 0, };
* ## Simple GtkDrawingArea usage
*
* |[<!-- language="C" -->
* void
* draw_function (GtkDrawingArea *area, cairo_t *cr,
* int width, int height,
* gpointer data)
* static void
* draw_function (GtkDrawingArea *area,
* cairo_t *cr,
* int width,
* int height,
* gpointer data)
* {
* GdkRGBA color;
* GtkStyleContext *context;
......@@ -107,7 +109,8 @@ static guint signals[LAST_SIGNAL] = { 0, };
* cairo_fill (cr);
* }
*
* void main (int argc, char **argv)
* int
* main (int argc, char **argv)
* {
* gtk_init ();
*
......@@ -117,7 +120,7 @@ static guint signals[LAST_SIGNAL] = { 0, };
* gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (area),
* draw_function,
* NULL, NULL);
*
* return 0;
* }
* ]|
*
......
......@@ -40,7 +40,7 @@
* ## Forcing entry to uppercase.
*
* |[<!-- language="C" -->
* #include <ctype.h>;
* #include <ctype.h>
*
* void
* insert_text_handler (GtkEditable *editable,
......
......@@ -482,17 +482,26 @@ gtk_file_chooser_get_files (GtkFileChooser *chooser)
* file and is saving it for the first time, do not call this function.
* Instead, use something similar to this:
* |[<!-- language="C" -->
* if (document_is_new)
* {
* // the user just created a new document
* gtk_file_chooser_set_current_folder (chooser, default_file_for_saving);
* gtk_file_chooser_set_current_name (chooser, "Untitled document");
* }
* else
* {
* // the user edited an existing document
* gtk_file_chooser_set_file (chooser, existing_file);
* }
* static void
* prepare_file_chooser (GtkFileChooser *chooser,
* GFile *existing_file)
* {
* gboolean document_is_new = (existing_file == NULL);
*
* if (document_is_new)
* {
* GFile *default_file_for_saving = g_file_new_for_path ("./out.txt");
* // the user just created a new document
* gtk_file_chooser_set_current_folder (chooser, default_file_for_saving, NULL);
* gtk_file_chooser_set_current_name (chooser, "Untitled document");
* g_object_unref (default_file_for_saving);
* }
* else
* {
* // the user edited an existing document
* gtk_file_chooser_set_file (chooser, existing_file, NULL);
* }
* }
* ]|
*
* Returns: Not useful.
......
......@@ -84,7 +84,7 @@
*
* button = gtk_file_chooser_button_new (_("Select a file"),
* GTK_FILE_CHOOSER_ACTION_OPEN);
* gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), cwd);
* gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (button), cwd, NULL);
* g_object_unref (cwd);
* }
* ]|
......
......@@ -68,7 +68,7 @@
*
* |[<!-- language="C" -->
* static void
* on_response (GtkNativeDialog *dialog,
* on_response (GtkNativeDialog *native,
* int response)
* {
* if (response == GTK_RESPONSE_ACCEPT)
......@@ -102,12 +102,12 @@
*
* |[<!-- language="C" -->
* static void
* on_response (GtkNativeDialog *dialog,
* on_response (GtkNativeDialog *native,
* int response)
* {
* if (response == GTK_RESPONSE_ACCEPT)
* {
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
* GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
* GFile *file = gtk_file_chooser_get_file (chooser);
*
* save_to_file (file);
......@@ -131,11 +131,9 @@
* chooser = GTK_FILE_CHOOSER (native);
*
* if (user_edited_a_new_document)
* gtk_file_chooser_set_current_name (chooser,
* _("Untitled document"));
* gtk_file_chooser_set_current_name (chooser, _("Untitled document"));
* else
* gtk_file_chooser_set_filename (chooser,
* existing_filename);
* gtk_file_chooser_set_file (chooser, existing_file, NULL);
*
* g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
* gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment