Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Menu Options for limiting text length and line length.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpaquay committed Mar 15, 2016
1 parent 017eb5c commit f343a87
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 55 deletions.
60 changes: 43 additions & 17 deletions src/AccessBridgeExplorer/ExplorerForm.Designer.cs

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

12 changes: 10 additions & 2 deletions src/AccessBridgeExplorer/ExplorerForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,16 @@ ToolStripMenuItem IExplorerFormView.EventsMenu {
get { return _eventsMenu; }
}

ToolStripMenuItem IExplorerFormView.EnumerationSizesMenu {
get { return _enumerationSizeMenu; }
ToolStripMenuItem IExplorerFormView.LimitCollectionSizesMenu {
get { return _limitCollectionsCountMenu; }
}

ToolStripMenuItem IExplorerFormView.LimitTextLineCountMenu {
get { return _limitTextLineCountsMenu; }
}

ToolStripMenuItem IExplorerFormView.LimitTextLineLengthsMenu {
get { return _limitTextLineLengthsMenu; }
}

ToolStripStatusLabel IExplorerFormView.StatusLabel {
Expand Down
2 changes: 1 addition & 1 deletion src/AccessBridgeExplorer/ExplorerForm.resx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADM
BwAAAk1TRnQBSQFMAgEBAgEAAfgBBAH4AQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
BwAAAk1TRnQBSQFMAgEBAgEAAWgBBQFoAQUBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
64 changes: 49 additions & 15 deletions src/AccessBridgeExplorer/ExplorerFormController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public ExplorerFormController(IExplorerFormView explorerFormView) {

_view.EventsMenu.Enabled = false;
_view.PropertiesMenu.Enabled = false;
_view.EnumerationSizesMenu.Enabled = false;
_view.LimitCollectionSizesMenu.Enabled = false;

_view.AccessibilityTree.AfterSelect += AccessibilityTreeAfterSelect;
_view.AccessibilityTree.BeforeExpand += AccessibilityTreeBeforeExpand;
Expand Down Expand Up @@ -92,10 +92,12 @@ public void Initialize() {
_accessBridge.Initilized += (sender, args) => {
CreateEventMenuItems();
CreatePropertyOptionsMenuItems();
CreateEnumerationSizesMenuItems();
CreateLimitCollectionSizesMenuItems();
CreateLimitTextLineCountMenuItems();
CreateLimitTextLineLengthsMenuItems();
_view.EventsMenu.Enabled = true;
_view.PropertiesMenu.Enabled = true;
_view.EnumerationSizesMenu.Enabled = true;
_view.LimitCollectionSizesMenu.Enabled = true;
LogMessage("Ready!");
};

Expand Down Expand Up @@ -242,35 +244,67 @@ private void CreatePropertyOptionsMenuItem(FieldInfo field, int index) {
};
}

private void CreateEnumerationSizesMenuItems() {
private void CreateLimitCollectionSizesMenuItems() {
int index = 0;
foreach (var size in new int[] {10, 20, 50, 100, 250, 500, 1000, 2000}) {
CreateEnumerationSizesMenuItem(size, index);
foreach (var size in new int[] { 10, 20, 50, 100, 250, 500, 1000, 2000 }) {
char mnemonicCharacter = (char)('A' + index);
var text = string.Format("&{0} - {1} elements", mnemonicCharacter, size);
CreateLimitSizeItem(_view.LimitCollectionSizesMenu, text, index, size,
_accessBridge.CollectionSizeLimit,
x => {
_accessBridge.CollectionSizeLimit = x;
});
index++;
}
}

private void CreateEnumerationSizesMenuItem(int size, int index) {
// Create menu item (fixed font for alignment)
private void CreateLimitTextLineCountMenuItems() {
int index = 0;
foreach (var size in new int[] {100, 200, 300, 500, 1000, 2000, 5000}) {
char mnemonicCharacter = (char)('A' + index);
var text = string.Format("&{0} - {1} lines", mnemonicCharacter, size);
CreateLimitSizeItem(_view.LimitTextLineCountMenu, text, index, size,
_accessBridge.TextLineCountLimit,
x => {
_accessBridge.TextLineCountLimit = x;
});
index++;
}
}

private void CreateLimitTextLineLengthsMenuItems() {
int index = 0;
foreach (var size in new int[] { 40, 80, 120, 160, 200, 300, 400, 500, 1000 }) {
char mnemonicCharacter = (char)('A' + index);
var text = string.Format("&{0} - {1} characters", mnemonicCharacter, size);
CreateLimitSizeItem(_view.LimitTextLineLengthsMenu, text, index, size,
_accessBridge.TextLineLengthLimit,
x => {
_accessBridge.TextLineLengthLimit = x;
});
index++;
}
}

private static void CreateLimitSizeItem(ToolStripMenuItem menu, string text, int index, int size, int defaultSize, Action<int> setter) {
var item = new ToolStripMenuItem();
char mnemonicCharacter = (char)(index < 10 ? '0' + index : 'A' + index - 10);
item.Text = string.Format("&{0} - {1}", mnemonicCharacter, size);
item.Text = text;
item.CheckOnClick = false;
item.CheckState = size == 100 ? CheckState.Checked : CheckState.Unchecked;
_view.EnumerationSizesMenu.DropDownItems.Add(item);
item.CheckState = size == defaultSize ? CheckState.Checked : CheckState.Unchecked;
menu.DropDownItems.Add(item);

// Create click handler
item.Click += (sender, args) => {
if (item.Checked)
return;

for(var i = 0; i < _view.EnumerationSizesMenu.DropDownItems.Count; i++) {
var subItem = (ToolStripMenuItem)_view.EnumerationSizesMenu.DropDownItems[i];
for (var i = 0; i < menu.DropDownItems.Count; i++) {
var subItem = (ToolStripMenuItem)menu.DropDownItems[i];
if (subItem.Checked)
subItem.Checked = false;
}
item.Checked = true;
_accessBridge.CollectionSizeLimit = size;
setter(size);
};
}

Expand Down
4 changes: 3 additions & 1 deletion src/AccessBridgeExplorer/IExplorerFormView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public interface IExplorerFormView {

ToolStripMenuItem PropertiesMenu { get; }
ToolStripMenuItem EventsMenu { get; }
ToolStripMenuItem EnumerationSizesMenu { get; }
ToolStripMenuItem LimitCollectionSizesMenu { get; }
ToolStripMenuItem LimitTextLineCountMenu { get; }
ToolStripMenuItem LimitTextLineLengthsMenu { get; }

ToolStripStatusLabel StatusLabel { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/WindowsAccessBridgeInterop/AccessBridge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class AccessBridge : IDisposable {
public AccessBridge() {
CollectionSizeLimit = 100;
TextLineCountLimit = 200;
TextLineLengthLimit = 1024;
TextLineLengthLimit = 200;
}

public AccessBridgeFunctions Functions {
Expand Down
25 changes: 14 additions & 11 deletions src/WindowsAccessBridgeInterop/AccessibleContextNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,17 +675,16 @@ private void AddTextProperties(PropertyList list, PropertyOptions options) {
if ((options & PropertyOptions.AccessibleText) != 0) {
var info = GetInfo();
if (info.accessibleText != 0) {
int x = 0;
int y = 0;

var group = list.AddGroup("Accessible Text");
group.Expanded = false;
group.LoadChildren = () => {
var point = new Point(0, 0);

AccessibleTextInfo textInfo;
if (Succeeded(AccessBridge.Functions.GetAccessibleTextInfo(JvmId, _ac, out textInfo, x, y))) {
if (Succeeded(AccessBridge.Functions.GetAccessibleTextInfo(JvmId, _ac, out textInfo, point.X, point.Y))) {
group.AddProperty("Character count", textInfo.charCount);
group.AddProperty("Character index of caret", textInfo.caretIndex);
group.AddProperty(string.Format("Character index of point ({0}, {1})", x, y), textInfo.indexAtPoint);
group.AddProperty(string.Format("Character index of point ({0}, {1})", point.X, point.Y), textInfo.indexAtPoint);

AccessibleTextSelectionInfo textSelection;
if (Succeeded(AccessBridge.Functions.GetAccessibleTextSelectionInfo(JvmId, _ac, out textSelection))) {
Expand All @@ -700,7 +699,7 @@ private void AddTextProperties(PropertyList list, PropertyOptions options) {
AddTextAttributeAtIndex(caretGroup.Children, textInfo.caretIndex);
};

var pointGroup = group.AddGroup(string.Format("Text attributes at point ({0}, {1})", x, y));
var pointGroup = group.AddGroup(string.Format("Text attributes at point ({0}, {1})", point.X, point.Y));
pointGroup.Expanded = false;
pointGroup.LoadChildren = () => {
AddTextAttributeAtIndex(pointGroup.Children, textInfo.indexAtPoint);
Expand All @@ -710,11 +709,15 @@ private void AddTextProperties(PropertyList list, PropertyOptions options) {
textGroup.Expanded = false;
textGroup.LoadChildren = () => {
var reader = new AccessibleTextReader(this, textInfo.charCount);
foreach (var lineData in reader.ReadFullLines(AccessBridge.TextLineLengthLimit).Take(AccessBridge.TextLineCountLimit)) {
var lines = reader
.ReadFullLines(AccessBridge.TextLineLengthLimit)
.Where(x => !x.Continuation)
.Take(AccessBridge.TextLineCountLimit);
foreach (var lineData in lines) {
var lineEndOffset = lineData.Offset + lineData.Text.Length - 1;
textGroup.AddProperty(
string.Format("Line {0} [{1}, {2}]", lineData.Number + 1, lineData.Offset, lineEndOffset),
MakePrintable(lineData.Text));
var name = string.Format("Line {0} [{1}, {2}]", lineData.Number + 1, lineData.Offset, lineEndOffset);
var value = MakePrintable(lineData.Text) + (lineData.Incomplete ? "..." : "");
textGroup.AddProperty(name, value);
}
};
}
Expand Down Expand Up @@ -877,7 +880,7 @@ private static string LimitStringSize(string value, int maxLength) {
if (value.Length < maxLength)
return value;

return value.Substring(0, maxLength).Trim() + "(...)";
return value.Substring(0, maxLength).Trim() + "...";
}

public override bool Equals(AccessibleNode other) {
Expand Down
2 changes: 1 addition & 1 deletion src/WindowsAccessBridgeInterop/AccessibleWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public override AccessibleNode GetParent() {
}

protected override void AddToolTipProperties(PropertyList list, PropertyOptions options) {
list.AddProperty("WindowHandle", _hWnd);
base.AddToolTipProperties(list, options);
list.AddProperty("WindowHandle", _hWnd);
}

protected override void AddProperties(PropertyList list, PropertyOptions options) {
Expand Down
Loading

0 comments on commit f343a87

Please sign in to comment.