[banshee] [TrackEditor] Make sync-all sync the track count



commit ae88a12009a5abcf5645cce10b543fd91edbb953
Author: Gabriel Burt <gabriel burt gmail com>
Date:   Fri Dec 18 14:19:32 2009 -0800

    [TrackEditor] Make sync-all sync the track count
    
    Add an optional SyncClosure that can be used instead of the WriteClosure
    for sync (eg so we can only sync the track count, not track number).
    Add FieldOptions.NoShowSync for use by track number, since it already
    has it's auto-set button.  Change the dialog to enumerate the syncable
    fields by asking each FieldPage for its fields, instead of looking for
    sync buttons in each notebook page.

 .../BasicTrackDetailsPage.cs                       |   46 ++++++++++++--------
 .../Banshee.Gui.TrackEditor/FieldOptions.cs        |    3 +-
 .../Banshee.Gui.TrackEditor/FieldPage.cs           |   26 +++++++++--
 .../Banshee.Gui.TrackEditor/TrackEditorDialog.cs   |   13 ++++--
 4 files changed, 60 insertions(+), 28 deletions(-)
---
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/BasicTrackDetailsPage.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/BasicTrackDetailsPage.cs
index d3fd95b..913d8ed 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/BasicTrackDetailsPage.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/BasicTrackDetailsPage.cs
@@ -118,24 +118,28 @@ namespace Banshee.Gui.TrackEditor
 
             // Right
 
-            /* Translators: "of" is the word beteen a track/disc number and the total count. */
-            AddField (right, new RangeEntry (Catalog.GetString ("of"), !MultipleTracks
-                ? null as RangeEntry.RangeOrderClosure
-                : delegate (RangeEntry entry) {
-                    for (int i = 0, n = Dialog.TrackCount; i < n; i++) {
-                        EditorTrackInfo track = Dialog.LoadTrack (i);
-
-                        if (Dialog.CurrentTrackIndex == i) {
-                            // In this case the writeClosure is invoked,
-                            // which will take care of updating the TrackInfo
-                            entry.From.Value = i + 1;
-                            entry.To.Value = n;
-                        } else {
-                            track.TrackNumber = i + 1;
-                            track.TrackCount = n;
+            AddField (right,
+                EditorUtilities.CreateLabel (""),
+                /* Translators: "of" is the word beteen a track/disc number and the total count. */
+                new RangeEntry (Catalog.GetString ("of"), !MultipleTracks
+                    ? null as RangeEntry.RangeOrderClosure
+                    : delegate (RangeEntry entry) {
+                        for (int i = 0, n = Dialog.TrackCount; i < n; i++) {
+                            EditorTrackInfo track = Dialog.LoadTrack (i);
+
+                            if (Dialog.CurrentTrackIndex == i) {
+                                // In this case the writeClosure is invoked,
+                                // which will take care of updating the TrackInfo
+                                entry.From.Value = i + 1;
+                                entry.To.Value = n;
+                            } else {
+                                track.TrackNumber = i + 1;
+                                track.TrackCount = n;
+                            }
                         }
-                    }
-                }, Catalog.GetString ("Automatically set track number and count")),
+                    },
+                    Catalog.GetString ("Automatically set track number and count")
+                ),
                 null,
                 delegate { return Catalog.GetString ("Track _Number:"); },
                 delegate (EditorTrackInfo track, Widget widget) {
@@ -143,12 +147,18 @@ namespace Banshee.Gui.TrackEditor
                     entry.From.Value = track.TrackNumber;
                     entry.To.Value = track.TrackCount;
                 },
+                // Write closure
                 delegate (EditorTrackInfo track, Widget widget) {
                     RangeEntry entry = (RangeEntry)widget;
                     track.TrackNumber = (int)entry.From.Value;
                     track.TrackCount = (int)entry.To.Value;
                 },
-                FieldOptions.NoSync
+                // Sync closure (doesn't modify TrackNumber)
+                delegate (EditorTrackInfo track, Widget widget) {
+                    RangeEntry entry = (RangeEntry)widget;
+                    track.TrackCount = (int)entry.To.Value;
+                },
+                FieldOptions.NoShowSync
             );
 
             AddField (right, new RangeEntry (Catalog.GetString ("of")),
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldOptions.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldOptions.cs
index 999f8f5..4b3bb9d 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldOptions.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldOptions.cs
@@ -35,6 +35,7 @@ namespace Banshee.Gui.TrackEditor
     {
         None = (0 << 0),
         Shrink = (1 << 0),
-        NoSync = (1 << 1)
+        NoSync = (1 << 1),
+        NoShowSync = (1 << 2)
     }
 }
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldPage.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldPage.cs
index 6143f88..37a172f 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldPage.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/FieldPage.cs
@@ -61,6 +61,9 @@ namespace Banshee.Gui.TrackEditor
             public FieldLabelClosure LabelClosure;
             public FieldValueClosure ReadClosure;
             public FieldValueClosure WriteClosure;
+            public FieldValueClosure SyncClosure;
+
+            public System.Action Sync;
         }
 
         private object tooltip_host;
@@ -125,6 +128,12 @@ namespace Banshee.Gui.TrackEditor
         public FieldSlot AddField (Box parent, Widget label, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
             FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldOptions options)
         {
+            return AddField (parent, label, field, syncTooltip, labelClosure, readClosure, writeClosure, null, options);
+        }
+
+        public FieldSlot AddField (Box parent, Widget label, Widget field, string syncTooltip, FieldLabelClosure labelClosure,
+            FieldValueClosure readClosure, FieldValueClosure writeClosure, FieldValueClosure syncClosure, FieldOptions options)
+        {
             FieldSlot slot = new FieldSlot ();
 
             slot.Parent = parent;
@@ -133,16 +142,23 @@ namespace Banshee.Gui.TrackEditor
             slot.LabelClosure = labelClosure;
             slot.ReadClosure = readClosure;
             slot.WriteClosure = writeClosure;
+            slot.SyncClosure = syncClosure;
+
             if (MultipleTracks && (options & FieldOptions.NoSync) == 0) {
+                slot.Sync = delegate {
+                    dialog.ForeachNonCurrentTrack (delegate (EditorTrackInfo track) {
+                        (slot.SyncClosure ?? slot.WriteClosure) (track, slot.Field);
+                    });
+                };
+            }
+
+            if (MultipleTracks && (options & FieldOptions.NoSync) == 0 && (options & FieldOptions.NoShowSync) == 0) {
                 slot.SyncButton = new SyncButton ();
                 if (syncTooltip != null) {
                     TooltipSetter.Set (tooltip_host, slot.SyncButton, syncTooltip);
                 }
-                slot.SyncButton.Clicked += delegate {
-                    dialog.ForeachNonCurrentTrack (delegate (EditorTrackInfo track) {
-                        slot.WriteClosure (track, slot.Field);
-                    });
-                };
+
+                slot.SyncButton.Clicked += delegate { slot.Sync (); };
             }
 
             Table table = new Table (1, 1, false);
diff --git a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TrackEditorDialog.cs b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TrackEditorDialog.cs
index 2f6a9ec..aeb2c07 100644
--- a/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TrackEditorDialog.cs
+++ b/src/Core/Banshee.ThickClient/Banshee.Gui.TrackEditor/TrackEditorDialog.cs
@@ -319,11 +319,16 @@ namespace Banshee.Gui.TrackEditor
 
         private void InvokeFieldSync ()
         {
-            ForeachWidget<SyncButton> (delegate (SyncButton button) {
-                if (button.Sensitive) {
-                    button.Click ();
+            for (int i = 0; i < notebook.NPages; i++) {
+                var field_page = notebook.GetNthPage (i) as FieldPage;
+                if (field_page != null) {
+                    foreach (var slot in field_page.FieldSlots) {
+                        if (slot.Sync != null && (slot.SyncButton == null || slot.SyncButton.Sensitive)) {
+                            slot.Sync ();
+                        }
+                    }
                 }
-            });
+            }
         }
 
         private int action_area_children_allocated = 0;



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