Example #1
0
        public AssetBrowserViewModel(
            IProjectManager projectManager,
            INotificationService notificationService,
            IGameControllerFactory gameController,
            IArchiveManager archiveManager,
            ISettingsManager settings,
            IProgressService <double> progressService
            ) : base(ToolTitle)
        {
            _projectManager      = projectManager;
            _notificationService = notificationService;
            _gameController      = gameController;
            _archiveManager      = archiveManager;
            _settings            = settings;
            _progressService     = progressService;

            ContentId = ToolContentId;

            TogglePreviewCommand      = new RelayCommand(ExecuteTogglePreview, CanTogglePreview);
            OpenFileSystemItemCommand = new RelayCommand(ExecuteOpenFile, CanOpenFile);
            AddSelectedCommand        = new RelayCommand(ExecuteAddSelected, CanAddSelected);
            ToggleModBrowserCommand   = new RelayCommand(ExecuteToggleModBrowser, CanToggleModBrowser);
            OpenFileLocationCommand   = new RelayCommand(ExecuteOpenFileLocationCommand, CanOpenFileLocationCommand);

            ExpandAll   = ReactiveCommand.Create(() => { });
            CollapseAll = ReactiveCommand.Create(() => { });
            Collapse    = ReactiveCommand.Create(() => { });
            Expand      = ReactiveCommand.Create(() => { });

            AddSearchKeyCommand = ReactiveCommand.Create <string>(x => SearchBarText += $" {x}:");
            FindUsingCommand    = ReactiveCommand.CreateFromTask(FindUsing);

            archiveManager.ConnectGameRoot()
            .ObserveOn(RxApp.MainThreadScheduler)
            .Bind(out _boundRootNodes)
            .Subscribe(
                _ =>
            {
                // binds only the root node
                LeftItems = new ObservableCollection <RedFileSystemModel>(_boundRootNodes);
            });

            _archiveManager
            .WhenAnyValue(x => x.IsManagerLoaded)
            .Subscribe(loaded =>
            {
                LoadVisibility = loaded ? Visibility.Collapsed : Visibility.Visible;
                if (loaded)
                {
                    _notificationService.Success($"Asset Browser is initialized");
                    NoProjectBorderVisibility = Visibility.Collapsed;
                }
            });
            _projectManager
            .WhenAnyValue(_ => _.IsProjectLoaded)
            .Subscribe(loaded =>
            {
                NoProjectBorderVisibility = loaded ? Visibility.Collapsed : Visibility.Visible;
            });


            Classes = _gameController
                      .GetController()
                      .GetAvaliableClasses();
        }