mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-19 09:35:36 -05:00
Add modifiable sort priority to OE nodes (#1627)
* modifiable sort priority, dropped ledger folders sorted to the bottom * reorganizing dropped table and view objects in OE integration test * update to Int32
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
|
||||
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
@@ -11,8 +11,8 @@ using System.Linq;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
{
|
||||
/// <summary>
|
||||
/// A collection class for <see cref="TreeNode"/>
|
||||
/// <summary>
|
||||
/// A collection class for <see cref="TreeNode"/>
|
||||
/// </summary>
|
||||
public sealed class NodeObservableCollection : ObservableCollection<TreeNode>
|
||||
{
|
||||
@@ -30,13 +30,17 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
get { return numInits.HasValue && numInits != 0; }
|
||||
}
|
||||
|
||||
public bool IsSorted
|
||||
{
|
||||
get
|
||||
{
|
||||
// SMO objects are already sorted so no need to sort them again
|
||||
return this.FirstOrDefault() is SmoTreeNode;
|
||||
}
|
||||
public bool IsSorted
|
||||
{
|
||||
get
|
||||
{
|
||||
// SMO objects are already sorted so no need to sort them again, unless they have dropped folders
|
||||
bool anyDroppedFolders = this.Any(
|
||||
node => node is FolderNode &&
|
||||
(node.NodeTypeId == NodeTypes.DroppedLedgerTables ||
|
||||
node.NodeTypeId == NodeTypes.DroppedLedgerViews));
|
||||
return this.FirstOrDefault() is SmoTreeNode && !anyDroppedFolders;
|
||||
}
|
||||
}
|
||||
|
||||
public void BeginInit()
|
||||
@@ -64,9 +68,9 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!IsSorted)
|
||||
{
|
||||
DoSort();
|
||||
if (!IsSorted)
|
||||
{
|
||||
DoSort();
|
||||
}
|
||||
|
||||
if (deferredChildren != null)
|
||||
|
||||
@@ -413,23 +413,16 @@ namespace Microsoft.SqlTools.ServiceLayer.ObjectExplorer.Nodes
|
||||
return CompareSamePriorities(this, other);
|
||||
}
|
||||
|
||||
if (this.SortPriority.HasValue &&
|
||||
!other.SortPriority.HasValue)
|
||||
{
|
||||
return -1; // this is above other
|
||||
}
|
||||
if (!this.SortPriority.HasValue)
|
||||
{
|
||||
return 1; // this is below other
|
||||
}
|
||||
// Higher SortPriority = lower in the list. A couple nodes are defined with SortPriority of Int16.MaxValue
|
||||
// so they're placed at the bottom of the node list (Dropped Ledger Tables and Dropped Ledger Views folders)
|
||||
// Individual objects, like tables and views, don't have a SortPriority defined, so their values need
|
||||
// to be resolved. If a node doesn't have a SortPriority, set it to the second-highest value.
|
||||
int thisPriority = this.SortPriority ?? Int32.MaxValue - 1;
|
||||
int otherPriority = other.SortPriority ?? Int32.MaxValue - 1;
|
||||
|
||||
// Both have sort priority
|
||||
int priDiff = this.SortPriority.Value - other.SortPriority.Value;
|
||||
if (priDiff < 0)
|
||||
return -1; // this is below other
|
||||
if (priDiff == 0)
|
||||
return 0;
|
||||
return 1;
|
||||
// diff > 0 == this below other
|
||||
// diff < 0 == other below this
|
||||
return thisPriority - otherPriority;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user