Skip to content

Commit

Permalink
Fixed variables not saving; Improved ui (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmayer-dev authored Jun 11, 2022
1 parent 0f4a5d0 commit 2682dd6
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 152 deletions.
31 changes: 16 additions & 15 deletions GUI/CustomControls/Variables/VariableItem.Designer.cs

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

23 changes: 12 additions & 11 deletions GUI/CustomControls/Variables/VariableItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,17 @@ public VariableItem(Variables.Variable variable)
{
this.Variable = variable;
InitializeComponent();
this.SuspendLayout();
this.lblName.Text = Language.LanguageManager.Strings.Name;
this.lblType.Text = Language.LanguageManager.Strings.Type;
this.lblValue.Text = Language.LanguageManager.Strings.Value;
this.lblCreator.Text = Language.LanguageManager.Strings.Creator;
this.Update();
this.ResumeLayout();
}

public new void Update()
{
this.lblName.Text = this.Variable.Name;
this.lblType.Text = this.Variable.Type.ToString();
this.lblValue.Text = this.Variable.Value;
this.lblCreator.Text = this.Variable.Creator;
this.Invoke(new Action(() =>
{
this.lblName.Text = this.Variable.Name;
this.lblType.Text = this.Variable.Type.ToString();
this.lblValue.Text = this.Variable.Value;
this.lblCreator.Text = this.Variable.Creator;
}));
}

private void BtnEdit_Click(object sender, EventArgs e)
Expand All @@ -42,5 +38,10 @@ private void BtnEdit_Click(object sender, EventArgs e)
variableDialog.ShowDialog();
}
}

private void VariableItem_Load(object sender, EventArgs e)
{
this.Update();
}
}
}
4 changes: 2 additions & 2 deletions GUI/Dialogs/VariableDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void BtnOk_Click(object sender, EventArgs e)
int variableCount = VariableManager.Variables.FindAll(v => v.Name.Equals(this.variableName.Text)).Count;
if (variableCount > 0)
{
variableName.Text = String.Format(variableName.Text + " ({0})", variableCount);
variableName.Text = String.Format(variableName.Text + " _{0}", variableCount);
}
this.Variable.Name = VariableManager.ConvertNameString(this.variableName.Text);
}
Expand All @@ -91,7 +91,7 @@ private void BtnOk_Click(object sender, EventArgs e)
break;
}

VariableManager.RefreshVariable(this.Variable);
VariableManager.SetValue(this.Variable.Name, this.Variable.Value, this.Variable.VariableType, this.Variable.Creator);

this.DialogResult = DialogResult.OK;
this.Close();
Expand Down
30 changes: 15 additions & 15 deletions GUI/MainWindowViews/VariablesView.Designer.cs

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

84 changes: 34 additions & 50 deletions GUI/MainWindowViews/VariablesView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
Expand Down Expand Up @@ -37,27 +38,26 @@ public void UpdateTranslation()

private void LoadCreators()
{
foreach (CheckBox checkBox in this.creatorFilter.Controls)
{
checkBox.CheckedChanged -= CreatorCheckBox_CheckedChanged;
}
this.creatorFilter.Controls.Clear();
List<string> variableCreators = new List<string>();
foreach (Variable variable in VariableManager.Variables)
{
if (!variableCreators.Contains(variable.Creator)) {
variableCreators.Add(variable.Creator);
}
}

foreach (string creator in variableCreators)
{
if (this.creatorFilter.Controls.OfType<CheckBox>().Where(x => x.Name.Equals(creator)).Count() > 0)
continue;

CheckBox creatorCheckBox = new CheckBox
{
Checked = true,
Text = creator,
Name = creator,
AutoSize = true,
Padding = new Padding(10, 0, 10, 0),
AutoSize = false,
Size = new Size(200, 20),
};
this.creatorFilter.Controls.Add(creatorCheckBox);
creatorCheckBox.CheckedChanged += CreatorCheckBox_CheckedChanged;
Expand Down Expand Up @@ -86,57 +86,41 @@ private void VariablesPage_Load(object sender, EventArgs e)
VariableManager.OnVariableRemoved += this.VariableRemoved;
}

private void VariableRemoved(object sender, EventArgs e) {
Task.Run(() =>
private void VariableRemoved(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
this.Invoke(new Action(() => this.SuspendLayout()));
foreach (VariableItem variableItem in this.variablesPanel.Controls)
{
if (sender.Equals(variableItem.Variable.Name))
{
this.Invoke(new Action(() =>
{
this.variablesPanel.Controls.Remove(variableItem);
}));
return;
}
}

this.Invoke(new Action(() => this.ResumeLayout()));
});
this.Invoke(new Action(() => VariableRemoved(sender, e)));
return;
}
string variableName = sender as string;
var variableItemView = this.variablesPanel.Controls.OfType<VariableItem>().Where(x => x.Variable.Name.Equals(variableName)).FirstOrDefault();
if (variableItemView != null)
{
this.variablesPanel.Controls.Remove(variableItemView);
}
}

private void VariableChanged(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
this.Invoke(new Action(() => VariableChanged(sender, e)));
return;
}
Variable variable = sender as Variable;
Task.Run(() =>
if (this.IsDisposed) return;
var variableItemView = this.variablesPanel.Controls.OfType<VariableItem>().Where(x => x.Variable.Name.Equals(variable.Name)).FirstOrDefault();
if (variableItemView == null)
{
if (this.IsDisposed) return;
this.Invoke(new Action(() => this.SuspendLayout()));
foreach (VariableItem variableItem in this.variablesPanel.Controls)
{
if (variable.Name.Equals(variableItem.Variable.Name))
{
this.Invoke(new Action(() =>
{
try
{
if (this == null || this.Disposing || this.IsDisposed) return;
variableItem.Variable = variable;
variableItem.Update();
} catch { }
}));
return;
}
}
VariableItem newVariableItem = new VariableItem(variable);
this.Invoke(new Action(() =>
{
this.variablesPanel.Controls.Add(newVariableItem);
this.ResumeLayout();
}));

});
this.variablesPanel.Controls.Add(newVariableItem);
this.LoadCreators();
} else
{
variableItemView.Variable = variable;
variableItemView.Update();
}
}

private void LoadVariables()
Expand Down
4 changes: 2 additions & 2 deletions MacroDeck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ private static void Start(bool show = false, int port = -1)
{
Language.LanguageManager.SetLanguage(_configuration.Language);
_ = new HotkeyManager();
VariableManager.Load();
VariableManager.Initialize();
PluginManager.Load();
PluginManager.OnUpdateCheckFinished += OnPackageManagerUpdateCheckFinished;
PluginManager.EnablePlugins();
Expand Down Expand Up @@ -622,7 +622,7 @@ private static void MainWindowLoadEvent(object sender, EventArgs e)

private static void OnApplicationExit(object sender, EventArgs e)
{
VariableManager.Save();
//VariableManager.Save();
MacroDeckLogger.Info("Exiting Macro Deck...");
}

Expand Down
Loading

0 comments on commit 2682dd6

Please sign in to comment.