[gnome-builder] dnd: follow up commit for dnd



commit 6c71c3f30d1b589bfb7bceadfb2d0f2d21128957
Author: Christian Hergert <christian hergert me>
Date:   Sun Jan 18 17:50:15 2015 -0800

    dnd: follow up commit for dnd
    
     1) adjust style a bit to match other code
     2) use gb_widget_activate_action()
     3) adjust copyright to Dimitris

 src/editor/gb-editor-frame.c     |   21 ++++++++-------------
 src/editor/gb-editor-workspace.c |   31 ++++++++++++++++++++-----------
 src/editor/gb-source-view.c      |   36 +++++++++++++++++++++++-------------
 src/util/gb-dnd.c                |    5 +++--
 src/util/gb-dnd.h                |    2 +-
 5 files changed, 55 insertions(+), 40 deletions(-)
---
diff --git a/src/editor/gb-editor-frame.c b/src/editor/gb-editor-frame.c
index d67f7b1..e9244ce 100644
--- a/src/editor/gb-editor-frame.c
+++ b/src/editor/gb-editor-frame.c
@@ -1128,15 +1128,13 @@ gb_editor_frame_on_jump_to_doc (GbEditorFrame *self,
 }
 
 static void
-gb_editor_frame_on_drop_uris (GbEditorFrame *self,
+gb_editor_frame_on_drop_uris (GbEditorFrame  *self,
                               const gchar   **uri_list,
-                              GbSourceView  *source_view)
+                              GbSourceView   *source_view)
 {
-  GActionGroup *action_group;
-  GbWorkbench *workbench;
   GVariantBuilder *builder;
   GVariant *variant;
-  int i;
+  guint i;
 
   ENTRY;
 
@@ -1145,17 +1143,14 @@ gb_editor_frame_on_drop_uris (GbEditorFrame *self,
   g_return_if_fail (uri_list);
 
   builder = g_variant_builder_new (G_VARIANT_TYPE_STRING_ARRAY);
-  for (i = 0; uri_list[i] != NULL; i++)
-    {
-      g_variant_builder_add (builder, "s", uri_list[i]);
-    }
+  for (i = 0; uri_list [i]; i++)
+    g_variant_builder_add (builder, "s", uri_list[i]);
   variant = g_variant_builder_end (builder);
   g_variant_builder_unref (builder);
 
-  workbench = gb_widget_get_workbench (GTK_WIDGET (self));
-  action_group = gtk_widget_get_action_group (GTK_WIDGET (workbench),
-                                              "workspace");
-  g_action_group_activate_action (action_group, "open-uri-list", variant);
+  gb_widget_activate_action (GTK_WIDGET (self),
+                             "workspace", "open-uri-list",
+                             variant);
 
   EXIT;
 }
diff --git a/src/editor/gb-editor-workspace.c b/src/editor/gb-editor-workspace.c
index 239ed2e..f0c5e8c 100644
--- a/src/editor/gb-editor-workspace.c
+++ b/src/editor/gb-editor-workspace.c
@@ -34,11 +34,11 @@
 
 enum
 {
-       TARGET_URI_LIST = 100
+  TARGET_URI_LIST = 100
 };
 
 static const GtkTargetEntry drop_types [] = {
-       { "text/uri-list", 0, TARGET_URI_LIST}
+  { "text/uri-list", 0, TARGET_URI_LIST}
 };
 
 struct _GbEditorWorkspacePrivate
@@ -83,20 +83,26 @@ gb_editor_workspace_open (GbEditorWorkspace *workspace,
 }
 
 static void
-gb_editor_workspace_open_uri_list (GbEditorWorkspace *workspace,
-                                   const gchar        **uri_list)
+gb_editor_workspace_open_uri_list (GbEditorWorkspace  *workspace,
+                                   const gchar       **uri_list)
 {
-  int i;
   GFile *file;
+  guint i;
 
   g_return_if_fail (GB_IS_EDITOR_WORKSPACE (workspace));
   g_return_if_fail (uri_list);
 
-  for (i = 0; uri_list[i] != NULL; i++)
+  for (i = 0; uri_list [i]; i++)
     {
-      file = g_file_new_for_commandline_arg (uri_list[i]);
-      gb_editor_workspace_open (workspace, file);
-      g_clear_object (&file);
+      file = g_file_new_for_commandline_arg (uri_list [i]);
+
+      if (file)
+        {
+          gb_editor_workspace_open (workspace, file);
+          g_clear_object (&file);
+        }
+      else
+        g_warning ("Received invalid URI target");
     }
 }
 
@@ -120,11 +126,14 @@ gb_editor_workspace_drag_data_received (GtkWidget        *widget,
     {
     case TARGET_URI_LIST:
       uri_list = gb_dnd_get_uri_list (selection_data);
-      if (uri_list != NULL)
+
+      if (uri_list)
         {
-          gb_editor_workspace_open_uri_list (workspace, (const gchar **) uri_list);
+          gb_editor_workspace_open_uri_list (workspace,
+                                             (const gchar **)uri_list);
                                g_strfreev (uri_list);
         }
+
       handled = TRUE;
       break;
 
diff --git a/src/editor/gb-source-view.c b/src/editor/gb-source-view.c
index 886c59e..3a5e239 100644
--- a/src/editor/gb-source-view.c
+++ b/src/editor/gb-source-view.c
@@ -46,9 +46,8 @@
 #include "gb-source-vim.h"
 #include "gb-widget.h"
 
-enum
-{
-       TARGET_URI_LIST = 100
+enum {
+  TARGET_URI_LIST = 100
 };
 
 struct _GbSourceViewPrivate
@@ -2006,11 +2005,13 @@ gb_source_view_drag_data_received (GtkWidget        *widget,
     {
     case TARGET_URI_LIST:
       uri_list = gb_dnd_get_uri_list (selection_data);
-      if (uri_list != NULL)
+
+      if (uri_list)
         {
-          g_signal_emit (widget, gSignals[DROP_URIS], 0, uri_list);
+          g_signal_emit (widget, gSignals [DROP_URIS], 0, uri_list);
           g_strfreev (uri_list);
         }
+
       gtk_drag_finish (context, TRUE, FALSE, timestamp);
       break;
 
@@ -2375,7 +2376,7 @@ static void
 gb_source_view_init (GbSourceView *view)
 {
   GtkSourceCompletion *completion;
-  GtkTargetList *tl;
+  GtkTargetList *target_list;
 
   view->priv = gb_source_view_get_instance_private (view);
 
@@ -2388,16 +2389,21 @@ gb_source_view_init (GbSourceView *view)
                     G_CALLBACK (gb_source_view_notify_buffer),
                     NULL);
 
+  /*
+   * Add various completion providers.
+   */
   view->priv->snippets_provider =
     g_object_new (GB_TYPE_SOURCE_SNIPPET_COMPLETION_PROVIDER,
                   "source-view", view,
                   NULL);
-
   view->priv->words_provider =
     g_object_new (GTK_SOURCE_TYPE_COMPLETION_WORDS,
                   "minimum-word-size", 4,
                   NULL);
 
+  /*
+   * Setup VIM integration.
+   */
   view->priv->vim = g_object_new (GB_TYPE_SOURCE_VIM,
                                   "enabled", FALSE,
                                   "text-view", view,
@@ -2413,13 +2419,17 @@ gb_source_view_init (GbSourceView *view)
                            view,
                            G_CONNECT_SWAPPED);
 
+  /*
+   * We block completion when we are not focused so that two SourceViews
+   * viewing the same GtkTextBuffer do not both show completion windows.
+   */
   completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (view));
   gtk_source_completion_block_interactive (completion);
 
-  /* Drag and drop support */
-  tl = gtk_drag_dest_get_target_list (GTK_WIDGET (view));
-  if (tl != NULL)
-    {
-      gtk_target_list_add_uri_targets (tl, TARGET_URI_LIST);
-    }
+  /*
+   * Drag and drop support
+   */
+  target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (view));
+  if (target_list)
+    gtk_target_list_add_uri_targets (target_list, TARGET_URI_LIST);
 }
diff --git a/src/util/gb-dnd.c b/src/util/gb-dnd.c
index 0e0820b..b907a7d 100644
--- a/src/util/gb-dnd.c
+++ b/src/util/gb-dnd.c
@@ -1,6 +1,6 @@
 /* gb-dnd.c
  *
- * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ * Copyright (C) 2015 Dimitris Zenios <dimitris zenios gmail 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
@@ -36,6 +36,7 @@ gb_dnd_get_uri_list (GtkSelectionData *selection_data)
   g_return_val_if_fail (selection_data, NULL);
   g_return_val_if_fail (gtk_selection_data_get_length (selection_data) > 0, NULL);
 
-  data = (const gchar*) gtk_selection_data_get_data (selection_data);
+  data = (const gchar *)gtk_selection_data_get_data (selection_data);
+
   return g_uri_list_extract_uris (data);
 }
diff --git a/src/util/gb-dnd.h b/src/util/gb-dnd.h
index 3e440fd..043cf1e 100644
--- a/src/util/gb-dnd.h
+++ b/src/util/gb-dnd.h
@@ -1,6 +1,6 @@
 /* gb-dnd.h
  *
- * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ * Copyright (C) 2015 Dimitris Zenios <dimitris zenios gmail 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


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