static void on_drag_data_received (GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, gpointer user_data) { gint length = gtk_selection_data_get_length (data) ; if (length >= 0) { guchar *text = gtk_selection_data_get_text(data); if (text) { BijiManager *manager; BijiNoteObj *ret; BjbMainView *self = BJB_MAIN_VIEW (user_data); BjbSettings *settings; /* FIXME Text is guchar utf 8, conversion to perform */ manager = bjb_window_base_get_manager (self->priv->window); settings = bjb_app_get_settings (g_application_get_default ()); ret = biji_manager_note_new (manager, (gchar*) text, bjb_settings_get_default_location (settings)); switch_to_note_view (self, ret); // maybe AFTER drag finish? g_free (text); } } /* Return false to ensure text is not removed from source * We just want to create a note. */ gtk_drag_finish (context, FALSE, FALSE, time); }
/* Gobj */ static void bjb_window_base_constructed (GObject *obj) { BjbWindowBase *self = BJB_WINDOW_BASE (obj); BjbWindowBasePriv *priv; gboolean maximized; const gint32 *position; const gint32 *size; gsize n_elements; GVariant *variant; G_OBJECT_CLASS (bjb_window_base_parent_class)->constructed (obj); priv = self->priv; 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)); variant = g_settings_get_value (G_SETTINGS (priv->settings), "window-size"); size = g_variant_get_fixed_array (variant, &n_elements, sizeof (gint32)); if (n_elements == 2) gtk_window_set_default_size (GTK_WINDOW (self), size[0], size[1]); g_variant_unref (variant); variant = g_settings_get_value (G_SETTINGS (priv->settings), "window-position"); position = g_variant_get_fixed_array (variant, &n_elements, sizeof (gint32)); if (n_elements == 2) gtk_window_move (GTK_WINDOW (self), position[0], position[1]); g_variant_unref (variant); maximized = g_settings_get_boolean (G_SETTINGS (priv->settings), "window-maximized"); if (maximized) gtk_window_maximize (GTK_WINDOW (self)); /* We probably want to offer a no entry window at first (startup) */ priv->entry = NULL ; priv->controller = bjb_controller_new (bijiben_get_manager (BIJIBEN_APPLICATION(g_application_get_default())), GTK_WINDOW (obj), priv->entry ); /* Shared toolbar */ priv->view = bjb_main_view_new (GTK_WIDGET (obj), priv->controller); priv->main_toolbar = bjb_main_toolbar_new (priv->view, priv->controller); gtk_window_set_titlebar (GTK_WINDOW (self), GTK_WIDGET (priv->main_toolbar)); /* Search entry toolbar */ priv->search_bar = bjb_search_toolbar_new (GTK_WIDGET (obj), priv->controller); gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (priv->search_bar), FALSE, FALSE, 0); /* UI : stack for different views */ priv->stack = GTK_STACK (gtk_stack_new ()); gtk_box_pack_start (GTK_BOX (priv->vbox), GTK_WIDGET (priv->stack), TRUE, TRUE, 0); priv->spinner = gtk_spinner_new (); gtk_stack_add_named (priv->stack, priv->spinner, "spinner"); gtk_stack_set_visible_child_name (priv->stack, "spinner"); gtk_widget_show (priv->spinner); gtk_spinner_start (GTK_SPINNER (priv->spinner)); priv->no_note = bjb_empty_results_box_new (); gtk_stack_add_named (priv->stack, priv->no_note, "empty"); gtk_stack_add_named (priv->stack, GTK_WIDGET (priv->view), "main-view"); gtk_widget_show (GTK_WIDGET (priv->stack)); /* Connection to window signals */ g_signal_connect (GTK_WIDGET (self), "destroy", G_CALLBACK (bjb_window_base_destroy), self); g_signal_connect (self, "window-state-event", G_CALLBACK (bjb_application_window_state_changed), priv->settings); g_signal_connect (self, "configure-event", G_CALLBACK (bjb_application_window_configured), self); /* Keys */ g_signal_connect (GTK_WIDGET (self), "key-press-event", G_CALLBACK(on_key_pressed_cb), 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)); } /* For some reason, do not gtk_widget_show _self_ * or gtk_application_get_menu_bar will run, * fire a warning, while app menu will not show up * you have been warned! * * This is probably due to the fact that, * at startup, we still are * inside... drums... gapplication startup () */ gtk_widget_show (priv->vbox); }