Example #1
0
        /// <inheritdoc/>
        public override void SetModel(TextToolbar model)
        {
            base.SetModel(model);

            CommonButtons = new CommonButtons(model);
            ButtonActions = new RichTextButtonActions(this);
        }
        public void Test_TextToolbar_Localization_Retrieve()
        {
            var treeRoot = XamlReader.Load(
                @"<Page
    xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation""
    xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml""
    xmlns:controls=""using:Microsoft.Toolkit.Uwp.UI.Controls"">

    <controls:TextToolbar x:Name=""TextToolbarControl"">
    </controls:TextToolbar>

</Page>") as FrameworkElement;

            Assert.IsNotNull(treeRoot, "Could not load XAML tree.");

            var toolbar = treeRoot.FindChildByName("TextToolbarControl") as TextToolbar;

            Assert.IsNotNull(toolbar, "Could not find TextToolbar in tree.");

            var commonButtons = new CommonButtons(toolbar);
            var boldButton    = commonButtons.Bold;

            Assert.IsNotNull(boldButton, "Bold Button not found.");

            Assert.AreEqual("Bold", boldButton.ToolTip, "Label doesn't match expected default value.");
        }
        public async Task Test_TextToolbar_Localization_Override_Fr()
        {
            await App.DispatcherQueue.EnqueueAsync(async() =>
            {
                // Just double-check we've got the right environment setup in our tests.
                CollectionAssert.AreEquivalent(new string[] { "en-US", "fr" }, ApplicationLanguages.ManifestLanguages.ToArray(), "Missing locales for test");

                // Override the default language for this test only (we'll set it back after).
                var defaultLanguage = ApplicationLanguages.PrimaryLanguageOverride;
                ApplicationLanguages.PrimaryLanguageOverride = "fr";

                // Need to add a delay for release mode as otherwise the language switch doesn't kickover quick enough
                // This should be sufficient as we're just using this as a test-harness.
                await Task.Delay(3000);

                var commonButtons = new CommonButtons(new TextToolbar());
                var italicsButton = commonButtons.Italics;

                // Note: When running locally if the test somehow fails before the default is reset, then
                // the tests will be in a bad state as PrimaryLanguageOverride is persisted.
                // To fix this, uninstall the UnitTests UWP app and run the tests again.
                ApplicationLanguages.PrimaryLanguageOverride = defaultLanguage;

                // Check for expected values.
                Assert.IsNotNull(italicsButton, "Italics Button not found.");

                Assert.AreEqual("ItalicsFr", italicsButton.ToolTip, "Label doesn't match expected default value.");
            });
        }
        public void Test_TextToolbar_Localization_Override()
        {
            var commonButtons = new CommonButtons(new TextToolbar());
            var italicsButton = commonButtons.Italics;

            Assert.IsNotNull(italicsButton, "Italics Button not found.");

            Assert.AreEqual("ItalicsOverride", italicsButton.ToolTip, "Label doesn't match expected default value.");
        }
Example #5
0
 public static DialogResult MessageBox(string title,
                                       string mainInstruction,
                                       string content,
                                       CommonButtons buttons,
                                       CommonIcon mainIcon,
                                       ProgressBarStyle progressBarStyle)
 {
     return(MessageBox(IntPtr.Zero, title, mainInstruction, content, string.Empty, string.Empty, string.Empty, buttons, mainIcon, CommonIcon.Information, progressBarStyle));
 }
Example #6
0
        public async Task Test_TextToolbar_Localization_Override()
        {
            await App.Dispatcher.EnqueueAsync(() =>
            {
                var commonButtons = new CommonButtons(new TextToolbar());
                var italicsButton = commonButtons.Italics;

                Assert.IsNotNull(italicsButton, "Italics Button not found.");

                Assert.AreEqual("ItalicsOverride", italicsButton.ToolTip, "Label doesn't match expected default value.");
            });
        }
Example #7
0
 // Overloaded versions...
 public static DialogResult MessageBox(string title,
                                       string mainInstruction,
                                       string content,
                                       string expandedInfo,
                                       string footer,
                                       string verificationText,
                                       CommonButtons buttons,
                                       CommonIcon mainIcon,
                                       CommonIcon footerIcon,
                                       ProgressBarStyle progressBarStyle)
 {
     return(ShowTaskDialogBox(IntPtr.Zero, title, mainInstruction, content, expandedInfo, footer, verificationText, string.Empty, string.Empty,
                              buttons, mainIcon, footerIcon, progressBarStyle));
 }
Example #8
0
 // Overloaded versions...
 public static DialogResult ShowTaskDialogBox(IntPtr owner,
                                              string title,
                                              string mainInstruction,
                                              string content,
                                              string expandedInfo,
                                              string footer,
                                              string verificationText,
                                              string radioButtons,
                                              string commandButtons,
                                              CommonButtons buttons,
                                              CommonIcon mainIcon,
                                              CommonIcon footerIcon,
                                              ProgressBarStyle progressBarStyle)
 {
     return(ShowTaskDialogBox(owner, title, mainInstruction, content, expandedInfo, footer, verificationText,
                              radioButtons, commandButtons, buttons, mainIcon, footerIcon, 0, progressBarStyle));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="RichTextFormatter"/> class.
 /// </summary>
 /// <param name="model">The <see cref="TextToolbar"/></param>
 public RichTextFormatter(TextToolbar model)
     : base(model)
 {
     CommonButtons = new CommonButtons(model);
     ButtonActions = new RichTextButtonActions(this);
 }
        /// <summary>
        /// Create all controls needed for the current settings.
        /// </summary>
        private void BuildForm()
        {
            if (InvokeRequired)
            {
                EndInvoke(BeginInvoke(new MethodInvoker(BuildForm)));
                return;
            }

            // Setup Content
            contentText.Text = TaskConfig.Content;
            if (!string.IsNullOrEmpty(TaskConfig.Content))
            {
                contentText.ConvertLinks();
                contentText.ReadOnly  = true;
                contentText.BackColor = BackColor;
            }

            // Setup Expanded Info and Buttons panels
            if (!string.IsNullOrEmpty(TaskConfig.ExpandedInformation))
            {
                expandedInfoText.ConvertLinks();
                expandedInfoText.ReadOnly  = true;
                expandedInfoText.BackColor = BackColor;
            }

            progressBar.Minimum = 0;
            progressBar.Maximum = 100;

            // Setup RadioButtons
            radioButtonsPanel.Controls.Clear();
            if (TaskConfig.RadioButtons.Count > 0)
            {
                foreach (TaskDialogButton t in TaskConfig.RadioButtons)
                {
                    RadioButton radioButton = new RadioButton {
                        Parent  = radioButtonsPanel,
                        Text    = t.ButtonText,
                        Tag     = t.ButtonId,
                        Checked = (TaskConfig.DefaultRadioButton == t.ButtonId)
                    };

                    if (radioButton.Checked)
                    {
                        RadioButtonClick(radioButton, EventArgs.Empty);
                    }

                    radioButton.Click += RadioButtonClick;
                }
            }

            // Setup CommandButtons
            commandButtonsPanel.Controls.Clear();
            if (TaskConfig.Buttons.Count > 0)
            {
                foreach (TaskDialogButton button in TaskConfig.Buttons)
                {
                    Control commandButton;
                    if (TaskConfig.Flags.UseCommandLinks)
                    {
                        commandButton = new CommandButton {
                            Parent = commandButtonsPanel
                        };
                    }
                    else
                    {
                        commandButton = new Button {
                            Parent = commonButtonPanel
                        };
                        ((Button)commandButton).AutoSizeMode = AutoSizeMode.GrowOnly;
                        commandButton.AutoSize = true;
                    }

                    if (_isVista)
                    {
                        commandButton.Font = new Font(commandButton.Font, FontStyle.Regular);
                    }
                    commandButton.Text   = button.ButtonText;
                    commandButton.Tag    = button.ButtonId;
                    commandButton.Click += CommandButton_Click;
                    if (button.ButtonId == TaskConfig.DefaultButton)
                    {
                        FocusControl = commandButton;
                    }
                }
                if (0 == TaskConfig.DefaultButton)
                {
                    FocusControl = commandButtonsPanel.Controls.OfType <CommandButton>().ToArray()[0];
                }
            }

            // Setup common buttons
            commonButtonPanel.Controls.Clear();
            if (TaskConfig.CommonButtons == CommonButtons.None)
            {
                TaskConfig.CommonButtons = CommonButtons.Ok;
            }

            if ((TaskConfig.CommonButtons & CommonButtons.Ok) > 0)
            {
                Button button = new Button();
                commonButtonPanel.Controls.Add(button);

                button.Text     = "&Ok";
                button.Tag      = (int)DialogResult.OK;
                _acceptButtonId = CommonButtons.Ok;
            }
            if ((TaskConfig.CommonButtons & CommonButtons.Yes) > 0)
            {
                Button button = new Button();
                commonButtonPanel.Controls.Add(button);

                button.Text     = "&Yes";
                button.Tag      = (int)DialogResult.Yes;
                _acceptButtonId = CommonButtons.Yes;
            }
            if ((TaskConfig.CommonButtons & CommonButtons.No) > 0)
            {
                Button button = new Button();
                commonButtonPanel.Controls.Add(button);

                button.Text     = "&No";
                button.Tag      = (int)DialogResult.No;
                _cancelButtonId = CommonButtons.No;
            }
            if ((TaskConfig.CommonButtons & CommonButtons.Retry) > 0)
            {
                Button button = new Button();
                commonButtonPanel.Controls.Add(button);

                button.Text = "&Retry";
                button.Tag  = (int)DialogResult.Retry;
            }
            if ((TaskConfig.CommonButtons & CommonButtons.Cancel) > 0)
            {
                Button button = new Button();
                commonButtonPanel.Controls.Add(button);

                button.Text     = "&Cancel";
                button.Tag      = (int)DialogResult.Cancel;
                _cancelButtonId = CommonButtons.Cancel;
            }
            if ((TaskConfig.CommonButtons & CommonButtons.Close) > 0)
            {
                Button button = new Button();
                commonButtonPanel.Controls.Add(button);

                button.Text     = "C&lose";
                button.Tag      = 8; // No equivalent in DialogResult enum
                _cancelButtonId = CommonButtons.Close;
            }

            foreach (Button button in commonButtonPanel.Controls)
            {
                button.UseVisualStyleBackColor = true;
                button.Click += CommonButtonClick;
            }

            ControlBox = ((TaskConfig.CommonButtons & CommonButtons.Cancel) > 0 ||
                          (TaskConfig.CommonButtons & CommonButtons.Close) > 0);

            MinimizeBox = TaskConfig.Flags.CanBeMinimized;

            if (!string.IsNullOrEmpty(TaskConfig.Footer))
            {
                footerText.Text = TaskConfig.Footer;
                if (TaskConfig.Flags.EnableHyperLinks)
                {
                    footerText.ConvertLinks();
                }
                footerText.ReadOnly  = true;
                footerText.BackColor = pnlFooter.BackColor;
            }

            // Set title
            Text = TaskConfig.WindowTitle;

            // Set up timer
            callbackTimer.Enabled = TaskConfig.Flags.CallbackTimer;

            ReCalculateLayout();

            _formBuilt = true;

            if (null != DialogConstructed)
            {
                DialogConstructed(this, EventArgs.Empty);
            }
        }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MarkDownFormatter"/> class.
 /// </summary>
 /// <param name="model"><see cref="TextToolbar"/> where formatter will be used</param>
 public MarkDownFormatter(TextToolbar model)
     : base(model)
 {
     CommonButtons = new CommonButtons(model);
     ButtonActions = new MarkDownButtonActions(this);
 }
        public override void SetModel(TextToolbar model)
        {
            base.SetModel(model);

            CommonButtons = new CommonButtons(model);
        }
Example #13
0
        /// <exception cref="ArgumentException">Not supported yet.</exception>
        public static DialogResult ShowTaskDialogBox(IntPtr owner,
                                                     string title,
                                                     string mainInstruction,
                                                     string content,
                                                     string expandedInfo,
                                                     string footer,
                                                     string verificationText,
                                                     string radioButtons,
                                                     string commandButtons,
                                                     CommonButtons buttons,
                                                     CommonIcon mainIcon,
                                                     CommonIcon footerIcon,
                                                     int defaultIndex,
                                                     ProgressBarStyle progressBarStyle)
        {
            ITaskDialog taskDialog;

            if (NativeTaskDialog.IsAvailableOnThisOs && !ForceEmulationMode)
            {
                taskDialog = new NativeTaskDialog();
            }
            else
            {
                taskDialog = new EmulatedTaskDialog(false);
            }

            TaskConfig = new TaskDialogConfig();

            TaskConfig.Parent              = owner;
            TaskConfig.WindowTitle         = title;
            TaskConfig.MainInstruction     = mainInstruction;
            TaskConfig.Content             = content;
            TaskConfig.ExpandedInformation = expandedInfo;
            TaskConfig.Footer              = footer;

            // Radio Buttons
            if (!string.IsNullOrEmpty(radioButtons))
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                string[] arr = radioButtons.Split(new[] { '|' });
                for (int i = 0; i < arr.Length; i++)
                {
                    try {
                        TaskDialogButton button = new TaskDialogButton {
                            ButtonId = 1000 + i, ButtonText = arr[i]
                        };
                        lst.Add(button);
                    } catch (FormatException) {}
                }
                TaskConfig.RadioButtons.AddRange(lst);
                TaskConfig.Flags.NoDefaultRadioButton = (defaultIndex == -1);
                if (defaultIndex >= 0)
                {
                    TaskConfig.DefaultRadioButton = defaultIndex + 1000;
                }
                else
                {
                    TaskConfig.DefaultRadioButton = 1000;
                }
            }

            // Custom Buttons
            if (!string.IsNullOrEmpty(commandButtons))
            {
                List <TaskDialogButton> lst = new List <TaskDialogButton>();
                string[] arr = commandButtons.Split(new[] { '|' });
                for (int i = 0; i < arr.Length; i++)
                {
                    try {
                        TaskDialogButton button = new TaskDialogButton {
                            ButtonId = 2000 + i, ButtonText = arr[i]
                        };
                        lst.Add(button);
                    } catch (FormatException) {}
                }
                TaskConfig.Buttons.AddRange(lst);
                if (defaultIndex >= 0)
                {
                    TaskConfig.DefaultButton = defaultIndex;
                }
            }

            TaskConfig.CommonButtons = buttons;
            TaskConfig.MainIcon      = mainIcon;
            if (TaskConfig.MainIcon == CommonIcon.Custom)
            {
                throw new ArgumentException("Not supported yet.", "mainIcon");
            }
            TaskConfig.FooterIcon = footerIcon;
            if (TaskConfig.FooterIcon == CommonIcon.Custom)
            {
                throw new ArgumentException("Not supported yet.", "footerIcon");
            }

            TaskConfig.Flags.EnableHyperLinks        = true;
            TaskConfig.Flags.ShowProgressBar         = (progressBarStyle == ProgressBarStyle.Continous) ? true : false;
            TaskConfig.Flags.ShowMarqueeProgressBar  = (progressBarStyle == ProgressBarStyle.Marquee) ? true : false;
            TaskConfig.Flags.AllowDialogCancellation = ((buttons & CommonButtons.Cancel) >= 0 ||
                                                        (buttons & CommonButtons.Close) >= 0);

            TaskConfig.Flags.CallbackTimer            = true;
            TaskConfig.Flags.ExpandedByDefault        = false;
            TaskConfig.Flags.ExpandFooterArea         = false;
            TaskConfig.Flags.PositionRelativeToWindow = true;
            TaskConfig.Flags.RtlLayout               = false;
            TaskConfig.Flags.CanBeMinimized          = false;
            TaskConfig.Flags.UseCommandLinks         = (TaskConfig.Buttons.Count > 0);
            TaskConfig.Flags.UseCommandLinksNoIcon   = false;
            TaskConfig.VerificationText              = verificationText;
            TaskConfig.Flags.VerificationFlagChecked = false;
            TaskConfig.ExpandedControlText           = "Hide details";
            TaskConfig.CollapsedControlText          = "Show details";

            taskDialog.Created             += TaskDialogCreated;
            taskDialog.ButtonClicked       += TaskDialogButtonClicked;
            taskDialog.HyperlinkClicked    += TaskDialogHyperlinkClicked;
            taskDialog.Timer               += TaskDialogTimer;
            taskDialog.Destroyed           += TaskDialogDestroyed;
            taskDialog.RadioButtonClicked  += TaskDialogRadioButtonClicked;
            taskDialog.DialogConstructed   += TaskDialogDialogConstructed;
            taskDialog.VerificationClicked += TaskDialogVerificationClicked;
            taskDialog.Help += TaskDialogHelp;
            taskDialog.ExpandoButtonClicked += TaskDialogExpandoButtonClicked;
            taskDialog.Navigated            += TaskDialogNavigated;

            DialogResult dialogResult = DialogResult.None;
            int          result       = taskDialog.TaskDialogIndirect(TaskConfig, out ButtonResult, out RadioButtonResult, out VerificationChecked);

            // Try to interpret the ButtonResult as a DialogResult
            try {
                if (ButtonResult < 1000)
                {
                    dialogResult = (DialogResult)ButtonResult;
                }
// ReSharper disable EmptyGeneralCatchClause
            } catch {}
// ReSharper restore EmptyGeneralCatchClause

            // if a command button was clicked, then change return result
            // to "DialogResult.OK" and set the CommandButtonResult)
            if (result >= 2000)
            {
                CommandButtonResult = result - 2000;
                dialogResult        = DialogResult.OK;
            }
            if (RadioButtonResult >= 1000)
            {
                // deduct the ButtonID start value for radio buttons
                RadioButtonResult -= 1000;
            }

            return(dialogResult);
        }
Example #14
0
 public SampleFormatter(TextToolbar model)
     : base(model)
 {
     CommonButtons = new CommonButtons(model);
 }