Skip to content

Commit 4f4b8a6

Browse files
committed
v1.3 - Updates to "Text File Updater" and "Last Word Display" actions
- `Last Word Display` action now supports splitting long words into multiple lines on the key. - `Text File Updater` action now supports appending data (instead of only overwriting like before). - Updated input textbox in `Text File Updater` to support multiple lines of text
1 parent dbb0fb9 commit 4f4b8a6

File tree

11 files changed

+158
-33
lines changed

11 files changed

+158
-33
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ A set of tools for manipulating text files through the Elgato Stream Deck. Usefu
44

55
**Author's website and contact information:** [https://barraider.com](https://barraider.com)
66

7+
## New in v1.3
8+
- `Last Word Display` action now supports splitting long words into multiple lines on the key.
9+
- `Text File Updater` action now supports appending data (instead of only overwriting like before).
10+
- Updated input textbox in `Text File Updater` to support multiple lines of text
11+
12+
713
## New in v1.2
814
- `Last Word Display` action can now alert if the text equals a preset value. This works great with the `CountDown Timer` if you're saving the timer to a file and want to show it/alert on it from a different profile.
915
- `Last Word Display` now supports modifying the Title settings from the Title properties menu

streamdeck-textfiletools/LastWordDisplayAction.cs

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ public static PluginSettings CreateDefaultSettings()
2525
FileName = String.Empty,
2626
AlertText = String.Empty,
2727
AlertColor = DEFAULT_ALERT_COLOR,
28-
BackgroundFile = String.Empty
28+
BackgroundFile = String.Empty,
29+
SplitLongWord = false
2930
};
3031
return instance;
3132
}
@@ -43,18 +44,24 @@ public static PluginSettings CreateDefaultSettings()
4344

4445
[JsonProperty(PropertyName = "alertColor")]
4546
public string AlertColor { get; set; }
47+
48+
[JsonProperty(PropertyName = "splitLongWord")]
49+
public bool SplitLongWord { get; set; }
50+
4651
}
4752

4853
#region Private Members
4954
private const string DEFAULT_ALERT_COLOR = "#FF0000";
5055
private const int TOTAL_ALERT_STAGES = 4;
5156
private const double POINTS_TO_PIXEL_CONVERT = 1.3;
57+
private const int STRING_SPLIT_SIZE = 7;
5258

5359

5460
private readonly PluginSettings settings;
5561
private readonly InputSimulator iis = new InputSimulator();
5662
private readonly System.Timers.Timer tmrAlert = new System.Timers.Timer();
57-
private TitleParser titleParser = new TitleParser(null);
63+
private SdTools.Wrappers.TitleParameters titleParameters = null;
64+
private string userTitle;
5865
private Color titleColor = Color.White;
5966
private bool isAlerting = false;
6067
private int alertStage = 0;
@@ -70,25 +77,21 @@ public LastWordDisplayAction(SDConnection connection, InitialPayload payload) :
7077
{
7178
this.settings = payload.Settings.ToObject<PluginSettings>();
7279
}
73-
Connection.StreamDeckConnection.OnTitleParametersDidChange += StreamDeckConnection_OnTitleParametersDidChange;
80+
Connection.OnTitleParametersDidChange += Connection_OnTitleParametersDidChange;
7481
tmrAlert.Interval = 200;
7582
tmrAlert.Elapsed += TmrAlert_Elapsed;
7683
}
7784

78-
private void StreamDeckConnection_OnTitleParametersDidChange(object sender, streamdeck_client_csharp.StreamDeckEventReceivedEventArgs<streamdeck_client_csharp.Events.TitleParametersDidChangeEvent> e)
85+
private void Connection_OnTitleParametersDidChange(object sender, SdTools.Wrappers.SDEventReceivedEventArgs<SdTools.Events.TitleParametersDidChange> e)
7986
{
80-
if (Connection.ContextId != e.Event.Context)
81-
{
82-
return;
83-
}
84-
85-
titleParser = new TitleParser(e.Event?.Payload?.TitleParameters);
87+
titleParameters = e.Event?.Payload?.TitleParameters;
88+
userTitle = e.Event?.Payload?.Title;
8689
}
8790

8891
public override void Dispose()
8992
{
9093
Logger.Instance.LogMessage(TracingLevel.INFO, $"Destructor called");
91-
Connection.StreamDeckConnection.OnTitleParametersDidChange -= StreamDeckConnection_OnTitleParametersDidChange;
94+
Connection.OnTitleParametersDidChange -= Connection_OnTitleParametersDidChange;
9295
}
9396

9497
public async override void KeyPressed(KeyPayload payload)
@@ -111,6 +114,11 @@ public override void KeyReleased(KeyPayload payload) { }
111114
public async override void OnTick()
112115
{
113116
string lastWord = ReadLastWordFromFile();
117+
if (settings.SplitLongWord)
118+
{
119+
lastWord = SplitLongWord(lastWord);
120+
}
121+
114122
if (!String.IsNullOrEmpty(settings.AlertText) && !isAlerting && settings.AlertText == lastWord)
115123
{
116124
// Start the alert
@@ -199,7 +207,7 @@ private void TmrAlert_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
199207
// Background
200208
var bgBrush = new SolidBrush(GenerateStageColor(settings.AlertColor, alertStage, TOTAL_ALERT_STAGES));
201209
graphics.FillRectangle(bgBrush, 0, 0, width, height);
202-
Tools.AddTextPathToGraphics(graphics, titleParser, img.Height, img.Width, settings.AlertText);
210+
Tools.AddTextPathToGraphics(graphics, titleParameters, img.Height, img.Width, settings.AlertText);
203211
Connection.SetImageAsync(img);
204212

205213
alertStage = (alertStage + 1) % TOTAL_ALERT_STAGES;
@@ -224,12 +232,26 @@ private async Task DrawImage(string text)
224232
}
225233
}
226234

227-
Tools.AddTextPathToGraphics(graphics, titleParser, img.Height, img.Width, text);
235+
Tools.AddTextPathToGraphics(graphics, titleParameters, img.Height, img.Width, text);
228236
await Connection.SetImageAsync(img);
229237
graphics.Dispose();
230238
}
231239
}
232240

241+
private string SplitLongWord(string word)
242+
{
243+
// Split up to 4 lines
244+
for (int idx = 0; idx < 3; idx++)
245+
{
246+
int cutSize = STRING_SPLIT_SIZE * (idx + 1);
247+
if (word.Length > cutSize)
248+
{
249+
word = $"{word.Substring(0, cutSize)}\n{word.Substring(cutSize)}";
250+
}
251+
}
252+
return word;
253+
}
254+
233255
#endregion
234256
}
235257
}

streamdeck-textfiletools/Properties/AssemblyInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
// General Information about an assembly is controlled through the following
66
// set of attributes. Change these attribute values to modify the information
77
// associated with an assembly.
8-
[assembly: AssemblyTitle("streamdeck-streamcounter")]
8+
[assembly: AssemblyTitle("com.barraider.textfiletools")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
1111
[assembly: AssemblyCompany("")]
12-
[assembly: AssemblyProduct("streamdeck-streamcounter")]
13-
[assembly: AssemblyCopyright("Copyright © 2019")]
12+
[assembly: AssemblyProduct("com.barraider.textfiletools")]
13+
[assembly: AssemblyCopyright("Copyright © 2020")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

streamdeck-textfiletools/PropertyInspector/TextFileUpdater.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,14 @@
22
var payload = {};
33
payload.property_inspector = 'resetCounter';
44
sendPayloadToPlugin(payload);
5-
}
5+
}
6+
7+
function openSaveFilePicker(title, filter, propertyName) {
8+
console.log("openSaveFilePicker called: ", title, filter, propertyName);
9+
var payload = {};
10+
payload.property_inspector = 'loadsavepicker';
11+
payload.picker_title = title;
12+
payload.picker_filter = filter;
13+
payload.property_name = propertyName;
14+
sendPayloadToPlugin(payload);
15+
}

streamdeck-textfiletools/PropertyInspector/TextFileUpdater/LastWordDisplay.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@
2222
<label class="sdpi-file-label" for="fileName">Choose file...</label>
2323
</div>
2424
</div>
25+
<div type="checkbox" class="sdpi-item" id="dvSplitLongWord">
26+
<div class="sdpi-item-label">Split long words</div>
27+
<div class="sdpi-item-value">
28+
<input id="splitLongWord" type="checkbox" value="" class="sdProperty sdCheckbox" oninput="setSettings()">
29+
<label for="splitLongWord" class="sdpi-item-label"><span></span>Split long words to multiple lines</label>
30+
</div>
31+
</div>
2532
<div class="sdpi-item" id="dvFileName">
2633
<div class="sdpi-item-label">Background Image</div>
2734
<div class="sdpi-item-group file" id="filepickergroup">
@@ -41,7 +48,6 @@
4148
<div class="sdpi-item-label">Alert Color</div>
4249
<input type="color" class="sdpi-item-value sdProperty" value="#FF0000" id="alertColor" oninput="setSettings()">
4350
</div>
44-
4551
</div>
4652
</body>
4753
</html>

streamdeck-textfiletools/PropertyInspector/TextFileUpdater/TextFileUpdater.html

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,29 @@
1616
<summary>For feedback/suggestions contact me at <span class="linkspan" onclick="openWebsite()">https://BarRaider.com</span></summary>
1717
</details>
1818
<div class="sdpi-item" id="dvOutputFileName">
19-
<div class="sdpi-item-label">File Name:</div>
20-
<input class="sdpi-item-value sdProperty" placeholder="c:\mycounter.txt" value="" id="outputFileName" oninput="setSettings()">
19+
<div class="sdpi-item-label">File Name</div>
20+
<input class="sdpi-item-value sdProperty hasFileButton" disabled value="" id="outputFileName">
21+
<button class="max100 minmargin" onclick="openSaveFilePicker('Counter File Name', 'Text files (*.txt)|*.txt|All files (*.*)|*.*', 'outputFileName');">...</button>
2122
</div>
22-
<div class="sdpi-item" id="dvTitlePrefix">
23+
<!---
24+
<div class="sdpi-item" id="dvTitlePrefix">
25+
<div class="sdpi-item-label">Input Text</div>
26+
<input class="sdpi-item-value sdProperty" placeholder="" value="" id="inputString" oninput="setSettings()">
27+
</div>
28+
-->
29+
<div type="textarea" class="sdpi-item" id="dvTitlePrefix">
2330
<div class="sdpi-item-label">Input Text</div>
24-
<input class="sdpi-item-value sdProperty" placeholder="" value="" id="inputString" oninput="setSettings()">
31+
<span class="sdpi-item-value textarea doubleLineTextArea">
32+
<textarea type="textarea" id="inputString" oninput="setSettings()" class="sdProperty doubleLineTextArea" rows="1"></textarea>
33+
</span>
34+
</div>
35+
36+
<div type="checkbox" class="sdpi-item" id="dvAppend">
37+
<div class="sdpi-item-label">Append</div>
38+
<div class="sdpi-item-value">
39+
<input id="appendToFile" type="checkbox" value="" class="sdProperty sdCheckbox" oninput="setSettings()">
40+
<label for="appendToFile" class="sdpi-item-label"><span></span>Append instead of overwriting file</label>
41+
</div>
2542
</div>
2643
</div>
2744
</body>

streamdeck-textfiletools/PropertyInspector/sdpi.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1471,3 +1471,9 @@ input[type=range].vHorizon {
14711471
margin: 4px 0px;
14721472
}
14731473
*/
1474+
1475+
.doubleLineTextArea
1476+
{
1477+
height: 30px;
1478+
overflow:hidden;
1479+
}

streamdeck-textfiletools/PropertyInspector/sdtools.common.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// sdtools.common.js v1.0
1+
// sdtools.common.js v1.1
22
var websocket = null,
33
uuid = null,
44
registerEventName = null,
@@ -87,6 +87,9 @@ function loadConfiguration(payload) {
8787
}
8888
elem.value = payload[valueField];
8989
}
90+
else if (elem.classList.contains("sdHTML")) { // HTML element
91+
elem.innerHTML = payload[key];
92+
}
9093
else { // Normal value
9194
elem.value = payload[key];
9295
}
@@ -123,6 +126,10 @@ function setSettings() {
123126
var valueField = elem.getAttribute("sdValueField");
124127
payload[valueField] = elem.value;
125128
}
129+
else if (elem.classList.contains("sdHTML")) { // HTML element
130+
var valueField = elem.getAttribute("sdValueField");
131+
payload[valueField] = elem.innerHTML;
132+
}
126133
else { // Normal value
127134
payload[key] = elem.value;
128135
}
@@ -177,7 +184,7 @@ function openWebsite() {
177184
const json = {
178185
'event': 'openUrl',
179186
'payload': {
180-
'url': 'https://BarRaider.com'
187+
'url': 'https://BarRaider.github.io'
181188
}
182189
};
183190
websocket.send(JSON.stringify(json));

streamdeck-textfiletools/TextFileTools.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@
4444
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
4545
<HintPath>..\..\..\DotNet\StreamDeck\packages\NLog.4.6.8\lib\net45\NLog.dll</HintPath>
4646
</Reference>
47+
<Reference Include="PickersUtil">
48+
<HintPath>..\..\PickersUtil\PickersUtil\bin\Release\PickersUtil.dll</HintPath>
49+
</Reference>
4750
<Reference Include="streamdeck-client-csharp, Version=4.1.1.0, Culture=neutral, processorArchitecture=MSIL">
4851
<HintPath>..\packages\streamdeck-client-csharp.4.1.1\lib\netstandard2.0\streamdeck-client-csharp.dll</HintPath>
4952
</Reference>

streamdeck-textfiletools/TextFileUpdaterAction.cs

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,24 @@
1010

1111
namespace BarRaider.TextFileUpdater
1212
{
13+
14+
//---------------------------------------------------
15+
// BarRaider's Hall Of Fame
16+
// CSSGuru : tobitege
17+
//---------------------------------------------------
1318
[PluginActionId("com.barraider.textfiletools.textfileupdater")]
1419
public class TextFileUpdaterAction : PluginBase
1520
{
1621
private class PluginSettings
1722
{
1823
public static PluginSettings CreateDefaultSettings()
1924
{
20-
PluginSettings instance = new PluginSettings();
21-
instance.OutputFileName = String.Empty;
22-
instance.InputString = String.Empty;
25+
PluginSettings instance = new PluginSettings
26+
{
27+
OutputFileName = String.Empty,
28+
InputString = String.Empty,
29+
AppendToFile = false
30+
};
2331
return instance;
2432
}
2533

@@ -29,11 +37,14 @@ public static PluginSettings CreateDefaultSettings()
2937

3038
[JsonProperty(PropertyName = "inputString")]
3139
public string InputString { get; set; }
40+
41+
[JsonProperty(PropertyName = "appendToFile")]
42+
public bool AppendToFile { get; set; }
3243
}
3344

3445
#region Private Members
3546

36-
private PluginSettings settings;
47+
private readonly PluginSettings settings;
3748

3849
#endregion
3950
public TextFileUpdaterAction(SDConnection connection, InitialPayload payload) : base(connection, payload)
@@ -46,11 +57,15 @@ public TextFileUpdaterAction(SDConnection connection, InitialPayload payload) :
4657
{
4758
this.settings = payload.Settings.ToObject<PluginSettings>();
4859
}
60+
61+
Connection.OnSendToPlugin += Connection_OnSendToPlugin;
62+
4963
}
5064

5165
public override void Dispose()
5266
{
5367
Logger.Instance.LogMessage(TracingLevel.INFO, $"Destructor called");
68+
Connection.OnSendToPlugin -= Connection_OnSendToPlugin;
5469
}
5570

5671
public override void KeyPressed(KeyPayload payload)
@@ -81,8 +96,15 @@ private void SaveInputStringToFile()
8196
Logger.Instance.LogMessage(TracingLevel.INFO, $"Saving value: {settings.InputString} to file: {settings.OutputFileName}");
8297
if (!String.IsNullOrWhiteSpace(settings.OutputFileName))
8398
{
84-
85-
File.WriteAllText(settings.OutputFileName, settings.InputString);
99+
string output = settings.InputString.Replace(@"\n", "\n");
100+
if (settings.AppendToFile)
101+
{
102+
File.AppendAllText(settings.OutputFileName, output);
103+
}
104+
else
105+
{
106+
File.WriteAllText(settings.OutputFileName, output);
107+
}
86108
Connection.ShowOk();
87109
}
88110
}
@@ -100,6 +122,32 @@ private Task SaveSettings()
100122
return Connection.SetSettingsAsync(JObject.FromObject(settings));
101123
}
102124

103-
#endregion
125+
private void Connection_OnSendToPlugin(object sender, SdTools.Wrappers.SDEventReceivedEventArgs<SdTools.Events.SendToPlugin> e)
126+
{
127+
var payload = e.Event.Payload;
128+
if (payload["property_inspector"] != null)
129+
{
130+
switch (payload["property_inspector"].ToString().ToLower())
131+
{
132+
case "loadsavepicker":
133+
string propertyName = (string)payload["property_name"];
134+
string pickerTitle = (string)payload["picker_title"];
135+
string pickerFilter = (string)payload["picker_filter"];
136+
string fileName = PickersUtil.Pickers.SaveFilePicker(pickerTitle, null, pickerFilter);
137+
if (!string.IsNullOrEmpty(fileName))
138+
{
139+
if (!PickersUtil.Pickers.SetJsonPropertyValue(settings, propertyName, fileName))
140+
{
141+
Logger.Instance.LogMessage(TracingLevel.ERROR, "Failed to save picker value to settings");
142+
}
143+
SaveSettings();
144+
}
145+
break;
146+
}
147+
}
148+
}
149+
150+
151+
#endregion
104152
}
105153
}

0 commit comments

Comments
 (0)