Skip to content

Commit

Permalink
[nodelist] add treelist ui and base logic
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinZonda committed Jun 19, 2020
1 parent 11f74a1 commit d655083
Show file tree
Hide file tree
Showing 11 changed files with 301 additions and 190 deletions.
6 changes: 3 additions & 3 deletions NaiveSharp/App.config
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
</startup>
</configuration>
</configuration>
2 changes: 1 addition & 1 deletion NaiveSharp/Controller/Extension/Dictionary.cs
Expand Up @@ -2,7 +2,7 @@

namespace NaiveSharp.Controller.Extension
{
public static class Dictionary
public static class DictionaryEx
{
public static bool HasKey<K, V>(this Dictionary<K, V> dic, K value)
=> dic.ContainsKey(value);
Expand Down
2 changes: 1 addition & 1 deletion NaiveSharp/Controller/Extension/String.cs
Expand Up @@ -2,7 +2,7 @@

namespace NaiveSharp.Controller.Extension
{
public static class String
public static class StringEx
{
public static string ToBase64(this string str)
=> ConvertToBase64(str, false);
Expand Down
6 changes: 3 additions & 3 deletions NaiveSharp/Controller/Extension/String[].cs
Expand Up @@ -2,11 +2,11 @@

namespace NaiveSharp.Controller.Extension
{
public static class StringArray
public static class StringArrayEx
{
public static string[] Trim(this string[] ss)
{
for (int i = 0; i < ss.Length; --i)
for (int i = 0; i < ss.Length; ++i)
{
ss[i] = ss[i].Trim();
}
Expand All @@ -22,7 +22,7 @@ public static string[] Trim(this string[] ss, bool removeNullOrWhiteSpace)
else
{
var x = new List<string>();
for (int i = 0; i < ss.Length; --i)
for (int i = 0; i < ss.Length; ++i)
{
if (string.IsNullOrWhiteSpace(ss[i]))
{
Expand Down
25 changes: 25 additions & 0 deletions NaiveSharp/Controller/Extension/TreeNodeCollection.cs
@@ -0,0 +1,25 @@
using System.Linq;
using System.Windows.Forms;

namespace NaiveSharp.Controller.Extension
{
public static class TreeNodeCollectionEx
{
public static bool ContainsText(this TreeNodeCollection tnc, string text)
{
/*
=> tnc.Cast<TreeNode>()
.Where(tn => tn.Text == text)
.Count() > 0;
*/
foreach (TreeNode tn in tnc)
{
if (tn.Text == text)
{
return true;
}
}
return false;
}
}
}
35 changes: 33 additions & 2 deletions NaiveSharp/Controller/NodeList.cs
@@ -1,13 +1,44 @@
using System.Collections.Generic;
using NaiveSharp.Controller.Extension;

using System;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Forms;

namespace NaiveSharp.Controller
{
public class NodeList
{
public static void LoadFromStringArray(string[] s)
public static void LoadFromStringArray(ref TreeView tv, string[] s)
{
tv.Nodes.Clear();
s = s.Trim(true);

string group = "default";

for (int i = 0; i < s.Length; ++i)
{
if (s[i].StartsEndsWith("[", "]"))
{
group = s[i].Substring(1, s[i].Length - 2);
if (!tv.Nodes.ContainsText(group))
{
tv.Nodes.Add(new TreeNode() { Name = group, Text = group });
}
}
else
{
if (i == 0)
{
tv.Nodes.Add(new TreeNode() { Name = group, Text = group });
}
tv.Nodes[group].Nodes.Add(new TreeNode()
{
Tag = s[i],
Text = new Uri(s[i]).Fragment.Substring(1)
});
}
}
}

public static string[] ToStringArray(TreeView tv)
Expand Down
3 changes: 3 additions & 0 deletions NaiveSharp/NaiveSharp.csproj
Expand Up @@ -30,6 +30,7 @@
<ApplicationVersion>0.5.0.%2a</ApplicationVersion>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down Expand Up @@ -84,6 +85,7 @@
<Compile Include="Controller\Extension\Dictionary.cs" />
<Compile Include="Controller\Extension\String.cs" />
<Compile Include="Controller\Extension\String[].cs" />
<Compile Include="Controller\Extension\TreeNodeCollection.cs" />
<Compile Include="Controller\IniHelper.cs" />
<Compile Include="Controller\NaiveCmdBuilder.cs" />
<Compile Include="Controller\Net.cs" />
Expand Down Expand Up @@ -120,6 +122,7 @@
<Compile Include="Properties\Resources.Designer.cs">
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
<DesignTime>True</DesignTime>
</Compile>
<EmbeddedResource Include="View\About.resx">
<DependentUpon>About.cs</DependentUpon>
Expand Down
68 changes: 30 additions & 38 deletions NaiveSharp/Properties/Resources.Designer.cs

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

22 changes: 9 additions & 13 deletions NaiveSharp/Properties/Settings.Designer.cs

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

0 comments on commit d655083

Please sign in to comment.