Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
sir-kokabi committed Oct 23, 2023
1 parent 29efd34 commit d7abf8f
Show file tree
Hide file tree
Showing 79 changed files with 23,093 additions and 2 deletions.
213 changes: 211 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Created by https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,git,dotnetcore
# Edit at https://www.toptal.com/developers/gitignore?templates=visualstudio,csharp,git,dotnetcore

### Csharp ###
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
Expand Down Expand Up @@ -302,8 +306,6 @@ node_modules/
*.dsp

# Visual Studio 6 technical files
*.ncb
*.aps

# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
Expand Down Expand Up @@ -396,3 +398,210 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml

### DotnetCore ###
# .NET Core build folders
bin/
obj/

# Common node modules locations
/node_modules
/wwwroot/node_modules

### Git ###
# Created by git for backups. To disable backups in Git:
# $ git config --global mergetool.keepBackup false
*.orig

# Created by git when using merge tools for conflicts
*.BACKUP.*
*.BASE.*
*.LOCAL.*
*.REMOTE.*
*_BACKUP_*.txt
*_BASE_*.txt
*_LOCAL_*.txt
*_REMOTE_*.txt

### VisualStudio ###

# User-specific files

# User-specific files (MonoDevelop/Xamarin Studio)

# Mono auto generated files

# Build results

# Visual Studio 2015/2017 cache/options directory
# Uncomment if you have tasks that create the project's static files in wwwroot

# Visual Studio 2017 auto generated files

# MSTest test Results

# NUnit

# Build Results of an ATL Project

# Benchmark Results

# .NET Core

# ASP.NET Scaffolding

# StyleCop

# Files built by Visual Studio

# Chutzpah Test files

# Visual C++ cache files

# Visual Studio profiler

# Visual Studio Trace Files

# TFS 2012 Local Workspace

# Guidance Automation Toolkit

# ReSharper is a .NET coding add-in

# TeamCity is a build add-in

# DotCover is a Code Coverage Tool

# AxoCover is a Code Coverage Tool

# Coverlet is a free, cross platform Code Coverage Tool

# Visual Studio code coverage results

# NCrunch

# MightyMoose

# Web workbench (sass)

# Installshield output folder

# DocProject is a documentation generator add-in

# Click-Once directory

# Publish Web Output
# Note: Comment the next line if you want to checkin your web deploy settings,
# but database connection strings (with potential passwords) will be unencrypted

# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted

# NuGet Packages
# NuGet Symbol Packages
# The packages folder can be ignored because of Package Restore
# except build/, which is used as an MSBuild target.
# Uncomment if necessary however generally it will be regenerated when needed
# NuGet v3's project.json files produces more ignorable files

# Microsoft Azure Build Output

# Microsoft Azure Emulator

# Windows Store app package directories and files

# Visual Studio cache files
# files ending in .cache can be ignored
# but keep track of directories ending in .cache

# Others

# Including strong name files can present a security risk
# (https://github.com/github/gitignore/pull/2483#issue-259490424)

# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)

# RIA/Silverlight projects

# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)

# SQL Server files

# Business Intelligence projects

# Microsoft Fakes

# GhostDoc plugin setting file

# Node.js Tools for Visual Studio

# Visual Studio 6 build log

# Visual Studio 6 workspace options file

# Visual Studio 6 auto-generated workspace file (contains which files were open etc.)

# Visual Studio 6 auto-generated project file (contains which files were open etc.)

# Visual Studio 6 workspace and project file (working project files containing files to include in project)

# Visual Studio 6 technical files

# Visual Studio LightSwitch build output

# Paket dependency manager

# FAKE - F# Make

# CodeRush personal settings

# Python Tools for Visual Studio (PTVS)

# Cake - Uncomment if you are using it
# tools/**
# !tools/packages.config

# Tabs Studio

# Telerik's JustMock configuration file

# BizTalk build output

# OpenCover UI analysis results

# Azure Stream Analytics local run output

# MSBuild Binary and Structured Log

# NVidia Nsight GPU debugger configuration file

# MFractors (Xamarin productivity tool) working folder

# Local History for Visual Studio

# Visual Studio History (VSHistory) files

# BeatPulse healthcheck temp database

# Backup folder for Package Reference Convert tool in Visual Studio 2017

# Ionide (cross platform F# VS Code tools) working folder

# Fody - auto-generated XML schema

# VS Code files for those working on multiple tools

# Local History for Visual Studio Code

# Windows Installer files from build outputs

# JetBrains Rider

### VisualStudio Patch ###
# Additional files built by Visual Studio

# End of https://www.toptal.com/developers/gitignore/api/visualstudio,csharp,git,dotnetcore
25 changes: 25 additions & 0 deletions WhichKey.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.8.34205.153
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WhichKey", "WhichKey\WhichKey.csproj", "{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A6655C53-BA5D-48C6-8A84-C033FFD45C2B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {814AD2CE-BFB7-4F71-BF1F-C3D289AF9357}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions WhichKey/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application x:Class="WhichKey.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
DispatcherUnhandledException="App_OnDispatcherUnhandledException"
>
<Application.Resources/>
</Application>
87 changes: 87 additions & 0 deletions WhichKey/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
using NHotkey;
using NHotkey.Wpf;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Input;
using System.Windows.Threading;
using WhichKey.ViewModels;


namespace WhichKey
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
public Window _mainWindow = new MainWindow();

protected override void OnStartup(StartupEventArgs e)
{
_mainWindow.PreviewKeyDown += _mainWindow_PreviewKeyDown;
_mainWindow.StateChanged+= MainWindow_OnStateChanged;
HotkeyManager.Current.AddOrReplace("ShowWindow", Key.None, ModifierKeys.Control | ModifierKeys.Alt, ShowWindow);
base.OnStartup(e);
}

private void MainWindow_OnStateChanged(object? sender, EventArgs e)
{

if (_mainWindow.WindowState == WindowState.Minimized)
{
_mainWindow.Hide();
}
}

private void _mainWindow_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
_mainWindow.WindowState = WindowState.Minimized;
}
}

private void ShowWindow(object? sender, HotkeyEventArgs e)
{
var appName = GetActiveProcessFileName();
_mainWindow.DataContext = new MainViewModel(appName.ToLower());
_mainWindow.Show();
_mainWindow.Activate();
_mainWindow.WindowState=WindowState.Normal;

e.Handled = true;
if (_mainWindow is MainWindow mainWindow)
{
if (mainWindow.ShortcutListingView.SearchTextBox != null)
{
mainWindow.ShortcutListingView.SearchTextBox.Focus();
mainWindow.ShortcutListingView.SearchTextBox.SelectAll();
}
}
}

private void App_OnDispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var text = $"\n\n{DateTime.Now}\n{e.Exception.ToStringDemystified()}";
var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "log.txt");
File.AppendAllText(path, text);
}

[DllImport("user32.dll")]
public static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, out uint processId);

[DllImport("user32.dll")]
private static extern IntPtr GetForegroundWindow();

static string GetActiveProcessFileName()
{
var hwnd = GetForegroundWindow();
GetWindowThreadProcessId(hwnd, out var pid);
var p = Process.GetProcessById((int)pid);
return p.ProcessName;
}
}

}
10 changes: 10 additions & 0 deletions WhichKey/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
Loading

0 comments on commit d7abf8f

Please sign in to comment.