From 59c9801437fcd0d2f941dd66ea6633caa6b78784 Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Sun, 27 Aug 2017 18:48:54 +0200
Subject: [PATCH] Address code analysis and remove unused code

---
 Configuration/SystemConfig.cs                 |  4 +---
 Core/Controls/ControlExtensions.cs            |  8 --------
 Core/Notification/FormNotificationBase.cs     |  6 +-----
 Core/Notification/FormNotificationMain.cs     |  2 +-
 Core/Other/Settings/BaseTabSettings.cs        |  2 +-
 Core/Utils/NativeMethods.cs                   |  1 -
 Plugins/Events/PluginErrorEventArgs.cs        |  2 +-
 Resources/ScriptLoader.cs                     | 17 ++--------------
 Resources/Scripts/code.js                     |  3 +++
 lib/TweetLib.Communication/Comms.cs           | 20 -------------------
 .../Utils/NativeMethods.cs                    |  3 ---
 11 files changed, 10 insertions(+), 58 deletions(-)

diff --git a/Configuration/SystemConfig.cs b/Configuration/SystemConfig.cs
index ee162df9..6e57f9a1 100644
--- a/Configuration/SystemConfig.cs
+++ b/Configuration/SystemConfig.cs
@@ -5,9 +5,7 @@
 
 namespace TweetDuck.Configuration{
     sealed class SystemConfig{
-        private static readonly FileSerializer<SystemConfig> Serializer = new FileSerializer<SystemConfig>{
-            // HandleUnknownProperties = (obj, data) => {}
-        };
+        private static readonly FileSerializer<SystemConfig> Serializer = new FileSerializer<SystemConfig>();
 
         public static readonly bool IsHardwareAccelerationSupported = File.Exists(Path.Combine(Program.ProgramPath, "libEGL.dll")) &&
                                                                       File.Exists(Path.Combine(Program.ProgramPath, "libGLESv2.dll"));
diff --git a/Core/Controls/ControlExtensions.cs b/Core/Controls/ControlExtensions.cs
index dda9871e..18aeee23 100644
--- a/Core/Controls/ControlExtensions.cs
+++ b/Core/Controls/ControlExtensions.cs
@@ -2,8 +2,6 @@
 using System.Drawing;
 using System.Linq;
 using System.Windows.Forms;
-using TweetDuck.Core.Utils;
-using TweetLib.Communication;
 
 namespace TweetDuck.Core.Controls{
     static class ControlExtensions{
@@ -68,12 +66,6 @@ public static bool AlignValueToTick(this TrackBar trackBar){
             else return true;
         }
 
-        public static void SetElevated(this Button button){
-            button.Text = " "+button.Text;
-            button.FlatStyle = FlatStyle.System;
-            Comms.SendMessage(button.Handle, NativeMethods.BCM_SETSHIELD, 0, 1);
-        }
-
         public static void EnableMultilineShortcuts(this TextBox textBox){
             textBox.KeyDown += (sender, args) => {
                 if (args.Control && args.KeyCode == Keys.A){
diff --git a/Core/Notification/FormNotificationBase.cs b/Core/Notification/FormNotificationBase.cs
index 2f8ca4e6..f181472a 100644
--- a/Core/Notification/FormNotificationBase.cs
+++ b/Core/Notification/FormNotificationBase.cs
@@ -91,7 +91,7 @@ public bool CanResizeWindow{
 
         public event EventHandler Initialized;
 
-        public FormNotificationBase(FormBrowser owner, bool enableContextMenu){
+        protected FormNotificationBase(FormBrowser owner, bool enableContextMenu){
             InitializeComponent();
 
             this.owner = owner;
@@ -190,10 +190,6 @@ protected virtual void SetNotificationSize(int width, int height){
             browser.ClientSize = ClientSize = new Size(BrowserUtils.Scale(width, SizeScale), BrowserUtils.Scale(height, SizeScale));
         }
 
-        protected virtual void OnNotificationReady(){
-            MoveToVisibleLocation();
-        }
-
         protected virtual void UpdateTitle(){
             string title = currentNotification?.ColumnTitle;
             Text = string.IsNullOrEmpty(title) || !Program.UserConfig.DisplayNotificationColumn ? Program.BrandName : Program.BrandName+" - "+title;
diff --git a/Core/Notification/FormNotificationMain.cs b/Core/Notification/FormNotificationMain.cs
index dde55700..57f9effa 100644
--- a/Core/Notification/FormNotificationMain.cs
+++ b/Core/Notification/FormNotificationMain.cs
@@ -279,7 +279,7 @@ private void PrepareAndDisplayWindow(){
             StartMouseHook();
         }
 
-        protected override void OnNotificationReady(){
+        protected virtual void OnNotificationReady(){
             PrepareAndDisplayWindow();
             timerProgress.Start();
         }
diff --git a/Core/Other/Settings/BaseTabSettings.cs b/Core/Other/Settings/BaseTabSettings.cs
index 30c96ba3..dc87e9af 100644
--- a/Core/Other/Settings/BaseTabSettings.cs
+++ b/Core/Other/Settings/BaseTabSettings.cs
@@ -17,7 +17,7 @@ public IEnumerable<Control> InteractiveControls{
             }
         }
 
-        public BaseTabSettings(){
+        protected BaseTabSettings(){
             Padding = new Padding(6);
         }
 
diff --git a/Core/Utils/NativeMethods.cs b/Core/Utils/NativeMethods.cs
index aa19e561..631a98b8 100644
--- a/Core/Utils/NativeMethods.cs
+++ b/Core/Utils/NativeMethods.cs
@@ -16,7 +16,6 @@ static class NativeMethods{
         public const int GWL_STYLE = -16;
 
         public const int SB_HORZ = 0;
-        public const int BCM_SETSHIELD = 0x160C;
 
         public const int WM_MOUSE_LL = 14;
         public const int WM_MOUSEWHEEL = 0x020A;
diff --git a/Plugins/Events/PluginErrorEventArgs.cs b/Plugins/Events/PluginErrorEventArgs.cs
index 1f35b93e..e9e31766 100644
--- a/Plugins/Events/PluginErrorEventArgs.cs
+++ b/Plugins/Events/PluginErrorEventArgs.cs
@@ -5,7 +5,7 @@ namespace TweetDuck.Plugins.Events{
     class PluginErrorEventArgs : EventArgs{
         public bool HasErrors => Errors.Count > 0;
 
-        public IList<string> Errors;
+        public IList<string> Errors { get; }
 
         public PluginErrorEventArgs(IList<string> errors){
             this.Errors = errors;
diff --git a/Resources/ScriptLoader.cs b/Resources/ScriptLoader.cs
index 0d28abd8..5954109c 100644
--- a/Resources/ScriptLoader.cs
+++ b/Resources/ScriptLoader.cs
@@ -1,5 +1,4 @@
 using CefSharp;
-using CefSharp.WinForms;
 using System;
 using System.IO;
 using System.Text;
@@ -21,28 +20,16 @@ public static string LoadResource(string name, bool silent = false){
             }
         }
 
-        public static void ExecuteFile(ChromiumWebBrowser browser, string file){
-            ExecuteScript(browser, LoadResource(file), GetRootIdentifier(file));
-        }
-
         public static void ExecuteFile(IFrame frame, string file){
             ExecuteScript(frame, LoadResource(file), GetRootIdentifier(file));
         }
 
-        public static void ExecuteScript(ChromiumWebBrowser browser, string script, string identifier){
-            if (script == null)return;
-
-            using(IFrame frame = browser.GetMainFrame()){
+        public static void ExecuteScript(IFrame frame, string script, string identifier){
+            if (script != null){
                 frame.ExecuteJavaScriptAsync(script, UrlPrefix+identifier, 1);
             }
         }
 
-        public static void ExecuteScript(IFrame frame, string script, string identifier){
-            if (script == null)return;
-
-            frame.ExecuteJavaScriptAsync(script, UrlPrefix+identifier, 1);
-        }
-
         public static string GetRootIdentifier(string file){
             return "root:"+Path.GetFileNameWithoutExtension(file);
         }
diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index a79a7e0c..d35304a5 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -208,6 +208,9 @@
     };
   })();
   
+  //
+  // Function: Shows tweet detail, used in notification context menu.
+  //
   window.TDGF_showTweetDetail = function(columnKey, tweetId){
     let column = TD.controller.columnManager.get(columnKey);
     return 1 if !column; // column no longer exists
diff --git a/lib/TweetLib.Communication/Comms.cs b/lib/TweetLib.Communication/Comms.cs
index 2a52a57f..8d80f67a 100644
--- a/lib/TweetLib.Communication/Comms.cs
+++ b/lib/TweetLib.Communication/Comms.cs
@@ -3,30 +3,10 @@
 
 namespace TweetLib.Communication{
     public static class Comms{
-        public static void SendMessage(IntPtr hWnd, uint msg, uint wParam, int lParam){
-            NativeMethods.SendMessage(hWnd, msg, new UIntPtr(wParam), new IntPtr(lParam));
-        }
-
-        public static void SendMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam){
-            NativeMethods.SendMessage(hWnd, msg, wParam, lParam);
-        }
-
-        public static void PostMessage(IntPtr hWnd, uint msg, uint wParam, int lParam){
-            NativeMethods.PostMessage(hWnd, msg, new UIntPtr(wParam), new IntPtr(lParam));
-        }
-
-        public static void PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam){
-            NativeMethods.PostMessage(hWnd, msg, wParam, lParam);
-        }
-
         public static void BroadcastMessage(uint msg, uint wParam, int lParam){
             NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, msg, new UIntPtr(wParam), new IntPtr(lParam));
         }
 
-        public static void BroadcastMessage(uint msg, UIntPtr wParam, IntPtr lParam){
-            NativeMethods.PostMessage(NativeMethods.HWND_BROADCAST, msg, wParam, lParam);
-        }
-
         public static uint RegisterMessage(string name){
             return NativeMethods.RegisterWindowMessage(name);
         }
diff --git a/lib/TweetLib.Communication/Utils/NativeMethods.cs b/lib/TweetLib.Communication/Utils/NativeMethods.cs
index 9c43c77a..24cf524f 100644
--- a/lib/TweetLib.Communication/Utils/NativeMethods.cs
+++ b/lib/TweetLib.Communication/Utils/NativeMethods.cs
@@ -4,9 +4,6 @@
 namespace TweetLib.Communication.Utils{
     static class NativeMethods{
         public static readonly IntPtr HWND_BROADCAST = new IntPtr(0xFFFF);
-
-        [DllImport("user32.dll")]
-        public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam);
         
         [DllImport("user32.dll")]
         public static extern bool PostMessage(IntPtr hWnd, uint msg, UIntPtr wParam, IntPtr lParam);