Commits

Ikey Doherty committed eed5031

Allow back/forward navigation between disks

  • Participants
  • Parent commits b51fba1

Comments (0)

Files changed (2)

File src/pages/disks/disks.vala

 			devices = DeviceManager.get_all_devices ();
 			if (devices.length () >= 1) {
 				set_bar_from_disk (0);
-				Disk d = devices.nth_data(0).disk;
-				disk_chooser.add_disk (d);
+				foreach (unowned Device d in devices) {
+					//Disk d = devices.nth_data(0).disk;
+					disk_chooser.add_disk (d.disk);
+				}
 			}
 		}
 		navigate_update (NavigationState.ENABLE, NavigationDirection.FORWARD);

File src/widgets/diskchooser/diskchooser.vala

 
    private DiskItem current_disk_item;
 
+   private int index = 0;
+
    /**
     * Construct a new DiskChooser
     */
 	backBtn.sensitive = false;
 	var backArrow = new Gtk.Arrow (ArrowType.LEFT, ShadowType.NONE);
 	backBtn.add(backArrow);
-	backBtn.clicked.connect ( () => navigate () );
+	backBtn.clicked.connect ( () => navigate (false) );
 	btnBox.pack_start (backBtn, false, false, 0);
 
 	// Forward button
 	forwardBtn.sensitive = false;
 	var forwardArrow = new Gtk.Arrow (ArrowType.RIGHT, ShadowType.NONE);
 	forwardBtn.add(forwardArrow);
-	forwardBtn.clicked.connect ( () => navigate (false) );
+	forwardBtn.clicked.connect ( () => navigate (true) );
 	btnBox.pack_start (forwardBtn, false, false, 0);
 
 	this.pack_end (btnBox, false, false, 0);
    }
 
    protected void navigate (bool forward = true) {
+	if (forward) {
+		index += 1;
+	} else {
+		index -= 1;
+	}
+	check_limits ();
+	this.holder.remove (current_disk_item);
+	current_disk = disks.nth_data (index);
+	current_disk_item = new DiskItem(current_disk);
+	holder.add (current_disk_item);
+	holder.show_all ();
+   }
+
+   private void check_limits () {
+	if (index >= disks.length() - 1) {
+		forwardBtn.sensitive = false;
+		index = (int)disks.length() - 1;
+	} else {
+		forwardBtn.sensitive = true;
+	}
 
+	if (index <= 0) {
+		index = 0;
+		backBtn.sensitive = false;
+	} else {
+		backBtn.sensitive = true;
+	}
    }
 
    /**
 		current_disk_item = new DiskItem (newDisk);
 		holder.add (current_disk_item);
 		holder.show_all ();
+	} else {
+		forwardBtn.set_sensitive (true);
 	}
    }
 }