Skip to content
Browse files

Merge branch 'master' of https://github.com/fitzchak1/ravendb

  • Loading branch information...
2 parents 092b01f + 4154a2e commit f00a9e3d94ff2e3bf706aa07c18c2e3e6c3a9df5 @ayende ayende committed Dec 5, 2011
View
42 Raven.Studio/Behaviors/SelectItemOnRightClick.cs
@@ -0,0 +1,42 @@
+// -----------------------------------------------------------------------
+// <copyright file="SelectItemOnRightClick.cs" company="Hibernating Rhinos LTD">
+// Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// </copyright>
+// -----------------------------------------------------------------------
+
+using System.Linq;
+using System.Windows.Controls;
+using System.Windows.Input;
+using System.Windows.Interactivity;
+using System.Windows.Media;
+
+namespace Raven.Studio.Behaviors
+{
+ public class SelectItemOnRightClick : Behavior<ListBox>
+ {
+ protected override void OnAttached()
+ {
+ AssociatedObject.MouseRightButtonDown += AssociatedObjectOnMouseRightButtonDown;
+ base.OnAttached();
+ }
+
+ protected override void OnDetaching()
+ {
+ AssociatedObject.MouseRightButtonDown -= AssociatedObjectOnMouseRightButtonDown;
+ base.OnDetaching();
+ }
+
+ void AssociatedObjectOnMouseRightButtonDown(object sender, MouseButtonEventArgs e)
+ {
+ var item = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(null),AssociatedObject)
+ .OfType<ListBoxItem>()
+ .FirstOrDefault();
+
+ if (item == null || AssociatedObject.SelectedItems.Contains(item.DataContext))
+ return;
+
+ AssociatedObject.SelectedItems.Clear();
+ item.IsSelected = true;
+ }
+ }
+}
View
20 Raven.Studio/Behaviors/ShowItemsBasedOnControlDimensions.cs
@@ -4,6 +4,7 @@
using System.Windows.Controls;
using System.Windows.Interactivity;
using Raven.Studio.Models;
+using Raven.Studio.Infrastructure;
namespace Raven.Studio.Behaviors
{
@@ -22,10 +23,10 @@ public DocumentsModel Model
protected override void OnAttached()
{
- var events = Observable.FromEventPattern<EventArgs>(AssociatedObject, "SizeChanged")
- .Concat(Observable.FromEventPattern<EventArgs>(DocumentsModel.DocumentSize, "PropertyChanged"))
+ var events = Observable.FromEventPattern<SizeChangedEventHandler, SizeChangedEventArgs>(e => AssociatedObject.SizeChanged += e, e => AssociatedObject.SizeChanged -= e).NoSignature()
+ .Merge(Observable.FromEventPattern<EventHandler, EventArgs>(e => DocumentsModel.DocumentSize.SizeChanged += e, e => DocumentsModel.DocumentSize.SizeChanged -= e))
.Throttle(TimeSpan.FromSeconds(0.5))
- .Concat(Observable.FromEventPattern<EventArgs>(AssociatedObject, "Loaded")) // Loaded should execute immediately.
+ .Merge(Observable.FromEventPattern<RoutedEventHandler, EventArgs>(e => AssociatedObject.Loaded += e, e => AssociatedObject.Loaded -= e)) // Loaded should execute immediately.
.ObserveOnDispatcher();
disposable = events.Subscribe(_ => CalculatePageSize());
@@ -42,9 +43,16 @@ private void CalculatePageSize()
if (Model == null)
return;
- var row = AssociatedObject.ActualWidth / DocumentsModel.DocumentSize.Width;
- var column = AssociatedObject.ActualHeight / DocumentsModel.DocumentSize.Height;
- Model.Pager.PageSize = (int)(row * column);
+ // ReSharper disable CompareOfFloatsByEqualityOperator
+ if (AssociatedObject.ActualWidth == 0)
+ return;
+ // ReSharper restore CompareOfFloatsByEqualityOperator
+
+ int row = (int) (AssociatedObject.ActualWidth / (DocumentsModel.DocumentSize.Width + 28));
+ int column = (int) (AssociatedObject.ActualHeight / (DocumentsModel.DocumentSize.Height + 24));
+ int pageSize = row * column;
+ Model.Pager.PageSize = pageSize;
+ Model.Pager.OnPagerChanged();
}
}
}
View
9 Raven.Studio/Features/Documents/DocumentsView.xaml
@@ -118,6 +118,11 @@
Grid.ColumnSpan="3"
Margin="10"
ItemTemplate="{StaticResource DataTemplate_Document_CardView}">
+
+ <i:Interaction.Behaviors>
+ <Behaviors:SelectItemOnRightClick />
+ <Behaviors:ShowItemsBasedOnControlDimensions Model="{Binding}" />
+ </i:Interaction.Behaviors>
<Controls:ContextMenuService.ContextMenu>
<Controls:ContextMenu x:Name="DocumentsContextMenu">
@@ -129,10 +134,6 @@
CommandParameter="{Binding RelativeSource={RelativeSource Self}}" />
</Controls:ContextMenu>
</Controls:ContextMenuService.ContextMenu>
-
- <i:Interaction.Behaviors>
- <Behaviors:ShowItemsBasedOnControlDimensions Model="{Binding}" />
- </i:Interaction.Behaviors>
</ListBox>
</toolkit:HeaderedContentControl>
View
25 Raven.Studio/Features/Documents/ViewableDocument.cs
@@ -29,19 +29,11 @@ public ViewableDocument(JsonDocument inner)
ClrType = inner.Metadata.IfPresent<string>(Constants.RavenClrType);
CollectionType = DetermineCollectionType(inner.Metadata);
- Observable.FromEventPattern<EventArgs>(DocumentsModel.DocumentSize, "SizeChanged")
+ Observable.FromEventPattern<EventHandler, EventArgs>(e => DocumentsModel.DocumentSize.SizeChanged += e, e => DocumentsModel.DocumentSize.SizeChanged -= e)
.Throttle(TimeSpan.FromSeconds(0.5))
- .Subscribe(e =>
- {
- string d = null;
- if (DocumentsModel.DocumentSize.Height >= DocumentsModel.ExpandedMinimumHeight)
- {
- var margin = Math.Sqrt(DocumentsModel.DocumentSize.Width) - 4;
- d = ShortViewOfJson.GetContentDataWithMargin(inner.DataAsJson, (int)margin);
- }
- Execute.OnTheUI(() => Data = d);
- });
+ .Subscribe(_ => CalculateData());
+ CalculateData();
ToolTipText = ShortViewOfJson.GetContentDataWithMargin(inner.DataAsJson, 10);
}
@@ -78,7 +70,16 @@ public string Data
}
}
-
+ private void CalculateData()
+ {
+ string d = null;
+ if (DocumentsModel.DocumentSize.Height >= DocumentsModel.ExpandedMinimumHeight)
+ {
+ var margin = Math.Sqrt(DocumentsModel.DocumentSize.Width) - 4;
+ d = ShortViewOfJson.GetContentDataWithMargin(inner.DataAsJson, (int)margin);
+ }
+ Execute.OnTheUI(() => Data = d);
+ }
public string DisplayId
{
View
18 Raven.Studio/Features/Query/QueryView.xaml
@@ -8,7 +8,8 @@
xmlns:Documents="clr-namespace:Raven.Studio.Features.Documents"
xmlns:Editors="clr-namespace:Raven.Studio.Controls.Editors"
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
- xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
+ xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
+ xmlns:Controls="clr-namespace:System.Windows.Controls">
<toolkit:DockPanel Margin="{StaticResource Margin_ContentPage}">
<Border Background="{StaticResource Brush_HeaderBackground}"
@@ -69,7 +70,7 @@
ToolTipService.ToolTip="Add sort by option for this query"
VerticalAlignment="Center"
HorizontalAlignment="Left"
- Margin="0,0,4,0"
+ Margin="0,0,6,0"
Command="{Binding AddSortBy}"
Visibility="{Binding Path=SortByOptions.Count, Converter={StaticResource HiddenWhenEmpty}}"
VerticalContentAlignment="Center">
@@ -86,6 +87,11 @@
</Button.Content>
</Button>
+ <Controls:Separator Style="{StaticResource Style_Separator_HeaderLink}"
+ VerticalAlignment="Center"
+ Height="20"
+ Margin="2,0,6,0" />
+
<Button Grid.Column="1"
Command="{Binding Execute}"
HorizontalAlignment="Right"
@@ -259,12 +265,12 @@
</StackPanel>
- <Border Grid.Row="2"
- Margin="{StaticResource Margin_ContentPage}"
- Visibility="{Binding Path=DocumentsResult.Value, Converter={StaticResource HiddenWhenNull}}">
+ <Grid Grid.Row="2"
+ Margin="{StaticResource Margin_ContentPage}"
+ Visibility="{Binding Path=DocumentsResult.Value, Converter={StaticResource HiddenWhenNull}}">
<Documents:DocumentsView Visibility="{Binding Path=Documents.Count, Converter={StaticResource HiddenWhenEmpty}}"
DataContext="{Binding Path=DocumentsResult.Value}" />
- </Border>
+ </Grid>
</Grid>
</toolkit:DockPanel>
</Infrastructure:View>
View
14 Raven.Studio/Infrastructure/RxExtensions.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Reactive;
+using System.Reactive.Linq;
+
+namespace Raven.Studio.Infrastructure
+{
+ public static class RxExtensions
+ {
+ public static IObservable<object> NoSignature<T>(this IObservable<EventPattern<T>> observable) where T : EventArgs
+ {
+ return observable.Select(e => (object) null);
+ }
+ }
+}
View
8 Raven.Studio/Models/AllDocumentsModel.cs
@@ -9,7 +9,13 @@ static AllDocumentsModel()
{
Documents = new Observable<DocumentsModel>();
Documents.Value = new DocumentsModel();
- Documents.Value.Pager.SetTotalResults(new Observable<long?>(ApplicationModel.Database.Value.Statistics, v => ((DatabaseStatistics)v).CountOfDocuments));
+ SetTotalResults();
+ ApplicationModel.Current.Server.Value.SelectedDatabase.PropertyChanged += (sender, args) => SetTotalResults();
+ }
+
+ private static void SetTotalResults()
+ {
+ Documents.Value.Pager.SetTotalResults(new Observable<long?>(ApplicationModel.Database.Value.Statistics, v => ((DatabaseStatistics) v).CountOfDocuments));
}
public AllDocumentsModel()
View
2 Raven.Studio/Models/DocumentsModel.cs
@@ -30,7 +30,7 @@ public DocumentsModel()
Documents.CollectionChanged += (sender, args) => DetermineDocumentViewStyle();
Pager = new PagerModel();
- Pager.Navigated += (sender, args) => ForceTimerTicked();
+ Pager.PagerChanged += (sender, args) => ForceTimerTicked();
ShowEditControls = true;
}
View
30 Raven.Studio/Models/PagerModel.cs
@@ -7,25 +7,36 @@ namespace Raven.Studio.Models
{
public class PagerModel : NotifyPropertyChangedBase
{
- public event EventHandler Navigated;
+ public event EventHandler PagerChanged;
public PagerModel()
{
PageSize = 25;
- SetTotalResults(new Observable<long?>());
+ SetTotalResults();
}
- public void SetTotalResults(Observable<long?> observable)
+ public void SetTotalResults(Observable<long?> observable = null)
{
- TotalResults = observable;
+ TotalResults = observable ?? new Observable<long?>();
TotalResults.PropertyChanged += (sender, args) =>
{
OnPropertyChanged("TotalPages");
OnPropertyChanged("HasNextPage");
};
}
- public int PageSize { get; set; }
+ private int pageSize;
+ public int PageSize
+ {
+ get { return pageSize; }
+ set
+ {
+ pageSize = value;
+ OnPropertyChanged();
+ OnPropertyChanged("CurrentPage");
+ OnPropertyChanged("TotalPages");
+ }
+ }
public int CurrentPage
{
@@ -92,8 +103,13 @@ private void NavigateToPage(int pageOffset)
urlParser.SetQueryParam("skip", Skip);
UrlUtil.Navigate(urlParser.BuildUrl());
- if (Navigated != null)
- Navigated(this, EventArgs.Empty);
+ OnPagerChanged();
+ }
+
+ public void OnPagerChanged()
+ {
+ if (PagerChanged != null)
+ PagerChanged(this, EventArgs.Empty);
}
public ICommand NextPage
View
2 Raven.Studio/Raven.Studio.csproj
@@ -115,6 +115,7 @@
<DependentUpon>App.xaml</DependentUpon>
</Compile>
<EmbeddedResource Include="Assets\EmbeddedData\MvcMusicStore_Dump.json" />
+ <Compile Include="Behaviors\SelectItemOnRightClick.cs" />
<Compile Include="Behaviors\ShowItemsBasedOnControlDimensions.cs" />
<Compile Include="Behaviors\UpdateTextBindingOnPropertyChanged.cs" />
<Compile Include="Behaviors\DoubleClickBehavior.cs" />
@@ -261,6 +262,7 @@
<Compile Include="Infrastructure\Converters\NullToVisibilityConverter.cs" />
<Compile Include="Infrastructure\KeysComparer.cs" />
<Compile Include="Infrastructure\Execute.cs" />
+ <Compile Include="Infrastructure\RxExtensions.cs" />
<Compile Include="Infrastructure\StringExtensions.cs" />
<Compile Include="Infrastructure\UrlParser.cs" />
<Compile Include="Infrastructure\UrlUtil.cs" />

0 comments on commit f00a9e3

Please sign in to comment.
Something went wrong with that request. Please try again.