[KS] Added tab movements shortcuts
authorDavid Baz Fayos <david.baz@openbravo.com>
Wed, 01 Jun 2011 21:00:26 +0200
changeset 12656 d549a87140e1
parent 12655 62889a6b8947
child 12657 52fa5d26c6dd
[KS] Added tab movements shortcuts
modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js
--- a/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Wed Jun 01 20:54:49 2011 +0200
+++ b/modules/org.openbravo.client.application/src-db/database/sourcedata/AD_PREFERENCE.xml	Wed Jun 01 21:00:26 2011 +0200
@@ -17,11 +17,11 @@
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <AD_ORG_ID><![CDATA[0]]></AD_ORG_ID>
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <ISACTIVE><![CDATA[Y]]></ISACTIVE>
 <!--5EE6D055A7FE4C4DA7EB557F6C61D0EA-->  <VALUE><![CDATA[[
-  {"id": "TabSet_closeAllTabs", "keyComb": {"ctrl": true, "alt": true, "key": "0"}},
-  {"id": "TabSet_ActivateParentTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Up"}},
-  {"id": "TabSet_ActivateChildTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Down"}},
-  {"id": "TabSet_ActivateLeftTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Left"}},
-  {"id": "TabSet_ActivateRightTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Right"}},
+  {"id": "TabSet_closeSelectedTab", "keyComb": {"alt": true, "shift": true, "key": "W"}},
+  {"id": "TabSet_SelectParentTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Up"}},
+  {"id": "TabSet_SelectChildTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Down"}},
+  {"id": "TabSet_SelectPreviousTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Left"}},
+  {"id": "TabSet_SelectNextTab", "keyComb": {"alt": true, "shift": true, "key": "Arrow_Right"}},
   {"id": "Grid_EditInForm", "keyComb": {"ctrl": true, "alt": false, "key": "f2"}},
   {"id": "Grid_EditInGrid", "keyComb": {"ctrl": false, "alt": false, "key": "f2"}}
 ]]]></VALUE>
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js	Wed Jun 01 20:54:49 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-standard-window.js	Wed Jun 01 21:00:26 2011 +0200
@@ -75,7 +75,7 @@
     if (this.command === isc.OBStandardWindow.COMMAND_NEW) {
       this.viewProperties.allowDefaultEditMode = false;
     }
-    this.viewState = OB.PropertyStore.get("OBUIAPP_GridConfiguration", this.windowId);
+    this.viewState = OB.PropertyStore.get('OBUIAPP_GridConfiguration', this.windowId);
     this.view = isc.OBStandardView.create(this.viewProperties);
     this.addView(this.view);
     this.addMember(this.view);
@@ -242,17 +242,135 @@
     }
   },
 
+  // is called from the main app tabset. Redirects to custom viewSelected
   tabSelected: function(tabNum, tabPane, ID, tab) {
     if (this.activeView && this.activeView.setViewFocus) {
       this.activeView.setViewFocus();
     }
   },
-  
-  // is called from the main app tabset
+
+  // is called from the main app tabset. Redirects to custom viewDeselected
   tabDeselected: function(tabNum, tabPane, ID, tab, newTab){
     this.wasDeselected = true;
     this.disableKeyBoardShortCuts();
   },
+
+  // ** {{{ selectParentTab }}} **
+  //
+  // Called from the main app tabset
+  // Selects the parent tab of the current selected and active tab (independently of its level)
+  selectParentTab: function(mainTabSet) {
+    if (!this.activeView.parentView) {
+      return false;
+    }
+
+    var parentTabSet = this.activeView.parentView.parentTabSet;
+
+    if (!parentTabSet) { // If parentTabSet is null means that we are going to move to the top level
+      parentTabSet = mainTabSet;
+    }
+
+    var parentTab = parentTabSet.getSelectedTab(),
+        parentTabNum = parentTabSet.getTabNumber(parentTab),
+        parentTabPane = parentTabSet.getTabPane(parentTab);
+
+    parentTabSet.selectTab(parentTabNum);
+    if (parentTabPane.setAsActiveView) {
+      parentTabPane.setAsActiveView();
+      isc.Timer.setTimeout(function(){ // Inside a timeout like in itemClick case. Also to avoid a strange effect that child tab not deployed properly
+        parentTabSet.doHandleClick();
+      }, 0);
+    } else if (parentTabPane.view.setAsActiveView) {
+      parentTabPane.view.setAsActiveView();
+      isc.Timer.setTimeout(function(){ // Inside a timeout like in itemClick case. Also to avoid a strange effect that parent tab not deployed properly
+        parentTabPane.view.doHandleClick();
+      }, 0);
+    }
+  },
+
+  // ** {{{ selectChildTab }}} **
+  //
+  // Called from the main app tabset
+  // Selects the child tab of the current selected and active tab (independently of its level)
+  selectChildTab: function(mainTabSet) {
+    var childTabSet = this.activeView.childTabSet;
+
+    if (!childTabSet) {
+      return false;
+    }
+
+    var childTab = childTabSet.getSelectedTab(),
+        childTabNum = childTabSet.getTabNumber(childTab),
+        childTabPane = childTabSet.getTabPane(childTab);
+
+    childTabSet.selectTab(childTabNum);
+    if (childTabPane.setAsActiveView) {
+      childTabPane.setAsActiveView();
+      isc.Timer.setTimeout(function(){ // Inside a timeout like in itemClick case. Also to avoid a strange effect that child tab not deployed properly
+        childTabSet.doHandleClick();
+      }, 0);
+    }
+  },
+
+  // ** {{{ selectPreviousTab }}} **
+  //
+  // Called from the main app tabset
+  // Selects the previous tab of the current selected and active tab (independently of its level)
+  selectPreviousTab: function(mainTabSet) {
+    var activeTabSet = this.activeView.parentTabSet;
+    if (!activeTabSet) { // If activeTabSet is null means that we are in the top level
+      activeTabSet = mainTabSet;
+    }
+    var activeTab = activeTabSet.getSelectedTab(),
+        activeTabNum = activeTabSet.getTabNumber(activeTab),
+        activeTabPane = activeTabSet.getTabPane(activeTab);
+
+    if ((activeTabNum-1) < 0) {
+      return false;
+    }
+
+    activeTabSet.selectTab(activeTabNum-1);
+
+    // after select the new tab, activeTab related variables are updated
+    activeTab = activeTabSet.getSelectedTab();
+    activeTabNum = activeTabSet.getTabNumber(activeTab);
+    activeTabPane = activeTabSet.getTabPane(activeTab);
+
+    // and the new selected view is set as active
+    if (activeTabPane.setAsActiveView) {
+      activeTabPane.setAsActiveView();
+    }
+  },
+
+  // ** {{{ selectNextTab }}} **
+  //
+  // Called from the main app tabset
+  // Selects the next tab of the current selected and active tab (independently of its level)
+  selectNextTab: function(mainTabSet) {
+    var activeTabSet = this.activeView.parentTabSet;
+    if (!activeTabSet) { // If activeTabSet is null means that we are in the top level
+      activeTabSet = mainTabSet;
+    }
+    var activeTab = activeTabSet.getSelectedTab(),
+        activeTabNum = activeTabSet.getTabNumber(activeTab),
+        activeTabPane = activeTabSet.getTabPane(activeTab);
+
+    if ((activeTabNum+1) >= activeTabSet.tabs.getLength()) {
+      return false;
+    }
+
+    activeTabSet.selectTab(activeTabNum+1);
+
+    // after select the new tab, activeTab related variables are updated
+    activeTab = activeTabSet.getSelectedTab();
+    activeTabNum = activeTabSet.getTabNumber(activeTab);
+    activeTabPane = activeTabSet.getTabPane(activeTab);
+
+    // and the new selected view is set as active
+    if (activeTabPane.setAsActiveView) {
+      activeTabPane.setAsActiveView();
+    }
+  },
   
   closeClick: function(tab, tabSet){
     if (!this.activeView.viewForm.hasChanged && this.activeView.viewForm.isNew) {
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js	Wed Jun 01 20:54:49 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/main/ob-tab.js	Wed Jun 01 21:00:26 2011 +0200
@@ -66,7 +66,7 @@
     if (!tabPane.isLoadingTab) {
       OB.Layout.HistoryManager.updateHistory();
     }
-    if (tabPane.tabSelected) {
+    if (tabPane.tabSelected) { //Redirect if tabPane has its own tabSelected handler
       tabPane.tabSelected(tabNum, tabPane, ID, tab);
     }
 
@@ -75,7 +75,7 @@
   },
 
   tabDeselected: function (tabNum, tabPane, ID, tab, newTab) {
-    if (tabPane.tabDeselected) {
+    if (tabPane.tabDeselected) { //Redirect if tabPane has its own tabDeselected handler
       tabPane.tabDeselected(tabNum, tabPane, ID, tab, newTab);
     }
   },
@@ -102,35 +102,124 @@
 
   draw : function() {
     var me = this;
-    var ksAction_closeAllTabs = function() {
-      var tabCount, tabArray = [], i;
-      for (i = 1; i > 0; i++) {
-        if (typeof me.getTab(i) === 'undefined') {
-          break;
-        }
-      }
-      tabCount = i-1;
-      me.selectTab(0);
-      for (i = 1; i <= tabCount; i++) {
-        tabArray.push(i);
-      }
-      me.removeTabs(tabArray);
+    var ksAction_closeSelectedTab = function() {
+      me.closeSelectedTab();
       return false; //To avoid keyboard shortcut propagation
     };
-    OB.KeyboardManager.KS.set('TabSet_closeAllTabs', ksAction_closeAllTabs);
-    var ksAction_ActivateRightTab = function() {
-      me.selectTab((me.getTabNumber(me.getSelectedTab()))+1);
+    OB.KeyboardManager.KS.set('TabSet_closeSelectedTab', ksAction_closeSelectedTab);
+    var ksAction_SelectParentTab = function() {
+      me.selectParentTab();
       return false; //To avoid keyboard shortcut propagation
     };
-    OB.KeyboardManager.KS.set('TabSet_ActivateRightTab', ksAction_ActivateRightTab);
-    var ksAction_ActivateLeftTab = function() {
-      me.selectTab((me.getTabNumber(me.getSelectedTab()))-1);
+    OB.KeyboardManager.KS.set('TabSet_SelectParentTab', ksAction_SelectParentTab);
+    var ksAction_SelectChildTab = function() {
+      me.selectChildTab();
       return false; //To avoid keyboard shortcut propagation
     };
-    OB.KeyboardManager.KS.set('TabSet_ActivateLeftTab', ksAction_ActivateLeftTab);
+    OB.KeyboardManager.KS.set('TabSet_SelectChildTab', ksAction_SelectChildTab);
+    var ksAction_SelectPreviousTab = function() {
+      me.selectPreviousTab();
+      return false; //To avoid keyboard shortcut propagation
+    };
+    OB.KeyboardManager.KS.set('TabSet_SelectPreviousTab', ksAction_SelectPreviousTab);
+    var ksAction_SelectNextTab = function() {
+      me.selectNextTab();
+      return false; //To avoid keyboard shortcut propagation
+    };
+    OB.KeyboardManager.KS.set('TabSet_SelectNextTab', ksAction_SelectNextTab);
     this.Super('draw', arguments);
   },
 
+  closeAllTabs: function() { // Except "Workspace" tab
+    var tabCount, tabArray = [], i;
+    for (i = 1; i > 0; i++) {
+      if (typeof this.getTab(i) === 'undefined') {
+        break;
+      }
+    }
+    tabCount = i-1;
+    this.selectTab(0);
+    for (i = 1; i <= tabCount; i++) {
+      tabArray.push(i);
+    }
+    this.removeTabs(tabArray);
+  },
+
+  closeSelectedTab: function() { // Only if selected tab is closable
+    var selectedTab = this.getSelectedTab();
+    if (selectedTab.canClose) {
+      this.removeTabs(selectedTab);
+    }
+  },
+
+  selectParentTab : function() {
+    var tabSet = this,
+        tab = tabSet.getSelectedTab(),
+        ID = tab.ID,
+        tabNum = tabSet.getTabNumber(tab),
+        tabPane = tabSet.getTabPane(tab);
+
+    if (tabPane.selectParentTab) { //Redirect if tabPane has its own selectPreviousTab handler
+      tabPane.selectParentTab(tabSet);
+    }
+
+    return true;
+  },
+
+  selectChildTab : function() {
+    var tabSet = this,
+        tab = tabSet.getSelectedTab(),
+        ID = tab.ID,
+        tabNum = tabSet.getTabNumber(tab),
+        tabPane = tabSet.getTabPane(tab);
+
+    if (tabPane.selectChildTab) { //Redirect if tabPane has its own selectPreviousTab handler
+      tabPane.selectChildTab(tabSet);
+    }
+
+    return true;
+  },
+
+  selectPreviousTab : function(doDefaultAction) {
+    var tabSet = this,
+        tab = tabSet.getSelectedTab(),
+        ID = tab.ID,
+        tabNum = tabSet.getTabNumber(tab),
+        tabPane = tabSet.getTabPane(tab);
+
+    if (!doDefaultAction) {
+      doDefaultAction = false;
+    }
+
+    if (!doDefaultAction && tabPane.selectPreviousTab) { //Redirect if tabPane has its own selectPreviousTab handler
+      tabPane.selectPreviousTab(tabSet);
+    } else {
+      tabSet.selectTab(tabNum-1);
+    }
+
+    return true;
+  },
+
+  selectNextTab : function(doDefaultAction) {
+    var tabSet = this,
+        tab = tabSet.getSelectedTab(),
+        ID = tab.ID,
+        tabNum = tabSet.getTabNumber(tab),
+        tabPane = tabSet.getTabPane(tab);
+
+    if (!doDefaultAction) {
+      doDefaultAction = false;
+    }
+
+    if (!doDefaultAction && tabPane.selectNextTab) { //Redirect if tabPane has its own selectNextTab handler
+      tabPane.selectNextTab(tabSet);
+    } else {
+      tabSet.selectTab(tabNum+1);
+    }
+
+    return true;
+  },
+
   // is used by selenium
   getTabFromTitle : function(title) {
     var index = 0, tab = null;