From d4fbe0a877cd0fb03d835b6a768fa36300d92e1b Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Mon, 21 Sep 2015 00:23:06 -0400
Subject: [PATCH] first stab at "Find" bar for Pd console

---
 pd/nw/css/default.css             |  9 +++++++
 pd/nw/index.html                  | 33 +++++++++++++++++++-------
 pd/nw/index.js                    | 39 +++++++++++++++++++++++++++++++
 pd/nw/locales/en/translation.json |  2 ++
 4 files changed, 75 insertions(+), 8 deletions(-)

diff --git a/pd/nw/css/default.css b/pd/nw/css/default.css
index 55193c589..3bb087c62 100644
--- a/pd/nw/css/default.css
+++ b/pd/nw/css/default.css
@@ -38,6 +38,7 @@
     margin: 8px;
 }
 
+/* This needs to be renamed, since the "Find" bar is actually at the bottom */
 #console_bottom {
     position: absolute;
     top: 50px;
@@ -47,6 +48,14 @@
     overflow-y: scroll;    
 }
 
+#console_find {
+    width: 100%;
+    height: 1em;
+    background: red;
+    position: fixed;
+    bottom: 0;
+}
+
 /* Pure Data Patch Window (aka canvas) */
 
 /* patch font and background color. (Note: margin needs to stay at zero.) */
diff --git a/pd/nw/index.html b/pd/nw/index.html
index a7dbcc057..298ab0233 100644
--- a/pd/nw/index.html
+++ b/pd/nw/index.html
@@ -1,27 +1,44 @@
 <!DOCTYPE html>
 <html>
   <head>
-  <link id="page_style" rel="stylesheet" type="text/css" href="css/default.css">
+    <link id="page_style" rel="stylesheet"
+          type="text/css" href="css/default.css">
   </head>
   <body id="console_body">
-    <input style="display:none;" id="fileDialog" type="file" nwworkingdir multiple />
+    <input style="display:none;" id="fileDialog" type="file"
+           nwworkingdir multiple />
     <div id="console_controls" class="noselect">
       <div id="control_frame">
-    <label><input type="checkbox" id="dsp_control" name="dsp_control" value="on"/>Compute Audio</label>
+        <label><input type="checkbox" id="dsp_control" name="dsp_control"
+                      value="on"/>Compute Audio
+        </label>
       </div>
     </div>
-    <script type="text/javascript" src="index.js">
-    </script>
+    <script type="text/javascript" src="index.js"></script>
     <input style="display:none;" id="saveDialog" type="file" nwsaveas />
     <div id = "console_bottom">
       <div id = "printout">
-      <pre id="p1" style="white-space: pre-wrap;">Welcome to Pd GUI using Node-Webkit
+        <pre id="p1"
+             style="white-space: pre-wrap;">Welcome to Pd GUI using Node-Webkit
         <script>document.write(process.versions['node-webkit'])</script><br/></pre> 
       </div>
     </div>
+    <div id = "console_find" style="display:none;">
+      <div>
+        <label><input type="text"
+                      id="console_find_text"
+                      name="console_find_text"
+                      defaultValue="Search in Console"
+                      style="width:10em;"
+                      onfocus="console_find_input_focus(this)"
+                      onblur="console_find_input_blur(this)"/>XXXXXX   
+        </label>
+      </div>
+    </div>
     <script>
-
-
+       var t = document.getElementById('console_find_text');
+       t.defaultValue = "Search in Console";
+       console_find_input_blur(t);
     </script>
   </body>
 </html>
diff --git a/pd/nw/index.js b/pd/nw/index.js
index 46cd11aa6..9cbd22de1 100644
--- a/pd/nw/index.js
+++ b/pd/nw/index.js
@@ -55,6 +55,20 @@ pdgui.init_socket_events();
 pdgui.set_new_window_fn(nw_create_window);
 pdgui.set_close_window_fn(nw_close_window);
 
+// Greyed out text for the "Find" bar
+function console_find_input_focus(e) {
+    if (e.value === e.defaultValue) {
+        e.value = '';
+        e.style.color = "#000";
+    }
+}
+
+function console_find_input_blur(e) {
+    if (e.value === '' || e.value === e.defaultValue) {
+        e.value = e.defaultValue;
+        e.style.color = "#888";
+    }
+}
 
 function pdmenu_copy () {
     alert("Please implement pdmenu_copy"); 
@@ -290,6 +304,31 @@ function nw_create_pd_window_menus () {
         tooltip: l('menu.zoomout_tt')
     }));
 
+    editMenu.append(new nw.MenuItem({
+        type: 'separator'
+    }));
+
+    editMenu.append(new nw.MenuItem({
+        label: l('menu.find'),
+        click: function () {
+            var find_bar = document.getElementById('console_find'),
+                text_container = document.getElementById('console_bottom'),
+                state = find_bar.style.getPropertyValue('display');
+            if (state === 'none') {
+                text_container.style.setProperty('bottom', '1em');
+                find_bar.style.setProperty('display', 'inline');
+                find_bar.style.setProperty('height', '1em');
+                text_container.scrollTop = text_container.scrollHeight;
+            } else {
+                text_container.style.setProperty('bottom', '0px');
+                find_bar.style.setProperty('display', 'none');
+            }
+        },
+        key: 'f',
+        modifiers: "ctrl",
+        tooltip: l('menu.find_tt')
+    }));
+
     editMenu.append(new nw.MenuItem({
         label: l('menu.preferences'),
         click: pdgui.open_prefs,
diff --git a/pd/nw/locales/en/translation.json b/pd/nw/locales/en/translation.json
index 3df5dacbe..cf0808211 100644
--- a/pd/nw/locales/en/translation.json
+++ b/pd/nw/locales/en/translation.json
@@ -130,6 +130,8 @@
     "zoomin_tt": "Make the patch visually larger",
     "zoomout": "Zoom Out",
     "zoomout_tt": "Make the patch visually smaller",
+    "find": "Find",
+    "find_tt": "Find text in the console output",
     "tidyup": "Tidy Up",
     "tidyup_tt": "Line up the selected objects in straight rows and columns",
     "tofront": "Bring to Front",
-- 
GitLab