Example #1
0
        protected BasePopupWindow(LifetimeDefinition lifetimeDefinition, IPopupWindowContext context,
                                  PopupWindowMutex mutex, HideFlags hideFlags)
        {
            this.lifetimeDefinition = lifetimeDefinition;
            lifetime = lifetimeDefinition.Lifetime;
            Context  = context;
            Mutex    = mutex;

            HideMethod = FormHideMethod.Visibility;

            this.hideFlags = hideFlags;

            lifetime.OnTermination(() =>
            {
                if (!Visible)
                {
                    CloseWindowCore();
                    return;
                }

                void Handle(object sender, EventArgs args)
                {
                    CloseWindowCore();
                    Closed -= Handle;
                }

                Closed += Handle;
                HideWindow();
            });
        }
Example #2
0
        protected BasePopupWindow(LifetimeDefinition lifetimeDefinition, IPopupWindowContext context,
                                  PopupWindowMutex mutex, HideFlags hideFlags)
        {
            this.lifetimeDefinition = lifetimeDefinition;
            lifetime = lifetimeDefinition.Lifetime;
            Context  = context;
            Mutex    = mutex;

            HideMethod = FormHideMethod.Visibility;

            this.hideFlags = hideFlags;

            lifetime.AddAction(() =>
            {
                if (!Visible)
                {
                    CloseWindowCore();
                    return;
                }

                EventHandler handle = null;
                handle = (sender, args) =>
                {
                    CloseWindowCore();
                    Closed -= handle;
                };
                Closed += handle;
                HideWindow();
            });
        }
Example #3
0
 public FadingWpfPopupWindow(LifetimeDefinition lifetimeDefinition, IPopupWindowContext context,
                             PopupWindowMutex mutex, PopupWindowManager popupWindowManager,
                             Window window, double opacity, HideFlags hideFlags = HideFlags.None)
     : base(lifetimeDefinition, context, mutex, popupWindowManager, window, hideFlags)
 {
     this.window  = window;
     this.opacity = opacity;
     window.AllowsTransparency = true;
 }
        protected WpfPopupWindow(LifetimeDefinition lifetimeDefinition, IPopupWindowContext context,
                                 PopupWindowMutex mutex, PopupWindowManager popupWindowManager,
                                 Window window, HideFlags hideFlags = HideFlags.None)
            : base(lifetimeDefinition, context, mutex, hideFlags)
        {
            this.window = window;

            UpdatePopupLayout();
            AttachEvents(popupWindowManager);
        }
Example #5
0
        public override void Execute(IDataContext context, DelegateExecute nextExecute)
        {
            var solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION);

            if (solution == null)
            {
                return;
            }

            var textControl = context.GetData(TextControl.DataContext.DataConstants.TEXT_CONTROL);

            if (textControl == null)
            {
                return;
            }

            var shellLocks          = solution.GetComponent <IShellLocks>();
            var lifetimeDefinition  = Lifetimes.Define(EternalLifetime.Instance, "ZenCodingWrap");
            var lifetime            = lifetimeDefinition.Lifetime;
            var windowContextSource = context.GetData(DataConstants.PopupWindowContextSource);

            // Layouter
            // Achtung! You MUST either pass the layouter to CreatePopupWindow or dispose of it, don't let it drift off
            IPopupWindowContext ctxToUse;

            if (windowContextSource != null)
            {
                IPopupWindowContext windowContext = windowContextSource.Create(lifetime);
                var ctxTextControl = windowContext as TextControlPopupWindowContext;
                ctxToUse = ctxTextControl == null
                     ? windowContext
                     : ctxTextControl.OverrideLayouter(
                    lifetime,
                    lifetimeLayouter =>
                    new DockingLayouter(lifetimeLayouter,
                                        new TextControlAnchoringRect(
                                            lifetimeLayouter,
                                            ctxTextControl.TextControl,
                                            ctxTextControl.TextControl.Caret.Offset(),
                                            shellLocks),
                                        Anchoring2D.AnchorTopOrBottom));
            }
            else
            {
                ctxToUse = solution.GetComponent <MainWindowPopupWindowContext>().Create(lifetime);
            }

            var form = new ZenCodingWrapForm(lifetime, solution.GetComponent <IThemedIconManager>());

            // Popup support
            var window = solution.GetComponent <PopupWindowManager>().CreatePopupWindow(
                lifetimeDefinition, form, ctxToUse, HideFlags.All & ~HideFlags.Scrolling);

            window.HideMethod = FormHideMethod.Visibility;
            window.Closed    +=
                (sender, args) =>
                ReentrancyGuard.Current.ExecuteOrQueue(
                    "ZenCodingWrap",
                    () =>
            {
                if (form.DialogResult == DialogResult.Cancel)
                {
                    return;
                }

                string abbr = form.TextBox.Text.Trim();
                if (abbr.IsEmpty())
                {
                    Win32Declarations.MessageBeep(MessageBeepType.Error);
                    return;
                }

                var commandProcessor           = solution.GetComponent <ICommandProcessor>();
                var documentTransactionManager = solution.GetComponent <DocumentTransactionManager>();

                using (commandProcessor.UsingCommand("ZenCodingWrap"))
                {
                    documentTransactionManager.StartTransaction("ZenCodingWrap");

                    TextRange selection = textControl.Selection.OneDocRangeWithCaret();
                    if (!solution.IsValid())
                    {
                        return;
                    }

                    int insertPoint;
                    IProjectFile projectFile = textControl.GetProjectFile(solution);
                    string expanded          = GetEngine(solution).WrapWithAbbreviation
                                                   (abbr, textControl.Document.GetText(selection), GetDocTypeForFile(projectFile), out insertPoint);
                    CheckAndIndent(solution, projectFile, textControl, selection, expanded, insertPoint);

                    documentTransactionManager.CommitTransaction(null);
                }
            });
            window.ShowWindow();
        }