Texture and Flats browsers now have the current texture selected by default

This commit is contained in:
codeimp 2009-03-01 16:47:43 +00:00
parent 67f4237bc0
commit 6ba030d64d
3 changed files with 195 additions and 50 deletions

View file

@ -220,25 +220,46 @@ namespace CodeImp.DoomBuilder.Controls
#region ================== Methods
// This selects an item by name
public void SelectItem(string name)
public void SelectItem(string name, ListViewGroup preferredgroup)
{
ListViewItem lvi;
ListViewItem lvi = null;
// Not when selecting is prevented
if(preventselection) return;
// Find item with this text
lvi = list.FindItemWithText(name);
// 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;
}
}
}
// Select the item
if(lvi != null)
{
// Does the text really match?
if(lvi.Text == name)
{
// Select this item
list.SelectedItems.Clear();
lvi.Selected = true;
lvi.EnsureVisible();
}
// Select this item
list.SelectedItems.Clear();
lvi.Selected = true;
lvi.EnsureVisible();
}
UpdateTextureSizeLabel();

View file

@ -22,6 +22,7 @@ using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodeImp.DoomBuilder.IO;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Actions;
@ -42,6 +43,7 @@ namespace CodeImp.DoomBuilder.Windows
private Size lastsize;
private ListViewGroup usedgroup;
private ListViewGroup availgroup;
private ListViewItem selectedset;
// Properties
public string SelectedName { get { return selectedname; } }
@ -77,11 +79,10 @@ 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) i.Selected = true;
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) selectedset = i;
// None selected? Then select the first
if(texturesets.SelectedItems.Count == 0)
texturesets.Items[0].Selected = true;
if(selectedset == null) selectedset = texturesets.Items[0];
// Make groups
usedgroup = browser.AddGroup("Used Textures");
@ -104,6 +105,51 @@ namespace CodeImp.DoomBuilder.Windows
this.ResumeLayout(true);
}
// This fills the lists and selects the given texture
public void Setup(string selectflat)
{
if(!string.IsNullOrEmpty(selectflat))
{
// We prefer selecting the texture using the Texture Set that was previously selected
if(texturesets.SelectedItems.Count > 0)
{
if(SelectFlatInSet(texturesets.SelectedItems[0], 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();
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()
{
@ -203,6 +249,7 @@ namespace CodeImp.DoomBuilder.Windows
public static string Browse(IWin32Window parent, string select)
{
FlatBrowserForm browser = new FlatBrowserForm();
browser.Setup(select);
if(browser.ShowDialog(parent) == DialogResult.OK)
{
// Return result
@ -221,22 +268,12 @@ namespace CodeImp.DoomBuilder.Windows
// Anything slected?
if(texturesets.SelectedItems.Count > 0)
{
// Get the selected texture set
IFilledTextureSet set = (texturesets.SelectedItems[0].Tag as IFilledTextureSet);
// Start adding
browser.BeginAdding(false);
// Add all used flats
foreach(ImageData img in set.Flats)
if(img.UsedInMap) browser.Add(img.Name, img, img, usedgroup);
// Add all available flats
foreach(ImageData img in set.Flats)
browser.Add(img.Name, img, img, availgroup);
// Done adding
browser.EndAdding();
// Not the same?
if(texturesets.SelectedItems[0] != selectedset)
{
selectedset = texturesets.SelectedItems[0];
FillImagesList(null);
}
}
}
@ -245,5 +282,30 @@ namespace CodeImp.DoomBuilder.Windows
{
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
}
// This fills the list of textures, depending on the selected texture set
private void FillImagesList(string selectflat)
{
// Get the selected texture set
IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);
// Start adding
browser.BeginAdding(false);
// Add all used flats
foreach(ImageData img in set.Flats)
if(img.UsedInMap) browser.Add(img.Name, img, img, usedgroup);
// Add all available flats
foreach(ImageData img in set.Flats)
browser.Add(img.Name, img, img, availgroup);
// Done adding
browser.EndAdding();
// Select texture
if(!string.IsNullOrEmpty(selectflat))
browser.SelectItem(selectflat, usedgroup);
}
}
}

View file

@ -22,6 +22,7 @@ using System.ComponentModel;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CodeImp.DoomBuilder.IO;
using Microsoft.Win32;
using System.Diagnostics;
using CodeImp.DoomBuilder.Actions;
@ -42,6 +43,7 @@ namespace CodeImp.DoomBuilder.Windows
private Size lastsize;
private ListViewGroup usedgroup;
private ListViewGroup availgroup;
private ListViewItem selectedset;
// Properties
public string SelectedName { get { return selectedname; } }
@ -77,11 +79,10 @@ 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) i.Selected = true;
foreach(ListViewItem i in texturesets.Items) if(i.Text == selectname) selectedset = i;
// None selected? Then select the first
if(texturesets.SelectedItems.Count == 0)
texturesets.Items[0].Selected = true;
if(selectedset == null) selectedset = texturesets.Items[0];
// Make groups
usedgroup = browser.AddGroup("Used Textures");
@ -104,6 +105,51 @@ namespace CodeImp.DoomBuilder.Windows
this.ResumeLayout(true);
}
// This fills the lists and selects the given texture
public void Setup(string selecttexture)
{
if(!string.IsNullOrEmpty(selecttexture))
{
// We prefer selecting the texture using the Texture Set that was previously selected
if(texturesets.SelectedItems.Count > 0)
{
if(SelectTextureInSet(texturesets.SelectedItems[0], 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();
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()
{
@ -203,6 +249,7 @@ namespace CodeImp.DoomBuilder.Windows
public static string Browse(IWin32Window parent, string select)
{
TextureBrowserForm browser = new TextureBrowserForm();
browser.Setup(select);
if(browser.ShowDialog(parent) == DialogResult.OK)
{
// Return result
@ -221,22 +268,12 @@ namespace CodeImp.DoomBuilder.Windows
// Anything slected?
if(texturesets.SelectedItems.Count > 0)
{
// Get the selected texture set
IFilledTextureSet set = (texturesets.SelectedItems[0].Tag as IFilledTextureSet);
// Start adding
browser.BeginAdding(false);
// Add all available textures and mark the images for temporary loading
foreach(ImageData img in set.Textures)
browser.Add(img.Name, img, img, availgroup);
// Add all used textures and mark the images for permanent loading
foreach(ImageData img in set.Textures)
if(img.UsedInMap) browser.Add(img.Name, img, img, usedgroup);
// Done adding
browser.EndAdding();
// Not the same?
if(texturesets.SelectedItems[0] != selectedset)
{
selectedset = texturesets.SelectedItems[0];
FillImagesList(null);
}
}
}
@ -245,5 +282,30 @@ namespace CodeImp.DoomBuilder.Windows
{
if(apply.Enabled) apply_Click(this, EventArgs.Empty);
}
// This fills the list of textures, depending on the selected texture set
private void FillImagesList(string selecttexture)
{
// Get the selected texture set
IFilledTextureSet set = (selectedset.Tag as IFilledTextureSet);
// Start adding
browser.BeginAdding(false);
// Add all available textures and mark the images for temporary loading
foreach(ImageData img in set.Textures)
browser.Add(img.Name, img, img, availgroup);
// Add all used textures and mark the images for permanent loading
foreach(ImageData img in set.Textures)
if(img.UsedInMap) browser.Add(img.Name, img, img, usedgroup);
// Done adding
browser.EndAdding();
// Select texture
if(!string.IsNullOrEmpty(selecttexture))
browser.SelectItem(selecttexture, usedgroup);
}
}
}