OSDN Git Service

Implement "Discard" handler for GUI "Apply Changes" dialogue.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Sat, 8 Dec 2012 15:16:34 +0000 (15:16 +0000)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Sat, 8 Dec 2012 15:16:34 +0000 (15:16 +0000)
ChangeLog
src/guixmld.cpp
src/pkgbase.h
src/pkgtask.h

index 93ac415..dd587d3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+2012-12-08  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Implement "Discard" handler for GUI "Apply Changes" dialogue.
+
+       * src/pkgbase.h (pkgActionItem::Reset): New public method; declare it.
+       (pkgActionItem::Clear): New public method; declare two overloaded
+       variants, of which implement one inline.
+       (pkgXmlDocument::ClearScheduledActions): New public method; declare
+       and implement it inline.
+
+       * src/pkgtask.h (ACTION_DOWNLOAD_FAILED, ACTION_APPLY_FAILED): New
+       manifest bit-flag constants; define them.  They provide a mechanism
+       for blocking the discard event in respect of failed actions.
+
+       * src/guixmld.cpp (pkgActionItem::Reset): Implement it.
+       (pkgActionItem::Clear): Implement second, out-of-line variant.
+       (ACTION_PRESERVE_FAILED): New local manifest bit-flag constant; define
+       it as an aggregate of ACTION_DOWNLOAD_FAILED and ACTION_APPLY_FAILED.
+       (AppWindowMaker::OnCommand) [IDD_REPO_APPLY]: Use them.
+
 2012-12-07  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Implement GUI dialogue for "Apply Changes" action approval.
index b090fd7..93e12d7 100644 (file)
@@ -352,6 +352,83 @@ inline unsigned long AppWindowMaker::EnumerateActions( int classified )
   return pkgData->Schedule()->EnumeratePendingActions( classified );
 }
 
+pkgActionItem *pkgActionItem::Clear( pkgActionItem *schedule, unsigned long mask )
+# define ACTION_PRESERVE_FAILED  (ACTION_DOWNLOAD_FAILED | ACTION_APPLY_FAILED)
+{
+  /* Method to remove those action items which have no attribute flags in common
+   * with the specified mask, from the schedule; return the residual schedule of
+   * items, if any, which were not removed.  (Note that specifying a mask with a
+   * value of 0UL, which is the default, results in removal of all items).
+   */
+  pkgActionItem *residual = NULL;
+
+  /* Starting at the specified item, or the invoking class object item
+   * if no starting point is specified...
+   */
+  if( (schedule != NULL) || ((schedule = this) != NULL) )
+  {
+    /* ...and provided this starting point is not NULL, walk back to
+     * the first item in the associated task schedule...
+     */
+    while( schedule->prev != NULL ) schedule = schedule->prev;
+    while( schedule != NULL )
+    {
+      /* ...then, processing each scheduled task item in sequence, and
+       * keeping track of the next to be processed...
+       */
+      pkgActionItem *nextptr = schedule->next;
+      if( (schedule->flags & mask) == 0 )
+       /*
+        * ...delete each which doesn't match any masked attribute...
+        */
+       delete schedule;
+
+      else
+        /* ...otherwise add it to the residual schedule.
+        */
+       residual = schedule;
+
+      /* In either event, move on to the next item in sequence, if any.
+       */
+      schedule = nextptr;
+    }
+  }
+  /* Ultimately, return a pointer to the last item added to the residual
+   * schedule, or NULL if all items were deleted.
+   */
+  return residual;
+}
+
+void pkgActionItem::Reset
+( unsigned long set, unsigned long mask, pkgActionItem *schedule )
+{
+  /* A method to manipulate the control, error trapping, and state
+   * flags for all items in the specified schedule of actions.
+   *
+   * Starting at the specified item, or the invoking class object
+   * item if no starting point is specified...
+   */
+  if( (schedule != NULL) || ((schedule = this) != NULL) )
+  {
+    /* ...and provided this starting point is not NULL, walk back
+     * to the first item in the associated task schedule...
+     */
+    while( schedule->prev != NULL ) schedule = schedule->prev;
+    while( schedule != NULL )
+    {
+      /* ...then, processing each scheduled task item in sequence,
+       * update the flags according to the specified mask and new
+       * bits to be set...
+       */
+      schedule->flags = (flags & mask) | set;
+      /*
+       * ...before moving on to the next item in the sequence.
+       */
+      schedule = schedule->next;
+    }
+  }
+}
+
 static int pkgActionCount( HWND dlg, int id, const char *fmt, int classified )
 {
   /* Helper function to itemise the currently scheduled actions
@@ -528,14 +605,16 @@ long AppWindowMaker::OnCommand( WPARAM cmd )
 
     case IDM_REPO_APPLY:
       /* Initiated when the user selects the "Apply Changes" option,
-       * we present the user with a dialogue requesting confirmation
-       * of intent to proceed...
+       * we first reset the error trapping and download request state
+       * for all scheduled actions, then we present the user with a
+       * dialogue requesting confirmation of approval to proceed.
        */
+      pkgData->Schedule()->Reset( ACTION_DOWNLOAD, ~ACTION_PRESERVE_FAILED );
       switch( DialogueResponse( IDD_APPLY_APPROVE, pkgApplyApproved ) )
       {
-       /* ...then, of the three possible return conditions, we simply
-        * ignore the "Defer" option, (since it requires no action), but
-        * we must explicitly handle the "Apply" and "Discard" options.
+       /* Of the three possible responses, we simply ignore the "Defer"
+        * option, (since it requires no action), but we must explicitly
+        * handle the "Apply" and "Discard" options.
         */
        case ID_APPLY:
          /* When "Apply" confirmation is forthcoming, we proceed to
@@ -556,12 +635,8 @@ long AppWindowMaker::OnCommand( WPARAM cmd )
           * result of processing the "Apply" selection, we clear the
           * actions schedule, remove all marker icons, and refresh
           * the package list to reflect current status.
-          *
-          * FIXME: the pkgXmlDocument::ClearScheduledActions() method
-          * has yet to be implemented.
           */
          pkgListViewMaker pkglist( PackageListView );
-//       pkgData->ClearScheduledActions( PRESERVE_FAILED );
          pkglist.UpdateListView();
          
          /* Updating the list view clears pending action marks from
@@ -569,7 +644,8 @@ long AppWindowMaker::OnCommand( WPARAM cmd )
           * request relating to a failed action; restore marked state
           * for such residual actions.
           */
-         pkglist.MarkScheduledActions( pkgData->Schedule() );
+         if( pkgData->ClearScheduledActions( ACTION_PRESERVE_FAILED ) != NULL )
+           pkglist.MarkScheduledActions( pkgData->Schedule() );
 
          /* Clearing the schedule of actions may also affect the
           * validity of menu options; update accordingly.
index 3760bc1..97f1223 100644 (file)
@@ -340,6 +340,18 @@ class pkgActionItem
      */
     void Execute();
 
+    /* Method to manipulate error trapping, control, and state
+     * flags for the schedule of actions.
+     */
+    void Reset( unsigned long, unsigned long = ~0UL, pkgActionItem * = NULL );
+
+    /* Method to filter actions from an action list: the default is to
+     * clear ALL entries; specify a value of ACTION_MASK for the second
+     * argument, to filter out entries with no assigned action.
+     */
+    pkgActionItem *Clear( pkgActionItem * = NULL, unsigned long = 0UL );
+    pkgActionItem *Clear( unsigned long mask ){ return Clear( this, mask ); }
+
     /* Destructor...
      */
     ~pkgActionItem();
@@ -467,6 +479,13 @@ class pkgXmlDocument : public TiXmlDocument
      */
     inline void ExecuteActions(){ actions->Execute(); }
 
+    /* Method to clear the list of scheduled actions.
+     */
+    inline pkgActionItem* ClearScheduledActions( unsigned long mask = 0UL )
+    {
+      return actions = actions->Clear( mask );
+    }
+
     /* Methods to retrieve and optionally extract source archives
      * for a collection of dependent packages.
      */
index b9fae45..f4003d9 100644 (file)
@@ -82,6 +82,12 @@ enum
  */
 #define ACTION_MAY_SELECT      (ACTION_PRIMARY << 4)
 
+/* Flags which may be set to indicate that a scheduled action
+ * could not be completed successfully.
+ */
+#define ACTION_DOWNLOAD_FAILED (ACTION_PRIMARY << 5)
+#define ACTION_APPLY_FAILED    (ACTION_PRIMARY << 6)
+
 #ifndef EXTERN_C
 /* A convenience macro, to facilitate declaration of functions
  * which must exhibit extern "C" bindings, in a manner which is