добавили expand save
This commit is contained in:
parent
599f82140a
commit
3b95cf4ff6
|
|
@ -46,8 +46,9 @@ namespace Reseter2
|
||||||
|
|
||||||
|
|
||||||
SGlobalSetting.LoadSetting();
|
SGlobalSetting.LoadSetting();
|
||||||
|
|
||||||
WordsList.MainCategory = SGlobalSetting.LoadWords();
|
WordsList.MainCategory = SGlobalSetting.LoadWords();
|
||||||
|
|
||||||
|
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
checkControl1.updateCheck += CheckControl1_updateCheck;
|
checkControl1.updateCheck += CheckControl1_updateCheck;
|
||||||
|
|
@ -57,9 +58,10 @@ namespace Reseter2
|
||||||
HistoryList.Update += Update_lb;
|
HistoryList.Update += Update_lb;
|
||||||
lb_history.DataSource = HistoryList.Hitem;
|
lb_history.DataSource = HistoryList.Hitem;
|
||||||
lb_history.DisplayMember = "ToStr";
|
lb_history.DisplayMember = "ToStr";
|
||||||
|
treeView1.PathSeparator = "/";
|
||||||
|
|
||||||
treeView1.Nodes.AddRange(WordsList.ListNodes());
|
treeView1.Nodes.AddRange(WordsList.ListNodes());
|
||||||
|
SGlobalSetting.settingExpand.ExpendAll(treeView1.Nodes);
|
||||||
//treeView1.SelectedNode.
|
//treeView1.SelectedNode.
|
||||||
//treeView1.MouseCaptureChanged.;
|
//treeView1.MouseCaptureChanged.;
|
||||||
tabControl1.SelectedIndex = 1;
|
tabControl1.SelectedIndex = 1;
|
||||||
|
|
@ -169,22 +171,8 @@ namespace Reseter2
|
||||||
|
|
||||||
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
||||||
{
|
{
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
SGlobalSetting.settingExpand.SaveExpand(treeView1.Nodes);
|
||||||
FileStream file = null;
|
SGlobalSetting.SaveSettig();
|
||||||
try
|
|
||||||
{
|
|
||||||
file = new FileStream("res.dat", FileMode.OpenOrCreate);
|
|
||||||
binaryFormatter.Serialize(file, HistoryList.Hitem);
|
|
||||||
file.Close();
|
|
||||||
file.Dispose();
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
file.Close();
|
|
||||||
file.Dispose();
|
|
||||||
MessageBox.Show("Ошибка записи конфигурационных файлов.\n Текущие данные будут потерянны.", "Критическая ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
|
private void treeView1_AfterCheck(object sender, TreeViewEventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -75,6 +75,7 @@
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="reseter.cs" />
|
<Compile Include="reseter.cs" />
|
||||||
<Compile Include="ReseteTask.cs" />
|
<Compile Include="ReseteTask.cs" />
|
||||||
|
<Compile Include="Setting\SettingExpand.cs" />
|
||||||
<Compile Include="Setting\SettingWords.cs" />
|
<Compile Include="Setting\SettingWords.cs" />
|
||||||
<Compile Include="Setting\SSetting.cs" />
|
<Compile Include="Setting\SSetting.cs" />
|
||||||
<Compile Include="Shutdown.cs" />
|
<Compile Include="Shutdown.cs" />
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Security.Policy;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
|
using static System.Net.WebRequestMethods;
|
||||||
|
|
||||||
namespace Reseter2.Setting
|
namespace Reseter2.Setting
|
||||||
{
|
{
|
||||||
|
|
@ -17,6 +18,7 @@ namespace Reseter2.Setting
|
||||||
{
|
{
|
||||||
|
|
||||||
public static SettingWords settingWords = new SettingWords();
|
public static SettingWords settingWords = new SettingWords();
|
||||||
|
public static SettingExpand settingExpand = new SettingExpand();
|
||||||
|
|
||||||
//public static void LoadSetting()
|
//public static void LoadSetting()
|
||||||
// {
|
// {
|
||||||
|
|
@ -31,12 +33,30 @@ namespace Reseter2.Setting
|
||||||
object output = Load("res.dat");
|
object output = Load("res.dat");
|
||||||
if (!(output is SSetting)) return;
|
if (!(output is SSetting)) return;
|
||||||
SSetting setting = (SSetting)output;
|
SSetting setting = (SSetting)output;
|
||||||
settingWords = setting .settingWords;
|
if (setting.settingWords != null) settingWords = setting.settingWords;
|
||||||
|
if (setting.settingExpand != null) settingExpand = setting.settingExpand;
|
||||||
HistoryList.Hitem = setting.historyItems;
|
HistoryList.Hitem = setting.historyItems;
|
||||||
|
|
||||||
// return output;
|
// return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static bool SaveSettig()
|
||||||
|
{
|
||||||
|
SSetting sSetting = new SSetting();
|
||||||
|
sSetting.settingWords = settingWords;
|
||||||
|
sSetting.historyItems = HistoryList.Hitem;
|
||||||
|
sSetting.settingExpand = settingExpand;
|
||||||
|
if(Save("res.dat", sSetting))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static WordsCategory LoadWords()
|
public static WordsCategory LoadWords()
|
||||||
{
|
{
|
||||||
WordsCategory output = (WordsCategory)Load(settingWords.PathBase);
|
WordsCategory output = (WordsCategory)Load(settingWords.PathBase);
|
||||||
|
|
@ -61,6 +81,11 @@ namespace Reseter2.Setting
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
if (file != null)
|
||||||
|
{
|
||||||
|
file.Close();
|
||||||
|
file.Dispose();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +155,7 @@ namespace Reseter2.Setting
|
||||||
Memory.Dispose();
|
Memory.Dispose();
|
||||||
file.Close();
|
file.Close();
|
||||||
file.Dispose();
|
file.Dispose();
|
||||||
return SaveCheck(output);
|
return SaveCheck(settingWords.PathBase, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
WordsList.MainCategory = output;
|
WordsList.MainCategory = output;
|
||||||
|
|
@ -149,7 +174,7 @@ namespace Reseter2.Setting
|
||||||
{
|
{
|
||||||
return Save(settingWords.PathBase, output);
|
return Save(settingWords.PathBase, output);
|
||||||
}
|
}
|
||||||
public static bool Save(string path, object output)
|
public static bool Save(string path, object output)
|
||||||
{
|
{
|
||||||
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
BinaryFormatter binaryFormatter = new BinaryFormatter();
|
||||||
FileStream file = null;
|
FileStream file = null;
|
||||||
|
|
@ -163,19 +188,22 @@ namespace Reseter2.Setting
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
if(file != null)
|
||||||
|
{
|
||||||
file.Close();
|
file.Close();
|
||||||
file.Dispose();
|
file.Dispose();
|
||||||
return SaveCheck(output);
|
}
|
||||||
|
return SaveCheck(path, output);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static bool SaveCheck(object output)
|
public static bool SaveCheck(string path, object output)
|
||||||
{
|
{
|
||||||
DialogResult result1 = MessageBox.Show("Файл занят другой программой.\nПовторить еще раз?", "Ошибка сохранения", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
|
DialogResult result1 = MessageBox.Show("Файл занят другой программой.\nПовторить еще раз?", "Ошибка сохранения", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Error);
|
||||||
switch (result1)
|
switch (result1)
|
||||||
{
|
{
|
||||||
case (DialogResult.Retry):
|
case (DialogResult.Retry):
|
||||||
return SaveCheck(output);
|
return Save(path, output);
|
||||||
case (DialogResult.Abort):
|
case (DialogResult.Abort):
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,10 +7,12 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace Reseter2.Setting
|
namespace Reseter2.Setting
|
||||||
{
|
{
|
||||||
|
[Serializable]
|
||||||
internal struct SSetting
|
internal struct SSetting
|
||||||
{
|
{
|
||||||
public SettingWords settingWords;
|
public SettingWords settingWords;
|
||||||
public List<HistoryItem> historyItems;
|
public List<HistoryItem> historyItems;
|
||||||
|
public SettingExpand settingExpand;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,63 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace Reseter2.Setting
|
||||||
|
{
|
||||||
|
[Serializable]
|
||||||
|
internal class SettingExpand
|
||||||
|
{
|
||||||
|
private List<string> nodePathes;
|
||||||
|
public SettingExpand()
|
||||||
|
{
|
||||||
|
nodePathes = new List<string>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ExpendAll(TreeNodeCollection nodes)
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach (string path in nodePathes)
|
||||||
|
{
|
||||||
|
string[] folder = path.Split('/');
|
||||||
|
Expand(nodes, folder, 0);
|
||||||
|
}
|
||||||
|
nodePathes.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Expand(TreeNodeCollection nodes, string[] folder, int number)
|
||||||
|
{
|
||||||
|
|
||||||
|
int i = nodes.IndexOfKey(folder[number]);
|
||||||
|
if (i == -1) return;
|
||||||
|
if (folder.Count() == number+1)
|
||||||
|
{
|
||||||
|
nodes[i].Expand();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Expand(nodes[i].Nodes, folder, number+1);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveExpand(TreeNodeCollection nodes, string path = "")
|
||||||
|
{
|
||||||
|
|
||||||
|
foreach(TreeNode node in nodes)
|
||||||
|
{
|
||||||
|
if(node.Nodes.Count > 0)
|
||||||
|
{
|
||||||
|
if (node.IsExpanded)
|
||||||
|
{
|
||||||
|
nodePathes.Add(path + node.Name);
|
||||||
|
}
|
||||||
|
SaveExpand(node.Nodes, path + node.Name + "/" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -32,7 +32,8 @@ namespace Reseter2.Setting
|
||||||
|
|
||||||
public void HashSumm(MemoryStream memory)
|
public void HashSumm(MemoryStream memory)
|
||||||
{
|
{
|
||||||
hash = Hash.ComputeHash(memory);
|
if(Hash == null) Hash = MD5.Create();
|
||||||
|
hash = Hash.ComputeHash(memory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool HashCheck(MemoryStream memory)
|
public bool HashCheck(MemoryStream memory)
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,7 @@ namespace Reseter2.Words
|
||||||
public override TreeNode NodeList()
|
public override TreeNode NodeList()
|
||||||
{
|
{
|
||||||
TreeNode treeNode = new TreeNode(GetName());
|
TreeNode treeNode = new TreeNode(GetName());
|
||||||
|
treeNode.Name = GetName();
|
||||||
treeNode.Tag = this;
|
treeNode.Tag = this;
|
||||||
treeNode.ImageIndex = 0;
|
treeNode.ImageIndex = 0;
|
||||||
treeNode.SelectedImageIndex = 0;
|
treeNode.SelectedImageIndex = 0;
|
||||||
|
|
@ -114,7 +115,8 @@ namespace Reseter2.Words
|
||||||
|
|
||||||
foreach (var item in items)
|
foreach (var item in items)
|
||||||
{
|
{
|
||||||
treeNode.Nodes.Add(item.NodeList());
|
int i = treeNode.Nodes.Add(item.NodeList());
|
||||||
|
treeNode.Nodes[i].Name += treeNode.Nodes[i].Index;
|
||||||
}
|
}
|
||||||
return treeNode;
|
return treeNode;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ namespace Reseter2.Words
|
||||||
{
|
{
|
||||||
TreeNode treeNode = new TreeNode();
|
TreeNode treeNode = new TreeNode();
|
||||||
treeNode.Text = NameNode();
|
treeNode.Text = NameNode();
|
||||||
|
treeNode.Name = NameNode();
|
||||||
treeNode.Tag = this;
|
treeNode.Tag = this;
|
||||||
treeNode.ImageIndex = Comp.GetImage();
|
treeNode.ImageIndex = Comp.GetImage();
|
||||||
treeNode.SelectedImageIndex = Comp.GetImage();
|
treeNode.SelectedImageIndex = Comp.GetImage();
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ namespace Reseter2.Words
|
||||||
for(int i = 0; i < MainCategory.Count(); i++)
|
for(int i = 0; i < MainCategory.Count(); i++)
|
||||||
{
|
{
|
||||||
treeNodes[i] = MainCategory.Items(i).NodeList();
|
treeNodes[i] = MainCategory.Items(i).NodeList();
|
||||||
|
treeNodes[i].Name += i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return treeNodes;
|
return treeNodes;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue