commit 86c700a415e8267866edbce609a3d6bd106a47fa Author: Javier Suárez Ruiz Date: Sat Jan 12 13:50:16 2019 +0100 Initial Commit diff --git a/images/generate-text.png b/images/generate-text.png new file mode 100644 index 0000000..53f5df8 Binary files /dev/null and b/images/generate-text.png differ diff --git a/src/VS4Mac.TextGenerator.Tests/Properties/AssemblyInfo.cs b/src/VS4Mac.TextGenerator.Tests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..95aec4c --- /dev/null +++ b/src/VS4Mac.TextGenerator.Tests/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("VS4Mac.TextGenerator.Tests")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/src/VS4Mac.TextGenerator.Tests/TextGeneratorServiceTests.cs b/src/VS4Mac.TextGenerator.Tests/TextGeneratorServiceTests.cs new file mode 100644 index 0000000..cf67e54 --- /dev/null +++ b/src/VS4Mac.TextGenerator.Tests/TextGeneratorServiceTests.cs @@ -0,0 +1,27 @@ +using NUnit.Framework; +using VS4Mac.TextGenerator.Services; + +namespace VS4Mac.TextGenerator.Tests +{ + [TestFixture] + public class TextGeneratorServiceTests + { + [Test] + public void GenerateWordsTest() + { + var textGeneratorService = new TextGeneratorService(); + var words = textGeneratorService.GenerateWords(5); + + Assert.AreEqual(5, words.Length); + } + + [Test] + public void GenerateSentencesTest() + { + var textGeneratorService = new TextGeneratorService(); + var words = textGeneratorService.GenerateSentences(2); + + Assert.AreEqual(2, words.Length); + } + } +} \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator.Tests/VS4Mac.TextGenerator.Tests.csproj b/src/VS4Mac.TextGenerator.Tests/VS4Mac.TextGenerator.Tests.csproj new file mode 100644 index 0000000..2880c4b --- /dev/null +++ b/src/VS4Mac.TextGenerator.Tests/VS4Mac.TextGenerator.Tests.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + {70C11D03-0B14-41A7-88D3-268C216CB086} + Library + VS4Mac.TextGenerator.Tests + VS4Mac.TextGenerator.Tests + v4.7 + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + false + + + + + ..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll + + + + + + + + + + + + {28CF4525-CBE2-428F-A525-6E60F9F4BEA2} + VS4Mac.TextGenerator + + + + \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator.Tests/VS4Mac.TextGenerator.Tests.csproj.user b/src/VS4Mac.TextGenerator.Tests/VS4Mac.TextGenerator.Tests.csproj.user new file mode 100644 index 0000000..7306da1 --- /dev/null +++ b/src/VS4Mac.TextGenerator.Tests/VS4Mac.TextGenerator.Tests.csproj.user @@ -0,0 +1,7 @@ + + + + Project + true + + \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator.Tests/packages.config b/src/VS4Mac.TextGenerator.Tests/packages.config new file mode 100644 index 0000000..25dca1e --- /dev/null +++ b/src/VS4Mac.TextGenerator.Tests/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator.sln b/src/VS4Mac.TextGenerator.sln new file mode 100644 index 0000000..9508b38 --- /dev/null +++ b/src/VS4Mac.TextGenerator.sln @@ -0,0 +1,23 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VS4Mac.TextGenerator", "VS4Mac.TextGenerator\VS4Mac.TextGenerator.csproj", "{28CF4525-CBE2-428F-A525-6E60F9F4BEA2}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VS4Mac.TextGenerator.Tests", "VS4Mac.TextGenerator.Tests\VS4Mac.TextGenerator.Tests.csproj", "{70C11D03-0B14-41A7-88D3-268C216CB086}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {28CF4525-CBE2-428F-A525-6E60F9F4BEA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28CF4525-CBE2-428F-A525-6E60F9F4BEA2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28CF4525-CBE2-428F-A525-6E60F9F4BEA2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28CF4525-CBE2-428F-A525-6E60F9F4BEA2}.Release|Any CPU.Build.0 = Release|Any CPU + {70C11D03-0B14-41A7-88D3-268C216CB086}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {70C11D03-0B14-41A7-88D3-268C216CB086}.Debug|Any CPU.Build.0 = Debug|Any CPU + {70C11D03-0B14-41A7-88D3-268C216CB086}.Release|Any CPU.ActiveCfg = Release|Any CPU + {70C11D03-0B14-41A7-88D3-268C216CB086}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/VS4Mac.TextGenerator/Commands/GenerateTextCommand.cs b/src/VS4Mac.TextGenerator/Commands/GenerateTextCommand.cs new file mode 100644 index 0000000..714b239 --- /dev/null +++ b/src/VS4Mac.TextGenerator/Commands/GenerateTextCommand.cs @@ -0,0 +1,22 @@ +using MonoDevelop.Components.Commands; +using MonoDevelop.Ide; +using VS4Mac.TextGenerator.Views; + +namespace VS4Mac.TextGenerator.Commands +{ + public class GenerateTextCommand : CommandHandler + { + protected override void Run() + { + using (var generateTextDialog = new GenerateTextDialog()) + { + generateTextDialog.Run(Xwt.MessageDialog.RootWindow); + } + } + + protected override void Update(CommandInfo info) + { + info.Enabled = IdeApp.Workbench.ActiveDocument?.Editor != null; + } + } +} \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator/Properties/AddinInfo.cs b/src/VS4Mac.TextGenerator/Properties/AddinInfo.cs new file mode 100644 index 0000000..3ae1343 --- /dev/null +++ b/src/VS4Mac.TextGenerator/Properties/AddinInfo.cs @@ -0,0 +1,13 @@ +using Mono.Addins; +using Mono.Addins.Description; + +[assembly: Addin( + "VS4Mac.TextGenerator", + Namespace = "VS4Mac.TextGenerator", + Version = "0.1" +)] + +[assembly: AddinName("VS4Mac.TextGenerator")] +[assembly: AddinCategory("IDE extensions")] +[assembly: AddinDescription("VS4Mac.TextGenerator")] +[assembly: AddinAuthor("Javier Suárez Ruiz")] \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator/Properties/Manifest.addin.xml b/src/VS4Mac.TextGenerator/Properties/Manifest.addin.xml new file mode 100644 index 0000000..9104d7e --- /dev/null +++ b/src/VS4Mac.TextGenerator/Properties/Manifest.addin.xml @@ -0,0 +1,23 @@ + + +
+ Text Generator Addin + VS4Mac addin with functionality to generate dummy text. + Javier Suárez + Javier Suárez + https://github.com/jsuarezruiz/VSMac-TextGenerator +
+ + + + + + +
\ No newline at end of file diff --git a/src/VS4Mac.TextGenerator/Services/TextGeneratorService.cs b/src/VS4Mac.TextGenerator/Services/TextGeneratorService.cs new file mode 100644 index 0000000..867c6ed --- /dev/null +++ b/src/VS4Mac.TextGenerator/Services/TextGeneratorService.cs @@ -0,0 +1,42 @@ +using NLipsum.Core; + +namespace VS4Mac.TextGenerator.Services +{ + public class TextGeneratorService + { + LipsumGenerator _generator; + + public TextGeneratorService() + { + _generator = new LipsumGenerator(); + } + + public string[] GenerateWords(int numberOfWords) + { + string[] words = _generator.GenerateWords(numberOfWords); + + return words; + } + + public string[] GenerateCharacters(int numberOfChars) + { + string[] words = _generator.GenerateCharacters(numberOfChars); + + return words; + } + + public string[] GenerateSentences(int numberOfSentences) + { + string[] words = _generator.GenerateSentences(numberOfSentences); + + return words; + } + + public string GenerateLipsumHtml(int count) + { + string html = _generator.GenerateLipsumHtml(count); + + return html; + } + } +} \ No newline at end of file diff --git a/src/VS4Mac.TextGenerator/VS4Mac.TextGenerator.csproj b/src/VS4Mac.TextGenerator/VS4Mac.TextGenerator.csproj new file mode 100644 index 0000000..e30b479 --- /dev/null +++ b/src/VS4Mac.TextGenerator/VS4Mac.TextGenerator.csproj @@ -0,0 +1,14 @@ + + + net461 + + + + + + + + + + + diff --git a/src/VS4Mac.TextGenerator/Views/GenerateTextDialog.cs b/src/VS4Mac.TextGenerator/Views/GenerateTextDialog.cs new file mode 100644 index 0000000..a6c8c45 --- /dev/null +++ b/src/VS4Mac.TextGenerator/Views/GenerateTextDialog.cs @@ -0,0 +1,102 @@ +using System; +using MonoDevelop.Core; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Gui; +using VS4Mac.TextGenerator.Services; +using Xwt; + +namespace VS4Mac.TextGenerator.Views +{ + public class GenerateTextDialog : Dialog + { + VBox _mainBox; + HBox _numberBox; + Label _numberLabel; + TextEntry _numberEntry; + HBox _buttonBox; + Button _generateButton; + + TextGeneratorService _textGeneratorService; + + public GenerateTextDialog() + { + Init(); + BuildGui(); + AttachEvents(); + } + + void Init() + { + Title = "Text Generator"; + + _textGeneratorService = new TextGeneratorService(); + + _mainBox = new VBox + { + HeightRequest = 50, + WidthRequest = 200 + }; + + _numberBox = new HBox(); + _numberLabel = new Label("Introduce number of words:"); + + _numberEntry = new TextEntry + { + WidthRequest = 48 + }; + + _buttonBox = new HBox(); + _generateButton = new Button("Add") + { + BackgroundColor = Styles.BaseSelectionBackgroundColor, + LabelColor = Styles.BaseSelectionTextColor, + WidthRequest = 48 + }; + } + + void BuildGui() + { + _numberBox.PackStart(_numberLabel, true); + _numberBox.PackEnd(_numberEntry, false); + _buttonBox.PackEnd(_generateButton); + + _mainBox.PackStart(_numberBox); + _mainBox.PackEnd(_buttonBox); + + Content = _mainBox; + Resizable = false; + } + + void AttachEvents() + { + _numberEntry.Changed += OnNumberEntryChanged; + _generateButton.Clicked += OnGenerateClicked; + } + + void OnNumberEntryChanged(object sender, EventArgs e) + { + if (System.Text.RegularExpressions.Regex.IsMatch(_numberEntry.Text, "[^0-9]")) + { + _numberEntry.Text = _numberEntry.Text.Remove(_numberEntry.Text.Length - 1); + } + } + + void OnGenerateClicked(object sender, EventArgs args) + { + try + { + var editor = IdeApp.Workbench.ActiveDocument.Editor; + int.TryParse(_numberEntry.Text, out int numberOfWords); + var words = _textGeneratorService.GenerateWords(numberOfWords); + var result = string.Join(" ", words); + editor.InsertAtCaret(result); + + Respond(Command.Ok); + } + catch (Exception ex) + { + LoggingService.LogError(ex.Message, ex); + } + } + } +} \ No newline at end of file