[toolbar][ks] Added keyboard shortcuts capabilities to icon buttons
authorDavid Baz Fayos <david.baz@openbravo.com>
Tue, 25 Jan 2011 00:11:07 +0100
changeset 10112 226d5756b073
parent 10111 cb0dfdfa6fea
child 10113 ef76ba573a7d
[toolbar][ks] Added keyboard shortcuts capabilities to icon buttons
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml
modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-keyboard-manager.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Tue Jan 25 00:11:07 2011 +0100
@@ -54,6 +54,19 @@
 <!--6EE6D055A7FE4C4DA7EB557F6C61D0EB-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--6EE6D055A7FE4C4DA7EB557F6C61D0EB--></AD_PREFERENCE>
 
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC--><AD_PREFERENCE>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <AD_PREFERENCE_ID><![CDATA[7EE6D055A7FE4C4DA7EB557F6C61D0EC]]></AD_PREFERENCE_ID>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <VALUE><![CDATA[[
+  {"id": "ToolBar_Save", "keyComb": {"ctrl": true, "alt": true, "key": "S"}}
+]]]></VALUE>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <PROPERTY><![CDATA[UITOOLB_KeyboardShortcuts]]></PROPERTY>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <ISPROPERTYLIST><![CDATA[Y]]></ISPROPERTYLIST>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--7EE6D055A7FE4C4DA7EB557F6C61D0EC--></AD_PREFERENCE>
+
 <!--C085B29F345B423F9E7DE5677359E02B--><AD_PREFERENCE>
 <!--C085B29F345B423F9E7DE5677359E02B-->  <AD_PREFERENCE_ID><![CDATA[C085B29F345B423F9E7DE5677359E02B]]></AD_PREFERENCE_ID>
 <!--C085B29F345B423F9E7DE5677359E02B-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_REF_LIST.xml	Tue Jan 25 00:11:07 2011 +0100
@@ -116,6 +116,17 @@
 <!--BF6EAC4255D0484399EF03DB23376CD4-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
 <!--BF6EAC4255D0484399EF03DB23376CD4--></AD_REF_LIST>
 
+<!--CF6EAC4255D0484399EF03DB23376CD5--><AD_REF_LIST>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <AD_REF_LIST_ID><![CDATA[CF6EAC4255D0484399EF03DB23376CD5]]></AD_REF_LIST_ID>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <VALUE><![CDATA[UITOOLB_KeyboardShortcuts]]></VALUE>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <NAME><![CDATA[Keyboard Shortcuts (UITOOLB)]]></NAME>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <AD_REFERENCE_ID><![CDATA[A26BA480E2014707B47257024C3CBFF7]]></AD_REFERENCE_ID>
+<!--CF6EAC4255D0484399EF03DB23376CD5-->  <AD_MODULE_ID><![CDATA[9BA0836A3CD74EE4AB48753A47211BCC]]></AD_MODULE_ID>
+<!--CF6EAC4255D0484399EF03DB23376CD5--></AD_REF_LIST>
+
 <!--C38DEECEC59544609E4CC4D7FC819E46--><AD_REF_LIST>
 <!--C38DEECEC59544609E4CC4D7FC819E46-->  <AD_REF_LIST_ID><![CDATA[C38DEECEC59544609E4CC4D7FC819E46]]></AD_REF_LIST_ID>
 <!--C38DEECEC59544609E4CC4D7FC819E46-->  <AD_CLIENT_ID><![CDATA[0]]></AD_CLIENT_ID>
--- a/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/src/org/openbravo/client/application/templates/layout.js.ftl	Tue Jan 25 00:11:07 2011 +0100
@@ -45,6 +45,7 @@
 
 OB.KeyboardManager.KS.readRegisteredKSList('OBUIAPP_KeyboardShortcuts');
 OB.KeyboardManager.KS.readRegisteredKSList('UINAVBA_KeyboardShortcuts');
+OB.KeyboardManager.KS.readRegisteredKSList('UITOOLB_KeyboardShortcuts');
 
 // should be moved to client.kernel component
 // placed here to prevent dependencies of client.kernel on Preferences
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-keyboard-manager.js	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-keyboard-manager.js	Tue Jan 25 00:11:07 2011 +0100
@@ -107,6 +107,15 @@
         this.list[position].funcParam = funcParam;
       },
       
+      remove: function(id, action, funcParam){
+        var position = this.getPosition(id, 'id');
+        if (position === null) {
+          return false;
+        }
+        this.list[position].action = null;
+        this.list[position].funcParam = null;
+      },
+      
       getPosition: function(element, searchPattern){
         for (var i = 0; i < this.list.length; i++) {
           if (searchPattern === 'id' && this.list[i].id === element) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-view.js	Tue Jan 25 00:11:07 2011 +0100
@@ -632,15 +632,21 @@
   setAsActiveView: function(){
     this.standardWindow.setActiveView(this);
   },
+
+  setToolBarState: function(state) {
+    if (state) {
+      this.toolBar.setActive(true);
+    } else {
+      this.toolBar.setActive(false);
+    }
+  },
   
-  setActiveViewVisualState: function(state){
+  setActiveViewProps: function(state){
     if (state) {
-      this.toolBar.show();
       this.activeBar.setActive(true);
       this.setViewFocus();
     } else {
       this.activeBar.setActive(false);
-      this.toolBar.hide();
       // note we can not check on viewForm visibility as 
       // the grid and form can both be hidden when changing
       // to another tab, this handles the case that the grid
@@ -652,6 +658,7 @@
       }
     }
     this.setTabButtonState(state);
+    this.setToolBarState(state);
   },
   
   // do refresh contents with a small delay to not refresh child views
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-standard-window.js	Tue Jan 25 00:11:07 2011 +0100
@@ -162,9 +162,9 @@
     // the other one
     this.activeView = view;
     if (currentView) {
-      currentView.setActiveViewVisualState(false);
+      currentView.setActiveViewProps(false);
     }
-    view.setActiveViewVisualState(true);
+    view.setActiveViewProps(true);
   },
   
   setFocusInView: function(view){
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js	Mon Jan 24 19:25:43 2011 +0100
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/ob-toolbar.js	Tue Jan 25 00:11:07 2011 +0100
@@ -42,6 +42,18 @@
         // enable when supporting grid editing
         this.setDisabled(true);
       }      
+    },
+    enableShortcut: function(){
+      var me = this;
+      var ksAction = function(){
+        if (!me.disabled) {
+          me.action();
+        }
+      }
+      OB.KeyboardManager.KS.add('ToolBar_Save', ksAction);
+    },
+    disableShortcut: function(){
+      OB.KeyboardManager.KS.remove('ToolBar_Save');
     }
   },
   NEW_ROW_BUTTON_PROPERTIES: {
@@ -691,6 +703,32 @@
       doRefresh(buttons, currentValues, hideAllButtons);
     } 
   },
+
+  isActive: false,
+
+  setActive: function(value) {
+    if (value === true && this.isActive === false) {
+      this.isActive = true;
+      this.show();
+      if (this.leftMembers) {
+        for (i = 0; i < this.leftMembers.length; i++) {
+          if (this.leftMembers[i].enableShortcut) {
+            this.leftMembers[i].enableShortcut();
+          }
+        }
+      }
+    } else if (value === false && this.isActive === true) {
+      this.isActive = false;
+      if (this.leftMembers) {
+        for (i = 0; i < this.leftMembers.length; i++) {
+          if (this.leftMembers[i].disableShortcut) {
+            this.leftMembers[i].disableShortcut();
+          }
+        }
+      }
+      this.hide();
+    }
+  },
   
   addMembers: 'null',