Skip to content

Commit

Permalink
Review code QL
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Cerqueira committed Oct 19, 2023
1 parent 696fc76 commit 499e5a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 48 deletions.
65 changes: 22 additions & 43 deletions Src/Controls/TreeDiagram/BrowserMultiSelectControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
var oldcur = ConsolePlus.CursorVisible;
ConsolePlus.SetCursorPosition(0, ConsolePlus.CursorTop);
var (CursorLeft, CursorTop) = (ConsolePlus.CursorLeft, ConsolePlus.CursorTop);
var scrool = 0;

_firstLoad = false;
ConsolePlus.CursorVisible = false;
Expand All @@ -402,7 +401,7 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
(CursorLeft, CursorTop) = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}
}
if (!_options.OptMinimalRender)
Expand All @@ -412,15 +411,15 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
(CursorLeft, CursorTop) = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}
}

_cusorSpinner = (ConsolePlus.CursorLeft, ConsolePlus.CursorTop);

if (_options.Spinner != null)
{
qtd = ConsolePlus.WriteLine();
ConsolePlus.WriteLine();
}

if (!string.IsNullOrEmpty(_options.OptDescription) && !_options.OptMinimalRender)
Expand All @@ -430,15 +429,13 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
_cusorSpinner = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}
top = ConsolePlus.CursorTop;
qtd = ConsolePlus.Write(_options.OptDescription, _options.OptStyleSchema.Description());
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
_cusorSpinner = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}

Expand Down Expand Up @@ -879,12 +876,9 @@ public override void FinalizeControl(CancellationToken cancellationToken)
private void RemoveSelectAll(TreeNode<ItemBrowser> node)
{
var index = _selectedItems.FindIndex(x => x.UniqueId == node.UniqueId);
if (index >= 0)
if (index >= 0 && !IsFixedSelect(node))
{
if (!IsFixedSelect(node))
{
_selectedItems.RemoveAt(index);
}
_selectedItems.RemoveAt(index);
}
if (node.Childrens != null)
{
Expand All @@ -902,12 +896,9 @@ private void AddSelectAll(TreeNode<ItemBrowser> node)
return;
}
var index = _selectedItems.FindIndex(x => x.UniqueId == node.UniqueId);
if (index < 0)
if (index < 0 && node.IsSelected)
{
if (node.IsSelected)
{
_selectedItems.Add(new(node.UniqueId, node.Value));
}
_selectedItems.Add(new(node.UniqueId, node.Value));
}
if (node.Childrens != null)
{
Expand Down Expand Up @@ -1114,19 +1105,16 @@ private void WriteSpinner((int CursorLeft, int CursorTop) cursor, CancellationTo
while (KeyAvailable)
{
var keypress = WaitKeypress(_lnkcts.Token);
if (_options.OptEnabledAbortKey)
if (_options.OptEnabledAbortKey && keypress != null)
{
if (keypress != null)
if (CheckAbortKey(keypress.Value))
{
if (CheckAbortKey(keypress.Value))
while (KeyAvailable)
{
while (KeyAvailable)
{
_ = WaitKeypress(_lnkcts.Token);
}
_ctsesc.Cancel();
break;
_ = WaitKeypress(_lnkcts.Token);
}
_ctsesc.Cancel();
break;
}
}
}
Expand Down Expand Up @@ -1173,13 +1161,10 @@ private TreeNode<ItemBrowser> TryLoadFolder(bool refresh, TreeNode<ItemBrowser>
{
node.IsSelected = _options.ExpressionSelected?.Invoke(node.Value) ?? false;
}
if (!node.IsSelected)
if (!node.IsSelected && IsFixedSelect(node))
{
if (IsFixedSelect(node))
{
node.IsSelected = true;
node.IsDisabled = true;
}
node.IsSelected = true;
node.IsDisabled = true;
}
}
var loadfiles = false;
Expand Down Expand Up @@ -1246,28 +1231,22 @@ private TreeNode<ItemBrowser> TryLoadFolder(bool refresh, TreeNode<ItemBrowser>
{
newnode.IsSelected = _options.ExpressionSelected?.Invoke(newnode.Value) ?? false;
}
if (!newnode.IsSelected)
if (!newnode.IsSelected && IsFixedSelect(newnode))
{
if (IsFixedSelect(newnode))
{
newnode.IsSelected = true;
newnode.IsDisabled = true;
}
newnode.IsSelected = true;
newnode.IsDisabled = true;
}
}
}
if (index >= 0)
{
node.Childrens.Last().NextNode = lastnextnode;
}
if (allnodes)
if (allnodes && node.IsHasChild)
{
if (node.IsHasChild)
foreach (var item in node.Childrens.Where(x => x.Value.IsFolder))
{
foreach (var item in node.Childrens.Where(x => x.Value.IsFolder))
{
TryLoadFolder(false, item, null, allnodes, cancellationToken);
}
TryLoadFolder(false, item, null, allnodes, cancellationToken);
}
}
node.UpdateTreeLength<ItemBrowser>();
Expand Down
8 changes: 3 additions & 5 deletions Src/Controls/TreeDiagram/BrowserSelectControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
var oldcur = ConsolePlus.CursorVisible;
ConsolePlus.SetCursorPosition(0, ConsolePlus.CursorTop);
var (CursorLeft, CursorTop) = (ConsolePlus.CursorLeft, ConsolePlus.CursorTop);
var scrool = 0;

_firstLoad = false;
ConsolePlus.CursorVisible = false;
Expand All @@ -362,7 +361,8 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
(CursorLeft, CursorTop) = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);

}
}
if (!_options.OptMinimalRender)
Expand All @@ -372,7 +372,7 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
(CursorLeft, CursorTop) = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}
}

Expand All @@ -390,15 +390,13 @@ public override void InputTemplate(ScreenBuffer screenBuffer)
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
_cusorSpinner = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}
top = ConsolePlus.CursorTop;
qtd = ConsolePlus.Write(_options.OptDescription, _options.OptStyleSchema.Description());
if (ConsolePlus.IsTerminal && top + qtd >= ConsolePlus.BufferHeight)
{
var dif = top + qtd - ConsolePlus.BufferHeight;
scrool += dif;
_cusorSpinner = (_cusorSpinner.CursorLeft, _cusorSpinner.CursorTop - dif);
}

Expand Down

0 comments on commit 499e5a5

Please sign in to comment.