public SmartScriptBase(ISmartFactory smartFactory,
                               ISmartDataManager smartDataManager,
                               IMessageBoxService messageBoxService)
        {
            this.smartFactory      = smartFactory;
            this.smartDataManager  = smartDataManager;
            this.messageBoxService = messageBoxService;
            Events          = new ObservableCollection <SmartEvent>();
            selectionHelper = new SmartSelectionHelper(this);
            selectionHelper.ScriptSelectedChanged += CallScriptSelectedChanged;
            selectionHelper.EventChanged          += (e, a, mask) =>
            {
                RenumerateEvents();
                EventChanged?.Invoke(e, a, mask);
            };
            AllSmartObjectsFlat = selectionHelper.AllSmartObjectsFlat;
            AllActions          = selectionHelper.AllActions;

            Events.ToStream()
            .Subscribe((e) =>
            {
                if (e.Type == CollectionEventType.Add)
                {
                    e.Item.Parent = this;
                }
            });
        }
示例#2
0
 public SmartFactory(IParameterFactory parameterFactory,
                     ISmartDataManager smartDataManager,
                     IConditionDataManager conditionDataManager)
 {
     this.parameterFactory     = parameterFactory;
     this.smartDataManager     = smartDataManager;
     this.conditionDataManager = conditionDataManager;
 }
示例#3
0
 public TrinityCoreSmartScriptImporter(ISmartFactory smartFactory,
                                       ISmartDataManager smartDataManager,
                                       IMessageBoxService messageBoxService)
 {
     this.smartFactory      = smartFactory;
     this.smartDataManager  = smartDataManager;
     this.messageBoxService = messageBoxService;
 }
示例#4
0
 public SmartScript(ISmartScriptSolutionItem item,
                    ISmartFactory smartFactory,
                    ISmartDataManager smartDataManager,
                    IMessageBoxService messageBoxService) : base(smartFactory, smartDataManager, messageBoxService)
 {
     EntryOrGuid = (int)item.Entry;
     SourceType  = item.SmartType;
 }
示例#5
0
 public SmartTypeListProvider(IWindowManager windowManager,
                              ISmartDataManager smartDataManager,
                              IConditionDataManager conditionDataManager,
                              IFavouriteSmartsService favouriteSmartsService)
 {
     this.windowManager          = windowManager;
     this.smartDataManager       = smartDataManager;
     this.conditionDataManager   = conditionDataManager;
     this.favouriteSmartsService = favouriteSmartsService;
 }
示例#6
0
 public NoWaitInDeathEventInspection(ISmartDataManager smartDataManager)
 {
     foreach (var a in smartDataManager.GetAllData(SmartType.SmartAction))
     {
         if (a.Flags.HasFlag(ActionFlags.WaitAction))
         {
             waitActionId = a.Id;
         }
     }
 }
 public TrinityCoreSmartScriptImporter(ISmartFactory smartFactory,
                                       ISmartDataManager smartDataManager,
                                       IMessageBoxService messageBoxService,
                                       IDatabaseProvider databaseProvider)
 {
     this.smartFactory      = smartFactory;
     this.smartDataManager  = smartDataManager;
     this.messageBoxService = messageBoxService;
     this.databaseProvider  = databaseProvider;
 }
 public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory,
                                       ISmartDataManager smartDataManager,
                                       ICurrentCoreVersion currentCoreVersion,
                                       IConditionQueryGenerator conditionQueryGenerator)
 {
     this.smartFactory            = smartFactory;
     this.smartDataManager        = smartDataManager;
     this.currentCoreVersion      = currentCoreVersion;
     this.conditionQueryGenerator = conditionQueryGenerator;
 }
示例#9
0
 public SmartScriptBaseFindAnywhereSource(ISmartDataManager smartDataManager,
                                          ISmartScriptDatabaseProvider databaseProvider,
                                          IEditorFeatures editorFeatures,
                                          ISolutionItemNameRegistry nameRegistry,
                                          ISolutionItemIconRegistry iconRegistry)
 {
     this.smartDataManager = smartDataManager;
     this.databaseProvider = databaseProvider;
     this.editorFeatures   = editorFeatures;
     this.nameRegistry     = nameRegistry;
     this.iconRegistry     = iconRegistry;
 }
示例#10
0
 public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory,
                                       ISmartDataManager smartDataManager,
                                       ICurrentCoreVersion currentCoreVersion,
                                       ISolutionItemNameRegistry nameRegistry,
                                       IDatabaseProvider databaseProvider,
                                       IConditionQueryGenerator conditionQueryGenerator)
 {
     this.smartFactory            = smartFactory;
     this.smartDataManager        = smartDataManager;
     this.currentCoreVersion      = currentCoreVersion;
     this.nameRegistry            = nameRegistry;
     this.databaseProvider        = databaseProvider;
     this.conditionQueryGenerator = conditionQueryGenerator;
 }
示例#11
0
 public WaitInCombatEventInspection(ISmartDataManager smartDataManager)
 {
     foreach (var a in smartDataManager.GetAllData(SmartType.SmartAction))
     {
         if (a.Flags.HasFlag(ActionFlags.WaitAction))
         {
             waitActionId = a.Id;
         }
         else if (a.NameReadable == "Disable reset AI state")
         {
             disableResetAi = a.Id;
         }
     }
 }
        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 DelegateCommand <SmartGenericJsonData?>(ShowEditorWindow);
            CreateNew      = new DelegateCommand(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);
        }
        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
        public SmartFactory(IParameterFactory parameterFactory,
                            ISmartDataManager smartDataManager,
                            IConditionDataManager conditionDataManager)
        {
            this.parameterFactory     = parameterFactory;
            this.smartDataManager     = smartDataManager;
            this.conditionDataManager = conditionDataManager;

            if (!parameterFactory.IsRegisteredLong("StoredTargetParameter"))
            {
                parameterFactory.Register("StoredTargetParameter", new VariableContextualParameter(GlobalVariableType.StoredTarget, "storedTarget"));
                parameterFactory.Register("DataVariableParameter", new VariableContextualParameter(GlobalVariableType.DataVariable, "data"));
                parameterFactory.Register("TimedEventParameter", new VariableContextualParameter(GlobalVariableType.TimedEvent, "timedEvent"));
                parameterFactory.Register("DoActionParameter", new VariableContextualParameter(GlobalVariableType.Action, "action"));
                parameterFactory.Register("DoFunctionParameter", new VariableContextualParameter(GlobalVariableType.Function, "function"));
                parameterFactory.Register("StoredPointParameter", new VariableContextualParameter(GlobalVariableType.StoredPoint, "storedPoint"));
                parameterFactory.Register("DatabasePointParameter", new VariableContextualParameter(GlobalVariableType.DatabasePoint, "databasePoint"));
            }
        }
示例#15
0
 public SmartScriptEditorProvider(
     ISolutionItemNameRegistry solutionItemNameRegistry,
     IHistoryManager historyManager,
     IDatabaseProvider databaseProvider,
     IEventAggregator eventAggregator,
     ISmartDataManager smartDataManager,
     ISmartFactory smartFactory,
     IItemFromListProvider itemFromListProvider,
     SmartTypeListProvider smartTypeListProvider
     )
 {
     this.solutionItemNameRegistry = solutionItemNameRegistry;
     this.historyManager           = historyManager;
     this.databaseProvider         = databaseProvider;
     this.eventAggregator          = eventAggregator;
     this.smartDataManager         = smartDataManager;
     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")));
            }
        }
示例#17
0
        public SmartScript(ISmartScriptSolutionItem item,
                           ISmartFactory smartFactory,
                           ISmartDataManager smartDataManager,
                           IMessageBoxService messageBoxService)
        {
            this.smartFactory      = smartFactory;
            this.smartDataManager  = smartDataManager;
            this.messageBoxService = messageBoxService;
            EntryOrGuid            = (int)item.Entry;
            SourceType             = item.SmartType;
            Events          = new ObservableCollection <SmartEvent>();
            selectionHelper = new SmartSelectionHelper(this);
            selectionHelper.ScriptSelectedChanged += CallScriptSelectedChanged;
            AllSmartObjectsFlat = selectionHelper.AllSmartObjectsFlat;

            Events.ToStream()
            .Subscribe((e) =>
            {
                if (e.Type == CollectionEventType.Add)
                {
                    e.Item.Parent = this;
                }
            });
        }
        public SmartSelectViewModel(string file, SmartType type, Func <SmartGenericJsonData, bool> predicate, ISmartDataManager smartDataManager)
        {
            _predicate = predicate;
            string group = null;

            foreach (string line in File.ReadLines("SmartData/" + file))
            {
                if (line.IndexOf(" ", StringComparison.Ordinal) == 0)
                {
                    if (!smartDataManager.Contains(type, line.Trim()))
                    {
                        continue;
                    }

                    SmartItem i    = new SmartItem();
                    var       data = smartDataManager.GetDataByName(type, line.Trim());

                    i.Group      = group;
                    i.Name       = data.NameReadable;
                    i.Id         = data.Id;
                    i.Help       = data.Help;
                    i.Deprecated = data.Deprecated;
                    i.Data       = data;

                    _allItems.Add(i);
                }
                else
                {
                    group = line;
                }
            }

            _items        = new CollectionViewSource();
            _items.Source = _allItems;
            _items.GroupDescriptions.Add(new PropertyGroupDescription("Group"));
            _items.Filter += ItemsOnFilter;

            if (_items.View.MoveCurrentToFirst())
            {
                SelectedItem = _items.View.CurrentItem as SmartItem;
            }
        }
示例#19
0
 public TrinityCoreSmartScriptExporter(ISmartFactory smartFactory, ISmartDataManager smartDataManager)
 {
     this.smartFactory     = smartFactory;
     this.smartDataManager = smartDataManager;
 }
示例#20
0
 public SmartTypeListProvider(ISmartDataManager smartDataManager)
 {
     this.smartDataManager = smartDataManager;
 }
示例#21
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();
                    }
                }
            });
        }
示例#22
0
 public SmartTypeListProvider(IWindowManager windowManager, ISmartDataManager smartDataManager, IConditionDataManager conditionDataManager)
 {
     this.windowManager        = windowManager;
     this.smartDataManager     = smartDataManager;
     this.conditionDataManager = conditionDataManager;
 }
示例#23
0
 public SmartFactory(IParameterFactory parameterFactory, ISmartDataManager smartDataManager)
 {
     _parameterFactory     = parameterFactory;
     this.smartDataManager = smartDataManager;
 }
        public SmartDataEditorsProvider(ISmartRawDataProvider smartDataProvider, IParameterFactory parameterFactory, ISmartDataManager smartDataManager,
                                        ITaskRunner taskRunner, IMessageBoxService messageBoxService, IWindowManager windowManager, Func <IHistoryManager> historyCreator)
        {
            var editors = new List <IMenuItem> {
                new SmartDataCategoryMenuItemProvider <SmartDataDefinesListViewModel>("Events", new object[] { smartDataProvider, smartDataManager, parameterFactory,
                                                                                                               taskRunner, messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_EVENTS }),
                new SmartDataCategoryMenuItemProvider <SmartDataDefinesListViewModel>("Actions", new object[] { smartDataProvider, smartDataManager, parameterFactory,
                                                                                                                taskRunner, messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_ACTIONS }),
                new SmartDataCategoryMenuItemProvider <SmartDataDefinesListViewModel>("Targets", new object[] { smartDataProvider, smartDataManager, parameterFactory,
                                                                                                                taskRunner, messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_TARGETS }),
                new SmartDataCategoryMenuItemProvider <SmartDataGroupsEditorViewModel>("Event Groups", new object[] { smartDataProvider, taskRunner,
                                                                                                                      messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_EVENTS }),
                new SmartDataCategoryMenuItemProvider <SmartDataGroupsEditorViewModel>("Action Groups", new object[] { smartDataProvider, taskRunner,
                                                                                                                       messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_ACTIONS }),
                new SmartDataCategoryMenuItemProvider <SmartDataGroupsEditorViewModel>("Target Groups", new object[] { smartDataProvider, taskRunner,
                                                                                                                       messageBoxService, windowManager, historyCreator, SmartDataSourceMode.SD_SOURCE_TARGETS }),
            };

            var saiCategory = new List <IMenuItem> {
                new SmartDataCategoryItem("Smart Scripts", editors)
            };
            IMenuCategoryItem obj = new SmartDataCategoryItem("Smart Data", saiCategory);

            SubItems = new List <IMenuItem>()
            {
                obj
            };
        }
示例#25
0
 public TrinitySmartScriptFindAnywhereSource(ISmartDataManager smartDataManager, ISmartScriptDatabaseProvider databaseProvider, IEditorFeatures editorFeatures, ISolutionItemNameRegistry nameRegistry, ISolutionItemIconRegistry iconRegistry) : base(smartDataManager, databaseProvider, editorFeatures, nameRegistry, iconRegistry)
 {
 }