Skip to content

Commit 9a666d9

Browse files
committed
Fix context-menus not showing up in some places, and mobile menus not behaving correctly.
1 parent 7fe2a29 commit 9a666d9

File tree

4 files changed

+57
-78
lines changed

4 files changed

+57
-78
lines changed

InterSpec/PopupDiv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class PopupDivMenu : public Wt::WPopupMenu
207207
void parentMouseWentOver();
208208
void undoParentHoveredOver();
209209

210+
bool isMobile() const;
211+
210212
protected:
211213
void desktopDoHide();
212214

src/InterSpec.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -658,8 +658,6 @@ InterSpec::InterSpec( WContainerWidget *parent )
658658

659659
//hamburger
660660
PopupDivMenu *popup = new PopupDivMenu( m_mobileMenuButton, PopupDivMenu::AppLevelMenu );
661-
popup->addPhoneBackItem( nullptr );
662-
663661
m_mobileMenuButton->removeStyleClass( "Wt-btn" );
664662
menuWidget = popup;
665663

@@ -991,16 +989,17 @@ InterSpec::InterSpec( WContainerWidget *parent )
991989
m_spectrum->shiftAltKeyDragged().connect( this, &InterSpec::handleShiftAltDrag );
992990

993991
// m_spectrum->rightClicked().connect( boost::bind( &InterSpec::createPeakEdit, this, _1) );
994-
m_rightClickMenu = new PopupDivMenu( m_mobileMenuButton, PopupDivMenu::TransientMenu );
995-
m_rightClickMenu->setPositionScheme( Wt::Absolute );
996-
m_rightClickMenu->addStyleClass( " Wt-popupmenu Wt-outset" );
992+
m_rightClickMenu = new PopupDivMenu( nullptr, PopupDivMenu::TransientMenu );
997993
m_rightClickMenu->aboutToHide().connect( this, &InterSpec::rightClickMenuClosed );
998994

999-
if( isMobile() )
995+
if( m_rightClickMenu->isMobile() )
996+
{
997+
m_rightClickMenu->addPhoneBackItem( nullptr );
998+
}else
1000999
{
1001-
PopupDivMenuItem *item = m_rightClickMenu->addPhoneBackItem( NULL );
1002-
item->triggered().connect( boost::bind(&PopupDivMenu::setHidden, m_rightClickMenu, true, WAnimation()) );
1003-
}//if( isPhone() || isTablet() )
1000+
m_rightClickMenu->setPositionScheme( Wt::Absolute );
1001+
m_rightClickMenu->addStyleClass( " Wt-popupmenu Wt-outset" );
1002+
}
10041003

10051004
for( RightClickItems i = RightClickItems(0);
10061005
i < kNumRightClickItems; i = RightClickItems(i+1) )
@@ -2613,7 +2612,7 @@ void InterSpec::handleRightClick( double energy, double counts,
26132612
}//switch( i )
26142613
}//for( loop over right click menu items )
26152614

2616-
if( isMobile() )
2615+
if( m_rightClickMenu->isMobile() )
26172616
m_rightClickMenu->showMobile();
26182617
else
26192618
m_rightClickMenu->popup( WPoint(pageX,pageY) );
@@ -10270,10 +10269,7 @@ void InterSpec::userAskedToFitPeaksInRange( double x0, double x1,
1027010269
menu->aboutToHide().connect( menu, &DeleteOnClosePopupMenu::markForDelete );
1027110270
menu->setPositionScheme( Wt::Absolute );
1027210271

10273-
PopupDivMenuItem *item = 0;
10274-
if( isMobile() )
10275-
item = menu->addPhoneBackItem( NULL );
10276-
// item->triggered().connect( boost::bind( &deleteMenu, menu ) );
10272+
PopupDivMenuItem *item = nullptr;
1027710273

1027810274
item = menu->addMenuItem( "Single Peak" );
1027910275
// item->triggered().connect( boost::bind( &InterSpec::findPeakFromUserRange, this, x0, x1 ) );

src/PopupDiv.cpp

Lines changed: 44 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ WT_DECLARE_WT_MEMBER
135135
}, 500 );
136136
});
137137

138-
WT_DECLARE_WT_MEMBER(HideOverlay, Wt::JavaScriptFunction, "HideOverlay", function()
138+
WT_DECLARE_WT_MEMBER(SetupHideOverlay, Wt::JavaScriptFunction, "SetupHideOverlay", function()
139139
{
140140
function hideverything(e)
141141
{
@@ -152,21 +152,8 @@ WT_DECLARE_WT_MEMBER(HideOverlay, Wt::JavaScriptFunction, "HideOverlay", functio
152152
//Scroll back to the top of the menu
153153
jel.scrollTop(0);
154154

155-
//I cant actually tell the differnce in smoothness between my version
156-
// and jQueries version.
157155
var a = -jel.width() - 10;
158156
jel.animate({left: a+'px'}, {queue: false, duration: 255}, "linear", function(){jel.hide();});
159-
160-
// var w = jel.width(), t0 = (new Date()).valueOf();
161-
// ( function slideout()
162-
// {
163-
// var t = (new Date()).valueOf();
164-
// var pos = -w*((t-t0)/250);
165-
// el.style['left'] = pos + 'px';
166-
// if( pos>-w )
167-
// setTimeout(slideout,1);
168-
// else jel.hidde();
169-
// })()
170157
});
171158

172159
$('.mobilePopupMenuOverlay').hide();
@@ -668,7 +655,7 @@ PopupDivMenu::PopupDivMenu( Wt::WPushButton *menuParent,
668655
{
669656
addStyleClass( "PopupDivMenuPhone" );
670657
LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "ShowPhone", wtjsShowPhone);
671-
LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "HideOverlay", wtjsHideOverlay);
658+
LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "SetupHideOverlay", wtjsSetupHideOverlay);
672659

673660
// Note: need to call this to reset the menus when a submenu is
674661
// selected/hidden. No need to call triggered(), as it will be hidden too.
@@ -702,48 +689,47 @@ PopupDivMenu::PopupDivMenu( Wt::WPushButton *menuParent,
702689
}//if( useNativeMenu )
703690
#endif
704691

705-
if( menuParent )
692+
if( m_mobile)
706693
{
707-
if( m_mobile)
708-
{
709-
switch( m_type )
710-
{
711-
case AppLevelMenu:
712-
menuParent->clicked().connect( this, &PopupDivMenu::showMobile );
713-
break;
714-
715-
case TransientMenu:
716-
menuParent->setMenu( this );
717-
break;
718-
}//switch( m_type )
719-
}else
694+
if( menuParent )
720695
{
696+
addPhoneBackItem( nullptr );
697+
menuParent->clicked().connect( this, &PopupDivMenu::showMobile );
698+
}//if( menuParent )
699+
}else if( menuParent )
700+
{
721701
#if(USE_OSX_NATIVE_MENU)
722-
if( useNativeMenu && (menutype == AppLevelMenu) )
723-
{
724-
const string buttontxt = menuParent->text().toUTF8();
725-
if( buttontxt.length() )
726-
m_nsmenu = addOsxMenu( this, buttontxt.c_str() );
727-
} //AppLevelMenu
702+
if( useNativeMenu && (menutype == AppLevelMenu) )
703+
{
704+
const string buttontxt = menuParent->text().toUTF8();
705+
if( buttontxt.length() )
706+
m_nsmenu = addOsxMenu( this, buttontxt.c_str() );
707+
} //AppLevelMenu
728708
#endif
729709

730710
#if( USING_ELECTRON_NATIVE_MENU )
731-
if( useNativeMenu && (menutype == AppLevelMenu) )
732-
{
733-
//Here we are adding a menu at the topof the window. "InterSpec", "View", "Tools", "Help"
734-
//In Js, we should find the menu, and get a reference to it.
735-
//app->doJavaScript( "console.log('Adding PopupDivMenu id=" + id() + " parentTxt=" + menuParent->text().toUTF8() + "');" );
736-
app->doJavaScript( "Wt.WT.FindElectronMenu('" + menuParent->text().toUTF8() + "', '" + id() + "');" );
737-
m_hasElectronCounterpart = true;
738-
}
711+
if( useNativeMenu && (menutype == AppLevelMenu) )
712+
{
713+
//Here we are adding a menu at the topof the window. "InterSpec", "View", "Tools", "Help"
714+
//In Js, we should find the menu, and get a reference to it.
715+
//app->doJavaScript( "console.log('Adding PopupDivMenu id=" + id() + " parentTxt=" + menuParent->text().toUTF8() + "');" );
716+
app->doJavaScript( "Wt.WT.FindElectronMenu('" + menuParent->text().toUTF8() + "', '" + id() + "');" );
717+
m_hasElectronCounterpart = true;
718+
}
739719
#endif
740720

741-
if( !useNativeMenu && (menutype == AppLevelMenu) )
742-
setupDesktopMenuStuff();
743-
else
744-
menuParent->setMenu( this );
745-
} //if( m_mobile) / else
746-
}else //if( menuParent )
721+
if( !useNativeMenu && (menutype == AppLevelMenu) )
722+
{
723+
setupDesktopMenuStuff();
724+
}else
725+
{
726+
menuParent->setMenu( this );
727+
728+
const string js = "function(){Wt.WT.BringAboveDialogs('" + id() + "');"
729+
"Wt.WT.AdjustTopPos('" + menuParent->id() + "');}";
730+
menuParent->clicked().connect( js );
731+
}
732+
}else //if( m_mobile) / else if( menuParent )
747733
{
748734
#if( USING_ELECTRON_NATIVE_MENU )
749735
if( m_hasElectronCounterpart && (menutype == AppLevelMenu) )
@@ -941,17 +927,16 @@ void PopupDivMenu::setHidden( bool hidden, const Wt::WAnimation &animation )
941927

942928
void PopupDivMenu::showMobile()
943929
{
944-
//Note/Hack: This is needed to check if clicked or mouseover. If clicked,
945-
// calling popup() will somehow cause the popupmenu to not show.
946-
// I know, weird huh.
947930
if( m_menuParent )
948931
popup( m_menuParent, Wt::Vertical );
949-
932+
else
933+
popup( {0,0} );
934+
950935
if( m_mobile )
951936
{
952937
doJavaScript("$('.mobilePopupMenuOverlay').show();");
953938
doJavaScript( "Wt.WT.ShowPhone('" + id() + "');" );
954-
doJavaScript( "Wt.WT.HideOverlay();" );
939+
doJavaScript( "Wt.WT.SetupHideOverlay();" );
955940
}//if( m_mobile )
956941
}//void doShow()
957942

@@ -1008,6 +993,10 @@ void PopupDivMenu::undoParentHoveredOver()
1008993
}//void undoParentHoveredOver()
1009994

1010995

996+
bool PopupDivMenu::isMobile() const
997+
{
998+
return m_mobile;
999+
}
10111000

10121001
void PopupDivMenu::setupDesktopMenuStuff()
10131002
{
@@ -1307,7 +1296,7 @@ PopupDivMenuItem *PopupDivMenu::addPhoneBackItem( PopupDivMenu *parent )
13071296
PopupDivMenu *PopupDivMenu::addPopupMenuItem( const Wt::WString &text,
13081297
const std::string &iconPath )
13091298
{
1310-
PopupDivMenu *menu = new PopupDivMenu( 0, m_type );
1299+
PopupDivMenu *menu = new PopupDivMenu( nullptr, m_type );
13111300

13121301
if( m_mobile )
13131302
{

src/ShieldingSourceDisplay.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4277,15 +4277,7 @@ ShieldingSourceDisplay::ShieldingSourceDisplay( PeakModel *peakModel,
42774277

42784278
Wt::WPushButton *addItemMenubutton = new WPushButton( " " );
42794279
m_addItemMenu = new PopupDivMenu( addItemMenubutton, PopupDivMenu::TransientMenu );
4280-
if( m_specViewer->isMobile() )
4281-
{
4282-
m_addItemMenu->addPhoneBackItem( NULL );
4283-
addItemMenubutton->clicked().connect( m_addItemMenu, &PopupDivMenu::showMobile );
4284-
} //mobile
4285-
else
4286-
{
4287-
m_addItemMenu->setButton( addItemMenubutton );
4288-
} //not mobile
4280+
42894281
addItemMenubutton->setStyleClass( "ShiledingSourceOptionsBtn" );
42904282
addItemMenubutton->addStyleClass( "GearIcon" );
42914283

0 commit comments

Comments
 (0)