A Swiss Army knife for developers.
C# blazorcross-platformcsharpdesktopdesktop-appdesktop-applicationdeveloper-toolsextensiblefluentfluent-designlinuxmacosmicasyntax-highlightingtypescriptwindowswindows-10windows-11winui
New option to the generator that starts generation with "Lorem Ipsum dolor sit amet..." (#392)
Guus Beltmanc26266c05923
diff --git a/src/dev/impl/DevToys/LanguageManager.cs b/src/dev/impl/DevToys/LanguageManager.csindex 4cfac63ad..731ffd521 100644--- a/src/dev/impl/DevToys/LanguageManager.cs+++ b/src/dev/impl/DevToys/LanguageManager.cs@@ -1400,6 +1400,11 @@ namespace DevToys/// </summary>public string SentencesType => _resources.GetString("SentencesType");+ /// <summary>+ /// Gets the resource StartWithLoremTitle.+ /// </summary>+ public string StartWithLoremTitle => _resources.GetString("StartWithLoremTitle");+/// <summary>/// Gets the resource TypeDescription./// </summary>diff --git a/src/dev/impl/DevToys/Strings/cs-CZ/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/cs-CZ/LoremIpsumGenerator.reswindex a17f4b4c7..5995b4ad2 100644--- a/src/dev/impl/DevToys/Strings/cs-CZ/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/cs-CZ/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Věty</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generovat slova, věty nebo odstavce</value></data>diff --git a/src/dev/impl/DevToys/Strings/de-DE/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/de-DE/LoremIpsumGenerator.reswindex 17f369a4d..37a1cb8c0 100644--- a/src/dev/impl/DevToys/Strings/de-DE/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/de-DE/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Sätze</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generiere Wörter, Sätze oder Absätze mit Lorem Ipsum Text</value></data>diff --git a/src/dev/impl/DevToys/Strings/en-US/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/en-US/LoremIpsumGenerator.reswindex b350b2c32..d68e3dd43 100644--- a/src/dev/impl/DevToys/Strings/en-US/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/en-US/LoremIpsumGenerator.resw@@ -1,17 +1,17 @@<?xml version="1.0" encoding="utf-8"?><root>- <!--- Microsoft ResX Schema-+ <!--+ Microsoft ResX Schema+Version 2.0-- The primary goals of this format is to allow a simple XML format- that is mostly human readable. The generation and parsing of the- various data types are done through the TypeConverter classes++ The primary goals of this format is to allow a simple XML format+ that is mostly human readable. The generation and parsing of the+ various data types are done through the TypeConverter classesassociated with the data types.-+Example:-+... ado.net/XML headers & schema ...<resheader name="resmimetype">text/microsoft-resx</resheader><resheader name="version">2.0</resheader>@@ -26,36 +26,36 @@<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value><comment>This is a comment</comment></data>-- There are any number of "resheader" rows that contain simple++ There are any number of "resheader" rows that contain simplename/value pairs.-- Each data row contains a name, and value. The row also contains a- type or mimetype. Type corresponds to a .NET class that support- text/value conversion through the TypeConverter architecture.- Classes that don't support this are serialized and stored with the++ Each data row contains a name, and value. The row also contains a+ type or mimetype. Type corresponds to a .NET class that support+ text/value conversion through the TypeConverter architecture.+ Classes that don't support this are serialized and stored with themimetype set.-- The mimetype is used for serialized objects, and tells the- ResXResourceReader how to depersist the object. This is currently not++ The mimetype is used for serialized objects, and tells the+ ResXResourceReader how to depersist the object. This is currently notextensible. For a given mimetype the value must be set accordingly:-- Note - application/x-microsoft.net.object.binary.base64 is the format- that the ResXResourceWriter will generate, however the reader can++ Note - application/x-microsoft.net.object.binary.base64 is the format+ that the ResXResourceWriter will generate, however the reader canread any of the formats listed below.-+mimetype: application/x-microsoft.net.object.binary.base64- value : The object must be serialized with+ value : The object must be serialized with: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter: and then encoded with base64 encoding.-+mimetype: application/x-microsoft.net.object.soap.base64- value : The object must be serialized with+ value : The object must be serialized with: System.Runtime.Serialization.Formatters.Soap.SoapFormatter: and then encoded with base64 encoding.mimetype: application/x-microsoft.net.object.bytearray.base64- value : The object must be serialized into a byte array+ value : The object must be serialized into a byte array: using a System.ComponentModel.TypeConverter: and then encoded with base64 encoding.-->@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Sentences</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generate words, sentences or paragraphs of Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/es-AR/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/es-AR/LoremIpsumGenerator.reswindex de69b5160..f662447c8 100644--- a/src/dev/impl/DevToys/Strings/es-AR/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/es-AR/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Oraciones</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generar palabras, oraciones o párrafos de Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/es-ES/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/es-ES/LoremIpsumGenerator.reswindex 4a63bd810..febdf1f2b 100644--- a/src/dev/impl/DevToys/Strings/es-ES/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/es-ES/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Frases</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generar palabras, frases o párrafos de Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/fr-FR/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/fr-FR/LoremIpsumGenerator.reswindex b350b2c32..1a1909865 100644--- a/src/dev/impl/DevToys/Strings/fr-FR/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/fr-FR/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Sentences</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generate words, sentences or paragraphs of Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/hu-HU/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/hu-HU/LoremIpsumGenerator.reswindex d7b4931f6..52dabd1c5 100644--- a/src/dev/impl/DevToys/Strings/hu-HU/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/hu-HU/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Mondatok</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Lorem Ipsum szavak, mondatok vagy paragrafusok generálása</value></data>diff --git a/src/dev/impl/DevToys/Strings/id-ID/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/id-ID/LoremIpsumGenerator.reswindex 85073713e..c79a70104 100644--- a/src/dev/impl/DevToys/Strings/id-ID/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/id-ID/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Kalimat</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Buat kata, kalimat atau paragraf Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/it-IT/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/it-IT/LoremIpsumGenerator.reswindex 606050205..a4322c1ae 100644--- a/src/dev/impl/DevToys/Strings/it-IT/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/it-IT/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Frasi</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Genera placeholder Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/ja-JP/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/ja-JP/LoremIpsumGenerator.reswindex 36ec34641..903a607d8 100644--- a/src/dev/impl/DevToys/Strings/ja-JP/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/ja-JP/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>文</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>ダミーテキストの単語、文、または段落を生成します</value></data>diff --git a/src/dev/impl/DevToys/Strings/ko-KR/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/ko-KR/LoremIpsumGenerator.reswindex 34ced8e30..169c39374 100644--- a/src/dev/impl/DevToys/Strings/ko-KR/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/ko-KR/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>문장</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>로렌 입숨 내용을 생성할 단어, 문장 및 문단 개수를 선택 후 생성합니다.</value></data>diff --git a/src/dev/impl/DevToys/Strings/pl-PL/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/pl-PL/LoremIpsumGenerator.reswindex 8f181b3b8..c4f9dfca7 100644--- a/src/dev/impl/DevToys/Strings/pl-PL/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/pl-PL/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Zdania</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generuj słowa, zdania lub akapity Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/pt-PT/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/pt-PT/LoremIpsumGenerator.reswindex 18e82e297..9ece80b04 100644--- a/src/dev/impl/DevToys/Strings/pt-PT/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/pt-PT/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Sentenças</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Gera palavras, sentenças ou parágrafos de Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/ru-RU/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/ru-RU/LoremIpsumGenerator.reswindex b350b2c32..1a1909865 100644--- a/src/dev/impl/DevToys/Strings/ru-RU/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/ru-RU/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>Sentences</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>Generate words, sentences or paragraphs of Lorem Ipsum</value></data>diff --git a/src/dev/impl/DevToys/Strings/zh-Hans/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/zh-Hans/LoremIpsumGenerator.reswindex 550ac8ce2..e39aa2730 100644--- a/src/dev/impl/DevToys/Strings/zh-Hans/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/zh-Hans/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>句子</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>生成单词、句子或段落形式的乱数假文</value></data>diff --git a/src/dev/impl/DevToys/Strings/zh-Hant/LoremIpsumGenerator.resw b/src/dev/impl/DevToys/Strings/zh-Hant/LoremIpsumGenerator.reswindex 13e7a76c6..ade7edc33 100644--- a/src/dev/impl/DevToys/Strings/zh-Hant/LoremIpsumGenerator.resw+++ b/src/dev/impl/DevToys/Strings/zh-Hant/LoremIpsumGenerator.resw@@ -147,6 +147,9 @@<data name="SentencesType" xml:space="preserve"><value>句子</value></data>+ <data name="StartWithLoremTitle" xml:space="preserve">+ <value>Start with 'Lorem ipsum dolor sit amet...'</value>+ </data><data name="TypeDescription" xml:space="preserve"><value>產生假文單字、句子、或段落</value></data>diff --git a/src/dev/impl/DevToys/ViewModels/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolViewModel.cs b/src/dev/impl/DevToys/ViewModels/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolViewModel.csindex 9f126c480..b56bed9a5 100644--- a/src/dev/impl/DevToys/ViewModels/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolViewModel.cs+++ b/src/dev/impl/DevToys/ViewModels/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolViewModel.cs@@ -14,6 +14,7 @@ using DevToys.Shared.Core.Threading;using DevToys.Views.Tools.LoremIpsumGenerator;using Microsoft.Toolkit.Mvvm.ComponentModel;using NLipsum.Core;+using System.Linq;namespace DevToys.ViewModels.Tools.LoremIpsumGenerator{@@ -32,6 +33,17 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGeneratorisRoaming: true,defaultValue: 1);+ /// <summary>+ /// Whether the generated text should start with Lorem ipsum dolor sit amet+ /// </summary>+ private static readonly SettingDefinition<bool> StartWithLoremIpsum+ = new(+ name: $"{nameof(LoremIpsumGeneratorToolViewModel)}.{nameof(StartWithLoremIpsum)}",+ isRoaming: true,+ defaultValue: false);++ private const string LoremIpsumStartText = "Lorem ipsum dolor sit amet";+private const string ParagraphsType = "Paragraphs";private const string SentencesType = "Sentences";private const string WordsType = "Words";@@ -40,7 +52,7 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGeneratorprivate readonly IMarketingService _marketingService;private readonly ISettingsProvider _settingsProvider;- private readonly Queue<(string Type, int Length)> _generationQueue = new();+ private readonly Queue<(string Type, int Length, bool StartWithLoremIpsum)> _generationQueue = new();private string _output = string.Empty;private bool _generationInProgress;@@ -78,6 +90,20 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGenerator}}+ internal bool StartWithLorem+ {+ get => _settingsProvider.GetSetting(StartWithLoremIpsum);+ set+ {+ if (_settingsProvider.GetSetting(StartWithLoremIpsum) != value)+ {+ _settingsProvider.SetSetting(StartWithLoremIpsum, value);+ OnPropertyChanged();+ QueueGeneration();+ }+ }+ }+internal string Output{get => _output;@@ -95,7 +121,7 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGeneratorprivate void QueueGeneration(){- _generationQueue.Enqueue((LoremIpsumType, LoremIpsumLength));+ _generationQueue.Enqueue((LoremIpsumType, LoremIpsumLength, StartWithLorem));TreatQueueAsync().Forget();}@@ -110,9 +136,9 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGeneratorawait TaskScheduler.Default;- while (_generationQueue.TryDequeue(out (string Type, int Length) options))+ while (_generationQueue.TryDequeue(out (string Type, int Length, bool StartWithLoremIpsum) options)){- string output = GenerateLipsum(options.Type, options.Length);+ string output = GenerateLipsum(options.Type, options.Length, options.StartWithLoremIpsum);ThreadHelper.RunOnUIThreadAsync(() =>{@@ -129,7 +155,7 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGenerator_generationInProgress = false;}- private string GenerateLipsum(string type, int length)+ private string GenerateLipsum(string type, int length, bool startWithLoremIpsum){if (length <= 0){@@ -137,21 +163,37 @@ namespace DevToys.ViewModels.Tools.LoremIpsumGenerator}var generator = new LipsumGenerator();+ string startWords = startWithLoremIpsum ? LoremIpsumStartText : string.Empty;switch (type){case WordsType:string[] words = generator.GenerateWords(length);words[0] = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(words[0]);- return string.Join(' ', words);+ return ApplyStartWords(startWords, string.Join(' ', words));case SentencesType:- return string.Join(' ', generator.GenerateSentences(length, Sentence.Medium));+ return ApplyStartWords(startWords, string.Join(' ', generator.GenerateSentences(length, Sentence.Medium)));case ParagraphsType:- return string.Join($"{Environment.NewLine}{Environment.NewLine}",- generator.GenerateParagraphs(length, Paragraph.Medium));+ return ApplyStartWords(startWords, string.Join($"{Environment.NewLine}{Environment.NewLine}",+ generator.GenerateParagraphs(length, Paragraph.Medium)));default:return string.Empty;}}++ private string ApplyStartWords(string startText, string originalText)+ {+ if (string.IsNullOrWhiteSpace(startText))+ {+ return originalText;+ }++ char space = ' ';+ string[] startTokens = (startText ?? "").Split(space, StringSplitOptions.RemoveEmptyEntries);+ string[] endTokens = (originalText ?? "").Split(space, StringSplitOptions.RemoveEmptyEntries);+ int wordsNeeded = Math.Min(startTokens.Length, endTokens.Length);++ return string.Join(space, startTokens.Take(wordsNeeded).Concat(endTokens.Skip(wordsNeeded)));+ }}}diff --git a/src/dev/impl/DevToys/Views/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolPage.xaml b/src/dev/impl/DevToys/Views/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolPage.xamlindex 8abe609dd..7b9474712 100644--- a/src/dev/impl/DevToys/Views/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolPage.xaml+++ b/src/dev/impl/DevToys/Views/Tools/Generators/LoremIpsumGenerator/LoremIpsumGeneratorToolPage.xaml@@ -54,6 +54,17 @@SpinButtonPlacementMode="Compact"Value="{x:Bind ViewModel.LoremIpsumLength, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/></controls:ExpandableSettingControl>+ <controls:ExpandableSettingControl+ x:Name="StartWithLoremIpsumSetting"+ TabIndex="0"+ Title="{x:Bind ViewModel.Strings.StartWithLoremTitle}">+ <controls:ExpandableSettingControl.Icon>+ <FontIcon Glyph="" />+ </controls:ExpandableSettingControl.Icon>+ <ToggleSwitch+ Style="{StaticResource RightAlignedToggleSwitchStyle}"+ IsOn="{x:Bind ViewModel.StartWithLorem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>+ </controls:ExpandableSettingControl></StackPanel><controls:CustomTextBox