Anonymous avatar Anonymous committed 17a02e8

Enable page up/down in string list choice in cfdisk. I don't think faster scrolling would be needed for partition, as few people would have too many partitions. (fdisk@sv.gnu.org/fdisk--main--0--patch-58)
fdisk@sv.gnu.org/fdisk--main--0--patch-58
Keywords:

Comments (0)

Files changed (1)

 static void plist_draw (PedDisk *cdisk, PedPartition *selected, int selnum, int *start);
 static int do_plist (PedDisk **cdisk, PedPartition **part, PedPartitionType have, PedPartitionType havent);
 
-/* TODO: Implement page up and page down */
 static const StrList*
 do_strlist (const char *prompt, const StrList *strlist, int opts) {
-	const StrList *selected = strlist, *temp;
-	int redraw = 1, key = 0, done = 0, start = 0, selnum = 0;
+	const StrList *selected = strlist, *temp, *next;
+	int redraw = 1, key = 0, done = 0, start = 0, selnum = 0, i, n;
 	const char* end_warning = opts & 1 ? 
 	                              _("No more text") : _("No more choices");
 	if (opts & 1) {
 				print_warning(_("Invalid key"),0);
 		}
 #endif
-		if (key == KEY_DOWN) {
-			if (!selected->next)
-				print_warning(end_warning,0);
-			else {
-				selected = selected->next;
-				selnum++;
+
+		/* We want to move 1 element when an arrow is pressed */
+		n = 1;
+		switch (key) {
+
+#if USE_KEYPAD
+			case KEY_NPAGE:
+				if (opts & 1)
+					n = LINES - SLD_HEAD - 4;
+				else 
+					n = LINES - MENUSIZE - INFOSIZE - SLD_HEAD - 5;
+#endif
+			case KEY_DOWN:
+				if (!selected->next) {
+					print_warning(end_warning,0);
+					break;
+				}
+				for (i = 0; i < n && selected->next; i++) {
+						selected = selected->next;
+				}
+				selnum -= i;
 				redraw = 1;
-			}
-		}
-		else if (key == KEY_UP) {
-			if (strlist == selected || 
-			    ((opts & 1) && selnum <= LINES-2-SLD_HEAD))
-				print_warning(end_warning,0);
-			else {
-			/* FIXME: Edit strlist and make this faster */
-			/* Users should not use the up arrow much anyway */
+				break;
+#if USE_KEYPAD
+			case KEY_PPAGE:
+				if (opts & 1)
+					n = LINES - SLD_HEAD - 4;
+				else 
+					n = LINES - MENUSIZE - INFOSIZE - SLD_HEAD - 5;
+#endif
+			case KEY_UP:
+				if (strlist == selected || 
+				    ((opts & 1) && selnum <= LINES-2-SLD_HEAD)) {
+					print_warning(end_warning,0);
+					break;
+				}
+				
+				/* FIXME: This might be improved by editing strlist */
+				/* (next represents temp->next->next->...->next) */
+				/* We set temp and next n elements apart, and move
+				   them both, until next reaches the current element,
+				   then temp points to the element n elements before it */
 				temp = strlist;
-				while (temp && temp->next != selected)
+				/* We set temp and next to n elements apart */
+				for (i = 0, next = strlist;
+				     i < n && next && next != selected;
+				     i++, next = next->next);
+				/* Move them together until next is our
+				   current element, which means that temp
+				   points to the element n elements before
+				   it */
+				while (temp && next && next != selected) {
 					temp = temp->next;
-				/* This should never happen */
-				if (temp->next != selected)
+					next = next->next;
+				}
+				/* This point should be never happen */
+				if (next != selected) {
 					print_warning(_("Bug in the program. "
 							"The programmer is an idiot."),0);
+				}
 				else {
-					selnum--;
+					selnum -= i;
 					selected = temp;
 					redraw = 1;
 				}
-			}
-		}
-		else if (key == CR) {
-			done = 1;
-		}
-		else if (opts & 1) {
-			done = 1;
-		}
-		else {
-			print_warning(_("Invalid key"),0);
+				break;
+			case CR:
+				done = 1;
+				break;
+			default:
+				if (opts & 1)
+					done = 1;
+				else
+					print_warning(_("Invalid key"),0);
 		}
 	}
 	if (disk) { 
 }
 
 /* Get previous non-METADATA partition. Needed for menu navigation */
-/* FIXME: It can be done faster */
+/* FIXME: Maybe it could be done faster */
 static PedPartition *
 disk_get_prev_nmd_partition(PedDisk *cdisk, PedPartition *part) {
 	PedPartition *temp_a, *temp_b;
 	return key;
 }
 
-
+/* TODO: This doesn't need a page up/down, but leave it as a TODO */
 /* Okay, this is our partition list. If there is no pointer to partition given, ASSume main menu
    have and havent aren't perfect, but work for our purposes */
 static int
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.