private void InitialiseGui()
        {
            GuiHelpers.ClearGridGuiItems(gridCommands);

            var parameterisedCommands = Task.Commands.Where(command => command.Parameterised);

            if (parameterisedCommands.Any())
            {
                // Add column definitions
                int commandColumnWidthPercentage = 45;
                int argsColumnWidthPercentage    = 100 - commandColumnWidthPercentage;

                gridCommands.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(commandColumnWidthPercentage, GridUnitType.Star),
                });

                gridCommands.ColumnDefinitions.Add(new ColumnDefinition()
                {
                    Width = new GridLength(argsColumnWidthPercentage, GridUnitType.Star),
                });

                const string tooltipLabel  = "Command";
                const string tooltipButton = "Execute command with specified parameters";

                // Add row definitions and all of the Gui elements for each parameterised command.
                int row = 0;
                foreach (var command in parameterisedCommands)
                {
                    gridCommands.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(50, GridUnitType.Pixel)
                    });

                    var fullCommandTooltipTextbox = $"Evaluates to: ({command.GetFullEvaluatedCommandWithArgs()})";

                    GuiHelpers.CreateControlAndAddToGrid(
                        gridCommands,
                        GuiHelpers.ControlType.eTextBlock,
                        command.Id,
                        command.GetCommandExpandEnvironmentVariables(),
                        row,
                        0,
                        0,
                        0,
                        tooltipLabel,
                        new Thickness(10, 10, 10, 10),
                        null,
                        null
                        );

                    if (command.SupportedParams.Count() > 0)
                    {
                        GuiHelpers.CreateControlAndAddToGrid(
                            gridCommands,
                            GuiHelpers.ControlType.eComboBox,
                            command.Id,
                            command.Args,
                            command.SupportedParams,
                            row,
                            1,
                            0,
                            0,
                            fullCommandTooltipTextbox,
                            new Thickness(10, 10, 10, 10),
                            null,
                            TextBoxSetTooltip
                            );
                    }
                    else
                    {
                        GuiHelpers.CreateControlAndAddToGrid(
                            gridCommands,
                            GuiHelpers.ControlType.eTextBox,
                            command.Id,
                            command.Args,
                            row,
                            1,
                            0,
                            0,
                            fullCommandTooltipTextbox,
                            new Thickness(10, 10, 10, 10),
                            null,
                            TextBoxSetTooltip
                            );
                    }

                    ++row;
                }

                // Add Ok button on at the end.
                var okBtnRowIndex = parameterisedCommands.Count() + 1;

                gridCommands.RowDefinitions.Add(new RowDefinition()
                {
                    Height = new GridLength(60, GridUnitType.Pixel)
                });

                GuiHelpers.CreateControlAndAddToGrid(
                    gridCommands,
                    GuiHelpers.ControlType.eButton,
                    null,
                    "Ok",
                    okBtnRowIndex,
                    1,
                    60,
                    30,
                    tooltipButton,
                    new Thickness(0, 0, 0, 0),
                    Ok_Click,
                    null
                    );
            }
        }
示例#2
0
        private void PopulateTasksToExecute()
        {
            try
            {
                if (!CheckAccess())
                {
                    // On a different thread
                    Dispatcher.Invoke(() => PopulateTasksToExecute());
                    return;
                }

                GuiHelpers.ClearGridGuiItems(gridTasks);

                // Get the configured tasks
                var configuredTasks = ConfigManager.Instance.AvailableTaskConfigurator.GetTasks();
                // Get the configured tasks per row
                int columns = ConfigManager.Instance.SettingsConfigurator.TasksPerRow;
                // Get the amount of rows required
                int rows = configuredTasks.Count;
                if (columns > 0 && configuredTasks.Count > columns)
                {
                    rows = (int)(Math.Ceiling(configuredTasks.Count / (double)columns));
                }

                // Work out roughly how much of the screen, as a percentage, each column should consume.
                var columnPercentageWidth = (this.Width / (columns > 0 ? columns : 1));

                // Add column definitions
                for (var column = 0; column < columns; column++)
                {
                    gridTasks.ColumnDefinitions.Add(new ColumnDefinition()
                    {
                        Width = new GridLength(columnPercentageWidth, GridUnitType.Star),
                    });
                }

                // Add row definitions and all of the buttons for each command.
                for (var row = 0; row < rows; row++)
                {
                    gridTasks.RowDefinitions.Add(new RowDefinition()
                    {
                        Height = new GridLength(75, GridUnitType.Pixel)
                    });

                    for (var column = 0; column < columns; column++)
                    {
                        int taskIndex = (column + 1);
                        if (row > 0)
                        {
                            taskIndex += row * columns;
                        }

                        var task = CollectionUtils.SafeGetItemByIndex <ExecutionTask>((taskIndex - 1), configuredTasks);

                        CreateButtonForGrid(task, gridTasks, row, column);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Instance.OutputLog(string.Format("{0}", ex.Message), Log.LogLevel.Error);
            }
        }