private void MoveWorkerCommand(object obj) { var itemToMove = obj as WorkerCopy; if (itemToMove != null) { int oldIndex = 0; int newIndex = 0; int i = 0; foreach (var w in Workers.WorkerList) { if (w == itemToMove.SourceWorker) { oldIndex = i; } if (w == itemToMove.DestinationWorker) { newIndex = i; } i++; } if (oldIndex != newIndex) { Workers.WorkerListMove(oldIndex, newIndex); } } }
private void MoveWorkerDownCommand(object parameter) { var workerIndex = Workers.WorkerList.IndexOf((Worker)parameter); if (workerIndex != -1) { Workers.WorkerListMove(workerIndex, workerIndex + 1); } }
private void RestoreState(UndoObject undoObject) { switch (undoObject.OperationType) { case UndoOperationType.WorkerEdit: Workers.WorkerListReplaceItem(undoObject.Index, ((Worker)undoObject.Data).Clone()); break; case UndoOperationType.WorkersPowerCost: Workers.PowerCost = (double)undoObject.Data; break; case UndoOperationType.WorkersCoinType: Workers.CoinType = (string)undoObject.Data; break; case UndoOperationType.WorkersDisplayCoinAs: Workers.DisplayCoinAs = (string)undoObject.Data; break; case UndoOperationType.WorkerAdd: Workers.WorkerListRemoveAt(Workers.WorkerList.Count - 1); break; case UndoOperationType.WorkerAddRange: Workers.WorkerListRemoveRangeAt(undoObject.Index, (int)undoObject.Data); break; case UndoOperationType.WorkerInsert: Workers.WorkerListRemoveAt(undoObject.Index); break; case UndoOperationType.WorkerRemove: Workers.WorkerListInsert(undoObject.Index, ((Worker)undoObject.Data).Clone()); break; case UndoOperationType.WorkerRemoveRange: Workers.WorkerListAddRangeAt((ObservableCollection <Worker>)undoObject.Data, undoObject.Index); break; case UndoOperationType.WorkerMove: Workers.WorkerListMove((int)undoObject.Data, undoObject.Index); break; case UndoOperationType.SettingsEdit: UnHookUpWmtSettingsPropertyChangeEvents(); SaveUndoRedo("WtmSettings"); var wtms = ((WtmSettingsObject)undoObject.Data).Clone(); bool switchTimeFromEqual = WtmSwitchTimeFromStored.Equals(wtms.SwitchTimeFrom); bool switchTimeToEqual = WtmSwitchTimeToStored.Equals(wtms.SwitchTimeTo); bool historicalAverageEqual = WtmHistoricalAveragePeriodStored == wtms.HistoricalAveragePeriod; bool historyTimeFromEqual = WtmHistoryTimeFromStored.Equals(wtms.HistoryTimeFrom); bool historyTimeToEqual = WtmHistoryTimeToStored.Equals(wtms.HistoryTimeTo); WtmSettings = wtms; HookUpWmtSettingsPropertyChangeEvents(); if (WtmSettings.AutoSwitch) { SwitchTimeIsUpdated = false; } if (WtmSettings.BackupHistoricalPrices) { HistoryTimeIsUpdated = false; } WtmSettings.ServerSettingsAreUpdated = true; break; case UndoOperationType.WorkersAll: SaveUndoRedo("WorkersAll"); var allWorkers = undoObject.Data as ObservableCollection <Worker>; Workers.WorkerList.Clear(); foreach (var worker in allWorkers) { Workers.WorkerList.Add(worker.Clone()); } break; } }