SF.net SVN: geany-plugins:[1265] trunk/geanygendoc/src

colombanw at users.sourceforge.net colombanw at xxxxx
Wed Apr 21 13:22:58 UTC 2010


Revision: 1265
          http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1265&view=rev
Author:   colombanw
Date:     2010-04-21 13:22:58 +0000 (Wed, 21 Apr 2010)

Log Message:
-----------
GeanyGenDoc: Add ability to document a whole file at once

Modified Paths:
--------------
    trunk/geanygendoc/src/ggd-plugin.c
    trunk/geanygendoc/src/ggd.c
    trunk/geanygendoc/src/ggd.h

Modified: trunk/geanygendoc/src/ggd-plugin.c
===================================================================
--- trunk/geanygendoc/src/ggd-plugin.c	2010-04-21 13:22:25 UTC (rev 1264)
+++ trunk/geanygendoc/src/ggd-plugin.c	2010-04-21 13:22:58 UTC (rev 1265)
@@ -34,9 +34,6 @@
 
 
 /*
- * TODO:
- *  * add option to generate comments for the whole file
- * 
  * Questions:
  *  * how to update tag list? (tm_source_file_buffer_update() is not found in
  *    symbols table)
@@ -121,6 +118,20 @@
   }
 }
 
+/* tries to insert comments for all the document */
+static void
+insert_all_comments (void)
+{
+  GeanyDocument *doc;
+  
+  doc = document_get_current ();
+  if (DOC_VALID (doc)) {
+    /* try to ensure tags corresponds to the actual state of the file */
+    refresh_tag_list (doc->tm_file, doc->editor->sci, doc);
+    ggd_insert_all_comments (doc, OPT_doctype);
+  }
+}
+
 static gboolean
 load_configuration (void)
 {
@@ -189,7 +200,7 @@
 }
 
 static void
-keybinding_activated_handler (guint key_id)
+insert_comment_keybinding_handler (guint key_id)
 {
   (void)key_id;
   
@@ -219,7 +230,7 @@
   /* make item document-presence sensitive */
   ui_add_document_sensitive (pdata->edit_menu_item);
   /* and attach a keybinding */
-  keybindings_set_item (plugin_key_group, KB_INSERT, keybinding_activated_handler,
+  keybindings_set_item (plugin_key_group, KB_INSERT, insert_comment_keybinding_handler,
                         GDK_d, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
                         "instert_doc", _("Insert documentation comment"),
                         pdata->edit_menu_item);
@@ -282,6 +293,14 @@
   
   /* build submenu */
   menu = gtk_menu_new ();
+  /* build "document all" item */
+  item = gtk_menu_item_new_with_mnemonic (_("_Document all"));
+  g_signal_connect (item, "activate",
+                    G_CALLBACK (insert_all_comments), NULL);
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+  /* separator */
+  item = gtk_separator_menu_item_new ();
+  gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
   /* build "reload" item */
   item = gtk_image_menu_item_new_with_mnemonic (_("_Reload configuration files"));
   gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item),

Modified: trunk/geanygendoc/src/ggd.c
===================================================================
--- trunk/geanygendoc/src/ggd.c	2010-04-21 13:22:25 UTC (rev 1264)
+++ trunk/geanygendoc/src/ggd.c	2010-04-21 13:22:58 UTC (rev 1265)
@@ -28,6 +28,7 @@
 
 #include "ggd-file-type.h"
 #include "ggd-file-type-manager.h"
+#include "ggd-utils.h"
 #include "ggd-plugin.h"
 
 
@@ -395,3 +396,65 @@
   
   return success;
 }
+
+/**
+ * ggd_insert_all_comments:
+ * @doc: A #GeanyDocument for which insert the comments
+ * @doc_type: Documentation type identifier
+ * 
+ * Tries to insert a comment for each symbol of a document.
+ * 
+ * Returns: %TRUE on full success, %FALSE otherwise.
+ */
+gboolean
+ggd_insert_all_comments (GeanyDocument *doc,
+                         const gchar   *doc_type)
+{
+  gboolean      success = FALSE;
+  GgdFileType  *ft;
+  
+  g_return_val_if_fail (DOC_VALID (doc), FALSE);
+  
+  ft = ggd_file_type_manager_get_file_type (doc->file_type->id);
+  if (ft) {
+    GgdDocType *doctype;
+    
+    doctype = ggd_file_type_get_doc (ft, doc_type);
+    if (! doctype) {
+      msgwin_status_add (_("No documentation type \"%s\" for language \"%s\""),
+                         doc_type, doc->file_type->name);
+    } else {
+      GPtrArray        *tag_array;
+      ScintillaObject  *sci = doc->editor->sci;
+      const TMTag      *tag;
+      guint             i;
+      GHashTable       *tag_done_table; /* keeps the list of documented tags.
+                                         * Useful since documenting a tag might
+                                         * actually document another one */
+      
+      success = TRUE;
+      tag_array = doc->tm_file->tags_array;
+      tag_done_table = g_hash_table_new (NULL, NULL);
+      /* sort the tags to be sure to insert by the end of the document, then we
+       * don't modify the element's position of tags we'll work on */
+      ggd_tag_sort_by_line (tag_array, GGD_SORT_DESC);
+      sci_start_undo_action (sci);
+      GGD_PTR_ARRAY_FOR (tag_array, i, tag) {
+        GgdDocSetting  *setting;
+        
+        setting = get_setting_from_tag (doctype, tag_array, tag, &tag);
+        if (! setting) {
+          success = FALSE;
+          break;
+        } else if (! g_hash_table_lookup (tag_done_table, tag)) {
+          success = do_insert_comment (sci, tag_array, tag, ft, setting);
+          g_hash_table_insert (tag_done_table, (gpointer)tag, (gpointer)tag);
+        }
+      }
+      sci_end_undo_action (sci);
+      g_hash_table_destroy (tag_done_table);
+    }
+  }
+  
+  return success;
+}

Modified: trunk/geanygendoc/src/ggd.h
===================================================================
--- trunk/geanygendoc/src/ggd.h	2010-04-21 13:22:25 UTC (rev 1264)
+++ trunk/geanygendoc/src/ggd.h	2010-04-21 13:22:58 UTC (rev 1265)
@@ -29,6 +29,8 @@
 gboolean        ggd_insert_comment            (GeanyDocument *doc,
                                                gint           line,
                                                const gchar   *doc_type);
+gboolean        ggd_insert_all_comments       (GeanyDocument *doc,
+                                               const gchar   *doc_type);
 
 
 G_END_DECLS


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Plugins-Commits mailing list