mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-31 12:50:52 +00:00
Changed, Texture Browser: "Used Textures" group is now collapsible.
This commit is contained in:
parent
81522c3283
commit
2d02e9b539
3 changed files with 131 additions and 5 deletions
|
@ -303,6 +303,7 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
if(n == selected) continue;
|
if(n == selected) continue;
|
||||||
if(n.Text == selected.Text)
|
if(n.Text == selected.Text)
|
||||||
{
|
{
|
||||||
|
if(list.IsGroupCollapsed(n.Group)) list.SetGroupCollapsed(n.Group, false);
|
||||||
n.Selected = true;
|
n.Selected = true;
|
||||||
n.Focused = true;
|
n.Focused = true;
|
||||||
n.EnsureVisible();
|
n.EnsureVisible();
|
||||||
|
@ -417,6 +418,20 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
list.Groups.Add(grp);
|
list.Groups.Add(grp);
|
||||||
return grp;
|
return grp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//mxd
|
||||||
|
public bool IsGroupCollapsed(ListViewGroup group)
|
||||||
|
{
|
||||||
|
if(!list.Groups.Contains(group)) return false;
|
||||||
|
return list.IsGroupCollapsed(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
//mxd. This enables group collapsability and optionally collapses it
|
||||||
|
public void SetGroupCollapsed(ListViewGroup group, bool collapse)
|
||||||
|
{
|
||||||
|
if(!list.Groups.Contains(group)) return;
|
||||||
|
list.SetGroupCollapsed(group, collapse);
|
||||||
|
}
|
||||||
|
|
||||||
// This begins adding items
|
// This begins adding items
|
||||||
public void BeginAdding(bool keepselectedindex)
|
public void BeginAdding(bool keepselectedindex)
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
#region ================== Namespaces
|
#region ================== Namespaces
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
@ -24,22 +27,57 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
{
|
{
|
||||||
public class OptimizedListView : ListView
|
public class OptimizedListView : ListView
|
||||||
{
|
{
|
||||||
#region ================== Constants
|
#region ================== API Declarations
|
||||||
|
|
||||||
|
[DllImport("user32.dll")]
|
||||||
|
private static extern int SendMessage(IntPtr window, int message, int wParam, ref LVGROUP lParam);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Variables
|
#region ================== Structs
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
private struct LVGROUP
|
||||||
|
{
|
||||||
|
public int cbSize;
|
||||||
|
public int mask;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)]
|
||||||
|
public string pszHeader;
|
||||||
|
public int cchHeader;
|
||||||
|
[MarshalAs(UnmanagedType.LPTStr)]
|
||||||
|
public string pszFooter;
|
||||||
|
public int cchFooter;
|
||||||
|
public int iGroupId;
|
||||||
|
public int stateMask;
|
||||||
|
public int state;
|
||||||
|
public int uAlign;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Properties
|
#region ================== Enums
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
private enum GroupState
|
||||||
|
{
|
||||||
|
COLLAPSIBLE = 8,
|
||||||
|
COLLAPSED = 1,
|
||||||
|
EXPANDED = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region ================== Delegates
|
||||||
|
|
||||||
|
private delegate bool CallBackSetGroupCollapsible(ListViewGroup group, bool collapsed);
|
||||||
|
private delegate bool CallBackGetGroupCollapsed(ListViewGroup group);
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region ================== Constructor
|
#region ================== Constructor
|
||||||
|
|
||||||
// Constructor
|
// Constructor
|
||||||
public OptimizedListView() : base()
|
public OptimizedListView()
|
||||||
{
|
{
|
||||||
this.DoubleBuffered = true;
|
this.DoubleBuffered = true;
|
||||||
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
|
||||||
|
@ -49,6 +87,73 @@ namespace CodeImp.DoomBuilder.Controls
|
||||||
|
|
||||||
#region ================== Methods
|
#region ================== Methods
|
||||||
|
|
||||||
|
//mxd. Collapsible groups support. Created using http://www.codeproject.com/Articles/31276/Add-Group-Collapse-Behavior-on-a-Listview-Control as a reference
|
||||||
|
public bool SetGroupCollapsed(ListViewGroup group, bool collapsed)
|
||||||
|
{
|
||||||
|
// Insanity checks...
|
||||||
|
if(!this.Groups.Contains(group)) return false;
|
||||||
|
if(Environment.OSVersion.Version.Major < 6) return false; //Only Vista and forward allows collapse of ListViewGroups
|
||||||
|
if(this.InvokeRequired) return (bool)this.Invoke(new CallBackSetGroupCollapsible(SetGroupCollapsed), group, collapsed);
|
||||||
|
|
||||||
|
LVGROUP groupstruct = new LVGROUP();
|
||||||
|
groupstruct.cbSize = Marshal.SizeOf(typeof(LVGROUP));
|
||||||
|
groupstruct.state = (int)((collapsed ? GroupState.COLLAPSED : GroupState.EXPANDED) | GroupState.COLLAPSIBLE);
|
||||||
|
groupstruct.stateMask = (int)(GroupState.COLLAPSIBLE | GroupState.COLLAPSED);
|
||||||
|
groupstruct.mask = 4; // LVGF_STATE
|
||||||
|
SendMessage(this.Handle, 0x1000 + 147, GetGroupID(group), ref groupstruct); // #define LVM_SETGROUPINFO (LVM_FIRST + 147)
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mxd. Collapsible groups support. Created using http://fed.googlecode.com/svn/trunk/Plain.Forms/ListViewGroupEx.cs as a reference
|
||||||
|
public bool IsGroupCollapsed(ListViewGroup group)
|
||||||
|
{
|
||||||
|
// Insanity checks...
|
||||||
|
if(!this.Groups.Contains(group)) return false;
|
||||||
|
if(Environment.OSVersion.Version.Major < 6) return false; //Only Vista and forward allows collapse of ListViewGroups
|
||||||
|
if(this.InvokeRequired) return (bool)this.Invoke(new CallBackGetGroupCollapsed(IsGroupCollapsed), group);
|
||||||
|
|
||||||
|
LVGROUP groupstruct = new LVGROUP();
|
||||||
|
groupstruct.cbSize = Marshal.SizeOf(typeof(LVGROUP));
|
||||||
|
groupstruct.stateMask = (int)(GroupState.COLLAPSIBLE | GroupState.COLLAPSED);
|
||||||
|
groupstruct.mask = 4; // LVGF_STATE
|
||||||
|
|
||||||
|
SendMessage(this.Handle, 0x1000 + 149, GetGroupID(group), ref groupstruct); // #define LVM_GETGROUPINFO (LVM_FIRST + 149)
|
||||||
|
return (groupstruct.state & (int)GroupState.COLLAPSED) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mxd.
|
||||||
|
private static int GetGroupID(ListViewGroup group)
|
||||||
|
{
|
||||||
|
int id = int.MinValue;
|
||||||
|
Type grouptype = group.GetType();
|
||||||
|
|
||||||
|
PropertyInfo pi = grouptype.GetProperty("ID", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||||
|
if(pi != null)
|
||||||
|
{
|
||||||
|
object idprop = pi.GetValue(group, null);
|
||||||
|
if(idprop != null) id = (int)idprop;
|
||||||
|
}
|
||||||
|
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
//mxd. Required to make "Expand/Collapse" group header button work.
|
||||||
|
protected override void WndProc(ref Message m)
|
||||||
|
{
|
||||||
|
switch(m.Msg)
|
||||||
|
{
|
||||||
|
case 0x202: // WM_LBUTTONUP
|
||||||
|
base.DefWndProc(ref m);
|
||||||
|
base.WndProc(ref m);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
base.WndProc(ref m);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,7 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
private readonly ListViewGroup availgroup;
|
private readonly ListViewGroup availgroup;
|
||||||
private TreeNode selectedset; //mxd
|
private TreeNode selectedset; //mxd
|
||||||
private string selecttextureonfill;
|
private string selecttextureonfill;
|
||||||
|
private readonly bool usedgroupcollapsed; //mxd
|
||||||
private readonly bool browseflats; //mxd
|
private readonly bool browseflats; //mxd
|
||||||
|
|
||||||
// Properties
|
// Properties
|
||||||
|
@ -80,6 +81,10 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
usedgroup = browser.AddGroup("Used " + imagetype + ":");
|
usedgroup = browser.AddGroup("Used " + imagetype + ":");
|
||||||
availgroup = browser.AddGroup("Available " + imagetype + ":");
|
availgroup = browser.AddGroup("Available " + imagetype + ":");
|
||||||
|
|
||||||
|
//mxd. Make "Used" group collapsible
|
||||||
|
usedgroupcollapsed = General.Settings.ReadSetting("browserwindow.usedgroupcollapsed", false);
|
||||||
|
browser.SetGroupCollapsed(usedgroup, usedgroupcollapsed);
|
||||||
|
|
||||||
//mxd. Fill texture sets list with normal texture sets
|
//mxd. Fill texture sets list with normal texture sets
|
||||||
foreach(IFilledTextureSet ts in General.Map.Data.TextureSets)
|
foreach(IFilledTextureSet ts in General.Map.Data.TextureSets)
|
||||||
{
|
{
|
||||||
|
@ -455,6 +460,7 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
General.Settings.WriteSetting("browserwindow.windowstate", windowstate);
|
General.Settings.WriteSetting("browserwindow.windowstate", windowstate);
|
||||||
if(!splitter.IsCollapsed) General.Settings.WriteSetting("browserwindow.splitterdistance", splitter.SplitPosition); //mxd
|
if(!splitter.IsCollapsed) General.Settings.WriteSetting("browserwindow.splitterdistance", splitter.SplitPosition); //mxd
|
||||||
General.Settings.WriteSetting("browserwindow.splittercollapsed", splitter.IsCollapsed); //mxd
|
General.Settings.WriteSetting("browserwindow.splittercollapsed", splitter.IsCollapsed); //mxd
|
||||||
|
General.Settings.WriteSetting("browserwindow.usedgroupcollapsed", browser.IsGroupCollapsed(usedgroup)); //mxd
|
||||||
|
|
||||||
//mxd. Save last selected texture set, if it's not "All" (it will be selected anyway if search for initial texture set fails)
|
//mxd. Save last selected texture set, if it's not "All" (it will be selected anyway if search for initial texture set fails)
|
||||||
if(this.DialogResult == DialogResult.OK && tvTextureSets.SelectedNodes.Count > 0 && !(tvTextureSets.SelectedNodes[0].Tag is AllTextureSet))
|
if(this.DialogResult == DialogResult.OK && tvTextureSets.SelectedNodes.Count > 0 && !(tvTextureSets.SelectedNodes[0].Tag is AllTextureSet))
|
||||||
|
@ -534,7 +540,7 @@ namespace CodeImp.DoomBuilder.Windows
|
||||||
// Select texture
|
// Select texture
|
||||||
if(!string.IsNullOrEmpty(selecttextureonfill))
|
if(!string.IsNullOrEmpty(selecttextureonfill))
|
||||||
{
|
{
|
||||||
browser.SelectItem(selecttextureonfill, usedgroup);
|
browser.SelectItem(selecttextureonfill, (usedgroupcollapsed ? availgroup : usedgroup)); //mxd. availgroup/usedgroup switch.
|
||||||
selecttextureonfill = null;
|
selecttextureonfill = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue