Commit 608a27bc by wangonghui

页面布局保存功能开发

parent f61fe3cb
...@@ -60,5 +60,10 @@ namespace VIZ.Package.Domain ...@@ -60,5 +60,10 @@ namespace VIZ.Package.Domain
/// 包装任务服务 /// 包装任务服务
/// </summary> /// </summary>
public const string PACKAGE_TASK_SERVICE = "PACKAGE_TASK_SERVICE"; public const string PACKAGE_TASK_SERVICE = "PACKAGE_TASK_SERVICE";
/// <summary>
/// 主视图Top服务
/// </summary>
public const string MAIN_TOPVIEW_SERVICE = "MAIN_TOPVIEW_SERVICE";
} }
} }
...@@ -68,18 +68,34 @@ namespace VIZ.Package.Domain.Model ...@@ -68,18 +68,34 @@ namespace VIZ.Package.Domain.Model
#endregion #endregion
#region 文件路径
private string filePath;
/// <summary>
/// 文件路径
/// </summary>
public string FilePath
{
get { return filePath; }
set { filePath=value; this.RaisePropertyChanged(nameof(FilePath)); }
}
#endregion
#region Command -- 命令 #region Command -- 命令
private VCommand command; private VCommand<string> command;
/// <summary> /// <summary>
/// 命令 /// 命令
/// </summary> /// </summary>
public VCommand Command public VCommand<string> Command
{ {
get { return command; } get { return command; }
set { command = value; this.RaisePropertyChanged(nameof(Command)); } set { command = value; this.RaisePropertyChanged(nameof(Command)); }
} }
#endregion #endregion
} }
} }
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Package.Domain.Model;
namespace VIZ.Package.Module
{
public interface IMainTopViewService : IService
{
ObservableCollection<MenuItemModel> ItemsSource { get; set; }
VCommand<string> ImportLayoutCommand { get; set; }
}
}
...@@ -29,13 +29,13 @@ namespace VIZ.Package.Module ...@@ -29,13 +29,13 @@ namespace VIZ.Package.Module
void SetIsEnabled(bool isEnabled); void SetIsEnabled(bool isEnabled);
/// <summary> /// <summary>
/// 保存位置 /// 导出布局
/// </summary> /// </summary>
void SaveLayout1(); void ExportLayout(string param);
/// <summary> /// <summary>
/// 加载位置 /// 加载布局
/// </summary> /// </summary>
void LoadLayout1(); void ImportLayout(string param);
} }
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
<DataTemplate> <DataTemplate>
<ContentControl> <ContentControl>
<dxb:BarButtonItem Glyph="{Binding Icon}" Content="{Binding Header}" <dxb:BarButtonItem Glyph="{Binding Icon}" Content="{Binding Header}"
Command="{Binding Path=Command}"></dxb:BarButtonItem> Command="{Binding Path=Command}" CommandParameter="{Binding Path=FilePath}" ></dxb:BarButtonItem>
</ContentControl> </ContentControl>
</DataTemplate> </DataTemplate>
</local:MainTopViewMenuDataTemplateSelector.ButtonDataTemplate> </local:MainTopViewMenuDataTemplateSelector.ButtonDataTemplate>
......
<dx:ThemedWindow
x:Class="VIZ.Package.Module.ManagerLayoutView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
ResizeMode="NoResize" WindowStartupLocation="CenterScreen"
Title="管理窗口布局" Height="300" Width="400" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"/>
<RowDefinition Height="*"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="100"/>
</Grid.ColumnDefinitions>
<TextBlock Text="已保存的布局:" VerticalAlignment="Center" Margin="5"/>
<ListBox Name="saveLayoutBox" Grid.Row="1" Margin="5,0,0,0" ItemsSource="{Binding Path=ItemsSource}" SelectedItem="{Binding SelectItem}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Header}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<StackPanel Grid.Row="2" Orientation="Horizontal" Margin="5,0,0,0">
<Button Content="重命名" Width="60" Command="{Binding ReNameCommand}" Margin="0,0,5,0"/>
<Button Content="删除" Width="60" Command="{Binding DeleteCommand}"/>
</StackPanel>
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right" >
<Button Content="关闭" Width="60" Command="{Binding CloseCommand}"/>
</StackPanel>
</Grid>
</dx:ThemedWindow>
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.Package.Module
{
/// <summary>
/// Interaction logic for ManagerLayout.xaml
/// </summary>
public partial class ManagerLayoutView : ThemedWindow
{
public ManagerLayoutView()
{
InitializeComponent();
WPFHelper.BindingViewModel(this, new ManagerLayoutViewModel());
}
}
}
<dx:ThemedWindow
x:Class="VIZ.Package.Module.SaveLayoutView"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:VIZ.Package.Module"
Title="{Binding Path=TitleName}"
mc:Ignorable="d"
Width="300" Height="160" ResizeMode="NoResize" WindowStartupLocation="CenterScreen" >
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="50"></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Text="布局名称:" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,10,0" Grid.Row="0"></TextBlock>
<TextBox Text="{Binding Path=FolderName,Mode=TwoWay}" Grid.Row="1" VerticalContentAlignment="Center" HorizontalAlignment="Left" HorizontalContentAlignment="Left"
AcceptsReturn="False" TextWrapping="NoWrap" Height="30" Margin="10,0,10,0" Width="275"></TextBox>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button Content="确定" Width="80" Height="30" Margin="10" Command="{Binding EnterCommand}"></Button>
<Button Content="取消" Width="80" Height="30" Margin="10" Command="{Binding CancelCommand}"></Button>
</StackPanel>
</Grid>
</dx:ThemedWindow>
using DevExpress.Xpf.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using VIZ.Framework.Core;
namespace VIZ.Package.Module
{
/// <summary>
/// Interaction logic for SaveLayout.xaml
/// </summary>
public partial class SaveLayoutView : ThemedWindow
{
public SaveLayoutView()
{
InitializeComponent();
WPFHelper.BindingViewModel(this, new SaveLayoutViewModel());
}
}
}
...@@ -4,6 +4,7 @@ using log4net; ...@@ -4,6 +4,7 @@ using log4net;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO;
using System.Linq; using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
...@@ -21,7 +22,7 @@ namespace VIZ.Package.Module ...@@ -21,7 +22,7 @@ namespace VIZ.Package.Module
/// <summary> /// <summary>
/// 主视图顶部视图模型 /// 主视图顶部视图模型
/// </summary> /// </summary>
public class MainTopViewModel : ViewModelBase public class MainTopViewModel : ViewModelBase, IMainTopViewService
{ {
/// <summary> /// <summary>
/// 日志 /// 日志
...@@ -35,6 +36,9 @@ namespace VIZ.Package.Module ...@@ -35,6 +36,9 @@ namespace VIZ.Package.Module
// 初始化消息 // 初始化消息
this.InitMessage(); this.InitMessage();
// 注册服务
ApplicationDomainEx.ServiceManager.AddService(ViewServiceKeys.MAIN_TOPVIEW_SERVICE, this);
} }
/// <summary> /// <summary>
...@@ -50,14 +54,16 @@ namespace VIZ.Package.Module ...@@ -50,14 +54,16 @@ namespace VIZ.Package.Module
this.CloseProjectCommand = new VCommand(this.CloseProject, this.CanCloseProject); this.CloseProjectCommand = new VCommand(this.CloseProject, this.CanCloseProject);
this.SettingCommand = new VCommand(this.Setting); this.SettingCommand = new VCommand(this.Setting);
this.ResetLayoutCommand = new VCommand(this.ResetLayout); this.ResetLayoutCommand = new VCommand<string>(this.ResetLayout);
this.AboutCommand = new VCommand(this.About); this.AboutCommand = new VCommand(this.About);
this.AboutCustomControlFieldCommand = new VCommand(this.AboutCustomControlField); this.AboutCustomControlFieldCommand = new VCommand(this.AboutCustomControlField);
this.AboutPageCommandCommand = new VCommand(this.AboutPageCommand); this.AboutPageCommandCommand = new VCommand(this.AboutPageCommand);
this.ExportLayoutCommand = new VCommand(this.ExportLayout); this.ExportLayoutCommand = new VCommand<string>(this.ExportLayout);
this.ImportLayoutCommand = new VCommand<string>(this.ImportLayout);
this.ImportLayoutCommand = new VCommand(this.ImportLayout); this.ManageLayoutCommand = new VCommand<string>(this.ManageLayout);
} }
/// <summary> /// <summary>
...@@ -163,29 +169,65 @@ namespace VIZ.Package.Module ...@@ -163,29 +169,65 @@ namespace VIZ.Package.Module
}).ToList(); }).ToList();
items.Add(new MenuItemModel { Type = MenuItemType.Separator }); items.Add(new MenuItemModel { Type = MenuItemType.Separator });
string path = GetLayoutPath();
items.Add(new MenuItemModel items.Add(new MenuItemModel
{ {
Header = "重置布局", Header = "保存布局",
Icon = "/VIZ.Package.Module.Resource;component/Icons/top_icon_layout_20x20.png", Icon = "/VIZ.Package.Module.Resource;component/Icons/top_icon_layout_20x20.png",
Type = MenuItemType.Button, Type = MenuItemType.Button,
Command = this.ResetLayoutCommand FilePath = path,
Command = this.ExportLayoutCommand
}); });
items.Add(new MenuItemModel items.Add(new MenuItemModel
{ {
Header = "导入布局", Header = "管理布局",
Icon = "/VIZ.Package.Module.Resource;component/Icons/top_icon_layout_20x20.png", Icon = "/VIZ.Package.Module.Resource;component/Icons/top_icon_layout_20x20.png",
Type = MenuItemType.Button, Type = MenuItemType.Button,
Command = this.ExportLayoutCommand // FilePath = path,
Command = this.ManageLayoutCommand
}); });
items.Add(new MenuItemModel items.Add(new MenuItemModel
{ {
Header = "导出布局", Header = "重置布局",
Icon = "/VIZ.Package.Module.Resource;component/Icons/top_icon_layout_20x20.png", Icon = "/VIZ.Package.Module.Resource;component/Icons/top_icon_layout_20x20.png",
Type = MenuItemType.Button, Type = MenuItemType.Button,
Command = this.ImportLayoutCommand Command = this.ResetLayoutCommand
}); });
items.Add(new MenuItemModel { Type = MenuItemType.Separator });
//读取文件中配置文件
if (Directory.Exists(path))
{
string[] files = Directory.GetFiles(path);
foreach (var file in files)
{
MenuItemModel menuItemModel = new MenuItemModel();
menuItemModel.Header = Path.GetFileNameWithoutExtension(file);
if (Convert.ToString(menuItemModel.Header) != "layout" && (Convert.ToString(menuItemModel.Header) != "default_layout"))
{
menuItemModel.Type = MenuItemType.Button;
menuItemModel.FilePath = file;
menuItemModel.Command = this.ImportLayoutCommand;
items.Add(menuItemModel);
}
}
}
this.ItemsSource = items.ToObservableCollection(); this.ItemsSource = items.ToObservableCollection();
} }
...@@ -428,12 +470,12 @@ namespace VIZ.Package.Module ...@@ -428,12 +470,12 @@ namespace VIZ.Package.Module
/// <summary> /// <summary>
/// 重置布局命令 /// 重置布局命令
/// </summary> /// </summary>
public VCommand ResetLayoutCommand { get; set; } public VCommand<string> ResetLayoutCommand { get; set; }
/// <summary> /// <summary>
/// 重置布局 /// 重置布局
/// </summary> /// </summary>
private void ResetLayout() private void ResetLayout(string param)
{ {
IMainViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainViewService>(ViewServiceKeys.MAIN_VIEW_SERVICE); IMainViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainViewService>(ViewServiceKeys.MAIN_VIEW_SERVICE);
if (service == null) if (service == null)
...@@ -450,9 +492,9 @@ namespace VIZ.Package.Module ...@@ -450,9 +492,9 @@ namespace VIZ.Package.Module
#region ImportLayoutCommand --导入布局 #region ImportLayoutCommand --导入布局
public VCommand ImportLayoutCommand { get; set; } public VCommand<string> ImportLayoutCommand { get; set; }
private void ImportLayout() private void ImportLayout(string param)
{ {
IMainViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainViewService>(ViewServiceKeys.MAIN_VIEW_SERVICE); IMainViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainViewService>(ViewServiceKeys.MAIN_VIEW_SERVICE);
...@@ -462,8 +504,30 @@ namespace VIZ.Package.Module ...@@ -462,8 +504,30 @@ namespace VIZ.Package.Module
// 记录操作日志 // 记录操作日志
this.recordLogService.AppendLog(ApplicationConstants.APPLICATION_GROUP_NAME, RecordLogOperate.Operate, RecordLogTrigger.Human, "导入布局"); this.recordLogService.AppendLog(ApplicationConstants.APPLICATION_GROUP_NAME, RecordLogOperate.Operate, RecordLogTrigger.Human, "导入布局");
service.LoadLayout1(); service.ImportLayout(param);
}
/// <summary>
/// 获取布局文件路径
/// </summary>
/// <returns>布局文件路径</returns>
private string GetLayoutPath()
{
string path;
if (string.IsNullOrWhiteSpace(ApplicationDomainEx.VizConfig.PluginGroup))
{
path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "layout");
}
else
{
path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "layout", ApplicationDomainEx.VizConfig.PluginGroup);
}
return path;
} }
#endregion #endregion
...@@ -471,10 +535,10 @@ namespace VIZ.Package.Module ...@@ -471,10 +535,10 @@ namespace VIZ.Package.Module
#region ExportLayoutCommand---导出布局 #region ExportLayoutCommand---导出布局
public VCommand ExportLayoutCommand { get; set; } public VCommand<string> ExportLayoutCommand { get; set; }
private void ExportLayout() private void ExportLayout(string param)
{ {
IMainViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainViewService>(ViewServiceKeys.MAIN_VIEW_SERVICE); IMainViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainViewService>(ViewServiceKeys.MAIN_VIEW_SERVICE);
...@@ -484,7 +548,28 @@ namespace VIZ.Package.Module ...@@ -484,7 +548,28 @@ namespace VIZ.Package.Module
// 记录操作日志 // 记录操作日志
this.recordLogService.AppendLog(ApplicationConstants.APPLICATION_GROUP_NAME, RecordLogOperate.Operate, RecordLogTrigger.Human, "导出布局"); this.recordLogService.AppendLog(ApplicationConstants.APPLICATION_GROUP_NAME, RecordLogOperate.Operate, RecordLogTrigger.Human, "导出布局");
service.SaveLayout1();
service.ExportLayout(param);
}
#endregion
#region ManageLayoutCommand---管理布局
public VCommand<string> ManageLayoutCommand { get; set; }
private void ManageLayout(string param)
{
ManagerLayoutView managerLayout = new ManagerLayoutView();
ManagerLayoutViewModel vm = managerLayout.DataContext as ManagerLayoutViewModel;
vm.ItemsSource = ItemsSource.Where(a => !string.IsNullOrEmpty(a.FilePath)&&Convert.ToString(a.Header)!= "保存布局").ToObservableCollection();
managerLayout.ShowDialog();
} }
#endregion #endregion
......
using DevExpress.Xpf.Docking; using DevExpress.Xpf.Core;
using DevExpress.Xpf.Docking;
using Gma.System.MouseKeyHook; using Gma.System.MouseKeyHook;
using log4net; using log4net;
using Microsoft.Win32; using Microsoft.Win32;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.IO;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Shapes;
using VIZ.Framework.Common; using VIZ.Framework.Common;
using VIZ.Framework.Core; using VIZ.Framework.Core;
using VIZ.Package.Domain; using VIZ.Package.Domain;
...@@ -312,31 +316,57 @@ namespace VIZ.Package.Module ...@@ -312,31 +316,57 @@ namespace VIZ.Package.Module
} }
const string filter = "Configuration (*.xml)|*.xml|All files (*.*)|*.*"; // const string filter = "Configuration (*.xml)|*.xml|All files (*.*)|*.*";
public void SaveLayout1() /// <summary>
/// 导出窗口布局
/// </summary>
/// <param name="param"></param>
public void ExportLayout(string param)
{ {
MainView view = this.GetView<MainView>(); MainView view = this.GetView<MainView>();
if (view == null) if (view == null)
return; return;
OpenFileDialog openFileDialog = new OpenFileDialog() { Filter = filter }; //SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = filter }; //RestoreLayoutFromXml
var openResult = openFileDialog.ShowDialog(); //var saveResult = saveFileDialog.ShowDialog();
if (openResult.HasValue && openResult.Value) //if (saveResult.HasValue && saveResult.Value)
view.dockLayoutManager.RestoreLayoutFromXml(openFileDialog.FileName); // view.dockLayoutManager.SaveLayoutToXml(saveFileDialog.FileName);
SaveLayoutView saveLayout = new SaveLayoutView();
SaveLayoutViewModel vm = saveLayout.DataContext as SaveLayoutViewModel;
vm.TitleName = "保存窗口布局";
vm.view = view;
// string createPath = "";
//createPath = System.IO.Path.Combine(param, vm.FolderName + ".xml");
vm.createPath = param;
saveLayout.ShowDialog();
} }
public void LoadLayout1()
/// <summary>
/// 导入窗体布局
/// </summary>
/// <param name="param"></param>
public void ImportLayout(string param)
{ {
MainView view = this.GetView<MainView>(); MainView view = this.GetView<MainView>();
if (view == null) if (view == null)
return; return;
SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = filter }; if (File.Exists(param))
var saveResult = saveFileDialog.ShowDialog(); {
if (saveResult.HasValue && saveResult.Value) view.dockLayoutManager.RestoreLayoutFromXml(param);
view.dockLayoutManager.SaveLayoutToXml(saveFileDialog.FileName); }
} }
} }
} }
using DevExpress.Xpf.Core;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Domain.Model;
using VIZ.Package.Service;
using VIZ.Package.Storage;
using static System.Net.WebRequestMethods;
using File = System.IO.File;
namespace VIZ.Package.Module
{
/// <summary>
/// 管理布局菜单实体类
/// </summary>
public class ManagerLayoutViewModel : ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(ManagerLayoutViewModel));
//获取topViewService服务
//IMainTopViewService service;
public ManagerLayoutViewModel()
{
//service = ApplicationDomainEx.ServiceManager.GetService<IMainTopViewService>(ViewServiceKeys.MAIN_TOPVIEW_SERVICE);
// itemsSource = service.ItemsSource.Where(a=> !string.IsNullOrEmpty(a.FilePath)).ToObservableCollection();
//初始化命令
this.ReNameCommand = new VCommand(this.ReName);
this.DeleteCommand = new VCommand(this.Delete);
this.CloseCommand = new VCommand(this.Close);
}
/// <summary>
/// 操作日志服务
/// </summary>
private RecordLogService recordLogService = new RecordLogService();
#region 视图集合
/// <summary>
/// 选中视图集合
/// </summary>
private MenuItemModel selectItem;
public MenuItemModel SelectItem
{
get { return selectItem; }
set { selectItem = value; this.RaisePropertyChanged(nameof(SelectItem)); }
}
/// <summary>
/// 视图项的集合
/// </summary>
private ObservableCollection<MenuItemModel> itemsSource;
/// <summary>
/// 视图项
/// </summary>
public ObservableCollection<MenuItemModel> ItemsSource
{
get { return itemsSource; }
set { itemsSource = value; this.RaisePropertyChanged(nameof(ItemsSource)); }
}
#endregion
#region Command 命令
/// <summary>
/// 重命名命令
/// </summary>
public VCommand ReNameCommand { get; set; }
private void ReName()
{
if (selectItem == null) return;
this.recordLogService.AppendLog(ApplicationConstants.APPLICATION_GROUP_NAME, RecordLogOperate.Operate, RecordLogTrigger.Human, "重命名布局");
SaveLayoutView saveLayout = new SaveLayoutView();
SaveLayoutViewModel vm = saveLayout.DataContext as SaveLayoutViewModel;
vm.TitleName = "重命名窗口布局";
vm.FolderName = SelectItem.Header.ToString();
vm.SelectItem = SelectItem;
vm.ItemsSource = ItemsSource;
saveLayout.ShowDialog();
}
/// <summary>
/// 删除命令
/// </summary>
public VCommand DeleteCommand { get; set; }
private void Delete()
{
if (SelectItem == null) return;
this.recordLogService.AppendLog(ApplicationConstants.APPLICATION_GROUP_NAME, RecordLogOperate.Operate, RecordLogTrigger.Human, "删除布局");
if (DXMessageBox.Show("是否替确定要删除布局 " + SelectItem.Header, "提示", System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
{
MenuItemModel tempSelectItem = SelectItem;
if (File.Exists(SelectItem.FilePath))
{
File.Delete(SelectItem.FilePath);
ItemsSource.Remove(SelectItem);
IMainTopViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainTopViewService>(ViewServiceKeys.MAIN_TOPVIEW_SERVICE);
service.ItemsSource.Remove(tempSelectItem);
}
}
}
/// <summary>
/// 关闭命令
/// </summary>
public VCommand CloseCommand { get; set; }
private void Close()
{
ManagerLayoutView view = this.GetView<ManagerLayoutView>();
if (view == null)
return;
view.Close();
}
#endregion
}
}
using DevExpress.Xpf.Core;
using log4net;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Package.Domain;
using VIZ.Package.Domain.Model;
namespace VIZ.Package.Module
{
public class SaveLayoutViewModel : ViewModelBase
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(CreateFolderViewModel));
/// <summary>
/// 初始化
/// </summary>
public SaveLayoutViewModel()
{
EnterCommand = new VCommand(Enter);
CancelCommand = new VCommand(Cancel);
}
public MainView view { get; set; }
public string createPath { get; set; }
/// <summary>
/// 窗口布局名称
/// </summary>
private string titleName;
public string TitleName
{
get { return titleName; }
set { titleName = value; this.RaisePropertyChanged(nameof(TitleName)); }
}
private string folderName;
/// <summary>
/// 文件夹名称
/// </summary>
public string FolderName
{
get { return folderName; }
set { folderName = value; this.RaisePropertyChanged(nameof(FolderName)); }
}
private bool isEnter;
/// <summary>
/// 是否确定
/// </summary>
public bool IsEnter
{
get { return isEnter; }
set { isEnter = value; this.RaisePropertyChanged(nameof(IsEnter)); }
}
public VCommand EnterCommand { get; set; }
public VCommand CancelCommand { get; set; }
/// <summary>
/// 确定
/// </summary>
private void Enter()
{
if (string.IsNullOrWhiteSpace(this.FolderName))
{
DXMessageBox.Show("请输入文件名");
return;
}
//this.IsEnter = true;
//this.GetWindow()?.Close();
if (TitleName== "保存窗口布局")
{
SaveLayout();
}
else if(TitleName== "重命名窗口布局")
{
ReName();
}
}
private void SaveLayout()
{
createPath = System.IO.Path.Combine(createPath, FolderName + ".xml");
//判断此文件路径是否存在不存在就创建
string dir = System.IO.Path.GetDirectoryName(createPath);
if (!System.IO.Directory.Exists(dir))
{
System.IO.Directory.CreateDirectory(dir);
}
if (File.Exists(createPath))
{
if (DXMessageBox.Show("是否替换当前存在布局", "提示", System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
{
view.dockLayoutManager.SaveLayoutToXml(createPath);
this.GetWindow()?.Close();
}
}
else
{
view.dockLayoutManager.SaveLayoutToXml(createPath);
IMainTopViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainTopViewService>(ViewServiceKeys.MAIN_TOPVIEW_SERVICE);
service.ItemsSource.Add(new Domain.Model.MenuItemModel()
{
Header = FolderName,
Type = MenuItemType.Button,
FilePath = createPath,
Command = service.ImportLayoutCommand
});
this.GetWindow()?.Close();
}
}
public MenuItemModel SelectItem { get; set; }
public ObservableCollection<MenuItemModel> ItemsSource { get; set; }
private void ReName()
{
if (File.Exists(SelectItem.FilePath))
{
IMainTopViewService service = ApplicationDomainEx.ServiceManager.GetService<IMainTopViewService>(ViewServiceKeys.MAIN_TOPVIEW_SERVICE);
MenuItemModel tempSelectItem = SelectItem;
//得到没有扩展的文件名称
string fileName = Path.GetFileNameWithoutExtension(SelectItem.FilePath);
//D:\Projects\VIZ.Package\VIZ.Package\bin\x64\Debug\layout\CBA\556.xml
int index = SelectItem.FilePath.LastIndexOf("\\"); //返回“//”最后一次出现的位置
string filepath = SelectItem.FilePath.Substring(0, index);
string newFilePath = filepath + "\\" + FolderName + ".xml";
if (File.Exists(newFilePath))
{
if (DXMessageBox.Show("是否替换当前存在布局", "提示", System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
{
File.Delete(newFilePath);
if (System.IO.File.Exists(SelectItem.FilePath))
{
FileInfo fi = new FileInfo(SelectItem.FilePath);
fi.MoveTo(newFilePath);
}
//文件管理页面对应的移除
ItemsSource.Remove(SelectItem);
//视频导航菜单移除
service.ItemsSource.Remove(tempSelectItem);
this.GetWindow()?.Close();
}
}
else
{
if (System.IO.File.Exists(SelectItem.FilePath))
{
FileInfo fi = new FileInfo(SelectItem.FilePath);
fi.MoveTo(newFilePath);
}
SelectItem.Header = FolderName;
SelectItem.FilePath = newFilePath;
this.GetWindow()?.Close();
}
}
}
/// <summary>
/// 取消
/// </summary>
private void Cancel()
{
this.IsEnter = false;
this.GetWindow()?.Close();
}
}
}
...@@ -156,6 +156,15 @@ ...@@ -156,6 +156,15 @@
<Compile Include="Log\ViewModel\VizCommandWindowModel.cs" /> <Compile Include="Log\ViewModel\VizCommandWindowModel.cs" />
<Compile Include="Main\Controller\HotkeyController.cs" /> <Compile Include="Main\Controller\HotkeyController.cs" />
<Compile Include="Main\Core\MainTopViewMenuDataTemplateSelector.cs" /> <Compile Include="Main\Core\MainTopViewMenuDataTemplateSelector.cs" />
<Compile Include="Main\Service\IMainTopViewService.cs" />
<Compile Include="Main\ViewModel\ManagerLayoutViewModel.cs" />
<Compile Include="Main\ViewModel\SaveLayoutViewModel.cs" />
<Compile Include="Main\View\ManagerLayoutView.xaml.cs">
<DependentUpon>ManagerLayoutView.xaml</DependentUpon>
</Compile>
<Compile Include="Main\View\SaveLayoutView.xaml.cs">
<DependentUpon>SaveLayoutView.xaml</DependentUpon>
</Compile>
<Compile Include="PageCommand\Controller\PageCommandController.cs" /> <Compile Include="PageCommand\Controller\PageCommandController.cs" />
<Compile Include="PageCommand\PageCommandLifeCycle.cs" /> <Compile Include="PageCommand\PageCommandLifeCycle.cs" />
<Compile Include="PageCommand\Service\IPageCommandService.cs" /> <Compile Include="PageCommand\Service\IPageCommandService.cs" />
...@@ -503,6 +512,14 @@ ...@@ -503,6 +512,14 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="Main\View\ManagerLayoutView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Main\View\SaveLayoutView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="PageCommand\View\PageCommandView.xaml"> <Page Include="PageCommand\View\PageCommandView.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
......
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