Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple changes and fixes from @glmnet and myself #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
838 changes: 838 additions & 0 deletions .gitignore

Large diffs are not rendered by default.

97 changes: 28 additions & 69 deletions RightKeyboard/Layout.cs
Original file line number Diff line number Diff line change
@@ -1,78 +1,37 @@
using System;
using System.IO;
using System.Reflection;
using System.Collections.Generic;
using System.Globalization;

namespace RightKeyboard {
/// <summary>
/// Represents a keyboard layout
/// </summary>
public class Layout {
private readonly ushort identifier;

/// <summary>
/// Gets the layout's identifier
/// </summary>
public ushort Identifier {
get {
return identifier;
}
}

private readonly string name;

/// <summary>
/// Gets the layout's name
/// </summary>
public string Name {
get {
return name;
}
}

/// <summary>
/// Initializes a new instance of Layout
/// </summary>
/// <param name="identifier"></param>
/// <param name="name"></param>
public Layout(ushort identifier, string name) {
this.identifier = identifier;
this.name = name;
namespace RightKeyboard
{
/// <summary>
/// Represents a keyboard layout
/// </summary>
public class Layout {

/// <summary>
/// Gets the layout's identifier
/// </summary>
public ushort Identifier { get; }

/// <summary>
/// Gets the layout's name
/// </summary>
public string Name { get; }

public IntPtr Hkl { get; set; }

/// <summary>
/// Initializes a new instance of Layout
/// </summary>
/// <param name="identifier"></param>
/// <param name="name"></param>
public Layout(ushort identifier, string name) {
this.Identifier = identifier;
Name = name;
}

public override string ToString() {
return name;
}

private static Layout[] cachedLayouts = null;

/// <summary>
/// Gets the keyboard layouts from a ressource file
/// </summary>
/// <returns></returns>
public static Layout[] GetLayouts() {
if(cachedLayouts == null) {
List<Layout> layouts = new List<Layout>();
using(Stream input = Assembly.GetExecutingAssembly().GetManifestResourceStream("RightKeyboard.Layouts.txt")) {
using(TextReader reader = new StreamReader(input)) {
string line;
while((line = reader.ReadLine()) != null) {
layouts.Add(GetLayout(line));
}
}
}
cachedLayouts = layouts.ToArray();
}
return cachedLayouts;
}

private static Layout GetLayout(string line) {
string[] parts = line.Trim().Split('=');

ushort identifier = ushort.Parse(parts[0], NumberStyles.HexNumber);
string name = parts[1];
return new Layout(identifier, name);
return Name + " (" + Hkl.ToString("X8") + ")";
}
}
}
205 changes: 103 additions & 102 deletions RightKeyboard/LayoutSelectionDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading