[tomboy: 1/2] Added feature to work on search results in addition to just one note



commit 5927d38b863ec1c080b3a3f053020d9ebd905e0b
Author: Alex Tereschenko <frozenblue zoho com>
Date:   Sun Mar 25 12:56:03 2012 +0200

    Added feature to work on search results in addition to just one note
    
    Rebased on top of the current version & refactored the plugin - now it consists of NoteAddin and
    NoteApplicationAddin + utility class. Incorporated changes based on the previous discussion
    in bgo #384034.
    
    Signed-off-by: Jared Jennings <jjennings src gnome org>

 Tomboy/Addins/RemoveBrokenLinks/Makefile.am        |    4 +-
 .../RemoveBrokenLinks/RemoveBrokenLinks.addin.xml  |    9 ++-
 .../RemoveBrokenLinks/RemoveBrokenLinks.csproj     |    8 ++-
 .../RemoveBrokenLinks/RemoveBrokenLinksAddin.cs    |   57 ++------------
 .../RemoveBrokenLinksApplicationAddin.cs           |   82 +++++++++++++++++++
 .../RemoveBrokenLinks/RemoveBrokenLinksUtils.cs    |   83 ++++++++++++++++++++
 Tomboy/RecentChanges.cs                            |   18 ++++
 7 files changed, 205 insertions(+), 56 deletions(-)
---
diff --git a/Tomboy/Addins/RemoveBrokenLinks/Makefile.am b/Tomboy/Addins/RemoveBrokenLinks/Makefile.am
index 6256d35..66e482b 100644
--- a/Tomboy/Addins/RemoveBrokenLinks/Makefile.am
+++ b/Tomboy/Addins/RemoveBrokenLinks/Makefile.am
@@ -14,7 +14,9 @@ ASSEMBLIES = 					\
 ADDIN_NAME = RemoveBrokenLinks
 TARGET = $(top_builddir)/bin/addins/$(ADDIN_NAME).dll
 CSFILES = \
-	$(srcdir)/RemoveBrokenLinksAddin.cs
+	$(srcdir)/RemoveBrokenLinksAddin.cs	\
+	$(srcdir)/RemoveBrokenLinksApplicationAddin.cs	\
+	$(srcdir)/RemoveBrokenLinksUtils.cs
 	
 RESOURCES = \
 	-resource:$(srcdir)/$(ADDIN_NAME).addin.xml
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml
index e465523..660f453 100644
--- a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml
@@ -2,10 +2,10 @@
 	namespace="Tomboy"
 	name="RemoveBrokenLinks"
 	author="Alex Tereschenko"
-	description="Adds ability to remove broken links."
+	description="Adds an ability to remove broken links."
 	category="Tools"
 	defaultEnabled="false"
-	version="0.1">
+	version="0.2">
 
  	<Runtime>
  		<Import assembly="RemoveBrokenLinks.dll" />
@@ -18,4 +18,9 @@
 	<Extension path="/Tomboy/NoteAddins">
 		<NoteAddin type="Tomboy.RemoveBrokenLinks.RemoveBrokenLinksAddin" />
 	</Extension>
+
+	<Extension path="/Tomboy/ApplicationAddins">
+		<ApplicationAddin type="Tomboy.RemoveBrokenLinks.RemoveBrokenLinksApplicationAddin" />
+	</Extension>
+
 </Addin>
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj
index f6de482..5848236 100644
--- a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj
@@ -1,9 +1,9 @@
-ï<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003";>
   <PropertyGroup>
     <ProjectGuid>{AD6C9F12-3F95-497C-AF7E-629F787A097E}</ProjectGuid>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
     <OutputType>Library</OutputType>
     <RootNamespace>RemoveBrokenLinks</RootNamespace>
     <AssemblyName>RemoveBrokenLinks</AssemblyName>
@@ -18,6 +18,8 @@
     </FileUpgradeFlags>
     <OldToolsVersion>3.5</OldToolsVersion>
     <UpgradeBackupLocation />
+    <ProductVersion>10.0.0</ProductVersion>
+    <SchemaVersion>2.0</SchemaVersion>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Platform)' == 'x86' ">
     <PlatformTarget>x86</PlatformTarget>
@@ -72,6 +74,8 @@
     <Compile Include="RemoveBrokenLinksAddin.cs" />
     <EmbeddedResource Include="RemoveBrokenLinks.addin.xml" />
     <None Include="Makefile.am" />
+    <Compile Include="RemoveBrokenLinksApplicationAddin.cs" />
+    <Compile Include="RemoveBrokenLinksUtils.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\..\..\Tomboy.csproj">
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs
index 0103946..ad5a760 100644
--- a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs
@@ -1,10 +1,9 @@
-ï// Plugin for removing broken links.
-// (c) 2009 Alex Tereschenko <frozenblue zoho com>
+ï// Plugin for removing broken links (NoteAddin).
+// (c) 2010 Alex Tereschenko <frozenblue zoho com>
 // LGPL 2.1 or later.
 
 
 using System;
-using System.Text.RegularExpressions;
 using Gtk;
 using Mono.Unix;
 using Tomboy;
@@ -42,56 +41,12 @@ namespace Tomboy.RemoveBrokenLinks
 
 		void OnMenuItemActivated (object sender, EventArgs args)
 		{
+			RemoveBrokenLinksUtils utils = new RemoveBrokenLinksUtils ();
 			
-			NoteTag broken_link_tag = Note.TagTable.BrokenLinkTag;
-			Gtk.TextIter note_start, note_end;
+			utils.RemoveBrokenLinkTag (Note);
+			if ((bool) Preferences.Get (Preferences.ENABLE_WIKIWORDS))
+				utils.HighlightWikiWords (Note);
 			
-			// We get the whole note as a range
-			// and then just remove the "broken link" tag from it
-			Note.Buffer.GetBounds (out note_start, out note_end);
-			
-			// Sweep 'em & recreate WikiWord broken links (depending on Preferences),
-			Buffer.RemoveTag (broken_link_tag,note_start,note_end);
-		
-			// HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
-			// It turns WikiWords back into broken links after sweeping all broken links,
-			// but only in case WikiWords are enabled.
-			// Most probably there's more elegant way of doing this.
-			
-			if ((bool) Preferences.Get (Preferences.ENABLE_WIKIWORDS)) {
-			
-				const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";
-
-				Regex regex = new Regex (WIKIWORD_REGEX, RegexOptions.Compiled);
-			
-				NoteBuffer.GetBlockExtents (ref note_start,
-				                            ref note_end,
-				                            80 /* max wiki name */,
-				                            broken_link_tag);
-
-				//Buffer.RemoveTag (broken_link_tag, start, end);
-	
-				for (Match match = regex.Match (note_start.GetText (note_end));
-				                match.Success;
-				                match = match.NextMatch ()) {
-					System.Text.RegularExpressions.Group group = match.Groups [1];
-	
-					Logger.Debug ("Highlighting back wikiword: '{0}' at offset {1}",
-					              group,
-					              group.Index);
-	
-					Gtk.TextIter start_cpy = note_start;
-					start_cpy.ForwardChars (group.Index);
-	
-					note_end = start_cpy;
-					note_end.ForwardChars (group.Length);
-	
-					if (Manager.Find (group.ToString ()) == null) {
-						Buffer.ApplyTag (broken_link_tag, start_cpy, note_end);
-					}
-				}
-			}
-			/// End of hack 
 		}
 		                                      
 	}
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksApplicationAddin.cs b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksApplicationAddin.cs
new file mode 100644
index 0000000..1320c7e
--- /dev/null
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksApplicationAddin.cs
@@ -0,0 +1,82 @@
+ï// Plugin for removing broken links (ApplicationAddin).
+// (c) 2010 Alex Tereschenko <frozenblue zoho com>
+// LGPL 2.1 or later.
+
+using System;
+using Gtk;
+using Mono.Unix;
+using Tomboy;
+
+namespace Tomboy.RemoveBrokenLinks
+{
+	/// <summary>
+	/// Class for operating on all notes/search results for RemoveBrokenLinks addin
+	/// </summary>
+	public class RemoveBrokenLinksApplicationAddin : ApplicationAddin
+	{
+		bool initialized = false;
+		static Gtk.ActionGroup action_group;
+		static uint rblUi = 0;
+				
+		public static void OnRemoveBrokenLinksActivated ()
+		{
+			NoteManager def_note_manager;
+			NoteRecentChanges search;
+			RemoveBrokenLinksUtils utils = new RemoveBrokenLinksUtils ();
+			def_note_manager = Tomboy.DefaultNoteManager;
+			search = NoteRecentChanges.GetInstance (def_note_manager);
+
+			foreach (Note note in search.GetFilteredNotes ()) {
+				utils.RemoveBrokenLinkTag (note);
+				if ((bool) Preferences.Get (Preferences.ENABLE_WIKIWORDS))
+					utils.HighlightWikiWords (note);
+			}
+		}
+
+		public override void Initialize ()
+		{
+			
+			action_group = new Gtk.ActionGroup ("RemoveBrokenLinks");
+			action_group.Add (new Gtk.ActionEntry [] {
+				new Gtk.ActionEntry ("ToolsMenuAction", null,
+				Catalog.GetString ("_Tools"), null, null, null),
+				new Gtk.ActionEntry ("RemoveBrokenLinksAction", null,
+				Catalog.GetString ("_Remove broken links"), null, null,
+				delegate {
+					OnRemoveBrokenLinksActivated ();
+				})
+			});
+					
+			rblUi = Tomboy.ActionManager.UI.AddUiFromString (@"
+			                <ui>
+			                <menubar name='MainWindowMenubar'>
+			                <placeholder name='MainWindowMenuPlaceholder'>
+			                <menu name='ToolsMenu' action='ToolsMenuAction'>
+			                <menuitem name='RemoveBrokenLinks' action='RemoveBrokenLinksAction' />
+			                </menu>
+			                </placeholder>
+			                </menubar>
+			                </ui>
+			                ");
+			
+			Tomboy.ActionManager.UI.InsertActionGroup (action_group, 0);			
+			
+			initialized = true;
+		}
+
+		public override void Shutdown ()
+		{
+			Tomboy.ActionManager.UI.RemoveActionGroup (action_group);
+			Tomboy.ActionManager.UI.RemoveUi (rblUi);
+			initialized = false;
+		}
+
+		public override bool Initialized
+		{
+			get {
+				return initialized;
+			}
+		}		
+		
+	}
+}
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksUtils.cs b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksUtils.cs
new file mode 100644
index 0000000..73383cf
--- /dev/null
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksUtils.cs
@@ -0,0 +1,83 @@
+ï// Plugin for removing broken links (util functions).
+// (c) 2010 Alex Tereschenko <frozenblue zoho com>
+// LGPL 2.1 or later.
+
+
+using System;
+using System.Text.RegularExpressions;
+using Gtk;
+using Mono.Unix;
+using Tomboy;
+
+
+namespace Tomboy.RemoveBrokenLinks
+{
+	/// <summary>
+	/// Dummy class containing util functions used by App and Note RemoveBrokenLinks addins
+	/// </summary>
+	public class RemoveBrokenLinksUtils
+	{
+		
+		public void RemoveBrokenLinkTag (Note note)
+		{
+			
+			NoteTag broken_link_tag = note.TagTable.BrokenLinkTag;
+			Gtk.TextIter note_start, note_end;
+			
+			// We get the whole note as a range
+			// and then just remove the "broken link" tag from it
+			note.Buffer.GetBounds (out note_start, out note_end);
+			
+			// Sweep 'em
+			note.Buffer.RemoveTag (broken_link_tag,note_start,note_end);
+
+			Logger.Debug ("Removed broken links from a note: " + note.Title);
+		}
+		
+		public void HighlightWikiWords (Note note)
+		{
+			NoteTag broken_link_tag = note.TagTable.BrokenLinkTag;
+			Gtk.TextIter note_start, note_end;
+			
+			note.Buffer.GetBounds (out note_start, out note_end);
+			
+			// HACK: The below is copied from Watchers.cs->ApplyWikiwordToBlock()
+			// It turns WikiWords back into broken links after sweeping all broken links,
+			// but only in case WikiWords are enabled.
+			// Most probably there's more elegant way of doing this.
+			
+			const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";
+
+			Regex regex = new Regex (WIKIWORD_REGEX, RegexOptions.Compiled);
+			
+			NoteBuffer.GetBlockExtents (ref note_start,
+			                            ref note_end,
+			                            80 /* max wiki name */,
+			                            broken_link_tag);
+			
+			for (Match match = regex.Match (note_start.GetText (note_end));
+			     match.Success;
+			     match = match.NextMatch ()) {
+				System.Text.RegularExpressions.Group group = match.Groups [1];
+				
+				Logger.Debug ("Highlighting back wikiword: '{0}' at offset {1}",
+				              group,
+				              group.Index);
+				
+				Gtk.TextIter start_cpy = note_start;
+				start_cpy.ForwardChars (group.Index);
+				
+				note_end = start_cpy;
+				note_end.ForwardChars (group.Length);
+				
+				if (note.Manager.Find (group.ToString ()) == null) {
+					note.Buffer.ApplyTag (broken_link_tag, start_cpy, note_end);
+				}
+			}
+			/// End of hack
+		}
+		
+		
+	}
+		
+}
diff --git a/Tomboy/RecentChanges.cs b/Tomboy/RecentChanges.cs
index 8d90a06..d40b2a4 100644
--- a/Tomboy/RecentChanges.cs
+++ b/Tomboy/RecentChanges.cs
@@ -1604,5 +1604,23 @@ namespace Tomboy
 		{
 			SavePosition ();
 		}
+
+		// This one presents a List of notes that Search has found
+		public List<Note> GetFilteredNotes ()
+		{
+			Gtk.TreeIter iter;
+			List<Note> filtered_notes = new List<Note> ();
+
+			if (store_sort.IterChildren (out iter) == false)
+				return filtered_notes; /* if nothing was found we return empty list */
+
+			// Getting filtered out notes (found by search) to our list
+			// 3 is a column where note itself is stored
+			do {
+				filtered_notes.Add ((Note) store_sort.GetValue (iter, 3));
+			} while (store_sort.IterNext (ref iter));
+
+			return filtered_notes;
+		}
 	}
 }



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