예제 #1
0
        private async void OnLoaded(object sender, RoutedEventArgs e)
        {
            SetupFocusMode(Settings.FocusMode);

            await SetOverlayMode(Settings.CurrentMode);

            Settings.Dispatch(() => Bindings.Update());

            if (Settings.DefaultMode == "Compact Overlay")
            {
                if (await ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay))
                {
                    //set the current mode to be the launch mode
                    Settings.CurrentMode = Settings.DefaultMode;
                }
            }

            if (Settings.DefaultMode == "LaunchFocusMode")
            {
                //set return mode in case the user wants to leave focus mode
                Settings.ReturnToMode = nameof(DisplayModes.LaunchClassicMode);

                //set the current mode to be the launch mode
                Settings.CurrentMode = Settings.DefaultMode;
            }

            Settings.NotDeferred = true;
            Settings.Status("Ready", TimeSpan.FromSeconds(10), Verbosity.Release);

            if (ViewModel.CurrentFileType == ".rtf")
            {
                RichEditBox.Focus(FocusState.Programmatic);
            }
            else
            {
                TextBox.Focus(FocusState.Programmatic);
            }

            TextBox.SelectionFlyout.Opening     += Menu_Opening;
            TextBox.ContextFlyout.Opening       += Menu_Opening;
            RichEditBox.SelectionFlyout.Opening += RMenu_Opening;
            RichEditBox.ContextFlyout.Opening   += RMenu_Opening;

            // Add shadow to the title bar
            TopBarShadow.Receivers.Add(TextScrollViewer);
        }
        public async void OpenLinkCreator(ToolbarButton button)
        {
            var selection = button.Model.Editor.Document.Selection;

            var labelBox = new RichEditBox
            {
                PlaceholderText = Model.Labels.LabelLabel,
                Margin          = new Thickness(0, 0, 0, 5),
                AcceptsReturn   = false
            };
            var linkBox = new TextBox
            {
                PlaceholderText = Model.Labels.UrlLabel
            };

            labelBox.Document.SetDefaultCharacterFormat(selection.CharacterFormat);
            selection.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out string Labeltext);
            labelBox.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, Labeltext);

            var result = await new ContentDialog
            {
                Title   = Model.Labels.CreateLinkLabel,
                Content = new StackPanel
                {
                    Children =
                    {
                        labelBox,
                        linkBox
                    }
                },
                PrimaryButtonText   = Model.Labels.OkLabel,
                SecondaryButtonText = Model.Labels.CancelLabel
            }.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                string labelText;
                labelBox.Document.GetText(Windows.UI.Text.TextGetOptions.None, out labelText);

                string formattedlabelText;
                labelBox.Document.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out formattedlabelText);

                Model.Formatter.ButtonActions.FormatLink(button, labelText.Trim(), formattedlabelText.Trim(), linkBox.Text.Trim());
            }
        }
예제 #3
0
        public static void ReplaceAllWords(this RichEditBox richEditBox, string replacementWord, string searchedWord, bool isMatchCase)
        {
            if (richEditBox is null)
            {
                throw new ArgumentNullException(nameof(richEditBox));
            }

            // Avoids infinite lool
            if (replacementWord != searchedWord && !string.IsNullOrEmpty(searchedWord))
            {
                richEditBox.FindWord(searchedWord, isMatchCase);
                do
                {
                    richEditBox.ReplaceSelectedWord(replacementWord);
                    richEditBox.FindWord(searchedWord, isMatchCase);
                }while (string.Compare(richEditBox.Document.Selection.Text, searchedWord, isMatchCase, CultureInfo.CurrentCulture) == 0);
            }
        }
        private void CreateNewEntryButton_Click(object sender, RoutedEventArgs e)
        {
            PivotItem pi = new PivotItem();

            var entryText = String.Format("Entry{0}", rootPivot.Items.Count + 1);

            pi.Header = entryText;
            RichEditBox reb = new RichEditBox();

            reb.HorizontalAlignment = HorizontalAlignment.Stretch;
            reb.VerticalAlignment   = VerticalAlignment.Stretch;

            pi.Content = reb;

            pi.Loaded += PivotItem_Loaded;
            rootPivot.Items.Add(pi);
            rootPivot.SelectedIndex = rootPivot.Items.Count - 1;
        }
예제 #5
0
 private void EnterTabKey(RichEditBox richEditBox, Windows.UI.Xaml.Input.KeyRoutedEventArgs e)
 {
     if (!ViewModel.UseSoftTab)
     {
         richEditBox.Document.Selection.TypeText("\t");
         e.Handled = true;
     }
     else
     {
         var start = richEditBox.Document.Selection.StartPosition;
         var end   = richEditBox.Document.Selection.EndPosition;
         richEditBox.Document.Selection.HomeKey(Windows.UI.Text.TextRangeUnit.Line, false);
         var lineBeginPos = richEditBox.Document.Selection.StartPosition;
         var numSpaces    = ViewModel.TabSize - ((start - lineBeginPos) % ViewModel.TabSize);
         richEditBox.Document.Selection.SetRange(start, end);
         richEditBox.Document.Selection.TypeText(new string(' ', numSpaces));
         e.Handled = true;
     }
 }
        private void OnTextViewChanged(RichEditBox oldValue, RichEditBox newValue)
        {
            if (oldValue != null)
            {
                oldValue.TextChanged -= HandleTextViewTextChanged;
                oldValue.KeyUp       -= HandleTextViewKeyUp;
            }

            if (newValue != null)
            {
                newValue.TextChanged += HandleTextViewTextChanged;
                newValue.KeyUp       += HandleTextViewKeyUp;

                BindTextViewStyle();
                RefreshLineNumbers(); // (1)

                // newValue.Paste += RequestLineNumberRedraw;
            }
        }
예제 #7
0
        public async Task Init()
        {
            await App.Dispatcher.ExecuteOnUIThreadAsync(() =>
            {
                var richEditBox = new RichEditBox
                {
                    PlaceholderText          = "Enter Text Here",
                    TextWrapping             = TextWrapping.Wrap,
                    VerticalContentAlignment = VerticalAlignment.Stretch,
                    MinHeight       = 300,
                    BorderThickness = new Thickness(1),
                    SelectionFlyout = null
                };

                _textToolbar = new TextToolbar
                {
                    Editor    = richEditBox,
                    IsEnabled = true,
                    Format    = Microsoft.Toolkit.Uwp.UI.Controls.TextToolbarFormats.Format.RichText
                };

                var grid = new Grid
                {
                    Children =
                    {
                        _textToolbar,
                        richEditBox
                    },
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Height = 200,
                    Width  = 300
                };
                grid.RowDefinitions.Add(new RowDefinition
                {
                    Height = GridLength.Auto
                });
                grid.RowDefinitions.Add(new RowDefinition());
                TestsPage.Instance.SetMainTestContent(grid);
                Grid.SetRow(richEditBox, 1);
            });
        }
예제 #8
0
 public JournalEntry(RichEditBox richEditBox,
                     String AppHomeFolderPath,
                     String YMDDate,
                     String EntryHeader,
                     String FileName = null)
 {
     _richEditBox           = richEditBox;
     this.AppHomeFolderPath = AppHomeFolderPath;
     this.YMDDate           = YMDDate;
     this.YMFolder          = YMDDate.Substring(0, 7);
     this.EntryHeader       = EntryHeader;
     if (FileName == null)
     {
         GenerateFileName();
     }
     else
     {
         this.FileName = FileName;
     }
 }
예제 #9
0
        private void LoadEntriesByDate()
        {
            EntriesListView.Items.Add(MainCalendar.SelectedDates[0].ToString());
            String ymfolder = YMDDate.Substring(0, 7);

            if (Directory.Exists(Path.Combine(appHomeFolder.Path, ymfolder)))
            {
                String[] allCurrentFiles = Directory.GetFiles(
                    Path.Combine(appHomeFolder.Path, ymfolder),
                    String.Format("{0}*.rtf", YMDDate),
                    SearchOption.TopDirectoryOnly);
                if (allCurrentFiles.Length > 0)
                {
                    foreach (String f in allCurrentFiles)
                    {
                        PivotItem pi        = new PivotItem();
                        var       entryText = String.Format("Entry{0}", rootPivot.Items.Count + 1);

                        pi.Header = entryText;

                        RichEditBox reb = new RichEditBox();
                        reb.HorizontalAlignment = HorizontalAlignment.Stretch;
                        reb.VerticalAlignment   = VerticalAlignment.Stretch;

                        currentJournalEntries.Add(
                            new JournalEntry(reb,
                                             Path.Combine(appHomeFolder.Path),
                                             YMDDate, entryText));

                        pi.Content = reb;
                        pi.Loaded += PivotItem_Loaded;
                        rootPivot.Items.Add(pi);
                        rootPivot.SelectedIndex = rootPivot.Items.Count - 1;
                    }
                }
            }
            else
            {
                AddDefaultEntry();
            }
        }
예제 #10
0
        /// <summary>
        /// 设置富文本框的内容流
        /// </summary>
        /// <param name="editor">富文本框</param>
        public async Task SetRandomAccessStream(RichEditBox editor)
        {
            Windows.Storage.Pickers.FileSavePicker savePicker = new Windows.Storage.Pickers.FileSavePicker();
            savePicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;

            // Dropdown of file types the user can save the file as
            savePicker.FileTypeChoices.Add("Rich Text", new List <string>()
            {
                ".rtf"
            });

            // Default file name if the user does not type one in or select a file to replace
            savePicker.SuggestedFileName = "New Document";

            Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();

            if (file != null)
            {
                // Prevent updates to the remote version of the file until we
                // finish making changes and call CompleteUpdatesAsync.
                Windows.Storage.CachedFileManager.DeferUpdates(file);
                // write to file
                Windows.Storage.Streams.IRandomAccessStream randAccStream =
                    await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                editor.Document.SaveToStream(Windows.UI.Text.TextGetOptions.FormatRtf, randAccStream);


                // Let Windows know that we're finished changing the file so the
                // other app can update the remote version of the file.
                Windows.Storage.Provider.FileUpdateStatus status = await Windows.Storage.CachedFileManager.CompleteUpdatesAsync(file);

                if (status != Windows.Storage.Provider.FileUpdateStatus.Complete)
                {
                    Windows.UI.Popups.MessageDialog errorBox =
                        new Windows.UI.Popups.MessageDialog("File " + file.Name + " couldn't be saved.");
                    await errorBox.ShowAsync();
                }
            }
        }
예제 #11
0
        private void RichEditBox_SelectionChanging(RichEditBox sender, RichEditBoxSelectionChangingEventArgs args)
        {
            var selection = TextDocument.Selection;

            if (selection.Type != SelectionType.InsertionPoint && selection.Type != SelectionType.Normal)
            {
                return;
            }

            var range = selection.GetClone();

            range.Expand(TextRangeUnit.Link);
            lock (_tokensLock)
            {
                if (!_tokens.ContainsKey(range.Link))
                {
                    return;
                }
            }

            ExpandSelectionOnPartialTokenSelect(selection, range);
        }
예제 #12
0
        private void CreateNewEntryButton_Click(object sender, RoutedEventArgs e)
        {
            PivotItem pi        = new PivotItem();
            var       entryText = String.Format("Entry{0}", rootPivot.Items.Count + 1);

            pi.Header = entryText;

            RichEditBox reb = new RichEditBox();

            reb.HorizontalAlignment = HorizontalAlignment.Stretch;
            reb.VerticalAlignment   = VerticalAlignment.Stretch;

            currentJournalEntries.Add(
                new JournalEntry(reb,
                                 Path.Combine(appHomeFolder.Path),
                                 YMDDate, entryText));

            pi.Content = reb;
            pi.Loaded += PivotItem_Loaded;
            rootPivot.Items.Add(pi);
            rootPivot.SelectedIndex = rootPivot.Items.Count - 1;
        }
예제 #13
0
        private async void OnLoaded(object sender, RoutedEventArgs e)
        {
            SetupFocusMode(Settings.FocusMode);

            await SetOverlayMode(Settings.CurrentMode);

            if (ViewModel.File == null)
            {
                await ViewModel.InitNewDocument();
            }

            Mvvm.ViewModels.ViewModel.Dispatch(() => Bindings.Update());

            if (Settings.DefaultMode == "Compact Overlay")
            {
                if (await ApplicationView.GetForCurrentView().TryEnterViewModeAsync(ApplicationViewMode.CompactOverlay))
                {
                    Settings.CurrentMode = "Compact Overlay";
                }
            }

            Settings.NotDeferred = true;
            Settings.Status("Ready", TimeSpan.FromSeconds(10), Verbosity.Release);

            if (ViewModel.CurrentFileType == ".rtf")
            {
                RichEditBox.Focus(FocusState.Programmatic);
            }
            else
            {
                TextBox.Focus(FocusState.Programmatic);
            }

            TextBox.SelectionFlyout.Opening     += Menu_Opening;
            TextBox.ContextFlyout.Opening       += Menu_Opening;
            RichEditBox.SelectionFlyout.Opening += RMenu_Opening;
            RichEditBox.ContextFlyout.Opening   += RMenu_Opening;
        }
예제 #14
0
        /// <summary>
        /// Exports the translated code without style elements into various files for each class.
        /// </summary>
        /// <param name="fileLocation">Location of the files that will be created</param>
        /// <returns>True if the export succeeded</returns>
        public async void Export(StorageFolder folder)
        {
            // Translate to plain text
            RichEditBox box = new RichEditBox();

            box.Document.SetText(TextSetOptions.FormatRtf, CurrentLanguage.result.ToString());
            string output;

            box.Document.GetText(TextGetOptions.UseCrlf, out output);

            // Split into pages and write into files
            string pattern = "-+([\\.\\w]+)[-\\s]+([^-]*)";
            Regex  regex   = new Regex(pattern);

            foreach (Match match in regex.Matches(output))
            {
                string      fileName    = match.Groups[1].Value;
                string      fileContent = match.Groups[2].Value;
                StorageFile file        = await folder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting);

                await FileIO.WriteTextAsync(file, fileContent);
            }
        }
예제 #15
0
        public static void InsertHyperLink(this RichEditBox richEditBox, string link, string text)
        {
            if (richEditBox is null)
            {
                throw new ArgumentNullException(nameof(richEditBox));
            }

            if (link is null)
            {
                throw new ArgumentNullException(nameof(link));
            }

            richEditBox.Document.Selection.Text = text;
            string hyperlink = link;

            if (!link.StartsWith("http://", StringComparison.CurrentCultureIgnoreCase))
            {
                hyperlink = "http://" + hyperlink;
            }

            hyperlink = '\u0022' + hyperlink + '\u0022';

            richEditBox.Document.Selection.Link = hyperlink;
        }
예제 #16
0
        public async void ClearOneAnnotation(RichEditBox box)
        {
            if (App.Corpus.SystemSentences.ElementAt(CurrentSentence.ActiveIndex).Annotations.Any())
            {
                ITextSelection selectedTxt = box.Document.Selection;
                if (selectedTxt != null)
                {
                    List <SysAnnotation> delAnno = CurrentSentence.ActiveSysSentence.Annotations.
                                                   Where(p => p.StartPosition == selectedTxt.StartPosition && p.EndPosition == selectedTxt.EndPosition).ToList();

                    if (delAnno.Any())
                    {
                        int delIndex = CurrentSentence.ActiveSysSentence.Annotations.IndexOf(delAnno.ElementAt(0));
                        CurrentSentence.ActiveSysSentence.Annotations.RemoveAt(delIndex);
                        //App.Corpus.SystemSentences.ElementAt(CurrentSentence.ActiveIndex).Annotations.RemoveAt(delIndex);
                        sentenceService.UndoVisualChangeAnno(selectedTxt);
                    }
                    else
                    {
                        await new Windows.UI.Popups.MessageDialog("Please select correctly the annotation - partial selection is not allowed!").ShowAsync();
                    }
                }
            }
        }
예제 #17
0
        private void OnTextChanging(RichEditBox sender, RichEditBoxTextChangingEventArgs args)
        {
            if (ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4))
            {
                ContentChanged = args.IsContentChanging;
            }
            else
            {
                ContentChanged = (CoreText.Text.Length > 1 && Document.CanUndo());
            }

            if (TextSaveState == SaveState.OpenedFile && !ContentChanged)
            {
                TextSaveState  = SaveState.TextIsUnchanged;
                ContentChanged = false;
            }
            else
            {
                if (ContentChanged)
                {
                    TextSaveState = SaveState.TextIsChanged;
                }
            }
        }
예제 #18
0
        public async void Save(RichEditBox display)
        {
            try
            {
                FileSavePicker picker = new FileSavePicker
                {
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary
                };
                picker.FileTypeChoices.Add("Rich Text", new List<string>() { ".rtf" });
                picker.DefaultFileExtension = ".rtf";
                picker.SuggestedFileName = "Document";
                StorageFile file = await picker.PickSaveFileAsync();
                if (file != null)
                {
                    CachedFileManager.DeferUpdates(file);
                    await FileIO.WriteTextAsync(file, get(ref display));
                    FileUpdateStatus status = await CachedFileManager.CompleteUpdatesAsync(file);
                }
            }
            catch
            {

            }
        }
예제 #19
0
        public static string ConvertToHtml(RichEditBox richEditBox, List <string> list)
        {
            string strColour, strFntName, strHTML;

            richEditBox.Document.GetText(TextGetOptions.None, out string text);
            ITextRange txtRange = richEditBox.Document.GetRange(0, text.Length);

            strHTML = "<!DOCTYPE html><html>";
            if (Settings.Default.HTMLEncoding != 0)
            {
                strHTML += "<meta charset=\"" + list[Settings.Default.HTMLEncoding] + "\">";
            }
            strHTML += "<head><title>" + Settings.Default.DefaultExportName + "</title></head>";
            int   lngOriginalStart  = txtRange.StartPosition;
            int   lngOriginalLength = txtRange.EndPosition;
            float shtSize           = 11;
            // txtRange.SetRange(txtRange.StartPosition, txtRange.EndPosition);
            bool bOpened = false, liOpened = false, numbLiOpened = false, iOpened = false, uOpened = false, bulletOpened = false, numberingOpened = false;

            for (int i = 0; i < text.Length; i++)
            {
                txtRange.SetRange(i, i + 1);
                if (i == 0)
                {
                    strColour  = Windows.UI.Colors.Black.ToHex().ToString();
                    shtSize    = txtRange.CharacterFormat.Size;
                    strFntName = txtRange.CharacterFormat.Name;
                    strHTML   += "<span style=\"font-family:" + strFntName + "; font-size: " + shtSize + "pt; color: #" + strColour.Substring(3) + "\">";
                }
                if (txtRange.CharacterFormat.Size != shtSize)
                {
                    shtSize  = txtRange.CharacterFormat.Size;
                    strHTML += "</span><span style=\"font-family: " + txtRange.CharacterFormat.Name + "; font-size: " + txtRange.CharacterFormat.Size + "pt; color: #" + txtRange.CharacterFormat.ForegroundColor.ToString().Substring(3) + "\">";
                }
                if (txtRange.Character == Convert.ToChar(13))
                {
                    strHTML += "<br/>";
                }
                #region bullet
                if (txtRange.ParagraphFormat.ListType == MarkerType.Bullet)
                {
                    if (!bulletOpened)
                    {
                        strHTML     += "<ul>";
                        bulletOpened = true;
                    }

                    if (!liOpened)
                    {
                        strHTML += "<li>";
                        liOpened = true;
                    }

                    if (txtRange.Character == Convert.ToChar(13))
                    {
                        strHTML += "</li>";
                        liOpened = false;
                    }
                }
                else
                {
                    if (bulletOpened)
                    {
                        strHTML     += "</ul>";
                        bulletOpened = false;
                    }
                }
                #endregion
                #region numbering
                if (txtRange.ParagraphFormat.ListType == MarkerType.LowercaseRoman)
                {
                    if (!numberingOpened)
                    {
                        strHTML        += "<ol type=\"i\">";
                        numberingOpened = true;
                    }

                    if (!numbLiOpened)
                    {
                        strHTML     += "<li>";
                        numbLiOpened = true;
                    }

                    if (txtRange.Character == Convert.ToChar(13))
                    {
                        strHTML     += "</li>";
                        numbLiOpened = false;
                    }
                }
                else
                {
                    if (numberingOpened)
                    {
                        strHTML        += "</ol>";
                        numberingOpened = false;
                    }
                }
                #endregion
                #region bold
                if (txtRange.CharacterFormat.Bold == FormatEffect.On)
                {
                    if (!bOpened)
                    {
                        strHTML += "<b>";
                        bOpened  = true;
                    }
                }
                else
                {
                    if (bOpened)
                    {
                        strHTML += "</b>";
                        bOpened  = false;
                    }
                }
                #endregion
                #region italic
                if (txtRange.CharacterFormat.Italic == FormatEffect.On)
                {
                    if (!iOpened)
                    {
                        strHTML += "<i>";
                        iOpened  = true;
                    }
                }
                else
                {
                    if (iOpened)
                    {
                        strHTML += "</i>";
                        iOpened  = false;
                    }
                }
                #endregion
                #region underline
                if (txtRange.CharacterFormat.Underline == UnderlineType.Single)
                {
                    if (!uOpened)
                    {
                        strHTML += "<u>";
                        uOpened  = true;
                    }
                }
                else
                {
                    if (uOpened)
                    {
                        strHTML += "</u>";
                        uOpened  = false;
                    }
                }
                #endregion
                strHTML += txtRange.Character;
            }
            strHTML += "</span></html>";
            return(strHTML);
        }
예제 #20
0
        private async void LoadEntriesByDate()
        {
            EntriesListView.Items.Add(
                new
            {
                date       = MainCalendar.SelectedDates[0].ToString("yyyy-MM-dd"),
                entryCount = 12
            }
                );

            String ymfolder = YMDDate.Substring(0, 7);

            if (Directory.Exists(Path.Combine(appHomeFolder.Path, ymfolder)))
            {
                String[] allCurrentFiles = Directory.GetFiles(
                    Path.Combine(appHomeFolder.Path, ymfolder),
                    String.Format("{0}*.rtf", YMDDate),
                    SearchOption.TopDirectoryOnly);
                if (allCurrentFiles.Length > 0)
                {
                    LoadFileFromStorage(ymfolder,
                                        System.IO.Path.GetFileName(allCurrentFiles[0]), MainRichEdit);

                    currentJournalEntries.Add(
                        new JournalEntry(MainRichEdit, appHomeFolder.Path,
                                         YMDDate, "Entry1",
                                         Path.GetFileName(allCurrentFiles[0])));

                    allCurrentFiles = allCurrentFiles.Skip(1).ToArray();

                    foreach (String f in allCurrentFiles)
                    {
                        PivotItem pi        = new PivotItem();
                        var       entryText = String.Format("Entry{0}", rootPivot.Items.Count + 1);

                        pi.Header = entryText;

                        RichEditBox reb = new RichEditBox();
                        reb.HorizontalAlignment = HorizontalAlignment.Stretch;
                        reb.VerticalAlignment   = VerticalAlignment.Stretch;

                        LoadFileFromStorage(ymfolder, System.IO.Path.GetFileName(f), reb);

                        currentJournalEntries.Add(
                            new JournalEntry(reb,
                                             Path.Combine(appHomeFolder.Path),
                                             YMDDate, entryText));

                        pi.Content = reb;
                        pi.Loaded += PivotItem_Loaded;
                        rootPivot.Items.Add(pi);

                        rootPivot.SelectedIndex = 0;
                    }
                }
                else
                {
                    AddDefaultEntry();
                }
            }
            else
            {
                AddDefaultEntry();
            }
        }
 private void OnCodeEditorSelectionChanging(RichEditBox sender, RichEditBoxSelectionChangingEventArgs e)
 {
     previousSelection = currentSelection;
     currentSelection  = new TextSpan(e.SelectionStart, e.SelectionLength);
 }
예제 #22
0
 public static void RichEditBoxSetError(RichEditBox richEditBox, String errorMsg)
 {
     RichEditBoxSetText(richEditBox, errorMsg, Windows.UI.Colors.Red, true);
 }
예제 #23
0
        /// <summary>
        /// Opens a <see cref="ContentDialog"/> for the user to enter a URL
        /// </summary>
        /// <param name="button">The <see cref="ToolbarButton"/> invoked</param>
        public async void OpenLinkCreator(ToolbarButton button)
        {
            var selection = button.Model.Editor.Document.Selection;

            var labelBox = new RichEditBox
            {
                PlaceholderText = StringExtensions.GetLocalized("TextToolbarStrings_LabelLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
                Margin          = new Thickness(0, 0, 0, 5),
                AcceptsReturn   = false
            };
            var linkBox = new TextBox
            {
                PlaceholderText = StringExtensions.GetLocalized("TextToolbarStrings_UrlLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources")
            };

            CheckBox relativeBox = null;

            var contentPanel = new StackPanel
            {
                Children =
                {
                    labelBox,
                    linkBox
                }
            };

            if (Model.UseURIChecker)
            {
                relativeBox = new CheckBox
                {
                    Content = StringExtensions.GetLocalized("TextToolbarStrings_RelativeLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources")
                };
                contentPanel.Children.Add(relativeBox);
            }

            labelBox.Document.SetDefaultCharacterFormat(selection.CharacterFormat);
            selection.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out string labeltext);
            labelBox.Document.SetText(Windows.UI.Text.TextSetOptions.FormatRtf, labeltext);

            var contentDialog = new ContentDialog
            {
                Title               = StringExtensions.GetLocalized("TextToolbarStrings_CreateLinkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
                Content             = contentPanel,
                PrimaryButtonText   = StringExtensions.GetLocalized("TextToolbarStrings_OkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources"),
                SecondaryButtonText = StringExtensions.GetLocalized("TextToolbarStrings_CancelLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources")
            };

            if (ControlHelpers.IsXamlRootAvailable && button.XamlRoot != null)
            {
                contentDialog.XamlRoot = button.XamlRoot;
            }

            var result = await contentDialog.ShowAsync();

            if (result == ContentDialogResult.Primary)
            {
                labelBox.Document.GetText(Windows.UI.Text.TextGetOptions.None, out string labelText);
                labelBox.Document.GetText(Windows.UI.Text.TextGetOptions.FormatRtf, out string formattedlabelText);

                string linkInvalidLabel = StringExtensions.GetLocalized("TextToolbarStrings_LinkInvalidLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources");
                string okLabel          = StringExtensions.GetLocalized("TextToolbarStrings_OkLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources");
                string warningLabel     = StringExtensions.GetLocalized("TextToolbarStrings_WarningLabel", "Microsoft.Toolkit.Uwp.UI.Controls/Resources");
                string linkText         = linkBox.Text.Trim();

                if (string.IsNullOrWhiteSpace(linkText))
                {
                    ShowContentDialog(warningLabel, linkInvalidLabel, okLabel, button);
                    return;
                }

                if (Model.UseURIChecker && !string.IsNullOrWhiteSpace(linkText))
                {
                    var wellFormed = Uri.IsWellFormedUriString(linkText, relativeBox?.IsChecked == true ? UriKind.RelativeOrAbsolute : UriKind.Absolute);
                    if (!wellFormed)
                    {
                        ShowContentDialog(warningLabel, linkInvalidLabel, okLabel, button);
                        return;
                    }
                }

                Model.Formatter.ButtonActions.FormatLink(button, labelText.Trim(), formattedlabelText.Trim(), linkText);
            }
        }
 public bool Left(ref RichEditBox display)
 {
     display.Document.Selection.ParagraphFormat.Alignment = Windows.UI.Text.ParagraphAlignment.Left;
     focus(ref display);
     return(display.Document.Selection.ParagraphFormat.Alignment.Equals(Windows.UI.Text.ParagraphAlignment.Left));
 }
 public bool Italic(ref RichEditBox display)
 {
     display.Document.Selection.CharacterFormat.Italic = Windows.UI.Text.FormatEffect.Toggle;
     focus(ref display);
     return(display.Document.Selection.CharacterFormat.Italic.Equals(Windows.UI.Text.FormatEffect.On));
 }
 private static void PutCursorFollowEndPositionBeforeSetText(RichEditBox editor)
 {
     editor.Document.Selection.StartPosition += 1;
     editor.Document.Selection.EndPosition   += 1;
 }
 private static void PutCursorFollowEndPositionAfterSetText(RichEditBox editor, int wordLength)
 {
     editor.Document.Selection.StartPosition += wordLength;
     editor.Document.Selection.EndPosition   += wordLength;
 }
예제 #28
0
 private void TextField_TextChanging(RichEditBox sender, RichEditBoxTextChangingEventArgs args)
 {
     CheckMessageBoxEmpty();
 }
예제 #29
0
 public static void RichEditBoxSetMsg(RichEditBox richEditBox, String msg, bool fReadOnly)
 {
     RichEditBoxSetText(richEditBox, msg, Windows.UI.Colors.White, fReadOnly);
 }
예제 #30
0
 public static ITextSelection GetRichTextSelection(RichEditBox richEditBox)
 {
     return(richEditBox.Document?.Selection);
 }