[tomboy] New addin for removing broken links from notes (fix for bgo#384034)
- From: Aaron Borden <adborden src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tomboy] New addin for removing broken links from notes (fix for bgo#384034)
- Date: Sat, 11 Jun 2011 14:58:56 +0000 (UTC)
commit 768b218ac38c35bee9d539a2e712e01eaad01cfb
Author: Alex Tereschenko <frozenblue zoho com>
Date: Thu Nov 4 15:39:17 2010 +0300
New addin for removing broken links from notes (fix for bgo#384034)
New RemoveBrokenLinks addin for removing all broken links from a note.
Adds a menu item to the note's Tool menu.
If "Highlight WikiWords" is enabled - WikiWord broken links are preserved.
Tomboy.sln | 10 ++-
Tomboy/Addins/Makefile.am | 1 +
Tomboy/Addins/RemoveBrokenLinks/Makefile.am | 40 ++++++++
.../RemoveBrokenLinks/RemoveBrokenLinks.addin.xml | 21 ++++
.../RemoveBrokenLinks/RemoveBrokenLinks.csproj | 77 +++++++++++++++
.../RemoveBrokenLinks/RemoveBrokenLinksAddin.cs | 99 ++++++++++++++++++++
configure.in | 1 +
7 files changed, 248 insertions(+), 1 deletions(-)
---
diff --git a/Tomboy.sln b/Tomboy.sln
index b1384b9..077833e 100644
--- a/Tomboy.sln
+++ b/Tomboy.sln
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
-# SharpDevelop 3.0.0.2970
+# SharpDevelop 3.2.0.5777
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tomboy", "Tomboy.csproj", "{315DBB30-1461-4A41-A23F-A888D84E1EA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FixedWidth", "Tomboy\Addins\FixedWidth\FixedWidth.csproj", "{30A75F9A-7305-465E-8754-334345424569}"
@@ -28,6 +28,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Underline", "Tomboy\Addins\
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebSyncService", "Tomboy\Addins\WebSyncService\WebSyncService.csproj", "{A207AD10-9C5E-495F-9DEF-E7321A6FCB8F}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RemoveBrokenLinks", "Tomboy\Addins\RemoveBrokenLinks\RemoveBrokenLinks.csproj", "{AD6C9F12-3F95-497C-AF7E-629F787A097E}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -113,6 +115,12 @@ Global
{15A0F2C4-9BAD-11DE-B022-C19356D89593}.Mac|Any CPU.Build.0 = Mac|Any CPU
{15A0F2C4-9BAD-11DE-B022-C19356D89593}.Release|Any CPU.ActiveCfg = Release|Any CPU
{15A0F2C4-9BAD-11DE-B022-C19356D89593}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AD6C9F12-3F95-497C-AF7E-629F787A097E}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {AD6C9F12-3F95-497C-AF7E-629F787A097E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {AD6C9F12-3F95-497C-AF7E-629F787A097E}.Mac|Any CPU.Build.0 = Debug|Any CPU
+ {AD6C9F12-3F95-497C-AF7E-629F787A097E}.Mac|Any CPU.ActiveCfg = Debug|Any CPU
+ {AD6C9F12-3F95-497C-AF7E-629F787A097E}.Release|Any CPU.Build.0 = Release|Any CPU
+ {AD6C9F12-3F95-497C-AF7E-629F787A097E}.Release|Any CPU.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/Tomboy/Addins/Makefile.am b/Tomboy/Addins/Makefile.am
index a5f32f9..1d1f8ae 100644
--- a/Tomboy/Addins/Makefile.am
+++ b/Tomboy/Addins/Makefile.am
@@ -9,6 +9,7 @@ SUBDIRS = \
InsertTimestamp \
NoteOfTheDay \
PrintNotes \
+ RemoveBrokenLinks \
Sketching \
SshSyncService \
StickyNoteImport \
diff --git a/Tomboy/Addins/RemoveBrokenLinks/Makefile.am b/Tomboy/Addins/RemoveBrokenLinks/Makefile.am
new file mode 100644
index 0000000..6256d35
--- /dev/null
+++ b/Tomboy/Addins/RemoveBrokenLinks/Makefile.am
@@ -0,0 +1,40 @@
+include $(top_srcdir)/Makefile.include
+
+CSFLAGS = \
+ -debug \
+ -define:DEBUG \
+ -target:library
+
+ASSEMBLIES = \
+ $(LINK_TOMBOY_EXE) \
+ $(GTKSHARP_LIBS) \
+ $(LINK_MONO_ADDINS) \
+ -r:Mono.Posix
+
+ADDIN_NAME = RemoveBrokenLinks
+TARGET = $(top_builddir)/bin/addins/$(ADDIN_NAME).dll
+CSFILES = \
+ $(srcdir)/RemoveBrokenLinksAddin.cs
+
+RESOURCES = \
+ -resource:$(srcdir)/$(ADDIN_NAME).addin.xml
+
+$(TARGET).mdb: $(TARGET)
+
+$(TARGET): $(CSFILES) $(TOMBOY_EXE_PATH)
+ mkdir -p `dirname $(TARGET)` && $(CSC) -out:$@ $(CSFLAGS) $(ASSEMBLIES) $(CSFILES) $(RESOURCES)
+
+
+addinsdir = $(pkglibdir)/addins
+addins_DATA = \
+ $(TARGET) \
+ $(TARGET).mdb
+
+EXTRA_DIST = \
+ $(CSFILES) \
+ $(srcdir)/$(ADDIN_NAME).addin.xml
+
+CLEANFILES = \
+ $(TARGET).mdb \
+ $(TARGET)
+
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml
new file mode 100644
index 0000000..e465523
--- /dev/null
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.addin.xml
@@ -0,0 +1,21 @@
+<Addin id="RemoveBrokenLinksAddin"
+ namespace="Tomboy"
+ name="RemoveBrokenLinks"
+ author="Alex Tereschenko"
+ description="Adds ability to remove broken links."
+ category="Tools"
+ defaultEnabled="false"
+ version="0.1">
+
+ <Runtime>
+ <Import assembly="RemoveBrokenLinks.dll" />
+ </Runtime>
+
+ <Dependencies>
+ <Addin id="Tomboy" version="0.10" />
+ </Dependencies>
+
+ <Extension path="/Tomboy/NoteAddins">
+ <NoteAddin type="Tomboy.RemoveBrokenLinks.RemoveBrokenLinksAddin" />
+ </Extension>
+</Addin>
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj
new file mode 100644
index 0000000..550c373
--- /dev/null
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinks.csproj
@@ -0,0 +1,77 @@
+<Project ToolsVersion="3.5" 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>
+ <OutputType>Library</OutputType>
+ <RootNamespace>RemoveBrokenLinks</RootNamespace>
+ <AssemblyName>RemoveBrokenLinks</AssemblyName>
+ <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
+ <AppDesignerFolder>Properties</AppDesignerFolder>
+ <SourceAnalysisOverrideSettingsFile>C:\Users\avt\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis</SourceAnalysisOverrideSettingsFile>
+ <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
+ <NoStdLib>False</NoStdLib>
+ <WarningLevel>4</WarningLevel>
+ <TreatWarningsAsErrors>false</TreatWarningsAsErrors>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Platform)' == 'x86' ">
+ <PlatformTarget>x86</PlatformTarget>
+ <RegisterForComInterop>False</RegisterForComInterop>
+ <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
+ <BaseAddress>4194304</BaseAddress>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
+ <OutputPath>..\..\..\bin\Debug\</OutputPath>
+ <DebugSymbols>true</DebugSymbols>
+ <DebugType>Full</DebugType>
+ <Optimize>False</Optimize>
+ <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
+ <DefineConstants>DEBUG;TRACE</DefineConstants>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
+ <OutputPath>bin\Release\</OutputPath>
+ <DebugSymbols>False</DebugSymbols>
+ <DebugType>None</DebugType>
+ <Optimize>True</Optimize>
+ <CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
+ <DefineConstants>TRACE</DefineConstants>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Platform)' == 'AnyCPU' ">
+ <RegisterForComInterop>False</RegisterForComInterop>
+ <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
+ <BaseAddress>4194304</BaseAddress>
+ <PlatformTarget>x86</PlatformTarget>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <PropertyGroup Condition=" '$(Platform)' == 'Any CPU' ">
+ <RegisterForComInterop>False</RegisterForComInterop>
+ <GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
+ <BaseAddress>4194304</BaseAddress>
+ <PlatformTarget>x86</PlatformTarget>
+ <FileAlignment>512</FileAlignment>
+ </PropertyGroup>
+ <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
+ <ItemGroup>
+ <Reference Include="atk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="gdk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="glib-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="gtk-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="Mono.Posix">
+ <HintPath>..\..\..\winbin\Mono.Posix.dll</HintPath>
+ </Reference>
+ <Reference Include="pango-sharp, Version=2.12.0.0, Culture=neutral, PublicKeyToken=35e10195dab3c99f" />
+ <Reference Include="System" />
+ </ItemGroup>
+ <ItemGroup>
+ <Compile Include="RemoveBrokenLinksAddin.cs" />
+ <EmbeddedResource Include="RemoveBrokenLinks.addin.xml" />
+ <None Include="Makefile.am" />
+ </ItemGroup>
+ <ItemGroup>
+ <ProjectReference Include="..\..\..\Tomboy.csproj">
+ <Project>{315DBB30-1461-4A41-A23F-A888D84E1EA0}</Project>
+ <Name>Tomboy</Name>
+ </ProjectReference>
+ </ItemGroup>
+</Project>
\ No newline at end of file
diff --git a/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs
new file mode 100644
index 0000000..0103946
--- /dev/null
+++ b/Tomboy/Addins/RemoveBrokenLinks/RemoveBrokenLinksAddin.cs
@@ -0,0 +1,99 @@
+// Plugin for removing broken links.
+// (c) 2009 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
+{
+
+ public class RemoveBrokenLinksAddin : NoteAddin
+ {
+ Gtk.ImageMenuItem item;
+
+ public override void Initialize ()
+ {
+ }
+
+ public override void Shutdown ()
+ {
+ if (item != null)
+ item.Activated -= OnMenuItemActivated;
+ }
+
+ public override void OnNoteOpened ()
+ {
+ // Adding menu item when note is opened and window created
+ item = new Gtk.ImageMenuItem (Catalog.GetString ("Remove broken links"));
+ item.Image = new Gtk.Image (Gtk.Stock.Clear, Gtk.IconSize.Menu);
+ item.AddAccelerator ("activate", Window.AccelGroup,
+ (uint) Gdk.Key.r, Gdk.ModifierType.ControlMask,
+ Gtk.AccelFlags.Visible);
+ item.Activated += OnMenuItemActivated;
+ item.Show ();
+ AddPluginMenuItem (item);
+ }
+
+
+ void OnMenuItemActivated (object sender, EventArgs args)
+ {
+
+ 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 & 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
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/configure.in b/configure.in
index c44cc50..6ad3355 100644
--- a/configure.in
+++ b/configure.in
@@ -350,6 +350,7 @@ Tomboy/Addins/GalagoPresence/Makefile
Tomboy/Addins/InsertTimestamp/Makefile
Tomboy/Addins/NoteOfTheDay/Makefile
Tomboy/Addins/PrintNotes/Makefile
+Tomboy/Addins/RemoveBrokenLinks/Makefile
Tomboy/Addins/Sketching/Makefile
Tomboy/Addins/SshSyncService/Makefile
Tomboy/Addins/StickyNoteImport/Makefile
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]