[tepl] io-error-info-bars: add file_already_open_warning_new()



commit 629473231e7cafef45417049746be9cc691f9298
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Tue Mar 24 06:46:28 2020 +0100

    io-error-info-bars: add file_already_open_warning_new()
    
    This will be used in gedit.

 docs/reference/tepl-4.0-sections.txt |  5 +++
 docs/reference/tepl-docs.xml.in      |  1 +
 po/POTFILES.in                       |  1 +
 tepl/Makefile.am                     |  2 +
 tepl/tepl-io-error-info-bars.c       | 75 ++++++++++++++++++++++++++++++++++++
 tepl/tepl-io-error-info-bars.h       | 32 +++++++++++++++
 tepl/tepl.h                          |  3 +-
 7 files changed, 118 insertions(+), 1 deletion(-)
---
diff --git a/docs/reference/tepl-4.0-sections.txt b/docs/reference/tepl-4.0-sections.txt
index 01f1704..aca80a4 100644
--- a/docs/reference/tepl-4.0-sections.txt
+++ b/docs/reference/tepl-4.0-sections.txt
@@ -289,6 +289,11 @@ TEPL_TYPE_INFO_BAR
 TeplInfoBarClass
 </SECTION>
 
+<SECTION>
+<FILE>io-error-info-bars</FILE>
+tepl_io_error_info_bar_file_already_open_warning_new
+</SECTION>
+
 <SECTION>
 <FILE>iter</FILE>
 tepl_iter_get_line_indentation
diff --git a/docs/reference/tepl-docs.xml.in b/docs/reference/tepl-docs.xml.in
index 504ab4c..ab61ffe 100644
--- a/docs/reference/tepl-docs.xml.in
+++ b/docs/reference/tepl-docs.xml.in
@@ -48,6 +48,7 @@
       <xi:include href="xml/file-saver.xml"/>
       <xi:include href="xml/file-metadata.xml"/>
       <xi:include href="xml/metadata-manager.xml"/>
+      <xi:include href="xml/io-error-info-bars.xml"/>
     </chapter>
 
     <chapter id="code-folding">
diff --git a/po/POTFILES.in b/po/POTFILES.in
index e1f5b2a..5821b6c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -16,6 +16,7 @@ tepl/tepl-file-metadata.c
 tepl/tepl-file-saver.c
 tepl/tepl-info-bar.c
 tepl/tepl-init.c
+tepl/tepl-io-error-info-bars.c
 tepl/tepl-iter.c
 tepl/tepl-menu-shell.c
 tepl/tepl-metadata-manager.c
diff --git a/tepl/Makefile.am b/tepl/Makefile.am
index 5636b25..c40b7b1 100644
--- a/tepl/Makefile.am
+++ b/tepl/Makefile.am
@@ -28,6 +28,7 @@ tepl_public_headers =                         \
        tepl-gutter-renderer-folds.h            \
        tepl-info-bar.h                         \
        tepl-init.h                             \
+       tepl-io-error-info-bars.h               \
        tepl-iter.h                             \
        tepl-menu-shell.h                       \
        tepl-metadata-manager.h                 \
@@ -54,6 +55,7 @@ tepl_public_c_files =                         \
        tepl-gutter-renderer-folds.c            \
        tepl-info-bar.c                         \
        tepl-init.c                             \
+       tepl-io-error-info-bars.c               \
        tepl-iter.c                             \
        tepl-menu-shell.c                       \
        tepl-metadata-manager.c                 \
diff --git a/tepl/tepl-io-error-info-bars.c b/tepl/tepl-io-error-info-bars.c
new file mode 100644
index 0000000..9bc81ab
--- /dev/null
+++ b/tepl/tepl-io-error-info-bars.c
@@ -0,0 +1,75 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2005 - Paolo Maggi
+ * Copyright 2020 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+#include "tepl-io-error-info-bars.h"
+#include <glib/gi18n-lib.h>
+
+/**
+ * SECTION:io-error-info-bars
+ * @Short_description: Verbose error reporting for file I/O operations
+ * @Title: IO error info bars
+ *
+ * Verbose error reporting for file I/O operations.
+ */
+
+/**
+ * tepl_io_error_info_bar_file_already_open_warning_new:
+ * @location: the #GFile already open in another window.
+ *
+ * Creates a warning about @location being already open in another window,
+ * offering two possible actions:
+ * - Edit anyway: %GTK_RESPONSE_YES.
+ * - Don't edit: %GTK_RESPONSE_CANCEL.
+ *
+ * Returns: (transfer floating): the newly created #TeplInfoBar.
+ * Since: 4.6
+ */
+TeplInfoBar *
+tepl_io_error_info_bar_file_already_open_warning_new (GFile *location)
+{
+       TeplInfoBar *info_bar;
+       gchar *uri;
+       gchar *primary_msg;
+
+       g_return_val_if_fail (G_IS_FILE (location), NULL);
+
+       info_bar = tepl_info_bar_new ();
+
+       gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                                _("_Edit Anyway"),
+                                GTK_RESPONSE_YES);
+
+       gtk_info_bar_add_button (GTK_INFO_BAR (info_bar),
+                                _("_Don’t Edit"),
+                                GTK_RESPONSE_CANCEL);
+
+       gtk_info_bar_set_message_type (GTK_INFO_BAR (info_bar), GTK_MESSAGE_WARNING);
+
+       uri = g_file_get_parse_name (location);
+       primary_msg = g_strdup_printf (_("This file “%s” is already open in another window."), uri);
+       tepl_info_bar_add_primary_message (info_bar, primary_msg);
+       g_free (uri);
+       g_free (primary_msg);
+
+       tepl_info_bar_add_secondary_message (info_bar, _("Do you want to edit it anyway?"));
+
+       return info_bar;
+}
diff --git a/tepl/tepl-io-error-info-bars.h b/tepl/tepl-io-error-info-bars.h
new file mode 100644
index 0000000..19772ba
--- /dev/null
+++ b/tepl/tepl-io-error-info-bars.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of Tepl, a text editor library.
+ *
+ * Copyright 2020 - Sébastien Wilmet <swilmet gnome org>
+ *
+ * Tepl is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the
+ * Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * Tepl is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef TEPL_IO_ERROR_INFO_BARS_H
+#define TEPL_IO_ERROR_INFO_BARS_H
+
+#include <gio/gio.h>
+#include <tepl/tepl-info-bar.h>
+
+G_BEGIN_DECLS
+
+TeplInfoBar *  tepl_io_error_info_bar_file_already_open_warning_new    (GFile *location);
+
+G_END_DECLS
+
+#endif /* TEPL_IO_ERROR_INFO_BARS_H */
diff --git a/tepl/tepl.h b/tepl/tepl.h
index 6bf1f16..ff48365 100644
--- a/tepl/tepl.h
+++ b/tepl/tepl.h
@@ -1,7 +1,7 @@
 /*
  * This file is part of Tepl, a text editor library.
  *
- * Copyright 2016, 2017 - Sébastien Wilmet <swilmet gnome org>
+ * Copyright 2016-2020 - Sébastien Wilmet <swilmet gnome org>
  *
  * Tepl is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the
@@ -41,6 +41,7 @@
 #include <tepl/tepl-gutter-renderer-folds.h>
 #include <tepl/tepl-info-bar.h>
 #include <tepl/tepl-init.h>
+#include <tepl/tepl-io-error-info-bars.h>
 #include <tepl/tepl-iter.h>
 #include <tepl/tepl-menu-shell.h>
 #include <tepl/tepl-metadata-manager.h>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]