From 485994978ffa1e592b9030fe9a22188a295e3cec Mon Sep 17 00:00:00 2001
From: Gerhard Gonter <ggonter@gmail.com>
Date: Fri, 25 Jul 2014 08:22:34 +0200
Subject: [PATCH] added new command: show <uuid>

---
 perl/Gnome-Tomboy/lib/Tomboy/TOC.pm | 13 +++++++++++--
 perl/Gnome-Tomboy/tom               |  7 +++++--
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/perl/Gnome-Tomboy/lib/Tomboy/TOC.pm b/perl/Gnome-Tomboy/lib/Tomboy/TOC.pm
index 617ed3b..cdf7078 100644
--- a/perl/Gnome-Tomboy/lib/Tomboy/TOC.pm
+++ b/perl/Gnome-Tomboy/lib/Tomboy/TOC.pm
@@ -25,17 +25,26 @@ sub set
   foreach my $par (keys %par) { $self->{$par}= $par{$par}; }
 }
 
+=head2 $toc->find($pattern [, $where])
+
+Search TOC for matching $pattern in field specified by $where; if $where is not defined, 'title' is used.
+
+Returns a list of matching TOC entries
+
+=cut
+
 sub find
 {
   my $self= shift;
   my $pattern= shift;
+  my $where= shift || 'title';
 
-print "find: pattern=[$pattern]\n";
+print "find: where=[$where] pattern=[$pattern]\n";
   my ($mode, $toc, $rows)= $self->load_toc();
   my @res;
   foreach my $row (@$rows)
   {
-    next unless ($row->{'title'} =~ m#$pattern#i);
+    next unless ($row->{$where} =~ m#$pattern#i);
     # print "row: ", main::Dumper ($row);
     push (@res, $row);
   }
diff --git a/perl/Gnome-Tomboy/tom b/perl/Gnome-Tomboy/tom
index 61a3649..98ce7ee 100755
--- a/perl/Gnome-Tomboy/tom
+++ b/perl/Gnome-Tomboy/tom
@@ -88,9 +88,10 @@ print "op_code=[$op_code] par=[", join (';', @PAR), "]\n";
 
    if ($op_code eq 'help') { usage(); }
 elsif ($op_code eq 'dump') { dump_note ($_) foreach (@PAR); }
+elsif ($op_code eq 'show') { find_note ('uuid', $_) foreach (@PAR); }
 elsif ($op_code eq 'toc')  { tom_toc(); }
 elsif ($op_code eq 'csv')  { tom_csv(); }
-elsif ($op_code eq 'find') { find_note(@PAR); }
+elsif ($op_code eq 'find') { find_note('title', @PAR); }
 elsif ($op_code eq 'diff')
 {
   my $f1= shift (@PAR);
@@ -130,12 +131,14 @@ sub tom_toc
 
 sub find_note
 {
+  my $where= shift;
+
   setup_toc();
 
   my %uuid;
   foreach my $pattern (@_)
   {
-    my @res= $toc->find ($pattern);
+    my @res= $toc->find ($pattern, $where);
     foreach my $res (@res) { $uuid{$res->{'uuid'}}= $res; } # TODO: count hits
   }
 
-- 
GitLab