Exemplo n.º 1
0
        public SettingStore(Options option, UserOptions userOption)
        {
            ReadOnlyReactiveProperty <Color> convert(ReactiveProperty <Color?> r, Color d, Func <VSCodeConfigLoader, Color?> func)
            {
                return(r.CombineLatest(UserOptionEnable, UserOptionFindVSCExtConfig, VSCodeConfig, (c, e, ve, vc) => {
                    if (ve && vc?.IsLoaded == true)
                    {
                        var tmp = func(vc);
                        if (tmp.HasValue)
                        {
                            return tmp.Value;
                        }
                    }
                    return (e && c.HasValue) ? c.Value : d;
                }).ToReadOnlyReactiveProperty(d));
            }

            ReactiveProperty <Color?> to_property_as_sync(Expression <Func <UserOptions, string> > func)
            {
                return(UserOption.ToReactivePropertyAsSynchronized <UserOptions, string, Color?>(
                           func,
                           convert: x =>
                           Common.TryConvertColor(x),
                           convertBack: x =>
                           x.HasValue ? Common.ConvertColor(x.Value) : ""
                           ));
            }

            UserOption = userOption;

            SolutionFilePath = new ReactiveProperty <string>();
            SolutionFilePath.Subscribe(x =>
            {
                // VSCodeConfig.Value = VSCodeConfigLoader.FindFromSolutionDir(x);
            });


            VSCodeConfig = SolutionFilePath.Select(x => VSCodeConfigLoader.FindFromSolutionDir(x)).ToReadOnlyReactiveProperty();

            UserActiveBackground   = to_property_as_sync(x => x.ActiveBackground);
            UserActiveForeground   = to_property_as_sync(x => x.ActiveForeground);
            UserInActiveBackground = to_property_as_sync(x => x.InActiveBackground);
            UserInActiveForeground = to_property_as_sync(x => x.InActiveForeground);

            UserOptionEnable           = UserOption.ToReactivePropertyAsSynchronized(x => x.IsEnabled);
            UserOptionFindVSCExtConfig = UserOption.ToReactivePropertyAsSynchronized(x => x.IsFindVSCExtConfig);
            IsPenguin = option.Penguin;

            ActiveBackground   = convert(UserActiveBackground, option.DefaultActiveBackgroundColor, x => x.ActiveBackground);
            ActiveForeground   = convert(UserActiveForeground, option.DefaultActiveForegroundColor, x => x.ActiveForeground);
            InActiveBackground = convert(UserInActiveBackground, option.DefaultInActiveBackgroundColor, x => x.InActiveBackground);
            InActiveForeground = convert(UserInActiveForeground, option.DefaultInActiveForegroundColor, x => x.InActiveForeground);
        }
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            DTE = (DTE2)GetGlobalService(typeof(DTE));

            DTE.Events.WindowEvents.WindowCreated     += (_) => UpdateWindow();
            DTE.Events.WindowEvents.WindowActivated   += (_, __) => UpdateWindow();
            DTE.Events.WindowEvents.WindowClosing     += (_) => UpdateWindow();
            DTE.Events.DocumentEvents.DocumentOpened  += (_) => UpdateWindow();
            DTE.Events.DocumentEvents.DocumentClosing += (_) => UpdateWindow();



            SolutionEvents.OnAfterRenameSolution += (_, __) => OnSolutionUpdated();
            SolutionEvents.OnAfterOpenSolution   += (_, __) => OnSolutionOpend();
            SolutionEvents.OnAfterCloseSolution  += (_, __) => OnSolutionClosed();
            SolutionEvents.OnBeforeCloseSolution += (_, __) => CloseToolWindow();

            bool isSolutionLoaded = await IsSolutionLoadedAsync();

            if (isSolutionLoaded)
            {
                OnSolutionOpend();
            }
            await SolutionOptionWindowCommand.InitializeAsync(this);

            UserOption = new UserOptions();
            UserOption.LoadSetting();
            Settings = new SettingStore((Options)GetDialogPage(typeof(Options)), UserOption);
            if (isSolutionLoaded)
            {
                Settings.SolutionFilePath.Value = DTE.Solution.FileName;
            }
            SolutionOptionWindow.ConnectExisits(this);
        }