2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#region ================== Copyright (c) 2007 Pascal vd Heiden
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com
|
|
|
|
* This program is released under GNU General Public License
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Namespaces
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Drawing;
|
2015-11-20 14:31:54 +00:00
|
|
|
using System.Globalization;
|
2009-04-19 18:07:22 +00:00
|
|
|
using System.Windows.Forms;
|
|
|
|
using CodeImp.DoomBuilder.Data;
|
2015-04-03 12:05:37 +00:00
|
|
|
using CodeImp.DoomBuilder.Windows;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace CodeImp.DoomBuilder.Controls
|
|
|
|
{
|
|
|
|
internal partial class ImageBrowserControl : UserControl
|
|
|
|
{
|
|
|
|
#region ================== Constants
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Delegates / Events
|
|
|
|
|
|
|
|
public delegate void SelectedItemChangedDelegate();
|
|
|
|
public delegate void SelectedItemDoubleClickDelegate();
|
|
|
|
|
|
|
|
public event SelectedItemChangedDelegate SelectedItemChanged;
|
|
|
|
public event SelectedItemDoubleClickDelegate SelectedItemDoubleClicked;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Variables
|
|
|
|
|
|
|
|
// Properties
|
|
|
|
private bool preventselection;
|
|
|
|
|
|
|
|
// States
|
|
|
|
private bool updating;
|
|
|
|
private int keepselected;
|
2014-01-24 08:09:57 +00:00
|
|
|
private bool browseFlats; //mxd
|
2014-12-03 23:30:58 +00:00
|
|
|
private static bool uselongtexturenames; //mxd
|
2015-09-16 12:10:43 +00:00
|
|
|
private static bool showtexturesfromsubdirs; //mxd
|
|
|
|
private int currentlevel; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// All items
|
2014-05-19 13:33:38 +00:00
|
|
|
private readonly List<ImageBrowserItem> items;
|
2009-05-05 12:24:00 +00:00
|
|
|
|
|
|
|
// Items visible in the list
|
|
|
|
private List<ImageBrowserItem> visibleitems;
|
2013-03-26 12:31:07 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
private static int mixMode;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Properties
|
|
|
|
|
|
|
|
public bool PreventSelection { get { return preventselection; } set { preventselection = value; } }
|
|
|
|
public bool HideInputBox { get { return splitter.Panel2Collapsed; } set { splitter.Panel2Collapsed = value; } }
|
2014-01-24 08:09:57 +00:00
|
|
|
public bool BrowseFlats { get { return browseFlats; } set { browseFlats = value; } } //mxd
|
2015-09-16 12:10:43 +00:00
|
|
|
public static bool ShowTexturesFromSubDirectories { get { return showtexturesfromsubdirs; } internal set { showtexturesfromsubdirs = value; } } //mxd
|
2014-12-03 23:30:58 +00:00
|
|
|
public static bool UseLongTextureNames { get { return uselongtexturenames; } internal set { uselongtexturenames = value; } } //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
public ListViewItem SelectedItem { get { if(list.SelectedItems.Count > 0) return list.SelectedItems[0]; else return null; } }
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Constructor / Disposer
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
public ImageBrowserControl()
|
|
|
|
{
|
|
|
|
// Initialize
|
|
|
|
InitializeComponent();
|
|
|
|
items = new List<ImageBrowserItem>();
|
2013-09-26 12:43:39 +00:00
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
2013-09-26 12:43:39 +00:00
|
|
|
StepsList sizes = new StepsList { 4, 8, 16, 32, 48, 64, 96, 128, 196, 256, 512, 1024 };
|
|
|
|
filterWidth.StepValues = sizes;
|
|
|
|
filterHeight.StepValues = sizes;
|
2015-04-03 12:05:37 +00:00
|
|
|
|
|
|
|
//mxd. Looks like SplitterDistance is unaffected by DPI scaling. Let's fix that...
|
|
|
|
if(MainForm.DPIScaler.Height != 1.0f)
|
|
|
|
{
|
|
|
|
splitter.SplitterDistance = splitter.Height - splitter.Panel2.Height - (int)Math.Round(splitter.SplitterWidth * MainForm.DPIScaler.Height);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This applies the application settings
|
|
|
|
public void ApplySettings()
|
|
|
|
{
|
|
|
|
// Force black background?
|
|
|
|
if(General.Settings.BlackBrowsers)
|
|
|
|
{
|
|
|
|
list.BackColor = Color.Black;
|
|
|
|
list.ForeColor = Color.White;
|
|
|
|
}
|
|
|
|
|
2011-12-02 22:18:55 +00:00
|
|
|
// Set the size of preview images
|
2009-05-12 08:01:50 +00:00
|
|
|
if(General.Map != null)
|
2011-12-02 22:18:55 +00:00
|
|
|
{
|
|
|
|
int itemwidth = General.Map.Data.Previews.MaxImageWidth + 26;
|
|
|
|
int itemheight = General.Map.Data.Previews.MaxImageHeight + 26;
|
|
|
|
list.TileSize = new Size(itemwidth, itemheight);
|
2013-06-19 11:18:13 +00:00
|
|
|
|
|
|
|
//mxd
|
2014-11-25 11:52:01 +00:00
|
|
|
if(General.Map.Config.MixTexturesFlats)
|
|
|
|
{
|
2013-06-19 11:18:13 +00:00
|
|
|
cbMixMode.SelectedIndex = mixMode;
|
2014-11-25 11:52:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-19 11:18:13 +00:00
|
|
|
labelMixMode.Visible = false;
|
|
|
|
cbMixMode.Visible = false;
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
|
|
int offset = label.Left - labelMixMode.Left;
|
|
|
|
label.Left -= offset;
|
|
|
|
objectname.Left -= offset;
|
|
|
|
filterWidth.Left -= offset;
|
|
|
|
filterwidthlabel.Left -= offset;
|
|
|
|
filterHeight.Left -= offset;
|
|
|
|
filterheightlabel.Left -= offset;
|
2015-09-16 12:10:43 +00:00
|
|
|
showsubdirtextures.Left -= offset;
|
2014-12-03 09:06:05 +00:00
|
|
|
longtexturenames.Left -= offset;
|
|
|
|
|
2013-06-19 11:18:13 +00:00
|
|
|
mixMode = 0;
|
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
|
|
|
//mxd. Use long texture names?
|
|
|
|
longtexturenames.Checked = (uselongtexturenames && General.Map.Config.UseLongTextureNames);
|
|
|
|
longtexturenames.Visible = General.Map.Config.UseLongTextureNames;
|
2015-09-25 13:20:53 +00:00
|
|
|
if(!General.Map.Config.UseLongTextureNames)
|
|
|
|
showsubdirtextures.Left = longtexturenames.Left; //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
longtexturenames.Visible = false; //mxd
|
|
|
|
uselongtexturenames = false; //mxd
|
2015-09-25 13:20:53 +00:00
|
|
|
showsubdirtextures.Left = longtexturenames.Left; //mxd
|
2011-12-02 22:18:55 +00:00
|
|
|
}
|
2014-07-15 08:50:52 +00:00
|
|
|
|
|
|
|
//mxd
|
|
|
|
if(!General.Settings.CapitalizeTextureNames)
|
|
|
|
objectname.CharacterCasing = CharacterCasing.Normal;
|
2014-12-03 09:06:05 +00:00
|
|
|
|
2015-09-16 12:10:43 +00:00
|
|
|
//mxd. Show textures in subfolders?
|
|
|
|
showsubdirtextures.Checked = showtexturesfromsubdirs;
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This cleans everything up
|
|
|
|
public virtual void CleanUp()
|
|
|
|
{
|
|
|
|
// Stop refresh timer
|
|
|
|
refreshtimer.Enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Rendering
|
|
|
|
|
|
|
|
// Draw item
|
|
|
|
private void list_DrawItem(object sender, DrawListViewItemEventArgs e)
|
|
|
|
{
|
|
|
|
if(!updating) (e.Item as ImageBrowserItem).Draw(e.Graphics, e.Bounds);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Refresher
|
|
|
|
private void refreshtimer_Tick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
bool allpreviewsloaded = true;
|
|
|
|
|
|
|
|
// Go for all items
|
|
|
|
foreach(ImageBrowserItem i in list.Items)
|
|
|
|
{
|
|
|
|
// Check if there are still previews that are not loaded
|
|
|
|
allpreviewsloaded &= i.IsPreviewLoaded;
|
|
|
|
|
|
|
|
// Items needs to be redrawn?
|
|
|
|
if(i.CheckRedrawNeeded())
|
|
|
|
{
|
|
|
|
// Refresh item in list
|
|
|
|
//list.RedrawItems(i.Index, i.Index, false);
|
|
|
|
list.Invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If all previews were loaded, stop this timer
|
|
|
|
if(allpreviewsloaded) refreshtimer.Stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Events
|
|
|
|
|
|
|
|
// Name typed
|
|
|
|
private void objectname_TextChanged(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
// Update list
|
|
|
|
RefillList(false);
|
|
|
|
|
|
|
|
// No item selected?
|
|
|
|
if(list.SelectedItems.Count == 0)
|
|
|
|
{
|
|
|
|
// Select first
|
|
|
|
SelectFirstItem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-05 12:24:00 +00:00
|
|
|
// Key pressed in textbox
|
2009-04-19 18:07:22 +00:00
|
|
|
private void objectname_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
// Check what key is pressed
|
|
|
|
switch(e.KeyData)
|
|
|
|
{
|
|
|
|
// Cursor keys
|
|
|
|
case Keys.Left: SelectNextItem(SearchDirectionHint.Left); e.SuppressKeyPress = true; break;
|
|
|
|
case Keys.Right: SelectNextItem(SearchDirectionHint.Right); e.SuppressKeyPress = true; break;
|
|
|
|
case Keys.Up: SelectNextItem(SearchDirectionHint.Up); e.SuppressKeyPress = true; break;
|
|
|
|
case Keys.Down: SelectNextItem(SearchDirectionHint.Down); e.SuppressKeyPress = true; break;
|
2009-05-05 12:24:00 +00:00
|
|
|
|
|
|
|
// Tab
|
|
|
|
case Keys.Tab: GoToNextSameTexture(); e.SuppressKeyPress = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-10 23:40:02 +00:00
|
|
|
//mxd. Handle keyboard navigation the same way regardless of list being focused...
|
|
|
|
private void list_KeyDown(object sender, KeyEventArgs e)
|
|
|
|
{
|
|
|
|
// Check what key is pressed
|
|
|
|
switch(e.KeyData)
|
|
|
|
{
|
|
|
|
// Cursor keys
|
|
|
|
case Keys.Left: SelectNextItem(SearchDirectionHint.Left); e.SuppressKeyPress = true; break;
|
|
|
|
case Keys.Right: SelectNextItem(SearchDirectionHint.Right); e.SuppressKeyPress = true; break;
|
|
|
|
case Keys.Up: SelectNextItem(SearchDirectionHint.Up); e.SuppressKeyPress = true; break;
|
|
|
|
case Keys.Down: SelectNextItem(SearchDirectionHint.Down); e.SuppressKeyPress = true; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-26 12:43:39 +00:00
|
|
|
//mxd
|
2014-05-19 13:33:38 +00:00
|
|
|
private void filterSize_WhenTextChanged(object sender, EventArgs e)
|
|
|
|
{
|
2013-09-26 12:43:39 +00:00
|
|
|
objectname_TextChanged(sender, e);
|
|
|
|
}
|
|
|
|
|
2015-03-25 22:13:40 +00:00
|
|
|
//mxd
|
|
|
|
protected override bool ProcessTabKey(bool forward)
|
|
|
|
{
|
|
|
|
GoToNextSameTexture();
|
|
|
|
return false;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Selection changed
|
|
|
|
private void list_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
|
|
|
|
{
|
2014-07-15 08:22:45 +00:00
|
|
|
if(!e.IsSelected) return; //mxd. Don't want to trigger this twice
|
|
|
|
|
2009-04-19 18:07:22 +00:00
|
|
|
// Prevent selecting?
|
|
|
|
if(preventselection)
|
|
|
|
{
|
|
|
|
foreach(ListViewItem i in list.SelectedItems) i.Selected = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Raise event
|
|
|
|
if(SelectedItemChanged != null) SelectedItemChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Doublelicking an item
|
|
|
|
private void list_DoubleClick(object sender, EventArgs e)
|
|
|
|
{
|
|
|
|
if(!preventselection && (list.SelectedItems.Count > 0))
|
|
|
|
if(SelectedItemDoubleClicked != null) SelectedItemDoubleClicked();
|
|
|
|
}
|
2014-12-03 09:06:05 +00:00
|
|
|
|
2015-11-20 14:31:54 +00:00
|
|
|
//mxd. Transfer focus to Filter textbox
|
|
|
|
private void list_KeyPress(object sender, KeyPressEventArgs e)
|
|
|
|
{
|
2016-02-10 23:40:02 +00:00
|
|
|
if(!General.Settings.KeepTextureFilterFocused) return;
|
|
|
|
|
2015-11-20 14:31:54 +00:00
|
|
|
objectname.Focus();
|
|
|
|
if(e.KeyChar == '\b') // Any better way to check for Backspace?..
|
|
|
|
{
|
|
|
|
if(!string.IsNullOrEmpty(objectname.Text) && objectname.SelectionStart > 0 && objectname.SelectionLength == 0)
|
|
|
|
{
|
|
|
|
int s = objectname.SelectionStart - 1;
|
|
|
|
objectname.Text = objectname.Text.Remove(s, 1);
|
|
|
|
objectname.SelectionStart = s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
objectname.AppendText(e.KeyChar.ToString(CultureInfo.InvariantCulture));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
|
|
|
private void cbMixMode_SelectedIndexChanged(object sender, EventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
mixMode = cbMixMode.SelectedIndex;
|
|
|
|
RefillList(false);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd
|
|
|
|
private void longtexturenames_CheckedChanged(object sender, EventArgs e)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
uselongtexturenames = longtexturenames.Checked;
|
|
|
|
RefillList(false);
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2013-03-26 12:31:07 +00:00
|
|
|
|
|
|
|
//mxd
|
2015-09-16 12:10:43 +00:00
|
|
|
private void showsubdirtextures_CheckedChanged(object sender, EventArgs e)
|
2014-11-25 11:52:01 +00:00
|
|
|
{
|
2015-09-16 12:10:43 +00:00
|
|
|
showtexturesfromsubdirs = showsubdirtextures.Checked;
|
|
|
|
RefillList(false);
|
2013-03-26 12:31:07 +00:00
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region ================== Methods
|
|
|
|
|
2009-05-05 12:24:00 +00:00
|
|
|
// This selects the next texture with the same name as the selected texture
|
|
|
|
public void GoToNextSameTexture()
|
|
|
|
{
|
|
|
|
if(list.SelectedItems.Count > 0)
|
|
|
|
{
|
2015-11-17 17:50:56 +00:00
|
|
|
list.Focus(); //mxd
|
2009-05-05 12:24:00 +00:00
|
|
|
ListViewItem selected = list.SelectedItems[0];
|
|
|
|
|
2013-12-20 09:24:43 +00:00
|
|
|
//mxd
|
2015-03-22 20:43:05 +00:00
|
|
|
foreach(ImageBrowserItem n in visibleitems)
|
2014-11-25 11:52:01 +00:00
|
|
|
{
|
2013-12-20 09:24:43 +00:00
|
|
|
if(n == selected) continue;
|
2014-11-25 11:52:01 +00:00
|
|
|
if(n.Text == selected.Text)
|
|
|
|
{
|
2015-03-16 08:54:31 +00:00
|
|
|
if(list.IsGroupCollapsed(n.Group)) list.SetGroupCollapsed(n.Group, false);
|
2009-05-05 12:24:00 +00:00
|
|
|
n.Selected = true;
|
2013-12-20 09:24:43 +00:00
|
|
|
n.Focused = true;
|
2009-05-05 12:24:00 +00:00
|
|
|
n.EnsureVisible();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-07 18:37:54 +00:00
|
|
|
// This selects an item by longname (mxd - changed from name to longname)
|
|
|
|
public void SelectItem(long longname, ListViewGroup preferredgroup)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
ImageBrowserItem lvi = null; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Not when selecting is prevented
|
|
|
|
if(preventselection) return;
|
|
|
|
|
|
|
|
// Search in preferred group first
|
|
|
|
if(preferredgroup != null)
|
|
|
|
{
|
|
|
|
foreach(ListViewItem item in list.Items)
|
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
ImageBrowserItem curitem = item as ImageBrowserItem;
|
2015-07-07 18:37:54 +00:00
|
|
|
if(curitem != null && longname == curitem.Icon.LongName) //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-11-25 11:52:01 +00:00
|
|
|
lvi = curitem;
|
2009-04-19 18:07:22 +00:00
|
|
|
if(item.Group == preferredgroup) break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the item
|
|
|
|
if(lvi != null)
|
|
|
|
{
|
|
|
|
// Select this item
|
|
|
|
list.SelectedItems.Clear();
|
|
|
|
lvi.Selected = true;
|
|
|
|
lvi.EnsureVisible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This performs item sleection by keys
|
|
|
|
private void SelectNextItem(SearchDirectionHint dir)
|
|
|
|
{
|
|
|
|
// Not when selecting is prevented
|
|
|
|
if(preventselection) return;
|
|
|
|
|
|
|
|
// Nothing selected?
|
|
|
|
if(list.SelectedItems.Count == 0)
|
|
|
|
{
|
|
|
|
// Select first
|
|
|
|
SelectFirstItem();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-02-10 23:40:02 +00:00
|
|
|
//mxd
|
|
|
|
int index = list.SelectedItems[0].Index;
|
|
|
|
int targetindex = -1;
|
|
|
|
ListViewGroup startgroup = list.SelectedItems[0].Group;
|
2016-02-15 14:06:46 +00:00
|
|
|
Rectangle startrect = list.SelectedItems[0].GetBounds(ItemBoundsPortion.Entire);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
2016-02-10 23:40:02 +00:00
|
|
|
switch(dir)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2016-02-10 23:40:02 +00:00
|
|
|
// Check previous items untill groups match...
|
|
|
|
case SearchDirectionHint.Left:
|
|
|
|
if(list.SelectedIndices[0] > 0)
|
|
|
|
{
|
|
|
|
while(--index > -1)
|
|
|
|
{
|
|
|
|
if(list.Items[index].Group == startgroup)
|
|
|
|
{
|
|
|
|
targetindex = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Same thing, other direction...
|
|
|
|
case SearchDirectionHint.Right:
|
|
|
|
if(list.SelectedIndices[0] < list.Items.Count - 1)
|
|
|
|
{
|
|
|
|
while(++index < list.Items.Count)
|
|
|
|
{
|
|
|
|
if(list.Items[index].Group == startgroup)
|
|
|
|
{
|
|
|
|
targetindex = index;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
// Check previous items untill X coordinate match and Y coordinate is less than the start ones...
|
|
|
|
case SearchDirectionHint.Up:
|
|
|
|
while(--index > -1)
|
|
|
|
{
|
2016-02-15 14:06:46 +00:00
|
|
|
ListViewItem item = list.Items[index];
|
|
|
|
if(item != null && item.Group == startgroup)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-02-15 14:06:46 +00:00
|
|
|
Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);
|
|
|
|
if(rect.X == startrect.X && rect.Y < startrect.Y)
|
|
|
|
{
|
|
|
|
targetindex = index;
|
|
|
|
break;
|
|
|
|
}
|
2016-02-10 23:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
break;
|
2016-02-10 23:40:02 +00:00
|
|
|
|
|
|
|
// Same thing, other direction...
|
|
|
|
case SearchDirectionHint.Down:
|
|
|
|
if(list.SelectedIndices[0] < list.Items.Count - 1)
|
|
|
|
{
|
|
|
|
while(++index < list.Items.Count)
|
|
|
|
{
|
2016-02-15 14:06:46 +00:00
|
|
|
ListViewItem item = list.Items[index];
|
|
|
|
if(item != null && item.Group == startgroup)
|
2016-02-10 23:40:02 +00:00
|
|
|
{
|
2016-02-15 14:06:46 +00:00
|
|
|
Rectangle rect = item.GetBounds(ItemBoundsPortion.Entire);
|
|
|
|
if(rect.X == startrect.X && rect.Y > startrect.Y)
|
|
|
|
{
|
|
|
|
targetindex = index;
|
|
|
|
break;
|
|
|
|
}
|
2016-02-10 23:40:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
//mxd. Use the old method for Up/Down keys, becaue it can jump between Groups...
|
|
|
|
if(targetindex == -1 && (dir == SearchDirectionHint.Up || dir == SearchDirectionHint.Down))
|
|
|
|
{
|
|
|
|
Point spos = new Point(startrect.Location.X + startrect.Width / 2, startrect.Y + startrect.Height / 2);
|
|
|
|
|
|
|
|
// Try finding 5 times in the given direction
|
|
|
|
for(int i = 0; i < 5; i++)
|
|
|
|
{
|
|
|
|
// Move point in given direction
|
|
|
|
switch(dir)
|
|
|
|
{
|
|
|
|
case SearchDirectionHint.Up: spos.Y -= list.TileSize.Height / 2; break;
|
|
|
|
case SearchDirectionHint.Down: spos.Y += list.TileSize.Height / 2; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test position
|
|
|
|
ListViewItem lvi = list.GetItemAt(spos.X, spos.Y);
|
|
|
|
if(lvi != null)
|
|
|
|
{
|
|
|
|
targetindex = lvi.Index;
|
|
|
|
break;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
2016-02-10 23:40:02 +00:00
|
|
|
|
|
|
|
//mxd. Found something?..
|
|
|
|
if(targetindex != -1)
|
|
|
|
{
|
|
|
|
// Select item
|
|
|
|
list.SelectedItems.Clear();
|
|
|
|
list.Items[targetindex].Selected = true;
|
|
|
|
list.SelectedItems[0].EnsureVisible();
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This selectes the first item
|
|
|
|
private void SelectFirstItem()
|
|
|
|
{
|
|
|
|
// Not when selecting is prevented
|
|
|
|
if(preventselection) return;
|
|
|
|
|
|
|
|
// Select first
|
|
|
|
if(list.Items.Count > 0)
|
|
|
|
{
|
|
|
|
list.SelectedItems.Clear();
|
2014-11-25 11:52:01 +00:00
|
|
|
ListViewItem lvi = list.GetItemAt(list.TileSize.Width / 2, list.TileSize.Height / 2);
|
2009-04-19 18:07:22 +00:00
|
|
|
if(lvi != null)
|
|
|
|
{
|
|
|
|
lvi.Selected = true;
|
|
|
|
lvi.EnsureVisible();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds a group
|
|
|
|
public ListViewGroup AddGroup(string name)
|
|
|
|
{
|
|
|
|
ListViewGroup grp = new ListViewGroup(name);
|
|
|
|
list.Groups.Add(grp);
|
|
|
|
return grp;
|
|
|
|
}
|
2015-03-16 08:54:31 +00:00
|
|
|
|
|
|
|
//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);
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This begins adding items
|
2015-09-16 12:10:43 +00:00
|
|
|
public void BeginAdding(bool keepselectedindex) { BeginAdding(0, keepselectedindex); } //mxd
|
|
|
|
public void BeginAdding(int selectedlevel, bool keepselectedindex)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
if(keepselectedindex && (list.SelectedItems.Count > 0))
|
|
|
|
keepselected = list.SelectedIndices[0];
|
|
|
|
else
|
|
|
|
keepselected = -1;
|
2015-09-16 12:10:43 +00:00
|
|
|
|
|
|
|
currentlevel = selectedlevel;
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Clean list
|
|
|
|
items.Clear();
|
|
|
|
|
|
|
|
// Stop updating
|
|
|
|
refreshtimer.Enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This ends adding items
|
|
|
|
public void EndAdding()
|
|
|
|
{
|
|
|
|
// Fill list with items
|
|
|
|
RefillList(true);
|
|
|
|
|
|
|
|
// Start updating
|
|
|
|
refreshtimer.Enabled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds an item
|
2014-12-03 09:06:05 +00:00
|
|
|
public void Add(ImageData image, object tag, ListViewGroup group)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
ImageBrowserItem i = new ImageBrowserItem(image, tag, uselongtexturenames); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
i.ListGroup = group;
|
|
|
|
i.Group = group;
|
2014-12-03 09:06:05 +00:00
|
|
|
i.ToolTipText = image.Name; //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
items.Add(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This adds an item
|
2014-12-03 09:06:05 +00:00
|
|
|
public void Add(ImageData image, object tag, ListViewGroup group, string tooltiptext)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
ImageBrowserItem i = new ImageBrowserItem(image, tag, uselongtexturenames); //mxd
|
2009-04-19 18:07:22 +00:00
|
|
|
i.ListGroup = group;
|
|
|
|
i.Group = group;
|
|
|
|
i.ToolTipText = tooltiptext;
|
|
|
|
items.Add(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
// This fills the list based on the objectname filter
|
|
|
|
private void RefillList(bool selectfirst)
|
|
|
|
{
|
2009-05-05 12:24:00 +00:00
|
|
|
visibleitems = new List<ImageBrowserItem>();
|
2016-02-10 23:40:02 +00:00
|
|
|
|
|
|
|
//mxd. Store info about currently selected item
|
|
|
|
string selectedname = string.Empty;
|
|
|
|
ListViewGroup selecteditemgroup = null;
|
|
|
|
if(!selectfirst && keepselected == -1 && list.SelectedIndices.Count > 0)
|
|
|
|
{
|
|
|
|
selectedname = list.Items[list.SelectedIndices[0]].Text;
|
|
|
|
selecteditemgroup = list.Items[list.SelectedIndices[0]].Group;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Begin updating list
|
|
|
|
updating = true;
|
|
|
|
//list.SuspendLayout();
|
|
|
|
list.BeginUpdate();
|
|
|
|
|
|
|
|
// Clear list first
|
|
|
|
// Group property of items will be set to null, we will restore it later
|
|
|
|
list.Items.Clear();
|
2013-09-26 12:43:39 +00:00
|
|
|
|
|
|
|
//mxd. Filtering by texture size?
|
|
|
|
int w = filterWidth.GetResult(-1);
|
|
|
|
int h = filterHeight.GetResult(-1);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Go for all items
|
2015-03-22 20:43:05 +00:00
|
|
|
ImageBrowserItem previtem = null; //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
for(int i = items.Count - 1; i > -1; i--)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
|
|
|
// Add item if valid
|
2014-12-03 09:06:05 +00:00
|
|
|
items[i].ShowFullName = uselongtexturenames; //mxd
|
2015-03-22 20:43:05 +00:00
|
|
|
if(ValidateItem(items[i], previtem) && ValidateItemSize(items[i], w, h))
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
items[i].Group = items[i].ListGroup;
|
|
|
|
items[i].Selected = false;
|
|
|
|
visibleitems.Add(items[i]);
|
2015-03-22 20:43:05 +00:00
|
|
|
previtem = items[i];
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fill list
|
2009-05-05 12:24:00 +00:00
|
|
|
visibleitems.Sort();
|
|
|
|
ListViewItem[] array = new ListViewItem[visibleitems.Count];
|
|
|
|
for(int i = 0; i < visibleitems.Count; i++) array[i] = visibleitems[i];
|
|
|
|
list.Items.AddRange(array);
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// Done updating list
|
|
|
|
updating = false;
|
|
|
|
list.EndUpdate();
|
|
|
|
list.Invalidate();
|
|
|
|
//list.ResumeLayout();
|
|
|
|
|
|
|
|
// Make selection?
|
|
|
|
if(!preventselection && (list.Items.Count > 0))
|
|
|
|
{
|
|
|
|
// Select specific item?
|
|
|
|
if(keepselected > -1)
|
|
|
|
{
|
|
|
|
list.Items[keepselected].Selected = true;
|
|
|
|
list.Items[keepselected].EnsureVisible();
|
|
|
|
}
|
|
|
|
// Select first item?
|
|
|
|
else if(selectfirst)
|
|
|
|
{
|
|
|
|
SelectFirstItem();
|
|
|
|
}
|
2016-02-10 23:40:02 +00:00
|
|
|
//mxd. Try reselecting the same/next closest item
|
|
|
|
else if(selecteditemgroup != null && !string.IsNullOrEmpty(selectedname))
|
|
|
|
{
|
|
|
|
ListViewItem bestmatch = null;
|
|
|
|
int charsmatched = 1;
|
|
|
|
foreach(ListViewItem item in list.Items)
|
|
|
|
{
|
|
|
|
if(item.Group == selecteditemgroup && item.Text[0] == selectedname[0])
|
|
|
|
{
|
|
|
|
if(item.Text == selectedname)
|
|
|
|
{
|
|
|
|
bestmatch = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 1; i < Math.Min(item.Text.Length, selectedname.Length); i++)
|
|
|
|
{
|
|
|
|
if(item.Text[i] != selectedname[i])
|
|
|
|
{
|
|
|
|
if(i > charsmatched)
|
|
|
|
{
|
|
|
|
bestmatch = item;
|
|
|
|
charsmatched = i;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select the first item from the same group...
|
|
|
|
if(bestmatch == null)
|
|
|
|
{
|
|
|
|
foreach(ListViewItem item in list.Items)
|
|
|
|
{
|
|
|
|
if(item.Group == selecteditemgroup)
|
|
|
|
{
|
|
|
|
bestmatch = item;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Select found item
|
|
|
|
if(bestmatch != null)
|
|
|
|
{
|
|
|
|
bestmatch.Selected = true;
|
|
|
|
bestmatch.EnsureVisible();
|
|
|
|
}
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Raise event
|
|
|
|
if((SelectedItemChanged != null) && !preventselection) SelectedItemChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
// This validates an item
|
2015-03-22 20:43:05 +00:00
|
|
|
private bool ValidateItem(ImageBrowserItem item, ImageBrowserItem previtem)
|
2009-04-19 18:07:22 +00:00
|
|
|
{
|
2014-12-03 09:06:05 +00:00
|
|
|
//mxd. Don't show duplicate items
|
2015-03-22 20:43:05 +00:00
|
|
|
if(previtem != null && item.TextureName == previtem.TextureName && item.Group == previtem.Group) return false; //mxd
|
2014-12-03 09:06:05 +00:00
|
|
|
|
2014-01-24 08:09:57 +00:00
|
|
|
//mxd. mixMode: 0 = All, 1 = Textures, 2 = Flats, 3 = Based on BrowseFlats
|
2014-12-03 09:06:05 +00:00
|
|
|
if(!splitter.Panel2Collapsed)
|
|
|
|
{
|
2015-03-22 20:43:05 +00:00
|
|
|
if(mixMode == 1 && item.Icon.IsFlat) return false;
|
|
|
|
if(mixMode == 2 && !item.Icon.IsFlat) return false;
|
|
|
|
if(mixMode == 3 && (browseFlats != item.Icon.IsFlat)) return false;
|
2015-12-07 21:57:59 +00:00
|
|
|
if(!showtexturesfromsubdirs && item.Icon.Level > currentlevel) return false;
|
2013-03-26 12:31:07 +00:00
|
|
|
}
|
|
|
|
|
2015-03-22 20:43:05 +00:00
|
|
|
return item.Text.ToUpperInvariant().Contains(objectname.Text.ToUpperInvariant());
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
2013-09-26 12:43:39 +00:00
|
|
|
|
|
|
|
//mxd. This validates an item's texture size
|
2014-05-19 13:33:38 +00:00
|
|
|
private static bool ValidateItemSize(ImageBrowserItem i, int w, int h)
|
|
|
|
{
|
2015-12-28 15:01:53 +00:00
|
|
|
if(!i.Icon.IsPreviewLoaded) return true;
|
|
|
|
if(w > 0 && i.Icon.Width != w) return false;
|
|
|
|
if(h > 0 && i.Icon.Height != h) return false;
|
2013-09-26 12:43:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
2009-04-19 18:07:22 +00:00
|
|
|
|
|
|
|
// This sends the focus to the textbox
|
|
|
|
public void FocusTextbox()
|
|
|
|
{
|
2016-02-10 23:40:02 +00:00
|
|
|
if(General.Settings.KeepTextureFilterFocused) //mxd
|
|
|
|
objectname.Focus();
|
|
|
|
else
|
|
|
|
list.Focus();
|
2009-04-19 18:07:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|