Fixed some bug that caused slow opening of the images browser with many (thousands) textures

This commit is contained in:
codeimp 2009-04-13 11:12:42 +00:00
parent e8d1ad19a8
commit 1f27979f43
5 changed files with 117 additions and 140 deletions

View file

@ -229,26 +229,13 @@ namespace CodeImp.DoomBuilder.Controls
// Search in preferred group first
if(preferredgroup != null)
{
foreach(ListViewItem item in list.Items)
{
if((item.Group == preferredgroup) && (string.Compare(item.Text, name, true) == 0))
{
lvi = item;
break;
}
}
}
// If nothing found yet, search all items
if(lvi == null)
{
foreach(ListViewItem item in list.Items)
{
if(string.Compare(item.Text, name, true) == 0)
{
lvi = item;
break;
if(item.Group == preferredgroup) break;
}
}
}

View file

@ -139,6 +139,7 @@ namespace CodeImp.DoomBuilder.Windows
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Browse Flats";
this.Load += new System.EventHandler(this.FlatBrowserForm_Load);
this.Shown += new System.EventHandler(this.FlatBrowserForm_Shown);
this.Activated += new System.EventHandler(this.FlatBrowserForm_Activated);
this.Move += new System.EventHandler(this.FlatBrowserForm_Move);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FlatBrowserForm_FormClosing);

View file

@ -47,15 +47,18 @@ namespace CodeImp.DoomBuilder.Windows
private ListViewGroup usedgroup;
private ListViewGroup availgroup;
private ListViewItem selectedset;
private string selecttextureonfill;
// Properties
public string SelectedName { get { return selectedname; } }
// Constructor
public FlatBrowserForm()
public FlatBrowserForm(string selecttexture)
{
Cursor.Current = Cursors.WaitCursor;
ListViewItem item;
bool foundselecttexture = false;
long longname = Lump.MakeLongName(selecttexture);
// Initialize
InitializeComponent();
@ -97,13 +100,50 @@ namespace CodeImp.DoomBuilder.Windows
item.SubItems.Add(ts.Textures.Count.ToString(), item.ForeColor,
item.BackColor, new Font(item.Font, FontStyle.Regular));
}
// Select the last one that was selected
string selectname = General.Settings.ReadSetting("browserwindow.textureset", "");
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) selectedset = i;
foreach(ListViewItem i in texturesets.Items)
{
if(i.Text == selectname)
{
i.Selected = true;
IFilledTextureSet set = (i.Tag as IFilledTextureSet);
foreach(ImageData img in set.Textures)
{
if(img.LongName == longname)
{
i.Selected = true;
foundselecttexture = true;
break;
}
}
break;
}
}
// If the selected texture was not found in the last-selected set, try finding it in the other sets
if(!foundselecttexture)
{
foreach(ListViewItem i in texturesets.Items)
{
IFilledTextureSet set = (i.Tag as IFilledTextureSet);
foreach(ImageData img in set.Textures)
{
if(img.LongName == longname)
{
i.Selected = true;
break;
}
}
}
}
// None selected? Then select the first
if(selectedset == null) selectedset = texturesets.Items[0];
if(texturesets.SelectedItems.Count == 0)
texturesets.Items[0].Selected = true;
selecttextureonfill = selecttexture;
// Make groups
usedgroup = browser.AddGroup("Used Textures");
@ -125,53 +165,6 @@ namespace CodeImp.DoomBuilder.Windows
if(this.WindowState == FormWindowState.Normal) this.StartPosition = FormStartPosition.CenterParent;
this.ResumeLayout(true);
}
// This fills the lists and selects the given texture
public void Setup(string selectflat)
{
bool fillrequired = (texturesets.SelectedItems.Count == 0) || (selectedset == texturesets.SelectedItems[0]);
if(!string.IsNullOrEmpty(selectflat))
{
// We prefer selecting the texture using the Texture Set that was previously selected
if(selectedset != null)
{
if(SelectFlatInSet(selectedset, selectflat)) return;
}
// Otherwise, go from top to bottom to find the texture
foreach(ListViewItem i in texturesets.Items)
{
if(SelectFlatInSet(i, selectflat)) return;
}
}
// Select texture set and fill list
selectedset.Selected = true;
selectedset.EnsureVisible();
if(fillrequired) FillImagesList(selectflat);
}
// This selects a Texture Set and the texture if it can be found
private bool SelectFlatInSet(ListViewItem setitem, string selectflat)
{
long longname = Lump.MakeLongName(selectflat);
IFilledTextureSet set = (setitem.Tag as IFilledTextureSet);
foreach(ImageData img in set.Textures)
{
if(img.LongName == longname)
{
// Texture found in this set! Select it now.
selectedset = setitem;
selectedset.Selected = true;
selectedset.EnsureVisible();
FillImagesList(selectflat);
return true;
}
}
return false;
}
// Selection changed
private void browser_SelectedItemChanged()
@ -279,8 +272,7 @@ namespace CodeImp.DoomBuilder.Windows
// Returns null when cancelled.
public static string Browse(IWin32Window parent, string select)
{
FlatBrowserForm browser = new FlatBrowserForm();
browser.Setup(select);
FlatBrowserForm browser = new FlatBrowserForm(select);
if(browser.ShowDialog(parent) == DialogResult.OK)
{
// Return result
@ -299,12 +291,8 @@ namespace CodeImp.DoomBuilder.Windows
// Anything slected?
if(texturesets.SelectedItems.Count > 0)
{
// Not the same?
if(texturesets.SelectedItems[0] != selectedset)
{
selectedset = texturesets.SelectedItems[0];
FillImagesList(null);
}
selectedset = texturesets.SelectedItems[0];
FillImagesList(null);
}
}
@ -333,10 +321,6 @@ namespace CodeImp.DoomBuilder.Windows
// Done adding
browser.EndAdding();
// Select texture
if(!string.IsNullOrEmpty(selectflat))
browser.SelectItem(selectflat, usedgroup);
}
// Help requested
@ -345,5 +329,15 @@ namespace CodeImp.DoomBuilder.Windows
General.ShowHelp("w_imagesbrowser.html");
hlpevent.Handled = true;
}
private void FlatBrowserForm_Shown(object sender, EventArgs e)
{
// Select texture
if(!string.IsNullOrEmpty(selecttextureonfill))
{
browser.SelectItem(selecttextureonfill, usedgroup);
selecttextureonfill = null;
}
}
}
}

View file

@ -139,6 +139,7 @@ namespace CodeImp.DoomBuilder.Windows
this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
this.Text = "Browse Textures";
this.Load += new System.EventHandler(this.TextureBrowserForm_Load);
this.Shown += new System.EventHandler(this.TextureBrowserForm_Shown);
this.Activated += new System.EventHandler(this.TextureBrowserForm_Activated);
this.Move += new System.EventHandler(this.TextureBrowserForm_Move);
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TextureBrowserForm_FormClosing);

View file

@ -47,15 +47,18 @@ namespace CodeImp.DoomBuilder.Windows
private ListViewGroup usedgroup;
private ListViewGroup availgroup;
private ListViewItem selectedset;
private string selecttextureonfill;
// Properties
public string SelectedName { get { return selectedname; } }
// Constructor
public TextureBrowserForm()
public TextureBrowserForm(string selecttexture)
{
Cursor.Current = Cursors.WaitCursor;
ListViewItem item;
bool foundselecttexture = false;
long longname = Lump.MakeLongName(selecttexture);
// Initialize
InitializeComponent();
@ -100,11 +103,48 @@ namespace CodeImp.DoomBuilder.Windows
// Select the last one that was selected
string selectname = General.Settings.ReadSetting("browserwindow.textureset", "");
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) selectedset = i;
foreach(ListViewItem i in texturesets.Items)
{
if(i.Text == selectname)
{
i.Selected = true;
IFilledTextureSet set = (i.Tag as IFilledTextureSet);
foreach(ImageData img in set.Textures)
{
if(img.LongName == longname)
{
i.Selected = true;
foundselecttexture = true;
break;
}
}
break;
}
}
// If the selected texture was not found in the last-selected set, try finding it in the other sets
if(!foundselecttexture)
{
foreach(ListViewItem i in texturesets.Items)
{
IFilledTextureSet set = (i.Tag as IFilledTextureSet);
foreach(ImageData img in set.Textures)
{
if(img.LongName == longname)
{
i.Selected = true;
break;
}
}
}
}
// None selected? Then select the first
if(selectedset == null) selectedset = texturesets.Items[0];
if(texturesets.SelectedItems.Count == 0)
texturesets.Items[0].Selected = true;
selecttextureonfill = selecttexture;
// Make groups
usedgroup = browser.AddGroup("Used Textures");
availgroup = browser.AddGroup("Available Textures");
@ -126,53 +166,6 @@ namespace CodeImp.DoomBuilder.Windows
this.ResumeLayout(true);
}
// This fills the lists and selects the given texture
public void Setup(string selecttexture)
{
bool fillrequired = (texturesets.SelectedItems.Count == 0) || (selectedset == texturesets.SelectedItems[0]);
if(!string.IsNullOrEmpty(selecttexture))
{
// We prefer selecting the texture using the Texture Set that was previously selected
if(selectedset != null)
{
if(SelectTextureInSet(selectedset, selecttexture)) return;
}
// Otherwise, go from top to bottom to find the texture
foreach(ListViewItem i in texturesets.Items)
{
if(SelectTextureInSet(i, selecttexture)) return;
}
}
// Select texture set and fill list
selectedset.Selected = true;
selectedset.EnsureVisible();
if(fillrequired) FillImagesList(selecttexture);
}
// This selects a Texture Set and the texture if it can be found
private bool SelectTextureInSet(ListViewItem setitem, string selecttexture)
{
long longname = Lump.MakeLongName(selecttexture);
IFilledTextureSet set = (setitem.Tag as IFilledTextureSet);
foreach(ImageData img in set.Textures)
{
if(img.LongName == longname)
{
// Texture found in this set! Select it now.
selectedset = setitem;
selectedset.Selected = true;
selectedset.EnsureVisible();
FillImagesList(selecttexture);
return true;
}
}
return false;
}
// Selection changed
private void browser_SelectedItemChanged()
{
@ -279,8 +272,7 @@ namespace CodeImp.DoomBuilder.Windows
// Returns null when cancelled.
public static string Browse(IWin32Window parent, string select)
{
TextureBrowserForm browser = new TextureBrowserForm();
browser.Setup(select);
TextureBrowserForm browser = new TextureBrowserForm(select);
if(browser.ShowDialog(parent) == DialogResult.OK)
{
// Return result
@ -299,12 +291,8 @@ namespace CodeImp.DoomBuilder.Windows
// Anything slected?
if(texturesets.SelectedItems.Count > 0)
{
// Not the same?
if(texturesets.SelectedItems[0] != selectedset)
{
selectedset = texturesets.SelectedItems[0];
FillImagesList(null);
}
selectedset = texturesets.SelectedItems[0];
FillImagesList();
}
}
@ -315,7 +303,7 @@ namespace CodeImp.DoomBuilder.Windows
}
// This fills the list of textures, depending on the selected texture set
private void FillImagesList(string selecttexture)
private void FillImagesList()
{
// Get the selected texture set
IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);
@ -333,10 +321,6 @@ namespace CodeImp.DoomBuilder.Windows
// Done adding
browser.EndAdding();
// Select texture
if(!string.IsNullOrEmpty(selecttexture))
browser.SelectItem(selecttexture, usedgroup);
}
// Help
@ -345,5 +329,15 @@ namespace CodeImp.DoomBuilder.Windows
General.ShowHelp("w_imagesbrowser.html");
hlpevent.Handled = true;
}
private void TextureBrowserForm_Shown(object sender, EventArgs e)
{
// Select texture
if(!string.IsNullOrEmpty(selecttextureonfill))
{
browser.SelectItem(selecttextureonfill, usedgroup);
selecttextureonfill = null;
}
}
}
}