[gnome-builder/wip/gtk4-port] libide/gui: add helper to get context from window



commit 639153d05b6188d26023d2400b79047c4806bb98
Author: Christian Hergert <chergert redhat com>
Date:   Sat May 14 14:54:00 2022 -0700

    libide/gui: add helper to get context from window

 src/libide/gui/ide-preferences-window.c | 23 +++++++++++++++++++++++
 src/libide/gui/ide-preferences-window.h |  2 ++
 2 files changed, 25 insertions(+)
---
diff --git a/src/libide/gui/ide-preferences-window.c b/src/libide/gui/ide-preferences-window.c
index 914c956e4..bd8a7464e 100644
--- a/src/libide/gui/ide-preferences-window.c
+++ b/src/libide/gui/ide-preferences-window.c
@@ -513,6 +513,8 @@ GtkWidget *
 ide_preferences_window_new (IdePreferencesMode  mode,
                             IdeContext         *context)
 {
+  g_return_val_if_fail (!context || IDE_IS_CONTEXT (context), NULL);
+
   return g_object_new (IDE_TYPE_PREFERENCES_WINDOW,
                        "context", context,
                        "mode", mode,
@@ -1549,3 +1551,24 @@ ide_preferences_window_get_mode (IdePreferencesWindow *self)
 
   return self->mode;
 }
+
+/**
+ * ide_preferences_window_get_context:
+ * @self: a #IdePreferencesWindow
+ *
+ * Gets the context for the preferences window, if any.
+ *
+ * This will always return non-%NULL if the mode is %IDE_PREFERENCES_MODE_PROJECT.
+ *
+ * Otherwise, it will only return non-%NULL if the preferences window was
+ * opened while a project is open.
+ *
+ * Returns: (transfer none) (nullable): an #IdeContext or %NULL
+ */
+IdeContext *
+ide_preferences_window_get_context (IdePreferencesWindow *self)
+{
+  g_return_val_if_fail (IDE_IS_PREFERENCES_WINDOW (self), NULL);
+
+  return self->context;
+}
diff --git a/src/libide/gui/ide-preferences-window.h b/src/libide/gui/ide-preferences-window.h
index 5b8a0adb1..d39cbbfd2 100644
--- a/src/libide/gui/ide-preferences-window.h
+++ b/src/libide/gui/ide-preferences-window.h
@@ -95,6 +95,8 @@ GtkWidget          *ide_preferences_window_new        (IdePreferencesMode
 IDE_AVAILABLE_IN_ALL
 IdePreferencesMode  ide_preferences_window_get_mode   (IdePreferencesWindow          *self);
 IDE_AVAILABLE_IN_ALL
+IdeContext         *ide_preferences_window_get_context (IdePreferencesWindow          *self);
+IDE_AVAILABLE_IN_ALL
 void                ide_preferences_window_add_pages  (IdePreferencesWindow          *self,
                                                        const IdePreferencePageEntry  *pages,
                                                        gsize                          n_pages,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]