Exemple #1
0
        private async void CommandButton_Clicked(object sender, EventArgs e)
        {
            CommandButton button     = sender as CommandButton;
            CommandDef    commandDef = (sender as CommandButton)?.CommandDef;

            if (commandDef == null)
            {
                return;
            }

            if (commandDef.UserInput)
            {
                string result = await DisplayPromptAsync(commandDef.PromptTitle, commandDef.PromptMessage);

                if (!string.IsNullOrEmpty(result))
                {
                    string cmd = string.Format(commandDef.CommandFormat, result);
                    DisplayCommandResponse(_piSystemClient?.Post(cmd));
                }
            }
            else
            {
                if (commandDef.UserConfirm)
                {
                    bool answer = await DisplayAlert(commandDef.Name, "Do you really want to send the command?", "Yes", "Cancel");

                    if (!answer)
                    {
                        return;
                    }
                }
                DisplayCommandResponse(_piSystemClient?.Post(commandDef.Command));
            }
        }
 public void FallToDefaultHookWithEmptyArgs() {
     var defaultHookPopulated = false;
     var options = new CommandDef(() => defaultHookPopulated = true) {
         {'h', "Print help message", () => { }}
     };
     var extraArgs = options.Parse(new string[] {});
     Assert.Empty(extraArgs);
     Assert.True(defaultHookPopulated);
 }
        private static MyCommandDef makeCommand(CommandIds commandId, Record fromRecord)
        {
            CommandDef commandDef   = new CommandDef(commandId, fromRecord.Database);
            var        myCommandDef = new MyCommandDef();

            myCommandDef.CommandId        = (HP.HPTRIM.ServiceModel.CommandIds)commandId;
            myCommandDef.MenuEntryString  = commandDef.GetMenuEntryString(fromRecord.TrimType);
            myCommandDef.Tooltip          = commandDef.GetTooltip(fromRecord.TrimType);
            myCommandDef.StatusBarMessage = commandDef.GetStatusBarMessage(fromRecord.TrimType);
            myCommandDef.IsEnabled        = commandDef.IsEnabled(fromRecord);

            return(myCommandDef);
        }
Exemple #4
0
        /// <summary>
        /// Registers a command for a command client.
        /// NOTE: CommandInfo.MenuItem and CommandInfo.Button will not be valid.
        /// Shortcut related properties and methods on CommandInfo will have no effect.</summary>
        /// <param name="info">Command description; standard commands are defined as static
        /// members on the CommandInfo class</param>
        /// <param name="client">Client that handles the command</param>
        public void RegisterCommand(Sce.Atf.Applications.CommandInfo info, Sce.Atf.Applications.ICommandClient client)
        {
            // Embedded image resources will not be available as WPF app resources
            // If image resource does not exist we need to create it and add it to app resources
            object imageResourceKey = null;

            if (!string.IsNullOrEmpty(info.ImageName))
            {
                var embeddedImage = ResourceUtil.GetImage(info.ImageName);
                if (embeddedImage == null)
                {
                    throw new InvalidOperationException("Could not find embedded image: " + info.ImageName);
                }

                Util.GetOrCreateResourceForEmbeddedImage(embeddedImage);
                imageResourceKey = embeddedImage;
            }

            // Convert text and path
            string displayText = GetDisplayMenuText(info.MenuText);

            info.DisplayedMenuText = displayText;

            string[] menuPath = GetMenuPath(info.MenuText);

            // Convert shortcuts
            var inputGestures = new List <InputGesture>();

            foreach (var formsKey in info.Shortcuts)
            {
                inputGestures.Add(Util.ConvertKey(formsKey));
            }

            // Create and register command passing this as command client
            var def = new CommandDef(
                info.CommandTag,
                info.MenuTag,
                info.GroupTag,
                displayText,
                menuPath,
                info.Description,
                imageResourceKey,
                inputGestures.ToArray <InputGesture>(),
                info.Visibility);

            var clientAdapter = GetOrCreateClientAdapter(client);

            var command = m_commandService.RegisterCommand(def, clientAdapter);

            clientAdapter.AddCommand(command);
        }
Exemple #5
0
        private void DoParameterSuggestions(int termIdx)
        {
            // TODO - null ptr checks for suggestion text box

            CommandDef commandDef = CommandRegistry.GetCommand(UserInputTerms[0]);

            if (!commandDef.IsValid())
            {
                SuggestionText.text = "No Matching Commands!";
                return;
            }
            Assert.IsTrue(commandDef.IsValid());

            if (termIdx < 0 || termIdx >= commandDef.Command.GetNumExpectedTerms())
            {
                return;
            }

            string[] terms = commandDef.GetCommandFormatAsTerms();
            if (termIdx < terms.Length)
            {
                terms[termIdx] = "<b><color=#ffffffff>" + terms[termIdx] + "</color></b>";
            }

            SuggestionText.text += Utils.GetCommand(terms) + "\n";

            string searchTerm       = termIdx < UserInputTerms.Length ? UserInputTerms[termIdx] : "";
            int    paramIdx         = termIdx - 1;
            var    cmd              = commandDef.Command;
            var    paramSuggestions = ParameterProcessorRegistry.FindSuggestionsFor(cmd.GetParamType(paramIdx), cmd.GetParameterAttributes(paramIdx), searchTerm, 20);

            if (paramSuggestions != null)
            {
                string suggestionDisplayPrefix = "";
                for (int i = 0; i < Mathf.Min(terms.Length, termIdx); i++)
                {
                    suggestionDisplayPrefix += terms[i] + " ";
                }

                suggestionDisplayPrefix = "<color=#ffffff00>" + suggestionDisplayPrefix + "</color>";

                for (int i = 0, num = paramSuggestions.Count; i < num; i++)
                {
                    var paramSuggestion = paramSuggestions[i];
                    Suggestions.Add(paramSuggestion);
                    SuggestionText.text += suggestionDisplayPrefix + paramSuggestion.Display + "\n";
                }
            }
        }
Exemple #6
0
        public CommandItem(CommandDef def,
                           Func <object, bool> canExecuteMethod,
                           Action <ICommandItem> executeMethod)
            : base(def.MenuTag, def.GroupTag, def.Text, def.Description)
        {
            m_commandTag     = def.CommandTag;
            m_imageSourceKey = def.ImageSourceKey;
            m_inputGestures  = def.InputGestures;
            m_menuPath       = def.MenuPath;

            // Special hack here - if no menu tag is set then this command is only available
            // in context menus.  Ideally should add CommandVisibility.ContextMenu option
            // for now just use CommandVisibility.None
            m_visibility       = def.MenuTag != null ? def.Visibility : CommandVisibility.None;
            m_canExecuteMethod = canExecuteMethod;
            m_executeMethod    = executeMethod;

            RebuildBinding();
        }
Exemple #7
0
 static void Main(string[] args) {
     var options = new CommandDef(ShortHelp) {
         {'h', "help", "print this message", ShortHelp},
         {"server", "server address", (string v) => _server = v},
         {'u', "user", "user name", (string v) => _username = v},
         {"help", "print detailed help message", new CommandDef(HelpUsage) {
             {"commands", "list all subcommands", new CommandDef(ListSubCommands)},
             {"options", "description of all global options", new CommandDef(ListOptions)},
         }},
         {"checkout", "Checkout files", new CommandDef(Checkout) {
             {'f', "force", "force checkout", () => _forceCheckout = true}
         }},
         {"checkin", "Checkin files", new CommandDef(Checkin) {
             {'a', "all", "checkin all files", () => _checkinAll = true}
         }}
     };
     _extra = options.Parse(args);
     _extra.ForEach(Console.Out.WriteLine);
     Console.Out.WriteLine(_server);
     Console.Out.WriteLine(_username);
 }
Exemple #8
0
        private CommandButton CreateCommandButton(string name, string cmd, string confirmStr)
        {
            if (string.IsNullOrEmpty(cmd))
            {
                return(null);
            }

            // command string syntax: command_text_1 {prompt_title, prompt_message} command_text_2
            bool confirm = false;

            if (!string.IsNullOrEmpty(confirmStr))
            {
                confirm = string.Equals("Yes", confirmStr, StringComparison.OrdinalIgnoreCase);
            }
            CommandDef def = new CommandDef {
                Name = name, Command = cmd, UserConfirm = confirm
            };
            CommandButton button = new CommandButton {
                CommandDef = def, Text = name
            };

            button.Clicked += CommandButton_Clicked;
            int index  = cmd.IndexOf('{');
            int index2 = cmd.IndexOf('}');

            if (index < 0 || index2 < 0 || index + 3 >= index2)
            {
                return(button);                                                // minimum 3 chars like: {a,b}
            }
            def.CommandFormat = cmd.Substring(0, index).Trim() + " {0} ";
            if (index2 < cmd.Length)
            {
                def.CommandFormat += cmd.Substring(index2 + 1).Trim();
            }
            string[] parts = cmd.Substring(index + 1, index2 - index - 1).Split(CommaDelimiter);
            def.PromptTitle   = parts[0].Trim();
            def.PromptMessage = parts[1].Trim();
            def.UserInput     = true;
            return(button);
        }
Exemple #9
0
        private static MyCommandDef makeCommand(CommandIds commandId, TrimMainObject fromRecord)
        {
            CommandDef commandDef   = new CommandDef(commandId, fromRecord.Database);
            var        myCommandDef = new MyCommandDef();

            myCommandDef.CommandId        = (HP.HPTRIM.ServiceModel.CommandIds)commandId;
            myCommandDef.MenuEntryString  = commandDef.GetMenuEntryString(fromRecord.TrimType);
            myCommandDef.Tooltip          = commandDef.GetTooltip(fromRecord.TrimType);
            myCommandDef.StatusBarMessage = commandDef.GetStatusBarMessage(fromRecord.TrimType);

            if (fromRecord is CheckinPlace)
            {
                myCommandDef.IsEnabled = commandDef.IsEnabled((fromRecord as CheckinPlace).CheckinAs);
            }
            else
            {
                myCommandDef.IsEnabled = commandDef.IsEnabled(fromRecord);
            }
            myCommandDef.IsListCommand = commandDef.IsListCommand;
            myCommandDef.NeedsAnObject = commandDef.NeedsAnObject;
            return(myCommandDef);
        }
 public CommandIndexAttribute(CommandDef ID)
 {
     CommandID = ID;
 }