Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
dxn-9 committed Aug 11, 2023
0 parents commit 5620d86
Show file tree
Hide file tree
Showing 11 changed files with 710 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.vs
bin
obj
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Lorem Ipsum Generator for PowerToys Run

## Installation

Download the release or compile it and copy the folder 'Lorem' to
%LOCALAPPDATA%/Microsoft/PowerToys/PowerToys Run/Plugins

## Usage

Type in PowerToys Run the command: lorem _number_of_words_, press Enter and it will be copied to your clipboard.

![Example](https://i.gyazo.com/e05bb208eee96364be5c118267168d35.png)
25 changes: 25 additions & 0 deletions src/Lorem.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.32014.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Lorem", "Lorem\Lorem.csproj", "{288BAC19-8B63-44DA-86E4-8DD6C6BE29D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{288BAC19-8B63-44DA-86E4-8DD6C6BE29D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{288BAC19-8B63-44DA-86E4-8DD6C6BE29D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{288BAC19-8B63-44DA-86E4-8DD6C6BE29D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{288BAC19-8B63-44DA-86E4-8DD6C6BE29D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3F0788A9-2D00-4744-B088-825CE465F873}
EndGlobalSection
EndGlobal
33 changes: 33 additions & 0 deletions src/Lorem/Lorem.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>

<ItemGroup>
<Reference Include="PowerToys.Common.UI">
<HintPath>..\libs\PowerToys.Common.UI.dll</HintPath>
</Reference>
<Reference Include="PowerToys.ManagedCommon">
<HintPath>..\libs\PowerToys.ManagedCommon.dll</HintPath>
</Reference>
<Reference Include="Wox.Infrastructure">
<HintPath>..\libs\Wox.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="Wox.Plugin">
<HintPath>..\libs\Wox.Plugin.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="plugin.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="lorem.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
126 changes: 126 additions & 0 deletions src/Lorem/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
using ManagedCommon;
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using Wox.Plugin;

using System.Diagnostics.Tracing;
using System.Windows.Shapes;
using System.Linq;

namespace Lorem
{
public class Main : IPlugin
{


private PluginInitContext Context { get; set; }
public string Name => "Lorem";

public string Description => "Lorem Ipsum Generator";

public List<Result> Query(Query query)
{

var results = new List<Result>();

var strs = query.RawQuery.Split(" ");
var nums = strs[1];

if(long.TryParse(nums, out var result))
{
string lorem = GetLorem(result);

if(lorem != null)
{
results.Add(new Result
{
Title = lorem,
Action = e => {
Clipboard.SetText(lorem);
return true;
},
});
}


}



return results;
}

public string? GetLorem(long WordsNumber)
{

try
{
// Get the directory where the current assembly (DLL) is located
string assemblyDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

// Specify the relative path to the file
string relativeFilePath = "lorem.txt";

// Combine the assembly directory with the relative file path to get the full path
string fullPath = System.IO.Path.Combine(assemblyDirectory, relativeFilePath);

// Check if the file exists
if (File.Exists(fullPath))
{
// Use FileStream to read the file as a stream
using FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read);
// Read the file's content as a stream
using StreamReader streamReader = new StreamReader(fileStream);
// Read and display each line in the file
var wordsList = new List<string>();


long ReadWords = 0;
string line;
while ((line = streamReader.ReadLine()) != null && ReadWords != WordsNumber)
{

var words = line.Trim().Split(' ');
foreach (string word in words)
{
if (ReadWords < WordsNumber)
{
wordsList.Add(word);
}
ReadWords += 1;
}

}

return string.Join(" ", wordsList);
}
else
{

return null;
}
}
catch (Exception ex)
{

return null;
}

}



public void Init(PluginInitContext context)
{
Context = context;


}


}
}
Loading

0 comments on commit 5620d86

Please sign in to comment.