From 38837ae84c816af90eb40420bc8035b371829bac Mon Sep 17 00:00:00 2001
From: chylex <contact@chylex.com>
Date: Thu, 7 Sep 2017 15:22:14 +0200
Subject: [PATCH] Add option to open search columns before the first column

---
 Configuration/UserConfig.cs                   | 11 +++--
 Core/Bridge/PropertyBridge.cs                 |  1 +
 .../Settings/TabSettingsGeneral.Designer.cs   | 47 ++++++++++++-------
 Core/Other/Settings/TabSettingsGeneral.cs     |  6 +++
 Resources/Scripts/code.js                     | 22 +++++++++
 5 files changed, 66 insertions(+), 21 deletions(-)

diff --git a/Configuration/UserConfig.cs b/Configuration/UserConfig.cs
index 39ba2837..64bfc1a9 100644
--- a/Configuration/UserConfig.cs
+++ b/Configuration/UserConfig.cs
@@ -47,11 +47,12 @@ static UserConfig(){
         public WindowState BrowserWindow { get; set; } = new WindowState();
         public WindowState PluginsWindow { get; set; } = new WindowState();
 
-        public bool ExpandLinksOnHover     { get; set; } = true;
-        public bool SwitchAccountSelectors { get; set; } = true;
-        public bool BestImageQuality       { get; set; } = true;
-        public bool EnableSpellCheck       { get; set; } = false;
-        public int VideoPlayerVolume       { get; set; } = 50;
+        public bool ExpandLinksOnHover      { get; set; } = true;
+        public bool SwitchAccountSelectors  { get; set; } = true;
+        public bool OpenSearchInFirstColumn { get; set; } = true;
+        public bool BestImageQuality        { get; set; } = true;
+        public bool EnableSpellCheck        { get; set; } = false;
+        public int VideoPlayerVolume        { get; set; } = 50;
         private int _zoomLevel                           = 100;
         private bool _muteNotifications;
         
diff --git a/Core/Bridge/PropertyBridge.cs b/Core/Bridge/PropertyBridge.cs
index 262e4257..01731a4b 100644
--- a/Core/Bridge/PropertyBridge.cs
+++ b/Core/Bridge/PropertyBridge.cs
@@ -17,6 +17,7 @@ string Bool(bool value){
             
             if (environment == Environment.Browser){
                 build.Append("x.switchAccountSelectors=").Append(Bool(Program.UserConfig.SwitchAccountSelectors));
+                build.Append("x.openSearchInFirstColumn=").Append(Bool(Program.UserConfig.OpenSearchInFirstColumn));
                 build.Append("x.muteNotifications=").Append(Bool(Program.UserConfig.MuteNotifications));
                 build.Append("x.hasCustomNotificationSound=").Append(Bool(Program.UserConfig.NotificationSoundPath.Length > 0));
                 build.Append("x.notificationMediaPreviews=").Append(Bool(Program.UserConfig.NotificationMediaPreviews));
diff --git a/Core/Other/Settings/TabSettingsGeneral.Designer.cs b/Core/Other/Settings/TabSettingsGeneral.Designer.cs
index f503f07f..d9df4256 100644
--- a/Core/Other/Settings/TabSettingsGeneral.Designer.cs
+++ b/Core/Other/Settings/TabSettingsGeneral.Designer.cs
@@ -44,6 +44,7 @@ private void InitializeComponent() {
             this.panelTray = new System.Windows.Forms.Panel();
             this.labelUpdates = new System.Windows.Forms.Label();
             this.checkBestImageQuality = new System.Windows.Forms.CheckBox();
+            this.checkOpenSearchInFirstColumn = new System.Windows.Forms.CheckBox();
             ((System.ComponentModel.ISupportInitialize)(this.trackBarZoom)).BeginInit();
             this.panelUI.SuspendLayout();
             this.panelUpdates.SuspendLayout();
@@ -88,11 +89,11 @@ private void InitializeComponent() {
             // checkSpellCheck
             // 
             this.checkSpellCheck.AutoSize = true;
-            this.checkSpellCheck.Location = new System.Drawing.Point(6, 74);
+            this.checkSpellCheck.Location = new System.Drawing.Point(6, 97);
             this.checkSpellCheck.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
             this.checkSpellCheck.Name = "checkSpellCheck";
             this.checkSpellCheck.Size = new System.Drawing.Size(119, 17);
-            this.checkSpellCheck.TabIndex = 3;
+            this.checkSpellCheck.TabIndex = 4;
             this.checkSpellCheck.Text = "Enable Spell Check";
             this.toolTip.SetToolTip(this.checkSpellCheck, "Underlines words that are spelled incorrectly.");
             this.checkSpellCheck.UseVisualStyleBackColor = true;
@@ -123,11 +124,11 @@ private void InitializeComponent() {
             // labelZoomValue
             // 
             this.labelZoomValue.BackColor = System.Drawing.Color.Transparent;
-            this.labelZoomValue.Location = new System.Drawing.Point(147, 123);
+            this.labelZoomValue.Location = new System.Drawing.Point(147, 146);
             this.labelZoomValue.Margin = new System.Windows.Forms.Padding(0, 0, 3, 0);
             this.labelZoomValue.Name = "labelZoomValue";
             this.labelZoomValue.Size = new System.Drawing.Size(38, 13);
-            this.labelZoomValue.TabIndex = 6;
+            this.labelZoomValue.TabIndex = 7;
             this.labelZoomValue.Text = "100%";
             this.labelZoomValue.TextAlign = System.Drawing.ContentAlignment.TopRight;
             this.toolTip.SetToolTip(this.labelZoomValue, "Changes the zoom level.\r\nAlso affects notifications and screenshots.");
@@ -159,24 +160,24 @@ private void InitializeComponent() {
             this.trackBarZoom.AutoSize = false;
             this.trackBarZoom.BackColor = System.Drawing.SystemColors.Control;
             this.trackBarZoom.LargeChange = 25;
-            this.trackBarZoom.Location = new System.Drawing.Point(3, 122);
+            this.trackBarZoom.Location = new System.Drawing.Point(3, 145);
             this.trackBarZoom.Maximum = 200;
             this.trackBarZoom.Minimum = 50;
             this.trackBarZoom.Name = "trackBarZoom";
             this.trackBarZoom.Size = new System.Drawing.Size(148, 30);
             this.trackBarZoom.SmallChange = 5;
-            this.trackBarZoom.TabIndex = 5;
+            this.trackBarZoom.TabIndex = 6;
             this.trackBarZoom.TickFrequency = 25;
             this.trackBarZoom.Value = 100;
             // 
             // labelZoom
             // 
             this.labelZoom.AutoSize = true;
-            this.labelZoom.Location = new System.Drawing.Point(3, 106);
+            this.labelZoom.Location = new System.Drawing.Point(3, 129);
             this.labelZoom.Margin = new System.Windows.Forms.Padding(3, 12, 3, 0);
             this.labelZoom.Name = "labelZoom";
             this.labelZoom.Size = new System.Drawing.Size(34, 13);
-            this.labelZoom.TabIndex = 4;
+            this.labelZoom.TabIndex = 5;
             this.labelZoom.Text = "Zoom";
             // 
             // zoomUpdateTimer
@@ -199,6 +200,7 @@ private void InitializeComponent() {
             // 
             this.panelUI.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 
             | System.Windows.Forms.AnchorStyles.Right)));
+            this.panelUI.Controls.Add(this.checkOpenSearchInFirstColumn);
             this.panelUI.Controls.Add(this.checkBestImageQuality);
             this.panelUI.Controls.Add(this.checkExpandLinks);
             this.panelUI.Controls.Add(this.checkSwitchAccountSelectors);
@@ -208,14 +210,14 @@ private void InitializeComponent() {
             this.panelUI.Controls.Add(this.labelZoomValue);
             this.panelUI.Location = new System.Drawing.Point(9, 31);
             this.panelUI.Name = "panelUI";
-            this.panelUI.Size = new System.Drawing.Size(322, 157);
+            this.panelUI.Size = new System.Drawing.Size(322, 179);
             this.panelUI.TabIndex = 1;
             // 
             // labelTray
             // 
             this.labelTray.AutoSize = true;
             this.labelTray.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.labelTray.Location = new System.Drawing.Point(6, 212);
+            this.labelTray.Location = new System.Drawing.Point(5, 234);
             this.labelTray.Margin = new System.Windows.Forms.Padding(0, 21, 0, 0);
             this.labelTray.Name = "labelTray";
             this.labelTray.Size = new System.Drawing.Size(96, 20);
@@ -228,7 +230,7 @@ private void InitializeComponent() {
             | System.Windows.Forms.AnchorStyles.Right)));
             this.panelUpdates.Controls.Add(this.checkUpdateNotifications);
             this.panelUpdates.Controls.Add(this.btnCheckUpdates);
-            this.panelUpdates.Location = new System.Drawing.Point(9, 358);
+            this.panelUpdates.Location = new System.Drawing.Point(8, 380);
             this.panelUpdates.Name = "panelUpdates";
             this.panelUpdates.Size = new System.Drawing.Size(322, 55);
             this.panelUpdates.TabIndex = 5;
@@ -240,7 +242,7 @@ private void InitializeComponent() {
             this.panelTray.Controls.Add(this.checkTrayHighlight);
             this.panelTray.Controls.Add(this.comboBoxTrayType);
             this.panelTray.Controls.Add(this.labelTrayIcon);
-            this.panelTray.Location = new System.Drawing.Point(9, 235);
+            this.panelTray.Location = new System.Drawing.Point(8, 257);
             this.panelTray.Name = "panelTray";
             this.panelTray.Size = new System.Drawing.Size(322, 76);
             this.panelTray.TabIndex = 3;
@@ -249,7 +251,7 @@ private void InitializeComponent() {
             // 
             this.labelUpdates.AutoSize = true;
             this.labelUpdates.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
-            this.labelUpdates.Location = new System.Drawing.Point(6, 335);
+            this.labelUpdates.Location = new System.Drawing.Point(5, 357);
             this.labelUpdates.Margin = new System.Windows.Forms.Padding(0, 21, 0, 0);
             this.labelUpdates.Name = "labelUpdates";
             this.labelUpdates.Size = new System.Drawing.Size(70, 20);
@@ -259,15 +261,27 @@ private void InitializeComponent() {
             // checkBestImageQuality
             // 
             this.checkBestImageQuality.AutoSize = true;
-            this.checkBestImageQuality.Location = new System.Drawing.Point(6, 51);
+            this.checkBestImageQuality.Location = new System.Drawing.Point(6, 74);
             this.checkBestImageQuality.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
             this.checkBestImageQuality.Name = "checkBestImageQuality";
             this.checkBestImageQuality.Size = new System.Drawing.Size(114, 17);
-            this.checkBestImageQuality.TabIndex = 2;
+            this.checkBestImageQuality.TabIndex = 3;
             this.checkBestImageQuality.Text = "Best Image Quality";
             this.toolTip.SetToolTip(this.checkBestImageQuality, "When right-clicking a tweet image, the context menu options\r\nwill use links to the original image size (:orig in the URL).");
             this.checkBestImageQuality.UseVisualStyleBackColor = true;
             // 
+            // checkOpenSearchInFirstColumn
+            // 
+            this.checkOpenSearchInFirstColumn.AutoSize = true;
+            this.checkOpenSearchInFirstColumn.Location = new System.Drawing.Point(6, 51);
+            this.checkOpenSearchInFirstColumn.Margin = new System.Windows.Forms.Padding(6, 3, 3, 3);
+            this.checkOpenSearchInFirstColumn.Name = "checkOpenSearchInFirstColumn";
+            this.checkOpenSearchInFirstColumn.Size = new System.Drawing.Size(219, 17);
+            this.checkOpenSearchInFirstColumn.TabIndex = 2;
+            this.checkOpenSearchInFirstColumn.Text = "Add Search Columns Before First Column";
+            this.toolTip.SetToolTip(this.checkOpenSearchInFirstColumn, "By default, TweetDeck adds Search columns at the end.\r\nThis option makes them appear before the first column instead.");
+            this.checkOpenSearchInFirstColumn.UseVisualStyleBackColor = true;
+            // 
             // TabSettingsGeneral
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -279,7 +293,7 @@ private void InitializeComponent() {
             this.Controls.Add(this.panelUI);
             this.Controls.Add(this.labelUI);
             this.Name = "TabSettingsGeneral";
-            this.Size = new System.Drawing.Size(340, 422);
+            this.Size = new System.Drawing.Size(340, 445);
             ((System.ComponentModel.ISupportInitialize)(this.trackBarZoom)).EndInit();
             this.panelUI.ResumeLayout(false);
             this.panelUI.PerformLayout();
@@ -314,5 +328,6 @@ private void InitializeComponent() {
         private System.Windows.Forms.Panel panelTray;
         private System.Windows.Forms.Label labelUpdates;
         private System.Windows.Forms.CheckBox checkBestImageQuality;
+        private System.Windows.Forms.CheckBox checkOpenSearchInFirstColumn;
     }
 }
diff --git a/Core/Other/Settings/TabSettingsGeneral.cs b/Core/Other/Settings/TabSettingsGeneral.cs
index f5bdec4b..2d12e4ca 100644
--- a/Core/Other/Settings/TabSettingsGeneral.cs
+++ b/Core/Other/Settings/TabSettingsGeneral.cs
@@ -27,6 +27,7 @@ public TabSettingsGeneral(UpdateHandler updates){
 
             checkExpandLinks.Checked = Config.ExpandLinksOnHover;
             checkSwitchAccountSelectors.Checked = Config.SwitchAccountSelectors;
+            checkOpenSearchInFirstColumn.Checked = Config.OpenSearchInFirstColumn;
             checkBestImageQuality.Checked = Config.BestImageQuality;
             checkSpellCheck.Checked = Config.EnableSpellCheck;
 
@@ -39,6 +40,7 @@ public TabSettingsGeneral(UpdateHandler updates){
         public override void OnReady(){
             checkExpandLinks.CheckedChanged += checkExpandLinks_CheckedChanged;
             checkSwitchAccountSelectors.CheckedChanged += checkSwitchAccountSelectors_CheckedChanged;
+            checkOpenSearchInFirstColumn.CheckedChanged += checkOpenSearchInFirstColumn_CheckedChanged;
             checkBestImageQuality.CheckedChanged += checkBestImageQuality_CheckedChanged;
             checkSpellCheck.CheckedChanged += checkSpellCheck_CheckedChanged;
             trackBarZoom.ValueChanged += trackBarZoom_ValueChanged;
@@ -62,6 +64,10 @@ private void checkSwitchAccountSelectors_CheckedChanged(object sender, EventArgs
             Config.SwitchAccountSelectors = checkSwitchAccountSelectors.Checked;
         }
 
+        private void checkOpenSearchInFirstColumn_CheckedChanged(object sender, EventArgs e){
+            Config.OpenSearchInFirstColumn = checkOpenSearchInFirstColumn.Checked;
+        }
+
         private void checkBestImageQuality_CheckedChanged(object sender, EventArgs e){
             Config.BestImageQuality = checkBestImageQuality.Checked;
         }
diff --git a/Resources/Scripts/code.js b/Resources/Scripts/code.js
index 56a4d5b8..f9eeb068 100644
--- a/Resources/Scripts/code.js
+++ b/Resources/Scripts/code.js
@@ -980,6 +980,28 @@
     }
   });
   
+  //
+  // Block: Make temporary search column appear as the first one and clear the input box.
+  //
+  $(document).on("uiSearchNoTemporaryColumn", function(e, data){
+    if (data.query && data.searchScope !== "users" && !data.columnKey){
+      if ($TDX.openSearchInFirstColumn){
+        let order = TD.controller.columnManager._columnOrder;
+        
+        if (order.length > 1){
+          let columnKey = order[order.length-1];
+          
+          order.splice(order.length-1, 1);
+          order.splice(1, 0, columnKey);
+          TD.controller.columnManager.move(columnKey, "left");
+        }
+      }
+      
+      $(".js-app-search-input").val("");
+      $(".js-perform-search").blur();
+    }
+  });
+  
   //
   // Block: Fix DM reply input box not getting focused after opening a conversation.
   //