[gnome-builder] libide: add new tool to print file settings for a given path
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add new tool to print file settings for a given path
- Date: Mon, 23 Mar 2015 23:31:51 +0000 (UTC)
commit c1a60261c63f86bc02259785dbc0db64746c2b1a
Author: Christian Hergert <christian hergert me>
Date: Sat Feb 14 18:05:44 2015 -0800
libide: add new tool to print file settings for a given path
.gitignore | 1 +
tools/Makefile.am | 5 +
tools/ide-list-file-settings.c | 190 ++++++++++++++++++++++++++++++++++++++++
3 files changed, 196 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index 7e44bbb..65c9690 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ gnome-builder
ide-build
ide-list-devices
ide-list-diagnostics
+ide-list-file-settings
ide-list-files
intltool-extract.in
intltool-merge.in
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 64afedb..632e513 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -4,6 +4,11 @@ ide_build_SOURCES = tools/ide-build.c
ide_build_CFLAGS = $(libide_la_CFLAGS)
ide_build_LDADD = libide.la
+noinst_PROGRAMS += ide-list-file-settings
+ide_list_file_settings_SOURCES = tools/ide-list-file-settings.c
+ide_list_file_settings_CFLAGS = $(libide_la_CFLAGS)
+ide_list_file_settings_LDADD = libide.la
+
noinst_PROGRAMS += ide-list-devices
ide_list_devices_SOURCES = tools/ide-list-devices.c
ide_list_devices_CFLAGS = $(libide_la_CFLAGS)
diff --git a/tools/ide-list-file-settings.c b/tools/ide-list-file-settings.c
new file mode 100644
index 0000000..5ab3ddd
--- /dev/null
+++ b/tools/ide-list-file-settings.c
@@ -0,0 +1,190 @@
+/* ide-list-file-settings.c
+ *
+ * Copyright (C) 2015 Christian Hergert <christian hergert me>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <ide.h>
+#include <stdlib.h>
+
+static GMainLoop *gMainLoop;
+static gint gExitCode = EXIT_SUCCESS;
+static gchar **gPaths;
+static int gActive;
+
+static void
+quit (gint exit_code)
+{
+ gExitCode = exit_code;
+ g_main_loop_quit (gMainLoop);
+}
+
+static const gchar *
+newline_string (GtkSourceNewlineType nt)
+{
+ switch (nt)
+ {
+ case GTK_SOURCE_NEWLINE_TYPE_LF:
+ return "lf";
+ case GTK_SOURCE_NEWLINE_TYPE_CR:
+ return "cr";
+ case GTK_SOURCE_NEWLINE_TYPE_CR_LF:
+ return "crlf";
+ default:
+ return "unknown";
+ }
+}
+
+static const gchar *
+indent_style_string (IdeIndentStyle style)
+{
+ switch (style)
+ {
+ case IDE_INDENT_STYLE_SPACES:
+ return "space";
+ case IDE_INDENT_STYLE_TABS:
+ return "tab";
+ default:
+ return "unknown";
+ }
+}
+
+static void
+load_settings_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ IdeFileSettings *settings;
+ IdeFile *file = (IdeFile *)object;
+ GError *error = NULL;
+ gint exit_code = EXIT_SUCCESS;
+
+ settings = ide_file_load_settings_finish (file, result, &error);
+
+ if (!settings)
+ {
+ g_printerr ("%s\n", error->message);
+ g_clear_error (&error);
+ gExitCode = EXIT_FAILURE;
+ goto cleanup;
+ }
+
+ g_print ("# %s\n", ide_file_get_path (file));
+ g_print ("encoding = %s\n", ide_file_settings_get_encoding (settings) ?: "default");
+ g_print ("indent_width = %u\n", ide_file_settings_get_indent_width (settings));
+ g_print ("tab_width = %u\n", ide_file_settings_get_tab_width (settings));
+ g_print ("insert_trailing_newline = %s\n", ide_file_settings_get_insert_trailing_newline (settings) ?
"true" : "false");
+ g_print ("trim_trailing_whitespace = %s\n", ide_file_settings_get_trim_trailing_whitespace (settings) ?
"true" : "false");
+ g_print ("newline_type = %s\n", newline_string (ide_file_settings_get_newline_type (settings)));
+ g_print ("indent_sytle = %s\n", indent_style_string (ide_file_settings_get_indent_style (settings)));
+
+ g_clear_object (&settings);
+
+cleanup:
+ if (!--gActive)
+ quit (gExitCode);
+}
+
+static void
+context_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ g_autoptr(IdeContext) context = NULL;
+ g_autoptr(GError) error = NULL;
+ IdeProject *project;
+ IdeFile *file;
+ int i;
+
+ context = ide_context_new_finish (result, &error);
+
+ if (!context)
+ {
+ g_printerr ("%s\n", error->message);
+ quit (EXIT_FAILURE);
+ return;
+ }
+
+ project = ide_context_get_project (context);
+
+ if (gPaths)
+ {
+ for (i = 0; gPaths [i]; i++)
+ {
+ gActive++;
+ file = ide_project_get_file_for_path (project, gPaths [i]);
+ ide_file_load_settings_async (file,
+ NULL,
+ load_settings_cb,
+ NULL);
+ }
+ }
+
+ if (!gActive)
+ {
+ g_printerr (_("No files provided to load settings for.\n"));
+ quit (EXIT_FAILURE);
+ }
+}
+
+gint
+main (gint argc,
+ gchar *argv[])
+{
+ g_autoptr(GOptionContext) context = NULL;
+ g_autoptr(GError) error = NULL;
+ g_autoptr(GFile) project_file = NULL;
+ const gchar *project_path = ".";
+ GPtrArray *strv;
+ int i;
+
+ ide_set_program_name ("gnome-builder");
+ g_set_prgname ("ide-list-file-settings");
+
+ context = g_option_context_new (_("- List files found in project."));
+
+ if (!g_option_context_parse (context, &argc, &argv, &error))
+ {
+ g_printerr ("%s\n", error->message);
+ return EXIT_FAILURE;
+ }
+
+ gMainLoop = g_main_loop_new (NULL, FALSE);
+
+ if (argc > 1)
+ project_path = argv [1];
+ project_file = g_file_new_for_path (project_path);
+
+ strv = g_ptr_array_new ();
+ for (i = 2; i < argc; i++)
+ g_ptr_array_add (strv, g_strdup (argv [i]));
+ g_ptr_array_add (strv, NULL);
+
+ gPaths = (gchar **)g_ptr_array_free (strv, FALSE);
+
+ ide_context_new_async (project_file, NULL, context_cb, NULL);
+
+ g_main_loop_run (gMainLoop);
+ g_clear_pointer (&gMainLoop, g_main_loop_unref);
+ g_strfreev (gPaths);
+
+ return gExitCode;
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]