Esempio n. 1
0
 void UpdateMappedUserSettings()
 {
     lock (DevicesToMapDataGridViewLock)
     {
         // If list not linked to any controller then return.
         if (_MappedTo == MapTo.None)
         {
             return;
         }
         var grid = MainDataGrid;
         var game = SettingsManager.CurrentGame;
         // Get rows which must be displayed on the list.
         var itemsToShow = SettingsManager.UserSettings.ItemsToArraySynchronized()
                           // Filter devices by controller.
                           .Where(x => x.MapTo == (int)_MappedTo)
                           // Filter devices by selected game (no items will be shown if game is not selected).
                           .Where(x => game != null && x.FileName == game.FileName && x.FileProductName == game.FileProductName)
                           .ToList();
         var itemsToRemove = mappedUserSettings.Except(itemsToShow).ToArray();
         var itemsToInsert = itemsToShow.Except(mappedUserSettings).ToArray();
         // If columns will be hidden or shown then...
         if (itemsToRemove.Length > 0 || itemsToInsert.Length > 0)
         {
             // Do removal.
             foreach (var item in itemsToRemove)
             {
                 mappedUserSettings.Remove(item);
             }
             // Do adding.
             foreach (var item in itemsToInsert)
             {
                 mappedUserSettings.Add(item);
             }
         }
         var itemToSelect = itemsToInsert.FirstOrDefault();
         // If item was inserted and not selected then...
         if (itemToSelect != null && !grid.SelectedItems.Contains(itemToSelect))
         {
             if (grid.SelectionMode == DataGridSelectionMode.Single)
             {
                 grid.SelectedItem = itemToSelect;
             }
             else
             {
                 // Clear current selection.
                 grid.SelectedItems.Clear();
                 // Select new item.
                 grid.SelectedItems.Add(itemToSelect);
             }
         }
         var visibleCount = mappedUserSettings.Count();
         var title        = string.Format("Enable {0} Mapped Device{1}", visibleCount, visibleCount == 1 ? "" : "s");
         if (mappedUserSettings.Count(x => x.IsEnabled) > 1)
         {
             title += " (Combine)";
         }
         ControlsHelper.SetText(EnabledLabel, title);
     }
 }
Esempio n. 2
0
 void UpdateMappedUserSettings()
 {
     lock (DevicesToMapDataGridViewLock)
     {
         var grid = MainDataGrid;
         var game = SettingsManager.CurrentGame;
         // Get rows which must be displayed on the list.
         var itemsToShow = SettingsManager.UserSettings.ItemsToArraySyncronized()
                           // Filter devices by controller.
                           .Where(x => x.MapTo == (int)_MappedTo)
                           // Filter devices by selected game (no items will be shown if game is not selected).
                           .Where(x => game != null && x.FileName == game.FileName && x.FileProductName == game.FileProductName)
                           .ToList();
         var itemsToRemove = mappedUserSettings.Except(itemsToShow).ToArray();
         var itemsToInsert = itemsToShow.Except(mappedUserSettings).ToArray();
         // If columns will be hidden or shown then...
         if (itemsToRemove.Length > 0 || itemsToInsert.Length > 0)
         {
             // Do removal.
             foreach (var item in itemsToRemove)
             {
                 mappedUserSettings.Remove(item);
             }
             // Do adding.
             foreach (var item in itemsToInsert)
             {
                 mappedUserSettings.Add(item);
             }
         }
         foreach (var item in itemsToInsert)
         {
             grid.SelectedItems.Add(item);
         }
         var visibleCount = mappedUserSettings.Count();
         var title        = string.Format("Enable {0} Mapped Device{1}", visibleCount, visibleCount == 1 ? "" : "s");
         if (mappedUserSettings.Count(x => x.IsEnabled) > 1)
         {
             title += " (Combine)";
         }
         ControlsHelper.SetText(EnabledLabel, title);
     }
 }