2015-07-30 17:42:58 -07:00
/ *
2017-12-24 19:40:14 -08:00
Copyright ( c ) 2017 , Kevin Pope , John Lewin
2015-07-30 17:42:58 -07:00
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 .
* /
2018-04-28 22:00:21 -07:00
using System ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using System.Collections.Generic ;
2017-09-25 13:45:42 -07:00
using System.IO ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using System.Linq ;
2015-07-30 17:42:58 -07:00
using MatterHackers.Agg ;
2017-09-25 13:45:42 -07:00
using MatterHackers.Agg.Platform ;
2015-07-30 17:42:58 -07:00
using MatterHackers.Agg.UI ;
2015-08-27 11:56:01 -07:00
using MatterHackers.Localizations ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
using MatterHackers.MatterControl.Library ;
2018-04-28 22:12:18 -07:00
using MatterHackers.VectorMath ;
2015-07-30 17:42:58 -07:00
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
namespace MatterHackers.MatterControl.CustomWidgets
2015-07-30 17:42:58 -07:00
{
public class FolderBreadCrumbWidget : FlowLayoutWidget
{
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
private ListView listView ;
public FolderBreadCrumbWidget ( ListView listView )
2015-07-30 17:42:58 -07:00
{
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
this . listView = listView ;
2017-09-25 13:45:42 -07:00
2017-12-24 19:40:14 -08:00
this . Name = "FolderBreadCrumbWidget" ;
2017-09-25 13:45:42 -07:00
this . HAnchor = HAnchor . Stretch ;
this . VAnchor = VAnchor . Fit | VAnchor . Center ;
2018-04-28 22:00:21 -07:00
this . MinimumSize = new VectorMath . Vector2 ( 0 , 1 ) ; // Force some minimum bounds to ensure draw and thus onload (and our local init) are called on startup
2015-08-27 15:17:44 -07:00
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
public static IEnumerable < ILibraryContainer > ItemAndParents ( ILibraryContainer item )
2015-08-27 15:17:44 -07:00
{
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
var container = item ;
while ( container ! = null )
{
yield return container ;
container = container . Parent ;
}
}
2015-07-30 17:42:58 -07:00
2017-12-24 19:40:14 -08:00
public void SetContainer ( ILibraryContainer currentContainer )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-06-19 18:52:10 -07:00
var linkButtonFactory = ApplicationController . Instance . Theme . LinkButtonFactory ;
2017-12-24 19:40:14 -08:00
var theme = ApplicationController . Instance . Theme ;
2015-07-31 16:01:57 -07:00
2017-12-24 19:40:14 -08:00
this . CloseAllChildren ( ) ;
2015-08-25 15:26:38 -07:00
2018-04-28 22:12:18 -07:00
var upbutton = new IconButton ( AggContext . StaticData . LoadIcon ( Path . Combine ( "FileDialog" , "up_folder_20.png" ) , theme . InvertIcons ) , theme )
{
VAnchor = VAnchor . Fit | VAnchor . Center ,
Enabled = currentContainer . Parent ! = null ,
Name = "Library Up Button" ,
Margin = theme . ButtonSpacing ,
MinimumSize = new Vector2 ( theme . ButtonHeight , theme . ButtonHeight )
} ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
upbutton . Click + = ( s , e ) = >
2015-07-30 17:42:58 -07:00
{
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
if ( listView . ActiveContainer . Parent ! = null )
2015-07-30 17:42:58 -07:00
{
2017-12-17 11:14:31 -08:00
UiThread . RunOnIdle ( ( ) = > listView . SetActiveContainer ( listView . ActiveContainer . Parent ) ) ;
2015-07-30 17:42:58 -07:00
}
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
} ;
this . AddChild ( upbutton ) ;
2015-07-30 17:42:58 -07:00
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
bool firstItem = true ;
2017-06-16 22:09:07 -07:00
if ( this . Width < 250 )
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
{
2017-11-03 13:43:31 -07:00
Button containerButton = linkButtonFactory . Generate ( listView . ActiveContainer . Name = = null ? "?" : listView . ActiveContainer . Name ) ;
2017-06-16 22:09:07 -07:00
containerButton . Name = "Bread Crumb Button " + listView . ActiveContainer . Name ;
2017-08-07 15:47:27 -07:00
containerButton . VAnchor = VAnchor . Center ;
2018-04-28 22:12:18 -07:00
containerButton . Margin = theme . ButtonSpacing ;
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
2017-06-16 22:09:07 -07:00
this . AddChild ( containerButton ) ;
2015-07-30 17:42:58 -07:00
}
2017-06-16 22:09:07 -07:00
else
2015-08-25 15:26:38 -07:00
{
2018-05-31 09:04:50 -07:00
var extraSpacing = ( theme . ButtonSpacing ) . Clone ( left : theme . ButtonSpacing . Right * . 4 ) ;
2017-06-16 22:09:07 -07:00
foreach ( var container in ItemAndParents ( currentContainer ) . Reverse ( ) )
2015-09-22 12:21:11 -07:00
{
2017-06-16 22:09:07 -07:00
if ( ! firstItem )
{
2018-04-28 22:12:18 -07:00
// Add path separator
2018-05-31 09:04:50 -07:00
var textContainer = new GuiWidget ( ) // HACK: Workaround for VAlign.Center failure in this specific case. Remove wrapper(with padding) once fixed and directly add TextWidget child
2018-04-28 22:12:18 -07:00
{
2018-05-31 09:04:50 -07:00
HAnchor = HAnchor . Fit ,
VAnchor = VAnchor . Fit | VAnchor . Center ,
Padding = new BorderDouble ( top : 4 ) ,
Margin = extraSpacing ,
} ;
textContainer . AddChild ( new TextWidget ( "/" , pointSize : theme . DefaultFontSize + 2 , textColor : ActiveTheme . Instance . PrimaryTextColor ) ) ;
this . AddChild ( textContainer ) ;
2017-06-16 22:09:07 -07:00
}
2017-12-25 09:13:56 -08:00
// Create a button for each container
2017-12-25 08:34:57 -08:00
Button containerButton = linkButtonFactory . Generate ( container . Name ) ;
containerButton . Name = "Bread Crumb Button " + container . Name ;
containerButton . VAnchor = VAnchor . Center ;
2018-04-28 22:12:18 -07:00
containerButton . Margin = theme . ButtonSpacing ;
2017-12-25 08:34:57 -08:00
containerButton . Click + = ( s , e ) = >
2017-06-16 22:09:07 -07:00
{
2017-12-17 11:14:31 -08:00
UiThread . RunOnIdle ( ( ) = > listView . SetActiveContainer ( container ) ) ;
2017-06-16 22:09:07 -07:00
} ;
2017-12-25 08:34:57 -08:00
this . AddChild ( containerButton ) ;
2017-06-16 22:09:07 -07:00
firstItem = false ;
2015-09-22 12:21:11 -07:00
}
2017-06-16 22:09:07 -07:00
// while all the buttons don't fit in the control
if ( this . Parent ! = null
& & this . Width > 0
& & this . Children . Count > 4
& & this . GetChildrenBoundsIncludingMargins ( ) . Width > ( this . Width - 20 ) )
2015-07-30 17:42:58 -07:00
{
2017-06-16 22:09:07 -07:00
// lets take out the > and put in a ...
this . RemoveChild ( 1 ) ;
2017-06-19 18:52:10 -07:00
var separator = new TextWidget ( "..." , textColor : ActiveTheme . Instance . PrimaryTextColor )
{
2017-08-07 15:47:27 -07:00
VAnchor = VAnchor . Center ,
2017-06-19 18:52:10 -07:00
Margin = new BorderDouble ( right : 5 )
} ;
2017-06-16 22:09:07 -07:00
this . AddChild ( separator , 1 ) ;
while ( this . GetChildrenBoundsIncludingMargins ( ) . Width > this . Width - 20
& & this . Children . Count > 4 )
{
this . RemoveChild ( 3 ) ;
this . RemoveChild ( 2 ) ;
}
2015-07-30 17:42:58 -07:00
}
}
}
2017-12-25 09:13:56 -08:00
2018-04-28 22:00:21 -07:00
public override void OnLoad ( EventArgs args )
{
this . SetContainer ( listView . ActiveContainer ) ;
base . OnLoad ( args ) ;
}
2015-07-30 17:42:58 -07:00
}
}