예제 #1
0
        private void InstallTabTitlePath(DocumentView view)
        {
            if (!(view.Title is WindowFrameTitle title))
            {
                return;
            }

            var bindingExpression = BindingOperations.GetBindingExpression(title, WindowFrameTitle.TitleProperty);

            if (!(bindingExpression?.DataItem is WindowFrame frame))
            {
                return;
            }

            var model = new TabModel(FixFileNameCase(frame.FrameMoniker.Filename));

            frame.PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(WindowFrame.AnnotatedTitle))
                {
                    model.FullPath = FixFileNameCase(frame.FrameMoniker.Filename);
                }
            };

            _displayPathResolver.Add(model);

            var viewModel = new TabViewModel(title, view.TabTitleTemplate, model);

            SetTabViewModel(view, viewModel);

            view.DocumentTabTitleTemplate = view.TabTitleTemplate =
                (DataTemplate)Application.Current.FindResource("TabPathTemplate");

            _viewModels.Add(view, viewModel);

            frame.FrameDestroyed += (sender, args) =>
            {
                _displayPathResolver.Remove(_viewModels[view].Model);
                _viewModels.Remove(view);
            };
        }
예제 #2
0
        public void WhenNewTabIsAdded_UpdatePaths()
        {
            var models = new[]
            {
                new TabModel(@"c:\Directory1\1.txt"),
                new TabModel(@"c:\Directory1\2.txt"),
                new TabModel(@"c:\Directory2\1.txt"),
            };

            var resolver = new DisplayPathResolver
            {
                models[0],
                models[1],
            };

            Assert.AreEqual(null, models[0].DisplayPath);
            Assert.AreEqual(null, models[1].DisplayPath);

            resolver.Add(models[2]);

            Assert.AreEqual(@"c:\Directory1", models[0].DisplayPath);
            Assert.AreEqual(null, models[1].DisplayPath);
            Assert.AreEqual(@"c:\Directory2", models[2].DisplayPath);
        }