[gnome-builder] code-index: start on code-index command line option



commit 9612d01062bdf2d7b20ddae05429820d86f765dd
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 30 11:48:59 2019 -0800

    code-index: start on code-index command line option

 src/plugins/code-index/code-index-plugin.c         |  6 +-
 src/plugins/code-index/code-index.plugin           |  1 +
 .../code-index/gbp-code-index-application-addin.c  | 95 ++++++++++++++++++++++
 .../code-index/gbp-code-index-application-addin.h  | 31 +++++++
 src/plugins/code-index/meson.build                 |  3 +-
 5 files changed, 134 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/code-index/code-index-plugin.c b/src/plugins/code-index/code-index-plugin.c
index 65029523e..c1538c57d 100644
--- a/src/plugins/code-index/code-index-plugin.c
+++ b/src/plugins/code-index/code-index-plugin.c
@@ -26,13 +26,17 @@
 #include <libide-gui.h>
 #include <libide-search.h>
 
+#include "gbp-code-index-application-addin.h"
+#include "gbp-code-index-workbench-addin.h"
 #include "ide-code-index-search-provider.h"
 #include "ide-code-index-symbol-resolver.h"
-#include "gbp-code-index-workbench-addin.h"
 
 _IDE_EXTERN void
 _ide_code_index_register_types (PeasObjectModule *module)
 {
+  peas_object_module_register_extension_type (module,
+                                              IDE_TYPE_APPLICATION_ADDIN,
+                                              GBP_TYPE_CODE_INDEX_APPLICATION_ADDIN);
   peas_object_module_register_extension_type (module,
                                               IDE_TYPE_SEARCH_PROVIDER,
                                               IDE_TYPE_CODE_INDEX_SEARCH_PROVIDER);
diff --git a/src/plugins/code-index/code-index.plugin b/src/plugins/code-index/code-index.plugin
index fbb2bd0bb..75230a8bf 100644
--- a/src/plugins/code-index/code-index.plugin
+++ b/src/plugins/code-index/code-index.plugin
@@ -6,5 +6,6 @@ Description=Manages Code Index and does Global Search and Jump to Definition usi
 Embedded=_ide_code_index_register_types
 Module=code-index
 Name=Code Index
+X-At-Startup=true
 X-Symbol-Resolver-Languages-Priority=200
 X-Symbol-Resolver-Languages=c,chdr,cpp,cpphdr
diff --git a/src/plugins/code-index/gbp-code-index-application-addin.c 
b/src/plugins/code-index/gbp-code-index-application-addin.c
new file mode 100644
index 000000000..e90af9286
--- /dev/null
+++ b/src/plugins/code-index/gbp-code-index-application-addin.c
@@ -0,0 +1,95 @@
+/* gbp-code-index-application-addin.c
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "gbp-code-index-application-addin"
+
+#include "config.h"
+
+#include <glib/gi18n.h>
+#include <libide-code.h>
+#include <libide-foundry.h>
+#include <libide-gui.h>
+
+#include "gbp-code-index-application-addin.h"
+
+struct _GbpCodeIndexApplicationAddin
+{
+  GObject parent_instance;
+};
+
+static void
+gbp_code_index_application_addin_add_option_entries (IdeApplicationAddin *addin,
+                                                     IdeApplication      *application)
+{
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODE_INDEX_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+
+  g_application_add_main_option (G_APPLICATION (application),
+                                 "index",
+                                 'i',
+                                 G_OPTION_FLAG_IN_MAIN,
+                                 G_OPTION_ARG_FILENAME,
+                                 _("Create or update code-index for project file"),
+                                 _("PROJECT_FILE"));
+}
+
+static void
+gbp_code_index_application_addin_handle_command_line (IdeApplicationAddin     *addin,
+                                                      IdeApplication          *application,
+                                                      GApplicationCommandLine *cmdline)
+{
+  g_autofree gchar *project_path = NULL;
+  GVariantDict *options;
+
+  g_assert (IDE_IS_MAIN_THREAD ());
+  g_assert (GBP_IS_CODE_INDEX_APPLICATION_ADDIN (addin));
+  g_assert (IDE_IS_APPLICATION (application));
+  g_assert (G_IS_APPLICATION_COMMAND_LINE (cmdline));
+
+  if (!(options = g_application_command_line_get_options_dict (cmdline)) ||
+      !g_variant_dict_contains (options, "index") ||
+      !g_variant_dict_lookup (options, "index", "^ay", &project_path))
+    return;
+
+  ide_application_set_command_line_handled (application, cmdline, TRUE);
+
+  g_print ("Re-index %s\n", project_path);
+}
+
+static void
+application_addin_iface_init (IdeApplicationAddinInterface *iface)
+{
+  iface->add_option_entries = gbp_code_index_application_addin_add_option_entries;
+  iface->handle_command_line = gbp_code_index_application_addin_handle_command_line;
+}
+
+G_DEFINE_TYPE_WITH_CODE (GbpCodeIndexApplicationAddin, gbp_code_index_application_addin, G_TYPE_OBJECT,
+                         G_IMPLEMENT_INTERFACE (IDE_TYPE_APPLICATION_ADDIN, application_addin_iface_init))
+
+static void
+gbp_code_index_application_addin_class_init (GbpCodeIndexApplicationAddinClass *klass)
+{
+}
+
+static void
+gbp_code_index_application_addin_init (GbpCodeIndexApplicationAddin *self)
+{
+}
diff --git a/src/plugins/code-index/gbp-code-index-application-addin.h 
b/src/plugins/code-index/gbp-code-index-application-addin.h
new file mode 100644
index 000000000..b562c13af
--- /dev/null
+++ b/src/plugins/code-index/gbp-code-index-application-addin.h
@@ -0,0 +1,31 @@
+/* gbp-code-index-application-addin.h
+ *
+ * Copyright 2019 Christian Hergert <chergert redhat com>
+ *
+ * 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#pragma once
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#define GBP_TYPE_CODE_INDEX_APPLICATION_ADDIN (gbp_code_index_application_addin_get_type())
+
+G_DECLARE_FINAL_TYPE (GbpCodeIndexApplicationAddin, gbp_code_index_application_addin, GBP, 
CODE_INDEX_APPLICATION_ADDIN, GObject)
+
+G_END_DECLS
diff --git a/src/plugins/code-index/meson.build b/src/plugins/code-index/meson.build
index e1faf9015..b24c8f2d2 100644
--- a/src/plugins/code-index/meson.build
+++ b/src/plugins/code-index/meson.build
@@ -2,11 +2,12 @@ if get_option('plugin_code_index')
 
 plugins_sources += files([
   'code-index-plugin.c',
+  'gbp-code-index-application-addin.c',
+  'gbp-code-index-workbench-addin.c',
   'ide-code-index-builder.c',
   'ide-code-index-index.c',
   'ide-code-index-search-provider.c',
   'ide-code-index-search-result.c',
-  'gbp-code-index-workbench-addin.c',
   'ide-code-index-symbol-resolver.c',
 ])
 


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