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
        /// <summary>
        /// 共有操作のターゲットとしてアプリケーションがアクティブにされたときに呼び出されます。
        /// </summary>
        /// <param name="args">アクティベーション要求の詳細。</param>
        protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
        {
            var shareTargetPage = new ShareTargetPage();

            DispatcherHolder.InitializeIfNeeded(shareTargetPage);
            shareTargetPage.Activate(args);
        }
Ejemplo n.º 5
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();
 }
        public void OnRemoteCollectionUpdated(object sender, EventTreeEventArgs e)
        {
            UpdateCollection(e.Collection);
            Action action = () => _collectionUpdatedEvent.Raise(this, e);

            DispatcherHolder.BeginInvoke(action);
        }
Ejemplo n.º 7
0
 private void UpdateFocusFromModel(int newFocus)
 {
     DispatcherHolder.Enqueue(() =>
     {
         _columns.ForEach(c => c.UpdateFocus());
         RaisePropertyChanged(() => FocusedColumn);
     });
 }
Ejemplo n.º 8
0
 private void UpdateFocusFromModel(int newFocus)
 {
     DispatcherHolder.Enqueue(() =>
     {
         this._tabs.ForEach(item => item.UpdateFocus());
         this.RaisePropertyChanged(() => this.FocusedTab);
     });
 }
Ejemplo n.º 9
0
 protected ApplicationBase(Guid uid, bool processOwner)
     : base(processOwner)
 {
     _uid          = uid;
     _container    = new Container();
     _bootstrapper = new Bootstrapper(_container);
     DispatcherHolder.Initialize(new WindowsDispatcher());
 }
Ejemplo n.º 10
0
        internal void ExecuteTimelineAction(Action <TimelineViewModelBase> action)
        {
            var timeline = TimelineActionTargetOverride ?? FocusedColumn.FocusedTab;

            if (timeline == null)
            {
                return;
            }
            DispatcherHolder.Enqueue(() => action(timeline));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// アプリケーションがエンド ユーザーによって正常に起動されたときに呼び出されます。他のエントリ ポイントは、
        /// アプリケーションが特定のファイルを開くために呼び出されたときに
        /// 検索結果やその他の情報を表示するために使用されます。
        /// </summary>
        /// <param name="args">起動要求とプロセスの詳細を表示します。</param>
        protected override async void OnLaunched(LaunchActivatedEventArgs args)
        {
            Frame rootFrame = Window.Current.Content as Frame;

            if (rootFrame == null)
            {
                SettingsPane.GetForCurrentView().CommandsRequested += App_CommandsRequested;

                // ナビゲーション コンテキストとして動作するフレームを作成し、最初のページに移動します
                rootFrame = new Frame();
                DispatcherHolder.InitializeIfNeeded(rootFrame);
                //フレームを SuspensionManager キーに関連付けます
                SuspensionManager.RegisterFrame(rootFrame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // 必要な場合のみ、保存されたセッション状態を復元します
                    try
                    {
                        await SuspensionManager.RestoreAsync();
                    }
                    catch (SuspensionManagerException)
                    {
                        //状態の復元に何か問題があります。
                        //状態がないものとして続行します
                    }
                }

                // フレームを現在のウィンドウに配置します
                Window.Current.Content = rootFrame;
            }

            if (rootFrame.Content == null)
            {
                // ナビゲーション スタックが復元されていない場合、最初のページに移動します。
                // このとき、必要な情報をナビゲーション パラメーターとして渡して、新しいページを
                // を構成します
                if (!rootFrame.Navigate(typeof(MainPage)))
                {
                    throw new Exception("Failed to create initial page");
                }
            }
            // 現在のウィンドウがアクティブであることを確認します
            Window.Current.Activate();
        }
Ejemplo n.º 12
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.º 13
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.º 14
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.º 15
0
        private static void SetSystemParameters(bool useProfiling, bool useHardwareRendering)
        {
            // enable multi-core JIT.
            // see reference: http://msdn.microsoft.com/en-us/library/system.runtime.profileoptimization.aspx
            if (useProfiling)
            {
                ProfileOptimization.SetProfileRoot(App.ConfigurationDirectoryPath);
                ProfileOptimization.StartProfile(App.ProfileFileName);
            }

            // initialize dispatcher helper
            DispatcherHelper.UIDispatcher = Application.Current.Dispatcher;
            DispatcherHolder.Initialize(Application.Current.Dispatcher);

            // set rendering mode
            if (!useHardwareRendering)
            {
                System.Windows.Media.RenderOptions.ProcessRenderMode = System.Windows.Interop.RenderMode.SoftwareOnly;
            }
        }
Ejemplo n.º 16
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.º 17
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.º 18
0
        private async void ChangeDisplayOfTimeline(TweetDisplayMode newValue)
        {
            if (Setting.TweetDisplayMode.Value == newValue)
            {
                RaisePropertyChanged();
                return;
            }
            var showDonationInfo = false;

            if (Setting.TweetDisplayMode.Value == Settings.TweetDisplayMode.Expanded &&
                (newValue == Settings.TweetDisplayMode.SingleLine || newValue == Settings.TweetDisplayMode.Mixed))
            {
                var resp = this.Messenger.GetResponse(new TaskDialogMessage(new TaskDialogOptions
                {
                    Title           = "一行表示モードの警告",
                    MainIcon        = VistaTaskDialogIcon.Warning,
                    MainInstruction = "一行表示モードを有効にしようとしています。",
                    Content         = "一行表示モードは複数行表示モードに比べ、リソースを大量に消費します。" + Environment.NewLine +
                                      "また、Krile StarryEyesは一行表示モードをベースとして設計されてはいないため、意図しない動作をする可能性があります。" +
                                      Environment.NewLine +
                                      "一行表示モードを本当に有効にしますか?",
                    CommonButtons = TaskDialogCommonButtons.YesNo
                }));
                if (resp.Response.Result == TaskDialogSimpleResult.No)
                {
                    this.TweetDisplayMode = (int)Settings.TweetDisplayMode.Expanded;
                    return;
                }
                showDonationInfo = true;
            }
            await DispatcherHolder.BeginInvoke(() =>
            {
                var ww = new WorkingWindow(
                    "changing timeline mode...", async() =>
                {
                    await Task.Run(() => Setting.TweetDisplayMode.Value = newValue);
                    RaisePropertyChanged(() => IsDonationVisible);
                    await DispatcherHolder.BeginInvoke(async() =>
                    {
                        await Dispatcher.Yield(DispatcherPriority.Background);
                    });
                });
                if (showDonationInfo && !ContributionService.IsContributor())
                {
                    ww.Closed += async(o, e) =>
                    {
                        await this.Messenger.RaiseAsync(new TaskDialogMessage(new TaskDialogOptions
                        {
                            Title           = "Krileの開発にご協力ください。",
                            MainIcon        = VistaTaskDialogIcon.Information,
                            MainInstruction = "Krileの開発にご協力ください。",
                            Content         = "多くのユーザーの補助によってKrileが開発されています。" + Environment.NewLine +
                                              "Krileの開発を継続するため、寄付にご協力ください。",
                            CustomButtons = new[] { "開発者に寄付" }
                        }));
                        BrowserHelper.Open(App.DonationUrl);
                    };
                }
                ww.ShowDialog();
            });
        }
Ejemplo n.º 19
0
        public void OnUnitServerCollectionUpdated(object sender, UnitCollectionEventArgs <T> e)
        {
            Action action = () => UpdateUnits(e.Units);

            DispatcherHolder.BeginInvoke(action);
        }
Ejemplo n.º 20
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);
                }
            })));
        }