/CurrentDev/OutlookDataExport/OutlookDataExport/ThisAddIn.cs
C# | 251 lines | 188 code | 52 blank | 11 comment | 4 complexity | ad1b89f5b0cbd0f7278acc19ad1ba155 MD5 | raw file
- using System;
- using System.ComponentModel;
- using System.Diagnostics;
- using OutlookDataExport.BusinessLayer;
- using OutlookDataExport.PresentationLayer;
- using OutlookDataExport.PresentationLayer.Images;
- using OutlookDataExport.PresentationLayer.Menu;
- using Office = Microsoft.Office.Core;
- using Outlook = Microsoft.Office.Interop.Outlook;
-
- namespace OutlookDataExport
- {
- public partial class ThisAddIn
- {
- /************************************************************************************************************************/
- #region Fields
-
- private static Outlook.Application s_OlApplication = null;
- private static ExceptionHandler exceptionHandler = ExceptionHandler.GetInstance();
-
- #if !Outlook2010
-
- private Office.CommandBar m_CommandBar = null;
- private Office.CommandBarPopup m_CommandBarPopup = null;
- private Office.CommandBarButton m_BtnExportSelection = null;
- private Office.CommandBarButton m_BtnExportAll = null;
- private Office.CommandBarButton m_BtnInfo = null;
- private Office.CommandBarButton m_BtnUserGuide = null;
- private Office.CommandBarButton m_BtnAskForHelp = null;
- private Office.CommandBarButton m_BtnWebsite = null;
- private Office.CommandBarButton m_BtnDonate = null;
-
- #endif
-
- #endregion
- /************************************************************************************************************************/
-
-
- /************************************************************************************************************************/
- #region Event Handler
-
- private void ThisAddIn_Startup(object sender, System.EventArgs e)
- {
- Init();
- }
-
- /// <summary>
- /// Shutdown code for this add-in.
- /// </summary>
- /// <param name="sender">Event sender.</param>
- /// <param name="e">Event arguments.</param>
- private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
- {
- }
-
- #if !Outlook2010
-
- private void btnExportSelection_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ExportSelection();
- }
-
- private void btnExportAll_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ExportAll();
- }
-
- private void btnInfo_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ShowInfo();
- }
-
- private void btnUserGuide_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ShowUserGuide();
- }
-
- private void btnAskForHelp_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ShowAskForHelp();
- }
-
- private void btnWebsite_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ShowWebsite();
- }
-
- private void btnDonate_Click(Office.CommandBarButton Ctrl, ref bool CancelDefault)
- {
- Menu.ShowDonate();
- }
-
- #endif
-
- #endregion
- /************************************************************************************************************************/
-
-
- /************************************************************************************************************************/
- #region Methods
-
- private void InternalStartup()
- {
- exceptionHandler.Init();
- this.Startup += new System.EventHandler(ThisAddIn_Startup);
- this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
- }
-
- private void Init()
- {
- try
- {
- s_OlApplication = this.Application;
-
- #if Outlook2010
-
- string version = "14";
-
- #else
-
- string version = "14";
-
- #endif
-
- if (!this.Application.Version.StartsWith(version))
- {
- Dialog.ShowError("This version of Outlook Data Export doesn't support the installed Microsoft Outlook " +
- "version. Please uninstall this add-in.\n\nThe add-in will be deactivated.");
-
- foreach (Office.COMAddIn addIn in this.Application.COMAddIns)
- {
- if ("OutlookDataExport".Equals(addIn.ProgId))
- {
- addIn.Connect = false;
- }
- }
- }
- else
- {
- Menu.SetOlApplication(this.Application);
-
- #if !Outlook2010
-
- CreateMenu();
-
- #endif
- }
- }
- catch (Exception ex)
- {
- Dialog.ShowError(ex.Message);
- }
- }
-
- public static Outlook.Application GetOlApplication()
- {
- return s_OlApplication;
- }
-
- #if Outlook2010
-
- protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
- {
- return new Ribbon();
- }
-
- #else
-
- public void CreateMenu()
- {
- if (s_OlApplication.ActiveExplorer() != null)
- {
- object missing = Type.Missing;
- ComponentResourceManager resManager = new ComponentResourceManager(typeof(ImageResources));
-
- m_CommandBar = s_OlApplication.ActiveExplorer().CommandBars.ActiveMenuBar;
-
- m_CommandBarPopup = (Office.CommandBarPopup)m_CommandBar.Controls
- .Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, true);
- m_CommandBarPopup.Caption = "Outlook data ex&port";
-
- m_BtnExportSelection = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnExportSelection.Caption = "Export &selection";
- m_BtnExportSelection.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnExportSelection_Click);
- m_BtnExportSelection.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnExportSelection.Picture = IconConverter.Convert(resManager.GetObject("Export_16x16"));
-
- m_BtnExportAll = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnExportAll.Caption = "Export &all";
- m_BtnExportAll.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnExportAll_Click);
- m_BtnExportAll.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnExportAll.Picture = IconConverter.Convert(resManager.GetObject("Export_16x16"));
-
- m_BtnInfo = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnInfo.Caption = "&Info";
- m_BtnInfo.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnInfo_Click);
- m_BtnInfo.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnInfo.Picture = IconConverter.Convert(resManager.GetObject("Info_16x16"));
-
- m_BtnUserGuide = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnUserGuide.Caption = "User &guide";
- m_BtnUserGuide.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnUserGuide_Click);
- m_BtnUserGuide.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnUserGuide.Picture = IconConverter.Convert(resManager.GetObject("Help_16x16"));
-
- m_BtnAskForHelp = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnAskForHelp.Caption = "Ask for &help";
- m_BtnAskForHelp.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnAskForHelp_Click);
- m_BtnAskForHelp.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnAskForHelp.Picture = IconConverter.Convert(resManager.GetObject("AskForHelp_16x16"));
-
- m_BtnWebsite = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnWebsite.Caption = "&Website";
- m_BtnWebsite.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnWebsite_Click);
- m_BtnWebsite.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnWebsite.Picture = IconConverter.Convert(resManager.GetObject("Website_16x16"));
-
- m_BtnDonate = (Office.CommandBarButton)m_CommandBarPopup.Controls
- .Add(Office.MsoControlType.msoControlButton, missing, missing, missing, true);
- m_BtnDonate.Caption = "&Donate";
- m_BtnDonate.Click += new Office._CommandBarButtonEvents_ClickEventHandler(btnDonate_Click);
- m_BtnDonate.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
- m_BtnDonate.Picture = IconConverter.Convert(resManager.GetObject("Donate_16x16"));
- }
- }
-
- private class IconConverter : System.Windows.Forms.AxHost
- {
- private IconConverter()
- : base(string.Empty)
- {
- }
-
- public static stdole.IPictureDisp Convert(object image)
- {
- return (stdole.IPictureDisp)GetIPictureDispFromPicture((System.Drawing.Image)image);
- }
- }
-
- #endif
-
- #endregion
- /************************************************************************************************************************/
- }
- }