Example #1
0
 private void ResetRemovedMonitor(HeliosProfile profile, int monitorIndex, MonitorResetItem item, int monitorToRemove)
 {
     ConfigManager.LogManager.LogDebug($"Removing Monitor {monitorIndex + 1} and saving its controls for replacement");
     Dispatcher.Invoke(DispatcherPriority.Background, new Action <HeliosObject>(CloseProfileItem), profile.Monitors[monitorToRemove]);
     Dispatcher.Invoke(DispatcherPriority.Background, new Action(item.RemoveControls));
     ConfigManager.UndoManager.AddUndoItem(new DeleteMonitorUndoEvent(profile, profile.Monitors[monitorToRemove], monitorToRemove));
     profile.Monitors.RemoveAt(monitorToRemove);
 }
Example #2
0
        private void ResetMonitorsThread(ResetMonitors resetDialog, HeliosProfile profile)
        {
            ConfigManager.UndoManager.StartBatch();
            ConfigManager.LogManager.LogDebug("Resetting Monitors");
            try
            {
                // WARNING: monitor naming is 1-based but indexing and NewMonitor references are 0-based
                Monitor[] localMonitors = ConfigManager.DisplayManager.Displays.ToArray <Monitor>();

                // pass1: process all new and/or old monitors in order
                int existingMonitors = Math.Min(localMonitors.Length, profile.Monitors.Count);
                int totalMonitors    = Math.Max(localMonitors.Length, profile.Monitors.Count);

                // monitors that are preserved
                for (int monitorIndex = 0; monitorIndex < existingMonitors; monitorIndex++)
                {
                    MonitorResetItem item = resetDialog.MonitorResets[monitorIndex];
                    ResetExistingMonitor(monitorIndex, item);
                }

                // monitors added (may be zero iterations)
                for (int monitorIndex = existingMonitors; monitorIndex < localMonitors.Length; monitorIndex++)
                {
                    // monitorIndex does not refer to any reset item, as we are off the end of the list
                    ResetAddedMonitor(profile, monitorIndex, localMonitors[monitorIndex]);
                }

                // monitors removed (may be zero iterations)
                for (int monitorIndex = existingMonitors; monitorIndex < resetDialog.MonitorResets.Count; monitorIndex++)
                {
                    MonitorResetItem item = resetDialog.MonitorResets[monitorIndex];
                    ResetRemovedMonitor(profile, monitorIndex, item, localMonitors.Length);
                }

                // pass2: place all controls that were temporarily lifted and
                // copy over any settings from source to target monitors
                foreach (MonitorResetItem item in resetDialog.MonitorResets)
                {
                    ConfigManager.LogManager.LogDebug($"Placing controls for old monitor {item.OldMonitor.Name} onto Monitor {item.NewMonitor + 1}");
                    Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(item.PlaceControls), profile.Monitors[item.NewMonitor]);
                    Dispatcher.Invoke(DispatcherPriority.Background, new Action <Monitor>(item.CopySettings), profile.Monitors[item.NewMonitor]);
                }

                ConfigManager.UndoManager.CloseBatch();
            }
            catch (Exception ex)
            {
                ConfigManager.LogManager.LogError("Reset Monitors - Unhandled exception", ex);
                ConfigManager.LogManager.LogError("Rolling back any undoable operations from monitor reset");
                ConfigManager.UndoManager.UndoBatch();
                MessageBox.Show("Error encountered while resetting monitors; please file a bug with the contents of the application log", "Error");
            }
            finally
            {
                Dispatcher.Invoke(DispatcherPriority.Background, new Action(RemoveLoadingAdorner));
            }
        }
Example #3
0
 private void ResetExistingMonitor(int monitorIndex, MonitorResetItem item)
 {
     if (item.NewMonitor != monitorIndex)
     {
         ConfigManager.LogManager.LogDebug($"Removing controls from Monitor {monitorIndex + 1} for replacement");
         Dispatcher.Invoke(DispatcherPriority.Background, new Action(item.RemoveControls));
     }
     ConfigManager.LogManager.LogDebug($"Resetting Monitor {monitorIndex + 1}");
     Dispatcher.Invoke(DispatcherPriority.Background, new Action(item.Reset));
 }