Merge commit 'eb020611b18223e163e5198ef270d66c6ef0a3fb' into mac-ui

This commit is contained in:
Justin Aquadro 2012-11-10 14:37:13 -05:00
commit e1259d6880
4 changed files with 75 additions and 23 deletions

View file

@ -194,6 +194,7 @@
<Compile Include="Vendor\Be.Windows.Forms.HexBox\Util.cs" />
<Compile Include="Windows\FormHandlers.cs" />
<Compile Include="Windows\NbtClipboardControllerWin.cs" />
<Compile Include="Windows\SearchStateWin.cs" />
<EmbeddedResource Include="Windows\CancelSearchForm.resx">
<DependentUpon>CancelSearchForm.cs</DependentUpon>
</EmbeddedResource>

View file

@ -1,35 +1,32 @@
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using NBTExplorer.Model;
namespace NBTExplorer
{
internal class SearchState
internal interface ISearchState
{
public DataNode RootNode { get; set; }
public string SearchName { get; set; }
public string SearchValue { get; set; }
DataNode RootNode { get; set; }
string SearchName { get; set; }
string SearchValue { get; set; }
public IEnumerator<DataNode> State { get; set; }
IEnumerator<DataNode> State { get; set; }
public Action<DataNode> DiscoverCallback { get; set; }
public Action<DataNode> ProgressCallback { get; set; }
public Action<DataNode> CollapseCallback { get; set; }
public Action<DataNode> EndCallback { get; set; }
void InvokeDiscoverCallback (DataNode node);
void InvokeProgressCallback (DataNode node);
void InvokeCollapseCallback (DataNode node);
void InvokeEndCallback (DataNode node);
}
internal class SearchWorker
{
private ContainerControl _sender;
private SearchState _state;
private ISearchState _state;
private bool _cancel;
private object _lock;
public SearchWorker (SearchState state, ContainerControl sender)
public SearchWorker (ISearchState state)
{
_state = state;
_sender = sender;
_lock = new object();
}
@ -102,20 +99,17 @@ namespace NBTExplorer
private void InvokeDiscoverCallback (DataNode node)
{
if (_sender != null && _state.DiscoverCallback != null)
_sender.BeginInvoke(_state.DiscoverCallback, new object[] { node });
_state.InvokeDiscoverCallback(node);
}
private void InvokeCollapseCallback (DataNode node)
{
if (_sender != null && _state.CollapseCallback != null)
_sender.BeginInvoke(_state.CollapseCallback, new object[] { node });
_state.InvokeCollapseCallback(node);
}
private void InvokeEndCallback ()
{
if (_sender != null && _state.EndCallback != null)
_sender.BeginInvoke(_state.EndCallback, new object[] { null });
_state.InvokeEndCallback(null);
}
}
}

View file

@ -470,7 +470,7 @@ namespace NBTExplorer.Windows
}
private CancelSearchForm _searchForm;
private SearchState _searchState;
private SearchStateWin _searchState;
private void SearchNode (TreeNode node)
{
@ -485,7 +485,7 @@ namespace NBTExplorer.Windows
if (form.ShowDialog() != DialogResult.OK)
return;
_searchState = new SearchState() {
_searchState = new SearchStateWin(this) {
RootNode = dataNode,
SearchName = form.NameToken,
SearchValue = form.ValueToken,
@ -502,7 +502,7 @@ namespace NBTExplorer.Windows
if (_searchState == null)
return;
SearchWorker worker = new SearchWorker(_searchState, this);
SearchWorker worker = new SearchWorker(_searchState);
Thread t = new Thread(new ThreadStart(worker.Run));
t.IsBackground = true;

57
Windows/SearchStateWin.cs Normal file
View file

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Text;
using NBTExplorer.Model;
using System.Windows.Forms;
namespace NBTExplorer.Windows
{
internal class SearchStateWin : ISearchState
{
private ContainerControl _sender;
public SearchStateWin (ContainerControl sender)
{
_sender = sender;
}
public Action<DataNode> DiscoverCallback { get; set; }
public Action<DataNode> ProgressCallback { get; set; }
public Action<DataNode> CollapseCallback { get; set; }
public Action<DataNode> EndCallback { get; set; }
#region ISearchState
public DataNode RootNode { get; set; }
public string SearchName { get; set; }
public string SearchValue { get; set; }
public IEnumerator<DataNode> State { get; set; }
public void InvokeDiscoverCallback (DataNode node)
{
if (_sender != null && DiscoverCallback != null)
_sender.BeginInvoke(DiscoverCallback, new object[] { node });
}
public void InvokeProgressCallback (DataNode node)
{
if (_sender != null && ProgressCallback != null)
_sender.BeginInvoke(ProgressCallback, new object[] { node });
}
public void InvokeCollapseCallback (DataNode node)
{
if (_sender != null && CollapseCallback != null)
_sender.BeginInvoke(CollapseCallback, new object[] { node });
}
public void InvokeEndCallback (DataNode node)
{
if (_sender != null && EndCallback != null)
_sender.BeginInvoke(EndCallback, new object[] { node });
}
#endregion
}
}