1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-01 08:34:11 +02:00
TweetDuck/Core/Other/FormPlugins.cs
Daniel Chýlek 1ccefe853a
Update .NET & begin refactoring code into a core lib ()
* Switch to .NET Framework 4.7.2 & C# 8.0, update libraries

* Add TweetLib.Core project targeting .NET Standard 2.0

* Enable reference nullability checks for TweetLib.Core

* Move a bunch of utility classes into TweetLib.Core & refactor

* Partially move TweetDuck plugin & update system to TweetLib.Core

* Move some constants and CultureInfo setup to TweetLib.Core

* Move some configuration classes to TweetLib.Core

* Minor refactoring and warning suppression

* Add App to TweetLib.Core

* Add IAppErrorHandler w/ implementation

* Continue moving config, plugin, and update classes to TweetLib.Core

* Fix a few nullability checks

* Update installers to check for .NET Framework 4.7.2
2019-05-26 14:55:12 +02:00

114 lines
4.0 KiB
C#

using System;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using TweetDuck.Configuration;
using TweetDuck.Plugins;
using TweetDuck.Plugins.Controls;
using TweetLib.Core.Features.Plugins;
namespace TweetDuck.Core.Other{
sealed partial class FormPlugins : Form, FormManager.IAppDialog{
private static UserConfig Config => Program.Config.User;
private readonly PluginManager pluginManager;
public FormPlugins(){
InitializeComponent();
Text = Program.BrandName+" Plugins";
}
public FormPlugins(PluginManager pluginManager) : this(){
this.pluginManager = pluginManager;
if (!Config.PluginsWindowSize.IsEmpty){
Size targetSize = Config.PluginsWindowSize;
Size = new Size(Math.Max(MinimumSize.Width, targetSize.Width), Math.Max(MinimumSize.Height, targetSize.Height));
}
Shown += (sender, args) => {
ReloadPluginList();
};
FormClosed += (sender, args) => {
Config.PluginsWindowSize = Size;
Config.Save();
};
ResizeEnd += (sender, args) => {
timerLayout.Start();
};
}
private int GetPluginOrderIndex(Plugin plugin){
return !plugin.CanRun ? 0 : pluginManager.Config.IsEnabled(plugin) ? 1 : 2;
}
private void ReloadPluginList(){
flowLayoutPlugins.Controls.Clear();
flowLayoutPlugins.SuspendLayout();
foreach(Plugin plugin in pluginManager.Plugins.OrderBy(GetPluginOrderIndex).ThenBy(plugin => plugin.Name)){
flowLayoutPlugins.Controls.Add(new PluginControl(pluginManager, plugin));
flowLayoutPlugins.Controls.Add(new Panel{
BackColor = Color.DimGray,
Margin = new Padding(0),
Size = new Size(1, 1)
});
}
flowLayoutPlugins.ResumeLayout(true);
timerLayout_Tick(null, EventArgs.Empty);
timerLayout.Start();
}
private void timerLayout_Tick(object sender, EventArgs e){
timerLayout.Stop();
// stupid WinForms scrollbars and panels
Padding = new Padding(Padding.Left, Padding.Top, Padding.Right+1, Padding.Bottom+1);
Padding = new Padding(Padding.Left, Padding.Top, Padding.Right-1, Padding.Bottom-1);
}
public void flowLayoutPlugins_Resize(object sender, EventArgs e){
Control lastPlugin = flowLayoutPlugins.Controls.OfType<PluginControl>().LastOrDefault();
if (lastPlugin == null){
return;
}
bool showScrollBar = lastPlugin.Location.Y+lastPlugin.Height+1 >= flowLayoutPlugins.Height;
int horizontalOffset = showScrollBar ? SystemInformation.VerticalScrollBarWidth : 0;
flowLayoutPlugins.AutoScroll = showScrollBar;
flowLayoutPlugins.VerticalScroll.Visible = showScrollBar;
foreach(Control control in flowLayoutPlugins.Controls){
control.Width = flowLayoutPlugins.Width-control.Margin.Horizontal-horizontalOffset;
}
flowLayoutPlugins.Controls[flowLayoutPlugins.Controls.Count-1].Visible = !showScrollBar;
flowLayoutPlugins.Focus();
}
private void btnOpenFolder_Click(object sender, EventArgs e){
using(Process.Start("explorer.exe", '"'+pluginManager.PathCustomPlugins+'"')){}
}
private void btnReload_Click(object sender, EventArgs e){
if (FormMessage.Warning("Reloading Plugins", "This will also reload the browser window. Do you want to proceed?", FormMessage.Yes, FormMessage.No)){
pluginManager.Reload();
ReloadPluginList();
}
}
private void btnClose_Click(object sender, EventArgs e){
Close();
}
}
}