Initial Commit
This commit is contained in:
Коммит
86c700a415
Двоичный файл не отображается.
После Ширина: | Высота: | Размер: 26 KiB |
|
@ -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("")]
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="..\packages\NUnit.3.11.0\build\NUnit.props" Condition="Exists('..\packages\NUnit.3.11.0\build\NUnit.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{70C11D03-0B14-41A7-88D3-268C216CB086}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<RootNamespace>VS4Mac.TextGenerator.Tests</RootNamespace>
|
||||
<AssemblyName>VS4Mac.TextGenerator.Tests</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug</OutputPath>
|
||||
<DefineConstants>DEBUG;</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release</OutputPath>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<ConsolePause>false</ConsolePause>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="nunit.framework">
|
||||
<HintPath>..\packages\NUnit.3.11.0\lib\net45\nunit.framework.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="TextGeneratorServiceTests.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\VS4Mac.TextGenerator\VS4Mac.TextGenerator.csproj">
|
||||
<Project>{28CF4525-CBE2-428F-A525-6E60F9F4BEA2}</Project>
|
||||
<Name>VS4Mac.TextGenerator</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
|
||||
<StartAction>Project</StartAction>
|
||||
<ConsolePause>true</ConsolePause>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="NUnit" version="3.11.0" targetFramework="net47" />
|
||||
</packages>
|
|
@ -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
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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")]
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Addin
|
||||
id = "com.jsuarezruiz.textgenerator">
|
||||
<Header>
|
||||
<Name>Text Generator Addin</Name>
|
||||
<Description>VS4Mac addin with functionality to generate dummy text.</Description>
|
||||
<Author>Javier Suárez</Author>
|
||||
<Copyright>Javier Suárez</Copyright>
|
||||
<Url>https://github.com/jsuarezruiz/VSMac-TextGenerator</Url>
|
||||
</Header>
|
||||
<Extension
|
||||
path = "/MonoDevelop/Ide/Commands/Edit">
|
||||
<Command
|
||||
id = "TextGenerator.Commands.GenerateText"
|
||||
_label = "Generate text..."
|
||||
defaultHandler = "VS4Mac.TextGenerator.Commands.GenerateTextCommand" />
|
||||
</Extension>
|
||||
<Extension
|
||||
path = "/MonoDevelop/Ide/MainMenu/Edit">
|
||||
<CommandItem
|
||||
id="TextGenerator.Commands.GenerateText" />
|
||||
</Extension>
|
||||
</Addin>
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net461</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MonoDevelop.Addins" Version="0.4.4" />
|
||||
<PackageReference Include="NLipsum" Version="1.1.0" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\" />
|
||||
<Folder Include="Commands\" />
|
||||
<Folder Include="Services\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче