[polari/wip/kunaljain/bug-fixes] entryArea: Select text & show styled error on unknown commands



commit 6a6999d3bae4c9ec844ab8aef83354da05304dc0
Author: Kunaal Jain <kunaalus gmail com>
Date:   Sun Oct 18 03:50:03 2015 +0530

    entryArea: Select text & show styled error on unknown commands
    
    When user enters unknown commands, instead of removing
    the whole message, select whole text message so that
    user can change command or delete whole text by del or
    backspace. Also styles with error class
    
    https://bugzilla.gnome.org/show_bug.cgi?id=756363

 src/entryArea.js |    9 +++++++--
 src/ircParser.js |   25 ++++++++++++++++++-------
 2 files changed, 25 insertions(+), 9 deletions(-)
---
diff --git a/src/entryArea.js b/src/entryArea.js
index bb6b7ac..2d10086 100644
--- a/src/entryArea.js
+++ b/src/entryArea.js
@@ -89,8 +89,12 @@ const EntryArea = new Lang.Class({
 
         this._entry.connect('activate', Lang.bind(this,
             function() {
-                this._ircParser.process(this._entry.text);
-                this._entry.text = '';
+                if (this._ircParser.process(this._entry.text)) {
+                    this._entry.text = '';
+                } else {
+                    this._entry.get_style_context().add_class('error');
+                    this._entry.grab_focus(); // select text
+                }
             }));
 
         this.widget.add_named(chatBox, 'default');
@@ -181,6 +185,7 @@ const EntryArea = new Lang.Class({
     },
 
     _onEntryChanged: function() {
+        this._entry.get_style_context().remove_class('error'); // remove error class if present
         let nLines = this._entry.text.split('\n').length;
 
         if (nLines < MAX_LINES)
diff --git a/src/ircParser.js b/src/ircParser.js
index ef9f8f4..959b847 100644
--- a/src/ircParser.js
+++ b/src/ircParser.js
@@ -65,17 +65,19 @@ const IrcParser = new Lang.Class({
 
     process: function(text) {
         if (!this._room || !this._room.channel || !text.length)
-            return;
+            return true;
 
         if (text[0] != '/') {
             this._sendText(text);
-            return;
+            return true;
         }
 
         let stripCommand = function(text) {
             return text.substr(text.indexOf(' ')).trimLeft();
         }
 
+        let retval = true;
+
         let argv = text.substr(1).split(/ +/);
         let cmd = argv.shift().toUpperCase();
         let output = null;
@@ -85,21 +87,22 @@ const IrcParser = new Lang.Class({
                 if (command)
                     command = command.toUpperCase();
 
-                let help;
-                if (command && knownCommands[command])
-                    output = this._createFeedbackUsage(command);
-                else if (command)
+                retval = (command == null || knownCommands[command] != null);
+
+                if (!retval) //error
                     output = this._createFeedbackLabel(_(UNKNOWN_COMMAND_MESSAGE));
+                else if (command)
+                    output = this._createFeedbackUsage(command);
                 else
                     output = this._createFeedbackGrid(_("Known commands:"),
                                                         Object.keys(knownCommands));
-
                 break;
             }
             case 'INVITE': {
                 let nick = argv.shift();
                 if (!nick) {
                     this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
                 this._room.channel.connection.dup_contact_by_id_async(nick, [],
@@ -120,6 +123,7 @@ const IrcParser = new Lang.Class({
                 let room = argv.shift();
                 if (!room) {
                     output = this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
                 if (argv.length)
@@ -138,6 +142,7 @@ const IrcParser = new Lang.Class({
                 let nick = argv.shift();
                 if (!nick) {
                     output = this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
                 this._room.channel.connection.dup_contact_by_id_async(nick, [],
@@ -156,6 +161,7 @@ const IrcParser = new Lang.Class({
             case 'ME': {
                 if (!argv.length) {
                     output = this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
                 let action = stripCommand(text);
@@ -176,6 +182,7 @@ const IrcParser = new Lang.Class({
                 let nick = argv.shift();
                 if (!nick) {
                     output = this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
                 if (argv.length)
@@ -211,6 +218,7 @@ const IrcParser = new Lang.Class({
                 let nick = argv.shift();
                 if (!nick) {
                     output = this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
 
@@ -240,6 +248,7 @@ const IrcParser = new Lang.Class({
             case 'SAY': {
                 if (!argv.length) {
                     output = this._createFeedbackUsage(cmd);
+                    retval = false;
                     break;
                 }
                 this._sendText(stripCommand(text));
@@ -254,11 +263,13 @@ const IrcParser = new Lang.Class({
             }
             default:
                 output = this._createFeedbackLabel(_(UNKNOWN_COMMAND_MESSAGE));
+                retval = false;
                 break;
         }
 
         if (output)
             this._app.commandOutputQueue.addNotification(output);
+        return retval;
     },
 
     _sendText: function(text) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]