Skip to content

Commit

Permalink
Use the tab name instead of the tab index to determine the current ta…
Browse files Browse the repository at this point in the history
…b. This ensures the current tab will be kept active when a switch from e.g. inspect to edit causes the number of tabs or their order to change. If the current tab is no longer available, fall back to the first tab.

Implement equals() with comparising limited to the name, as the default will only compare memory addresses, resulting in false negatives.
  • Loading branch information
fbarthez authored and darkv committed Nov 29, 2015
1 parent 1c86f5b commit fb791da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,27 @@ public String toString() {
sb.append(keys);
return sb.toString();
}

public boolean equals(Object something) {
boolean equals = true;
if (something == null) {
equals = false;
}
if (equals && !getClass().equals(something.getClass())) {
equals = false;
}
if (equals) {
ERD2WContainer other = (ERD2WContainer) something;
// verify name equality
if (name == null && other.name != null) {
equals = false;
}
if (equals && name != null && !name.equals(other.name)) {
equals = false;
}
// we don't verify display name and keys equality
}
return equals;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -992,14 +992,16 @@ public NSArray sectionsForCurrentTab() {

/** Returns the {@link er.directtoweb.ERD2WContainer} defining the current tab. */
public ERD2WContainer currentTab() {
if (_currentTab == null && tabSectionsContents() != null && tabSectionsContents().count() > 0) {
//If firstTab is not null, then try to find the tab named firstTab
Integer tabIndex = (Integer) d2wContext().valueForKey(Keys.tabIndex);
if(tabIndex!=null && tabIndex.intValue() <= tabSectionsContents().count()){
setCurrentTab(tabSectionsContents().objectAtIndex(tabIndex.intValue()));
}
if(_currentTab==null)
setCurrentTab(tabSectionsContents().objectAtIndex(0));
String tabName = (String) d2wContext().valueForKey(Keys.tabKey);
if (_currentTab == null && !ERXStringUtilities.stringIsNullOrEmpty(tabName)) {
for (ERD2WContainer aTab : tabSectionsContents()) {
if (tabName.equals(aTab.name)) {
setCurrentTab(aTab);
}
}
}
if (_currentTab == null) {
_currentTab = tabSectionsContents().objectAtIndex(0);
}
return _currentTab;
}
Expand Down

0 comments on commit fb791da

Please sign in to comment.