Beispiel #1
0
static void
sql_indent_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconsole)
{
	gchar *sql;
	GdaBatch *batch;

	if (!tconsole->priv->parser)
		tconsole->priv->parser = t_connection_create_parser (tconsole->priv->tcnc);

	sql = query_editor_get_all_text (tconsole->priv->editor);
	batch = gda_sql_parser_parse_string_as_batch (tconsole->priv->parser, sql, NULL, NULL);
	g_free (sql);
	if (batch) {
		GString *string;
		const GSList *stmt_list, *list;
		stmt_list = gda_batch_get_statements (batch);
		string = g_string_new ("");
		for (list = stmt_list; list; list = list->next) {
			sql = t_connection_render_pretty_sql (tconsole->priv->tcnc,
							      GDA_STATEMENT (list->data));
			if (!sql)
				sql = gda_statement_to_sql (GDA_STATEMENT (list->data), NULL, NULL);
			if (list != stmt_list)
				g_string_append (string, "\n\n");
			g_string_append_printf (string, "%s;\n", sql);
			g_free (sql);

		}
		g_object_unref (batch);

		query_editor_set_text (tconsole->priv->editor, string->str);
		g_string_free (string, TRUE);
	}
}
Beispiel #2
0
static void
history_copy_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconsole)
{
	QueryEditorHistoryItem *qih;
	QueryEditor *qe;
	GString *string;

	string = g_string_new ("");
	qe = tconsole->priv->history;
        qih = query_editor_get_current_history_item (qe, NULL);
        if (qih)
		g_string_append (string, qih->sql);
        else {
                QueryEditorHistoryBatch *qib;
                qib = query_editor_get_current_history_batch (qe);
                if (qib) {
			GSList *list;
			for (list =  qib->hist_items; list; list = list->next) {
				if (list != qib->hist_items)
					g_string_append (string, "\n\n");
				g_string_append (string, ((QueryEditorHistoryItem*) list->data)->sql);
			}
		}
        }

	query_editor_set_text (tconsole->priv->editor, string->str);
	tconsole->priv->fav_id = -1;
	g_string_free (string, TRUE);
}
Beispiel #3
0
static void
sql_clear_clicked_cb (G_GNUC_UNUSED GtkButton *button, QueryConsolePage *tconsole)
{
	query_editor_set_text (tconsole->priv->editor, NULL);
	tconsole->priv->fav_id = -1;
	gtk_widget_grab_focus (GTK_WIDGET (tconsole->priv->editor));
}
Beispiel #4
0
/**
 * query_console_page_set_text
 * @console: a #QueryConsolePage
 * @text: the new text
 * @fav_id: the favorite ID or -1 if not a favorite.
 *
 * Replaces the edited SQL with @text in @console
 */
void
query_console_page_set_text (QueryConsolePage *console, const gchar *text, gint fav_id)
{
	g_return_if_fail (IS_QUERY_CONSOLE_PAGE_PAGE (console));
	console->priv->fav_id = fav_id;
	query_editor_set_text (console->priv->editor, text);
}
static void
properties_activated_cb (GtkMenuItem *mitem, QueryFavoriteSelector *tsel)
{
	if (! tsel->priv->popup_properties) {
		GtkWidget *pcont, *vbox, *hbox, *label, *entry, *text, *grid;
		gchar *str;
		
		pcont = popup_container_new (GTK_WIDGET (mitem));
		vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
		gtk_container_add (GTK_CONTAINER (pcont), vbox);
		
		label = gtk_label_new ("");
		str = g_strdup_printf ("<b>%s:</b>", _("Favorite's properties"));
		gtk_label_set_markup (GTK_LABEL (label), str);
		g_free (str);
		gtk_widget_set_halign (label, GTK_ALIGN_START);
		gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
		
		hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0); /* HIG */
		gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 5);
		label = gtk_label_new ("      ");
		gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
		
		grid = gtk_grid_new ();
		gtk_box_pack_start (GTK_BOX (hbox), grid, TRUE, TRUE, 0);
		
		label = gtk_label_new ("");
		str = g_strdup_printf ("<b>%s:</b>", _("Name"));
		gtk_label_set_markup (GTK_LABEL (label), str);
		g_free (str);
		gtk_widget_set_halign (label, GTK_ALIGN_START);
		gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
		
		label = gtk_label_new ("");
		str = g_strdup_printf ("<b>%s:</b>", _("SQL Code"));
		gtk_label_set_markup (GTK_LABEL (label), str);
		g_free (str);
		gtk_widget_set_halign (label, GTK_ALIGN_START);
		gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);

		label = gtk_label_new ("");
		str = g_strdup_printf ("<b>%s:</b>", _("Is action"));
		gtk_label_set_markup (GTK_LABEL (label), str);
		g_free (str);
		gtk_widget_set_tooltip_text (label, _("Check this option to make this favorite an action\n"
						      "which can be proposed for execution from grids\n"
						      "containing data. The parameters required to execute\n"
						      "the query will be defined from the row selected in the grid"));
		gtk_widget_set_halign (label, GTK_ALIGN_START);
		gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
		
		entry = gtk_entry_new ();
		gtk_grid_attach (GTK_GRID (grid), entry, 1, 0, 1, 1);
		tsel->priv->properties_name = entry;
		g_signal_connect (entry, "changed",
				  G_CALLBACK (property_changed_cb), tsel);
		
		text = query_editor_new ();
		query_editor_show_tooltip (QUERY_EDITOR (text), FALSE);
		gtk_widget_set_size_request (GTK_WIDGET (text), 400, 300);
		gtk_grid_attach (GTK_GRID (grid), text, 1, 1, 1, 1);
		tsel->priv->properties_text = text;
		g_signal_connect (text, "changed",
				  G_CALLBACK (property_changed_cb), tsel);

		entry = gtk_check_button_new ();
		gtk_grid_attach (GTK_GRID (grid), entry, 1, 2, 1, 1);
		tsel->priv->properties_action = entry;
		g_signal_connect (entry, "toggled",
				  G_CALLBACK (property_changed_cb), tsel);

		tsel->priv->popup_properties = pcont;
		gtk_widget_show_all (vbox);
	}

	/* adjust contents */
	GtkTreeSelection *selection;
	GtkTreeModel *model;
	GtkTreeIter iter;
	selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tsel->priv->treeview));
	if (gtk_tree_selection_get_selected (selection, &model, &iter)) {
		gchar *name, *contents;
		
		gtk_tree_model_get (model, &iter,
				    COLUMN_ID, &(tsel->priv->properties_id),
				    COLUMN_POSITION, &(tsel->priv->properties_position),
				    COLUMN_NAME, &name,
				    COLUMN_CONTENTS, &contents, -1);

		g_signal_handlers_block_by_func (tsel->priv->properties_name,
						 G_CALLBACK (property_changed_cb), tsel);
		gtk_entry_set_text (GTK_ENTRY (tsel->priv->properties_name), name);
		g_signal_handlers_unblock_by_func (tsel->priv->properties_name,
						   G_CALLBACK (property_changed_cb), tsel);
		g_free (name);

		g_signal_handlers_block_by_func (tsel->priv->properties_text,
						 G_CALLBACK (property_changed_cb), tsel);
		query_editor_set_text (QUERY_EDITOR (tsel->priv->properties_text), contents);
		g_signal_handlers_unblock_by_func (tsel->priv->properties_text,
						   G_CALLBACK (property_changed_cb), tsel);
		g_free (contents);

		/* action, if any */
		g_signal_handlers_block_by_func (tsel->priv->properties_action,
						 G_CALLBACK (property_changed_cb), tsel);
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action), FALSE);
		if (tsel->priv->properties_id >= 0) {
			gint id;
			gchar *tmp;
			TFavorites *bfav;
			TFavoritesAttributes fav;
			bfav = t_connection_get_favorites (tsel->priv->tcnc);
			tmp = g_strdup_printf ("QUERY%d", tsel->priv->properties_id);
			id = t_favorites_find (bfav, 0, tmp, &fav, NULL);
			if (id >= 0) {
				gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (tsel->priv->properties_action),
							      TRUE);
				/*g_print ("ACTION_USED %d: %s\n", fav.id, tmp);*/
			}
			g_free (tmp);
		}
		g_signal_handlers_unblock_by_func (tsel->priv->properties_action,
						   G_CALLBACK (property_changed_cb), tsel);

		gtk_widget_show (tsel->priv->popup_properties);
	}
}