Below is a patch file that adds functionality to XPostitPlus-2.3 that
I find useful. The patch file adds the following new things.

1) Adds a new "Hide All Notes" menu selection.
   Files changed are xpostit.h, menu.c, note.c

2) Makes the "Find a Note" window bigger, but not too large.

   File changed is findnote.c
   This works fine with my Dell 21" monitor, your mileage 
   may vary. Comments welcome.

3) Sort all notes by title. This helps with "Find a note".
   
   Files changed are xpostit.h, note.c
   For sorting, I changed the notes list to a doubly-linked list and
   implemented a new MoveNote() function that will move a note to it's
   sorted order. CompareNotes() is used to compare one note with another
   in regards to sorted order. CompareNotes() also handles the "Note 2"
   before "Note 10" problem correctly.


This has been built on a FreeBSD 4.0-19991223-SNAP system.

--------------------8< cut-here -------------------------------------
--- xpostit.h.orig Sat Sep 14 23:59:14 1996
+++ xpostit.h      Tue Jan 11 21:15:32 2000
@@ -245,2 +245,3 @@
        struct  _PostItNote *pn_next;   /* pointer to next note record  */
+       struct  _PostItNote *pn_prev;   /* pointer to prev note record  */
 } PostItNote;
@@ -335,2 +336,3 @@
 void   UnHideAllNotes();
+void   HideAllNotes();
 void   LowerAllNotes();

--- findnote.c.orig  Fri Apr 12 13:51:30 1996
+++ findnote.c       Sat Jan  8 13:46:51 2000
@@ -219,3 +219,3 @@
        nargs = 0;
-       SetArg(XtNheight, 100);
+       SetArg(XtNheight, (int)((i>39) ? 839 : i*21.5)); 
        SetArg(XtNwidth, 200);

--- menu.c.orig Tue May  7 16:02:32 1996
+++ menu.c      Sat Jan  8 10:51:53 2000
@@ -69,11 +69,13 @@
        "Unhide All Notes",
-#define MenuCascade            12
+#define MenuHideAll            12
+       "Hide All Notes",
+#define MenuCascade            13
        "Cascade Notes",
-#define MenuFindANote          13
+#define MenuFindANote          14
        "Find A Note",
-#define EndNoteFunctions       14
+#define EndNoteFunctions       15
        " ",
-#define MenuExit               15
+#define MenuExit               16
        "Exit",
-#define MenuLastEntry          16
+#define MenuLastEntry          17
        0,
@@ -182,2 +184,5 @@
                UnHideAllNotes();
+               break;
+       case MenuHideAll:
+               HideAllNotes();
                break;

--- note.c.orig Sat Sep 14 19:31:30 1996
+++ note.c      Wed Jan 12 14:37:21 2000
@@ -112,2 +112,4 @@
 static PostItNote      *AllocNote();
+static PostItNote      *MoveNote();
+static int             CompareNotes();
 
@@ -213,2 +215,3 @@
        pn = AllocNote(NewIndex);
+       pn = MoveNote(pn);
 
@@ -369,2 +372,6 @@
                 * Get a note structure.
+                 * we will allocate this note, 
+                 * put it on the note chain,
+                 * when we have finished filling it in, we
+                 *    will put note in sorted order.
                 */
@@ -439,2 +446,8 @@
 
+                /*
+                 * Move this note to it's sorted order 
+                 * sorted by title (or note number)
+                 */
+                MoveNote(pn);
+
                /*
@@ -490,2 +503,24 @@
 
+/* 
+ * HideAllNotes - hide all unhidden notes
+ */
+void
+HideAllNotes()
+{ 
+       register PostItNote *pn;
+       Boolean found;
+ 
+       found = False;
+       for (pn = notes; pn != NULL; pn = pn->pn_next)
+               if ( pn->pn_hidden == False)
+               {
+                       XtPopdown ( pn->pn_shellwidget );
+                       pn->pn_hidden = True;
+                       found = True;
+               }
+ 
+       if ( !found )
+               ErrPopUp("There are no notes to hide.");
+}
+
 /*
@@ -1590,2 +1625,3 @@
        NameIt(pn, confirm, cancel);
+
 }
@@ -1841,2 +1877,8 @@
                XtSetSensitive ( pn->pn_savewidget, True );
+
+               /*
+                * Move the note to it's proper sorted order
+                */
+               MoveNote(pn);
+
        }
@@ -2001,4 +2043,3 @@
        /*
-        * Allocate a structure.
-        */
+        * Allocate a structure.  */
        if (notes == NULL) {
@@ -2006,2 +2047,3 @@
                pn = notes;
+               pn->pn_prev = NULL;
        }
@@ -2012,2 +2054,3 @@
                pn->pn_next = (PostItNote *) SafeAlloc(sizeof(PostItNote));
+               pn->pn_next->pn_prev = pn;
                pn = pn->pn_next;
@@ -2063,2 +2106,107 @@
        return(NULL);
+}
+
+/*
+ * MoveNote - move the given note to it's sorted position in
+ *           list of notes. The sort field is pn_name.
+ *            
+ *            When a note is added, it is always added to
+ *            the end of the list.
+ */
+static PostItNote *
+MoveNote(note)
+PostItNote *note;
+{
+       register PostItNote     *pn, *prevn;
+
+        /*
+         * If first and only note, return
+         */
+        if (notes == note && note->pn_next == NULL ) 
+               return(note);
+
+        /* 
+         * then remove note
+         */
+       /* if last note */
+        if (note->pn_next == NULL)
+               note->pn_prev->pn_next = NULL;
+        /* if first note */
+       else if (note->pn_prev == NULL) {
+               note->pn_next->pn_prev = NULL;
+                notes = note->pn_next;
+       }
+        /* else in middle of list */
+        else {
+               note->pn_prev->pn_next = note->pn_next;
+               note->pn_next->pn_prev = note->pn_prev;
+       }
+        note->pn_prev = note->pn_next = NULL;
+
+        /*
+         * find first note with name greater than or equal to this
+         * note
+         */
+        for (pn = notes; pn != NULL; prevn = pn, pn = pn->pn_next) {
+                if (CompareNotes(pn, note) >= 0) {
+                       /* if we are inserting at beginning of list */
+                       if (pn == notes) {
+                               notes = note; 
+                       }
+                       else {
+                               pn->pn_prev->pn_next = note; 
+                               note->pn_prev = pn->pn_prev;
+                       }
+                       note->pn_next = pn;
+                       pn->pn_prev = note;
+                        break;
+                }
+        }
+
+        /*
+         * if pn is NULL, we have the greatest name so far
+         */
+        if (pn == NULL) {
+               prevn->pn_next = note;
+               note->pn_next = NULL;
+               note->pn_prev = prevn;
+        }
+
+       return(note);
+}
+
+/*
+ * CompareNotes - Compare one note with another and
+ *               return -1, 0 or 1
+ */
+static int
+CompareNotes(na, nb)
+PostItNote *na, *nb;
+{
+       int rc;
+
+       /*
+        * Let's first see if we are comparing, Say,
+         * "Note 2" against "Note 10". For this type
+        * of compare, we need a numeric compare, so
+        * we don't end up with a bad placement (like ls)
+         */
+       if ((strncmp("Note ", na->pn_name, 5) == 0)
+       &&  (strncmp("Note ", nb->pn_name, 5) == 0)) {
+                int numa = atoi(&na->pn_name[5]);
+                int numb = atoi(&nb->pn_name[5]);
+               if (numa > numb)
+                       rc = 1;
+               else if (numa < numb)
+                       rc = -1; 
+               else
+                       rc = 0; 
+       }
+       /*
+        * Else let's just do an Alpha compare
+        */
+       else
+               rc = strcasecmp(na->pn_name, nb->pn_name);
+
+       return(rc);
 }

--
David Quattlebaum, ([EMAIL PROTECTED])         <IXOYE>

"The early bird may get the worm, but the second mouse gets the cheese"


To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to