/// <summary>
        /// The default action for a OneNote path is to navigate OneNote to that page.
        /// </summary>
        /// <param name="path"></param>
        protected override void InvokeDefaultAction(string path)
        {
            XmlNode node = getOneNoteNode(path);

            if (node == null)
            {
                WriteInvalidPathError(path);
                return;
            }
            Microsoft.Office.Interop.OneNote.ApplicationClass app = getOneNoteApplication( );
            string id   = node.Attributes["ID"].Value;
            string name = node.Attributes["name"].Value;

            app.NavigateTo(id, "", true);
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcesses( );
            string windowTitle = String.Format("{0} - Microsoft Office OneNote", name);

            WriteVerbose("Looking for window: " + windowTitle);
            bool foundWindow = false;

            foreach (System.Diagnostics.Process p in processes)
            {
                //
                //  BUGBUG: This will only work on English.
                //

                if (!String.IsNullOrEmpty(p.MainWindowTitle))
                {
                    WriteDebug("Found window " + p.MainWindowTitle);
                }
                if ((p.MainWindowTitle == windowTitle) && (p.MainWindowHandle != (IntPtr)0))
                {
                    SetForegroundWindow(p.MainWindowHandle);
                    foundWindow = true;
                    break;
                }
            }
            if (!foundWindow)
            {
                //
                //  I'll settle for activating any OneNote window.
                //

                processes = System.Diagnostics.Process.GetProcessesByName("onenote");
                foreach (System.Diagnostics.Process p in processes)
                {
                    if (p.MainWindowHandle != (IntPtr)0)
                    {
                        SetForegroundWindow(p.MainWindowHandle);
                        break;
                    }
                }
            }
        }
        /// <summary>
        /// Clears a OneNote item. This can really only be used against Notebooks, which results
        /// in closing the notebook.
        /// </summary>
        /// <param name="path">Path to the notebook to close.</param>
        protected override void ClearItem(string path)
        {
            XmlNode notebook = getOneNoteNode(path);

            if ((notebook == null) || (notebook.LocalName != "Notebook"))
            {
                WriteInvalidPathError(path);
                return;
            }
            Microsoft.Office.Interop.OneNote.ApplicationClass app = getOneNoteApplication( );
            string id = notebook.Attributes["ID"].Value;

            app.CloseNotebook(id);
        }
        /// <summary>
        /// Removes a OneNote item.
        /// </summary>
        /// <param name="path"></param>
        /// <param name="recurse"></param>
        protected override void RemoveItem(string path, bool recurse)
        {
            XmlNode node = getOneNoteNode(path);

            if (node == null)
            {
                WriteInvalidPathError(path);
                return;
            }
            if (ShouldProcess(path))
            {
                if ((node.ChildNodes.Count > 0) && !recurse &&
                    !ShouldContinue(path + " contains children, but -recurse was not specified. Continue?", "Remove"))
                {
                    return;
                }
                Microsoft.Office.Interop.OneNote.ApplicationClass app = getOneNoteApplication( );
                app.DeleteHierarchy(node.Attributes["ID"].Value, DateTime.MinValue);
            }
        }
Esempio n. 4
0
 protected override void BeginProcessing( )
 {
     base.BeginProcessing( );
     _onenoteApplication = new ApplicationClass( );
 }
 protected override void BeginProcessing( )
 {
     base.BeginProcessing( );
     _onenoteApplication = new ApplicationClass( );
 }