Skip to content

Commit

Permalink
Adjustments to Find/Find Next basic search system.
Browse files Browse the repository at this point in the history
  • Loading branch information
CheeseJedi committed Feb 4, 2018
1 parent 0a62d37 commit 395a3a1
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 72 deletions.
2 changes: 1 addition & 1 deletion HELLION.DataStructures/HEDocumentWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ private void InitialiseListView(ListView passedListView, ImageList passedImageLi
passedListView.Columns.Add("Type", 120, HorizontalAlignment.Left);
passedListView.Columns.Add("Count", 50, HorizontalAlignment.Left);
passedListView.Columns.Add("TotalCount", 60, HorizontalAlignment.Left);
passedListView.Columns.Add("SemiMajorAxis", 80, HorizontalAlignment.Left);
passedListView.Columns.Add("FullPath", 120, HorizontalAlignment.Left);
passedListView.Columns.Add("GUID", 50, HorizontalAlignment.Right);
passedListView.Columns.Add("SceneID", 30, HorizontalAlignment.Right);
}
Expand Down
66 changes: 62 additions & 4 deletions HELLION.DataStructures/HESearchHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,18 @@ public class HESearchOperator
public HESearchOperator(HESearchHandler passedParent)
{
parent = passedParent ?? throw new NullReferenceException("passedParent was null.");
rootNode = new HESearchHandlerTreeNode(this, "SEARCHRESULTFIND", HETreeNodeType.SearchResultsSet, "Search Results");
rootNode = new HESearchHandlerTreeNode(this, "SEARCHOPERATORRESULTS", HETreeNodeType.SearchResultsSet, baseDisplayName);
parent.rootNode.Nodes.Add(rootNode);
parent.searchOperators.Add(this);
}

/// <summary>
/// Defines the base display name of an object, to which additional info will
/// be appended to once the operator has been executed to generate the new
/// display name (the node's .Text field).
/// </summary>
protected string baseDisplayName = "Search Results";

/// <summary>
/// Public property for the root node of the Search Handler tree.
/// </summary>
Expand Down Expand Up @@ -143,6 +150,26 @@ public List<HETreeNode> Results
/// </summary>
protected List<HETreeNode> results = null;

/// <summary>
/// Determines whether the results set has members.
/// </summary>
/// <returns></returns>
public bool HasResults()
{
if (results == null || results.Count() < 1 ) return false;
else return true;
}

protected virtual string GenerateResultSetDisplayName()
{
string postfix = "";
if (query != null)
{
postfix = " " + query + " (" + results.Count().ToString() + ")";
}
return baseDisplayName + postfix;
}

/// <summary>
/// Public property to access the Query.
/// </summary>
Expand Down Expand Up @@ -172,6 +199,10 @@ public HETreeNode StartingNode

protected HETreeNode startingNode = null;

/// <summary>
/// Executes the query.
/// </summary>
/// <returns>Returns true if the result set has more than zero members.</returns>
public bool Execute()
{
if (query == null) return false;
Expand All @@ -182,8 +213,8 @@ public bool Execute()
|| f.Text.Contains(query, StringComparison.OrdinalIgnoreCase)
|| f.NodeType.ToString().Contains(query, StringComparison.OrdinalIgnoreCase))
.ToList<HETreeNode>();

return true;
rootNode.Text = GenerateResultSetDisplayName();
return results.Count() > 0 ? true : false;
}
}
}
Expand All @@ -192,8 +223,35 @@ public class HEFindOperator : HESearchOperator
{
public HEFindOperator(HESearchHandler passedParent) : base(passedParent)
{
rootNode.NodeType = HETreeNodeType.SearchResultsSet;
rootNode.Name = "FINDOPERATORRESULTS";
rootNode.Text = "Find Results";

// Will need to set itself to undeletable.
}
}

/// <summary>
/// Defines the base display name of an object, to which additional info will
/// be appended to once the operator has been executed to generate the new
/// display name (the node's .Text field).
/// </summary>
protected new string baseDisplayName = "Find: ";

protected override string GenerateResultSetDisplayName()

{
string postfix = "";
if (query != null)
{
postfix = " '" + query + "' (" + results.Count().ToString() + ")";
}
return baseDisplayName + postfix;
}





}
}
}
4 changes: 2 additions & 2 deletions HELLION.DataStructures/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.0.5.88")]
[assembly: AssemblyFileVersion("0.0.5.88")]
[assembly: AssemblyVersion("0.0.5.101")]
[assembly: AssemblyFileVersion("0.0.5.101")]
3 changes: 1 addition & 2 deletions HELLION.DataStructures/TreeNodes/HEGameDataTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ public HETreeNode BuildHETreeNodeTreeFromJson(
/// <param name="obj">Takes a JObject and attempts to generate a name from expected fields</param>
/// <returns></returns>
public string GenerateDisplayName(JObject obj)

{
StringBuilder sb = new StringBuilder();
sb.Append(((string)obj["Registration"] + " " + (string)obj["Name"]).Trim());
Expand All @@ -585,7 +584,7 @@ public string GenerateDisplayName(JObject obj)
sb.Append((string)obj["GroupName"]);
if (sb.Length > 0) sb.Append(" ");
sb.Append((string)obj["ItemID"]);
return sb.ToString();
return sb.ToString().Trim();
}

}
Expand Down
9 changes: 8 additions & 1 deletion HELLION.DataStructures/TreeNodes/HETreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,14 @@ public HETreeNode GetFirstChildNodeByName(string key)
}



public string Path()
{
string fullPath = FullPath;
int lastIndex = fullPath.LastIndexOf(TreeView.PathSeparator);
// Ensure the lastIndex is not -1
lastIndex = lastIndex != -1 ? lastIndex : 0;
return fullPath.Substring(0, lastIndex);
}


/// <summary>
Expand Down
89 changes: 34 additions & 55 deletions HELLION.Explorer/HELLION.Explorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Windows.Forms;
using System.Text;
using System.Drawing;
using System.Reflection;
using System.Diagnostics;
using System.Data;
using System.IO;
Expand Down Expand Up @@ -239,6 +238,10 @@ internal static void FileOpen(string sFileName = "")

// DO SOME OTHER STUFF HERE?

// Enable the Edit menu and the Find option, leaving the FindNext disabled
// frmMainForm.editToolStripMenuItem.Enabled = true;
frmMainForm.findToolStripMenuItem.Enabled = true;
frmMainForm.findNextToolStripMenuItem.Enabled = false;

// Begin repainting the TreeView.
frmMainForm.treeView1.EndUpdate();
Expand Down Expand Up @@ -285,6 +288,14 @@ internal static void FileClose()
}
}


// Enable the Find option, leaving the FindNext disabled
// frmMainForm.editToolStripMenuItem.Enabled = false;
frmMainForm.findToolStripMenuItem.Enabled = false;
frmMainForm.findNextToolStripMenuItem.Enabled = false;



// Clear any existing nodes from the tree view
frmMainForm.treeView1.Nodes.Clear();

Expand Down Expand Up @@ -345,14 +356,18 @@ internal static void EditFind()
docCurrent.SearchHandler.FindOperator.StartingNode = findStartingNode;

// Execute the query, which updates the results list.
docCurrent.SearchHandler.FindOperator.Execute();

// Get a reference to the Results list enumerator.
findEnumerator = docCurrent.SearchHandler.FindOperator.Results.GetEnumerator();

if (docCurrent.SearchHandler.FindOperator.Results.Count > 0) EditFindNext();
else MessageBox.Show("No results for search term " + findSearchKey);
if (docCurrent.SearchHandler.FindOperator.Execute())
{
// Get a reference to the Results list enumerator.
findEnumerator = docCurrent.SearchHandler.FindOperator.Results.GetEnumerator();

frmMainForm.findNextToolStripMenuItem.Enabled = true;
EditFindNext();
}
else
{
MessageBox.Show("No results for search term " + findSearchKey);
}
}

/// <summary>
Expand All @@ -363,26 +378,7 @@ internal static void EditFind()
internal static void EditFindNext()
{
// Most of this code needs to be migrated to the FindHandler
/*
StringBuilder sb = new StringBuilder();
sb.Append("Find Next activated:" + Environment.NewLine);
sb.Append("Search term: " + findSearchKey + Environment.NewLine);
sb.Append("Starting Node: " + findStartingNode.Text + "(" + findStartingNode.Name + ")" + Environment.NewLine);
sb.Append("FindOperator.Results.Count = " + docCurrent.SearchHandler.FindOperator.Results.Count + Environment.NewLine);
sb.Append("treeView1.SelectedNode = ");
if (frmMainForm.treeView1.SelectedNode != null)
{
sb.Append(frmMainForm.treeView1.SelectedNode.Text + "(" + frmMainForm.treeView1.SelectedNode.Name + ")" + Environment.NewLine);
}
else
{
sb.Append("null (no node is currently selected)");
}
sb.Append(Environment.NewLine);
MessageBox.Show(sb.ToString());
*/
if (docCurrent.SearchHandler.FindOperator.Results.Count > 0)
if (docCurrent.SearchHandler.FindOperator.Results.Count > 0 )
{
if (findEnumerator.MoveNext())
{
Expand All @@ -400,8 +396,6 @@ internal static void EditFindNext()
}
}



/// <summary>
/// Generates the About dialog text, to be returned to the user by the program in a
/// MessageBox.
Expand Down Expand Up @@ -757,7 +751,7 @@ internal static void RefreshListView(TreeNode nSelectedNode)
arr[1] = listItem.NodeType.ToString();
arr[2] = listItem.CountOfChildNodes.ToString();
arr[3] = listItem.CountOfAllChildNodes.ToString();
arr[4] = ""; // listItem.OrbitData.SemiMajorAxis.ToString();
arr[4] = listItem.Path();
arr[5] = ""; // listItem.GUID.ToString();
arr[6] = ""; // nodeChild.SceneID.ToString();

Expand All @@ -767,16 +761,8 @@ internal static void RefreshListView(TreeNode nSelectedNode)
Text = listItem.Text,
Tag = listItem
};
/*
if ((nodeChild.OrbitData.ParentGUID == -1) && (nodeChild.NodeType == HETreeNodeType.CelestialBody))
{
// It's the star, a special case
liNewItem.ImageIndex = (int)HEObjectTypesImageList.ButtonIcon_16x;
}
else */
{
liNewItem.ImageIndex = HEImageList.GetImageIndexByNodeType(listItem.NodeType);
}

liNewItem.ImageIndex = HEImageList.GetImageIndexByNodeType(listItem.NodeType);

// Add the item
frmMainForm.listView1.Items.Add(liNewItem);
Expand All @@ -792,7 +778,7 @@ internal static void RefreshListView(TreeNode nSelectedNode)
arr[1] = nodeChild.NodeType.ToString();
arr[2] = nodeChild.CountOfChildNodes.ToString();
arr[3] = nodeChild.CountOfAllChildNodes.ToString();
arr[4] = ""; // nodeChild.OrbitData.SemiMajorAxis.ToString();
arr[4] = nodeChild.Path();
arr[5] = ""; // nodeChild.GUID.ToString();
arr[6] = ""; // nodeChild.SceneID.ToString();

Expand All @@ -802,16 +788,8 @@ internal static void RefreshListView(TreeNode nSelectedNode)
Text = nodeChild.Text,
Tag = nodeChild
};
/*
if ((nodeChild.OrbitData.ParentGUID == -1) && (nodeChild.NodeType == HETreeNodeType.CelestialBody))
{
// It's the star, a special case
liNewItem.ImageIndex = (int)HEObjectTypesImageList.ButtonIcon_16x;
}
else */
{
liNewItem.ImageIndex = HEImageList.GetImageIndexByNodeType(nodeChild.NodeType);
}

liNewItem.ImageIndex = HEImageList.GetImageIndexByNodeType(nodeChild.NodeType);

// Add the item
frmMainForm.listView1.Items.Add(liNewItem);
Expand Down Expand Up @@ -887,8 +865,8 @@ internal static void RefreshSelectedObjectSummaryText(TreeNode nSelectedNode)
}
}
else throw new InvalidOperationException("tempNodes array length not greater than zero.");
*/
sb1.Append(Environment.NewLine);
sb1.Append("DockedPortID: " + nSelectedOrbitalObjNode.DockedPortID.ToString());
sb1.Append(Environment.NewLine);
sb1.Append("DockedToPortID: " + nSelectedOrbitalObjNode.DockedToPortID.ToString());
Expand All @@ -897,7 +875,7 @@ internal static void RefreshSelectedObjectSummaryText(TreeNode nSelectedNode)
sb1.Append("ORBITAL DATA");
sb1.Append(Environment.NewLine);
sb1.Append("ParentGUID: " + nSelectedOrbitalObjNode.OrbitData.ParentGUID.ToString());
/*
tempNodes = null;
tempNode = null;
tempNodes = docCurrent.SolarSystem.RootNode.Nodes.Find(nSelectedOrbitalObjNode.OrbitData.ParentGUID.ToString(), searchAllChildren: true);
Expand All @@ -906,8 +884,9 @@ internal static void RefreshSelectedObjectSummaryText(TreeNode nSelectedNode)
{
sb1.Append(" (" + tempNode.Text + ")");
}
sb1.Append(Environment.NewLine);
*/
sb1.Append(Environment.NewLine);


sb1.Append("SemiMajorAxis: " + nSelectedOrbitalObjNode.OrbitData.SemiMajorAxis.ToString());
sb1.Append(Environment.NewLine);
Expand Down
11 changes: 7 additions & 4 deletions HELLION.Explorer/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 395a3a1

Please sign in to comment.