1
0
mirror of https://github.com/chylex/Brotli-Builder.git synced 2025-05-03 23:34:13 +02:00

Update BrotliBuilder to use StatusStrip for when .NET removes StatusBar

This commit is contained in:
chylex 2020-02-17 11:29:22 +01:00
parent e247eda9b8
commit 3f7d4612b9
6 changed files with 158 additions and 85 deletions

View File

@ -25,13 +25,6 @@
private void InitializeComponent() {
this.components = new System.ComponentModel.Container();
this.flowPanelBlocks = new System.Windows.Forms.FlowLayoutPanel();
this.statusBar = new System.Windows.Forms.StatusBar();
this.statusBarPanelPadding1 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeStructure = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelPadding2 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeBits = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelPadding3 = new System.Windows.Forms.StatusBarPanel();
this.statusBarPanelTimeOutput = new System.Windows.Forms.StatusBarPanel();
this.timerRegenerationDelay = new System.Windows.Forms.Timer(this.components);
this.splitContainerRightBottom = new System.Windows.Forms.SplitContainer();
this.brotliFilePanelGenerated = new BrotliBuilder.Components.BrotliFilePanel();
@ -40,12 +33,6 @@
this.labelFileStructure = new System.Windows.Forms.Label();
this.splitContainerMain = new System.Windows.Forms.SplitContainer();
this.brotliMarkerInfoPanel = new BrotliBuilder.Components.BrotliMarkerInfoPanel();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding1)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeStructure)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeBits)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding3)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeOutput)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.splitContainerRightBottom)).BeginInit();
this.splitContainerRightBottom.Panel1.SuspendLayout();
this.splitContainerRightBottom.Panel2.SuspendLayout();
@ -76,58 +63,6 @@
this.flowPanelBlocks.SizeChanged += new System.EventHandler(this.flowPanelBlocks_SizeChanged);
this.flowPanelBlocks.ControlAdded += new System.Windows.Forms.ControlEventHandler(this.flowPanelBlocks_ControlAdded);
//
// statusBar
//
this.statusBar.Location = new System.Drawing.Point(0, 580);
this.statusBar.Name = "statusBar";
this.statusBar.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {
this.statusBarPanelPadding1,
this.statusBarPanelTimeStructure,
this.statusBarPanelPadding2,
this.statusBarPanelTimeBits,
this.statusBarPanelPadding3,
this.statusBarPanelTimeOutput});
this.statusBar.ShowPanels = true;
this.statusBar.Size = new System.Drawing.Size(1264, 22);
this.statusBar.SizingGrip = false;
this.statusBar.TabIndex = 1;
//
// statusBarPanelPadding1
//
this.statusBarPanelPadding1.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanelPadding1.MinWidth = 12;
this.statusBarPanelPadding1.Name = "statusBarPanelPadding1";
this.statusBarPanelPadding1.Width = 12;
//
// statusBarPanelTimeStructure
//
this.statusBarPanelTimeStructure.Name = "statusBarPanelTimeStructure";
this.statusBarPanelTimeStructure.Width = 200;
//
// statusBarPanelPadding2
//
this.statusBarPanelPadding2.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanelPadding2.MinWidth = 9;
this.statusBarPanelPadding2.Name = "statusBarPanelPadding2";
this.statusBarPanelPadding2.Width = 9;
//
// statusBarPanelTimeBits
//
this.statusBarPanelTimeBits.Name = "statusBarPanelTimeBits";
this.statusBarPanelTimeBits.Width = 200;
//
// statusBarPanelPadding3
//
this.statusBarPanelPadding3.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;
this.statusBarPanelPadding3.MinWidth = 9;
this.statusBarPanelPadding3.Name = "statusBarPanelPadding3";
this.statusBarPanelPadding3.Width = 9;
//
// statusBarPanelTimeOutput
//
this.statusBarPanelTimeOutput.Name = "statusBarPanelTimeOutput";
this.statusBarPanelTimeOutput.Width = 200;
//
// timerRegenerationDelay
//
this.timerRegenerationDelay.Interval = 300;
@ -255,7 +190,6 @@
this.BackColor = System.Drawing.SystemColors.ControlLight;
this.ClientSize = new System.Drawing.Size(1264, 602);
this.Controls.Add(this.splitContainerMain);
this.Controls.Add(this.statusBar);
this.Font = new System.Drawing.Font("Segoe UI", 9F);
this.MinimumSize = new System.Drawing.Size(480, 320);
this.Name = "FormMain";
@ -263,12 +197,6 @@
this.Resize += new System.EventHandler(this.FormMain_Resize);
this.Text = "Brotli Builder";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormMain_FormClosing);
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeStructure)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeBits)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelPadding3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTimeOutput)).EndInit();
this.splitContainerRightBottom.Panel1.ResumeLayout(false);
this.splitContainerRightBottom.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainerRightBottom)).EndInit();
@ -289,11 +217,6 @@
#endregion
private System.Windows.Forms.FlowLayoutPanel flowPanelBlocks;
private System.Windows.Forms.StatusBar statusBar;
private System.Windows.Forms.StatusBarPanel statusBarPanelTimeBits;
private System.Windows.Forms.StatusBarPanel statusBarPanelTimeOutput;
private System.Windows.Forms.StatusBarPanel statusBarPanelPadding1;
private System.Windows.Forms.StatusBarPanel statusBarPanelPadding2;
private System.Windows.Forms.Timer timerRegenerationDelay;
private System.Windows.Forms.SplitContainer splitContainerRightBottom;
private Components.BrotliFilePanel brotliFilePanelGenerated;
@ -302,7 +225,5 @@
private System.Windows.Forms.SplitContainer splitContainerMain;
private Components.BrotliMarkerInfoPanel brotliMarkerInfoPanel;
private System.Windows.Forms.Label labelFileStructure;
private System.Windows.Forms.StatusBarPanel statusBarPanelTimeStructure;
private System.Windows.Forms.StatusBarPanel statusBarPanelPadding3;
}
}

View File

@ -22,6 +22,11 @@ namespace BrotliBuilder{
private readonly BrotliFileController fileGenerated;
private readonly BrotliFileController fileOriginal;
private readonly StatusBarBase statusBar;
private readonly StatusBarBase.Panel statusBarPanelTimeStructure;
private readonly StatusBarBase.Panel statusBarPanelTimeBits;
private readonly StatusBarBase.Panel statusBarPanelTimeOutput;
public FormMain(){
InitializeComponent();
@ -40,6 +45,14 @@ namespace BrotliBuilder{
InitializeMenuEncoders(menuItemEncode);
InitializeMenuTransformers(menuItemTransform);
statusBar = DeprecatedControls.CreateStatusBar(this);
statusBar.AddPadding(12);
statusBarPanelTimeStructure = statusBar.AddPanel(200);
statusBar.AddPadding(9);
statusBarPanelTimeBits = statusBar.AddPanel(200);
statusBar.AddPadding(9);
statusBarPanelTimeOutput = statusBar.AddPanel(200);
ResumeLayout(true);
this.fileGenerated = new BrotliFileController(brotliFilePanelGenerated.Title);
@ -60,12 +73,12 @@ namespace BrotliBuilder{
statusBarPanelTimeOutput.Text = text;
}
private void UpdateStatusBar(StatusBarPanel bar, string type, Stopwatch? sw){
private void UpdateStatusBar(StatusBarBase.Panel panel, string type, Stopwatch? sw){
if (sw != null){
bar.Text = "Generated " + type + " in " + sw.ElapsedMilliseconds + " ms.";
panel.Text = "Generated " + type + " in " + sw.ElapsedMilliseconds + " ms.";
}
else{
bar.Text = "Loaded " + type + ".";
panel.Text = "Loaded " + type + ".";
}
}

View File

@ -1,21 +1,31 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using BrotliBuilder.Utils.Compat.Legacy;
using BrotliBuilder.Utils.Compat.Strip;
namespace BrotliBuilder.Utils.Compat{
static class DeprecatedControls{
public static MainMenuBase CreateMainMenu(Form form, IContainer container){
var winForms = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(assembly => assembly?.FullName?.StartsWith("System.Windows.Forms,") == true);
private static readonly Assembly WinForms = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(assembly => assembly?.FullName?.StartsWith("System.Windows.Forms,") == true);
if (winForms?.GetType("System.Windows.Forms.MainMenu") == null){
public static MainMenuBase CreateMainMenu(Form form, IContainer container){
if (WinForms?.GetType("System.Windows.Forms.MainMenu") == null){
return new StripMainMenu(form);
}
else{
return new LegacyMainMenu(form, container);
}
}
public static StatusBarBase CreateStatusBar(Form form){
if (WinForms?.GetType("System.Windows.Forms.StatusBar") == null){
return new StripStatusBar(form);
}
else{
return new LegacyStatusBar(form);
}
}
}
}

View File

@ -0,0 +1,58 @@
using System.Windows.Forms;
namespace BrotliBuilder.Utils.Compat.Legacy{
class LegacyStatusBar : StatusBarBase{
private readonly StatusBar statusBar;
public LegacyStatusBar(Form form){
this.statusBar = new StatusBar{
ShowPanels = true,
SizingGrip = false
};
form.Controls.Add(statusBar);
}
public override bool Visible{
get => statusBar.Visible;
set => statusBar.Visible = value;
}
public override Panel AddPanel(int width){
var panel = new StatusBarPanel();
panel.BeginInit();
panel.Width = width;
panel.EndInit();
statusBar.Panels.Add(panel);
return new InternalPanel(panel);
}
public override void AddPadding(int width){
var panel = new StatusBarPanel();
panel.BeginInit();
panel.MinWidth = width;
panel.Width = width;
panel.BorderStyle = StatusBarPanelBorderStyle.None;
panel.EndInit();
statusBar.Panels.Add(panel);
}
private class InternalPanel : Panel{
private readonly StatusBarPanel panel;
public InternalPanel(StatusBarPanel panel){
this.panel = panel;
}
public override int Width{
get => panel.Width;
set => panel.Width = value;
}
public override string Text{
get => panel.Text;
set => panel.Text = value;
}
}
}
}

View File

@ -0,0 +1,15 @@
using System.ComponentModel;
namespace BrotliBuilder.Utils.Compat{
abstract class StatusBarBase : Component{
public abstract bool Visible { get; set; }
public abstract Panel AddPanel(int width);
public abstract void AddPadding(int width);
public abstract class Panel{
public abstract int Width { get; set; }
public abstract string Text { get; set; }
}
}
}

View File

@ -0,0 +1,56 @@
using System.Drawing;
using System.Windows.Forms;
namespace BrotliBuilder.Utils.Compat.Strip{
class StripStatusBar : StatusBarBase{
private readonly StatusStrip statusStrip;
public StripStatusBar(Form form){
this.statusStrip = new StatusStrip{
SizingGrip = false
};
form.Controls.Add(statusStrip);
}
public override bool Visible{
get => statusStrip.Visible;
set => statusStrip.Visible = value;
}
public override Panel AddPanel(int width){
var panel = (ToolStripStatusLabel)statusStrip.Items.Add("");
panel.AutoSize = false;
panel.BackColor = SystemColors.Control;
panel.BorderSides = ToolStripStatusLabelBorderSides.Right;
panel.Size = new Size(width, 17);
panel.TextAlign = ContentAlignment.MiddleLeft;
return new InternalPanel(panel);
}
public override void AddPadding(int width){
var panel = statusStrip.Items.Add("");
panel.BackColor = SystemColors.Control;
panel.AutoSize = false;
panel.Size = new Size(width, 17);
}
private class InternalPanel : Panel{
private readonly ToolStripItem stripItem;
public InternalPanel(ToolStripItem stripItem){
this.stripItem = stripItem;
}
public override int Width{
get => stripItem.Width;
set => stripItem.Width = value;
}
public override string Text{
get => stripItem.Text;
set => stripItem.Text = value;
}
}
}
}