[f-spot/cleanup-backend: 4/24] More cleanups of IconView.SelectionCollection (Use methods of base class)



commit f30fe5637ad1ed3beca1b0e384a03f290154867e
Author: Mike Gemünde <mike gemuende de>
Date:   Fri Jul 16 09:34:01 2010 +0200

    More cleanups of IconView.SelectionCollection (Use methods of base class)

 src/MainWindow.cs                 |    9 +-
 src/SingleView.cs                 |   21 +++--
 src/UI.Dialog/AdjustTimeDialog.cs |    2 +-
 src/Widgets/IconView.cs           |  166 +++++++++----------------------------
 4 files changed, 58 insertions(+), 140 deletions(-)
---
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index b943f38..7ce1627 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -598,7 +598,7 @@ namespace FSpot
 				display_filmstrip.Sensitive = true;
 				group_selector.Visible = false;
 				
-				JumpTo (icon_view.FocusCell);
+				JumpTo (icon_view.Selection.FocusedIndex);
 				zoom_scale.Value = photo_view.NormalizedZoom;
 	
 				photo_view.View.GrabFocus();
@@ -1212,7 +1212,8 @@ namespace FSpot
 					PhotoVersionCommands.Reparent cmd = new PhotoVersionCommands.Reparent ();				
 					Photo[] photos_to_reparent = SelectedPhotos ();
 					// Give feedback to user that something happened, and leave the parent selected after reparenting
-					icon_view.Selection.Add (p_item); 
+					icon_view.Selection.Select (p_item);
+                    icon_view.Selection.FocusedIndex = p_item;
 					cmd.Execute (Database.Photos, photos_to_reparent, query.Photos [p_item], GetToplevel (null));
 					UpdateQuery ();
 				}
@@ -1233,7 +1234,7 @@ namespace FSpot
 	
 			switch (ViewMode) {
 			case ModeType.IconView:
-				icon_view.FocusCell = args.Items[0];
+				icon_view.Selection.FocusedIndex = args.Items[0];
 				SetViewMode (ModeType.PhotoView);
 				break;
 			case ModeType.PhotoView:
@@ -2147,7 +2148,7 @@ namespace FSpot
 				return;
 			}
 
-			icon_view.SelectAllCells ();
+			icon_view.Selection.SelectAll ();
 			UpdateStatusLabel ();
 		}
 	
diff --git a/src/SingleView.cs b/src/SingleView.cs
index daa3497..8175cca 100644
--- a/src/SingleView.cs
+++ b/src/SingleView.cs
@@ -168,9 +168,11 @@ namespace FSpot {
 			image_view.Item.Collection.ItemsChanged += sidebar.HandleSelectionItemsChanged;
 
 			UpdateStatusLabel ();
-			
-			if (collection.Count > 0)
-				directory_view.Selection.Add (0);
+
+			if (collection.Count > 0) {
+				directory_view.Selection.Select (0);
+                directory_view.Selection.FocusedIndex = 0;
+            }
 
 			export.Submenu = (Mono.Addins.AddinManager.GetExtensionNode ("/FSpot/Menus/Exports") as FSpot.Extensions.SubmenuNode).GetMenuItem (this).Submenu;
 			export.Submenu.ShowAll ();
@@ -192,7 +194,8 @@ namespace FSpot {
 		{
 			if (collection.Count > 0 && directory_view.Selection.Count == 0) {
 				Log.Debug ("Added selection");
-				directory_view.Selection.Add (0);
+				directory_view.Selection.Select (0);
+                directory_view.Selection.FocusedIndex = 0;
 			}
 
 			if (collection.Count > 1)
@@ -268,11 +271,11 @@ namespace FSpot {
 			if (pointer == null)
 				return;
 
-			directory_view.FocusCell = pointer.Index;
+			directory_view.Selection.FocusedIndex = pointer.Index;
 			directory_view.Selection.Clear ();
 			if (collection.Count > 0) {
-				directory_view.Selection.Add (directory_view.FocusCell);
-				directory_view.ScrollTo (directory_view.FocusCell);
+                directory_view.Selection.Select (directory_view.Selection.FocusedIndex);
+				directory_view.ScrollTo (directory_view.Selection.FocusedIndex);
 			}
 		}
 
@@ -378,8 +381,8 @@ namespace FSpot {
 		private void HandleFullScreenViewDestroy (object sender, System.EventArgs args)
 		{
 			directory_view.Selection.Clear ();
-			if (fsview.View.Item.IsValid) 
-				directory_view.Selection.Add (fsview.View.Item.Index);
+			if (fsview.View.Item.IsValid)
+				directory_view.Selection.Select (fsview.View.Item.Index);
 			fsview = null;
 		}
 		
diff --git a/src/UI.Dialog/AdjustTimeDialog.cs b/src/UI.Dialog/AdjustTimeDialog.cs
index ad93bae..6e83456 100644
--- a/src/UI.Dialog/AdjustTimeDialog.cs
+++ b/src/UI.Dialog/AdjustTimeDialog.cs
@@ -137,7 +137,7 @@ namespace FSpot.UI.Dialog {
 
 			if (!tray.Selection.Contains (Item.Index)) {
 				tray.Selection.Clear ();
-				tray.Selection.Add (Item.Index);
+				tray.Selection.Select (Item.Index);
 			}
 
 			photo_spin.Value = Item.Index + 1;
diff --git a/src/Widgets/IconView.cs b/src/Widgets/IconView.cs
index daf2846..9cbaf79 100644
--- a/src/Widgets/IconView.cs
+++ b/src/Widgets/IconView.cs
@@ -189,23 +189,6 @@ namespace FSpot.Widgets
 		private int y_offset;
 		private int x_offset;
 
-		// Focus Handling
-		private int real_focus_cell;
-		public int FocusCell {
-			set {
-				if (value != real_focus_cell) {
-					value = Math.Max (value, 0);
-					value = Math.Min (value, collection.Count - 1);
-					InvalidateCell (value);
-					InvalidateCell (real_focus_cell);
-					real_focus_cell = value;
-				}
-			}
-			get {
-				return real_focus_cell;
-			}
-		}
-
 		// Public events.
 		public event EventHandler<BrowsableEventArgs> DoubleClicked;
 		public event EventHandler ZoomChanged;
@@ -341,67 +324,11 @@ namespace FSpot.Widgets
 				}
 			}
 
-			public void Add (IBrowsableItem item)
-			{
-				Add (parent.IndexOf (item), true);
-			}
-
 			public bool Contains (IBrowsableItem item)
 			{
                 return Contains (parent.IndexOf (item));
 			}
 
-			public void Add (int num)
-			{
-                Add (num, true);
-			}
-
-			public void Add (int num, bool notify)
-			{
-                if (notify)
-                    Select (num);
-                else
-                    QuietSelect (num);
-
-                FocusedIndex = num;
-			}
-
-			public void Add (int start, int end)
-			{
-                SelectRange (start, end);
-			}
-
-			public void Remove (int cell, bool notify)
-			{
-                if (notify)
-                    Unselect (cell);
-                else
-                    QuietUnselect (cell);
-
-                FocusedIndex = cell;
-			}
-
-			public void Remove (IBrowsableItem item)
-			{
-				Remove (item, true);
-			}
-
-			public void Remove (int cell)
-			{
-				Remove (cell, true);
-			}
-
-			private void Remove (IBrowsableItem item, bool notify)
-			{
-                Remove (parent.IndexOf (item), true);
-			}
-
-			// Remove a range, except the start entry
-			public void Remove (int start, int end)
-			{
-                UnselectRange (start, end);
-			}
-
 			public int IndexOf (int parent_index)
 			{
 				return System.Array.IndexOf (this.Ids, parent_index);
@@ -415,26 +342,16 @@ namespace FSpot.Widgets
 				return System.Array.IndexOf (Ids, parent.IndexOf (item));
 			}
 
-			private void ToggleCell (int cell_num, bool notify)
-			{
-				if (Contains (cell_num))
-					Remove (cell_num, notify);
-				else
-					Add (cell_num, notify);
-			}
-
-			public void ToggleCell (int cell_num)
-			{
-				ToggleCell (cell_num, true);
-			}
-
 			public void SelectionInvert ()
 			{
-				int [] changed_cell = new int[parent.Count];
 				for (int i = 0; i < parent.Count; i++) {
-					ToggleCell (i, false);
-					changed_cell[i] = i;
+                    if (Contains (i))
+                        QuietUnselect (i);
+                    else
+                        QuietSelect (i);
 				}
+
+                OnChanged ();
 			}
 
 			public void SelectRect (int start_row, int end_row, int start_line, int end_line, int cells_per_row)
@@ -443,7 +360,7 @@ namespace FSpot.Widgets
 					for (int line = start_line; line < end_line; line++) {
 						int index = line*cells_per_row + row;
 						if (index < parent.Count)
-							Add (index, false);
+							QuietSelect (index);
 					}
 			}
 
@@ -453,7 +370,10 @@ namespace FSpot.Widgets
 					for (int line = start_line; line < end_line; line++) {
 						int index = line*cells_per_row + row;
 						if (index < parent.Count)
-							ToggleCell (index, false);
+                            if (Contains (index))
+                                QuietUnselect (index);
+                            else
+                                QuietSelect (index);
 					}
 			}
 
@@ -533,13 +453,6 @@ namespace FSpot.Widgets
 			h = cell_height;
 		}
 
-
-		// Private utility methods.
-		public void SelectAllCells ()
-		{
-			selection.Add (0, collection.Count - 1);
-		}
-
 		// Layout and drawing.
 
 		// FIXME I can't find a c# wrapper for the C PANGO_PIXELS () macro
@@ -695,7 +608,7 @@ namespace FSpot.Widgets
 
 			Gdk.Rectangle focus = Gdk.Rectangle.Inflate (bounds, -3, -3);
 
-			if (HasFocus && thumbnail_num == FocusCell) {
+			if (HasFocus && thumbnail_num == Selection.FocusedIndex) {
 				Style.PaintFocus(Style, BinWindow,
 						cell_state, area,
 						this, null,
@@ -1374,7 +1287,7 @@ namespace FSpot.Widgets
 //			BitArray initial_selection = selection.ToBitArray();
 			selection.Clear (false);
 			foreach (int i in start_select_selection)
-				selection.Add (i, false);
+				selection.QuietSelect (i);
 
 			// Select or toggle according to modifiers
 			int start_row  = (start_x - BORDER_SIZE) / cell_width;
@@ -1387,7 +1300,7 @@ namespace FSpot.Widgets
 				end_row = cells_per_row;
 
 
-			FocusCell = start_line * cells_per_row + start_row;
+			Selection.FocusedIndex = start_line * cells_per_row + start_row;
 
 			if ((mod & ModifierType.ControlMask) == 0)
 				selection.SelectRect (start_row, end_row, start_line, end_line, cells_per_row);
@@ -1565,14 +1478,15 @@ namespace FSpot.Widgets
 				int cell_num = CellAtPosition ((int) args.Event.X, (int) args.Event.Y, false, true);
 				if (cell_num != -1) {
 					if ((args.Event.State & ModifierType.ControlMask) != 0) {
-						selection.ToggleCell (cell_num);
+						selection.ToggleSelect (cell_num);
 					} else if ((args.Event.State & ModifierType.ShiftMask) != 0) {
-						selection.Add (FocusCell, cell_num);
+						selection.SelectRange (Selection.FocusedIndex, cell_num);
 					} else {
-						selection.Clear ();
-						selection.Add (cell_num);
+						selection.Clear (false);
+						selection.Select (cell_num);
+                        selection.FocusedIndex = cell_num;
 					}
-					FocusCell = cell_num;
+					Selection.FocusedIndex = cell_num;
 				}
 			}
 			isDragDrop = false;
@@ -1585,56 +1499,56 @@ namespace FSpot.Widgets
 			bool shift = ModifierType.ShiftMask == (args.Event.State & ModifierType.ShiftMask);
 			bool control = ModifierType.ControlMask == (args.Event.State & ModifierType.ControlMask);
 
-			focus_old = FocusCell;
+			focus_old = Selection.FocusedIndex;
 			switch (args.Event.Key) {
 			case Gdk.Key.Down:
 			case Gdk.Key.J:
 			case Gdk.Key.j:
-				FocusCell += cells_per_row;
+				Selection.FocusedIndex += cells_per_row;
 				break;
 			case Gdk.Key.Left:
 			case Gdk.Key.H:
 			case Gdk.Key.h:
 				if (control && shift)
-					FocusCell -= FocusCell % cells_per_row;
+					Selection.FocusedIndex -= Selection.FocusedIndex % cells_per_row;
 				else
-					FocusCell--;
+					Selection.FocusedIndex--;
 				break;
 			case Gdk.Key.Right:
 			case Gdk.Key.L:
 			case Gdk.Key.l:
 				if (control && shift)
-					FocusCell += cells_per_row - (FocusCell % cells_per_row) - 1;
+					Selection.FocusedIndex += cells_per_row - (Selection.FocusedIndex % cells_per_row) - 1;
 				else
-					FocusCell++;
+					Selection.FocusedIndex++;
 				break;
 			case Gdk.Key.Up:
 			case Gdk.Key.K:
 			case Gdk.Key.k:
-				FocusCell -= cells_per_row;
+				Selection.FocusedIndex -= cells_per_row;
 				break;
 			case Gdk.Key.Page_Up:
-				FocusCell -= cells_per_row * displayed_rows;
+				Selection.FocusedIndex -= cells_per_row * displayed_rows;
 				break;
 			case Gdk.Key.Page_Down:
-				FocusCell += cells_per_row * displayed_rows;
+				Selection.FocusedIndex += cells_per_row * displayed_rows;
 				break;
 			case Gdk.Key.Home:
-				FocusCell = 0;
+				Selection.FocusedIndex = 0;
 				break;
 			case Gdk.Key.End:
-				FocusCell = collection.Count - 1;
+				Selection.FocusedIndex = collection.Count - 1;
 				break;
 			case Gdk.Key.R:
 			case Gdk.Key.r:
-                                FocusCell = new Random().Next(0, collection.Count - 1);
+                                Selection.FocusedIndex = new Random().Next(0, collection.Count - 1);
                                 break;
 			case Gdk.Key.space:
-				selection.ToggleCell (FocusCell);
+				selection.ToggleSelect (Selection.FocusedIndex);
 				break;
 			case Gdk.Key.Return:
 				if (DoubleClicked != null)
-					DoubleClicked (this, new BrowsableEventArgs (FocusCell, null));
+					DoubleClicked (this, new BrowsableEventArgs (Selection.FocusedIndex, null));
 				break;
 			default:
 				args.RetVal = false;
@@ -1642,16 +1556,16 @@ namespace FSpot.Widgets
 			}
 
 			if (shift) {
-				if (focus_old != FocusCell && selection.Contains (focus_old) && selection.Contains (FocusCell))
-					selection.Remove (FocusCell, focus_old);
+				if (focus_old != Selection.FocusedIndex && selection.Contains (focus_old) && selection.Contains (Selection.FocusedIndex))
+					selection.UnselectRange (Selection.FocusedIndex, focus_old);
 				else
-					selection.Add (focus_old, FocusCell);
+					selection.SelectRange (focus_old, Selection.FocusedIndex);
 			} else if (!control) {
-				selection.Clear ();
-				selection.Add (FocusCell);
+				selection.Clear (false);
+				selection.Select (Selection.FocusedIndex);
 			}
 
-			ScrollTo (FocusCell);
+			ScrollTo (Selection.FocusedIndex);
 		}
 
 		private void HandleDestroyed (object sender, System.EventArgs args)



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]