-
Notifications
You must be signed in to change notification settings - Fork 1
/
Class1 - 20211014.cs.bak
182 lines (157 loc) · 5.76 KB
/
Class1 - 20211014.cs.bak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
using Extensibility;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.OneNote;
using System;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Linq;
using OneNote = Microsoft.Office.Interop.OneNote;
namespace litingaddin
{
[Guid("308DEEE4-9577-431A-8940-3C1A8418BD06"), ProgId("litingaddin.Class1")]
public class Class1 : IDTExtensibility2, IRibbonExtensibility
{
private OneNote.Application onApp = new OneNote.Application();
private object application;
public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
{
application = Application;
}
public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
{
application = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
public void OnAddInsUpdate(ref Array custom)
{
}
public void OnStartupComplete(ref Array custom)
{
}
public void OnBeginShutdown(ref Array custom)
{
if (application != null)
{
application = null;
}
}
public string GetCustomUI(string RibbonID)
{
return Properties.Resources.ribbon;
}
static XNamespace ns = null;
public void tittle(IRibbonControl control)
{
OneNote.Application onenoteApp = new OneNote.Application();
string xml;
var pageid = onenoteApp.Windows.CurrentWindow.CurrentPageId;
onenoteApp.GetPageContent(pageid, out xml, OneNote.PageInfo.piAll);
var doc = XDocument.Parse(xml);
ns = doc.Root.Name.Namespace;
var outLine_title = doc.Descendants(ns + "T").FirstOrDefault();
//MessageBox.Show(outLine.Value);
XElement element =doc.Descendants(ns + "TagDef").FirstOrDefault();
var outLine_tag = element.Attribute("name").Value.ToString();
outLine_title.Value = outLine_tag +"|"+ outLine_title.Value;
onenoteApp.UpdatePageContent(doc.ToString(), System.DateTime.MinValue);
}
class CCOMStreamWrapper : IStream
{
public CCOMStreamWrapper(System.IO.Stream streamWrap)
{
m_stream = streamWrap;
}
public void Clone(out IStream ppstm)
{
ppstm = new CCOMStreamWrapper(m_stream);
}
public void Commit(int grfCommitFlags)
{
m_stream.Flush();
}
public void CopyTo(IStream pstm, long cb, IntPtr pcbRead, IntPtr pcbWritten)
{
}
public void LockRegion(long libOffset, long cb, int dwLockType)
{
throw new System.NotImplementedException();
}
public void Read(byte[] pv, int cb, IntPtr pcbRead)
{
Marshal.WriteInt64(pcbRead, m_stream.Read(pv, 0, cb));
}
public void Revert()
{
throw new System.NotImplementedException();
}
public void Seek(long dlibMove, int dwOrigin, IntPtr plibNewPosition)
{
long posMoveTo = 0;
Marshal.WriteInt64(plibNewPosition, m_stream.Position);
switch (dwOrigin)
{
case 0:
{
/* STREAM_SEEK_SET */
posMoveTo = dlibMove;
}
break;
case 1:
{
/* STREAM_SEEK_CUR */
posMoveTo = m_stream.Position + dlibMove;
}
break;
case 2:
{
/* STREAM_SEEK_END */
posMoveTo = m_stream.Length + dlibMove;
}
break;
default:
return;
}
if (posMoveTo >= 0 && posMoveTo < m_stream.Length)
{
m_stream.Position = posMoveTo;
Marshal.WriteInt64(plibNewPosition, m_stream.Position);
}
}
public void SetSize(long libNewSize)
{
m_stream.SetLength(libNewSize);
}
public void Stat(out System.Runtime.InteropServices.ComTypes.STATSTG pstatstg, int grfStatFlag)
{
pstatstg = new System.Runtime.InteropServices.ComTypes.STATSTG();
pstatstg.cbSize = m_stream.Length;
if ((grfStatFlag & 0x0001/* STATFLAG_NONAME */) != 0)
return;
pstatstg.pwcsName = m_stream.ToString();
}
public void UnlockRegion(long libOffset, long cb, int dwLockType)
{
throw new System.NotImplementedException();
}
public void Write(byte[] pv, int cb, IntPtr pcbWritten)
{
Marshal.WriteInt64(pcbWritten, 0);
m_stream.Write(pv, 0, cb);
Marshal.WriteInt64(pcbWritten, cb);
}
private System.IO.Stream m_stream;
}
public IStream GetImage(string imageName)
{
MemoryStream mem = new MemoryStream();
Properties.Resources.HelloWorld.Save(mem, ImageFormat.Png);
return new CCOMStreamWrapper(mem);
}
}
}