private void SetColor(bool sendNotification, string propertyName, ColorKey colorKey, System.Drawing.Color value)
        {
#if DEBUG_COLOR_STYLE_OPTIONS
            Debug.WriteLine($"GeneralOptions.SetColor keyName={colorKey.Name}" + (colorKey.IsForeground? "FG":"BG") + $" color={value} Notify={sendNotification}");
#endif
            colorMap[colorKey].Color = value;
            if (sendNotification)
            {
                VsSettings.NotiifyInstancesFmtPropertyChanged(propertyName, fromDrawingColor(value));
            }
        }
Beispiel #2
0
 public static VsSettings GetOrCreate(IWpfTextView textView)
 {
     lock (Instances)
     {
         if (!Instances.TryGetValue(textView, out VsSettings settings))
         {
             settings = new VsSettings(textView);
             Instances.Add(textView, settings);
         }
         return(settings);
     }
 }
Beispiel #3
0
        public void Init()
        {
            {
                var A = new EditorHostFactory();
                var B = A.CreateCompositionContainer();
                IEditorFormatMapService efms = B.GetExportedValue <IEditorFormatMapService>();
                if (!VsSettings.IsInitialized)
                {
                    VsSettings.Initialize(this.pkg, efms);
                }
            }

            CreateMenu();
            cmdExec = new CommandExecutorService()
            {
            };
            disableVsVimCmdAvailable = cmdExec.IsCommandAvailable(VsVimSetDisabled);
            enableVsVimCmdAvailable  = cmdExec.IsCommandAvailable(VsVimSetEnabled);
            viEmuPluginPresent       = cmdExec.IsCommandAvailable(ViEmuEnableDisableCommand);
            iVsUiShell  = Package.GetGlobalService(typeof(SVsUIShell)) as IVsUIShell;
            iVsUiShell4 = iVsUiShell as IVsUIShell4;
            JumpLabelUserControl.WarmupCache();
            // warmup options
            GeneralOptions.Instance.caretPositionSensivity = GeneralOptions.Instance.caretPositionSensivity;
            // warmp up:
#if MEASUREEXECTIME
            var watch2_0 = System.Diagnostics.Stopwatch.StartNew();
#endif
            var wfs = iVsUiShell.GetDocumentWindowFrames().GetValueOrDefault();
            if (wfs.Count > 0)
            {
                Trace.WriteLine("GetDocumentWindowFrames warmed up");
                foreach (var wf in wfs)
                {
                    wf.GetProperty((int)VsFramePropID.Caption, out var oce);
                    wf.SetProperty((int)VsFramePropID.Caption, (string)oce);
                }
            }
#if MEASUREEXECTIME
            watch2_0.Stop();
            Trace.WriteLine($"PeasyMotion Adornment warmup document tabs: {watch2_0.ElapsedMilliseconds} ms");
#endif
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PeasyMotionEdAdornment"/> class.
        /// </summary>
        /// <param name="view">Text view to create the adornment for</param>
        public PeasyMotionEdAdornment(PeasyMotionEdAdornmentCtorArgs args)
        {
            this.jumpLabelKeyArray = GeneralOptions.Instance.AllowedJumpKeys;
#if MEASUREEXECTIME
            var watch0 = System.Diagnostics.Stopwatch.StartNew();
#endif
            jumpMode = args.jumpMode;

            var jumpLabelAssignmentAlgorithm = GeneralOptions.Instance.getJumpLabelAssignmentAlgorithm();
            var caretPositionSensivity       = Math.Min(Int32.MaxValue >> 2, Math.Abs(GeneralOptions.Instance.caretPositionSensivity));


            this.textStructureNavigator = args.textStructNav;

            this.vsTextView = args.vsTextView;
            this.view       = args.wpfView;

            this.layer = view.GetAdornmentLayer("PeasyMotionEdAdornment");
            //this.view.LayoutChanged += this.OnLayoutChanged;

            this.vsSettings = VsSettings.GetOrCreate(view);
            // subscribe to fmt updates, so user can tune color faster if PeasyMotion was invoked
            this.vsSettings.PropertyChanged += this.OnFormattingPropertyChanged;

            this.jumpLabelCachedSetupParams.fontRenderingEmSize = this.view.FormattedLineSource.DefaultTextProperties.FontRenderingEmSize;
            this.jumpLabelCachedSetupParams.typeface            = this.view.FormattedLineSource.DefaultTextProperties.Typeface;
            this.jumpLabelCachedSetupParams.labelFg             = this.vsSettings.JumpLabelFirstMotionForegroundColor;
            this.jumpLabelCachedSetupParams.labelBg             = this.vsSettings.JumpLabelFirstMotionBackgroundColor;
            this.jumpLabelCachedSetupParams.labelFinalMotionFg  = this.vsSettings.JumpLabelFinalMotionForegroundColor;
            this.jumpLabelCachedSetupParams.labelFinalMotionBg  = this.vsSettings.JumpLabelFinalMotionBackgroundColor;
            this.jumpLabelCachedSetupParams.Freeze();

            var jumpWords = new List <JumpWord>();
#if MEASUREEXECTIME
            watch0.Stop();
            Trace.WriteLine($"PeasyMotion Adornment ctor settings, members init, etc: {watch0.ElapsedMilliseconds} ms");
#endif


            if (jumpMode == JumpMode.VisibleDocuments)
            {
                SetupJumpToDocumentTabMode(jumpWords);
            }
            else
            {
                SetupJumpInsideTextViewMode(jumpWords, jumpLabelAssignmentAlgorithm, caretPositionSensivity, args.twoCharSearchJumpKeys);
            }

            if (JumpLabelAssignmentAlgorithm.CaretRelative == jumpLabelAssignmentAlgorithm)
            {
#if MEASUREEXECTIME
                var watch2 = System.Diagnostics.Stopwatch.StartNew();
#endif
                // sort jump words from closest to cursor to farthest
                jumpWords.Sort((a, b) => + a.distanceToCursor.CompareTo(b.distanceToCursor));
#if MEASUREEXECTIME
                watch2.Stop();
                Trace.WriteLine($"PeasyMotion Adornment sort words: {watch2.ElapsedMilliseconds} ms");
#endif
            }

#if MEASUREEXECTIME
            var watch3 = System.Diagnostics.Stopwatch.StartNew();
#endif
            _ = computeGroups(0, jumpWords.Count - 1, (jumpLabelKeyArray), "", jumpWords);

#if MEASUREEXECTIME
            watch3.Stop();
            Trace.WriteLine($"PeasyMotion Adornments group&create: {watch3?.ElapsedMilliseconds} ms");
#endif

#if MEASUREEXECTIME
            Trace.WriteLine($"PeasyMotion Adornments create: {adornmentCreateStopwatch?.ElapsedMilliseconds} ms");
            Trace.WriteLine($"PeasyMotion Adornments UI Elem create: {createAdornmentUIElem?.ElapsedMilliseconds} ms");
            Trace.WriteLine($"PeasyMotion Adornment total jump labels - {jumpWords?.Count}");
            createAdornmentUIElem    = null;
            adornmentCreateStopwatch = null;
#endif

            if (jumpMode == JumpMode.VisibleDocuments)
            {
                SetupJumpToDocumentTabFinalPhase();
            }
        }