2014-05-03 01:48:33 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2013 Intel Corporation
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-05-07 04:13:00 +00:00
|
|
|
#include "config.h"
|
2014-05-09 02:19:21 +00:00
|
|
|
#include <glib/gi18n-lib.h>
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2019-12-07 16:48:39 +00:00
|
|
|
#include "window.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "css-editor.h"
|
|
|
|
|
|
|
|
#include "gtkcssprovider.h"
|
|
|
|
#include "gtkstyleprovider.h"
|
|
|
|
#include "gtkstylecontext.h"
|
|
|
|
#include "gtktextview.h"
|
|
|
|
#include "gtkmessagedialog.h"
|
|
|
|
#include "gtkfilechooserdialog.h"
|
2014-11-22 18:26:53 +00:00
|
|
|
#include "gtktogglebutton.h"
|
|
|
|
#include "gtklabel.h"
|
2015-11-20 23:18:01 +00:00
|
|
|
#include "gtktooltip.h"
|
|
|
|
#include "gtktextiter.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2019-03-22 03:20:17 +00:00
|
|
|
#include "gtk/css/gtkcss.h"
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
struct _GtkInspectorCssEditorPrivate
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-04 18:53:17 +00:00
|
|
|
GtkWidget *view;
|
2014-05-03 01:48:33 +00:00
|
|
|
GtkTextBuffer *text;
|
2019-12-07 16:48:39 +00:00
|
|
|
GdkDisplay *display;
|
2014-05-03 01:48:33 +00:00
|
|
|
GtkCssProvider *provider;
|
2014-11-22 18:26:53 +00:00
|
|
|
GtkToggleButton *disable_button;
|
2014-06-03 13:44:28 +00:00
|
|
|
guint timeout;
|
2015-11-20 23:18:01 +00:00
|
|
|
GList *errors;
|
2014-05-03 01:48:33 +00:00
|
|
|
};
|
|
|
|
|
2015-11-20 23:18:01 +00:00
|
|
|
typedef struct {
|
|
|
|
GError *error;
|
|
|
|
GtkTextIter start;
|
|
|
|
GtkTextIter end;
|
|
|
|
} CssError;
|
|
|
|
|
|
|
|
static void
|
|
|
|
css_error_free (gpointer data)
|
|
|
|
{
|
|
|
|
CssError *error = data;
|
|
|
|
g_error_free (error->error);
|
|
|
|
g_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
query_tooltip_cb (GtkWidget *widget,
|
2020-07-24 13:54:49 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
2015-11-20 23:18:01 +00:00
|
|
|
gboolean keyboard_tip,
|
|
|
|
GtkTooltip *tooltip,
|
|
|
|
GtkInspectorCssEditor *ce)
|
|
|
|
{
|
|
|
|
GtkTextIter iter;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
if (keyboard_tip)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int offset;
|
2015-11-20 23:18:01 +00:00
|
|
|
|
|
|
|
g_object_get (ce->priv->text, "cursor-position", &offset, NULL);
|
|
|
|
gtk_text_buffer_get_iter_at_offset (ce->priv->text, &iter, offset);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int bx, by, trailing;
|
2015-11-20 23:18:01 +00:00
|
|
|
|
|
|
|
gtk_text_view_window_to_buffer_coords (GTK_TEXT_VIEW (ce->priv->view), GTK_TEXT_WINDOW_TEXT,
|
|
|
|
x, y, &bx, &by);
|
|
|
|
gtk_text_view_get_iter_at_position (GTK_TEXT_VIEW (ce->priv->view), &iter, &trailing, bx, by);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = ce->priv->errors; l; l = l->next)
|
|
|
|
{
|
|
|
|
CssError *css_error = l->data;
|
|
|
|
|
|
|
|
if (gtk_text_iter_in_range (&iter, &css_error->start, &css_error->end))
|
|
|
|
{
|
|
|
|
gtk_tooltip_set_text (tooltip, css_error->error->message);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-05-07 03:24:20 +00:00
|
|
|
G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorCssEditor, gtk_inspector_css_editor, GTK_TYPE_BOX)
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2019-04-06 18:00:09 +00:00
|
|
|
static char *
|
|
|
|
get_autosave_path (void)
|
|
|
|
{
|
|
|
|
return g_build_filename (g_get_user_cache_dir (), "gtk-4.0", "inspector-css-autosave", NULL);
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-09 02:19:21 +00:00
|
|
|
set_initial_text (GtkInspectorCssEditor *ce)
|
2014-05-04 18:53:17 +00:00
|
|
|
{
|
2019-04-06 18:00:09 +00:00
|
|
|
char *initial_text = NULL;
|
|
|
|
char *autosave_file = NULL;
|
|
|
|
gsize len;
|
|
|
|
|
|
|
|
autosave_file = get_autosave_path ();
|
|
|
|
|
2019-04-06 23:08:10 +00:00
|
|
|
if (g_file_get_contents (autosave_file, &initial_text, &len, NULL))
|
|
|
|
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (ce->priv->disable_button), TRUE);
|
|
|
|
else
|
2019-04-06 18:00:09 +00:00
|
|
|
initial_text = g_strconcat ("/*\n",
|
|
|
|
_("You can type here any CSS rule recognized by GTK."), "\n",
|
|
|
|
_("You can temporarily disable this custom CSS by clicking on the “Pause” button above."), "\n\n",
|
|
|
|
_("Changes are applied instantly and globally, for the whole application."), "\n",
|
|
|
|
"*/\n\n", NULL);
|
2017-03-20 14:01:28 +00:00
|
|
|
gtk_text_buffer_set_text (GTK_TEXT_BUFFER (ce->priv->text), initial_text, -1);
|
|
|
|
g_free (initial_text);
|
2019-04-06 18:00:09 +00:00
|
|
|
g_free (autosave_file);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
autosave_contents (GtkInspectorCssEditor *ce)
|
|
|
|
{
|
|
|
|
char *autosave_file = NULL;
|
|
|
|
char *dir = NULL;
|
|
|
|
char *contents;
|
|
|
|
GtkTextIter start, end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_bounds (GTK_TEXT_BUFFER (ce->priv->text), &start, &end);
|
|
|
|
contents = gtk_text_buffer_get_text (GTK_TEXT_BUFFER (ce->priv->text), &start, &end, TRUE);
|
|
|
|
autosave_file = get_autosave_path ();
|
|
|
|
dir = g_path_get_dirname (autosave_file);
|
2019-04-11 23:16:07 +00:00
|
|
|
g_mkdir_with_parents (dir, 0755);
|
2019-04-06 18:00:09 +00:00
|
|
|
g_file_set_contents (autosave_file, contents, -1, NULL);
|
|
|
|
|
|
|
|
g_free (dir);
|
|
|
|
g_free (autosave_file);
|
|
|
|
g_free (contents);
|
2014-05-04 18:53:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-11-22 18:26:53 +00:00
|
|
|
disable_toggled (GtkToggleButton *button,
|
2014-05-09 02:19:21 +00:00
|
|
|
GtkInspectorCssEditor *ce)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2019-12-07 16:48:39 +00:00
|
|
|
if (!ce->priv->display)
|
|
|
|
return;
|
|
|
|
|
2014-11-22 18:26:53 +00:00
|
|
|
if (gtk_toggle_button_get_active (button))
|
2019-12-07 16:48:39 +00:00
|
|
|
gtk_style_context_remove_provider_for_display (ce->priv->display,
|
2017-10-31 01:35:21 +00:00
|
|
|
GTK_STYLE_PROVIDER (ce->priv->provider));
|
2014-05-03 01:48:33 +00:00
|
|
|
else
|
2019-12-07 16:48:39 +00:00
|
|
|
gtk_style_context_add_provider_for_display (ce->priv->display,
|
2017-10-31 01:35:21 +00:00
|
|
|
GTK_STYLE_PROVIDER (ce->priv->provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
2014-05-31 00:35:43 +00:00
|
|
|
get_current_text (GtkTextBuffer *buffer)
|
|
|
|
{
|
|
|
|
GtkTextIter start, end;
|
|
|
|
|
|
|
|
gtk_text_buffer_get_start_iter (buffer, &start);
|
|
|
|
gtk_text_buffer_get_end_iter (buffer, &end);
|
|
|
|
gtk_text_buffer_remove_all_tags (buffer, &start, &end);
|
|
|
|
|
|
|
|
return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
save_to_file (GtkInspectorCssEditor *ce,
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *file)
|
2014-05-31 00:35:43 +00:00
|
|
|
{
|
|
|
|
GError *error = NULL;
|
2020-02-21 15:11:15 +00:00
|
|
|
char *text;
|
2014-05-31 00:35:43 +00:00
|
|
|
|
|
|
|
text = get_current_text (ce->priv->text);
|
|
|
|
|
2020-02-21 15:11:15 +00:00
|
|
|
g_file_replace_contents (file, text, -1,
|
|
|
|
NULL,
|
|
|
|
FALSE,
|
|
|
|
G_FILE_CREATE_NONE,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&error);
|
|
|
|
|
|
|
|
if (error != NULL)
|
2014-05-31 00:35:43 +00:00
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
2014-05-31 00:35:43 +00:00
|
|
|
GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
GTK_MESSAGE_INFO,
|
|
|
|
GTK_BUTTONS_OK,
|
|
|
|
_("Saving CSS failed"));
|
|
|
|
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
|
|
|
|
"%s", error->message);
|
2020-05-09 14:26:22 +00:00
|
|
|
g_signal_connect (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
|
2014-05-31 00:35:43 +00:00
|
|
|
gtk_widget_show (dialog);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
save_response (GtkWidget *dialog,
|
2020-07-24 13:54:49 +00:00
|
|
|
int response,
|
2014-05-31 00:35:43 +00:00
|
|
|
GtkInspectorCssEditor *ce)
|
|
|
|
{
|
|
|
|
gtk_widget_hide (dialog);
|
|
|
|
|
|
|
|
if (response == GTK_RESPONSE_ACCEPT)
|
|
|
|
{
|
2020-02-21 15:11:15 +00:00
|
|
|
GFile *file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
|
|
|
|
save_to_file (ce, file);
|
|
|
|
g_object_unref (file);
|
2014-05-31 00:35:43 +00:00
|
|
|
}
|
|
|
|
|
2020-05-09 14:26:22 +00:00
|
|
|
gtk_window_destroy (GTK_WINDOW (dialog));
|
2014-05-31 00:35:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-11-22 18:26:53 +00:00
|
|
|
save_clicked (GtkButton *button,
|
2014-05-31 00:35:43 +00:00
|
|
|
GtkInspectorCssEditor *ce)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
|
|
|
|
dialog = gtk_file_chooser_dialog_new ("",
|
2019-05-20 04:47:50 +00:00
|
|
|
GTK_WINDOW (gtk_widget_get_root (GTK_WIDGET (ce))),
|
2014-05-31 00:35:43 +00:00
|
|
|
GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
_("_Cancel"), GTK_RESPONSE_CANCEL,
|
|
|
|
_("_Save"), GTK_RESPONSE_ACCEPT,
|
|
|
|
NULL);
|
2014-07-29 11:38:54 +00:00
|
|
|
gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "custom.css");
|
2014-05-31 00:35:43 +00:00
|
|
|
gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_ACCEPT);
|
|
|
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
|
|
|
g_signal_connect (dialog, "response", G_CALLBACK (save_response), ce);
|
|
|
|
gtk_widget_show (dialog);
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-06-03 13:44:28 +00:00
|
|
|
update_style (GtkInspectorCssEditor *ce)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2015-11-20 23:18:01 +00:00
|
|
|
g_list_free_full (ce->priv->errors, css_error_free);
|
|
|
|
ce->priv->errors = NULL;
|
|
|
|
|
2014-06-03 13:44:28 +00:00
|
|
|
text = get_current_text (ce->priv->text);
|
2016-10-17 14:09:12 +00:00
|
|
|
gtk_css_provider_load_from_data (ce->priv->provider, text, -1);
|
2014-05-03 01:48:33 +00:00
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
|
2014-06-03 13:44:28 +00:00
|
|
|
static gboolean
|
|
|
|
update_timeout (gpointer data)
|
|
|
|
{
|
|
|
|
GtkInspectorCssEditor *ce = data;
|
|
|
|
|
|
|
|
ce->priv->timeout = 0;
|
|
|
|
|
2019-04-06 18:00:09 +00:00
|
|
|
autosave_contents (ce);
|
2014-06-03 13:44:28 +00:00
|
|
|
update_style (ce);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
text_changed (GtkTextBuffer *buffer,
|
|
|
|
GtkInspectorCssEditor *ce)
|
|
|
|
{
|
|
|
|
if (ce->priv->timeout != 0)
|
|
|
|
g_source_remove (ce->priv->timeout);
|
|
|
|
|
|
|
|
ce->priv->timeout = g_timeout_add (100, update_timeout, ce);
|
2015-12-20 19:40:49 +00:00
|
|
|
|
|
|
|
g_list_free_full (ce->priv->errors, css_error_free);
|
|
|
|
ce->priv->errors = NULL;
|
2014-06-03 13:44:28 +00:00
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
show_parsing_error (GtkCssProvider *provider,
|
|
|
|
GtkCssSection *section,
|
|
|
|
const GError *error,
|
2014-05-09 02:19:21 +00:00
|
|
|
GtkInspectorCssEditor *ce)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
const char *tag_name;
|
2014-05-09 02:19:21 +00:00
|
|
|
GtkTextBuffer *buffer = GTK_TEXT_BUFFER (ce->priv->text);
|
2019-04-10 03:18:14 +00:00
|
|
|
const GtkCssLocation *start, *end;
|
2015-11-20 23:18:01 +00:00
|
|
|
CssError *css_error;
|
|
|
|
|
|
|
|
css_error = g_new (CssError, 1);
|
|
|
|
css_error->error = g_error_copy (error);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2019-04-10 03:18:14 +00:00
|
|
|
start = gtk_css_section_get_start_location (section);
|
2015-10-15 12:10:00 +00:00
|
|
|
gtk_text_buffer_get_iter_at_line_index (buffer,
|
2015-11-20 23:18:01 +00:00
|
|
|
&css_error->start,
|
2019-04-10 03:18:14 +00:00
|
|
|
start->lines,
|
|
|
|
start->line_bytes);
|
|
|
|
end = gtk_css_section_get_end_location (section);
|
2015-10-15 12:10:00 +00:00
|
|
|
gtk_text_buffer_get_iter_at_line_index (buffer,
|
2015-11-20 23:18:01 +00:00
|
|
|
&css_error->end,
|
2019-04-10 03:18:14 +00:00
|
|
|
end->lines,
|
|
|
|
end->line_bytes);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2019-03-22 03:20:17 +00:00
|
|
|
if (error->domain == GTK_CSS_PARSER_WARNING)
|
2014-05-03 01:48:33 +00:00
|
|
|
tag_name = "warning";
|
|
|
|
else
|
|
|
|
tag_name = "error";
|
|
|
|
|
2015-11-21 01:58:42 +00:00
|
|
|
if (gtk_text_iter_equal (&css_error->start, &css_error->end))
|
|
|
|
gtk_text_iter_forward_char (&css_error->end);
|
|
|
|
|
2015-11-20 23:18:01 +00:00
|
|
|
gtk_text_buffer_apply_tag_by_name (buffer, tag_name, &css_error->start, &css_error->end);
|
|
|
|
|
|
|
|
ce->priv->errors = g_list_prepend (ce->priv->errors, css_error);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2014-05-09 02:19:21 +00:00
|
|
|
create_provider (GtkInspectorCssEditor *ce)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2016-03-07 02:41:46 +00:00
|
|
|
ce->priv->provider = gtk_css_provider_new ();
|
|
|
|
g_signal_connect (ce->priv->provider, "parsing-error",
|
2014-05-09 02:19:21 +00:00
|
|
|
G_CALLBACK (show_parsing_error), ce);
|
2019-12-07 16:48:39 +00:00
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 03:05:15 +00:00
|
|
|
static void
|
|
|
|
destroy_provider (GtkInspectorCssEditor *ce)
|
|
|
|
{
|
2019-12-07 16:48:39 +00:00
|
|
|
g_signal_handlers_disconnect_by_func (ce->priv->provider, show_parsing_error, ce);
|
2016-03-07 02:41:46 +00:00
|
|
|
g_clear_object (&ce->priv->provider);
|
2014-09-26 03:05:15 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 16:48:39 +00:00
|
|
|
static void
|
|
|
|
add_provider (GtkInspectorCssEditor *ce,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
gtk_style_context_add_provider_for_display (display,
|
|
|
|
GTK_STYLE_PROVIDER (ce->priv->provider),
|
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_USER);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
remove_provider (GtkInspectorCssEditor *ce,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
gtk_style_context_remove_provider_for_display (display,
|
|
|
|
GTK_STYLE_PROVIDER (ce->priv->provider));
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-09 02:19:21 +00:00
|
|
|
gtk_inspector_css_editor_init (GtkInspectorCssEditor *ce)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
2014-05-09 02:19:21 +00:00
|
|
|
ce->priv = gtk_inspector_css_editor_get_instance_private (ce);
|
|
|
|
gtk_widget_init_template (GTK_WIDGET (ce));
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
2014-05-09 02:19:21 +00:00
|
|
|
GtkInspectorCssEditor *ce = GTK_INSPECTOR_CSS_EDITOR (object);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-09 02:19:21 +00:00
|
|
|
create_provider (ce);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2014-06-03 13:44:28 +00:00
|
|
|
static void
|
|
|
|
finalize (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorCssEditor *ce = GTK_INSPECTOR_CSS_EDITOR (object);
|
|
|
|
|
|
|
|
if (ce->priv->timeout != 0)
|
|
|
|
g_source_remove (ce->priv->timeout);
|
|
|
|
|
2019-12-07 16:48:39 +00:00
|
|
|
if (ce->priv->display)
|
|
|
|
remove_provider (ce, ce->priv->display);
|
2014-09-26 03:05:15 +00:00
|
|
|
destroy_provider (ce);
|
|
|
|
|
2015-11-20 23:18:01 +00:00
|
|
|
g_list_free_full (ce->priv->errors, css_error_free);
|
|
|
|
|
2014-06-03 13:44:28 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_css_editor_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2014-05-03 01:48:33 +00:00
|
|
|
static void
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_inspector_css_editor_class_init (GtkInspectorCssEditorClass *klass)
|
2014-05-03 01:48:33 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-05-04 18:53:17 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
2014-05-03 01:48:33 +00:00
|
|
|
|
2014-05-04 18:53:17 +00:00
|
|
|
object_class->constructed = constructed;
|
2014-06-03 13:44:28 +00:00
|
|
|
object_class->finalize = finalize;
|
2014-05-04 18:53:17 +00:00
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/css-editor.ui");
|
2014-05-07 03:24:20 +00:00
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssEditor, text);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssEditor, view);
|
|
|
|
gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorCssEditor, disable_button);
|
2014-05-04 18:53:17 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, disable_toggled);
|
2014-05-31 00:35:43 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, save_clicked);
|
2014-05-04 18:53:17 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, text_changed);
|
2015-11-20 23:18:01 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, query_tooltip_cb);
|
2014-05-03 01:48:33 +00:00
|
|
|
}
|
|
|
|
|
2019-12-07 16:48:39 +00:00
|
|
|
void
|
|
|
|
gtk_inspector_css_editor_set_display (GtkInspectorCssEditor *ce,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
|
|
|
ce->priv->display = display;
|
|
|
|
add_provider (ce, display);
|
|
|
|
set_initial_text (ce);
|
|
|
|
}
|
|
|
|
|
2014-05-04 18:53:17 +00:00
|
|
|
// vim: set et sw=2 ts=2:
|