[bijiben] windowBase: add detached window, with note at construct
- From: Pierre-Yves Luyten <pyluyten src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bijiben] windowBase: add detached window, with note at construct
- Date: Thu, 23 Jan 2014 23:52:42 +0000 (UTC)
commit ad5618dd2e4b0c223b51a19b6504961fe2b7237c
Author: Pierre-Yves Luyten <py luyten fr>
Date: Fri Jan 24 00:51:49 2014 +0100
windowBase: add detached window, with note at construct
src/bjb-bijiben.c | 29 ++++---------
src/bjb-main-toolbar.c | 22 ++++++----
src/bjb-window-base.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++-
src/bjb-window-base.h | 50 +++++++++++++++--------
4 files changed, 155 insertions(+), 48 deletions(-)
---
diff --git a/src/bjb-bijiben.c b/src/bjb-bijiben.c
index 223843b..1ce1a8e 100644
--- a/src/bjb-bijiben.c
+++ b/src/bjb-bijiben.c
@@ -113,24 +113,9 @@ bijiben_new_window_internal (Bijiben *self,
BijiNoteObj* note;
gchar *path;
-
note = NULL;
path = NULL;
- window = BJB_WINDOW_BASE (bjb_window_base_new ());
- g_signal_connect (window, "activated",
- G_CALLBACK (on_window_activated_cb), self);
-
-
- if (error!= NULL)
- {
- g_warning ("%s", error->message);
- g_error_free (error);
- bjb_window_base_switch_to (window, BJB_WINDOW_BASE_ERROR_TRACKER);
- goto out;
- }
-
-
if (file != NULL)
{
path = g_file_get_parse_name (file);
@@ -143,15 +128,19 @@ bijiben_new_window_internal (Bijiben *self,
}
- bjb_window_base_switch_to (window, BJB_WINDOW_BASE_MAIN_VIEW);
+ window = BJB_WINDOW_BASE (bjb_window_base_new (note));
+ g_signal_connect (window, "activated",
+ G_CALLBACK (on_window_activated_cb), self);
+
- if (note != NULL)
+ if (error!= NULL)
{
- bjb_controller_apply_needle (bjb_window_base_get_controller (window));
- bjb_window_base_switch_to_item (window, BIJI_ITEM (note));
+ g_warning ("%s", error->message);
+ g_error_free (error);
+ bjb_window_base_switch_to (window, BJB_WINDOW_BASE_ERROR_TRACKER);
}
-out:
+
if (path != NULL)
g_free (path);
diff --git a/src/bjb-main-toolbar.c b/src/bjb-main-toolbar.c
index d654cb4..85b0a29 100644
--- a/src/bjb-main-toolbar.c
+++ b/src/bjb-main-toolbar.c
@@ -784,12 +784,13 @@ populate_bar_for_note_view (BjbMainToolbar *self)
BijiItem *item;
GtkWidget *share_image;
GtkWidget *menu_image;
- gboolean rtl;
+ gboolean rtl, detached;
priv->note = bjb_window_base_get_note (BJB_WINDOW_BASE (self->priv->window));
item = BIJI_ITEM (priv->note);
rtl = (gtk_widget_get_default_direction () == GTK_TEXT_DIR_RTL);
+ detached = bjb_window_base_is_detached (BJB_WINDOW_BASE (self->priv->window));
if (!priv->note) /* no reason this would happen */
return;
@@ -797,15 +798,18 @@ populate_bar_for_note_view (BjbMainToolbar *self)
settings = bjb_app_get_settings (g_application_get_default());
/* Go to main view basically means closing note */
- priv->back = gtk_button_new_from_icon_name (rtl ? "go-previous-rtl-symbolic" : "go-previous-symbolic",
- GTK_ICON_SIZE_MENU);
- gtk_widget_set_valign (priv->back, GTK_ALIGN_CENTER);
- gtk_header_bar_pack_start (bar, priv->back);
+ if (!detached)
+ {
+ priv->back = gtk_button_new_from_icon_name (rtl ? "go-previous-rtl-symbolic" : "go-previous-symbolic",
+ GTK_ICON_SIZE_MENU);
+ gtk_widget_set_valign (priv->back, GTK_ALIGN_CENTER);
+ gtk_header_bar_pack_start (bar, priv->back);
- g_signal_connect_swapped (priv->back, "clicked",
- G_CALLBACK (just_switch_to_main_view), self);
- gtk_widget_add_accelerator (priv->back, "activate", self->priv->accel,
- GDK_KEY_w, GDK_CONTROL_MASK, GTK_ACCEL_MASK);
+ g_signal_connect_swapped (priv->back, "clicked",
+ G_CALLBACK (just_switch_to_main_view), self);
+ gtk_widget_add_accelerator (priv->back, "activate", self->priv->accel,
+ GDK_KEY_w, GDK_CONTROL_MASK, GTK_ACCEL_MASK);
+ }
/* Note Title */
on_note_renamed (item, self);
diff --git a/src/bjb-window-base.c b/src/bjb-window-base.c
index 6ee389a..433a7da 100644
--- a/src/bjb-window-base.c
+++ b/src/bjb-window-base.c
@@ -18,6 +18,16 @@
#define BJB_DEFAULT_FONT "Serif 10"
+
+enum {
+ PROP_0,
+ PROP_NOTE,
+ NUM_PROPERTIES
+};
+
+static GParamSpec *properties[NUM_PROPERTIES] = { NULL, };
+
+
enum {
BJB_WIN_BASE_VIEW_CHANGED,
BJB_WIN_BASE_ACTIVATED,
@@ -49,6 +59,7 @@ struct _BjbWindowBasePriv
/* when a note is opened */
BijiNoteObj *note;
+ gboolean detached; // detached note
GtkWidget *note_overlay;
@@ -83,6 +94,55 @@ bjb_window_base_finalize (GObject *object)
G_OBJECT_CLASS (bjb_window_base_parent_class)->finalize (object);
}
+
+
+
+static void
+bjb_window_base_get_property (GObject *object,
+ guint property_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ BjbWindowBase *self = BJB_WINDOW_BASE (object);
+
+ switch (property_id)
+ {
+ case PROP_NOTE:
+ g_value_set_object (value, self->priv->note);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+static void
+bjb_window_base_set_property (GObject *object,
+ guint property_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ BjbWindowBase *self = BJB_WINDOW_BASE (object);
+
+ switch (property_id)
+ {
+ case PROP_NOTE:
+ self->priv->note = g_value_get_object (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+ break;
+ }
+}
+
+
+
+
+
+
+
+
/* Just disconnect to avoid crash, the finalize does the real
* job */
static void
@@ -171,9 +231,11 @@ bjb_window_base_constructed (GObject *obj)
G_OBJECT_CLASS (bjb_window_base_parent_class)->constructed (obj);
priv = self->priv;
- priv->note = NULL;
priv->settings = bjb_app_get_settings ((gpointer) g_application_get_default ());
+
+
+
gtk_window_set_position (GTK_WINDOW (self),GTK_WIN_POS_CENTER);
gtk_window_set_title (GTK_WINDOW (self), _(BIJIBEN_MAIN_WIN_TITLE));
@@ -268,6 +330,18 @@ bjb_window_base_constructed (GObject *obj)
G_CALLBACK (bjb_application_window_configured),
self);
+ /* If a note is requested at creation, show it
+ * This is a specific type of window not associated with any view */
+ if (priv->note == NULL)
+ {
+ bjb_window_base_switch_to (self, BJB_WINDOW_BASE_MAIN_VIEW);
+ }
+
+ else
+ {
+ priv->detached = TRUE;
+ bjb_window_base_switch_to_item (self, BIJI_ITEM (priv->note));
+ }
}
static void
@@ -281,6 +355,8 @@ bjb_window_base_init (BjbWindowBase *self)
/* Default window has no note opened */
priv->note_view = NULL;
+ priv->note = NULL;
+ priv->detached = FALSE;
priv->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add (GTK_CONTAINER (self), priv->vbox);
@@ -291,9 +367,12 @@ bjb_window_base_class_init (BjbWindowBaseClass *klass)
{
GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
gobject_class->constructed = bjb_window_base_constructed;
gobject_class->constructor = bjb_window_base_constructor;
gobject_class->finalize = bjb_window_base_finalize ;
+ gobject_class->get_property = bjb_window_base_get_property;
+ gobject_class->set_property = bjb_window_base_set_property;
g_type_class_add_private (klass, sizeof (BjbWindowBasePriv));
@@ -317,14 +396,26 @@ bjb_window_base_class_init (BjbWindowBaseClass *klass)
G_TYPE_NONE,
1,
G_TYPE_BOOLEAN);
+
+ properties[PROP_NOTE] = g_param_spec_object ("note",
+ "NoteObj",
+ "Currently opened note",
+ BIJI_TYPE_NOTE_OBJ,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT |
+ G_PARAM_STATIC_STRINGS);
+
+ g_object_class_install_properties (gobject_class, NUM_PROPERTIES, properties);
+
}
GtkWindow *
-bjb_window_base_new(void)
+bjb_window_base_new (BijiNoteObj *note)
{
return g_object_new (BJB_TYPE_WINDOW_BASE,
"application", g_application_get_default(),
+ "note", note,
NULL);
}
@@ -553,3 +644,10 @@ bjb_window_base_set_active (BjbWindowBase *self, gboolean active)
available);
}
}
+
+
+gboolean
+bjb_window_base_is_detached (BjbWindowBase *self)
+{
+ return self->priv->detached;
+}
diff --git a/src/bjb-window-base.h b/src/bjb-window-base.h
index 74ad300..004937d 100644
--- a/src/bjb-window-base.h
+++ b/src/bjb-window-base.h
@@ -41,43 +41,59 @@ typedef enum {
BJB_WINDOW_BASE_NO_VIEW
} BjbWindowViewType;
-GType bjb_window_base_get_type (void);
-GtkWindow * bjb_window_base_new(void);
-// Accessor
+GType bjb_window_base_get_type (void);
-BjbController * bjb_window_base_get_controller ( BjbWindowBase *window ) ;
+GtkWindow *bjb_window_base_new (BijiNoteObj *note);
-void bjb_window_base_switch_to (BjbWindowBase *bwb, BjbWindowViewType type);
-void bjb_window_base_switch_to_item (BjbWindowBase *bwb, BijiItem *item);
+BjbController *bjb_window_base_get_controller (BjbWindowBase *window ) ;
-BjbWindowViewType bjb_window_base_get_view_type (BjbWindowBase *win);
-BijiManager * bjb_window_base_get_manager(GtkWidget * win);
+void bjb_window_base_switch_to (BjbWindowBase *bwb, BjbWindowViewType type);
-void bjb_window_base_set_entry(GtkWidget *win, gchar *search_entry) ;
+void bjb_window_base_switch_to_item (BjbWindowBase *bwb, BijiItem *item);
-gchar * bjb_window_base_get_entry(GtkWidget *win) ;
+BjbWindowViewType bjb_window_base_get_view_type (BjbWindowBase *win);
-gpointer bjb_window_base_get_main_view (BjbWindowBase *self);
-BijiNoteObj * bjb_window_base_get_note (BjbWindowBase *self);
+BijiManager *bjb_window_base_get_manager (GtkWidget * win);
-gboolean switch_window_fullscreen();
-gboolean bjb_window_base_get_show_search_bar (BjbWindowBase *self);
+void bjb_window_base_set_entry(GtkWidget *win, gchar *search_entry) ;
-gboolean bjb_window_base_set_show_search_bar (BjbWindowBase *self, gboolean show);
-gboolean bjb_window_base_toggle_search_button (BjbWindowBase *self,
+gchar *bjb_window_base_get_entry(GtkWidget *win) ;
+
+
+gpointer bjb_window_base_get_main_view (BjbWindowBase *self);
+
+
+BijiNoteObj *bjb_window_base_get_note (BjbWindowBase *self);
+
+
+gboolean switch_window_fullscreen();
+
+
+gboolean bjb_window_base_get_show_search_bar (BjbWindowBase *self);
+
+
+gboolean bjb_window_base_set_show_search_bar (BjbWindowBase *self, gboolean show);
+
+
+gboolean bjb_window_base_toggle_search_button (BjbWindowBase *self,
gboolean active);
-void bjb_window_base_set_active (BjbWindowBase *self, gboolean active);
+void bjb_window_base_set_active (BjbWindowBase *self, gboolean active);
+
+
+
+gboolean bjb_window_base_is_detached (BjbWindowBase *self);
+
#endif /* _BJB_WINDOW_BASE_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]