Inheritance: Disposable
        public Subscription PushUnmanaged(ConsoleKey key, ConsoleModifiers? modifier, Action<ConsoleKeyInfo> handler)
        {
            Dictionary<ConsoleKey, Stack<Action<ConsoleKeyInfo>>> target;

            if (modifier.HasValue == false) target = nakedHandlers;
            else if (modifier.Value.HasFlag(ConsoleModifiers.Alt)) target = altHandlers;
            else if (modifier.Value.HasFlag(ConsoleModifiers.Shift)) target = shiftHandlers;
            else if (modifier.Value.HasFlag(ConsoleModifiers.Control)) target = controlHandlers;
            else throw new ArgumentException("Unsupported modifier: "+modifier.Value);

            Stack<Action<ConsoleKeyInfo>> targetStack;
            if(target.TryGetValue(key, out targetStack) == false)
            {
                targetStack = new Stack<Action<ConsoleKeyInfo>>();
                target.Add(key, targetStack);
            }

            targetStack.Push(handler);
            var sub = new Subscription(() =>
            {
                targetStack.Pop();
                if(targetStack.Count == 0)
                {
                    target.Remove(key);
                }
            });
            return sub;
        }
 public ProgressOperation()
 {
     StartTime = DateTime.Now;
     LastUpdatedTime = StartTime;
     State = OperationState.NotSet;
     Message = "".ToConsoleString();
     Progress = -1;
     Actions = new ObservableCollection<ProgressOperationAction>();
     selfSub = SubscribeUnmanaged(nameof(State), StateChanged);
 }
Ejemplo n.º 3
0
 public Subscription SubscribeUnmanaged(Action handler)
 {
     var sub = new Subscription(() => { subscribers.Remove(handler); });
     subscribers.Add(handler, sub);
     return sub;
 }
Ejemplo n.º 4
0
        private void TextBox_Focused()
        {
            enableBackspaceNavigationOptimization = true;
            blinkState = true;
            blinkTimerHandle = Application.SetInterval(() =>
            {
                if (HasFocus == false) return;
                blinkState = !blinkState;
                Application.Paint();
            }, BlinkInterval);

            backspacceSub = Application.FocusManager.GlobalKeyHandlers.PushUnmanaged(ConsoleKey.Backspace, null, (info)=>
            {
                if (enableBackspaceNavigationOptimization == false || Application is ConsolePageApp == false)
                {
                    OnKeyInputReceived(info);
                }
                else
                {
                    (Application as ConsolePageApp).PageStack.TryUp();
                }
            });
        }
Ejemplo n.º 5
0
        private void InitGridViewModel()
        {
            this.SelectionMode = GridSelectionMode.Row;
            this.RowPrefix = ConsoleString.Empty;
            this.Gutter = 3;
            this.VisibleColumns = new ObservableCollection<ColumnViewModel>();

            visibleRowOffset = 0;
            SelectedIndex = 0;
            dataSourceSub = SubscribeUnmanaged(nameof(DataSource), DataSourceOrBoundsChangedListener);
            boundsSub = SubscribeUnmanaged(nameof(Bounds), DataSourceOrBoundsChangedListener);

            this.query = new CollectionQuery();

            this.NoDataMessage = "No data";
            this.EndOfDataMessage = "End";
            this.NoVisibleColumnsMessage = "No visible columns";
        }
Ejemplo n.º 6
0
 public LineChartViewModel()
 {
     DataSeriesCollection = new ObservableCollection<DataSeries>();
     DataSeriesCollection.Added.SubscribeUnmanaged(SeriesAdded);
     seriesRemovedSubscription = DataSeriesCollection.Removed.SubscribeUnmanaged(SeriesRemoved);
     focusedDataPointSubscription = SubscribeUnmanaged(nameof(FocusedDataSeriesIndex), FocusedSeriesChanged);
     focusedDataPointSubscription = SubscribeUnmanaged(nameof(FocusedDataPointIndex), FocusedDataPointChanged);
 }
 public ProgressOperationsManager()
 {
     Operations = new ObservableCollection<ProgressOperation>();
     addSub = Operations.Added.SubscribeUnmanaged(Operations_Added);
     removeSub = Operations.Removed.SubscribeUnmanaged(Operations_Removed);
 }