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

Commit f343a87

Browse files
committed
Menu Options for limiting text length and line length.
1 parent 017eb5c commit f343a87

9 files changed

Lines changed: 152 additions & 55 deletions

File tree

src/AccessBridgeExplorer/ExplorerForm.Designer.cs

Lines changed: 43 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AccessBridgeExplorer/ExplorerForm.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -374,8 +374,16 @@ ToolStripMenuItem IExplorerFormView.EventsMenu {
374374
get { return _eventsMenu; }
375375
}
376376

377-
ToolStripMenuItem IExplorerFormView.EnumerationSizesMenu {
378-
get { return _enumerationSizeMenu; }
377+
ToolStripMenuItem IExplorerFormView.LimitCollectionSizesMenu {
378+
get { return _limitCollectionsCountMenu; }
379+
}
380+
381+
ToolStripMenuItem IExplorerFormView.LimitTextLineCountMenu {
382+
get { return _limitTextLineCountsMenu; }
383+
}
384+
385+
ToolStripMenuItem IExplorerFormView.LimitTextLineLengthsMenu {
386+
get { return _limitTextLineLengthsMenu; }
379387
}
380388

381389
ToolStripStatusLabel IExplorerFormView.StatusLabel {

src/AccessBridgeExplorer/ExplorerForm.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@
198198
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
199199
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
200200
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAADM
201-
BwAAAk1TRnQBSQFMAgEBAgEAAfgBBAH4AQQBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
201+
BwAAAk1TRnQBSQFMAgEBAgEAAWgBBQFoAQUBEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
202202
AwABQAMAARADAAEBAQABCAYAAQQYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
203203
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
204204
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA

src/AccessBridgeExplorer/ExplorerFormController.cs

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public ExplorerFormController(IExplorerFormView explorerFormView) {
4444

4545
_view.EventsMenu.Enabled = false;
4646
_view.PropertiesMenu.Enabled = false;
47-
_view.EnumerationSizesMenu.Enabled = false;
47+
_view.LimitCollectionSizesMenu.Enabled = false;
4848

4949
_view.AccessibilityTree.AfterSelect += AccessibilityTreeAfterSelect;
5050
_view.AccessibilityTree.BeforeExpand += AccessibilityTreeBeforeExpand;
@@ -92,10 +92,12 @@ public void Initialize() {
9292
_accessBridge.Initilized += (sender, args) => {
9393
CreateEventMenuItems();
9494
CreatePropertyOptionsMenuItems();
95-
CreateEnumerationSizesMenuItems();
95+
CreateLimitCollectionSizesMenuItems();
96+
CreateLimitTextLineCountMenuItems();
97+
CreateLimitTextLineLengthsMenuItems();
9698
_view.EventsMenu.Enabled = true;
9799
_view.PropertiesMenu.Enabled = true;
98-
_view.EnumerationSizesMenu.Enabled = true;
100+
_view.LimitCollectionSizesMenu.Enabled = true;
99101
LogMessage("Ready!");
100102
};
101103

@@ -242,35 +244,67 @@ private void CreatePropertyOptionsMenuItem(FieldInfo field, int index) {
242244
};
243245
}
244246

245-
private void CreateEnumerationSizesMenuItems() {
247+
private void CreateLimitCollectionSizesMenuItems() {
246248
int index = 0;
247-
foreach (var size in new int[] {10, 20, 50, 100, 250, 500, 1000, 2000}) {
248-
CreateEnumerationSizesMenuItem(size, index);
249+
foreach (var size in new int[] { 10, 20, 50, 100, 250, 500, 1000, 2000 }) {
250+
char mnemonicCharacter = (char)('A' + index);
251+
var text = string.Format("&{0} - {1} elements", mnemonicCharacter, size);
252+
CreateLimitSizeItem(_view.LimitCollectionSizesMenu, text, index, size,
253+
_accessBridge.CollectionSizeLimit,
254+
x => {
255+
_accessBridge.CollectionSizeLimit = x;
256+
});
249257
index++;
250258
}
251259
}
252260

253-
private void CreateEnumerationSizesMenuItem(int size, int index) {
254-
// Create menu item (fixed font for alignment)
261+
private void CreateLimitTextLineCountMenuItems() {
262+
int index = 0;
263+
foreach (var size in new int[] {100, 200, 300, 500, 1000, 2000, 5000}) {
264+
char mnemonicCharacter = (char)('A' + index);
265+
var text = string.Format("&{0} - {1} lines", mnemonicCharacter, size);
266+
CreateLimitSizeItem(_view.LimitTextLineCountMenu, text, index, size,
267+
_accessBridge.TextLineCountLimit,
268+
x => {
269+
_accessBridge.TextLineCountLimit = x;
270+
});
271+
index++;
272+
}
273+
}
274+
275+
private void CreateLimitTextLineLengthsMenuItems() {
276+
int index = 0;
277+
foreach (var size in new int[] { 40, 80, 120, 160, 200, 300, 400, 500, 1000 }) {
278+
char mnemonicCharacter = (char)('A' + index);
279+
var text = string.Format("&{0} - {1} characters", mnemonicCharacter, size);
280+
CreateLimitSizeItem(_view.LimitTextLineLengthsMenu, text, index, size,
281+
_accessBridge.TextLineLengthLimit,
282+
x => {
283+
_accessBridge.TextLineLengthLimit = x;
284+
});
285+
index++;
286+
}
287+
}
288+
289+
private static void CreateLimitSizeItem(ToolStripMenuItem menu, string text, int index, int size, int defaultSize, Action<int> setter) {
255290
var item = new ToolStripMenuItem();
256-
char mnemonicCharacter = (char)(index < 10 ? '0' + index : 'A' + index - 10);
257-
item.Text = string.Format("&{0} - {1}", mnemonicCharacter, size);
291+
item.Text = text;
258292
item.CheckOnClick = false;
259-
item.CheckState = size == 100 ? CheckState.Checked : CheckState.Unchecked;
260-
_view.EnumerationSizesMenu.DropDownItems.Add(item);
293+
item.CheckState = size == defaultSize ? CheckState.Checked : CheckState.Unchecked;
294+
menu.DropDownItems.Add(item);
261295

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

267-
for(var i = 0; i < _view.EnumerationSizesMenu.DropDownItems.Count; i++) {
268-
var subItem = (ToolStripMenuItem)_view.EnumerationSizesMenu.DropDownItems[i];
301+
for (var i = 0; i < menu.DropDownItems.Count; i++) {
302+
var subItem = (ToolStripMenuItem)menu.DropDownItems[i];
269303
if (subItem.Checked)
270304
subItem.Checked = false;
271305
}
272306
item.Checked = true;
273-
_accessBridge.CollectionSizeLimit = size;
307+
setter(size);
274308
};
275309
}
276310

src/AccessBridgeExplorer/IExplorerFormView.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public interface IExplorerFormView {
3535

3636
ToolStripMenuItem PropertiesMenu { get; }
3737
ToolStripMenuItem EventsMenu { get; }
38-
ToolStripMenuItem EnumerationSizesMenu { get; }
38+
ToolStripMenuItem LimitCollectionSizesMenu { get; }
39+
ToolStripMenuItem LimitTextLineCountMenu { get; }
40+
ToolStripMenuItem LimitTextLineLengthsMenu { get; }
3941

4042
ToolStripStatusLabel StatusLabel { get; }
4143

src/WindowsAccessBridgeInterop/AccessBridge.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class AccessBridge : IDisposable {
3535
public AccessBridge() {
3636
CollectionSizeLimit = 100;
3737
TextLineCountLimit = 200;
38-
TextLineLengthLimit = 1024;
38+
TextLineLengthLimit = 200;
3939
}
4040

4141
public AccessBridgeFunctions Functions {

src/WindowsAccessBridgeInterop/AccessibleContextNode.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -675,17 +675,16 @@ private void AddTextProperties(PropertyList list, PropertyOptions options) {
675675
if ((options & PropertyOptions.AccessibleText) != 0) {
676676
var info = GetInfo();
677677
if (info.accessibleText != 0) {
678-
int x = 0;
679-
int y = 0;
680-
681678
var group = list.AddGroup("Accessible Text");
682679
group.Expanded = false;
683680
group.LoadChildren = () => {
681+
var point = new Point(0, 0);
682+
684683
AccessibleTextInfo textInfo;
685-
if (Succeeded(AccessBridge.Functions.GetAccessibleTextInfo(JvmId, _ac, out textInfo, x, y))) {
684+
if (Succeeded(AccessBridge.Functions.GetAccessibleTextInfo(JvmId, _ac, out textInfo, point.X, point.Y))) {
686685
group.AddProperty("Character count", textInfo.charCount);
687686
group.AddProperty("Character index of caret", textInfo.caretIndex);
688-
group.AddProperty(string.Format("Character index of point ({0}, {1})", x, y), textInfo.indexAtPoint);
687+
group.AddProperty(string.Format("Character index of point ({0}, {1})", point.X, point.Y), textInfo.indexAtPoint);
689688

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

703-
var pointGroup = group.AddGroup(string.Format("Text attributes at point ({0}, {1})", x, y));
702+
var pointGroup = group.AddGroup(string.Format("Text attributes at point ({0}, {1})", point.X, point.Y));
704703
pointGroup.Expanded = false;
705704
pointGroup.LoadChildren = () => {
706705
AddTextAttributeAtIndex(pointGroup.Children, textInfo.indexAtPoint);
@@ -710,11 +709,15 @@ private void AddTextProperties(PropertyList list, PropertyOptions options) {
710709
textGroup.Expanded = false;
711710
textGroup.LoadChildren = () => {
712711
var reader = new AccessibleTextReader(this, textInfo.charCount);
713-
foreach (var lineData in reader.ReadFullLines(AccessBridge.TextLineLengthLimit).Take(AccessBridge.TextLineCountLimit)) {
712+
var lines = reader
713+
.ReadFullLines(AccessBridge.TextLineLengthLimit)
714+
.Where(x => !x.Continuation)
715+
.Take(AccessBridge.TextLineCountLimit);
716+
foreach (var lineData in lines) {
714717
var lineEndOffset = lineData.Offset + lineData.Text.Length - 1;
715-
textGroup.AddProperty(
716-
string.Format("Line {0} [{1}, {2}]", lineData.Number + 1, lineData.Offset, lineEndOffset),
717-
MakePrintable(lineData.Text));
718+
var name = string.Format("Line {0} [{1}, {2}]", lineData.Number + 1, lineData.Offset, lineEndOffset);
719+
var value = MakePrintable(lineData.Text) + (lineData.Incomplete ? "..." : "");
720+
textGroup.AddProperty(name, value);
718721
}
719722
};
720723
}
@@ -877,7 +880,7 @@ private static string LimitStringSize(string value, int maxLength) {
877880
if (value.Length < maxLength)
878881
return value;
879882

880-
return value.Substring(0, maxLength).Trim() + "(...)";
883+
return value.Substring(0, maxLength).Trim() + "...";
881884
}
882885

883886
public override bool Equals(AccessibleNode other) {

src/WindowsAccessBridgeInterop/AccessibleWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public override AccessibleNode GetParent() {
3434
}
3535

3636
protected override void AddToolTipProperties(PropertyList list, PropertyOptions options) {
37-
list.AddProperty("WindowHandle", _hWnd);
3837
base.AddToolTipProperties(list, options);
38+
list.AddProperty("WindowHandle", _hWnd);
3939
}
4040

4141
protected override void AddProperties(PropertyList list, PropertyOptions options) {

0 commit comments

Comments
 (0)