Пример #1
0
        // 我们让公共方法具有此行为,以便
        // 能够独立于 NewInspector 事件调用该行为。
        // 目的是为了允许争用条件,
        // 在此条件下可以在挂钩 NewInspector 事件之前进行
        // 功能区回调。
        public Office.Core.CustomTaskPane CreateTaskPane(
            Outlook.Inspector inspector)
        {
            Office.Core.CustomTaskPane taskpane = null;

            try
            {
                // 创建一个新的任务窗格,并将其宽度设置为与
                // SimpleControl 宽度匹配。
                taskpane = _taskPaneConnector.CreateTaskPane(
                    _controlProgId, _controlTitle, inspector);
                if (taskpane != null)
                {
                    taskpane.Width = 230;

                    // 将任务窗格映射到检查器,并将其缓存
                    // 在集合中。
                    _uiElements.Add(new UserInterfaceContainer(
                                        inspector, taskpane, _ribbonConnector));
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            return(taskpane);
        }
        // We factor this behavior out to a public method, so that
        // it can be called independently of the NewInspector event.
        // This is to allow for the race condition where ribbon
        // callbacks can come in before the NewInspector event is
        // hooked up.
        public Office.Core.CustomTaskPane CreateTaskPane(
            Outlook.Inspector inspector)
        {
            Office.Core.CustomTaskPane taskpane = null;

            try
            {
                // Create a new task pane, and set its width to match our
                // SimpleControl width.
                taskpane = _taskPaneConnector.CreateTaskPane(
                    _controlProgId, _controlTitle, inspector);
                if (taskpane != null)
                {
                    taskpane.Width = 230;

                    // Map the task pane to the inspector and cache it
                    // in our collection.
                    _uiElements.Add(new UserInterfaceContainer(
                                        inspector, taskpane, _ribbonConnector));
                }
            }
            catch (COMException ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            return(taskpane);
        }
        public Office.Core.CustomTaskPane GetTaskPaneForInspector(
            Outlook.Inspector inspector)
        {
            Office.Core.CustomTaskPane taskpane = null;

            foreach (UserInterfaceContainer uic in _items)
            {
                if (uic.Inspector == inspector)
                {
                    taskpane = uic.TaskPane;
                    break;
                }
            }
            return(taskpane);
        }
Пример #4
0
        public UserInterfaceContainer(
            Outlook.Inspector inspector,
            Office.Core.CustomTaskPane taskPane,
            IRibbonConnector ribbonConnector)
        {
            if (inspector != null)
            {
                _inspector       = inspector;
                _taskPane        = taskPane;
                _ribbonConnector = ribbonConnector;

                // Sink the InspectorClose event so that we can clean up.
                _inspectorEvents        = (Outlook.InspectorEvents_10_Event)_inspector;
                _inspectorEvents.Close +=
                    new Outlook.InspectorEvents_10_CloseEventHandler(
                        _inspectorEvents_Close);
            }
        }
Пример #5
0
        public UserInterfaceContainer(
            Outlook.Inspector inspector,
            Office.Core.CustomTaskPane taskPane,
            IRibbonConnector ribbonConnector)
        {
            if (inspector != null)
            {
                _inspector       = inspector;
                _taskPane        = taskPane;
                _ribbonConnector = ribbonConnector;

                // 接收 InspectorClose 事件以便我们能够进行清理。
                _inspectorEvents        = (Outlook.InspectorEvents_10_Event)_inspector;
                _inspectorEvents.Close +=
                    new Outlook.InspectorEvents_10_CloseEventHandler(
                        _inspectorEvents_Close);
            }
        }
Пример #6
0
        public UserInterfaceContainer(
            Outlook.Inspector inspector,
            Office.Core.CustomTaskPane taskPane,
            IRibbonConnector ribbonConnector)
        {
            if (inspector != null)
            {
                _inspector = inspector;
                _taskPane = taskPane;
                _ribbonConnector = ribbonConnector;

                // 接收 InspectorClose 事件以便我们能够进行清理。
                _inspectorEvents = (Outlook.InspectorEvents_10_Event)_inspector;
                _inspectorEvents.Close +=
                    new Outlook.InspectorEvents_10_CloseEventHandler(
                    _inspectorEvents_Close);
            }
        }
Пример #7
0
        void _inspectorEvents_Close()
        {
            // Remove ourselves from the collection of UI objects,
            // unhook the Close event, and clean up all references.
            _inspectorEvents.Close -=
                new Outlook.InspectorEvents_10_CloseEventHandler(
                    _inspectorEvents_Close);

            if (InspectorClose != null)
            {
                // Tell anyone who's listening that we're being closed.
                InspectorClose(this, new EventArgs());
            }

            _inspector          = null;
            _inspectorEvents    = null;
            _taskPane           = null;
            _formRegionControls = null;
            _ribbonConnector    = null;
        }
Пример #8
0
        void _inspectorEvents_Close()
        {
            // 将我们自身从 UI 对象集合中移除,
            // 解除挂钩关闭事件,然后清理所有引用。
            _inspectorEvents.Close -=
                new Outlook.InspectorEvents_10_CloseEventHandler(
                    _inspectorEvents_Close);

            if (InspectorClose != null)
            {
                // 告诉所有侦听方我们正在关闭。
                InspectorClose(this, new EventArgs());
            }

            _inspector          = null;
            _inspectorEvents    = null;
            _taskPane           = null;
            _formRegionControls = null;
            _ribbonConnector    = null;
        }
Пример #9
0
        private String GetTextFromTaskPane(Outlook.Inspector inspector)
        {
            String coffeeText = null;

            if (inspector != null)
            {
                // Get the usercontrol in the task pane.
                Office.Core.CustomTaskPane taskpane =
                    Globals.ThisAddIn._uiElements.GetTaskPaneForInspector(inspector);
                SimpleControl sc = (SimpleControl)taskpane.ContentControl;

                // Compose the mail body from the strings in the task pane listbox.
                StringBuilder builder = new StringBuilder();
                foreach (string s in sc._coffeeList.Items)
                {
                    builder.AppendLine(s);
                }
                coffeeText = builder.ToString();
            }

            return(coffeeText);
        }
Пример #10
0
        private String GetTextFromTaskPane(Outlook.Inspector inspector)
        {
            String coffeeText = null;

            if (inspector != null)
            {
                // 获取任务窗格中的用户控件。
                Office.Core.CustomTaskPane taskpane =
                    Globals.ThisAddIn._uiElements.GetTaskPaneForInspector(inspector);
                SimpleControl sc = (SimpleControl)taskpane.ContentControl;

                // 在任务窗格列表框中使用字符串撰写邮件正文。
                StringBuilder builder = new StringBuilder();
                foreach (string s in sc._coffeeList.Items)
                {
                    builder.AppendLine(s);
                }
                coffeeText = builder.ToString();
            }

            return(coffeeText);
        }
Пример #11
0
        public void OnToggleTaskPane(
            Office.Core.IRibbonControl control, bool isPressed)
        {
            // Toggle the visibility of the custom taskpane.
            if (control != null)
            {
                // Find the inspector for this ribbon, so that we can find the
                // corresponding task pane from our collection.
                Outlook.Inspector inspector =
                    (Outlook.Inspector)control.Context;
                Office.Core.CustomTaskPane taskpane =
                    Globals.ThisAddIn._uiElements.GetTaskPaneForInspector(
                        inspector);

                // If we've been called before we've had a chance to add this
                // Inspector/task pane to the collection, we can add it now.
                if (taskpane == null)
                {
                    taskpane = Globals.ThisAddIn.CreateTaskPane(inspector);
                }

                taskpane.Visible = isPressed;
            }
        }
Пример #12
0
        public void OnToggleTaskPane(
            Office.Core.IRibbonControl control, bool isPressed)
        {
            // 切换自定义任务窗格的可见性。
            if (control != null)
            {
                // 查找此功能区的检查器,以便我们能够从集合中找到
                // 对应的任务窗格。
                Outlook.Inspector inspector =
                    (Outlook.Inspector)control.Context;
                Office.Core.CustomTaskPane taskpane =
                    Globals.ThisAddIn._uiElements.GetTaskPaneForInspector(
                        inspector);

                // 如果我们在有机会将此
                // 检查器/任务窗格添加到集合中之前已被调用,则我们可以现在添加窗格。
                if (taskpane == null)
                {
                    taskpane = Globals.ThisAddIn.CreateTaskPane(inspector);
                }

                taskpane.Visible = isPressed;
            }
        }
Пример #13
0
        void _inspectorEvents_Close()
        {
            // 将我们自身从 UI 对象集合中移除,
            // 解除挂钩关闭事件,然后清理所有引用。
            _inspectorEvents.Close -=
                new Outlook.InspectorEvents_10_CloseEventHandler(
                _inspectorEvents_Close);

            if (InspectorClose != null)
            {
                // 告诉所有侦听方我们正在关闭。
                InspectorClose(this, new EventArgs());
            }

            _inspector = null;
            _inspectorEvents = null;
            _taskPane = null;
            _formRegionControls = null;
            _ribbonConnector = null;
        }