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); }
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); // 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); }