Esempio n. 1
0
        private void AddReplaceViewModel_Click(object sender, RoutedEventArgs e)
        {
            //添加替换内容
            ReplaceViewModel viewModel = new ReplaceViewModel();

            replacePagerPage.AddObject(viewModel);
        }
Esempio n. 2
0
        public void ChangeVisiblilityOfReplaceWindow_ShouldChangeVisibilityOfReplaceWindow()
        {
            ReplaceViewModel replaceViewModel = new ReplaceViewModel(new ReplaceModel(), new DocumentModel());
            var before = replaceViewModel.Replace.IsVisible;

            replaceViewModel.ChangeVisiblilityOfReplaceWindowCommand.Execute(null);

            var after = replaceViewModel.Replace.IsVisible;

            Assert.AreNotEqual(before, after);
        }
Esempio n. 3
0
        public void ReplaceText_ShouldNotBeAbleToExecute_WhenDocumentTextAndTextToReplaceAndReplacementAreNullOrEmpty()
        {
            DocumentModel documentModel = new DocumentModel();

            documentModel.Text = string.Empty;

            ReplaceModel replaceModel = new ReplaceModel();

            replaceModel.TextToReplace    = string.Empty;
            replaceModel.TextAfterReplace = string.Empty;

            ReplaceViewModel replaceViewModel = new ReplaceViewModel(replaceModel, documentModel);

            Assert.IsFalse(replaceViewModel.ReplaceTextCommand.CanExecute(null));
        }
Esempio n. 4
0
        public void ReplaceText_ShouldBeAbleToExecute_WhenDocumentTextAndTextToReplaceAndReplacementAreNotNullOrEmpty()
        {
            DocumentModel documentModel = new DocumentModel();

            documentModel.Text = "test";

            ReplaceModel replaceModel = new ReplaceModel();

            replaceModel.TextToReplace    = "test";
            replaceModel.TextAfterReplace = "test";

            ReplaceViewModel replaceViewModel = new ReplaceViewModel(replaceModel, documentModel);

            Assert.IsTrue(replaceViewModel.ReplaceTextCommand.CanExecute(null));
        }
Esempio n. 5
0
        private void SelectRepalceFile_Click(object sender, RoutedEventArgs e)
        {
            string path = FileUtils.SelectSingleExcelFile();

            if (Utils.CheckFileExists(path))
            {
                Dictionary <string, string> replaceDic = ExcelManager.ExcelRead.ReadExcelToDic(path, 0);
                IList <ReplaceViewModel>    list       = new List <ReplaceViewModel>();
                foreach (string oldText in replaceDic.Keys)
                {
                    ReplaceViewModel viewModel = new ReplaceViewModel {
                        OldText = oldText, NewText = replaceDic[oldText]
                    };
                    list.Add(viewModel);
                }
                replacePagerPage.AddObject(list);
            }
        }
Esempio n. 6
0
        public void ReplaceText_ShouldReplaceText_WhenRegex()
        {
            var text     = "test nontest word";
            var expected = "testnannontestnanword";

            ReplaceModel  replaceModel  = new ReplaceModel();
            DocumentModel documentModel = new DocumentModel();

            replaceModel.IsRegex          = true;
            replaceModel.TextToReplace    = @"\s+";
            replaceModel.TextAfterReplace = "nan";

            documentModel.Text = text;

            ReplaceViewModel replaceViewModel = new ReplaceViewModel(replaceModel, documentModel);

            replaceViewModel.ReplaceTextCommand.Execute(null);

            Assert.AreEqual(expected, documentModel.Text);
        }
Esempio n. 7
0
        public ActionResult <object> Replace([FromBody] ReplaceViewModel viewModel)
        {
            var path          = viewModel.Path;
            var search        = $"*{ viewModel.Search }*";
            var replace       = viewModel.Replace;
            var searchOptions = new EnumerationOptions()
            {
                MatchCasing           = viewModel.CaseSensitive ? MatchCasing.CaseSensitive : MatchCasing.CaseInsensitive,
                RecurseSubdirectories = viewModel.Recursive
            };
            var replaceOptions = viewModel.CaseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase;

            var oldFolders = Directory.GetDirectories(path, search, searchOptions);
            var folders    = Replace(
                path, viewModel.Search, replace, replaceOptions,
                oldFolders,
                (oldFolder, newFolder) => { Directory.Move(oldFolder, newFolder); });

            var oldFiles = Directory.GetFiles(path, search, searchOptions);
            var files    = Replace(
                path, viewModel.Search, replace, replaceOptions,
                oldFiles,
                (oldFile, newFile) => { System.IO.File.Move(oldFile, newFile); });

            var result = new
            {
                path          = viewModel.Path,
                search        = viewModel.Search,
                replace       = viewModel.Replace,
                caseSensitive = viewModel.CaseSensitive,
                recursive     = viewModel.Recursive,
                folders,
                files
            };

            return(result);
        }
Esempio n. 8
0
        public override IDock CreateLayout()
        {
            var untitledFileViewModel = new FileViewModel()
            {
                Path     = string.Empty,
                Title    = "Untitled",
                Text     = "",
                Encoding = Encoding.Default.WebName
            };

            var findViewModel = new FindViewModel
            {
                Id    = "Find",
                Title = "Find"
            };

            var replaceViewModel = new ReplaceViewModel
            {
                Id    = "Replace",
                Title = "Replace"
            };

            var files = new DocumentDock
            {
                Id               = MainWindowViewModel.DocumentsDockId,
                Title            = MainWindowViewModel.DocumentsDockId,
                IsCollapsable    = false,
                Proportion       = double.NaN,
                ActiveDockable   = untitledFileViewModel,
                VisibleDockables = CreateList <IDockable>
                                   (
                    untitledFileViewModel
                                   )
            };

            var tools = new ProportionalDock
            {
                Proportion       = 0.2,
                Orientation      = Orientation.Vertical,
                VisibleDockables = CreateList <IDockable>
                                   (
                    new ToolDock
                {
                    Proportion       = double.NaN,
                    ActiveDockable   = findViewModel,
                    VisibleDockables = CreateList <IDockable>
                                       (
                        findViewModel
                                       )
                },
                    new SplitterDock(),
                    new ToolDock
                {
                    Proportion       = double.NaN,
                    ActiveDockable   = replaceViewModel,
                    VisibleDockables = CreateList <IDockable>
                                       (
                        replaceViewModel
                                       )
                }
                                   )
            };

            var windowLayout = CreateRootDock();

            windowLayout.Title = "Default";
            var windowLayoutContent = new ProportionalDock
            {
                Proportion       = double.NaN,
                Orientation      = Orientation.Horizontal,
                IsCollapsable    = false,
                VisibleDockables = CreateList <IDockable>
                                   (
                    files,
                    new SplitterDock(),
                    tools
                                   )
            };

            windowLayout.IsCollapsable    = false;
            windowLayout.VisibleDockables = CreateList <IDockable>(windowLayoutContent);
            windowLayout.ActiveDockable   = windowLayoutContent;

            var root = CreateRootDock();

            root.IsCollapsable    = false;
            root.VisibleDockables = CreateList <IDockable>(windowLayout);
            root.ActiveDockable   = windowLayout;
            root.DefaultDockable  = windowLayout;
            root.Top              = CreatePinDock();
            root.Top.Alignment    = Alignment.Top;
            root.Bottom           = CreatePinDock();
            root.Bottom.Alignment = Alignment.Bottom;
            root.Left             = CreatePinDock();
            root.Left.Alignment   = Alignment.Left;
            root.Right            = CreatePinDock();
            root.Right.Alignment  = Alignment.Right;

            return(root);
        }
Esempio n. 9
0
        public override IRootDock CreateLayout()
        {
            var untitledFileViewModel = new FileViewModel()
            {
                Path     = string.Empty,
                Title    = "Untitled",
                Text     = "",
                Encoding = Encoding.Default.WebName
            };

            var findViewModel = new FindViewModel
            {
                Id    = "Find",
                Title = "Find"
            };

            var replaceViewModel = new ReplaceViewModel
            {
                Id    = "Replace",
                Title = "Replace"
            };

            var documentDock = new FilesDocumentDock()
            {
                Id               = "Files",
                Title            = "Files",
                IsCollapsable    = false,
                Proportion       = double.NaN,
                ActiveDockable   = untitledFileViewModel,
                VisibleDockables = CreateList <IDockable>
                                   (
                    untitledFileViewModel
                                   ),
                CanCreateDocument = true
            };

            var tools = new ProportionalDock
            {
                Proportion       = 0.2,
                Orientation      = Orientation.Vertical,
                VisibleDockables = CreateList <IDockable>
                                   (
                    new ToolDock
                {
                    ActiveDockable   = findViewModel,
                    VisibleDockables = CreateList <IDockable>
                                       (
                        findViewModel
                                       ),
                    Alignment = Alignment.Right,
                    GripMode  = GripMode.Visible
                },
                    new ProportionalDockSplitter(),
                    new ToolDock
                {
                    ActiveDockable   = replaceViewModel,
                    VisibleDockables = CreateList <IDockable>
                                       (
                        replaceViewModel
                                       ),
                    Alignment = Alignment.Right,
                    GripMode  = GripMode.Visible
                }
                                   )
            };

            var windowLayout = CreateRootDock();

            windowLayout.Title = "Default";
            var windowLayoutContent = new ProportionalDock
            {
                Orientation      = Orientation.Horizontal,
                IsCollapsable    = false,
                VisibleDockables = CreateList <IDockable>
                                   (
                    documentDock,
                    new ProportionalDockSplitter(),
                    tools
                                   )
            };

            windowLayout.IsCollapsable    = false;
            windowLayout.VisibleDockables = CreateList <IDockable>(windowLayoutContent);
            windowLayout.ActiveDockable   = windowLayoutContent;

            var rootDock = CreateRootDock();

            rootDock.IsCollapsable    = false;
            rootDock.VisibleDockables = CreateList <IDockable>(windowLayout);
            rootDock.ActiveDockable   = windowLayout;
            rootDock.DefaultDockable  = windowLayout;

            _documentDock = documentDock;
            _rootDock     = rootDock;
            _findTool     = findViewModel;
            _replaceTool  = replaceViewModel;

            return(rootDock);
        }