first commit
This commit is contained in:
62
EmoneyInteceptor/Fiddler/Models/PluginViewController.cs
Normal file
62
EmoneyInteceptor/Fiddler/Models/PluginViewController.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Fiddler;
|
||||
using EmoneyInteceptor.Fiddler.Interfaces;
|
||||
|
||||
namespace EmoneyInteceptor.Fiddler.Models
|
||||
{
|
||||
internal class PluginViewController
|
||||
{
|
||||
private static readonly IList<IFiddlerLayout> FiddlerLayoutViews = new List<IFiddlerLayout>();
|
||||
|
||||
public static void InsertFiddlerTabPage(IFiddlerViewProvider fiddlerViewProvider)
|
||||
{
|
||||
// 提供 fiddler 窗口变化的支持
|
||||
FiddlerApplication.UI.tabsViews.SizeChanged += TabsViewsOnSizeChanged;
|
||||
foreach (FiddlerTabPage fiddlerTabPage in fiddlerViewProvider.BuildFiddlerTabPages())
|
||||
{
|
||||
InsertFiddlerTabPage(fiddlerTabPage);
|
||||
}
|
||||
}
|
||||
|
||||
private static void InsertFiddlerTabPage(FiddlerTabPage fiddlerTabPage)
|
||||
{
|
||||
// new tab
|
||||
System.Windows.Forms.TabPage tabPage = new System.Windows.Forms.TabPage(fiddlerTabPage.TabTitle) { ImageIndex = (int)fiddlerTabPage.TabIcon };
|
||||
|
||||
if (fiddlerTabPage.WinFormUserControl != null)
|
||||
{
|
||||
InsertWinFormTabPage(tabPage, fiddlerTabPage.WinFormUserControl);
|
||||
}
|
||||
|
||||
UpdateViewSize();
|
||||
}
|
||||
|
||||
private static void InsertWinFormTabPage(System.Windows.Forms.TabPage tabPage, System.Windows.Forms.UserControl userControl)
|
||||
{
|
||||
// add view to tab
|
||||
tabPage.Controls.Add(userControl);
|
||||
// add tab to fiddler
|
||||
FiddlerApplication.UI.tabsViews.TabPages.Add(tabPage);
|
||||
|
||||
if (userControl is IFiddlerLayout layout)
|
||||
{
|
||||
FiddlerLayoutViews.Add(layout);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TabsViewsOnSizeChanged(object sender, EventArgs e)
|
||||
{
|
||||
UpdateViewSize();
|
||||
}
|
||||
|
||||
private static void UpdateViewSize()
|
||||
{
|
||||
System.Drawing.Size size = FiddlerApplication.UI.tabsViews.Size;
|
||||
foreach (IFiddlerLayout view in FiddlerLayoutViews)
|
||||
{
|
||||
view.OnTabViewSizeChanged(size);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user