Exemplo n.º 1
0
        /// <summary>
        ///      Implements the OnConnection method of the IDTExtensibility2 interface.
        ///      Receives notification that the Add-in is being loaded.
        /// </summary>
        /// <param term='application'>
        ///      Root object of the host application.
        /// </param>
        /// <param term='connectMode'>
        ///      Describes how the Add-in is being loaded.
        /// </param>
        /// <param term='addInInst'>
        ///      Object representing this Add-in.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public virtual void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
        {
            this._application = new LateBindingObject(application);

            // read Office version info
            int version;

            using (new UILanguageHelper())
            {
                int.TryParse(_application.GetString("Version"),
                             NumberStyles.Float,
                             CultureInfo.InvariantCulture,
                             out version);
                _officeVersion = (OfficeVersion)version;
            }

            Application.EnableVisualStyles();

            this.SetUICulture();

            this.DialogBoxTitle = _addinLib.GetString("OdfConverterTitle");

            LateBindingObject addInInstance = new LateBindingObject(addInInst);

            addInInstance.Set("Object", (object)this);

            if (connectMode != Extensibility.ext_ConnectMode.ext_cm_Startup)
            {
                OnStartupComplete(ref custom);
            }
        }
Exemplo n.º 2
0
        protected virtual string[] getOpenFileNames()
        {
            string[] fileNames = null;

            if (_officeVersion > OfficeVersion.Office2000 && _officeVersion != OfficeVersion.Office2010)
            {
                LateBindingObject fileDialog = _application.Invoke("FileDialog", MsoFileDialogType.msoFileDialogFilePicker);

                // allow multiple file opening
                fileDialog.SetBool("AllowMultiSelect", true);

                // add filter for ODT files
                fileDialog.Invoke("Filters").Invoke("Clear");
                fileDialog.Invoke("Filters").Invoke("Add", this._addinLib.GetString(this.OdfFileType), this.ImportOdfFileFilter, Type.Missing);
                fileDialog.Invoke("Filters").Invoke("Add", this._addinLib.GetString(ALL_FILE_TYPE), this.ImportAllFileFilter, Type.Missing);
                // set title
                fileDialog.SetString("Title", this._addinLib.GetString(IMPORT_LABEL));
                // display the dialog
                fileDialog.Invoke("Show");

                if (fileDialog.Invoke("SelectedItems").GetInt32("Count") > 0)
                {
                    fileNames = new string[fileDialog.Invoke("SelectedItems").GetInt32("Count")];
                    // process the chosen documents
                    for (int i = 0; i < fileDialog.Invoke("SelectedItems").GetInt32("Count"); i++)
                    {
                        // retrieve file name
                        fileNames[i] = fileDialog.Invoke("SelectedItems").Invoke("Item", i + 1).ToString();
                    }
                }
            }
            else
            {
                // Office 2000 does not provide its own file open dialog
                // using windows forms instead
                System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();

                ofd.CheckPathExists = true;
                ofd.CheckFileExists = true;
                ofd.Multiselect     = true;
                ofd.SupportMultiDottedExtensions = true;
                ofd.DefaultExt = "odt";
                ofd.Filter     = this._addinLib.GetString(this.OdfFileType) + this.ExportOdfFileFilter
                                 + this._addinLib.GetString(ALL_FILE_TYPE) + this.ExportAllFileFilter;

                ofd.Title = this._addinLib.GetString(IMPORT_LABEL);

                // process the chosen documents
                if (System.Windows.Forms.DialogResult.OK == ofd.ShowDialog())
                {
                    fileNames = ofd.FileNames;
                }
            }

            return(fileNames);
        }
Exemplo n.º 3
0
        /// <summary>
        ///      Implements the OnBeginShutdown method of the IDTExtensibility2 interface.
        ///      Receives notification that the host application is being unloaded.
        /// </summary>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public virtual void OnBeginShutdown(ref System.Array custom)
        {
            if (_officeVersion < OfficeVersion.Office2007)
            {
                // remove menu items (use FindControl instead of referenced object
                // in order to actually remove the items - this is a workaround)
                LateBindingObject button = _application.Invoke("CommandBars").Invoke("FindControl", Type.Missing, Type.Missing, this._addinLib.GetString("OdfImportLabel"), Type.Missing);
                button.Invoke("Delete", Type.Missing);

                button = _application.Invoke("CommandBars").Invoke("FindControl", Type.Missing, Type.Missing, this._addinLib.GetString("OdfExportLabel"), Type.Missing);
                button.Invoke("Delete", Type.Missing);

                button = _application.Invoke("CommandBars").Invoke("FindControl", Type.Missing, Type.Missing, this._addinLib.GetString("OdfOptionsLabel"), Type.Missing);
                button.Invoke("Delete", Type.Missing);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        ///      Implements the OnStartupComplete method of the IDTExtensibility2 interface.
        ///      Receives notification that the host application has completed loading.
        /// </summary>
        /// <param term='custom'>
        ///      Array of parameters that are host application specific.
        /// </param>
        /// <seealso class='IDTExtensibility2' />
        public virtual void OnStartupComplete(ref System.Array custom)
        {
            if (_officeVersion < OfficeVersion.Office2007)
            {
                // Add menu item
                // first retrieve "File" menu
                LateBindingObject commandBar = _application.Invoke("CommandBars", "File");

                // Add import button
                try
                {
                    // if item already exists, use it (should never happen)
                    _importButton = commandBar.Invoke("Controls", this._addinLib.GetString("OdfImportLabel"));
                }
                catch (Exception)
                {
                    // otherwise, create a new one
                    _importButton = commandBar.Invoke("Controls")
                                    .Invoke("Add", MsoControlType.msoControlButton, Type.Missing, Type.Missing, 3, true);
                }
                // set item's label
                _importButton.SetString("Caption", this._addinLib.GetString("OdfImportLabel"));
                _importButton.SetString("Tag", this._addinLib.GetString("OdfImportLabel"));

                // set action
                _importButton.SetString("OnAction", "!<" + this.ConnectClassName + ">");
                _importButton.SetBool("Visible", true);

                _importButton.AddClickEventHandler(new CommandBarButtonEvents_ClickEventHandler(this.importButton_Click));

                // Add export button
                try
                {
                    // if item already exists, use it (should never happen)
                    _exportButton = commandBar.Invoke("Controls", this._addinLib.GetString("OdfExportLabel"));
                }
                catch (Exception)
                {
                    // otherwise, create a new one
                    _exportButton = commandBar.Invoke("Controls")
                                    .Invoke("Add", MsoControlType.msoControlButton, Type.Missing, Type.Missing, 4, true);
                }
                // set item's label
                _exportButton.SetString("Caption", this._addinLib.GetString("OdfExportLabel"));
                _exportButton.SetString("Tag", this._addinLib.GetString("OdfExportLabel"));
                // set action
                _exportButton.SetString("OnAction", "!<" + this.ConnectClassName + ">");
                _exportButton.SetBool("Visible", true);
                _exportButton.SetBool("Enabled", true);
                _exportButton.AddClickEventHandler(new CommandBarButtonEvents_ClickEventHandler(this.exportButton_Click));

                // Add options button
                try
                {
                    // if item already exists, use it (should never happen)
                    _optionsButton = commandBar.Invoke("Controls", this._addinLib.GetString("OdfOptionsLabel"));
                }
                catch (Exception)
                {
                    // otherwise, create a new one
                    _optionsButton = commandBar.Invoke("Controls")
                                     .Invoke("Add", MsoControlType.msoControlButton, Type.Missing, Type.Missing, 5, true);
                }
                // set item's label
                _optionsButton.SetString("Caption", this._addinLib.GetString("OdfOptionsLabel"));
                _optionsButton.SetString("Tag", this._addinLib.GetString("OdfOptionsLabel"));
                // set action
                _optionsButton.SetString("OnAction", "!<" + this.ConnectClassName + ">");
                _optionsButton.SetBool("Visible", true);
                _optionsButton.SetBool("Enabled", true);
                _optionsButton.AddClickEventHandler(new CommandBarButtonEvents_ClickEventHandler(this.odfOptionsButton_Click));
            }

            this.InitializeAddin();
        }