44#region
55
66using System . Collections ;
7+ using System . Collections . Concurrent ;
78using System . Data ;
89using System . Diagnostics ;
910using System . Runtime . CompilerServices ;
@@ -396,4 +397,139 @@ void OnAction(ListView lv, Action<SearchEngineOptions> f)
396397 Tf_Input . SetFocus ( ) ;
397398 Tf_Input . EnsureFocus ( ) ;
398399 }
400+
401+ private void Queue_Dialog ( )
402+ {
403+ var d = new Dialog ( )
404+ {
405+ Title = $ "Queue ({ Queue . Count } items)",
406+ AutoSize = false ,
407+ Width = Dim . Percent ( 60 ) ,
408+ Height = Dim . Percent ( 55 ) ,
409+ // Height = UI.Dim_80_Pct,
410+ } ;
411+
412+ var cpy = Queue . ToList ( ) ;
413+
414+ var tf = new TextField ( )
415+ {
416+ Width = Dim . Fill ( ) ,
417+ Height = 2 ,
418+ } ;
419+
420+ var lv = new ListView ( cpy )
421+ {
422+ Width = Dim . Fill ( ) ,
423+ Height = Dim . Fill ( ) ,
424+ Y = Pos . Bottom ( tf ) ,
425+ Border = new Border ( )
426+ {
427+ BorderStyle = BorderStyle . Rounded ,
428+ BorderThickness = new Thickness ( 2 )
429+ }
430+ } ;
431+
432+ /*var btnAdd = new Button("Add")
433+ {
434+ X = Pos.Right(tf),
435+ Y = Pos.Y(tf)
436+ };
437+ btnAdd.Clicked += () =>
438+ {
439+ var s = tf.Text.ToString();
440+ Queue.Enqueue(s);
441+ lv.Source = new ListWrapper(Queue.ToList());
442+
443+ };*/
444+
445+ var btnRm = new Button ( "Remove" )
446+ {
447+ ColorScheme = UI . Cs_Btn3
448+ } ;
449+
450+ btnRm . Clicked += ( ) =>
451+ {
452+ var cpy2 = lv . Source . ToList ( ) ;
453+
454+ if ( lv . SelectedItem < cpy2 . Count && lv . SelectedItem >= 0 ) {
455+ var i = ( string ) cpy2 [ lv . SelectedItem ] ;
456+ // Debug.WriteLine($"{i}");
457+ cpy . Remove ( i ) ;
458+ // Queue.Clear();
459+ Queue = new ConcurrentQueue < string > ( cpy ) ;
460+ lv . SetFocus ( ) ;
461+
462+ }
463+ } ;
464+
465+ var btnRmAll = new Button ( "Clear" )
466+ {
467+ ColorScheme = UI . Cs_Btn3
468+ } ;
469+
470+ btnRmAll . Clicked += ( ) =>
471+ {
472+ lv . Source = new ListWrapper ( Array . Empty < string > ( ) ) ;
473+ Queue . Clear ( ) ;
474+ lv . SetFocus ( ) ;
475+ } ;
476+
477+ tf . TextChanged += delegate ( ustring ustring )
478+ {
479+ Debug . WriteLine ( $ "{ ustring } ") ;
480+ } ;
481+
482+ tf . TextChanging += a =>
483+ {
484+
485+ var s = a . NewText . ToString ( ) . CleanString ( ) . Trim ( '\" ' ) ;
486+
487+ // Application.MainLoop.Invoke(() => Task.Delay(TimeSpan.FromSeconds(1)));
488+ if ( SearchQuery . IsValidSourceType ( s ) ) {
489+ Queue . Enqueue ( s ) ;
490+ lv . Source = new ListWrapper ( Queue . ToList ( ) ) ;
491+ /*tf.DeleteAll();
492+ tf.Text = ustring.Empty;
493+ a.Cancel = false;
494+ a.NewText = ustring.Empty;
495+ tf.DeleteAll();*/
496+ tf . DeleteAll ( ) ;
497+ Debug . WriteLine ( $ "{ tf . Text } { s } ") ;
498+ // tf.Text = ustring.Empty;
499+ // a.NewText = ustring.Empty;
500+ // tf.SetFocus();
501+ // tf.SetNeedsDisplay();
502+ Application . MainLoop . Invoke ( ( ) => Action ( tf ) ) ;
503+ tf . Text = ustring . Empty ;
504+
505+ Debug . WriteLine ( $ "{ tf . Text } { a . NewText } ") ;
506+ }
507+ } ;
508+
509+ static void Action ( TextField tf )
510+ {
511+ Debug . WriteLine ( $ "clearing") ;
512+ // Task.Delay(TimeSpan.FromSeconds(3));
513+ // tf.Text = ustring.Empty;
514+ // tf.CursorPosition = 0;
515+ tf . DeleteAll ( ) ;
516+ tf . ClearHistoryChanges ( ) ;
517+ tf . ClearAllSelection ( ) ;
518+ tf . SetNeedsDisplay ( ) ;
519+ Debug . WriteLine ( $ "cleared") ;
520+ }
521+
522+ var btnOk = new Button ( "Ok" )
523+ {
524+ ColorScheme = UI . Cs_Btn3
525+ } ;
526+ btnOk . Clicked += ( ) => { Application . RequestStop ( ) ; } ;
527+
528+ d . Add ( tf , lv ) ;
529+ d . AddButton ( btnRm ) ;
530+ d . AddButton ( btnRmAll ) ;
531+ d . AddButton ( btnOk ) ;
532+
533+ Application . Run ( d ) ;
534+ }
399535}
0 commit comments