Skip to content

Commit

Permalink
Merge pull request #868 from Barsonax/feature/update-logview-settings
Browse files Browse the repository at this point in the history
#CHANGE Updated logview plugin to use the new model based editoruserdata settings API
  • Loading branch information
Barsonax authored Jul 27, 2020
2 parents e0331cf + ba2f866 commit 5794676
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 68 deletions.
10 changes: 10 additions & 0 deletions Source/Editor/DualityEditor/Utility/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ public XElement OldStyleSettings
return setting;
}
/// <summary>
/// Adds or replaces the stored editor plugin settings instance of type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="settings"></param>
public void Set<T>(T settings) where T : class
{
this.data.RemoveAll(obj => obj is T);
this.data.Add(settings);
}
/// <summary>
/// Clears all editor plugin settings from this container, and resets it to an empty state.
/// </summary>
internal void Clear()
Expand Down
29 changes: 8 additions & 21 deletions Source/Plugins/EditorModules/LogView/LogViewPlugin.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -41,30 +35,23 @@ protected override IDockContent DeserializeDockContent(Type dockContentType)
this.isLoading = false;
return result;
}
protected override void SaveUserData(XElement node)
protected override void LoadUserData(PluginSettings pluginSettings)
{
this.isLoading = true;
if (this.logView != null)
{
XElement logViewElem = new XElement("LogView");
this.logView.SaveUserData(logViewElem);
if (!logViewElem.IsEmpty)
node.Add(logViewElem);
this.logView.UserSettings = pluginSettings.Get<LogViewSettings>();
this.logView.ApplyUserSettings();
}
this.isLoading = false;
}
protected override void LoadUserData(XElement node)
protected override void SaveUserData(PluginSettings settings)
{
this.isLoading = true;
base.SaveUserData(settings);
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);
}
settings.Set(this.logView.UserSettings);
}
this.isLoading = false;
}
protected override void InitPlugin(MainForm main)
{
Expand Down
55 changes: 55 additions & 0 deletions Source/Plugins/EditorModules/LogView/LogViewSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
namespace Duality.Editor.Plugins.LogView
{
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; }
}
public bool ShowWarnings
{
get { return this.showWarnings; }
set { this.showWarnings = value; }
}
public bool ShowErrors
{
get { return this.showErrors; }
set { this.showErrors = value; }
}
public bool ShowCore
{
get { return this.showCore; }
set { this.showCore = value; }
}
public bool ShowEditor
{
get { return this.showEditor; }
set { this.showEditor = value; }
}
public bool ShowGame
{
get { return this.showGame; }
set { this.showGame = value; }
}
public bool AutoClear
{
get { return this.autoClear; }
set { this.autoClear = value; }
}
public bool PauseOnError
{
get { return this.pauseOnError; }
set { this.pauseOnError = value; }
}
}
}

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

101 changes: 54 additions & 47 deletions Source/Plugins/EditorModules/LogView/Modules/LogView.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
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
{
private LogViewSettings userSettings = new LogViewSettings();
private int unseenWarnings = 0;
private int unseenErrors = 0;
private int unseenErrors = 0;
private Dictionary<string,ToolStripButton> sourceFilterButtons = new Dictionary<string,ToolStripButton>();


public LogViewSettings UserSettings
{
get { return this.userSettings; }
set { this.userSettings = value ?? new LogViewSettings(); }
}


public LogView()
{
this.InitializeComponent();
Expand All @@ -36,6 +37,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);
Expand All @@ -52,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)
Expand All @@ -61,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)
Expand Down Expand Up @@ -90,38 +114,6 @@ private void DockPanel_ActiveContentChanged(object sender, EventArgs e)
}
}

internal void SaveUserData(XElement node)
{
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);
}
internal void LoadUserData(XElement node)
{
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.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;
Expand Down Expand Up @@ -224,20 +216,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();
Expand Down Expand Up @@ -309,7 +316,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)
{
Expand Down

0 comments on commit 5794676

Please sign in to comment.