2015-05-20 10:55:14 -07:00
/ *
Copyright ( c ) 2015 , Kevin Pope
All rights reserved .
Redistribution and use in source and binary forms , with or without
modification , are permitted provided that the following conditions are met :
1. Redistributions of source code must retain the above copyright notice , this
list of conditions and the following disclaimer .
2. Redistributions in binary form must reproduce the above copyright notice ,
this list of conditions and the following disclaimer in the documentation
and / or other materials provided with the distribution .
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES , INCLUDING , BUT NOT LIMITED TO , THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED . IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT , INDIRECT , INCIDENTAL , SPECIAL , EXEMPLARY , OR CONSEQUENTIAL DAMAGES
( INCLUDING , BUT NOT LIMITED TO , PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES ;
LOSS OF USE , DATA , OR PROFITS ; OR BUSINESS INTERRUPTION ) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY , WHETHER IN CONTRACT , STRICT LIABILITY , OR TORT
( INCLUDING NEGLIGENCE OR OTHERWISE ) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE , EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE .
The views and conclusions contained in the software and documentation are those
of the authors and should not be interpreted as representing official policies ,
either expressed or implied , of the FreeBSD Project .
* /
using MatterHackers.Agg ;
2014-12-09 15:16:08 -08:00
using MatterHackers.Agg.UI ;
using MatterHackers.MatterControl.CustomWidgets ;
2015-07-14 17:59:41 -07:00
using MatterHackers.MatterControl.AboutPage ;
2015-05-20 10:55:14 -07:00
using System ;
using MatterHackers.Localizations ;
2014-12-09 15:16:08 -08:00
namespace MatterHackers.MatterControl
{
2015-04-08 15:20:10 -07:00
public class ApplicationMenuRow : FlowLayoutWidget
{
2015-07-02 14:36:04 -07:00
public delegate void AddRightElementDelegate ( GuiWidget iconContainer ) ;
public static event AddRightElementDelegate AddRightElement ;
2015-05-20 10:55:14 -07:00
2015-05-22 12:33:59 -07:00
public static bool AlwaysShowUpdateStatus { get ; set ; }
2015-07-02 14:36:04 -07:00
private FlowLayoutWidget rightElement ;
LinkButtonFactory linkButtonFactory = new LinkButtonFactory ( ) ;
private event EventHandler unregisterEvents ;
2015-05-20 10:55:14 -07:00
GuiWidget popUpAboutPage ;
2015-04-08 15:20:10 -07:00
public ApplicationMenuRow ( )
: base ( FlowDirection . LeftToRight )
{
linkButtonFactory . textColor = ActiveTheme . Instance . PrimaryTextColor ;
linkButtonFactory . fontSize = 8 ;
Button signInLink = linkButtonFactory . Generate ( "(Sign Out)" ) ;
2015-08-12 13:16:39 -07:00
signInLink . ToolTipText = "Sign in to your MatterControl account" . Localize ( ) ;
2015-04-08 15:20:10 -07:00
signInLink . VAnchor = Agg . UI . VAnchor . ParentCenter ;
signInLink . Margin = new BorderDouble ( top : 0 ) ;
this . HAnchor = HAnchor . ParentLeftRight ;
this . BackgroundColor = ActiveTheme . Instance . PrimaryBackgroundColor ;
2014-12-09 15:16:08 -08:00
2015-02-13 17:35:48 -08:00
// put in the file menu
MenuOptionFile menuOptionFile = new MenuOptionFile ( ) ;
this . AddChild ( menuOptionFile ) ;
2014-12-09 15:16:08 -08:00
2015-05-19 14:43:24 -07:00
MenuOptionSettings menuOptionSettings = new MenuOptionSettings ( ) ;
this . AddChild ( menuOptionSettings ) ;
2015-02-13 17:35:48 -08:00
// put in the help menu
2015-04-08 15:20:10 -07:00
MenuOptionHelp menuOptionHelp = new MenuOptionHelp ( ) ;
this . AddChild ( menuOptionHelp ) ;
2015-05-22 16:11:52 -07:00
//linkButtonFactory.textColor = ActiveTheme.Instance.SecondaryAccentColor;
2015-05-20 10:55:14 -07:00
linkButtonFactory . fontSize = 10 ;
Button updateStatusMessage = linkButtonFactory . Generate ( "Update Available" ) ;
UpdateControlData . Instance . UpdateStatusChanged . RegisterEvent ( SetUpdateNotification , ref unregisterEvents ) ;
2015-06-15 09:55:38 -07:00
popUpAboutPage = new FlowLayoutWidget ( ) ;
2015-05-20 10:55:14 -07:00
popUpAboutPage . Margin = new BorderDouble ( 30 , 0 , 0 , 0 ) ;
popUpAboutPage . HAnchor = HAnchor . FitToChildren ;
popUpAboutPage . VAnchor = VAnchor . FitToChildren | VAnchor . ParentCenter ;
popUpAboutPage . AddChild ( updateStatusMessage ) ;
updateStatusMessage . Click + = ( sender , e ) = >
{
2015-07-14 17:59:41 -07:00
UiThread . RunOnIdle ( CheckForUpdateWindow . Show ) ;
2015-05-20 10:55:14 -07:00
} ;
this . AddChild ( popUpAboutPage ) ;
SetUpdateNotification ( this , null ) ;
2015-04-08 15:20:10 -07:00
// put in a spacer
this . AddChild ( new HorizontalSpacer ( ) ) ;
// make an object that can hold custom content on the right (like the sign in)
rightElement = new FlowLayoutWidget ( FlowDirection . LeftToRight ) ;
rightElement . Height = 24 ;
rightElement . Margin = new BorderDouble ( bottom : 4 ) ;
this . AddChild ( rightElement ) ;
2014-12-09 15:16:08 -08:00
2015-04-08 15:20:10 -07:00
this . Padding = new BorderDouble ( 0 , 0 , 6 , 0 ) ;
2014-12-09 15:16:08 -08:00
2015-07-15 12:28:52 -07:00
if ( AddRightElement ! = null )
2015-05-22 12:33:59 -07:00
{
2015-07-15 12:28:52 -07:00
AddRightElement ( rightElement ) ;
}
// When the application is first started, plugins are loaded after the MainView control has been initialize,
// and such they not around when this constructor executes. In that case, we run the AddRightElement
// delegate after the plugins get initialized via the PluginsLoaded event
ApplicationController . Instance . PluginsLoaded . RegisterEvent ( PluginsLoaded , ref unregisterEvents ) ;
}
2015-05-22 12:33:59 -07:00
2015-07-15 12:28:52 -07:00
public void PluginsLoaded ( object sender , EventArgs e )
{
if ( AddRightElement ! = null )
{
AddRightElement ( rightElement ) ;
}
2015-05-22 12:33:59 -07:00
}
2015-05-20 10:55:14 -07:00
public override void OnClosed ( EventArgs e )
{
if ( unregisterEvents ! = null )
{
unregisterEvents ( this , null ) ;
}
base . OnClosed ( e ) ;
}
public void SetUpdateNotification ( object sender , EventArgs widgetEvent )
{
switch ( UpdateControlData . Instance . UpdateStatus )
{
case UpdateControlData . UpdateStatusStates . MayBeAvailable :
{
popUpAboutPage . RemoveAllChildren ( ) ;
Button updateStatusMessage = linkButtonFactory . Generate ( "Check For Update" . Localize ( ) ) ;
updateStatusMessage . Click + = ( sender2 , e ) = >
{
2015-07-14 17:59:41 -07:00
UiThread . RunOnIdle ( CheckForUpdateWindow . Show ) ;
2015-05-20 10:55:14 -07:00
} ;
popUpAboutPage . AddChild ( updateStatusMessage ) ;
popUpAboutPage . Visible = true ;
}
break ;
case UpdateControlData . UpdateStatusStates . ReadyToInstall :
case UpdateControlData . UpdateStatusStates . UpdateAvailable :
case UpdateControlData . UpdateStatusStates . UpdateDownloading :
{
popUpAboutPage . RemoveAllChildren ( ) ;
Button updateStatusMessage = linkButtonFactory . Generate ( "Update Available" . Localize ( ) ) ;
updateStatusMessage . Click + = ( sender2 , e ) = >
{
2015-07-15 18:11:11 -07:00
UiThread . RunOnIdle ( CheckForUpdateWindow . Show ) ;
2015-05-20 10:55:14 -07:00
} ;
2015-06-15 09:55:38 -07:00
var updateMark = new UpdateNotificationMark ( ) ;
2015-06-22 15:12:48 -07:00
updateMark . Margin = new BorderDouble ( 0 , 0 , 3 , 2 ) ;
2015-06-15 09:55:38 -07:00
updateMark . VAnchor = VAnchor . ParentTop ;
popUpAboutPage . AddChild ( updateMark ) ;
2015-05-20 10:55:14 -07:00
popUpAboutPage . AddChild ( updateStatusMessage ) ;
popUpAboutPage . Visible = true ;
}
break ;
case UpdateControlData . UpdateStatusStates . UpToDate :
2015-05-22 12:33:59 -07:00
if ( AlwaysShowUpdateStatus )
{
popUpAboutPage . RemoveAllChildren ( ) ;
2015-05-22 16:11:52 -07:00
TextWidget updateStatusMessage = new TextWidget ( "Up to Date" . Localize ( ) , textColor : linkButtonFactory . textColor , pointSize : linkButtonFactory . fontSize ) ;
2015-05-22 12:33:59 -07:00
updateStatusMessage . VAnchor = VAnchor . ParentCenter ;
popUpAboutPage . AddChild ( updateStatusMessage ) ;
popUpAboutPage . Visible = true ;
UiThread . RunOnIdle ( ( state ) = > popUpAboutPage . Visible = false , 3 ) ;
AlwaysShowUpdateStatus = false ;
}
else
{
popUpAboutPage . Visible = false ;
}
break ;
2015-05-20 10:55:14 -07:00
case UpdateControlData . UpdateStatusStates . CheckingForUpdate :
2015-05-22 12:33:59 -07:00
if ( AlwaysShowUpdateStatus )
{
popUpAboutPage . RemoveAllChildren ( ) ;
2015-05-26 10:51:43 -07:00
TextWidget updateStatusMessage = new TextWidget ( "Checking For Update..." . Localize ( ) , textColor : linkButtonFactory . textColor , pointSize : linkButtonFactory . fontSize ) ;
2015-05-22 12:33:59 -07:00
updateStatusMessage . VAnchor = VAnchor . ParentCenter ;
popUpAboutPage . AddChild ( updateStatusMessage ) ;
popUpAboutPage . Visible = true ;
}
else
{
popUpAboutPage . Visible = false ;
}
2015-05-20 10:55:14 -07:00
break ;
default :
throw new NotImplementedException ( ) ;
}
}
2015-04-08 15:20:10 -07:00
}
}