OSDN Git Service

Implement enhanced action item enumeration capability.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 6 Dec 2012 12:41:38 +0000 (12:41 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Thu, 6 Dec 2012 12:41:38 +0000 (12:41 +0000)
ChangeLog
src/pkgbase.h
src/pkgdata.cpp

index 1955c10..f33ad96 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2012-12-06  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Implement enhanced action item enumeration capability.
+
+       * src/pkgbase.h (pkgActionItem::EnumeratePendingActions): New public
+       method; declare it.  It provides the capability to enumerate scheduled
+       actions, filtered by action classification; when invoked such that it
+       selects all actions, it may be used as a replacement for...
+       (pkgActionItem::Unapplied): ...this; delete declaration.
+
+       * src/pkgdata.cpp (pkgActionItem::EnumeratePendingActions): Implement
+       it; it is derived, with enhancement, from original implementation...
+       (pkgActionItem::Unapplied): ...of this; delete it, and...
+       (AppWindowMaker::OnClose): ...update calling reference accordingly.
+
 2012-12-05  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Implement PTY display emulation for GUI mode DMH.
index f85e716..3760bc1 100644 (file)
@@ -302,9 +302,10 @@ class pkgActionItem
     inline unsigned long CancelScheduledAction( void );
     inline void SetPrimary( pkgActionItem* );
 
-    /* Method to check for residual unapplied changes.
+    /* Method to enumerate and identify pending changes,
+     * and/or check for residual unapplied changes.
      */
-    inline unsigned long Unapplied( void );
+    unsigned long EnumeratePendingActions( int = 0 );
 
     /* Methods for defining the selection criteria for
      * packages to be processed.
index c46431e..5632230 100644 (file)
@@ -1165,7 +1165,7 @@ long AppWindowMaker::OnNotify( WPARAM client_id, LPARAM data )
   return EXIT_SUCCESS;
 }
 
-inline unsigned long pkgActionItem::Unapplied( void )
+unsigned long pkgActionItem::EnumeratePendingActions( int classified )
 {
   /* Helper method to count the pending actions in a
    * scheduled action list.
@@ -1173,33 +1173,64 @@ inline unsigned long pkgActionItem::Unapplied( void )
   unsigned long count = 0;
   if( this != NULL )
   {
-    /* Assuming that the initial 'this' pointer is closer
-     * to the end of the list, than to the beginning...
+    /* Regardless of the position of the 'this' pointer,
+     * within the list of scheduled actions...
      */
     pkgActionItem *item = this;
-    while( item->next != NULL )
+    while( item->prev != NULL )
       /*
-       * ...advance, to ensure we have located the very
-       * last item in the schedule.
+       * ...we want to get a reference to the first
+       * item in the list.
        */
-      item = item->next;
+      item = item->prev;
 
-    /* Now, working back from end to beginning...
+    /* Now, working through the list...
      */
     while( item != NULL )
     {
       /* ...note items with any scheduled action...
        */
-      if( item->flags & ACTION_MASK )
-       /*
-        * ...and count them...
+      int action;
+      if( (action = item->flags & ACTION_MASK) != 0 )
+      {
+       /* ...and, when one is found...
         */
-       ++count;
-
-      /* ...then move on, to consider the preceding
-       * entry, if any.
+       if( action == classified )
+       {
+         /* ...and it matches the classification in which
+          * we are interested, then we retrieve the tarname
+          * for the related package...
+          */
+         pkgXmlNode *selected = (classified & ACTION_REMOVE)
+           ? item->Selection( to_remove )
+           : item->Selection();
+         const char *notification = (selected != NULL)
+           ? selected->GetPropVal( tarname_key, NULL )
+           : NULL;
+         if( notification != NULL )
+         {
+           /* ...and, provided it is valid, we append it to
+            * the DMH driven dialogue in which the enumeration
+            * is being reported...
+            */
+           dmh_printf( "%s\n", notification );
+           /*
+            * ...and include it in the accumulated count...
+            */
+           ++count;
+         }
+       }
+       else if( classified == 0 )
+         /*
+          * ...otherwise, when we aren't interested in any
+          * particular class of action, just count all those
+          * which are found, regardless of classification.
+          */
+         ++count;
+      }
+      /* ...then move on, to consider the next entry, if any.
        */
-      item = item->prev;
+      item = item->next;
     }
   }
   /* Ultimately, return the count of pending actions,
@@ -1215,7 +1246,7 @@ long AppWindowMaker::OnClose()
    * option for the termination request, so that the user
    * has an opportunity to complete such actions.
    */
-  if( (pkgData->Schedule()->Unapplied() > 0)
+  if( (pkgData->Schedule()->EnumeratePendingActions() > 0)
   &&  (MessageBox( AppWindow,
        "You have marked changes which have not been applied;\n"
        "these will be lost, if you quit without applying them.\n\n"