-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
ಠ_ಠ
committed
Mar 20, 2023
0 parents
commit 58a6e40
Showing
23 changed files
with
987 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Composition", "Composition\Composition.csproj", "{EDFAC570-EDA6-463F-83A3-E2E15D0E31E8}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{EDFAC570-EDA6-463F-83A3-E2E15D0E31E8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{EDFAC570-EDA6-463F-83A3-E2E15D0E31E8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{EDFAC570-EDA6-463F-83A3-E2E15D0E31E8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{EDFAC570-EDA6-463F-83A3-E2E15D0E31E8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation"> | ||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=Composition_002FLocalization/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/ResxEditorPersonal/CheckedGroups/=Composition_002FResources/@EntryIndexedValue">True</s:Boolean> | ||
<s:Boolean x:Key="/Default/ResxEditorPersonal/Initialized/@EntryValue">True</s:Boolean></wpf:ResourceDictionary> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
using System; | ||
using Composition.Model; | ||
using Gtk; | ||
|
||
namespace Composition.Component; | ||
|
||
public class FileButtons: HBox | ||
{ | ||
/// Event to trigger when a file path is chosen for exporting | ||
public event Action<string>? Export; | ||
/// Event to trigger when a file path is chosen for importing | ||
public event Action<string>? Import; | ||
|
||
private readonly Button _exportButton = new(Localization.Export_Button); | ||
private readonly Button _importButton = new(Localization.Import_Fragment_Button); | ||
private readonly Button _importFolderButton = new(Localization.Import_Folder_Button); | ||
|
||
public FileButtons(Window window) | ||
{ | ||
Add(_exportButton); | ||
Add(_importButton); | ||
Add(_importFolderButton); | ||
|
||
const int buttonHeight = 50; | ||
_exportButton.HeightRequest = buttonHeight; | ||
_importButton.HeightRequest = buttonHeight; | ||
_importFolderButton.HeightRequest = buttonHeight; | ||
|
||
_exportButton.Image = new Image(Stock.Save, IconSize.Button); | ||
_importButton.Image = new Image(Stock.File, IconSize.Button); | ||
_importFolderButton.Image = new Image(Stock.Directory, IconSize.Button); | ||
|
||
var exportDialog = new FileChooserDialog(Localization.Dialog_Export, window, FileChooserAction.Save, Localization.Dialog_Cancel, ResponseType.Cancel, Localization.Dialog_Export, ResponseType.Apply); | ||
_exportButton.Clicked += (_, _) => exportDialog.Run(); | ||
exportDialog.Response += (_, response) => | ||
{ | ||
if (response.ResponseId == ResponseType.Apply) | ||
{ | ||
string filePath = exportDialog.Filename; | ||
if (filePath != null) | ||
{ | ||
Export?.Invoke(filePath); | ||
} | ||
} | ||
exportDialog.Hide(); | ||
}; | ||
|
||
var fileFilter = new FileFilter(); | ||
fileFilter.AddPattern("*.compose"); | ||
fileFilter.Name = Localization.File_Filter_Description; | ||
|
||
var importDialog = new FileChooserDialog(Localization.Dialog_Import, window, FileChooserAction.Open, Localization.Dialog_Cancel, ResponseType.Cancel, Localization.Dialog_Import, ResponseType.Apply); | ||
importDialog.AddFilter(fileFilter); | ||
_importButton.Clicked += (_, _) => importDialog.Run(); | ||
importDialog.Response += (_, response) => | ||
{ | ||
if (response.ResponseId == ResponseType.Apply) | ||
{ | ||
string filePath = importDialog.Filename; | ||
if (filePath != null) | ||
{ | ||
Import?.Invoke(filePath); | ||
} | ||
} | ||
importDialog.Hide(); | ||
}; | ||
|
||
var importFolderDialog = new FileChooserDialog(Localization.Dialog_Import, window, FileChooserAction.SelectFolder, Localization.Dialog_Cancel, ResponseType.Cancel, Localization.Dialog_Import, ResponseType.Apply); | ||
_importFolderButton.Clicked += (_, _) => importFolderDialog.Run(); | ||
importFolderDialog.Response += (_, response) => | ||
{ | ||
if (response.ResponseId == ResponseType.Apply) | ||
{ | ||
string filePath = importFolderDialog.Filename; | ||
if (filePath != null) | ||
{ | ||
Import?.Invoke(filePath); | ||
} | ||
} | ||
importFolderDialog.Hide(); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Gtk; | ||
using Key = Gdk.Key; | ||
|
||
namespace Composition.Component; | ||
|
||
public class KeysymView: HBox | ||
{ | ||
private readonly Label _noneLabel = new(); | ||
public string NoneText | ||
{ | ||
get => _noneLabel.Text; | ||
set => _noneLabel.Text = value; | ||
} | ||
|
||
public KeysymView() | ||
{ | ||
|
||
} | ||
|
||
public void Update(IReadOnlyCollection<string> keys) | ||
{ | ||
Foreach(child => Remove(child)); | ||
|
||
string[] keyArray = keys.ToArray(); | ||
if (keyArray.Length > 0) | ||
{ | ||
for (var i = 0; i < keyArray.Length; i++) | ||
{ | ||
Label label = new(keyArray[i]); | ||
label.Visible = true; | ||
label.StyleContext.AddClass("sequence-key"); | ||
|
||
// Separator | ||
if (i != 0) | ||
{ | ||
Label seperator = new(" + "); | ||
seperator.Visible = true; | ||
seperator.StyleContext.AddClass("sequence-seperator"); | ||
Add(seperator); | ||
} | ||
|
||
// Add the label to the box | ||
Add(label); | ||
} | ||
} | ||
else | ||
{ | ||
Label label = new("No keys chosen\nPress a key to add it"); | ||
label.Visible = true; | ||
label.StyleContext.AddClass("sequence-seperator"); | ||
Add(label); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using Composition.Model; | ||
using Gtk; | ||
using Key = Gdk.Key; | ||
|
||
namespace Composition.Component; | ||
|
||
public class SequenceInput: HBox | ||
{ | ||
readonly SequenceBuilder builder; | ||
private readonly Button _clear = new(); | ||
private readonly Button _keys = new(); | ||
private readonly KeysymView _keysymsView = new(); | ||
private readonly Entry _character = new(); | ||
private readonly Button _complete = new(); | ||
|
||
public event Action<Sequence>? CompletedEvent; | ||
|
||
public SequenceInput(SequenceBuilder builder) | ||
{ | ||
this.builder = builder; | ||
|
||
Add(_clear); | ||
Add(_keys); | ||
_keys.Add(_keysymsView); | ||
Add(_character); | ||
Add(_complete); | ||
|
||
// Clear button | ||
_clear.Image = new Image(Stock.Clear, IconSize.Button); | ||
_clear.AlwaysShowImage = true; | ||
_clear.Clicked += (_, _) => builder.ClearKeys(); | ||
// Apply button | ||
_complete.Image = new Image(Stock.Apply, IconSize.Button); | ||
_complete.AlwaysShowImage = true; | ||
_complete.Clicked += (_, _) => BuildSequence(); | ||
// Key input | ||
_keys.KeyPressEvent += (_, e) => e.RetVal = true; // Prevent event propagation to the window | ||
_keys.KeyReleaseEvent += KeyInput; | ||
_keysymsView.NoneText = "No keys chosen\nPress a key to add it"; | ||
// Character output | ||
_character.Alignment = 0.5f; // Center | ||
_character.StyleContext.AddClass(Resources.CSS_sequence_character); | ||
|
||
this.builder.OnChanged += _ => Update(); | ||
Update(); | ||
} | ||
|
||
public void KeyInput(object _, KeyReleaseEventArgs e) | ||
{ | ||
// Completes the sequence when enter is pressed | ||
if (e.Event.Key == Key.Return) | ||
{ | ||
_complete.Click(); | ||
} | ||
// Cancel input | ||
else if (e.Event.Key == Key.Escape) | ||
{ | ||
_clear.Click(); | ||
} | ||
// Appends the key to the sequence | ||
else | ||
{ | ||
builder.AddKey(e.Event.Key); | ||
} | ||
} | ||
|
||
private void BuildSequence() | ||
{ | ||
Sequence sequence = builder.Build()!; | ||
CompletedEvent?.Invoke(sequence); | ||
builder.ClearKeys(); | ||
} | ||
|
||
private void Update() | ||
{ | ||
_keysymsView.Update(builder.Keys); | ||
_character.Text = builder.Character?.ToString() ?? ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Composition.Model; | ||
using Gtk; | ||
|
||
namespace Composition.Component; | ||
|
||
public class SequenceTreeView: TreeView | ||
{ | ||
public SequenceTreeView(): base() | ||
{ | ||
TreeViewColumn keysymsColumn = new(); | ||
keysymsColumn.Title = "Sequence"; | ||
CellRendererText keysymsCell = new(); | ||
keysymsColumn.PackStart(keysymsCell, true); | ||
|
||
TreeViewColumn characterColumn = new(); | ||
characterColumn.Title = "Result"; | ||
CellRendererText characterCell = new(); | ||
characterCell.Style = Pango.Style.Oblique; | ||
characterColumn.PackStart(characterCell, true); | ||
|
||
TreeViewColumn toggleColumn = new(); | ||
toggleColumn.Title = "Enabled"; | ||
CellRendererToggle toggleCell = new(); | ||
toggleColumn.PackStart(toggleCell, true); | ||
|
||
AppendColumn(keysymsColumn); | ||
AppendColumn(characterColumn); | ||
AppendColumn(toggleColumn); | ||
|
||
keysymsColumn.AddAttribute(keysymsCell, "text", 0); | ||
characterColumn.AddAttribute(characterCell, "text", 1); | ||
toggleColumn.AddAttribute(toggleCell, "active", 3); | ||
|
||
toggleCell.Toggled += (widget, path) => | ||
{ | ||
TreeIter iter; | ||
Model.GetIter(out iter, new TreePath(path.Path)); | ||
bool enabled = (bool) Model.GetValue(iter, 3); | ||
Model.SetValue(iter, 3, !enabled); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using Composition.Model; | ||
using Gtk; | ||
|
||
namespace Composition.Component; | ||
|
||
public class SequenceView: HBox | ||
{ | ||
private Sequence _sequence; | ||
public Sequence Sequence | ||
{ | ||
get => _sequence; | ||
set | ||
{ | ||
_sequence = value; | ||
Update(); | ||
} | ||
} | ||
|
||
private readonly KeysymView _keysymView = new() { Visible = true }; | ||
private readonly Label _separator = new() { Visible = true, Text = "→" }; | ||
private readonly Label _character = new() { Visible = true }; | ||
|
||
public SequenceView() | ||
{ | ||
Add(_keysymView); | ||
Add(_separator); | ||
Add(_character); | ||
} | ||
|
||
private void Update() | ||
{ | ||
_keysymView.Update(_sequence.Keys); | ||
_character.Text = _sequence.Character.ToString(); | ||
} | ||
} |
Oops, something went wrong.