Re: [AD] Grabber glitch (A.CC thread)

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


> Adding new features, such as folding nested datafiles, is another issue.

I've attached a first try. It was not particularly difficult to implement, 
but I had to add a couple of hooks which are not pretty.

-- 
Eric Botcazou
Index: tools/datedit.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/datedit.c,v
retrieving revision 1.27
diff -u -r1.27 datedit.c
--- tools/datedit.c	7 Feb 2003 13:29:19 -0000	1.27
+++ tools/datedit.c	12 May 2003 10:33:37 -0000
@@ -480,7 +480,7 @@
 
 
 /* creates a new datafile */
-static void *makenew_file(long *size)
+static void *makenew_datafile(long *size)
 {
    DATAFILE *dat = _al_malloc(sizeof(DATAFILE));
 
@@ -494,16 +494,43 @@
 
 
 
+/* displays a datafile in the grabber object view window */
+static void plot_datafile(AL_CONST DATAFILE *dat, int x, int y)
+{
+   textout_ex(screen,
+	      font,
+	      "Double-click in the item list to (un)fold it",
+	      x,
+	      y+32,
+	      gui_fg_color,
+	      gui_bg_color);
+}
+
+
+
+/* handles double-clicking on a datafile in the grabber */
+static int dclick_datafile(DATAFILE *dat)
+{
+   if (utolower(*get_datafile_property(dat, DAT_FOLD)) == 'y')
+      datedit_set_property(dat, DAT_FOLD, "n");
+   else
+      datedit_set_property(dat, DAT_FOLD, "y");
+
+   return D_O_K;
+}
+
+
+
 /* header block for datafile objects */
 DATEDIT_OBJECT_INFO datfile_info =
 {
    DAT_FILE, 
    "Datafile", 
    NULL, 
-   makenew_file,
+   makenew_datafile,
    save_datafile,
-   NULL,
-   NULL,
+   plot_datafile,
+   dclick_datafile,
    NULL
 };
 
Index: tools/datedit.h
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/datedit.h,v
retrieving revision 1.14
diff -u -r1.14 datedit.h
--- tools/datedit.h	10 Oct 2002 16:31:53 -0000	1.14
+++ tools/datedit.h	12 May 2003 10:33:37 -0000
@@ -36,6 +36,7 @@
 #define DAT_HNAM  DAT_ID('H','N','A','M')
 #define DAT_HPRE  DAT_ID('H','P','R','E')
 #define DAT_BACK  DAT_ID('B','A','C','K')
+#define DAT_FOLD  DAT_ID('F','O','L','D')
 #define DAT_DITH  DAT_ID('D','I','T','H')
 #define DAT_TRAN  DAT_ID('T','R','A','N')
 #define DAT_XGRD  DAT_ID('X','G','R','D')
Index: tools/grabber.c
===================================================================
RCS file: /cvsroot/alleg/allegro/tools/grabber.c,v
retrieving revision 1.53
diff -u -r1.53 grabber.c
--- tools/grabber.c	12 May 2003 08:02:42 -0000	1.53
+++ tools/grabber.c	12 May 2003 10:33:42 -0000
@@ -919,11 +919,21 @@
 /* handles double-clicking on an item in the object list */
 static int handle_dclick(DATAFILE *dat)
 {
-   int i;
+   int i, ret;
 
    for (i=0; datedit_object_info[i]->type != DAT_END; i++) {
-      if ((datedit_object_info[i]->type == dat->type) && (datedit_object_info[i]->dclick))
-	 return datedit_object_info[i]->dclick(dat);
+      if ((datedit_object_info[i]->type == dat->type) && (datedit_object_info[i]->dclick)) {
+	 ret = datedit_object_info[i]->dclick(dat);
+
+	 /* Special treatment for nested datafiles because of the fold/unfold feature. */
+	 if (dat->type == DAT_FILE) {
+	    rebuild_list(dat->dat, TRUE);
+	    object_message(main_dlg+DLG_LIST, MSG_DRAW, 0);
+	    object_message(main_dlg+DLG_PROP, MSG_DRAW, 0);
+	 }
+
+	 return ret;
+      }
    }
 
    return D_O_K;
@@ -1038,14 +1048,14 @@
 
 	 textout_ex(screen, font, datedit_desc(dat), d->x, d->y, gui_fg_color, -1);
 
-	 if (dat->type != DAT_FILE) {
-	    for (i=0; datedit_object_info[i]->type != DAT_END; i++) {
-	       if ((datedit_object_info[i]->type == dat->type) && (datedit_object_info[i]->plot)) {
-		  datedit_object_info[i]->plot(dat, d->x, d->y);
-		  return D_O_K;
-	       }
+	 for (i=0; datedit_object_info[i]->type != DAT_END; i++) {
+	    if ((datedit_object_info[i]->type == dat->type) && (datedit_object_info[i]->plot)) {
+	       datedit_object_info[i]->plot(dat, d->x, d->y);
+	       return D_O_K;
 	    }
+	 }
 
+	 if (dat->type != DAT_FILE) {
 	    for (c1=0; c1<16; c1++) {
 	       for (c2=0; c2<32; c2++) {
 		  if ((c1*32+c2) >= dat->size)
@@ -1330,6 +1340,8 @@
          datedit_sort_datafile(*dat->parent);
       rebuild_list(old, TRUE);
    }
+   else if (type == DAT_FOLD)
+      rebuild_list(old, TRUE);
 
    select_property(type);
 }
@@ -1552,8 +1564,11 @@
    char tmp[80];
    DATAFILE *d;
    int digits = 1, i;
+   int indexed, folded = 0;
+
+   indexed = (opt_menu[MENU_INDEX].flags & D_SELECTED);
 
-   if (opt_menu[MENU_INDEX].flags & D_SELECTED) {
+   if (indexed) {
       i = 0;
 
       while ((*dat)[i].type != DAT_END)
@@ -1566,24 +1581,27 @@
    for (i=0; (*dat)[i].type != DAT_END; i++) {
       d = (*dat)+i;
 
-      if (opt_menu[MENU_INDEX].flags & D_SELECTED) {
+      if (d->type == DAT_FILE)
+         folded = (utolower(*get_datafile_property(d, DAT_FOLD)) == 'y');
+
+      if (indexed) {
 	 sprintf(tmp, "[%*d] %c%c%c%c %s%c ", digits, i, (d->type >> 24) & 0xFF,
 		 (d->type >> 16) & 0xFF, (d->type >> 8) & 0xFF,
 		 (d->type & 0xFF), prefix, 
-		 (d->type == DAT_FILE) ? '+' : '-');
+		 (d->type == DAT_FILE) && folded ? '+' : '-');
       }
       else {
 	 sprintf(tmp, "%c%c%c%c %s%c ", (d->type >> 24) & 0xFF,
 		 (d->type >> 16) & 0xFF, (d->type >> 8) & 0xFF,
 		 (d->type & 0xFF), prefix, 
-		 (d->type == DAT_FILE) ? '+' : '-');
+		 (d->type == DAT_FILE) && folded ? '+' : '-');
       }
 
       strncat(tmp, get_datafile_property(d, DAT_NAME), 32);
 
       add_to_list(d, dat, i, tmp, clear);
 
-      if (d->type == DAT_FILE) {
+      if ((d->type == DAT_FILE) && (!folded)) {
 	 strcpy(tmp, prefix);
 	 strcat(tmp, "|");
 	 add_datafile_to_list((DATAFILE **)&d->dat, tmp, clear);


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/