コード例 #1
0
        /// <summary>
        /// Inserts the snip into OneNote
        /// </summary>
        /// <param name="imageFilePath"></param>
        /// <param name="publishUrl"></param>
        /// <returns>bool on success or failure. Null if the user cancelled</returns>
        internal bool?InsertSnip(string imageFilePath, string publishUrl = null)
        {
            // Quick Filing dialog box interfaces (OneNote 2013) --> https://msdn.microsoft.com/EN-US/library/office/jj680122.aspx

            try
            {
                if (!Initialize(imageFilePath, publishUrl))
                {
                    return(false);
                }

                OneNote.IQuickFilingDialog qfDialog = _oneNoteApp.QuickFiling();

                qfDialog.Title              = Properties.Resources.SendToOneNoteDialogTitle;
                qfDialog.Description        = Properties.Resources.SendToOneNoteDialogDescription;
                qfDialog.TreeDepth          = OneNote.HierarchyElement.hePages;
                qfDialog.ParentWindowHandle = (ulong)new WindowInteropHelper(AppManager.TheBoss.MainWindow).Handle.ToInt64(); // sets the dialog modal to the editor window

                qfDialog.SetRecentResults(OneNote.RecentResultType.rrtFiling, true, true, false);

                // add a 'Send To' button, it will have index 0 since its the first button we added
                qfDialog.AddButton(Properties.Resources.SendToOneNoteDialogSendToButton, OneNote.HierarchyElement.heSections | OneNote.HierarchyElement.hePages, OneNote.HierarchyElement.heNone, true);

                // watch for the OneNote process to exit since the QuickFilingDialog is modal to the MainWindow, which will cause Snip to hang if OneNote is killed while the QuickFilingDialog is being displayed
                WatchForOneNoteProcessExit();

                qfDialog.Run(this); // OnDialogClosed() callback is called just after the user makes a selction and finishes running the dialog

                // wait for the OnDialogClosed() callback thread to complete the insert
                _insertCompleteEvent.WaitOne();

                if (_cancelled)
                {
                    return(null);
                }

                // check for an exception raised from the Insert code ran in the OnDialogClosed() callback thread
                if (_insertException != null)
                {
                    Diagnostics.LogException(_insertException);
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                Diagnostics.LogException(ex);
                return(false);
            }
        }
コード例 #2
0
 public void OnDialogClosed(OneNote.IQuickFilingDialog qfDialog)
 {
     try
     {
         if (qfDialog.PressedButton == 0) // 0 is the index for the 'Send To' button we added to the dialog
         {
             InsertSnipIntoSelectedObject(qfDialog.SelectedItem);
         }
         else
         {
             _cancelled = true;
         }
     }
     finally
     {
         _insertCompleteEvent.Set();
     }
 }