/// <summary>
        ///     Sets the default console setting.
        /// </summary>
        /// <returns>ConsoleSettings object with defaults</returns>
        private static ConsoleSettings SetDefaults()
        {
            var settings = new ConsoleSettings
            {
                AllowEmptyCommand     = false,
                ConsoleTitle          = "WPF Command Prompt - V" + Utility.AssemblyVersion(true, true, false),
                DefaultConsoleHeight  = 400.00,
                DefaultConsoleWidth   = 600.00,
                DefaultFontSize       = 12.00,
                DefaultPrompt         = ">",
                Delimiters            = @"((""((?<token>.*?)"")|(?<token>[\w]+))(\s)*)",
                EnableCommandHistory  = true,
                EnableLoadStyleThemes = false,
                ManualCommandHistory  = false,
                MaxConsoleHeight      = 0.00,
                MaxConsoleWidth       = 0.00,
                MaxFontSize           = 44.00,
                MinConsoleHeight      = 400.00,
                MinConsoleWidth       = 600.00,
                MinFontSize           = 8.00,
                Prompt                    = ">",
                StyleThemeIndex           = 0,
                UseInternalCommandParsing = true,
                WelcomeMessage            =
                    "---Welcome to WPF Command Prompt - Verson " + Utility.AssemblyVersion(true, true, true) + "---"
            };

            return(settings);
        }
        /// <summary>
        ///     Initializes the console.
        /// </summary>
        /// <param name="consoleSettings">The console settings.</param>
        private void InitializeConsole(ConsoleSettings.ConsoleSettings consoleSettings)
        {
            _allowEmptyCommand    = consoleSettings.AllowEmptyCommand;
            _defaultFontSize      = consoleSettings.DefaultFontSize;
            _defaultPrompt        = consoleSettings.Prompt;
            _delimeters           = consoleSettings.Delimiters;
            _enableCommandHistory = consoleSettings.EnableCommandHistory;
            _manualCommandHistory = consoleSettings.ManualCommandHistory;
            _maxFontSize          = consoleSettings.MaxFontSize;
            _minFontSize          = consoleSettings.MinFontSize;
            _prompt = consoleSettings.Prompt;
            _useInternalCommandParsing = consoleSettings.UseInternalCommandParsing;
            _welcomeMessage            = consoleSettings.WelcomeMessage;

            _txtCommandPrompt.Text       = consoleSettings.Prompt;
            _txtCommandPrompt.CaretIndex = _txtCommandPrompt.Text.Length;

            _rtbMessageArea.Document = new FlowDocument();

            SetTheme();

            var paragraph = new Paragraph();

            paragraph.Margin        = new Thickness(0);
            paragraph.TextAlignment = TextAlignment.Center;
            paragraph.Inlines.Add(new Run(_welcomeMessage)
            {
                Foreground = _styleThemeManager.WelcomeMessageColor
            });

            WriteLineToConsole(paragraph);

            _txtCommandPrompt.Focus();
        }
 /// <summary>
 ///     Writes the settings to disk.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="consoleSettings">The console settings</param>
 public static void SaveSettings(string path, string fileName, ConsoleSettings consoleSettings)
 {
     if (!path.EndsWith(@"\\") || !path.EndsWith(@"\"))
     {
         path += "\\";
     }
     Utility.ObjectToXMlFile(path + fileName, consoleSettings);
 }
 /// <summary>
 ///     Writes the settings to disk.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="fileName">Name of the file.</param>
 /// <param name="consoleSettings">The console settings</param>
 public static void SaveSettings(string path, string fileName, ConsoleSettings consoleSettings)
 {
     if (!path.EndsWith(@"\\") || !path.EndsWith(@"\"))
     {
         path += "\\";
     }
     Utility.ObjectToXMlFile(path + fileName, consoleSettings);
 }
        /// <summary>
        ///     Initializes the console window.
        /// </summary>
        /// <param name="consoleSettings">The console settings.</param>
        private void InitializeWindow(ConsoleSettings.ConsoleSettings consoleSettings)
        {
            SizeChanged += consoleWindow_SizeChanged;

            Title = consoleSettings.ConsoleTitle;
            WindowStartupLocation = WindowStartupLocation.CenterScreen;
            Height = consoleSettings.DefaultConsoleHeight;
            Width  = consoleSettings.DefaultConsoleWidth;

            _defaultConsoleHeight = consoleSettings.DefaultConsoleHeight;
            _defaultConsoleWidth  = consoleSettings.DefaultConsoleWidth;
            _maxConsoleHeight     = consoleSettings.MaxConsoleHeight;
            _maxConsoleWidth      = consoleSettings.MaxConsoleWidth;
            _minConsoleHeight     = consoleSettings.MinConsoleHeight;
            _minConsoleWidth      = consoleSettings.MinConsoleWidth;

            var grdMain = new Grid();

            grdMain.Name = "grdMain";
            Content      = grdMain;

            // Setup the grid layout
            var cd = new ColumnDefinition();

            cd.Width = new GridLength(100, GridUnitType.Star);
            grdMain.ColumnDefinitions.Add(cd);

            var rd1 = new RowDefinition();

            rd1.Height = new GridLength(100, GridUnitType.Star);
            grdMain.RowDefinitions.Add(rd1);
            var rd2 = new RowDefinition();

            rd2.Height = new GridLength(0, GridUnitType.Auto);
            grdMain.RowDefinitions.Add(rd2);

            _rtbMessageArea = new RichTextBox();
            Grid.SetRow(_rtbMessageArea, 0);
            grdMain.Children.Add(_rtbMessageArea);

            _txtCommandPrompt = new TextBox();
            Grid.SetRow(_txtCommandPrompt, 1);
            grdMain.Children.Add(_txtCommandPrompt);

            // *Box settings
            _rtbMessageArea.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
            _rtbMessageArea.IsReadOnly      = true;
            _txtCommandPrompt.TextWrapping  = TextWrapping.Wrap;
            _txtCommandPrompt.AcceptsReturn = false;

            // Command prompt key events
            _txtCommandPrompt.KeyDown        += txtCommandPrompt_KeyDown;
            _txtCommandPrompt.PreviewKeyDown += txtCommandPrompt_PreviewKeyDown;
            _txtCommandPrompt.PreviewKeyUp   += txtCommandPrompt_PreviewKeyUp;
            _txtCommandPrompt.KeyUp          += txtCommandPrompt_KeyUp;

            InitializeConsole(consoleSettings);
        }
Exemplo n.º 6
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="WpfPrompt" /> class.
 /// </summary>
 /// <param name="styleThemeIndex">The index number of the style theme to use.</param>
 public WpfPrompt(int styleThemeIndex)
 {
     _consoleSettings = ConsoleSettingsManager.LoadDefaults();
     _consoleSettings.StyleThemeIndex = styleThemeIndex;
 }
Exemplo n.º 7
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="WpfPrompt" /> class with defaults.
 /// </summary>
 public WpfPrompt()
 {
     _consoleSettings = ConsoleSettingsManager.LoadDefaults();
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Shows the console window.
        /// </summary>
        public void Show()
        {
            if (_consoleWindow == null)
            {
                if (_consoleSettings == null)
                {
                    _consoleSettings = ConsoleSettingsManager.LoadDefaults();
                }
                _consoleWindow = new ConsoleWindow(_consoleSettings);
                _consoleWindow.ConsoleReadLine += OnConsoleReadEvent;
                ConsoleWriteLine += _consoleWindow.WriteLine;
            }

            _consoleWindow.ShowConsole();
        }
Exemplo n.º 9
0
 /// <summary>
 ///     Loads the settings from a specified path and file name.
 ///     Uses defaults if configuration file does not exist.
 /// </summary>
 /// <param name="path">The path.</param>
 /// <param name="fileName">Name of the file.</param>
 public void LoadSettings(string path, string fileName)
 {
     _consoleSettings = ConsoleSettingsManager.LoadSettings(path, fileName);
 }
Exemplo n.º 10
0
 /// <summary>
 ///     Loads the settings from the default path and specified file name.
 ///     Uses defaults if configuration file does not exist.
 /// </summary>
 /// <param name="fileName">Name of the file.</param>
 public void LoadSettings(string fileName)
 {
     _consoleSettings = ConsoleSettingsManager.LoadSettings(Environment.CurrentDirectory, fileName);
 }
        /// <summary>
        ///     Sets the default console setting.
        /// </summary>
        /// <returns>ConsoleSettings object with defaults</returns>
        private static ConsoleSettings SetDefaults()
        {
            var settings = new ConsoleSettings
            {
                AllowEmptyCommand = false,
                ConsoleTitle = "WPF Command Prompt - V" + Utility.AssemblyVersion(true, true, false),
                DefaultConsoleHeight = 400.00,
                DefaultConsoleWidth = 600.00,
                DefaultFontSize = 12.00,
                DefaultPrompt = ">",
                Delimiters = @"((""((?<token>.*?)"")|(?<token>[\w]+))(\s)*)",
                EnableCommandHistory = true,
                EnableLoadStyleThemes = false,
                ManualCommandHistory = false,
                MaxConsoleHeight = 0.00,
                MaxConsoleWidth = 0.00,
                MaxFontSize = 44.00,
                MinConsoleHeight = 400.00,
                MinConsoleWidth = 600.00,
                MinFontSize = 8.00,
                Prompt = ">",
                StyleThemeIndex = 0,
                UseInternalCommandParsing = true,
                WelcomeMessage =
                    "---Welcome to WPF Command Prompt - Verson " + Utility.AssemblyVersion(true, true, true) + "---"
            };

            return settings;
        }
 /// <summary>
 ///     Resets the console window and all elements to default settings.
 /// </summary>
 /// <param name="consoleSettings">The console settings object.</param>
 public void ResetConsole(ConsoleSettings.ConsoleSettings consoleSettings)
 {
     InitializeConsole(consoleSettings);
     ResetConsoleSize();
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="ConsoleWindow" /> class.
 /// </summary>
 /// <param name="consoleSettings">The console settings.</param>
 public ConsoleWindow(ConsoleSettings.ConsoleSettings consoleSettings)
 {
     _styleThemeManager = new StyleThemeManager(consoleSettings.StyleThemeIndex,
                                                consoleSettings.EnableLoadStyleThemes);
     InitializeWindow(consoleSettings);
 }