public GameobjectParameter(IDatabaseProvider database,
                                   IServerIntegration serverIntegration,
                                   IItemFromListProvider itemFromListProvider)
        {
            this.database  = database;
            SpecialCommand = async() =>
            {
                var entry = await serverIntegration.GetNearestGameObjects();

                if (entry == null || entry.Count == 0)
                {
                    return(null);
                }

                var options = entry.GroupBy(e => e.Entry)
                              .OrderBy(group => group.Key)
                              .ToDictionary(g => (long)g.Key,
                                            g => new SelectOption(database.GetGameObjectTemplate(g.Key)?.Name ?? "Unknown name",
                                                                  $"{g.First().Distance} yd away"));

                if (options.Count == 1)
                {
                    return((uint)options.Keys.First());
                }

                var pick = await itemFromListProvider.GetItemFromList(options, false);

                if (pick.HasValue)
                {
                    return((uint)pick.Value);
                }

                return(null);
            };
        }
示例#2
0
 public ParameterEditorViewModel(Parameter parameter, string group, IItemFromListProvider itemFromListProvider)
 {
     Group = group;
     this.itemFromListProvider = itemFromListProvider;
     Parameter        = parameter;
     SelectItemAction = new DelegateCommand(SelectItem);
 }
示例#3
0
 public GossipMenuOptionParameter(IDatabaseProvider databaseProvider,
                                  ITableEditorPickerService tableEditorPickerService,
                                  IItemFromListProvider itemFromListProvider)
 {
     this.databaseProvider         = databaseProvider;
     this.tableEditorPickerService = tableEditorPickerService;
     this.itemFromListProvider     = itemFromListProvider;
 }
示例#4
0
 public CreatureTextParameter(IDatabaseProvider databaseProvider,
                              ITableEditorPickerService tableEditorPickerService,
                              IItemFromListProvider itemFromListProvider)
 {
     this.databaseProvider         = databaseProvider;
     this.tableEditorPickerService = tableEditorPickerService;
     this.itemFromListProvider     = itemFromListProvider;
 }
 internal VariableContextualParameter(GlobalVariableType type,
                                      string name, IVariablePickerService picker, IItemFromListProvider itemFromListProvider)
 {
     this.type   = type;
     this.name   = name;
     this.picker = picker;
     this.itemFromListProvider = itemFromListProvider;
 }
        protected ViewModelBase(IHistoryManager history,
                                DatabaseTableSolutionItem solutionItem,
                                ISolutionItemNameRegistry solutionItemName,
                                ISolutionManager solutionManager,
                                ISolutionTasksService solutionTasksService,
                                IEventAggregator eventAggregator,
                                IQueryGenerator queryGenerator,
                                IDatabaseTableDataProvider databaseTableDataProvider,
                                IMessageBoxService messageBoxService,
                                ITaskRunner taskRunner,
                                IParameterFactory parameterFactory,
                                ITableDefinitionProvider tableDefinitionProvider,
                                IItemFromListProvider itemFromListProvider,
                                ISolutionItemIconRegistry iconRegistry,
                                ISessionService sessionService,
                                IDatabaseTableCommandService commandService,
                                IParameterPickerService parameterPickerService,
                                IStatusBar statusBar,
                                IMySqlExecutor mySqlExecutor)
        {
            this.solutionItemName          = solutionItemName;
            this.solutionManager           = solutionManager;
            this.solutionTasksService      = solutionTasksService;
            this.queryGenerator            = queryGenerator;
            this.databaseTableDataProvider = databaseTableDataProvider;
            this.messageBoxService         = messageBoxService;
            this.taskRunner              = taskRunner;
            this.parameterFactory        = parameterFactory;
            this.tableDefinitionProvider = tableDefinitionProvider;
            this.itemFromListProvider    = itemFromListProvider;
            this.sessionService          = sessionService;
            this.commandService          = commandService;
            this.parameterPickerService  = parameterPickerService;
            this.statusBar     = statusBar;
            this.mySqlExecutor = mySqlExecutor;
            this.solutionItem  = solutionItem;
            History            = history;

            undoCommand            = new DelegateCommand(History.Undo, CanUndo);
            redoCommand            = new DelegateCommand(History.Redo, CanRedo);
            Save                   = new AsyncAutoCommand(SaveSolutionItem);
            title                  = solutionItemName.GetName(solutionItem);
            Icon                   = iconRegistry.GetIcon(solutionItem);
            nameGeneratorParameter = parameterFactory.Factory("Parameter");

            History.PropertyChanged += (_, _) =>
            {
                undoCommand.RaiseCanExecuteChanged();
                redoCommand.RaiseCanExecuteChanged();
                RaisePropertyChanged(nameof(IsModified));
            };

            tableDefinition = tableDefinitionProvider.GetDefinition(solutionItem.DefinitionId) !;
            LoadAndCreateCommands();
            nameGeneratorParameter = parameterFactory.Factory(tableDefinition.Picker);
        }
示例#7
0
        public EditableParameterViewModel(ParameterValueHolder <T> parameter, string group, IItemFromListProvider itemFromListProvider)
        {
            this.itemFromListProvider = itemFromListProvider;
            Group            = group;
            Parameter        = parameter;
            SelectItemAction = new DelegateCommand(SelectItem);

            Watch(parameter, p => p.IsUsed, nameof(IsHidden));
            Watch(parameter, p => p.Parameter, nameof(HasItems));
            Watch(parameter, p => p.Name, nameof(Name));
        }
示例#8
0
 public DatabaseTableSolutionItemProviderProvider(ITableDefinitionProvider definitionProvider,
                                                  IDatabaseTableDataProvider tableDataProvider,
                                                  IItemFromListProvider itemFromListProvider,
                                                  IMessageBoxService messageBoxService,
                                                  IParameterFactory parameterFactory)
 {
     this.definitionProvider   = definitionProvider;
     this.tableDataProvider    = tableDataProvider;
     this.itemFromListProvider = itemFromListProvider;
     this.messageBoxService    = messageBoxService;
     this.parameterFactory     = parameterFactory;
 }
        public ParametersEditViewModel(IItemFromListProvider itemFromListProvider, SmartBaseElement element, IEnumerable <KeyValuePair <Parameter, string> > parameters)
        {
            _element = element;

            foreach (var parameter in parameters)
            {
                Parameters.Add(new ParameterEditorViewModel(parameter.Key, parameter.Value, itemFromListProvider));
            }

            _items        = new CollectionViewSource();
            _items.Source = Parameters;
            _items.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
        }
示例#10
0
 internal DatabaseTableSolutionItemProvider(DatabaseTableDefinitionJson definition,
                                            IDatabaseTableDataProvider tableDataProvider,
                                            IItemFromListProvider itemFromListProvider,
                                            IMessageBoxService messageBoxService,
                                            IParameterFactory parameterFactory)
 {
     this.tableDataProvider    = tableDataProvider;
     this.itemFromListProvider = itemFromListProvider;
     this.messageBoxService    = messageBoxService;
     this.parameterFactory     = parameterFactory;
     this.definition           = definition;
     this.itemIcon             = new ImageUri($"Resources/SmartScriptGeneric.png");
 }
示例#11
0
 internal DatabaseTableSolutionItemProvider(DatabaseTableDefinitionJson definition,
                                            IDatabaseTableDataProvider tableDataProvider,
                                            IItemFromListProvider itemFromListProvider,
                                            IMessageBoxService messageBoxService,
                                            IParameterFactory parameterFactory)
 {
     this.tableDataProvider    = tableDataProvider;
     this.itemFromListProvider = itemFromListProvider;
     this.messageBoxService    = messageBoxService;
     this.parameterFactory     = parameterFactory;
     this.definition           = definition;
     this.itemIcon             = new ImageUri($"Icons/document_big.png");
 }
 public TableOpenService(
     IParameterFactory parameterFactory,
     IItemFromListProvider itemFromListProvider,
     IDatabaseTableDataProvider tableDataProvider,
     ITableDefinitionProvider definitionProvider,
     IMessageBoxService messageBoxService)
 {
     this.parameterFactory     = parameterFactory;
     this.itemFromListProvider = itemFromListProvider;
     this.tableDataProvider    = tableDataProvider;
     this.definitionProvider   = definitionProvider;
     this.messageBoxService    = messageBoxService;
 }
        public SmartScriptEditorViewModel(SmartScriptSolutionItem item, IHistoryManager history, IDatabaseProvider database, IEventAggregator eventAggregator, ISmartDataManager smartDataManager, ISmartFactory smartFactory, IItemFromListProvider itemFromListProvider, ISmartTypeListProvider smartTypeListProvider, ISolutionItemNameRegistry itemNameRegistry)
        {
            _item                      = item;
            _history                   = history;
            this.database              = database;
            this.smartDataManager      = smartDataManager;
            this.smartFactory          = smartFactory;
            this.itemFromListProvider  = itemFromListProvider;
            this.smartTypeListProvider = smartTypeListProvider;
            this.itemNameRegistry      = itemNameRegistry;
            var lines = database.GetScriptFor(_item.Entry, _item.SmartType);

            script = new SmartScript(_item, smartFactory);
            script.Load(lines);

            EditEvent  = new DelegateCommand(EditEventCommand);
            EditAction = new DelegateCommand <SmartAction>(EditActionCommand);
            AddEvent   = new DelegateCommand(AddEventCommand);
            AddAction  = new DelegateCommand <SmartEvent>(AddActionCommand);

            SaveCommand = new DelegateCommand(SaveAllToDb);

            DeleteAction = new DelegateCommand <SmartAction>(DeleteActionCommand);
            DeleteEvent  = new DelegateCommand(DeleteEventCommand);

            _history.AddHandler(new SaiHistoryHandler(script));

            UndoCommand = new DelegateCommand(history.Undo, () => history.CanUndo);
            RedoCommand = new DelegateCommand(history.Redo, () => history.CanRedo);

            _history.PropertyChanged += (sender, args) =>
            {
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
            };

            eventAggregator.GetEvent <EventRequestGenerateSql>().Subscribe((args) =>
            {
                if (args.Item is SmartScriptSolutionItem)
                {
                    var itemm = args.Item as SmartScriptSolutionItem;
                    if (itemm.Entry == _item.Entry && itemm.SmartType == _item.SmartType)
                    {
                        args.Sql = new SmartScriptExporter(script, smartFactory).GetSql();
                    }
                }
            });
        }
示例#14
0
        protected ViewModelBase(IHistoryManager history,
                                DatabaseTableSolutionItem solutionItem,
                                ISolutionItemNameRegistry solutionItemName,
                                ISolutionManager solutionManager,
                                ISolutionTasksService solutionTasksService,
                                IEventAggregator eventAggregator,
                                IQueryGenerator queryGenerator,
                                IDatabaseTableDataProvider databaseTableDataProvider,
                                IMessageBoxService messageBoxService,
                                ITaskRunner taskRunner,
                                IParameterFactory parameterFactory,
                                ITableDefinitionProvider tableDefinitionProvider,
                                IItemFromListProvider itemFromListProvider,
                                ISolutionItemIconRegistry iconRegistry)
        {
            this.solutionItemName          = solutionItemName;
            this.solutionManager           = solutionManager;
            this.solutionTasksService      = solutionTasksService;
            this.queryGenerator            = queryGenerator;
            this.databaseTableDataProvider = databaseTableDataProvider;
            this.messageBoxService         = messageBoxService;
            this.taskRunner           = taskRunner;
            this.parameterFactory     = parameterFactory;
            this.itemFromListProvider = itemFromListProvider;
            this.solutionItem         = solutionItem;
            History = history;

            undoCommand            = new DelegateCommand(History.Undo, CanUndo);
            redoCommand            = new DelegateCommand(History.Redo, CanRedo);
            Save                   = new DelegateCommand(SaveSolutionItem);
            title                  = solutionItemName.GetName(solutionItem);
            Icon                   = iconRegistry.GetIcon(solutionItem);
            nameGeneratorParameter = parameterFactory.Factory("Parameter");

            History.PropertyChanged += (_, _) =>
            {
                undoCommand.RaiseCanExecuteChanged();
                redoCommand.RaiseCanExecuteChanged();
                RaisePropertyChanged(nameof(IsModified));
            };

            tableDefinition        = tableDefinitionProvider.GetDefinition(solutionItem.DefinitionId) !;
            nameGeneratorParameter = parameterFactory.Factory(tableDefinition.Picker);

            AutoDispose(eventAggregator.GetEvent <EventRequestGenerateSql>()
                        .Subscribe(ExecuteSql));
        }
示例#15
0
 public SmartScriptEditorProvider(
     ISolutionItemNameRegistry solutionItemNameRegistry,
     IHistoryManager historyManager,
     IDatabaseProvider databaseProvider,
     IEventAggregator eventAggregator,
     ISmartFactory smartFactory,
     IItemFromListProvider itemFromListProvider,
     SmartTypeListProvider smartTypeListProvider
     )
 {
     this.solutionItemNameRegistry = solutionItemNameRegistry;
     this.historyManager           = historyManager;
     this.databaseProvider         = databaseProvider;
     this.eventAggregator          = eventAggregator;
     this.smartFactory             = smartFactory;
     this.itemFromListProvider     = itemFromListProvider;
     this.smartTypeListProvider    = smartTypeListProvider;
 }
示例#16
0
        public SmartFactory(IParameterFactory parameterFactory,
                            ISmartDataManager smartDataManager,
                            IDatabaseProvider databaseProvider,
                            IConditionDataManager conditionDataManager,
                            ITableEditorPickerService tableEditorPickerService,
                            IItemFromListProvider itemFromListProvider,
                            ICurrentCoreVersion currentCoreVersion,
                            IQuestEntryProviderService questEntryProviderService,
                            IContainerProvider containerProvider)
        {
            this.parameterFactory     = parameterFactory;
            this.smartDataManager     = smartDataManager;
            this.conditionDataManager = conditionDataManager;
            this.currentCoreVersion   = currentCoreVersion;

            if (!parameterFactory.IsRegisteredLong("StoredTargetParameter"))
            {
                parameterFactory.Register("GossipMenuOptionParameter", new GossipMenuOptionParameter(databaseProvider, tableEditorPickerService, itemFromListProvider));
                parameterFactory.Register("CreatureTextParameter", new CreatureTextParameter(databaseProvider, tableEditorPickerService, itemFromListProvider));
                parameterFactory.Register("QuestStarterParameter", new QuestStarterEnderParameter(databaseProvider, tableEditorPickerService, questEntryProviderService, true));
                parameterFactory.Register("QuestEnderParameter", new QuestStarterEnderParameter(databaseProvider, tableEditorPickerService, questEntryProviderService, false));
                parameterFactory.Register("CreatureSpawnKeyParameter", new CreatureSpawnKeyParameter(databaseProvider));
                parameterFactory.Register("GameobjectSpawnKeyParameter", new GameObjectSpawnKeyParameter(databaseProvider));
                parameterFactory.Register("StoredTargetParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.StoredTarget), (typeof(string), "storedTarget")));
                parameterFactory.Register("DataVariableParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.DataVariable), (typeof(string), "data")));
                parameterFactory.Register("TimedEventParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.TimedEvent), (typeof(string), "timedEvent")));
                parameterFactory.Register("DoActionParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.Action), (typeof(string), "action")));
                parameterFactory.Register("DoFunctionParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.Function), (typeof(string), "function")));
                parameterFactory.Register("StoredPointParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.StoredPoint), (typeof(string), "storedPoint")));
                parameterFactory.Register("DatabasePointParameter", containerProvider.Resolve <VariableContextualParameter>(
                                              (typeof(GlobalVariableType), GlobalVariableType.DatabasePoint), (typeof(string), "databasePoint")));
            }
        }
 public ParametersEditViewModel(IItemFromListProvider itemFromListProvider,
     ICurrentCoreVersion currentCoreVersion,
     SmartBaseElement element,
     bool focusFirst,
     IEnumerable<(ParameterValueHolder<long> parameter, string name)>? parameters,
        public ConditionsEditorViewModel(
            IConditionsFactory conditionsFactory,
            IConditionDataManager conditionDataManager,
            IItemFromListProvider itemFromListProvider,
            IHistoryManager historyManager,
            IEnumerable <ICondition>?conditions,
            int conditionSourceType)
        {
            this.conditionsFactory    = conditionsFactory;
            this.conditionDataManager = conditionDataManager;
            this.HistoryManager       = historyManager;

            ConditionTypes = conditionDataManager
                             .GetConditionGroups()
                             .SelectMany(group => group.Members)
                             .Where(conditionDataManager.HasConditionData)
                             .Select(conditionDataManager.GetConditionData)
                             .ToList();

            if (conditions != null)
            {
                int previousElseGroup = -1;
                foreach (var c in conditions)
                {
                    var vm = conditionsFactory.Create(conditionSourceType, c);
                    if (vm == null)
                    {
                        continue;
                    }

                    if (c.ElseGroup != previousElseGroup && previousElseGroup != -1)
                    {
                        Conditions.Add(conditionsFactory.CreateOr(conditionSourceType));
                    }

                    previousElseGroup = c.ElseGroup;
                    Conditions.Add(vm);
                }
            }

            Accept      = new DelegateCommand(() => CloseOk?.Invoke());
            Cancel      = new DelegateCommand(() => CloseCancel?.Invoke());
            PickCommand = new AsyncAutoCommand <ParameterValueHolder <long> >(async prh =>
            {
                if (!prh.HasItems)
                {
                    return;
                }

                var newItem = await itemFromListProvider.GetItemFromList(prh.Parameter.Items, prh.Parameter is FlagParameter, prh.Value);
                if (newItem.HasValue)
                {
                    prh.Value = newItem.Value;
                }
            });
            AddItemCommand = new DelegateCommand(() =>
            {
                int index = Conditions.Count;
                if (SelectedCondition != null)
                {
                    index = Conditions.IndexOf(SelectedCondition) + 1;
                }
                index = Math.Clamp(index, 0, Conditions.Count);

                Conditions.Insert(index, conditionsFactory.Create(conditionSourceType, 0) ?? conditionsFactory.CreateOr(conditionSourceType));
            });
            RemoveItemCommand = new DelegateCommand(() =>
            {
                if (SelectedCondition == null)
                {
                    return;
                }

                int indexOf = Conditions.IndexOf(SelectedCondition);
                if (indexOf != -1)
                {
                    Conditions.RemoveAt(indexOf);
                    if (indexOf - 1 >= 0 && Conditions.Count > 0)
                    {
                        SelectedCondition = Conditions[indexOf - 1];
                    }
                    else if (Conditions.Count > 0)
                    {
                        SelectedCondition = Conditions[indexOf];
                    }
                }
            }, () => SelectedCondition != null).ObservesProperty(() => SelectedCondition);
            CopyCommand = new DelegateCommand(() =>
            {
                if (SelectedCondition != null)
                {
                    Clipboard = SelectedCondition?.ToCondition(0);
                }
            }, () => SelectedCondition != null).ObservesProperty(() => SelectedCondition);
            CutCommand = new DelegateCommand(() =>
            {
                if (SelectedCondition != null)
                {
                    Clipboard = SelectedCondition?.ToCondition(0);
                    Conditions.Remove(SelectedCondition !);
                    SelectedCondition = null;
                }
            }, () => SelectedCondition != null).ObservesProperty(() => SelectedCondition);
            PasteCommand = new DelegateCommand(() =>
            {
                if (clipboard != null)
                {
                    int indexOf = Conditions.Count;
                    if (SelectedCondition != null)
                    {
                        indexOf = Conditions.IndexOf(SelectedCondition) + 1;
                    }
                    var item = conditionsFactory.Create(conditionSourceType, clipboard);
                    if (item != null)
                    {
                        Conditions.Insert(indexOf, item);
                    }
                }
            }, () => Clipboard != null).ObservesProperty(() => Clipboard);

            UndoCommand =
                new DelegateCommand(HistoryManager.Undo, () => HistoryManager.CanUndo).ObservesProperty(() =>
                                                                                                        HistoryManager.CanUndo);
            RedoCommand =
                new DelegateCommand(HistoryManager.Redo, () => HistoryManager.CanRedo).ObservesProperty(() =>
                                                                                                        HistoryManager.CanRedo);

            Watch(this, t => t.SelectedCondition, nameof(SelectedConditionsType));

            historyHandler = AutoDispose(new ConditionsEditorHistoryHandler(this, conditionsFactory));
            HistoryManager.AddHandler(historyHandler);
        }
示例#19
0
 public PacketDocumentSolutionItemWithCustomVersionProvider(IWindowManager windowManager, IItemFromListProvider itemFromListProvider)
 {
     this.windowManager        = windowManager;
     this.itemFromListProvider = itemFromListProvider;
 }
示例#20
0
        public SmartScriptEditorViewModel(IHistoryManager history,
                                          IDatabaseProvider database,
                                          IEventAggregator eventAggregator,
                                          ISmartDataManager smartDataManager,
                                          ISmartFactory smartFactory,
                                          IItemFromListProvider itemFromListProvider,
                                          ISmartTypeListProvider smartTypeListProvider,
                                          IStatusBar statusbar,
                                          ISolutionItemNameRegistry itemNameRegistry)
        {
            this.history               = history;
            this.database              = database;
            this.smartDataManager      = smartDataManager;
            this.smartFactory          = smartFactory;
            this.itemFromListProvider  = itemFromListProvider;
            this.smartTypeListProvider = smartTypeListProvider;
            this.statusbar             = statusbar;
            this.itemNameRegistry      = itemNameRegistry;

            EditEvent       = new DelegateCommand(EditEventCommand);
            DeselectActions = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    if (!e.IsSelected)
                    {
                        foreach (var a in e.Actions)
                        {
                            a.IsSelected = false;
                        }
                    }
                }
            });
            DeselectAll = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    foreach (var a in e.Actions)
                    {
                        a.IsSelected = false;
                    }
                    e.IsSelected = false;
                }
            });
            DeselectAllEvents = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    e.IsSelected = false;
                }
            });
            OnDropItems = new DelegateCommand <int?>(destIndex =>
            {
                using (script.BulkEdit("Reorder events"))
                {
                    var selected = new List <SmartEvent>();
                    int d        = destIndex.Value;
                    for (int i = Events.Count - 1; i >= 0; --i)
                    {
                        if (Events[i].IsSelected)
                        {
                            if (i <= destIndex)
                            {
                                d--;
                            }
                            selected.Add(Events[i]);
                            script.Events.RemoveAt(i);
                        }
                    }
                    if (d == -1)
                    {
                        d = 0;
                    }
                    selected.Reverse();
                    foreach (var s in selected)
                    {
                        script.Events.Insert(d++, s);
                    }
                }
            });
            OnDropActions = new DelegateCommand <DropActionsArgs>(data =>
            {
                using (script.BulkEdit("Reorder actions"))
                {
                    var selected = new List <SmartAction>();
                    var d        = data.ActionIndex;
                    for (var eventIndex = 0; eventIndex < Events.Count; eventIndex++)
                    {
                        var e = Events[eventIndex];
                        for (int i = e.Actions.Count - 1; i >= 0; --i)
                        {
                            if (e.Actions[i].IsSelected)
                            {
                                if (eventIndex == data.EventIndex && i < data.ActionIndex)
                                {
                                    d--;
                                }
                                selected.Add(e.Actions[i]);
                                e.Actions.RemoveAt(i);
                            }
                        }
                    }
                    selected.Reverse();
                    foreach (var s in selected)
                    {
                        Events[data.EventIndex].Actions.Insert(d++, s);
                    }
                }
            });
            EditAction = new DelegateCommand <SmartAction>(action => EditActionCommand(action));
            AddEvent   = new DelegateCommand(AddEventCommand);
            AddAction  = new DelegateCommand <NewActionViewModel>(AddActionCommand);

            SaveCommand = new AsyncAutoCommand(SaveAllToDb, null, e =>
            {
                statusbar.PublishNotification(new PlainNotification(NotificationType.Error, "Error while saving script to the database: " + e.Message));
            });

            DeleteAction   = new DelegateCommand <SmartAction>(DeleteActionCommand);
            DeleteSelected = new DelegateCommand(() =>
            {
                if (anyEventSelected)
                {
                    using (script.BulkEdit("Delete events"))
                    {
                        int?nextSelect = firstSelectedIndex;
                        if (multipleEventsSelected)
                        {
                            nextSelect = null;
                        }

                        for (int i = Events.Count - 1; i >= 0; --i)
                        {
                            if (Events[i].IsSelected)
                            {
                                Events.RemoveAt(i);
                            }
                        }

                        if (nextSelect.HasValue)
                        {
                            if (nextSelect.Value < Events.Count)
                            {
                                Events[nextSelect.Value].IsSelected = true;
                            }
                            else if (nextSelect.Value - 1 >= 0 && nextSelect.Value - 1 < Events.Count)
                            {
                                Events[nextSelect.Value - 1].IsSelected = true;
                            }
                        }
                    }
                }
                else if (anyActionSelected)
                {
                    using (script.BulkEdit("Delete actions"))
                    {
                        (int eventIndex, int actionIndex)? nextSelect = firstSelectedActionIndex;
                        if (multipleActionsSelected)
                        {
                            nextSelect = null;
                        }

                        for (int i = 0; i < Events.Count; ++i)
                        {
                            var e = Events[i];
                            for (int j = e.Actions.Count - 1; j >= 0; --j)
                            {
                                if (e.Actions[j].IsSelected)
                                {
                                    e.Actions.RemoveAt(j);
                                }
                            }
                        }

                        if (nextSelect.HasValue && nextSelect.Value.actionIndex < Events[nextSelect.Value.eventIndex].Actions.Count)
                        {
                            Events[nextSelect.Value.eventIndex].Actions[nextSelect.Value.actionIndex].IsSelected = true;
                        }
                    }
                }
            });

            UndoCommand = new DelegateCommand(history.Undo, () => history.CanUndo);
            RedoCommand = new DelegateCommand(history.Redo, () => history.CanRedo);

            EditSelected = new DelegateCommand(() =>
            {
                if (anyEventSelected)
                {
                    if (!multipleEventsSelected)
                    {
                        EditEventCommand();
                    }
                }
                else if (anyActionSelected && !multipleActionsSelected)
                {
                    EditActionCommand(Events[firstSelectedActionIndex.eventIndex]
                                      .Actions[firstSelectedActionIndex.actionIndex]);
                }
            });

            CopyCommand = new DelegateCommand(() =>
            {
                var selectedEvents = Events.Where(e => e.IsSelected).ToList();
                if (selectedEvents.Count > 0)
                {
                    var lines = string.Join("\n",
                                            selectedEvents.SelectMany((e, index) => e.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, index)).Select(s => s.ToSqlString()));
                    Clipboard.SetText(lines);
                }
                else
                {
                    var selectedActions = Events.SelectMany(e => e.Actions).Where(e => e.IsSelected).ToList();
                    if (selectedActions.Count > 0)
                    {
                        var fakeEvent = new SmartEvent(-1)
                        {
                            ReadableHint = ""
                        };
                        foreach (var a in selectedActions)
                        {
                            fakeEvent.AddAction(a.Copy());
                        }
                        var lines = string.Join("\n", fakeEvent.ToSmartScriptLines(script.EntryOrGuid, script.SourceType, 0).Select(s => s.ToSqlString()));
                        Clipboard.SetText(lines);
                    }
                }
            });
            CutCommand = new DelegateCommand(() =>
            {
                CopyCommand.Execute();
                DeleteSelected.Execute();
            });
            PasteCommand = new DelegateCommand(() =>
            {
                var lines = (Clipboard.GetText() ?? "").Split('\n').Select(line =>
                {
                    if (line.TryToISmartScriptLine(out var s))
                    {
                        return(s);
                    }
                    return(null);
                }).Where(l => l != null).ToList();
                if (lines.Count > 0)
                {
                    if (lines[0].EventType == -1) // actions
                    {
                        int?eventIndex  = null;
                        int?actionIndex = null;
                        using (script.BulkEdit("Paste actions"))
                        {
                            for (int i = 0; i < Events.Count - 1; ++i)
                            {
                                if (Events[i].IsSelected)
                                {
                                    eventIndex = i;
                                }

                                for (int j = Events[i].Actions.Count - 1; j >= 0; j--)
                                {
                                    if (Events[i].Actions[j].IsSelected)
                                    {
                                        eventIndex = i;
                                        if (!actionIndex.HasValue)
                                        {
                                            actionIndex = j;
                                        }
                                        else
                                        {
                                            actionIndex--;
                                        }
                                        //Events[i].Actions.RemoveAt(j);
                                    }
                                }
                            }

                            if (!eventIndex.HasValue)
                            {
                                eventIndex = Events.Count - 1;
                            }

                            if (eventIndex < 0)
                            {
                                return;
                            }

                            if (!actionIndex.HasValue)
                            {
                                actionIndex = Events[eventIndex.Value].Actions.Count - 1;
                            }

                            if (actionIndex < 0)
                            {
                                actionIndex = 0;
                            }

                            DeselectAll.Execute();
                            foreach (var smartAction in lines.Select(line => script.SafeActionFactory(line)))
                            {
                                Events[eventIndex.Value].Actions.Insert(actionIndex.Value, smartAction);
                                smartAction.IsSelected = true;
                                actionIndex++;
                            }
                        }
                    }
                    else
                    {
                        int?index = null;
                        using (script.BulkEdit("Paste events"))
                        {
                            for (int i = Events.Count - 1; i >= 0; --i)
                            {
                                if (Events[i].IsSelected)
                                {
                                    if (!index.HasValue)
                                    {
                                        index = i;
                                    }
                                    else
                                    {
                                        index--;
                                    }
                                    //Events.RemoveAt(i);
                                }
                            }
                            if (!index.HasValue)
                            {
                                index = Events.Count;
                            }
                            script.InsertFromClipboard(index.Value, lines);
                        }
                    }
                }
            });

            Action <bool, int> selectionUpDown = (addToSelection, diff) =>
            {
                if (anyEventSelected)
                {
                    var selectedEventIndex = Math.Clamp(firstSelectedIndex + diff, 0, Events.Count - 1);
                    if (!addToSelection)
                    {
                        DeselectAll.Execute();
                    }
                    Events[selectedEventIndex].IsSelected = true;
                }
                else if (anyActionSelected)
                {
                    var nextActionIndex = firstSelectedActionIndex.actionIndex + diff;
                    var nextEventIndex  = firstSelectedActionIndex.eventIndex;
                    while (nextActionIndex == -1 || nextActionIndex >= Events[nextEventIndex].Actions.Count)
                    {
                        nextEventIndex += diff;
                        if (nextEventIndex >= 0 && nextEventIndex < Events.Count)
                        {
                            nextActionIndex = diff > 0 ? (Events[nextEventIndex].Actions.Count > 0 ? 0 : -1) : Events[nextEventIndex].Actions.Count - 1;
                        }
                        else
                        {
                            break;
                        }
                    }

                    if (nextActionIndex != -1 && nextEventIndex >= 0 && nextEventIndex < Events.Count)
                    {
                        DeselectAll.Execute();
                        Events[nextEventIndex].Actions[nextActionIndex].IsSelected = true;
                    }
                }
                else
                {
                    if (Events.Count > 0)
                    {
                        Events[diff > 0 ? 0 : Events.Count - 1].IsSelected = true;
                    }
                }
            };

            SelectionUp   = new DelegateCommand <bool?>(addToSelection => selectionUpDown(addToSelection ?? false, -1));
            SelectionDown = new DelegateCommand <bool?>(addToSelection => selectionUpDown(addToSelection ?? false, 1));
            SelectionLeft = new DelegateCommand(() =>
            {
                if (!anyEventSelected && anyActionSelected)
                {
                    var actionEventIndex = firstSelectedActionIndex;
                    DeselectAll.Execute();
                    Events[actionEventIndex.eventIndex].IsSelected = true;
                }
                else if (!anyEventSelected && !anyActionSelected)
                {
                    selectionUpDown(false, -1);
                }
            });
            SelectionRight = new DelegateCommand(() =>
            {
                if (!anyEventSelected)
                {
                    selectionUpDown(false, -1);
                }
                if (anyEventSelected)
                {
                    var eventIndex = firstSelectedIndex;
                    if (Events[eventIndex].Actions.Count > 0)
                    {
                        DeselectAll.Execute();
                        Events[eventIndex].Actions[0].IsSelected = true;
                    }
                }
            });

            SelectAll = new DelegateCommand(() =>
            {
                foreach (var e in Events)
                {
                    e.IsSelected = true;
                }
            });

            this.history.PropertyChanged += (sender, args) =>
            {
                UndoCommand.RaiseCanExecuteChanged();
                RedoCommand.RaiseCanExecuteChanged();
            };

            token = eventAggregator.GetEvent <EventRequestGenerateSql>().Subscribe((args) =>
            {
                if (args.Item is SmartScriptSolutionItem)
                {
                    var itemm = args.Item as SmartScriptSolutionItem;
                    if (itemm.Entry == _item.Entry && itemm.SmartType == _item.SmartType)
                    {
                        args.Sql = new SmartScriptExporter(script, smartFactory).GetSql();
                    }
                }
            });
        }
示例#21
0
 public ParametersEditViewModel(IItemFromListProvider itemFromListProvider,
                                SmartBaseElement element,
                                bool focusFirst,
                                IEnumerable <(ParameterValueHolder <int> parameter, string name)> parameters,
示例#22
0
 public ParameterPickerService(IItemFromListProvider itemFromListProvider)
 {
     this.itemFromListProvider = itemFromListProvider;
 }