示例#1
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 private async Task OnUpdateData()
 {
     if (_context.Editor.Project != null && _context.Editor.Project.CurrentDatabase != null)
     {
         var database = _context.Editor.Project.CurrentDatabase;
         
         var dlg = new OpenFileDialog();
         dlg.Filters.Add(new FileDialogFilter() { Name = "Csv", Extensions = { "csv" } });
         dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
         var result = await dlg.ShowAsync(this);
         if (result != null)
         {
             var path = result.FirstOrDefault();
             _context.UpdateData(path, database);
         }
     }
 }
示例#2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="item"></param>
 /// <param name="type"></param>
 private async Task OnImportObject(object item, ImportType type)
 {
     if (item != null)
     {
         string name = string.Empty;
         string ext = string.Empty;
         
         switch (type)
         {
             case ImportType.Style:
                 name = "Style";
                 ext = "style";
                 break;
             case ImportType.Styles:
                 name = "Styles";
                 ext = "styles";
                 break;
             case ImportType.StyleLibrary:
                 name = "StyleLibrary";
                 ext = "stylelibrary";
                 break;
             case ImportType.StyleLibraries:
                 name = "StyleLibraries";
                 ext = "stylelibraries";
                 break;
             case ImportType.Group:
                 name = "Group";
                 ext = "group";
                 break;
             case ImportType.Groups:
                 name = "Groups";
                 ext = "groups";
                 break;
             case ImportType.GroupLibrary:
                 name = "GroupLibrary";
                 ext = "grouplibrary";
                 break;
             case ImportType.GroupLibraries:
                 name = "GroupLibraries";
                 ext = "grouplibraries";
                 break;
             case ImportType.Template:
                 name = "Template";
                 ext = "template";
                 break;
             case ImportType.Templates:
                 name = "Templates";
                 ext = "templates";
                 break;
         }
         
         var dlg = new OpenFileDialog();
         dlg.AllowMultiple = true;
         dlg.Filters.Add(new FileDialogFilter() { Name = name, Extensions = { ext } });
         dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
         var results = await dlg.ShowAsync(this);
         if (results != null)
         {
             foreach (var path in results)
             {
                 _context.ImportObject(path, item, type);
             }
         }
     }
 }
示例#3
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 private async Task<string> OnGetImageKey()
 {
     var dlg = new OpenFileDialog();
     dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
     var result = await dlg.ShowAsync(this);
     if (result != null)
     {
         var path = result.FirstOrDefault();
         var bytes = System.IO.File.ReadAllBytes(path);
         var key = _context.Editor.Project.AddImageFromFile(path, bytes);
         return key;
     }
     return null;
 }
示例#4
0
 /// <summary>
 /// 
 /// </summary>
 private async Task OnOpen(object parameter)
 {
     if (parameter == null)
     {
         var dlg = new OpenFileDialog();
         dlg.Filters.Add(new FileDialogFilter() { Name = "Project", Extensions = { "project" } });
         dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
         var result = await dlg.ShowAsync(this);
         if (result != null)
         {
             var path = result.FirstOrDefault();
             _context.Open(path);
             if (_context.Invalidate != null)
             {
                 _context.Invalidate();
             }
         }
     }
     else
     {
         string path = parameter as string;
         if (path != null && System.IO.File.Exists(path))
         {
             _context.Open(path);
         }
     }
 }
示例#5
0
        public MainWindowViewModel()
        {
            Items = new List<TestItem>();

            for (int i = 0; i < 10; ++i)
            {
                Items.Add(new TestItem($"Item {i}", $"Item {i} Value"));
            }

            Nodes = new List<TestNode>
            {
                new TestNode
                {
                    Header = "Root",
                    SubHeader = "Root Item",
                    IsExpanded = true,
                    Children = new[]
                    {
                        new TestNode
                        {
                            Header = "Child 1",
                            SubHeader = "Child 1 Value",
                        },
                        new TestNode
                        {
                            Header = "Child 2",
                            SubHeader = "Child 2 Value",
                            IsExpanded = false,
                            Children = new[]
                            {
                                new TestNode
                                {
                                    Header = "Grandchild",
                                    SubHeader = "Grandchild Value",
                                },
                                new TestNode
                                {
                                    Header = "Grandmaster Flash",
                                    SubHeader = "White Lines",
                                },
                            }
                        },
                    }
                }
            };

            CollapseNodesCommand = ReactiveCommand.Create();
            CollapseNodesCommand.Subscribe(_ => ExpandNodes(false));
            ExpandNodesCommand = ReactiveCommand.Create();
            ExpandNodesCommand.Subscribe(_ => ExpandNodes(true));

            OpenFileCommand = ReactiveCommand.Create();
            OpenFileCommand.Subscribe(_ =>
            {
                var ofd = new OpenFileDialog();

                ofd.ShowAsync();
            });

            OpenFolderCommand = ReactiveCommand.Create();
            OpenFolderCommand.Subscribe(_ =>
            {
                var ofd = new OpenFolderDialog();

                ofd.ShowAsync();
            });

        }
示例#6
0
        /// <summary>
        /// Import item object from external file.
        /// </summary>
        /// <param name="item">The item object to import.</param>
        /// <param name="type">The type of item object.</param>
        /// <returns>The await <see cref="Task"/>.</returns>
        private async Task OnImportObject(object item, ImportType type)
        {
            try
            {
                if (item != null)
                {
                    string name = string.Empty;
                    string ext = string.Empty;

                    switch (type)
                    {
                        case ImportType.Style:
                            name = "Style";
                            ext = "style";
                            break;
                        case ImportType.Styles:
                            name = "Styles";
                            ext = "styles";
                            break;
                        case ImportType.StyleLibrary:
                            name = "StyleLibrary";
                            ext = "stylelibrary";
                            break;
                        case ImportType.StyleLibraries:
                            name = "StyleLibraries";
                            ext = "stylelibraries";
                            break;
                        case ImportType.Group:
                            name = "Group";
                            ext = "group";
                            break;
                        case ImportType.Groups:
                            name = "Groups";
                            ext = "groups";
                            break;
                        case ImportType.GroupLibrary:
                            name = "GroupLibrary";
                            ext = "grouplibrary";
                            break;
                        case ImportType.GroupLibraries:
                            name = "GroupLibraries";
                            ext = "grouplibraries";
                            break;
                        case ImportType.Template:
                            name = "Template";
                            ext = "template";
                            break;
                        case ImportType.Templates:
                            name = "Templates";
                            ext = "templates";
                            break;
                    }

                    var dlg = new OpenFileDialog();
                    dlg.AllowMultiple = true;
                    dlg.Filters.Add(new FileDialogFilter() { Name = name, Extensions = { ext } });
                    dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
                    var results = await dlg.ShowAsync(_mainWindow);
                    if (results != null)
                    {
                        foreach (var path in results)
                        {
                            _context.ImportObject(path, item, type);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (_context.Editor.Log != null)
                {
                    _context.Editor.Log.LogError("{0}{1}{2}",
                        ex.Message,
                        Environment.NewLine,
                        ex.StackTrace);
                }
            }
        }
示例#7
0
        /// <summary>
        /// Update records in current database.
        /// </summary>
        /// <returns>The await <see cref="Task"/>.</returns>
        private async Task OnUpdateData()
        {
            try
            {
                if (_context.Editor.Project != null && _context.Editor.Project.CurrentDatabase != null)
                {
                    var database = _context.Editor.Project.CurrentDatabase;

                    var dlg = new OpenFileDialog();
                    dlg.Filters.Add(new FileDialogFilter() { Name = "Csv", Extensions = { "csv" } });
                    dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
                    var result = await dlg.ShowAsync(_mainWindow);
                    if (result != null)
                    {
                        var path = result.FirstOrDefault();
                        _context.UpdateData(path, database);
                    }
                }
            }
            catch (Exception ex)
            {
                if (_context.Editor.Log != null)
                {
                    _context.Editor.Log.LogError("{0}{1}{2}",
                        ex.Message,
                        Environment.NewLine,
                        ex.StackTrace);
                }
            }
        }
示例#8
0
 /// <summary>
 /// Open <see cref="Project"/> from file.
 /// </summary>
 /// <param name="parameter"></param>
 /// <returns>The await <see cref="Task"/>.</returns>
 private async Task OnOpen(object parameter)
 {
     try
     {
         if (parameter == null)
         {
             var dlg = new OpenFileDialog();
             dlg.Filters.Add(new FileDialogFilter() { Name = "Project", Extensions = { "project" } });
             dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
             var result = await dlg.ShowAsync(_mainWindow);
             if (result != null)
             {
                 var path = result.FirstOrDefault();
                 _context.Open(path);
                 _context.Editor.Invalidate();
             }
         }
         else
         {
             string path = parameter as string;
             if (path != null && System.IO.File.Exists(path))
             {
                 _context.Open(path);
             }
         }
     }
     catch (Exception ex)
     {
         if (_context.Editor.Log != null)
         {
             _context.Editor.Log.LogError("{0}{1}{2}",
                 ex.Message,
                 Environment.NewLine,
                 ex.StackTrace);
         }
     }
 }
示例#9
0
 /// <summary>
 /// Get the <see cref="XImage"/> key from file path.
 /// </summary>
 /// <returns>The image key.</returns>
 private async Task<string> OnGetImageKey()
 {
     try
     {
         var dlg = new OpenFileDialog();
         dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
         var result = await dlg.ShowAsync(_mainWindow);
         if (result != null)
         {
             var path = result.FirstOrDefault();
             var bytes = System.IO.File.ReadAllBytes(path);
             var key = _context.Editor.Project.AddImageFromFile(path, bytes);
             return key;
         }
         return null;
     }
     catch (Exception ex)
     {
         if (_context.Editor.Log != null)
         {
             _context.Editor.Log.LogError("{0}{1}{2}",
                 ex.Message,
                 Environment.NewLine,
                 ex.StackTrace);
         }
         return null;
     }
 }