Skip to content

Commit

Permalink
Merge pull request #13 from delegateas/DisplayNameColumn
Browse files Browse the repository at this point in the history
Display name column
  • Loading branch information
Ahmad Sattar authored Jan 7, 2020
2 parents de28700 + fa0405e commit b40330f
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 30 deletions.
19 changes: 8 additions & 11 deletions DeprecationTool/CustomControls/CheckBoxListView.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Lib;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
Expand All @@ -16,10 +17,6 @@ public enum CheckState {
Indeterminate = 2
}

const string UNCHECKED = "unchecked";
const string CHECKED = "checked";
const string INDETERMINATE = "indeterminate";

ImageList CheckStates = new ImageList();

public CheckBoxListView()
Expand All @@ -34,9 +31,9 @@ public CheckBoxListView()
Bitmap checkedstate = new Bitmap(16, 16);
CheckBoxRenderer.DrawCheckBox(Graphics.FromImage(checkedstate), new Point(0, 3), System.Windows.Forms.VisualStyles.CheckBoxState.CheckedNormal);

CheckStates.Images.Add(UNCHECKED, uncheckedstate);
CheckStates.Images.Add(CHECKED, checkedstate);
CheckStates.Images.Add(INDETERMINATE, intermediatestate);
CheckStates.Images.Add(Deprecate.UNCHECKED, uncheckedstate);
CheckStates.Images.Add(Deprecate.CHECKED, checkedstate);
CheckStates.Images.Add(Deprecate.INDETERMINATE, intermediatestate);

SmallImageList = CheckStates;
}
Expand All @@ -49,9 +46,9 @@ protected override void OnDoubleClick(EventArgs e)
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
SelectedItems[0].ImageKey = SelectedItems[0].ImageKey == CHECKED
? UNCHECKED
: CHECKED;
SelectedItems[0].ImageKey = SelectedItems[0].ImageKey == Deprecate.CHECKED
? Deprecate.UNCHECKED
: Deprecate.CHECKED;
}
}

Expand Down
22 changes: 16 additions & 6 deletions DeprecationTool/DeprecateControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,16 @@ private void PopulateFieldListView(Deprecate.MetaData[] fields)

foreach (var field in fields)
{
var names = field.ColumnNames();
var itemToAdd = new ListViewItem
{
Text = field.ToString(),
Text = names.logicalName,
Tag = field,
ImageIndex = (int) field.deprecationState
ImageIndex = (int) field.deprecationState,
ImageKey = Deprecate.DeprecationStateToCheckBoxLiteral(field.deprecationState)
};
// First column is given by Text field, subsequent ones are given by subitems
itemToAdd.SubItems.AddRange(new[] { names.displayName });

entityFieldList.Items.Add(itemToAdd);
}
Expand Down Expand Up @@ -368,7 +372,7 @@ private void tsInfo_Click(object sender, EventArgs e)
private void fieldListColumnClick(object sender, ColumnClickEventArgs e)
{
ListView myListView = (ListView)sender;
entityListViewComparer.toggleOrder();
entityListViewComparer.toggleOrder(e.Column);
myListView.Sort();
}

Expand Down Expand Up @@ -397,16 +401,22 @@ private void fieldListOnkeyboardPress(object sender, KeyEventArgs e)
class ListViewItemComparer : IComparer
{
// Start with false so we sync up with the beginning of the winform column state
public bool ascending { get; set; } = true;
public bool[] ascending { get; set; } = {true, true};
public int col { get; set; } = 0;

public ListViewItemComparer() { }

public void toggleOrder() => ascending = !ascending;
public void toggleOrder(int givenCol) {
if(ascending.Length > givenCol)
{
col = givenCol;
ascending[col] = !ascending[col];
}
}

public int Compare(object x, object y)
{
return ascending
return ascending[col]
? string.Compare(((ListViewItem)x).SubItems[col].Text, ((ListViewItem)y).SubItems[col].Text)
: string.Compare(((ListViewItem)y).SubItems[col].Text, ((ListViewItem)x).SubItems[col].Text);
}
Expand Down
18 changes: 12 additions & 6 deletions DeprecationTool/DeprecateControl.designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 23 additions & 3 deletions Lib/Deprecate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@ open Microsoft.Xrm.Sdk.Metadata

module Deprecate =
open System.Globalization

[<Literal>]
let UNCHECKED = "unchecked";
[<Literal>]
let CHECKED = "checked";
[<Literal>]
let INDETERMINATE = "indeterminate";

type DeprecationState = Favored = 0 // same as not deprecated
| Deprecated = 1
| Partial = 2 // Partial deprecation means only the name has been prefixed as deprecated.

let DeprecationStateToCheckBoxLiteral = function
| DeprecationState.Favored -> UNCHECKED
| DeprecationState.Deprecated -> CHECKED
| DeprecationState.Partial -> INDETERMINATE

type LogicalName = string

let labelToString (label: Label) =
label.UserLocalizedLabel.Label.ToString()

type FieldNames = {
logicalName: string
displayName: string
}

type MetaData = {
entityLName: LogicalName;
locale: int;
Expand All @@ -27,6 +47,9 @@ module Deprecate =
} with
override this.ToString() =
this.attribute.SchemaName
member this.ColumnNames() =
{ logicalName = this.attribute.SchemaName
displayName = labelToString this.attribute.DisplayName }

type SolutionData = {
id: Guid
Expand Down Expand Up @@ -58,9 +81,6 @@ module Deprecate =
| Favor of Data : MetaData


let labelToString (label: Label) =
label.UserLocalizedLabel.Label.ToString()

let deprecationStampPattern =
@"\n(\(Deprecated:)\s(?<date>\d{2,}\/\d{2,}\/\d{4,}\s\d{2,}.\d{2,}.\d{2,})(,\ssearch:\s(?<searchable>1|0))?(\))"

Expand Down
26 changes: 23 additions & 3 deletions Lib/deprecate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@ open Microsoft.Xrm.Sdk.Metadata

module Deprecate =
open System.Globalization

[<Literal>]
let UNCHECKED = "unchecked";
[<Literal>]
let CHECKED = "checked";
[<Literal>]
let INDETERMINATE = "indeterminate";

type DeprecationState = Favored = 0 // same as not deprecated
| Deprecated = 1
| Partial = 2 // Partial deprecation means only the name has been prefixed as deprecated.

let DeprecationStateToCheckBoxLiteral = function
| DeprecationState.Favored -> UNCHECKED
| DeprecationState.Deprecated -> CHECKED
| DeprecationState.Partial -> INDETERMINATE

type LogicalName = string

let labelToString (label: Label) =
label.UserLocalizedLabel.Label.ToString()

type FieldNames = {
logicalName: string
displayName: string
}

type MetaData = {
entityLName: LogicalName;
locale: int;
Expand All @@ -27,6 +47,9 @@ module Deprecate =
} with
override this.ToString() =
this.attribute.SchemaName
member this.ColumnNames() =
{ logicalName = this.attribute.SchemaName
displayName = labelToString this.attribute.DisplayName }

type SolutionData = {
id: Guid
Expand Down Expand Up @@ -58,9 +81,6 @@ module Deprecate =
| Favor of Data : MetaData


let labelToString (label: Label) =
label.UserLocalizedLabel.Label.ToString()

let deprecationStampPattern =
@"\n(\(Deprecated:)\s(?<date>\d{2,}\/\d{2,}\/\d{4,}\s\d{2,}.\d{2,}.\d{2,})(,\ssearch:\s(?<searchable>1|0))?(\))"

Expand Down
3 changes: 2 additions & 1 deletion Package.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
<releaseNotes>
Unreleased - 07/01/2020
* Fields are in a sortable listview
* Fixed issues with solution dropdown after reload all
* Fixed issues with solution dropdown after reload all
* Added "Display Name" to field list, and fixed bug with toggling states
1.0.7 - 07/11/2019
* User guide explaining the tool
* No pop ups when starting, just sane defaults
Expand Down

0 comments on commit b40330f

Please sign in to comment.