Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/CosmosDbExplorer/CosmosDbExplorer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
<Compile Include="Infrastructure\Models\StatusBarInfo.cs" />
<Compile Include="Infrastructure\Models\UIViewModelBase.cs" />
<Compile Include="Infrastructure\RadioButtonEx.cs" />
<Compile Include="Infrastructure\SortedObservableCollection.cs" />
<Compile Include="Infrastructure\TemplateSelectors\DocumentDescriptionTemplateSelector.cs" />
<Compile Include="Infrastructure\Extensions\DocumentClientExceptionExtension.cs" />
<Compile Include="Infrastructure\Extensions\NameValueCollectionExtensions.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using CosmosDbExplorer.Messages;
using GalaSoft.MvvmLight.Threading;
using CosmosDbExplorer.ViewModel;
using CosmosDbExplorer.Infrastructure;
using System.Collections.Generic;

namespace CosmosDbExplorer.Infrastructure.Models
{
Expand All @@ -22,17 +24,17 @@ public interface ITreeViewItemViewModel
/// Base class for all ViewModel classes displayed by TreeViewItems.
/// This acts as an adapter between a raw data object and a TreeViewItem.
/// </summary>
public class TreeViewItemViewModel : ObservableObject
public abstract class TreeViewItemViewModel : ObservableObject
{
private static readonly TreeViewItemViewModel DummyChild = new TreeViewItemViewModel();
private static readonly TreeViewItemViewModel DummyChild = new TreeViewItemViewModelDummy();

private bool _isExpanded;

protected TreeViewItemViewModel(TreeViewItemViewModel parent, IMessenger messenger, bool lazyLoadChildren)
{
Parent = parent;
MessengerInstance = messenger;
Children = new ObservableCollection<TreeViewItemViewModel>();
Children = new SortedObservableCollection<TreeViewItemViewModel>(Comparer);

messenger.Register<RemoveNodeMessage>(this, OnRemoveNodeMessage);

Expand Down Expand Up @@ -61,7 +63,7 @@ private TreeViewItemViewModel()
/// <summary>
/// Returns the logical child items of this object.
/// </summary>
public ObservableCollection<TreeViewItemViewModel> Children { get; }
public SortedObservableCollection<TreeViewItemViewModel> Children { get; }

/// <summary>
/// Returns true if this object's Children have not yet been populated.
Expand Down Expand Up @@ -126,9 +128,28 @@ protected virtual Task LoadChildren()
public TreeViewItemViewModel Parent { get; }

public IMessenger MessengerInstance { get; }

private static readonly IComparer<TreeViewItemViewModel> Comparer = new TreeViewItemViewModelComparer();

public abstract string Name { get; }

private class TreeViewItemViewModelDummy
: TreeViewItemViewModel
{
public override string Name => string.Empty;
}
}

public class TreeViewItemViewModelComparer
: IComparer<TreeViewItemViewModel>
{
int IComparer<TreeViewItemViewModel>.Compare(TreeViewItemViewModel x, TreeViewItemViewModel y)
{
return string.Compare(x.Name, y.Name);
}
}

public class TreeViewItemViewModel<TParent> : TreeViewItemViewModel
public abstract class TreeViewItemViewModel<TParent> : TreeViewItemViewModel
where TParent : TreeViewItemViewModel
{
public TreeViewItemViewModel(TParent parent, IMessenger messenger, bool lazyLoadChildren)
Expand Down
41 changes: 41 additions & 0 deletions src/CosmosDbExplorer/Infrastructure/SortedObservableCollection.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;

namespace CosmosDbExplorer.Infrastructure
{
public class SortedObservableCollection<TValue>
: ObservableCollection<TValue>
{
private readonly IComparer<TValue> _comparer;

public SortedObservableCollection(IComparer<TValue> comparer)
{
_comparer = comparer ?? throw new System.ArgumentNullException(nameof(comparer));
}

public SortedObservableCollection(IEnumerable<TValue> collection, IComparer<TValue> comparer)
: base(collection)
{
_comparer = comparer ?? throw new System.ArgumentNullException(nameof(comparer));
}

public SortedObservableCollection(List<TValue> list, IComparer<TValue> comparer)
: base(list)
{
_comparer = comparer ?? throw new System.ArgumentNullException(nameof(comparer));
}

protected override void InsertItem(int index, TValue item)
{
index = this.TakeWhile(i => _comparer.Compare(item, i) > 0).Count();
base.InsertItem(index, item);
}

protected override void SetItem(int index, TValue item)
{
RemoveAt(index);
InsertItem(default, item);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using System.Threading.Tasks;
using System.Windows.Media;
using CosmosDbExplorer.Infrastructure;
using CosmosDbExplorer.Infrastructure.Models;
using CosmosDbExplorer.Messages;
using CosmosDbExplorer.Services;
using GalaSoft.MvvmLight.Ioc;
using GalaSoft.MvvmLight.Messaging;
using GalaSoft.MvvmLight.Threading;
using Microsoft.Azure.Documents;

namespace CosmosDbExplorer.ViewModel
Expand All @@ -25,8 +21,6 @@ protected AssetRootNodeViewModelBase(CollectionNodeViewModel parent)
MessengerInstance.Register<UpdateOrCreateNodeMessage<TResource>>(this, InnerOnUpdateOrCreateNodeMessage);
}

public string Name { get; protected set; }

public new CollectionNodeViewModel Parent
{
get { return base.Parent; }
Expand Down Expand Up @@ -72,7 +66,7 @@ protected AssetNodeViewModelBase(TParent parent, TResource resource)
Resource = resource;
}

public string Name => Resource.Id;
public override string Name => Resource.Id;

public string ContentId => Resource.AltLink;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ public class CollectionMetricsNodeViewModel : TreeViewItemViewModel<CollectionNo
public CollectionMetricsNodeViewModel(CollectionNodeViewModel parent)
: base(parent, parent.MessengerInstance, false)
{
Name = "Collection Metrics";
}

public string Name { get; set; }
public override string Name => "Collection Metrics";

public RelayCommand OpenCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public ConnectionNodeViewModel(IDocumentDbService dbService, IMessenger messenge

public List<Database> Databases { get; protected set; }

public string Name => Connection.DatabaseUri.ToString();
public override string Name => Connection.DatabaseUri.ToString();

protected override async Task LoadChildren()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ public class DocumentNodeViewModel : TreeViewItemViewModel<CollectionNodeViewMod
public DocumentNodeViewModel(CollectionNodeViewModel parent)
: base(parent, parent.MessengerInstance, false)
{
Name = "Documents";
}

public string Name { get; set; }
public override string Name => "Documents";

public RelayCommand OpenDocumentCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public PermissionNodeViewModel(Permission permission, UserNodeViewModel parent)

public Permission Permission { get; set; }

public string Name => Permission?.Id;
public override string Name => Permission?.Id;

public string ContentId => Permission?.AltLink ?? "NewPermission";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected ResourceNodeViewModelBase(Resource resource, TParent parent, bool lazy
Resource = resource;
}

public string Name => Resource.Id;
public override string Name => Resource.Id;

public RelayCommand RefreshCommand
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ public class ScaleSettingsNodeViewModel : TreeViewItemViewModel<CollectionNodeVi
public ScaleSettingsNodeViewModel(CollectionNodeViewModel parent)
: base(parent, parent.MessengerInstance, false)
{
Name = "Scale & Settings";
}

public string Name { get; private set; }
public override string Name => "Scale & Settings";

public string ContentId => Parent.Collection.SelfLink + "/ScaleSettings";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public class StoredProcedureRootNodeViewModel : AssetRootNodeViewModelBase<Store
public StoredProcedureRootNodeViewModel(CollectionNodeViewModel parent)
: base(parent)
{
Name = "Stored Procedures";
}

public override string Name => "Stored Procedures";

protected override async Task LoadChildren()
{
IsLoading = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ public class TriggerRootNodeViewModel : AssetRootNodeViewModelBase<Trigger>
public TriggerRootNodeViewModel(CollectionNodeViewModel parent)
: base(parent)
{
Name = "Triggers";
}

public override string Name => "Triggers";

protected override async Task LoadChildren()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ public class UserDefFuncRootNodeViewModel : AssetRootNodeViewModelBase<UserDefin
public UserDefFuncRootNodeViewModel(CollectionNodeViewModel parent)
: base(parent)
{
Name = "User Defined Functions";
}

public override string Name => "User Defined Functions";

protected override async Task LoadChildren()
{
IsLoading = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public UserNodeViewModel(User user, UsersNodeViewModel parent)
_dbService = SimpleIoc.Default.GetInstance<IDocumentDbService>();
}

public string Name => User.Id;
public override string Name => User.Id;

public string ContentId => User.AltLink ?? "NewUser";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ public class UsersNodeViewModel : TreeViewItemViewModel<DatabaseNodeViewModel>,
public UsersNodeViewModel(Database database, DatabaseNodeViewModel parent)
: base(parent, parent.MessengerInstance, true)
{
Name = "Users";
Database = database;
_parent = parent;
_dbService = SimpleIoc.Default.GetInstance<IDocumentDbService>();
}

public string Name { get; set; }
public override string Name => "Users";

public Database Database { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/CosmosDbExplorer/ViewModel/DatabaseViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task LoadNodesAsync()
connection.Connection = c.Value;

return connection;
});
}).OrderBy(c => c.Name);

Nodes = new ObservableCollection<ConnectionNodeViewModel>(nodes);
}
Expand Down
4 changes: 3 additions & 1 deletion src/CosmosDbExplorer/Views/QueryEditorView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
Document="{Binding Content, UpdateSourceTrigger=PropertyChanged}"
IsModified="{Binding IsDirty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}">
<avalonEdit:TextEditor.InputBindings>
<KeyBinding Key="F5" Command="{Binding ExecuteCommand}" />
<KeyBinding Key="F5" Command="{Binding ExecuteCommand}" />
<KeyBinding Key="Return" Modifiers="Ctrl" Command="{Binding ExecuteCommand}" />
<KeyBinding Key="Return" Modifiers="Shift" Command="{Binding ExecuteCommand}" />
<KeyBinding Key="K" Modifiers="Ctrl" Command="controls:AvalonCommands.CommentCommand" CommandParameter="{Binding ElementName=editor}" />
<KeyBinding Key="U" Modifiers="Ctrl" Command="controls:AvalonCommands.UnCommentCommand" CommandParameter="{Binding ElementName=editor}" />
</avalonEdit:TextEditor.InputBindings>
Expand Down