Beispiel #1
0
        /// <summary>
        /// handles the action window getting focus
        /// </summary>
        public void OnEnter()
        {
            ThemeManager.SetupTextEditor(AceTextEditor, Syntax.Json);
            ThemeManager.SetupTextEditor(LanguageTextEditor, Syntax.Json);
            ThemeManager.SetupTextEditor(CodeTextEditor, Syntax.Javascript);
            ThemeManager.SetupSearchPanel(acePanel, langPanel, codePanel);

            if (AddonManager.CurrentAddon != null)
            {
                _actions = AddonManager.CurrentAddon.Actions;
                ActionListBox.ItemsSource = _actions;

                if (_actions.Any())
                {
                    ActionListBox.SelectedIndex = 0;
                    _selectedAction             = _actions.Values.First();
                    AceTextEditor.Text          = _selectedAction.Ace;
                    LanguageTextEditor.Text     = _selectedAction.Language;
                    CodeTextEditor.Text         = _selectedAction.Code;
                    Category.Text = _selectedAction.Category;
                }
            }
            else
            {
                ActionListBox.ItemsSource = null;
                AceTextEditor.Text        = string.Empty;
                LanguageTextEditor.Text   = string.Empty;
                CodeTextEditor.Text       = string.Empty;
                Category.Text             = string.Empty;
            }

            folding.UpdateFoldings(aceFoldingManager, CodeTextEditor.Document);
        }
Beispiel #2
0
        /// <summary>
        /// handles switching actions
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ActionListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (ActionListBox.SelectedIndex == -1)
            {
                return;
            }

            //save current selection
            if (_selectedAction != null)
            {
                _selectedAction.Ace               = AceTextEditor.Text;
                _selectedAction.Language          = LanguageTextEditor.Text;
                _selectedAction.Code              = CodeTextEditor.Text;
                _selectedAction.Category          = Category.Text;
                _actions[_selectedAction.Id]      = _selectedAction;
                AddonManager.CurrentAddon.Actions = _actions;
                AddonManager.SaveCurrentAddon();
            }

            //load new selection
            var selectedKey = ((KeyValuePair <string, Action>)ActionListBox.SelectedItem).Key;

            _selectedAction = _actions[selectedKey];

            Category.Text           = _selectedAction.Category;
            AceTextEditor.Text      = _selectedAction.Ace;
            LanguageTextEditor.Text = _selectedAction.Language;
            CodeTextEditor.Text     = _selectedAction.Code;

            folding.UpdateFoldings(aceFoldingManager, CodeTextEditor.Document);
        }
Beispiel #3
0
 /// <summary>
 /// clears all input in action window
 /// </summary>
 public void Clear()
 {
     _actions                  = new Dictionary <string, Action>();
     _selectedAction           = null;
     ActionListBox.ItemsSource = null;
     AceTextEditor.Text        = string.Empty;
     CodeTextEditor.Text       = string.Empty;
     LanguageTextEditor.Text   = string.Empty;
     Category.Text             = string.Empty;
 }
Beispiel #4
0
        public void C2AcesToAction(C3Addon addon, C2Ace ace)
        {
            try
            {
                var action = new Action
                {
                    Category    = ace.Category.ToLower(),
                    Id          = ace.ScriptName.SplitCamelCase("-"),
                    DisplayText = ace.DisplayString,
                    ListName    = ace.ListName,
                    Description = ace.Description,
                    Highlight   = "false",
                    C2Id        = ace.Id,
                    Deprecated  = ace.Flags.Contains("af_deprecated").ToString().ToLower()
                };

                if (ace.Params.Any())
                {
                    action.Ace      = TemplateCompiler.Insatnce.CompileTemplates(C2TemplateHelper.ActionAceImport, action);
                    action.Language = TemplateCompiler.Insatnce.CompileTemplates(addon.Template.ActionLanguage, action);
                    action.Code     = TemplateCompiler.Insatnce.CompileTemplates(addon.Template.ActionCode, action);

                    var paramId = 0;
                    //action params
                    foreach (var param in ace.Params)
                    {
                        var paramType = ResolveParamType(param);
                        action = paramType == "combo"
                            ? AceParameterHelper.Insatnce.GenerateParam(action, $"param{paramId}", paramType, param.DefaultValue, $"param{paramId}", param.Description, param.ComboItems)
                            : AceParameterHelper.Insatnce.GenerateParam(action, $"param{paramId}", paramType, param.DefaultValue, $"param{paramId}", param.Description);
                        paramId++;
                    }
                }
                else
                {
                    action.Ace      = TemplateCompiler.Insatnce.CompileTemplates(C2TemplateHelper.ActionAceImport, action);
                    action.Language = TemplateCompiler.Insatnce.CompileTemplates(addon.Template.ActionLanguage, action);
                    action.Code     = TemplateCompiler.Insatnce.CompileTemplates(addon.Template.ActionCode, action);
                }

                addon.Actions.Add(action.Id, action);
            }
            catch (Exception ex)
            {
                LogManager.AddImportLogMessage($"ERROR => \n{ex.Message}");
                LogManager.AddImportLogMessage($"STACK TRACE => \n{ex.StackTrace}");
                return;
            }
        }
Beispiel #5
0
        /// <summary>
        /// handles the save button on the add new action child window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveActionButton_Click(object sender, RoutedEventArgs e)
        {
            var id          = ActionIdText.Text.ToLower().Replace(" ", "-");
            var category    = ActionCategoryText.Text;
            var list        = ActionListNameText.Text;
            var highlight   = HighlightDropdown.Text;
            var async       = AsyncDropdown.Text == "yes" ? true : false;
            var displayText = DisplayText.Text;
            var desc        = DescriptionText.Text.Replace("\"", "\\\"");

            if (_actions.ContainsKey(id))
            {
                NotificationManager.PublishErrorNotification("action id already exists");
                return;
            }

            var action = new Action
            {
                Id          = id.Trim().ToLower(),
                Category    = category.Trim().ToLower(),
                Highlight   = highlight,
                DisplayText = displayText,
                Description = desc,
                ListName    = list,
                Async       = async ? ",\n\t\"isAsync\": true" : string.Empty
            };

            action.Ace      = TemplateCompiler.Insatnce.CompileTemplates(AddonManager.CurrentAddon.Template.ActionAces, action);
            action.Language = TemplateCompiler.Insatnce.CompileTemplates(AddonManager.CurrentAddon.Template.ActionLanguage, action);
            action.Code     = TemplateCompiler.Insatnce.CompileTemplates(AddonManager.CurrentAddon.Template.ActionCode, action);

            if (async)
            {
                action.Code = $"async {action.Code}";
            }

            _actions.Add(id, action);
            ActionListBox.Items.Refresh();
            ActionListBox.SelectedIndex = _actions.Count - 1;

            AddonManager.CurrentAddon.Actions = _actions;
            NewActionWindow.IsOpen            = false;
        }
Beispiel #6
0
        /// <summary>
        /// removes the selected action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void RemoveAction_OnClick(object sender, RoutedEventArgs e)
        {
            if (_selectedAction != null)
            {
                _actions.Remove(_selectedAction.Id);
                ActionListBox.ItemsSource = _actions;
                ActionListBox.Items.Refresh();

                //clear editors
                AceTextEditor.Text      = string.Empty;
                LanguageTextEditor.Text = string.Empty;
                CodeTextEditor.Text     = string.Empty;
                _selectedAction         = null;
            }
            else
            {
                NotificationManager.PublishErrorNotification("failed to remove action, no action selected");
            }
        }