Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
FDscend authored Jul 24, 2023
1 parent 91ae24c commit 0ffde25
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 14 deletions.
65 changes: 60 additions & 5 deletions Ribbon1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public partial class Ribbon1
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_ChangeChar = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };
private Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> HwndPaneDic_CharMatch = new Dictionary<int, Microsoft.Office.Tools.CustomTaskPane> { };

//侧面板
Microsoft.Office.Tools.CustomTaskPane FileTabPane;
Microsoft.Office.Tools.CustomTaskPane tableColoringPane;
Microsoft.Office.Tools.CustomTaskPane changCharPane;
Expand All @@ -90,6 +91,9 @@ public partial class Ribbon1
int paraShandingChoice = 1;
int styleShadingChoice = 1;

//标签栏
static int fileTabPaneHeight = 83;
public List<string> DocNamesList = new List<string>();


public static JObject ImportJSON(string jsonfile)
Expand Down Expand Up @@ -1816,7 +1820,13 @@ private void RefreshFileTabPane(int HwndInt)
{
//重新绑定面板
//MessageBox.Show(app.Documents[1].Name);



//保持标签顺序
DocNamesList = TabForm.DocNamesList_pane;
Doc2List();


if (HwndPaneDic_tab.ContainsKey(HwndInt))
{
//FileTabPane = HwndPaneDic[HwndInt];
Expand All @@ -1826,7 +1836,7 @@ private void RefreshFileTabPane(int HwndInt)
//HwndPaneDic.Remove(HwndInt);

//创建控件
UserControl FileTabPane2 = new TabForm(app.Documents);
TabForm FileTabPane2 = new TabForm(DocNamesList);
//添加控件
FileTabPane = Globals.ThisAddIn.CustomTaskPanes.Add(FileTabPane2, "分点标签栏");
//设置在上方显示
Expand All @@ -1837,7 +1847,7 @@ private void RefreshFileTabPane(int HwndInt)
//MessageBox.Show("2:"+Globals.ThisAddIn.Application.ActiveWindow.Width.ToString());
if (2* Globals.ThisAddIn.Application.ActiveWindow.Width > 129* app.Documents.Count)//放大倍数,窗口尺寸和实际不符
{
FileTabPane.Height = 83;
FileTabPane.Height = fileTabPaneHeight;
//MessageBox.Show("FileTabPane.Width> 129* app.Documents.Count");
}
else
Expand All @@ -1855,7 +1865,7 @@ private void RefreshFileTabPane(int HwndInt)
else
{
//创建控件
UserControl FileTabPane2 = new TabForm(app.Documents);
TabForm FileTabPane2 = new TabForm(DocNamesList);
//添加控件
FileTabPane = Globals.ThisAddIn.CustomTaskPanes.Add(FileTabPane2, "分点标签栏");
//设置在上方显示
Expand All @@ -1865,7 +1875,7 @@ private void RefreshFileTabPane(int HwndInt)
//设置高度
if (2* Globals.ThisAddIn.Application.ActiveWindow.Width > 129 * app.Documents.Count)
{
FileTabPane.Height = 83;
FileTabPane.Height = fileTabPaneHeight;
//MessageBox.Show("FileTabPane.Width> 129* app.Documents.Count");
}
else
Expand Down Expand Up @@ -1909,6 +1919,11 @@ private void CustomPane_WindowActivate(Word.Document Doc, Word.Window WD)
//app = Globals.ThisAddIn.Application;
//string DocName = Doc.Name;


//保持标签栏高度
fileTabPaneHeight = FileTabPane.Height;


int TempHwnd = WD.Hwnd;
RefreshFileTabPane(TempHwnd);
//设置面板可见性
Expand Down Expand Up @@ -2285,6 +2300,46 @@ private void SettingBt_Click(object sender, RibbonControlEventArgs e)
}

}

private void Doc2List()
{
//文档列表转列表,以及更新列表内容

int DocNums = app.Documents.Count;
for (int i = 1; i <= DocNums; i++)
{
if (!DocNamesList.Contains(app.Documents[i].Path + "\\" + app.Documents[i].Name))
{
DocNamesList.Add(app.Documents[i].Path + "\\" + app.Documents[i].Name);
}
}

foreach (string docname in DocNamesList)
{
if (!boolDocsContain(docname))
{
DocNamesList.Remove(docname);
}
}
}

private bool boolDocsContain(string doc_name)
{
//判断是否含有某个文档

int DocNums = app.Documents.Count;
for (int i = 1; i <= DocNums; i++)
{
if (doc_name == (app.Documents[i].Path + "\\" + app.Documents[i].Name))
{
return true;
}
}

return false;
}


}
}

2 changes: 2 additions & 0 deletions SettingForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ private void button1_Click(object sender, EventArgs e)

checkedListBox1.Items.Clear();
loadList();

textBox1.Text = "";
}
}

Expand Down
104 changes: 95 additions & 9 deletions TabForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,38 +21,48 @@ public partial class TabForm : UserControl
Color ColorSelected = Color.FromArgb(255, 255, 255);
Color ColorNoSelected = Color.FromArgb(230, 231, 232);

public TabForm(Word.Documents Docs)
static public List<string> DocNamesList_pane = new List<string>();


public TabForm(List<string> Docs)
{
InitializeComponent();


DocNums = Docs.Count;
DocNamesList_pane = Docs;


if(DocNums>1)
if (DocNums>1)
{
Button[] buttonNew = new Button[DocNums-1];
for(int i=0;i< DocNums - 1;i++)
for (int i = 0; i < DocNums - 1; i++)
{
buttonNew[i] = new Button();
buttonNew[i].Text = System.IO.Path.GetFileNameWithoutExtension(Docs[DocNums - 1-i].Name);
buttonNew[i].Text = System.IO.Path.GetFileNameWithoutExtension(Docs[DocNums - 2 - i]);
buttonNew[i].Size = new Size(sizeX, sizeY);
buttonNew[i].Name = "checkBox" + (i + 2).ToString();
buttonNew[i].Name = "button" + (i + 2).ToString();
buttonNew[i].BackColor = ColorNoSelected;
buttonNew[i].Location = new Point((i + 1) * sizeX, 0);
buttonNew[i].Visible = true;
buttonNew[i].Parent = this;
buttonNew[i].Click += new System.EventHandler(this.button1_Click);
this.Controls.Add(buttonNew[i]);
toolTip1.SetToolTip(buttonNew[i], Docs[DocNums - 1 - i].Path + "\\" + Docs[DocNums - 1 - i].Name);
toolTip1.SetToolTip(buttonNew[i], Docs[DocNums - 2 - i]);

buttonNew[i].MouseDown += button1_MouseDown;
buttonNew[i].MouseMove += button1_MouseMove;
}

}


button1.Text = System.IO.Path.GetFileNameWithoutExtension(Docs[DocNums].Name);
button1.Text = System.IO.Path.GetFileNameWithoutExtension(Docs[DocNums - 1]);
button1.BackColor = ColorNoSelected;
toolTip1.SetToolTip(button1, Docs[DocNums].Path + "\\" + Docs[DocNums].Name);
toolTip1.SetToolTip(button1, Docs[DocNums - 1]);

button1.MouseDown += button1_MouseDown;
button1.MouseMove += button1_MouseMove;


//遍历标签
Expand All @@ -64,7 +74,7 @@ public TabForm(Word.Documents Docs)
//}
if (ctrl is Button)
{
if (Docs.Application.ActiveDocument.Path + "\\" + Docs.Application.ActiveDocument.Name == toolTip1.GetToolTip(ctrl))
if (Globals.ThisAddIn.Application.ActiveDocument.Path + "\\" + Globals.ThisAddIn.Application.ActiveDocument.Name == toolTip1.GetToolTip(ctrl))
{
ctrl.BackColor = ColorSelected;
}
Expand Down Expand Up @@ -105,5 +115,81 @@ private void button1_Click(object sender, EventArgs e)

//MessageBox.Show(button.Name.Substring(button.Name.Length-1,1));
}

private Button b;
private Point location;

private void button1_MouseDown(object sender, MouseEventArgs e)
{
location = e.Location;
b = sender as Button;

//右键关闭文档
if (e.Button == MouseButtons.Right)
{
Globals.ThisAddIn.Application.ActiveDocument.Save();

Object saveChanges = Word.WdSaveOptions.wdSaveChanges;
Object originalFormat = Type.Missing;
Object routeDocument = Type.Missing;

Globals.ThisAddIn.Application.ActiveDocument.Close(ref saveChanges, ref originalFormat, ref routeDocument);

//若已经没有文档存在,则关闭应用程序
if (Globals.ThisAddIn.Application.Documents.Count == 0)
{
Globals.ThisAddIn.Application.Quit(Type.Missing, Type.Missing, Type.Missing);
}
}
}


private void button1_MouseMove(object sender, MouseEventArgs e)
{
Button button = (Button)sender;

string doc0 = toolTip1.GetToolTip(button);
string doc1;

int pos_x0 = button.Location.X;
int pos_x;

if (DocNums > 1)
{
if (e.Button == MouseButtons.Left)
{
pos_x = b.Location.X + (e.X - location.X);

pos_x = ((int)(pos_x / sizeX)) * sizeX; //移动整数个标签位置

foreach (Control ctrl in this.Controls)
{
if (ctrl is Button)
{
if (ctrl.Location.X == pos_x)
{
ctrl.Location = new Point(pos_x0, 0);

b.Location = new Point(pos_x, 0);


doc1 = toolTip1.GetToolTip(ctrl);

int index0 = DocNamesList_pane.FindIndex(x => x == doc0);
int index1 = DocNamesList_pane.FindIndex(x => x == doc1);

string temp = DocNamesList_pane[index0];
DocNamesList_pane[index0] = DocNamesList_pane[index1];
DocNamesList_pane[index1] = temp;
}
}
}
}
}

}



}
}

0 comments on commit 0ffde25

Please sign in to comment.