[gnome-text-editor] infobar: show error infobar on file failure
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] infobar: show error infobar on file failure
- Date: Tue, 11 Jan 2022 01:37:54 +0000 (UTC)
commit 10c8e9c4e357808edc322c6879fc016a7c6add49
Author: Christian Hergert <chergert redhat com>
Date: Mon Jan 10 17:37:40 2022 -0800
infobar: show error infobar on file failure
We probably still need this for save operations, but for loading this
allows us to get the ability to reload a file. Additionally, we probably
need to make things not editable during the process for these kind of
errors.
src/editor-document.c | 17 ++++++++++++++++-
src/editor-info-bar.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/editor-info-bar.ui | 42 ++++++++++++++++++++++++++++++++++++++++++
3 files changed, 101 insertions(+), 1 deletion(-)
---
diff --git a/src/editor-document.c b/src/editor-document.c
index 570e2ca..34ccbcf 100644
--- a/src/editor-document.c
+++ b/src/editor-document.c
@@ -89,12 +89,13 @@ G_DEFINE_TYPE (EditorDocument, editor_document, GTK_SOURCE_TYPE_BUFFER)
enum {
PROP_0,
- PROP_SUGGEST_ADMIN,
PROP_BUSY,
PROP_BUSY_PROGRESS,
PROP_EXTERNALLY_MODIFIED,
PROP_FILE,
+ PROP_HAD_ERROR,
PROP_SPELL_CHECKER,
+ PROP_SUGGEST_ADMIN,
PROP_TITLE,
N_PROPS
};
@@ -141,6 +142,7 @@ editor_document_track_error (EditorDocument *self,
{
self->suggest_admin = FALSE;
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SUGGEST_ADMIN]);
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAD_ERROR]);
return;
}
@@ -152,6 +154,8 @@ editor_document_track_error (EditorDocument *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SUGGEST_ADMIN]);
}
}
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAD_ERROR]);
}
static void
@@ -509,6 +513,10 @@ editor_document_get_property (GObject *object,
g_value_set_boolean (value, self->suggest_admin);
break;
+ case PROP_HAD_ERROR:
+ g_value_set_boolean (value, _editor_document_had_error (self));
+ break;
+
case PROP_BUSY:
g_value_set_boolean (value, editor_document_get_busy (self));
break;
@@ -583,6 +591,13 @@ editor_document_class_init (EditorDocumentClass *klass)
FALSE,
(G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+ properties [PROP_HAD_ERROR] =
+ g_param_spec_boolean ("had-error",
+ "Had Error",
+ "If there was an error with the document",
+ FALSE,
+ (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
+
properties [PROP_BUSY] =
g_param_spec_boolean ("busy",
"Busy",
diff --git a/src/editor-info-bar.c b/src/editor-info-bar.c
index de6384b..830d398 100644
--- a/src/editor-info-bar.c
+++ b/src/editor-info-bar.c
@@ -24,6 +24,7 @@
#include "editor-document-private.h"
#include "editor-info-bar-private.h"
+#include "editor-window.h"
struct _EditorInfoBar
{
@@ -39,6 +40,12 @@ struct _EditorInfoBar
GtkButton *save;
GtkLabel *title;
GtkLabel *subtitle;
+
+ /* Permission denied infobar */
+ GtkInfoBar *access_infobar;
+ GtkButton *access_subtitle;
+ GtkButton *access_title;
+ GtkButton *access_try_admin;
};
enum {
@@ -128,6 +135,30 @@ on_response_cb (EditorInfoBar *self,
gtk_info_bar_set_revealed (infobar, FALSE);
}
+static void
+on_try_admin_cb (EditorInfoBar *self,
+ GtkButton *button)
+{
+ g_assert (EDITOR_IS_INFO_BAR (self));
+ g_assert (GTK_IS_BUTTON (button));
+
+ _editor_document_use_admin (self->document);
+}
+
+static void
+on_try_again_cb (EditorInfoBar *self,
+ GtkButton *button)
+{
+ EditorWindow *window;
+
+ g_assert (EDITOR_IS_INFO_BAR (self));
+ g_assert (GTK_IS_BUTTON (button));
+
+ window = EDITOR_WINDOW (gtk_widget_get_ancestor (GTK_WIDGET (self), EDITOR_TYPE_WINDOW));
+
+ _editor_document_load_async (self->document, window, NULL, NULL, NULL);
+}
+
static void
editor_info_bar_dispose (GObject *object)
{
@@ -171,6 +202,12 @@ editor_info_bar_set_property (GObject *object,
case PROP_DOCUMENT:
if (g_set_object (&self->document, g_value_get_object (value)))
{
+ g_object_bind_property (self->document, "suggest-admin",
+ self->access_try_admin, "visible",
+ G_BINDING_SYNC_CREATE);
+ g_object_bind_property (self->document, "had-error",
+ self->access_infobar, "revealed",
+ G_BINDING_SYNC_CREATE);
g_signal_connect_object (self->document,
"notify::busy",
G_CALLBACK (on_notify_cb),
@@ -210,12 +247,18 @@ editor_info_bar_class_init (EditorInfoBarClass *klass)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/TextEditor/ui/editor-info-bar.ui");
+ gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, access_infobar);
+ gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, access_try_admin);
+ gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, access_subtitle);
+ gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, access_title);
gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, box);
gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, discard);
gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, discard_infobar);
gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, save);
gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, subtitle);
gtk_widget_class_bind_template_child (widget_class, EditorInfoBar, title);
+ gtk_widget_class_bind_template_callback (widget_class, on_try_admin_cb);
+ gtk_widget_class_bind_template_callback (widget_class, on_try_again_cb);
}
static void
diff --git a/src/editor-info-bar.ui b/src/editor-info-bar.ui
index bd54c93..6b49bc8 100644
--- a/src/editor-info-bar.ui
+++ b/src/editor-info-bar.ui
@@ -4,6 +4,48 @@
<child>
<object class="GtkBox" id="box">
<property name="orientation">vertical</property>
+ <child>
+ <object class="GtkInfoBar" id="access_infobar">
+ <property name="message-type">error</property>
+ <property name="show-close-button">false</property>
+ <property name="revealed">false</property>
+ <child>
+ <object class="GtkBox">
+ <property name="orientation">vertical</property>
+ <child>
+ <object class="GtkLabel" id="access_title">
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">Could Not Open File</property>
+ <attributes>
+ <attribute name="weight" value="bold"/>
+ </attributes>
+ </object>
+ </child>
+ <child>
+ <object class="GtkLabel" id="access_subtitle">
+ <property name="halign">start</property>
+ <property name="label" translatable="yes">You do not have permission to open the
file.</property>
+ </object>
+ </child>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="access_try_again">
+ <property name="label" translatable="yes">_Retry</property>
+ <property name="use-underline">True</property>
+ <signal name="clicked" handler="on_try_again_cb" swapped="true"/>
+ </object>
+ </child>
+ <child type="action">
+ <object class="GtkButton" id="access_try_admin">
+ <property name="label" translatable="yes">Open As _Administrator</property>
+ <property name="use-underline">True</property>
+ <property name="visible">false</property>
+ <signal name="clicked" handler="on_try_admin_cb" swapped="true"/>
+ </object>
+ </child>
+ </object>
+ </child>
<child>
<object class="GtkInfoBar" id="discard_infobar">
<property name="message-type">warning</property>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]