Ejemplo n.º 1
0
 private void RunAnimation(double offset, double height)
 {
     if (_remainHeight < 0)
     {
         _remainHeight = 0;
     }
     if (_currentOffset < 0)
     {
         _currentOffset = 0;
     }
     _currentOffset = offset;
     _remainHeight += height;
     if (_isAnimationRunning)
     {
         return;
     }
     _isAnimationRunning = true;
     Task.Run(() =>
     {
         for (var i = 20; i > 0; i--)
         {
             Thread.Sleep(10);
             var dx          = _remainHeight / i;
             _remainHeight  -= dx;
             _currentOffset -= dx;
             DispatcherHolder.Enqueue(() => this.AssociatedObject.ScrollToVerticalOffset(_currentOffset));
         }
         _isAnimationRunning = false;
     });
 }
Ejemplo n.º 2
0
 public static void ShowMarker(int displayIndex)
 {
     DispatcherHolder.Enqueue(() => new DisplayMarkerWindow
     {
         DataContext = new DisplayMarkerViewModel(displayIndex)
     }.Show());
 }
Ejemplo n.º 3
0
 public override void GotFocus()
 {
     this._parent.FocusedTab = this;
     this._parent.Focus();
     // wait for completion of creating view
     DispatcherHolder.Enqueue(this.SetFocus, DispatcherPriority.Input);
 }
Ejemplo n.º 4
0
 public TimelineViewModelBase(TimelineModelBase model)
 {
     this._model    = model;
     this._timeline = new ObservableCollection <StatusViewModel>();
     DispatcherHolder.Enqueue(this.InitializeCollection, DispatcherPriority.Background);
     this.CompositeDisposable.Add(
         new EventListener <Action <bool> >(
             h => model.InvalidationStateChanged += h,
             h => model.InvalidationStateChanged -= h,
             s => this.IsLoading = s));
     this.CompositeDisposable.Add(() =>
     {
         if (_listener != null)
         {
             _listener.Dispose();
         }
     });
     this.CompositeDisposable.Add(
         this.ListenPropertyChanged(() => this.CurrentAccounts)
         .ObserveOnDispatcher()
         .Select(_ => this.CurrentAccounts.ToArray())
         .Subscribe(a => _timeline.ForEach(s => s.BindingAccounts = a)));
     this.IsLoading = true;
     this._model.InvalidateTimeline();
 }
Ejemplo n.º 5
0
 private void UpdateFocusFromModel(int newFocus)
 {
     DispatcherHolder.Enqueue(() =>
     {
         _columns.ForEach(c => c.UpdateFocus());
         RaisePropertyChanged(() => FocusedColumn);
     });
 }
Ejemplo n.º 6
0
 private void UpdateFocusFromModel(int newFocus)
 {
     DispatcherHolder.Enqueue(() =>
     {
         this._tabs.ForEach(item => item.UpdateFocus());
         this.RaisePropertyChanged(() => this.FocusedTab);
     });
 }
Ejemplo n.º 7
0
        internal void ExecuteTimelineAction(Action <TimelineViewModelBase> action)
        {
            var timeline = TimelineActionTargetOverride ?? FocusedColumn.FocusedTab;

            if (timeline == null)
            {
                return;
            }
            DispatcherHolder.Enqueue(() => action(timeline));
        }
Ejemplo n.º 8
0
        private static void RunNextDecodeTask()
        {
            // uri, LazyImage, dpw, dph
            Tuple <Uri, LazyImage, byte[], int, int> item;

            if (!_decodeStack.TryPop(out item))
            {
                Interlocked.Decrement(ref _decodeThreadConcurrency);
            }
            else
            {
                Task.Run(() =>
                {
                    var b = CreateImage(item.Item3, item.Item4, item.Item5);
                    DispatcherHolder.Enqueue(() => SetImage(item.Item2, b, item.Item1),
                                             DispatcherPriority.Background);
                }).ContinueWith(_ => RunNextDecodeTask());
            }
        }
Ejemplo n.º 9
0
 static void Show(NormalNotificatorViewModel dataContext)
 {
     DispatcherHolder.Enqueue(() =>
     {
         var mwnd = Application.Current.MainWindow;
         if (mwnd != null &&
             (Setting.NotifyWhenWindowIsActive.Value || !mwnd.IsActive))
         {
             new NormalNotificatorView
             {
                 DataContext = dataContext
             }.Show();
         }
         else
         {
             dataContext.ReleaseSlot();
         }
     });
 }
Ejemplo n.º 10
0
 private static void Show(NotificationData next)
 {
     DispatcherHolder.Enqueue(() =>
     {
         var mwnd = Application.Current.MainWindow;
         if (mwnd != null && (Setting.NotifyWhenWindowIsActive.Value || !mwnd.IsActive))
         {
             new SlimNotificatorView
             {
                 DataContext = new SlimNotificatorViewModel(next)
             }.Show();
         }
         else
         {
             // do not show popup
             ShowNext();
         }
     });
 }
Ejemplo n.º 11
0
        private void StartSetting(ISubject <Unit> subject)
        {
            // ensure close before starting setting
            this.IsConfigurationActive = false;

            this.RefreshKeyAssignCandidates();
            this.RefreshThemeCandidates();
            this.ResetFilter();
            this.KeyAssignEditorViewModel.RefreshRegisteredActions();
            this._completeCallback       = subject;
            this._fsWatcher              = new FileSystemWatcher(ThemeManager.ThemeProfileDirectoryPath, "*.xml");
            this._fsWatcher.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.FileName |
                                           NotifyFilters.DirectoryName | NotifyFilters.Size;
            this._fsWatcher.Changed            += (_, e) => DispatcherHolder.Enqueue(this.RefreshThemeCandidates);
            this._fsWatcher.Created            += (_, e) => DispatcherHolder.Enqueue(this.RefreshThemeCandidates);
            this._fsWatcher.Deleted            += (_, e) => DispatcherHolder.Enqueue(this.RefreshThemeCandidates);
            this._fsWatcher.Renamed            += (_, e) => DispatcherHolder.Enqueue(this.RefreshThemeCandidates);
            this._fsWatcher.EnableRaisingEvents = true;
            this.RaisePropertyChanged();
            this.IsConfigurationActive = true;
        }
Ejemplo n.º 12
0
 private void InitializeCollection()
 {
     // on dispatcher.
     if (_listener != null)
     {
         _listener.Dispose();
         _listener = null;
     }
     lock (this._timelineLock)
     {
         var sts = this._model.Statuses.SynchronizedToArray(
             () => _listener = this._model.Statuses
                               .ListenCollectionChanged()
                               .Subscribe(e => DispatcherHolder.Enqueue(
                                              () => this.ReflectCollectionChanged(e),
                                              DispatcherPriority.Background)));
         this._timeline.Clear();
         sts.OrderByDescending(s => s.Status.CreatedAt)
         .Select(this.GenerateStatusViewModel)
         .ForEach(this._timeline.Add);
     }
 }
Ejemplo n.º 13
0
        private static IDisposable CreateSubscription <TModel, TViewModel>(
            INotifyCollectionChanged source, Func <TModel, TViewModel> converter,
            DispatcherCollectionRx <TViewModel> target)
        {
            return(new CollectionChangedEventListener(source, (o, e) =>
                                                      DispatcherHolder.Enqueue(() =>
            {
                if (e.NewItems != null && e.NewItems.Count >= 2)
                {
                    throw new ArgumentException("Too many new items.");
                }
                try
                {
                    switch (e.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        if (e.NewItems == null)
                        {
                            throw new ArgumentException("New item is null.");
                        }
                        target.Insert(e.NewStartingIndex, converter((TModel)e.NewItems[0]));
                        break;

                    case NotifyCollectionChangedAction.Move:
                        target.Move(e.OldStartingIndex, e.NewStartingIndex);
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        if (typeof(IDisposable).IsAssignableFrom(typeof(TViewModel)))
                        {
                            ((IDisposable)target[e.OldStartingIndex]).Dispose();
                        }
                        target.RemoveAt(e.OldStartingIndex);
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        if (typeof(IDisposable).IsAssignableFrom(typeof(TViewModel)))
                        {
                            ((IDisposable)target[e.NewStartingIndex]).Dispose();
                        }
                        if (e.NewItems == null)
                        {
                            throw new ArgumentException("New item is null.");
                        }
                        target[e.NewStartingIndex] = converter((TModel)e.NewItems[0]);
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        if (typeof(IDisposable).IsAssignableFrom(typeof(TViewModel)))
                        {
                            // ReSharper disable once PossibleInvalidCastExceptionInForeachLoop
                            foreach (IDisposable item in target)
                            {
                                item.Dispose();
                            }
                        }
                        target.Clear();
                        break;

                    default:
                        throw new ArgumentException();
                    }
                }
                catch (ArgumentOutOfRangeException aoex)
                {
                    throw new InvalidOperationException(
                        "Collection state is invalid." + Environment.NewLine +
                        "INDEX OUT OF RANGE - " + e.Action + "[" + typeof(TModel).Name + " -> " +
                        typeof(TViewModel).Name + "]" + Environment.NewLine +
                        "new start: " + e.NewStartingIndex + ", count: " +
                        (e.NewItems == null
                                ? "null"
                                : e.NewItems.Count.ToString(CultureInfo.InvariantCulture)) +
                        Environment.NewLine +
                        "source length: " + ((IList <TModel>)source).Count + ", target length: " + target.Count +
                        ".",
                        aoex);
                }
            })));
        }