|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Signum.Entities;
using System.Collections;
using Signum.Utilities;
using Signum.Entities.Basics;
namespace Signum.Windows
{
/// <summary>
/// Interaction logic for ListaNavegacion.xaml
/// </summary>
public partial class LeftNavigationPanel : UserControl
{
public IHaveQuickLinks IHasQuickLinks { get; set; }
public LeftNavigationPanel()
{
InitializeComponent();
this.DataContextChanged += new DependencyPropertyChangedEventHandler(LeftNavigationPanel_DataContextChanged);
lvQuickLinks.AddHandler(Button.ClickEvent, new RoutedEventHandler(QuickLink_MouseDown));
lvNotas.AddHandler(Button.ClickEvent, new RoutedEventHandler(Note_MouseDown));
}
void LeftNavigationPanel_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (IHasQuickLinks!= null)
{
lvQuickLinks.ItemsSource = IHasQuickLinks.QuickLinks();
borderQuickLinks.Visibility = Visibility.Visible;
}
else
{
borderQuickLinks.Visibility = Visibility.Collapsed;
}
ReloadNotes();
if (borderQuickLinks.Visibility == Visibility.Collapsed &&
borderNotas.Visibility == Visibility.Collapsed)
{
Visibility = Visibility.Collapsed;
}
else
{
Visibility = Visibility.Visible;
}
if (borderQuickLinks.Visibility == Visibility.Collapsed && ((IList)lvNotas.ItemsSource).Map(a=>a == null || a.Count == 0))
{
expander.IsExpanded = false;
}
}
private void ReloadNotes()
{
if (NotesProvider.Manager != null && DataContext is IdentifiableEntity)
{
List<Lazy<INoteDN>> notes = NotesProvider.Manager.RetrieveNotes((IdentifiableEntity)DataContext);
if (notes == null)
borderNotas.Visibility = Visibility.Collapsed;
else
{
borderNotas.Visibility = Visibility.Visible;
tbNotas.FontWeight = notes.Count == 0 ? FontWeights.Normal : FontWeights.Bold;
}
lvNotas.ItemsSource = notes;
}
else
{
borderNotas.Visibility = Visibility.Collapsed;
}
}
private void QuickLink_MouseDown(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is Button) //Not to capture the mouseDown of the scrollbar buttons
{
Button b = (Button)e.OriginalSource;
((Action)b.Tag).Invoke();
}
}
private void Note_MouseDown(object sender, RoutedEventArgs e)
{
if (e.OriginalSource is Button) //Not to capture the mouseDown of the scrollbar buttons
{
Button b = (Button)e.OriginalSource;
Lazy<INoteDN> nota = (Lazy<INoteDN>)b.Tag;
ViewNote(Server.RetrieveFromLazyAndForget(nota));
}
}
private void btnNewNote_Click(object sender, RoutedEventArgs e)
{
INoteDN nota = NotesProvider.Manager.CreateNote((IdentifiableEntity)DataContext);
ViewNote(nota);
}
void ViewNote(INoteDN note)
{
INoteDN result = (INoteDN)Navigator.View(new ViewOptions { Buttons = ViewButtons.SaveClose, Modal = true }, note);
ReloadNotes();
}
}
/// <summary>
/// Controls must implement this interface to have the left navigation panel
/// </summary>
public interface IHaveQuickLinks
{
List<QuickLink> QuickLinks();
}
/// <summary>
/// Represents an item of the left navigation panel
/// </summary>
public class QuickLink
{
public QuickLink(string label)
{
this.Label = label;
}
/// <summary>
/// Display name of the item
/// </summary>
public string Label { get; set; }
/// <summary>
/// Action to be executed on the mouseDoubleClick of the item
/// </summary>
public Action Action { get; set; }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I'm Computer Scientist, one of the founders of Signum Software, and the lead developer behind Signum Framework.
www.signumframework.com
I love programming in C#, Linq, Compilers, Algorithms, Functional Programming, Computer Graphics, Maths...