Skip to content

Commit

Permalink
Fix context-menus not showing up in some places, and mobile menus not…
Browse files Browse the repository at this point in the history
… behaving correctly.
  • Loading branch information
wcjohns committed Jul 15, 2021
1 parent 7fe2a29 commit 9a666d9
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 78 deletions.
2 changes: 2 additions & 0 deletions InterSpec/PopupDiv.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class PopupDivMenu : public Wt::WPopupMenu
void parentMouseWentOver();
void undoParentHoveredOver();

bool isMobile() const;

protected:
void desktopDoHide();

Expand Down
24 changes: 10 additions & 14 deletions src/InterSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,6 @@ InterSpec::InterSpec( WContainerWidget *parent )

//hamburger
PopupDivMenu *popup = new PopupDivMenu( m_mobileMenuButton, PopupDivMenu::AppLevelMenu );
popup->addPhoneBackItem( nullptr );

m_mobileMenuButton->removeStyleClass( "Wt-btn" );
menuWidget = popup;

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

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

if( isMobile() )
if( m_rightClickMenu->isMobile() )
{
m_rightClickMenu->addPhoneBackItem( nullptr );
}else
{
PopupDivMenuItem *item = m_rightClickMenu->addPhoneBackItem( NULL );
item->triggered().connect( boost::bind(&PopupDivMenu::setHidden, m_rightClickMenu, true, WAnimation()) );
}//if( isPhone() || isTablet() )
m_rightClickMenu->setPositionScheme( Wt::Absolute );
m_rightClickMenu->addStyleClass( " Wt-popupmenu Wt-outset" );
}

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

if( isMobile() )
if( m_rightClickMenu->isMobile() )
m_rightClickMenu->showMobile();
else
m_rightClickMenu->popup( WPoint(pageX,pageY) );
Expand Down Expand Up @@ -10270,10 +10269,7 @@ void InterSpec::userAskedToFitPeaksInRange( double x0, double x1,
menu->aboutToHide().connect( menu, &DeleteOnClosePopupMenu::markForDelete );
menu->setPositionScheme( Wt::Absolute );

PopupDivMenuItem *item = 0;
if( isMobile() )
item = menu->addPhoneBackItem( NULL );
// item->triggered().connect( boost::bind( &deleteMenu, menu ) );
PopupDivMenuItem *item = nullptr;

item = menu->addMenuItem( "Single Peak" );
// item->triggered().connect( boost::bind( &InterSpec::findPeakFromUserRange, this, x0, x1 ) );
Expand Down
99 changes: 44 additions & 55 deletions src/PopupDiv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ WT_DECLARE_WT_MEMBER
}, 500 );
});

WT_DECLARE_WT_MEMBER(HideOverlay, Wt::JavaScriptFunction, "HideOverlay", function()
WT_DECLARE_WT_MEMBER(SetupHideOverlay, Wt::JavaScriptFunction, "SetupHideOverlay", function()
{
function hideverything(e)
{
Expand All @@ -152,21 +152,8 @@ WT_DECLARE_WT_MEMBER(HideOverlay, Wt::JavaScriptFunction, "HideOverlay", functio
//Scroll back to the top of the menu
jel.scrollTop(0);

//I cant actually tell the differnce in smoothness between my version
// and jQueries version.
var a = -jel.width() - 10;
jel.animate({left: a+'px'}, {queue: false, duration: 255}, "linear", function(){jel.hide();});

// var w = jel.width(), t0 = (new Date()).valueOf();
// ( function slideout()
// {
// var t = (new Date()).valueOf();
// var pos = -w*((t-t0)/250);
// el.style['left'] = pos + 'px';
// if( pos>-w )
// setTimeout(slideout,1);
// else jel.hidde();
// })()
});

$('.mobilePopupMenuOverlay').hide();
Expand Down Expand Up @@ -668,7 +655,7 @@ PopupDivMenu::PopupDivMenu( Wt::WPushButton *menuParent,
{
addStyleClass( "PopupDivMenuPhone" );
LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "ShowPhone", wtjsShowPhone);
LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "HideOverlay", wtjsHideOverlay);
LOAD_JAVASCRIPT(wApp, "PopupDiv.cpp", "SetupHideOverlay", wtjsSetupHideOverlay);

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

if( menuParent )
if( m_mobile)
{
if( m_mobile)
{
switch( m_type )
{
case AppLevelMenu:
menuParent->clicked().connect( this, &PopupDivMenu::showMobile );
break;

case TransientMenu:
menuParent->setMenu( this );
break;
}//switch( m_type )
}else
if( menuParent )
{
addPhoneBackItem( nullptr );
menuParent->clicked().connect( this, &PopupDivMenu::showMobile );
}//if( menuParent )
}else if( menuParent )
{
#if(USE_OSX_NATIVE_MENU)
if( useNativeMenu && (menutype == AppLevelMenu) )
{
const string buttontxt = menuParent->text().toUTF8();
if( buttontxt.length() )
m_nsmenu = addOsxMenu( this, buttontxt.c_str() );
} //AppLevelMenu
if( useNativeMenu && (menutype == AppLevelMenu) )
{
const string buttontxt = menuParent->text().toUTF8();
if( buttontxt.length() )
m_nsmenu = addOsxMenu( this, buttontxt.c_str() );
} //AppLevelMenu
#endif

#if( USING_ELECTRON_NATIVE_MENU )
if( useNativeMenu && (menutype == AppLevelMenu) )
{
//Here we are adding a menu at the topof the window. "InterSpec", "View", "Tools", "Help"
//In Js, we should find the menu, and get a reference to it.
//app->doJavaScript( "console.log('Adding PopupDivMenu id=" + id() + " parentTxt=" + menuParent->text().toUTF8() + "');" );
app->doJavaScript( "Wt.WT.FindElectronMenu('" + menuParent->text().toUTF8() + "', '" + id() + "');" );
m_hasElectronCounterpart = true;
}
if( useNativeMenu && (menutype == AppLevelMenu) )
{
//Here we are adding a menu at the topof the window. "InterSpec", "View", "Tools", "Help"
//In Js, we should find the menu, and get a reference to it.
//app->doJavaScript( "console.log('Adding PopupDivMenu id=" + id() + " parentTxt=" + menuParent->text().toUTF8() + "');" );
app->doJavaScript( "Wt.WT.FindElectronMenu('" + menuParent->text().toUTF8() + "', '" + id() + "');" );
m_hasElectronCounterpart = true;
}
#endif

if( !useNativeMenu && (menutype == AppLevelMenu) )
setupDesktopMenuStuff();
else
menuParent->setMenu( this );
} //if( m_mobile) / else
}else //if( menuParent )
if( !useNativeMenu && (menutype == AppLevelMenu) )
{
setupDesktopMenuStuff();
}else
{
menuParent->setMenu( this );

const string js = "function(){Wt.WT.BringAboveDialogs('" + id() + "');"
"Wt.WT.AdjustTopPos('" + menuParent->id() + "');}";
menuParent->clicked().connect( js );
}
}else //if( m_mobile) / else if( menuParent )
{
#if( USING_ELECTRON_NATIVE_MENU )
if( m_hasElectronCounterpart && (menutype == AppLevelMenu) )
Expand Down Expand Up @@ -941,17 +927,16 @@ void PopupDivMenu::setHidden( bool hidden, const Wt::WAnimation &animation )

void PopupDivMenu::showMobile()
{
//Note/Hack: This is needed to check if clicked or mouseover. If clicked,
// calling popup() will somehow cause the popupmenu to not show.
// I know, weird huh.
if( m_menuParent )
popup( m_menuParent, Wt::Vertical );

else
popup( {0,0} );

if( m_mobile )
{
doJavaScript("$('.mobilePopupMenuOverlay').show();");
doJavaScript( "Wt.WT.ShowPhone('" + id() + "');" );
doJavaScript( "Wt.WT.HideOverlay();" );
doJavaScript( "Wt.WT.SetupHideOverlay();" );
}//if( m_mobile )
}//void doShow()

Expand Down Expand Up @@ -1008,6 +993,10 @@ void PopupDivMenu::undoParentHoveredOver()
}//void undoParentHoveredOver()


bool PopupDivMenu::isMobile() const
{
return m_mobile;
}

void PopupDivMenu::setupDesktopMenuStuff()
{
Expand Down Expand Up @@ -1307,7 +1296,7 @@ PopupDivMenuItem *PopupDivMenu::addPhoneBackItem( PopupDivMenu *parent )
PopupDivMenu *PopupDivMenu::addPopupMenuItem( const Wt::WString &text,
const std::string &iconPath )
{
PopupDivMenu *menu = new PopupDivMenu( 0, m_type );
PopupDivMenu *menu = new PopupDivMenu( nullptr, m_type );

if( m_mobile )
{
Expand Down
10 changes: 1 addition & 9 deletions src/ShieldingSourceDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4277,15 +4277,7 @@ ShieldingSourceDisplay::ShieldingSourceDisplay( PeakModel *peakModel,

Wt::WPushButton *addItemMenubutton = new WPushButton( " " );
m_addItemMenu = new PopupDivMenu( addItemMenubutton, PopupDivMenu::TransientMenu );
if( m_specViewer->isMobile() )
{
m_addItemMenu->addPhoneBackItem( NULL );
addItemMenubutton->clicked().connect( m_addItemMenu, &PopupDivMenu::showMobile );
} //mobile
else
{
m_addItemMenu->setButton( addItemMenubutton );
} //not mobile

addItemMenubutton->setStyleClass( "ShiledingSourceOptionsBtn" );
addItemMenubutton->addStyleClass( "GearIcon" );

Expand Down

0 comments on commit 9a666d9

Please sign in to comment.