Commit 3b7b11a9 authored by 潘栩锋's avatar 潘栩锋 🚴

优化 layout的多个备份,直接保存整个layout文件夹

parent 715ebee6
......@@ -32,82 +32,120 @@ namespace MultiLayout.MainEdit
{
this.listview_profile.ItemsSource = mList;
//查找 layout/graphcustoms 下的全部文件
string dirPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms");
//查找 default/layout.default 下的全部文件夹
string dirPath = System.IO.Path.Combine("default", "layout.default");
DirectoryInfo directoryInfo = new DirectoryInfo(dirPath);
if (!directoryInfo.Exists) {
return;
}
var files = directoryInfo.GetFiles("*.json");
foreach (var file in files) {
mList.Add(System.IO.Path.GetFileNameWithoutExtension(file.Name));
var directoryInfos = directoryInfo.GetDirectories();
foreach (var dirInfo in directoryInfos) {
//检查这个文件夹是否正确
string filePath = System.IO.Path.Combine(dirInfo.FullName, "graphcustom.json");
if (File.Exists(filePath)) {
//正确
mList.Add(dirInfo.Name);
}
}
}
private void button_read_Click(object sender, RoutedEventArgs e)
{
if (listview_profile.SelectedItem != null)
{
string strTipRebootForExecute = "需要重启,才能生效";
if (FLY.ControlLibrary.MyMessageBox.Show(strTipRebootForExecute) == true)
{
string filename = listview_profile.SelectedItem as string;
string filePath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms", filename + ".json");
string destPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustom.json");
File.Copy(filePath, destPath, true);
System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
if (listview_profile.SelectedItem == null)
return;
string strTipRebootForExecute = "需要重启,才能生效";
if (FLY.ControlLibrary.MyMessageBox.Show(strTipRebootForExecute) != true)
return;
string dirname = listview_profile.SelectedItem as string;
string srcDirPath = System.IO.Path.Combine("default", "layout.default", dirname);
//把 srcDirPath 下的全部文件 复制到 FlyLayout.BasePath 下
DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirPath);
var fileInfos = srcDirInfo.GetFiles();
foreach (var fileInfo in fileInfos)
{
string filePath = fileInfo.FullName;
string destPath = System.IO.Path.Combine(FlyLayout.BasePath, fileInfo.Name);
File.Copy(filePath, destPath, true);
}
System.Windows.Forms.Application.Restart();
Application.Current.Shutdown();
}
private void button_del_Click(object sender, RoutedEventArgs e)
{
if (listview_profile.SelectedItem != null)
{
string filename = listview_profile.SelectedItem as string;
string filePath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms", filename + ".json");
File.Delete(filePath);
mList.Remove(filename);
FLY.ControlLibrary.Window_Tip.Show("删除成功",
filename,
TimeSpan.FromSeconds(2));
}
if (listview_profile.SelectedItem == null)
return;
string dirname = listview_profile.SelectedItem as string;
if (FLY.ControlLibrary.MyMessageBox.Show($"将要删除 {dirname} ,是否确定?") != true)
return;
string srcDirPath = System.IO.Path.Combine("default", "layout.default", dirname);
Directory.Delete(srcDirPath, true);
mList.Remove(dirname);
FLY.ControlLibrary.Window_Tip.Show("删除成功",
dirname,
TimeSpan.FromSeconds(2));
}
private void button_save_Click(object sender, RoutedEventArgs e)
{
WdSaveFile w = new WdSaveFile();
if (listview_profile.SelectedItem != null)
w.FileName = listview_profile.SelectedItem as string;
w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
if (w.ShowDialog() == true) {
if (mList.Contains(w.FileName)) {
if (FLY.ControlLibrary.MyMessageBox.Show("文件已经存在,是否覆盖?")!=true)
{
return;
}
}
string dirPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms");
if (!Directory.Exists(dirPath))
Directory.CreateDirectory(dirPath);
string filename = w.FileName;
string destPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustoms", filename + ".json");
string srcPath = System.IO.Path.Combine(FlyLayout.BasePath, "graphcustom.json");
File.Copy(srcPath, destPath, true);
if (!mList.Contains(w.FileName))
{
mList.Add(filename);
}
FLY.ControlLibrary.Window_Tip.Show("保存成功",
filename,
TimeSpan.FromSeconds(2));
if (w.ShowDialog() != true)
return;
if (mList.Contains(w.FileName)) {
if (FLY.ControlLibrary.MyMessageBox.Show("布局文件已经存在,是否覆盖?")!=true)
return;
}
string dirname = w.FileName;
string destDirPath = System.IO.Path.Combine("default", "layout.default", dirname);
string srcDirPath = FlyLayout.BasePath;
if (!Directory.Exists(destDirPath))
Directory.CreateDirectory(destDirPath);
//把 srcDirPath 下的全部文件 复制到 destDirPath 下
DirectoryInfo srcDirInfo = new DirectoryInfo(srcDirPath);
var fileInfos = srcDirInfo.GetFiles();
foreach (var fileInfo in fileInfos)
{
string filePath = fileInfo.FullName;
string destPath = System.IO.Path.Combine(destDirPath, fileInfo.Name);
File.Copy(filePath, destPath, true);
}
if (!mList.Contains(w.FileName))
mList.Add(w.FileName);
FLY.ControlLibrary.Window_Tip.Show("保存成功",
w.FileName,
TimeSpan.FromSeconds(2));
}
}
}
......@@ -16,9 +16,9 @@
<StackPanel Margin="5,20">
<StackPanel Grid.Column="1" Margin="5">
<TextBlock Style="{StaticResource TextBlockStyle_FieldHeaderEditable}" Text="请输入布局名称:" />
<StackPanel Orientation="Horizontal">
<TextBox Style="{StaticResource ResourceKey=TextBoxStyle_FieldContent}" Name="textbox_productname" Tag="Full" MinWidth="300"/>
</StackPanel>
<Viewbox>
<TextBox Style="{StaticResource TextBoxStyle_FieldContent}" Name="textbox_productname" Tag="Full" MinWidth="300"/>
</Viewbox>
</StackPanel>
<StackPanel Orientation="Horizontal"></StackPanel>
<Button Content="保存" Style="{StaticResource ButtonStyle2}" Margin="5" Width="auto" Click="button_save_Click" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment