191110PX Bugfix for column width changing resulted in multi-XML-writes under mono

This commit is contained in:
phantomix 2019-11-10 14:12:05 +01:00
parent 5053248e50
commit 8b8eb87621
3 changed files with 51 additions and 12 deletions

View File

@ -25,7 +25,7 @@ namespace dezentrale
{
public class Program
{
public static uint VersionNumber { get; private set; } = 0x19110900;
public static uint VersionNumber { get; private set; } = 0x19111000;
public static string VersionString { get; private set; } = $"{VersionNumber:x}";
public static string AppData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

View File

@ -8,7 +8,14 @@ namespace dezentrale.model
[XmlAttribute] public string Name { get; set; } = "";
[XmlAttribute] public bool Visible { get; set; } = true;
[XmlAttribute] public int Width { get; set; } = 80;
[XmlAttribute] public int Width { get; set; } = 80;
/**\brief This is for resizing under mono: We need to store the width
* until the mouse button is released, to prevent an XML write
* for every pixel change.
*/
[XmlIgnore] public int NewWidth{ get; set; } = 80;
public ConfigLVColumn() : base() { }

View File

@ -83,6 +83,7 @@ namespace dezentrale.view
cm.MenuItems.Add("Configure columns...", mnuConfigColumns_Click);
ColumnWidthChanged += CustomListView_ColumnWidthChanged;
MouseUp += CustomListView_MouseUp;
if (colsChanged)
ColumnsChanged?.Invoke(this, new ColumnsChangedArgs() { Columns = this.actualColumns });
}
@ -105,26 +106,57 @@ namespace dezentrale.view
LoadFromList(internalList);
}
}
private void SetNewColWidth(ConfigLVDataHandler c, int newWidth)
{
Console.WriteLine($"SetNewColWidth({c},{newWidth})");
List<ConfigLVDataHandler> newList = new List<ConfigLVDataHandler>();
foreach (ConfigLVDataHandler lvc in actualColumns)
{
ConfigLVDataHandler c2 = new ConfigLVDataHandler(lvc, lvc);
if (c.Name == lvc.Name) c2.Width = newWidth;
newList.Add(c2);
}
ColumnsChangedArgs cca = new ColumnsChangedArgs() { Columns = newList };
ColumnsChanged?.Invoke(this, cca);
if (cca.Cancel) return;
actualColumns = cca.Columns;
}
private bool resizeWhileMouseDown = false;
private ConfigLVDataHandler resizedWhileMouseDown = null;
private void CustomListView_ColumnWidthChanged(object sender, ColumnWidthChangedEventArgs e)
{
ColumnHeader col = this.Columns[e.ColumnIndex];
ConfigLVDataHandler c = (ConfigLVDataHandler)col.Tag;
if ((c != null) && (c.Width != col.Width))
{
List<ConfigLVDataHandler> newList = new List<ConfigLVDataHandler>();
foreach (ConfigLVDataHandler lvc in actualColumns)
{
ConfigLVDataHandler c2 = new ConfigLVDataHandler(lvc, lvc);
if (c.Name == lvc.Name) c2.Width = col.Width;
newList.Add(c2);
if(Control.MouseButtons == MouseButtons.None)
SetNewColWidth(c, col.Width);
else
{
//Just remember that setting for later
//Console.WriteLine($"ColumnWidthChanged(): MouseButtons={Control.MouseButtons}");
c.NewWidth = col.Width;
resizeWhileMouseDown = true;
resizedWhileMouseDown = c;
}
ColumnsChangedArgs cca = new ColumnsChangedArgs() { Columns = newList };
ColumnsChanged?.Invoke(this, cca);
if (cca.Cancel) return;
actualColumns = cca.Columns;
}
}
void CustomListView_MouseUp(object sender, MouseEventArgs e)
{
Console.WriteLine($"MouseUp(): MouseButtons={Control.MouseButtons}");
if (resizeWhileMouseDown && (resizedWhileMouseDown != null))
{
//mono: Store new width.
resizeWhileMouseDown = false;
SetNewColWidth(resizedWhileMouseDown, resizedWhileMouseDown.NewWidth);
}
}
protected ListViewItem GetExistingLvi(T tag)
{
foreach (ListViewItem lvi in this.Items)