From 78bc8f5acd11ed6d69e773570b18fe8423056532 Mon Sep 17 00:00:00 2001 From: Rick van Dam Date: Mon, 13 Jul 2020 19:45:16 +0200 Subject: [PATCH 1/4] updated logviewsettings --- .../EditorModules/LogView/LogViewPlugin.cs | 26 +++----- .../EditorModules/LogView/LogViewSettings.cs | 61 +++++++++++++++++++ .../EditorModules/LogView/Modules/LogView.cs | 45 ++++++-------- 3 files changed, 86 insertions(+), 46 deletions(-) create mode 100644 Source/Plugins/EditorModules/LogView/LogViewSettings.cs diff --git a/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs b/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs index f674cfe8d..b2348e397 100644 --- a/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs +++ b/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs @@ -1,12 +1,6 @@ using System; -using System.Collections.Generic; -using System.Linq; using System.Windows.Forms; -using System.IO; -using System.Xml.Linq; -using Duality; -using Duality.Editor; using Duality.Editor.Forms; using Duality.Editor.Properties; using Duality.Editor.Plugins.LogView.Properties; @@ -41,28 +35,22 @@ protected override IDockContent DeserializeDockContent(Type dockContentType) this.isLoading = false; return result; } - protected override void SaveUserData(XElement node) + protected override void SaveUserData(PluginSettings pluginSettings) { if (this.logView != null) { - XElement logViewElem = new XElement("LogView"); - this.logView.SaveUserData(logViewElem); - if (!logViewElem.IsEmpty) - node.Add(logViewElem); + var logViewSettings = pluginSettings.GetSettings(); + this.logView.SaveUserData(logViewSettings); } } - protected override void LoadUserData(XElement node) + + protected override void LoadUserData(PluginSettings pluginSettings) { this.isLoading = true; if (this.logView != null) { - foreach (XElement logViewElem in node.Elements("LogView")) - { - int i = logViewElem.GetAttributeValue("id", 0); - if (i < 0 || i >= 1) continue; - - this.logView.LoadUserData(logViewElem); - } + var logViewSettings = pluginSettings.GetSettings(); + this.logView.LoadUserData(logViewSettings); } this.isLoading = false; } diff --git a/Source/Plugins/EditorModules/LogView/LogViewSettings.cs b/Source/Plugins/EditorModules/LogView/LogViewSettings.cs new file mode 100644 index 000000000..9899e1ed0 --- /dev/null +++ b/Source/Plugins/EditorModules/LogView/LogViewSettings.cs @@ -0,0 +1,61 @@ +namespace Duality.Editor.Plugins.LogView +{ + public class LogViewSettings + { + private bool showMessages = true; + public bool ShowMessages + { + get { return this.showMessages; } + set { this.showMessages = value; } + } + + private bool showWarnings = true; + public bool ShowWarnings + { + get { return this.showWarnings; } + set { this.showWarnings = value; } + } + + private bool showErrors = true; + public bool ShowErrors + { + get { return this.showErrors; } + set { this.showErrors = value; } + } + + private bool showCore = true; + public bool ShowCore + { + get { return this.showCore; } + set { this.showCore = value; } + } + + private bool showEditor = true; + public bool ShowEditor + { + get { return this.showEditor; } + set { this.showEditor = value; } + } + + private bool showGame = true; + public bool ShowGame + { + get { return this.showGame; } + set { this.showGame = value; } + } + + private bool autoClear = true; + public bool AutoClear + { + get { return this.autoClear; } + set { this.autoClear = value; } + } + + private bool pauseOnError = true; + public bool PauseOnError + { + get { return this.pauseOnError; } + set { this.pauseOnError = value; } + } + } +} diff --git a/Source/Plugins/EditorModules/LogView/Modules/LogView.cs b/Source/Plugins/EditorModules/LogView/Modules/LogView.cs index 77e1748e9..d68c48cf8 100644 --- a/Source/Plugins/EditorModules/LogView/Modules/LogView.cs +++ b/Source/Plugins/EditorModules/LogView/Modules/LogView.cs @@ -1,17 +1,10 @@ using System; using System.Drawing; using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using System.Text; -using System.Xml.Linq; using System.Windows.Forms; using WeifenLuo.WinFormsUI.Docking; -using Duality; -using Duality.Editor; - namespace Duality.Editor.Plugins.LogView { public partial class LogView : DockContent @@ -90,29 +83,27 @@ private void DockPanel_ActiveContentChanged(object sender, EventArgs e) } } - internal void SaveUserData(XElement node) + internal void SaveUserData(LogViewSettings logViewSettings) { - node.SetElementValue("ShowMessages", this.buttonMessages.Checked); - node.SetElementValue("ShowWarnings", this.buttonWarnings.Checked); - node.SetElementValue("ShowErrors", this.buttonErrors.Checked); - node.SetElementValue("ShowCore", this.buttonCore.Checked); - node.SetElementValue("ShowEditor", this.buttonEditor.Checked); - node.SetElementValue("ShowGame", this.buttonGame.Checked); - node.SetElementValue("AutoClear", this.checkAutoClear.Checked); - node.SetElementValue("PauseOnError", this.buttonPauseOnError.Checked); + logViewSettings.ShowMessages = this.buttonMessages.Checked; + logViewSettings.ShowWarnings = this.buttonWarnings.Checked; + logViewSettings.ShowErrors = this.buttonErrors.Checked; + logViewSettings.ShowCore = this.buttonCore.Checked; + logViewSettings.ShowEditor = this.buttonEditor.Checked; + logViewSettings.ShowGame = this.buttonGame.Checked; + logViewSettings.AutoClear = this.checkAutoClear.Checked; + logViewSettings.PauseOnError = this.buttonPauseOnError.Checked; } - internal void LoadUserData(XElement node) + internal void LoadUserData(LogViewSettings logViewSettings) { - bool tryParseBool; - - if (node.GetElementValue("ShowMessages", out tryParseBool)) this.buttonMessages.Checked = tryParseBool; - if (node.GetElementValue("ShowWarnings", out tryParseBool)) this.buttonWarnings.Checked = tryParseBool; - if (node.GetElementValue("ShowErrors", out tryParseBool)) this.buttonErrors.Checked = tryParseBool; - if (node.GetElementValue("ShowCore", out tryParseBool)) this.buttonCore.Checked = tryParseBool; - if (node.GetElementValue("ShowEditor", out tryParseBool)) this.buttonEditor.Checked = tryParseBool; - if (node.GetElementValue("ShowGame", out tryParseBool)) this.buttonGame.Checked = tryParseBool; - if (node.GetElementValue("AutoClear", out tryParseBool)) this.checkAutoClear.Checked = tryParseBool; - if (node.GetElementValue("PauseOnError", out tryParseBool)) this.buttonPauseOnError.Checked = tryParseBool; + this.buttonMessages.Checked = logViewSettings.ShowMessages; + this.buttonWarnings.Checked = logViewSettings.ShowWarnings; + this.buttonErrors.Checked = logViewSettings.ShowErrors; + this.buttonCore.Checked = logViewSettings.ShowCore; + this.buttonEditor.Checked = logViewSettings.ShowEditor; + this.buttonGame.Checked = logViewSettings.ShowGame; + this.checkAutoClear.Checked = logViewSettings.AutoClear; + this.buttonPauseOnError.Checked = logViewSettings.PauseOnError; this.logEntryList.SetSourceFilter(Logs.Core.Id, !this.buttonCore.Checked); this.logEntryList.SetSourceFilter(Logs.Editor.Id, !this.buttonEditor.Checked); From 986d71a86b4de4e328577a75b1622af9c265969a Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Jul 2020 12:35:46 +0200 Subject: [PATCH 2/4] Reordered LogViewSettings members to match style guide --- .../EditorModules/LogView/LogViewSettings.cs | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/Source/Plugins/EditorModules/LogView/LogViewSettings.cs b/Source/Plugins/EditorModules/LogView/LogViewSettings.cs index 9899e1ed0..49224a3a6 100644 --- a/Source/Plugins/EditorModules/LogView/LogViewSettings.cs +++ b/Source/Plugins/EditorModules/LogView/LogViewSettings.cs @@ -3,55 +3,49 @@ public class LogViewSettings { private bool showMessages = true; + private bool showWarnings = true; + private bool showErrors = true; + private bool showCore = true; + private bool showEditor = true; + private bool showGame = true; + private bool autoClear = true; + private bool pauseOnError = true; + public bool ShowMessages { get { return this.showMessages; } set { this.showMessages = value; } } - - private bool showWarnings = true; public bool ShowWarnings { get { return this.showWarnings; } set { this.showWarnings = value; } } - - private bool showErrors = true; public bool ShowErrors { get { return this.showErrors; } set { this.showErrors = value; } } - - private bool showCore = true; public bool ShowCore { get { return this.showCore; } set { this.showCore = value; } } - - private bool showEditor = true; public bool ShowEditor { get { return this.showEditor; } set { this.showEditor = value; } } - - private bool showGame = true; public bool ShowGame { get { return this.showGame; } set { this.showGame = value; } } - - private bool autoClear = true; public bool AutoClear { get { return this.autoClear; } set { this.autoClear = value; } } - - private bool pauseOnError = true; public bool PauseOnError { get { return this.pauseOnError; } From d54726def7d9d16400270daf8e14e44d4bfb01b6 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 22 Jul 2020 12:43:21 +0200 Subject: [PATCH 3/4] Rewired LogView to use LogViewSettings object directly, first draft --- .../DualityEditor/Utility/PluginSettings.cs | 10 ++ .../EditorModules/LogView/LogViewPlugin.cs | 16 ++-- .../LogView/Modules/LogView.Designer.cs | 1 + .../EditorModules/LogView/Modules/LogView.cs | 95 ++++++++++++------- 4 files changed, 77 insertions(+), 45 deletions(-) diff --git a/Source/Editor/DualityEditor/Utility/PluginSettings.cs b/Source/Editor/DualityEditor/Utility/PluginSettings.cs index d99b0bf70..b246ea2ef 100644 --- a/Source/Editor/DualityEditor/Utility/PluginSettings.cs +++ b/Source/Editor/DualityEditor/Utility/PluginSettings.cs @@ -43,6 +43,16 @@ public XElement OldStyleSettings return setting; } /// + /// Adds or replaces the stored editor plugin settings instance of type . + /// + /// + /// + public void Set(T settings) where T : class + { + this.data.RemoveAll(obj => obj is T); + this.data.Add(settings); + } + /// /// Clears all editor plugin settings from this container, and resets it to an empty state. /// internal void Clear() diff --git a/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs b/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs index b2348e397..a779f366a 100644 --- a/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs +++ b/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs @@ -35,24 +35,22 @@ protected override IDockContent DeserializeDockContent(Type dockContentType) this.isLoading = false; return result; } - protected override void SaveUserData(PluginSettings pluginSettings) + protected override void LoadUserData(PluginSettings pluginSettings) { + this.isLoading = true; if (this.logView != null) { - var logViewSettings = pluginSettings.GetSettings(); - this.logView.SaveUserData(logViewSettings); + this.logView.UserSettings = pluginSettings.Get(); } + this.isLoading = false; } - - protected override void LoadUserData(PluginSettings pluginSettings) + protected override void SaveUserData(PluginSettings settings) { - this.isLoading = true; + base.SaveUserData(settings); if (this.logView != null) { - var logViewSettings = pluginSettings.GetSettings(); - this.logView.LoadUserData(logViewSettings); + settings.Set(this.logView.UserSettings); } - this.isLoading = false; } protected override void InitPlugin(MainForm main) { diff --git a/Source/Plugins/EditorModules/LogView/Modules/LogView.Designer.cs b/Source/Plugins/EditorModules/LogView/Modules/LogView.Designer.cs index bc8634433..6ef4363f2 100644 --- a/Source/Plugins/EditorModules/LogView/Modules/LogView.Designer.cs +++ b/Source/Plugins/EditorModules/LogView/Modules/LogView.Designer.cs @@ -189,6 +189,7 @@ private void InitializeComponent() this.checkAutoClear.Name = "checkAutoClear"; this.checkAutoClear.Size = new System.Drawing.Size(143, 22); this.checkAutoClear.Text = "Clear on Play"; + this.checkAutoClear.CheckedChanged += new System.EventHandler(this.checkAutoClear_CheckedChanged); // // buttonPauseOnError // diff --git a/Source/Plugins/EditorModules/LogView/Modules/LogView.cs b/Source/Plugins/EditorModules/LogView/Modules/LogView.cs index d68c48cf8..3d86e635d 100644 --- a/Source/Plugins/EditorModules/LogView/Modules/LogView.cs +++ b/Source/Plugins/EditorModules/LogView/Modules/LogView.cs @@ -9,11 +9,26 @@ namespace Duality.Editor.Plugins.LogView { public partial class LogView : DockContent { + private LogViewSettings userSettings = new LogViewSettings(); private int unseenWarnings = 0; - private int unseenErrors = 0; + private int unseenErrors = 0; private Dictionary sourceFilterButtons = new Dictionary(); + public LogViewSettings UserSettings + { + get { return this.userSettings; } + set + { + if (this.userSettings != value) + { + this.userSettings = value; + this.ApplyUserSettings(); + } + } + } + + public LogView() { this.InitializeComponent(); @@ -29,6 +44,29 @@ public LogView() this.toolStrip.Renderer = new Duality.Editor.Controls.ToolStrip.DualitorToolStripProfessionalRenderer(); } + + public void ApplyUserSettings() + { + this.buttonMessages.Checked = this.userSettings.ShowMessages; + this.buttonWarnings.Checked = this.userSettings.ShowWarnings; + this.buttonErrors.Checked = this.userSettings.ShowErrors; + + this.buttonCore.Checked = this.userSettings.ShowCore; + this.buttonEditor.Checked = this.userSettings.ShowEditor; + this.buttonGame.Checked = this.userSettings.ShowGame; + + this.checkAutoClear.Checked = this.userSettings.AutoClear; + this.buttonPauseOnError.Checked = this.userSettings.PauseOnError; + + this.logEntryList.SetSourceFilter(Logs.Core.Id, !this.userSettings.ShowCore); + this.logEntryList.SetSourceFilter(Logs.Editor.Id, !this.userSettings.ShowEditor); + this.logEntryList.SetSourceFilter(Logs.Game.Id, !this.userSettings.ShowGame); + + this.logEntryList.SetTypeFilter(LogMessageType.Message, !this.userSettings.ShowMessages); + this.logEntryList.SetTypeFilter(LogMessageType.Warning, !this.userSettings.ShowWarnings); + this.logEntryList.SetTypeFilter(LogMessageType.Error, !this.userSettings.ShowErrors); + } + protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); @@ -83,36 +121,6 @@ private void DockPanel_ActiveContentChanged(object sender, EventArgs e) } } - internal void SaveUserData(LogViewSettings logViewSettings) - { - logViewSettings.ShowMessages = this.buttonMessages.Checked; - logViewSettings.ShowWarnings = this.buttonWarnings.Checked; - logViewSettings.ShowErrors = this.buttonErrors.Checked; - logViewSettings.ShowCore = this.buttonCore.Checked; - logViewSettings.ShowEditor = this.buttonEditor.Checked; - logViewSettings.ShowGame = this.buttonGame.Checked; - logViewSettings.AutoClear = this.checkAutoClear.Checked; - logViewSettings.PauseOnError = this.buttonPauseOnError.Checked; - } - internal void LoadUserData(LogViewSettings logViewSettings) - { - this.buttonMessages.Checked = logViewSettings.ShowMessages; - this.buttonWarnings.Checked = logViewSettings.ShowWarnings; - this.buttonErrors.Checked = logViewSettings.ShowErrors; - this.buttonCore.Checked = logViewSettings.ShowCore; - this.buttonEditor.Checked = logViewSettings.ShowEditor; - this.buttonGame.Checked = logViewSettings.ShowGame; - this.checkAutoClear.Checked = logViewSettings.AutoClear; - this.buttonPauseOnError.Checked = logViewSettings.PauseOnError; - - this.logEntryList.SetSourceFilter(Logs.Core.Id, !this.buttonCore.Checked); - this.logEntryList.SetSourceFilter(Logs.Editor.Id, !this.buttonEditor.Checked); - this.logEntryList.SetSourceFilter(Logs.Game.Id, !this.buttonGame.Checked); - this.logEntryList.SetTypeFilter(LogMessageType.Message, !this.buttonMessages.Checked); - this.logEntryList.SetTypeFilter(LogMessageType.Warning, !this.buttonWarnings.Checked); - this.logEntryList.SetTypeFilter(LogMessageType.Error, !this.buttonErrors.Checked); - } - private void MarkAsRead() { this.unseenErrors = 0; @@ -215,20 +223,35 @@ private void sourceFilterButton_CheckedChanged(object sender, EventArgs e) ToolStripButton button = sender as ToolStripButton; string sourceId = button.Tag as string; this.logEntryList.SetSourceFilter(sourceId, !button.Checked); + + // No support for saving custom log source filter states as user settings right now, could be added later + if (button == this.buttonCore) this.userSettings.ShowCore = button.Checked; + else if (button == this.buttonEditor) this.userSettings.ShowEditor = button.Checked; + else if(button == this.buttonGame) this.userSettings.ShowGame = button.Checked; } private void buttonMessages_CheckedChanged(object sender, EventArgs e) { - this.logEntryList.SetTypeFilter(LogMessageType.Message, !this.buttonMessages.Checked); + this.userSettings.ShowMessages = this.buttonMessages.Checked; + this.logEntryList.SetTypeFilter(LogMessageType.Message, !this.userSettings.ShowMessages); } private void buttonWarnings_CheckedChanged(object sender, EventArgs e) { - this.logEntryList.SetTypeFilter(LogMessageType.Warning, !this.buttonWarnings.Checked); + this.userSettings.ShowWarnings = this.buttonWarnings.Checked; + this.logEntryList.SetTypeFilter(LogMessageType.Warning, !this.userSettings.ShowWarnings); } private void buttonErrors_CheckedChanged(object sender, EventArgs e) { - this.logEntryList.SetTypeFilter(LogMessageType.Error, !this.buttonErrors.Checked); + this.userSettings.ShowErrors = this.buttonErrors.Checked; + this.logEntryList.SetTypeFilter(LogMessageType.Error, !this.userSettings.ShowErrors); + } + private void buttonPauseOnError_CheckedChanged(object sender, EventArgs e) + { + this.userSettings.PauseOnError = this.buttonPauseOnError.Checked; + } + private void checkAutoClear_CheckedChanged(object sender, EventArgs e) + { + this.userSettings.AutoClear = this.checkAutoClear.Checked; } - private void buttonPauseOnError_CheckedChanged(object sender, EventArgs e) {} private void actionClear_ButtonClick(object sender, EventArgs e) { this.logEntryList.Clear(); @@ -300,7 +323,7 @@ private void logEntryList_LogEntriesAdded(object sender, LogEntryList.ViewEntryE private void Sandbox_Entering(object sender, EventArgs e) { - if (this.checkAutoClear.Checked) this.actionClear_ButtonClick(sender, e); + if (this.userSettings.AutoClear) this.actionClear_ButtonClick(sender, e); } private void textBoxEntry_KeyDown(object sender, KeyEventArgs e) { From ba2f86696a6dd28d92fb2d7b9061d1938091e96c Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 24 Jul 2020 21:00:27 +0200 Subject: [PATCH 4/4] Fixed potential bug where LogView UI wouldn't update on user settings Apply event --- .../Plugins/EditorModules/LogView/LogViewPlugin.cs | 1 + .../EditorModules/LogView/Modules/LogView.cs | 13 +++---------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs b/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs index a779f366a..93f48ba0b 100644 --- a/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs +++ b/Source/Plugins/EditorModules/LogView/LogViewPlugin.cs @@ -41,6 +41,7 @@ protected override void LoadUserData(PluginSettings pluginSettings) if (this.logView != null) { this.logView.UserSettings = pluginSettings.Get(); + this.logView.ApplyUserSettings(); } this.isLoading = false; } diff --git a/Source/Plugins/EditorModules/LogView/Modules/LogView.cs b/Source/Plugins/EditorModules/LogView/Modules/LogView.cs index 3d86e635d..3f9638d77 100644 --- a/Source/Plugins/EditorModules/LogView/Modules/LogView.cs +++ b/Source/Plugins/EditorModules/LogView/Modules/LogView.cs @@ -18,14 +18,7 @@ public partial class LogView : DockContent public LogViewSettings UserSettings { get { return this.userSettings; } - set - { - if (this.userSettings != value) - { - this.userSettings = value; - this.ApplyUserSettings(); - } - } + set { this.userSettings = value ?? new LogViewSettings(); } } @@ -83,7 +76,7 @@ protected override void OnShown(EventArgs e) { base.OnShown(e); - this.DockPanel.ActiveContentChanged += DockPanel_ActiveContentChanged; + this.DockPanel.ActiveContentChanged += this.DockPanel_ActiveContentChanged; Sandbox.Entering += this.Sandbox_Entering; } protected override void OnClosed(EventArgs e) @@ -92,7 +85,7 @@ protected override void OnClosed(EventArgs e) this.logEntryList.BindTo(null); - this.DockPanel.ActiveContentChanged -= DockPanel_ActiveContentChanged; + this.DockPanel.ActiveContentChanged -= this.DockPanel_ActiveContentChanged; Sandbox.Entering -= this.Sandbox_Entering; } protected override void OnGotFocus(EventArgs e)