public AccountSelectionFlipViewModel()
 {
     CompositeDisposable.Add(Accounts = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                 Setting.Accounts.Collection,
                                 account => new SelectableAccountViewModel(this, account, RaiseSelectedAccountsChanged),
                                 DispatcherHelper.UIDispatcher));
 }
Esempio n. 2
0
 public VersionInfoViewModel()
 {
     // when update is available, callback this.
     AutoUpdateService.UpdateStateChanged += () => this._isUpdateAvailable = true;
     _contributors = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
         ContributionService.Contributors, c => new ContributorViewModel(c),
         DispatcherHolder.Dispatcher);
     this.CompositeDisposable.Add(
         _contributors.ListenCollectionChanged()
         .Subscribe(_ => RaisePropertyChanged(() => IsDonated)));
 }
Esempio n. 3
0
 public SettingFlipViewModel(MainWindowViewModel parent)
 {
     _parent = parent;
     this.CompositeDisposable.Add(Observable.FromEvent <ISubject <Unit> >(
                                      h => MainWindowModel.SettingRequested += h,
                                      h => MainWindowModel.SettingRequested -= h)
                                  .Subscribe(this.StartSetting));
     this.CompositeDisposable.Add(
         this._accounts = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
             Setting.Accounts.Collection,
             a => new TwitterAccountConfigurationViewModel(this, a),
             DispatcherHelper.UIDispatcher));
 }
 public VersionInfoViewModel()
 {
     // when update is available, callback this.
     if (DesignTimeUtil.IsInDesignMode)
     {
         return;
     }
     AutoUpdateService.UpdateStateChanged += () => _isUpdateAvailable = true;
     _contributors = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
         ContributionService.Contributors, c => new ContributorViewModel(c),
         DispatcherHelper.UIDispatcher);
     CompositeDisposable.Add(_contributors.ListenCollectionChanged(
                                 _ => RaisePropertyChanged(() => IsDonated)));
 }
Esempio n. 5
0
 public AccountSelectorViewModel(InputViewModel parent)
 {
     _parent = parent;
     this._accountSelectionFlip        = new AccountSelectionFlipViewModel();
     this.AccountSelectionFlip.Closed += () =>
     {
         // After selection accounts, return focus to text box
         // if input area is opened.
         if (_parent.IsOpening)
         {
             _parent.FocusToTextBox();
         }
     };
     this.AccountSelectionFlip.SelectedAccountsChanged += () =>
     {
         InputModel.AccountSelector.Accounts.Clear();
         Setting.Accounts.Collection
         .Where(a => AccountSelectionFlip.SelectedAccounts.Contains(a))
         .ForEach(InputModel.AccountSelector.Accounts.Add);
     };
     CompositeDisposable.Add(this.AccountSelectionFlip);
     CompositeDisposable.Add(
         ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
             InputModel.AccountSelector.Accounts,
             a => new TwitterAccountViewModel(a),
             DispatcherHelper.UIDispatcher));
     CompositeDisposable.Add(
         InputModel.AccountSelector.Accounts.ListenCollectionChanged()
         .Subscribe(_ =>
     {
         RaisePropertyChanged(() => AuthInfoGridRowColumn);
         this.RaisePropertyChanged(() => AuthInfoScreenNames);
     }));
     CompositeDisposable.Add(this._accounts =
                                 ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                     InputModel.AccountSelector.Accounts,
                                     account => new TwitterAccountViewModel(account),
                                     DispatcherHelper.UIDispatcher));
     CompositeDisposable.Add(this._accounts
                             .ListenCollectionChanged()
                             .Subscribe(_ =>
     {
         this.RaisePropertyChanged(() => AuthInfoGridRowColumn);
         RaisePropertyChanged(() => IsBindingAuthInfoExisted);
     }));
     CompositeDisposable.Add(
         InputModel.AccountSelector.ListenPropertyChanged(
             () => InputModel.AccountSelector.IsSynchronizedWithTab)
         .Subscribe(_ => RaisePropertyChanged(() => IsSynchronizedWithTab)));
 }
 public MainAreaViewModel()
 {
     CompositeDisposable.Add(
         _columns =
             ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                 TabManager.Columns,
                 cm => new ColumnViewModel(this, cm),
                 DispatcherHelper.UIDispatcher));
     CompositeDisposable.Add(
         Observable.FromEvent(
             h => TabManager.CurrentFocusColumnChanged += h,
             h => TabManager.CurrentFocusColumnChanged -= h)
         .Select(_ => TabManager.CurrentFocusColumnIndex)
         .Subscribe(UpdateFocusFromModel));
     CompositeDisposable.Add(
         _columns.ListenCollectionChanged(_ => _columns.ForEach(c => c.UpdateFocus())));
     RegisterEvents();
 }
 /// <summary>
 ///     for design-time support.
 /// </summary>
 public BackstageViewModel()
 {
     if (DesignTimeUtil.IsInDesignMode)
     {
         return;
     }
     _twitterEvents = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
         BackstageModel.TwitterEvents,
         tev => new TwitterEventViewModel(tev),
         DispatcherHelper.UIDispatcher,
         DispatcherPriority.Background);
     CompositeDisposable.Add(_twitterEvents);
     _accounts = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
         BackstageModel.Accounts,
         a => new BackstageAccountViewModel(this, a),
         DispatcherHelper.UIDispatcher);
     CompositeDisposable.Add(_accounts);
     CompositeDisposable.Add(
         Observable.FromEvent(
             h => BackstageModel.CloseBackstage += h,
             h => BackstageModel.CloseBackstage -= h)
         .Subscribe(_ => this.Close()));
     CompositeDisposable.Add(
         Observable.FromEvent <BackstageEventBase>(
             h => BackstageModel.EventRegistered += h,
             h => BackstageModel.EventRegistered -= h)
         .Subscribe(ev =>
     {
         lock (_syncLock)
         {
             _waitingEvents.Enqueue(ev);
             Monitor.Pulse(_syncLock);
         }
     }));
     CompositeDisposable.Add(() =>
     {
         lock (_syncLock)
         {
             _isDisposed = true;
             Monitor.Pulse(_syncLock);
         }
     });
 }
Esempio n. 8
0
 public ColumnViewModel(MainAreaViewModel parent, ColumnModel model)
 {
     this._parent = parent;
     this._model  = model;
     this.CompositeDisposable.Add(
         this._tabs = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
             model.Tabs,
             _ => new TabViewModel(this, _),
             DispatcherHelper.UIDispatcher));
     this.CompositeDisposable.Add(
         Observable.FromEvent(
             h => this._model.CurrentFocusTabChanged += h,
             h => this._model.CurrentFocusTabChanged -= h)
         .Select(_ => this._model.CurrentFocusTabIndex)
         .Subscribe(this.UpdateFocusFromModel));
     this.CompositeDisposable.Add(_tabs.ListenCollectionChanged(_ =>
                                                                this._tabs.ForEach(item => item.UpdateFocus())));
     if (this._tabs.Count > 0)
     {
         this.FocusedTab = this._tabs[0];
     }
 }
Esempio n. 9
0
        public InputCoreViewModel(InputViewModel parent)
        {
            this._parent   = parent;
            this._provider = new InputAreaSuggestItemProvider();

            CompositeDisposable.Add(
                this._bindingHashtags = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    InputModel.InputCore.BindingHashtags,
                    tag => new BindHashtagViewModel(tag, () => UnbindHashtag(tag)),
                    DispatcherHelper.UIDispatcher));
            CompositeDisposable.Add(_bindingHashtags
                                    .ListenCollectionChanged()
                                    .Subscribe(_ =>
            {
                InputData.BoundTags = _bindingHashtags.Select(h => h.Hashtag).ToArray();
                RaisePropertyChanged(() => IsBindingHashtagExisted);
            }));
            _bindableHashtagCandidates =
                new DispatcherCollection <BindHashtagViewModel>(DispatcherHelper.UIDispatcher);
            CompositeDisposable.Add(_bindableHashtagCandidates
                                    .ListenCollectionChanged()
                                    .Subscribe(_ => RaisePropertyChanged(() => IsBindableHashtagExisted)));

            CompositeDisposable.Add(_draftedInputs =
                                        ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                            InputModel.InputCore.Drafts,
                                            _ =>
                                            new InputDataViewModel(this, _, vm => InputModel.InputCore.Drafts.Remove(vm)),
                                            DispatcherHelper.UIDispatcher));

            CompositeDisposable.Add(_draftedInputs
                                    .ListenCollectionChanged()
                                    .Subscribe(_ =>
            {
                RaisePropertyChanged(() => DraftCount);
                RaisePropertyChanged(() => IsDraftsExisted);
            }));

            // listen setting changed
            CompositeDisposable.Add(
                Setting.SuppressTagBindingInReply.ListenValueChanged(
                    _ => RaisePropertyChanged(() => IsBindHashtagEnabled)));

            // listen text control
            CompositeDisposable.Add(new EventListener <Action <CursorPosition> >(
                                        h => InputModel.SetCursorRequest += h,
                                        h => InputModel.SetCursorRequest -= h,
                                        SetCursor));
            var plistener = new PropertyChangedEventListener(InputModel.InputCore);

            plistener.Add(() => InputModel.InputCore.CurrentInputData, (_, e) => InputDataChanged());
            CompositeDisposable.Add(plistener);

            // create temporary directory and reserve deletion before exit app.
            do
            {
                _tempDir = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            } while (Directory.Exists(_tempDir));
            Directory.CreateDirectory(_tempDir);
            App.ApplicationExit += () =>
            {
                try
                {
                    Directory.Delete(this._tempDir, true);
                }
                // ReSharper disable once EmptyGeneralCatchClause
                catch (Exception)
                {
                    // I think that is sign from God that I must not delete that folder if failed.
                }
            };

            // initialize clipboard watcher.
            ClipboardWatcher watcher;

            CompositeDisposable.Add(watcher = new ClipboardWatcher());
            watcher.ClipboardChanged       += (o, e) => RaisePropertyChanged(() => IsClipboardContentImage);
            watcher.StartWatching();
            Setting.DisableGeoLocationService.ValueChanged += this.UpdateGeoLocationService;
            this.UpdateGeoLocationService(Setting.DisableGeoLocationService.Value);
        }
Esempio n. 10
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
                               IEnumerable <long> initialBoundAccounts)
        {
            this._parent = parent;
            // get status model
            this.Model = status;
            this.RetweetedOriginalModel = status.RetweetedOriginal;

            // bind accounts
            this._bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            this._favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.FavoritedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._favoritedUsers);
            this.CompositeDisposable.Add(
                this._favoritedUsers.ListenCollectionChanged()
                .Subscribe(_ =>
            {
                this.RaisePropertyChanged(() => this.IsFavorited);
                this.RaisePropertyChanged(() => this.IsFavoritedUserExists);
                this.RaisePropertyChanged(() => this.FavoriteCount);
            }));
            this._retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                this.Model.RetweetedUsers, user => new UserViewModel(user),
                DispatcherHelper.UIDispatcher, DispatcherPriority.Background);
            this.CompositeDisposable.Add(this._retweetedUsers);
            this.CompositeDisposable.Add(
                this._retweetedUsers.ListenCollectionChanged()
                .Subscribe(_ =>
            {
                this.RaisePropertyChanged(() => this.IsRetweeted);
                this.RaisePropertyChanged(() => this.IsRetweetedUserExists);
                this.RaisePropertyChanged(() => this.RetweetCount);
            }));
            if (this.RetweetedOriginalModel != null)
            {
                this.CompositeDisposable.Add(
                    this.RetweetedOriginalModel.FavoritedUsers.ListenCollectionChanged()
                    .Subscribe(_ => this.RaisePropertyChanged(() => this.IsFavorited)));
                this.CompositeDisposable.Add(
                    this.RetweetedOriginalModel.RetweetedUsers.ListenCollectionChanged()
                    .Subscribe(_ => this.RaisePropertyChanged(() => this.IsRetweeted)));
            }

            // listen settings
            this.CompositeDisposable.Add(
                new EventListener <Action <bool> >(
                    h => Setting.AllowFavoriteMyself.ValueChanged += h,
                    h => Setting.AllowFavoriteMyself.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => CanFavorite)));
            this.CompositeDisposable.Add(
                new EventListener <Action <bool> >(
                    h => Setting.ShowThumbnails.ValueChanged += h,
                    h => Setting.ShowThumbnails.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => IsThumbnailAvailable)));
            this.CompositeDisposable.Add(
                new EventListener <Action <TweetDisplayMode> >(
                    h => Setting.TweetDisplayMode.ValueChanged += h,
                    h => Setting.TweetDisplayMode.ValueChanged -= h,
                    _ => this.RaisePropertyChanged(() => IsExpanded)));
            // when account is added/removed, all timelines are regenerated.
            // so, we don't have to listen any events which notify accounts addition/deletion.

            // resolve images
            var imgsubj = this.Model.ImagesSubject;

            if (imgsubj != null)
            {
                lock (imgsubj)
                {
                    var subscribe = imgsubj
                                    .Finally(() =>
                    {
                        this.RaisePropertyChanged(() => this.Images);
                        this.RaisePropertyChanged(() => this.ThumbnailImage);
                        this.RaisePropertyChanged(() => this.IsImageAvailable);
                        this.RaisePropertyChanged(() => this.IsThumbnailAvailable);
                    })
                                    .Subscribe();
                    this.CompositeDisposable.Add(subscribe);
                }
            }

            // look-up in-reply-to
            this._isInReplyToExists = this.Status.InReplyToStatusId.HasValue && this.Status.InReplyToStatusId != 0;
        }
Esempio n. 11
0
        public StatusViewModel(TimelineViewModelBase parent, StatusModel status,
                               IEnumerable <long> initialBoundAccounts)
        {
            _parent = parent;
            // get status model
            Model = status;
            RetweetedStatusModel = status.RetweetedStatus;

            // bind accounts
            _bindingAccounts = initialBoundAccounts.Guard().ToArray();

            // initialize users information
            CompositeDisposable.Add(
                _favoritedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    Model.FavoritedUsers, user => new UserViewModel(user),
                    DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
            CompositeDisposable.Add(
                _favoritedUsers.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => IsFavorited);
                RaisePropertyChanged(() => IsFavoritedUserExists);
                RaisePropertyChanged(() => FavoriteCount);
            }));
            CompositeDisposable.Add(
                _retweetedUsers = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                    Model.RetweetedUsers, user => new UserViewModel(user),
                    DispatcherHelper.UIDispatcher, DispatcherPriority.Background));
            CompositeDisposable.Add(
                _retweetedUsers.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => IsRetweeted);
                RaisePropertyChanged(() => IsRetweetedUserExists);
                RaisePropertyChanged(() => RetweetCount);
            }));

            if (RetweetedStatusModel != null)
            {
                CompositeDisposable.Add(
                    RetweetedStatusModel.FavoritedUsers.ListenCollectionChanged(
                        _ => RaisePropertyChanged(() => IsFavorited)));
                CompositeDisposable.Add(
                    RetweetedStatusModel.RetweetedUsers.ListenCollectionChanged(
                        _ => RaisePropertyChanged(() => IsRetweeted)));
            }

            // listen settings
            CompositeDisposable.Add(
                new EventListener <Action <bool> >(
                    h => Setting.AllowFavoriteMyself.ValueChanged += h,
                    h => Setting.AllowFavoriteMyself.ValueChanged -= h,
                    _ => RaisePropertyChanged(() => CanFavorite)));
            CompositeDisposable.Add(
                new EventListener <Action <ThumbnailMode> >(
                    h => Setting.ThumbnailMode.ValueChanged += h,
                    h => Setting.ThumbnailMode.ValueChanged -= h,
                    _ =>
            {
                RaisePropertyChanged(() => IsThumbnailAvailable);
                RaisePropertyChanged(() => IsThumbnailsAvailable);
            }));
            CompositeDisposable.Add(
                new EventListener <Action <TweetDisplayMode> >(
                    h => Setting.TweetDisplayMode.ValueChanged += h,
                    h => Setting.TweetDisplayMode.ValueChanged -= h,
                    _ =>
            {
                RaisePropertyChanged(() => IsExpanded);
                RaisePropertyChanged(() => IsSingleLine);
            }));
            // when account is added/removed, all timelines are regenerated.
            // so, we don't have to listen any events which notify accounts addition/deletion.

            CompositeDisposable.Add(_images = ViewModelHelperRx.CreateReadOnlyDispatcherCollectionRx(
                                        Model.Images, m => new ThumbnailImageViewModel(m), DispatcherHelper.UIDispatcher));
            // resolve images
            CompositeDisposable.Add(_images.ListenCollectionChanged(_ =>
            {
                RaisePropertyChanged(() => ThumbnailImage);
                RaisePropertyChanged(() => IsImageAvailable);
                RaisePropertyChanged(() => IsThumbnailAvailable);
                RaisePropertyChanged(() => IsThumbnailsAvailable);
            }));

            // look-up in-reply-to
            _isInReplyToExists = Status.InReplyToStatusId.HasValue && Status.InReplyToStatusId != 0;
        }