Beispiel #1
0
 public SmartDataGroupsEditorViewModel(ISmartRawDataProvider smartDataProvider, ITaskRunner taskRunner, IMessageBoxService messageBoxService,
                                       IWindowManager windowManager, Func <IHistoryManager> historyCreator, SmartDataSourceMode dataSourceMode)
 {
     this.smartDataProvider = smartDataProvider;
     this.messageBoxService = messageBoxService;
     this.windowManager     = windowManager;
     this.dataSourceMode    = dataSourceMode;
     SourceItems            = new ObservableCollection <SmartDataGroupsEditorData>();
     MakeItems();
     AddGroup = new AsyncAutoCommand(AddGroupToSource);
     Save     = new DelegateCommand(() =>
     {
         taskRunner.ScheduleTask("Saving Group Definitions to file", SaveGroupsToFile);
     });
     DeleteItem = new DelegateCommand <object>(DeleteItemFromSource);
     AddMember  = new AsyncAutoCommand <SmartDataGroupsEditorData>(AddItemToGroup);
     EditItem   = new AsyncAutoCommand <SmartDataGroupsEditorData>(EditSourceItem);
     // history setup
     History                  = historyCreator();
     historyHandler           = new SmartDataGroupsHistory(SourceItems);
     UndoCommand              = new DelegateCommand(History.Undo, () => History.CanUndo);
     RedoCommand              = new DelegateCommand(History.Redo, () => History.CanRedo);
     History.PropertyChanged += (sender, args) =>
     {
         UndoCommand.RaiseCanExecuteChanged();
         RedoCommand.RaiseCanExecuteChanged();
         IsModified = !History.IsSaved;
         RaisePropertyChanged(nameof(IsModified));
     };
     History.AddHandler(historyHandler);
 }
Beispiel #2
0
        public SmartDataDefinesListViewModel(ISmartRawDataProvider smartDataProvider, ISmartDataManager smartDataManager, IParameterFactory parameterFactory,
                                             ITaskRunner taskRunner, IMessageBoxService messageBoxService, IWindowManager windowManager, Func <IHistoryManager> historyCreator, SmartDataSourceMode dataSourceMode)
        {
            this.smartDataProvider = smartDataProvider;
            this.parameterFactory  = parameterFactory;
            this.smartDataManager  = smartDataManager;
            this.dataSourceMode    = dataSourceMode;
            this.messageBoxService = messageBoxService;
            this.windowManager     = windowManager;
            switch (dataSourceMode)
            {
            case SmartDataSourceMode.SD_SOURCE_EVENTS:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>(smartDataProvider.GetEvents());
                break;

            case SmartDataSourceMode.SD_SOURCE_ACTIONS:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>(smartDataProvider.GetActions());
                break;

            case SmartDataSourceMode.SD_SOURCE_TARGETS:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>(smartDataProvider.GetTargets());
                break;

            default:
                DefinesItems = new ObservableCollection <SmartGenericJsonData>();
                break;
            }

            OnItemSelected = new AsyncAutoCommand <SmartGenericJsonData?>(ShowEditorWindow);
            CreateNew      = new AsyncAutoCommand(CreateNewItem);
            DeleteItem     = new DelegateCommand(DeleteSelectedItem);
            Save           = new DelegateCommand(() =>
            {
                taskRunner.ScheduleTask("Saving modified SmartData defines", SaveDataToFile);
            }, () => IsModified);
            SelectedItemIndex = -1;
            // history setup
            History                  = historyCreator();
            historyHandler           = new SmartDataListHistoryHandler(DefinesItems);
            UndoCommand              = new DelegateCommand(History.Undo, () => History.CanUndo);
            RedoCommand              = new DelegateCommand(History.Redo, () => History.CanRedo);
            History.PropertyChanged += (sender, args) =>
            {
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
                IsModified = !History.IsSaved;
                RaisePropertyChanged(nameof(IsModified));
            };
            History.AddHandler(historyHandler);
        }