コード例 #1
0
        public StartPageViewModel(
            IDatabaseInteractions databaseInteractions,
            IApplicationInteraction applicationInteraction,
            IRecentDatabaseFilesProvider recentDatabaseFilesProvider)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            PathDefinitions = recentDatabaseFilesProvider;

            ShowStartPageOnOpen = Properties.Settings.Default.ShowStartPageOnOpen;

            var recentFilesTermFilter = this.WhenValueChanged(vm => vm.SearchTerm)
                                        .Throttle(TimeSpan.FromMilliseconds(150))
                                        .Select(CreatePredicate);

            _cleanUp = PathDefinitions.RecentFiles
                       .ToObservableChangeSet()
                       .Filter(recentFilesTermFilter)
                       .Sort(
                SortExpressionComparer <RecentDatabaseFileInfo>
                .Descending(p => p.FixedAt.HasValue)
                .ThenByDescending(p => p.FixedAt ?? p.LastOpenedAt)
                )
                       .ObserveOnDispatcher()
                       .Bind(out _recentFilesFiltered)
                       .Do(p =>
            {
                NotifyOfPropertyChange(nameof(RecentFilesListIsEmpty));
                NotifyOfPropertyChange(nameof(RecentFilesListEmptyMessage));
            })
                       .Subscribe();
        }
コード例 #2
0
        public DatabasesExplorerViewModel(
            IDatabaseInteractions databaseInteractions,
            IApplicationInteraction applicationInteraction,
            IRecentFilesProvider recentFilesProvider)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            PathDefinitions = recentFilesProvider;

            CloseDatabaseCommand      = new AsyncCommand <DatabaseReference>(CloseDatabase, CanCloseDatabase, this);
            EditDbPropertiesCommand   = new AsyncCommand <DatabaseReference>(EditDbProperties, CanEditDbProperties, this);
            SaveDatabaseCopyAsCommand = new AsyncCommand <DatabaseReference>(SaveDatabaseCopyAs, CanSaveDatabaseCopyAs, this);
            AddFileCommand            = new AsyncCommand <DatabaseReference>(AddFile, CanAddFile, this);
            AddCollectionCommand      = new AsyncCommand <DatabaseReference>(AddCollection, CanAddCollection, this);
            RefreshDatabaseCommand    = new AsyncCommand <DatabaseReference>(RefreshDatabase, CanRefreshDatabase, this);
            RevealInExplorerCommand   = new AsyncCommand <DatabaseReference>(RevealInExplorer, CanRevealInExplorer, this);

            RenameCollectionCommand = new AsyncCommand <CollectionReference>(RenameCollection, CanRenameCollection, this);
            DropCollectionCommand   = new AsyncCommand <CollectionReference>(DropCollection, CanDropCollection, this);
            ExportCollectionCommand = new AsyncCommand <CollectionReference>(ExportCollection, CanExportCollection, this);

            ImportDataCommand = new RelayCommand(_ => ImportData(), _ => CanImportData());

            OpenRecentItemCommand = new AsyncCommand <RecentFileInfo>(OpenRecentItem);

            NodeDefaulActionCommand = new AsyncCommand <object>(NodeDefaultAction);

            Store.Current.Databases.CollectionChanged += OnDatabasesCollectionChanged;
        }
コード例 #3
0
        public CollectionExplorerViewModel(
            IEventAggregator eventAggregator,
            IApplicationInteraction applicationInteraction,
            IDatabaseInteractions databaseInteractions)
        {
            _eventAggregator        = eventAggregator;
            _applicationInteraction = applicationInteraction;
            _databaseInteractions   = databaseInteractions;

            SplitOrientation    = Properties.Settings.Default.CollectionExplorer_SplitOrientation;
            ShowDocumentPreview = Properties.Settings.Default.CollectionExplorer_ShowPreview;
            ContentMaxLength    = Properties.Settings.Default.CollectionExplorer_ContentMaxLength;
            DoubleClickAction   = Properties.Settings.Default.CollectionExplorer_DoubleClickAction;

            FindTextModel = new FindTextModel();

            ItemDoubleClickCommand = new RelayCommand <DocumentReference>(async doc => await OnItemDoubleClick(doc));

            AddDocumentCommand    = new AsyncCommand(AddDocument, CanAddDocument, this);
            EditDocumentCommand   = new AsyncCommand <DocumentReference>(EditDocument, CanEditDocument, this);
            RemoveDocumentCommand = new AsyncCommand(RemoveDocument, CanRemoveDocument, this);
            ExportDocumentCommand = new AsyncCommand(ExportDocument, CanExportDocument, this);
            CopyDocumentCommand   = new AsyncCommand(CopyDocument, CanCopyDocument, this);
            PasteDocumentCommand  = new AsyncCommand(PasteDocument, CanPasteDocument, this);

            RefreshCollectionCommand = new RelayCommand(_ => RefreshCollection(), o => CanRefreshCollection());
            EditDbPropertiesCommand  = new RelayCommand(_ => EditDbProperties(), o => CanEditDbProperties());
            FindCommand         = new RelayCommand(_ => OpenFind(), o => CanOpenFind());
            FindNextCommand     = new RelayCommand(_ => Find(), o => CanFind());
            FindPreviousCommand = new RelayCommand(_ => FindPrevious(), o => CanFind());

            FileDroppedCommand = new AsyncCommand <IDataObject>(OnFileDropped);
        }
コード例 #4
0
ファイル: QueryViewModel.cs プロジェクト: n2i2/LiteDbExplorer
        public QueryViewModel(IApplicationInteraction applicationInteraction, IQueryHistoryProvider queryHistoryProvider)
        {
            _applicationInteraction = applicationInteraction;
            _queryHistoryProvider   = queryHistoryProvider;

            DisplayName = "Query";

            IconContent = new PackIcon {
                Kind = PackIconKind.CodeGreaterThan
            };

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(CurrentDatabase))
                {
                    SetDisplay(CurrentDatabase);
                }
            };

            RunQueryCommand = new RelayCommand(_ => RunAllRawQuery(), _ => CanRunQuery);

            RunSelectedQueryCommand = new RelayCommand(_ => RunSelectedQuery(), _ => CanRunSelectedQuery);

            OpenHelpCommand = new RelayCommand(_ => OpenHelp(), _ => true);

            QueryHistoryView = IoC.Get <QueryHistoryViewModel>();

            QueryHistoryView.Parent = this;

            QueryHistoryView.FilterActiveDatabase = true;
        }
コード例 #5
0
        public QueryHistoryViewModel(IQueryHistoryProvider queryHistoryProvider, IApplicationInteraction applicationInteraction)
        {
            _queryHistoryProvider   = queryHistoryProvider;
            _applicationInteraction = applicationInteraction;

            DisplayName = "Query History";

            QueryHistoriesView = new CollectionViewSource
            {
                Source = _queryHistoryProvider.QueryHistories
            };

            QueryHistoriesView.Filter += (sender, args) =>
            {
                if (_activeDatabase != null && FilterActiveDatabase && args.Item is RawQueryHistory rawQueryHistory)
                {
                    args.Accepted = rawQueryHistory.DatabaseLocation.Equals(_activeDatabase.Location,
                                                                            StringComparison.OrdinalIgnoreCase);
                }
                else
                {
                    args.Accepted = true;
                }
            };
        }
コード例 #6
0
        public DatabasePropertiesViewModel(IApplicationInteraction applicationInteraction, IDatabaseInteractions databaseInteractions)
        {
            _applicationInteraction = applicationInteraction;
            _databaseInteractions   = databaseInteractions;

            DisplayName = "Database Properties";
        }
コード例 #7
0
        public DatabasesExplorerViewModel(
            IDatabaseInteractions databaseInteractions,
            IApplicationInteraction applicationInteraction,
            IRecentFilesProvider recentFilesProvider)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            PathDefinitions = recentFilesProvider;

            OpenRecentItemCommand  = new RelayCommand <RecentFileInfo>(async info => await OpenRecentItem(info));
            ItemDoubleClickCommand = new RelayCommand <CollectionReference>(async reference => await NodeDoubleClick(reference));

            SaveDatabaseCopyAsCommand = new RelayCommand(async _ => await SaveDatabaseCopyAs(), o => CanSaveDatabaseCopyAs());
            CloseDatabaseCommand      = new RelayCommand(async _ => await CloseDatabase(), o => CanCloseDatabase());
            AddFileCommand            = new RelayCommand(async _ => await AddFile(), _ => CanAddFile());
            AddCollectionCommand      = new RelayCommand(async _ => await AddCollection(), _ => CanAddCollection());
            RefreshDatabaseCommand    = new RelayCommand(_ => RefreshDatabase(), _ => CanRefreshDatabase());
            RevealInExplorerCommand   = new RelayCommand(async _ => await RevealInExplorer(), _ => CanRevealInExplorer());
            RenameCollectionCommand   = new RelayCommand(async _ => await RenameCollection(), _ => CanRenameCollection());
            DropCollectionCommand     = new RelayCommand(async _ => await DropCollection(), _ => CanDropCollection());
            ExportCollectionCommand   = new RelayCommand(async _ => await ExportCollection(), _ => CanExportCollection());
            EditDbPropertiesCommand   = new RelayCommand(_ => EditDbProperties(), _ => CanEditDbProperties());
            ImportDataCommand         = new RelayCommand(_ => ImportData(), _ => CanImportData());

            Store.Current.Databases.CollectionChanged += (sender, args) =>
            {
                Commands.ShowNavigationPanel.MainExecute(true);
            };
        }
コード例 #8
0
        public QueryViewModel(
            IApplicationInteraction applicationInteraction,
            IQueryViewsProvider queryViewsProvider,
            IQueryHistoryProvider queryHistoryProvider)
        {
            _applicationInteraction = applicationInteraction;
            _queryViewsProvider     = queryViewsProvider;
            _queryHistoryProvider   = queryHistoryProvider;

            DisplayName = "Query";

            RunQueryCommand = new AsyncCommand(RunAllRawQuery, () => CanRunQuery);

            RunSelectedQueryCommand = new AsyncCommand(RunSelectedQuery, () => CanRunSelectedQuery);

            OpenHelpCommand = new AsyncCommand(OpenHelp);

            QueryHistoryView = IoC.Get <QueryHistoryViewModel>();

            QueryHistoryView.Parent = this;

            QueryHistoryView.FilterActiveDatabase = true;

            QueryHandlersMetadata = _queryViewsProvider.ListMetadata();

            CurrentQueryHandlerName = QueryHandlersMetadata.Select(p => p.Name).FirstOrDefault();
        }
コード例 #9
0
 public DatabaseInteractions(
     IEventAggregator eventAggregator,
     IApplicationInteraction applicationInteraction)
 {
     _eventAggregator        = eventAggregator;
     _applicationInteraction = applicationInteraction;
     PathDefinitions         = new Paths();
 }
コード例 #10
0
        public DefaultCommandsHandler(
            IDatabaseInteractions databaseInteractions,
            IApplicationInteraction applicationInteraction)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            Add(Commands.Exit, (sender, args) =>
            {
                Store.Current.CloseDatabases();

                if (Application.Current.MainWindow != null)
                {
                    Application.Current.MainWindow.Close();
                }
            });

            Add(ApplicationCommands.Open, async(sender, args) =>
            {
                await _databaseInteractions.OpenDatabase();
            });

            Add(ApplicationCommands.New, async(sender, args) =>
            {
                await _databaseInteractions.CreateAndOpenDatabase();
            });

            Add(Commands.FileDropped, async(sender, args) =>
            {
                if (!(args.Parameter is IDataObject dataObject))
                {
                    return;
                }

                try
                {
                    if (dataObject.GetDataPresent(DataFormats.FileDrop) && dataObject.GetData(DataFormats.FileDrop, false) is string[] paths)
                    {
                        await _databaseInteractions.OpenDatabases(paths);
                    }
                }
                catch (Exception exc)
                {
                    _applicationInteraction.ShowError("Failed to open database: " + exc.Message, "Database Error");
                }
            });

            Add(Commands.Import, (sender, args) =>
            {
                _applicationInteraction.ShowImportWizard();
            }, (sender, args) =>
            {
                var hasDatabaseOpen = Store.Current.Databases.Any();
                args.CanExecute     = hasDatabaseOpen;
            });
        }
コード例 #11
0
        public ShellMenuViewModel(
            IDatabaseInteractions databaseInteractions,
            IWindowManager windowManager,
            IApplicationInteraction applicationInteraction)
        {
            _databaseInteractions   = databaseInteractions;
            _windowManager          = windowManager;
            _applicationInteraction = applicationInteraction;

            PathDefinitions = databaseInteractions.PathDefinitions;
        }
コード例 #12
0
        public ShellMenuViewModel(
            IDatabaseInteractions databaseInteractions,
            IWindowManager windowManager,
            IApplicationInteraction applicationInteraction,
            IEventAggregator eventAggregator,
            IRecentFilesProvider recentFilesProvider)
        {
            _databaseInteractions   = databaseInteractions;
            _windowManager          = windowManager;
            _applicationInteraction = applicationInteraction;
            _eventAggregator        = eventAggregator;

            PathDefinitions = recentFilesProvider;
        }
コード例 #13
0
        public StartPageViewModel(IDatabaseInteractions databaseInteractions, IApplicationInteraction applicationInteraction)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            PathDefinitions = databaseInteractions.PathDefinitions;

            ShowStartPageOnOpen = Properties.Settings.Default.ShowStartPageOnOpen;

            PathDefinitions.RecentFiles.CollectionChanged += (sender, args) =>
            {
                NotifyOfPropertyChange(nameof(RecentFilesIsEmpty));
            };
        }
コード例 #14
0
        public QueryViewModel(IApplicationInteraction applicationInteraction)
        {
            _applicationInteraction = applicationInteraction;

            DisplayName = "Query";

            IconContent = new PackIcon {
                Kind = PackIconKind.CodeGreaterThan
            };

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(CurrentDatabase))
                {
                    SetDisplay(CurrentDatabase);
                }
            };

            RunQueryCommand = new RelayCommand(_ => RunQuery(), _ => CanRunQuery);

            RunSelectedQueryCommand = new RelayCommand(_ => RunSelectedQuery(), _ => CanRunSelectedQuery);
        }
コード例 #15
0
        public QueryViewModel(
            IApplicationInteraction applicationInteraction,
            IQueryViewsProvider queryViewsProvider,
            IQueryHistoryProvider queryHistoryProvider)
        {
            _applicationInteraction = applicationInteraction;
            _queryViewsProvider     = queryViewsProvider;
            _queryHistoryProvider   = queryHistoryProvider;

            DisplayName = "Query";

            IconContent = new PackIcon {
                Kind = PackIconKind.CodeGreaterThan
            };

            PropertyChanged += (sender, args) =>
            {
                if (args.PropertyName == nameof(CurrentDatabase))
                {
                    SetDisplay(CurrentDatabase);
                }
            };

            RunQueryCommand = new AsyncCommand(RunAllRawQuery, () => CanRunQuery);

            RunSelectedQueryCommand = new AsyncCommand(RunSelectedQuery, () => CanRunSelectedQuery);

            OpenHelpCommand = new AsyncCommand(OpenHelp);

            QueryHistoryView = IoC.Get <QueryHistoryViewModel>();

            QueryHistoryView.Parent = this;

            QueryHistoryView.FilterActiveDatabase = true;

            QueryHandlersMetadata = _queryViewsProvider.ListMetadata();

            CurrentQueryHandlerName = QueryHandlersMetadata.Select(p => p.Name).FirstOrDefault();
        }
コード例 #16
0
        public DatabasesExplorerViewModel(
            IDatabaseInteractions databaseInteractions,
            IApplicationInteraction applicationInteraction)
        {
            _databaseInteractions   = databaseInteractions;
            _applicationInteraction = applicationInteraction;

            PathDefinitions = databaseInteractions.PathDefinitions;

            OpenRecentItemCommand  = new RelayCommand <RecentFileInfo>(async info => await OpenRecentItem(info));
            ItemDoubleClickCommand = new RelayCommand <CollectionReference>(NodeDoubleClick);

            SaveDatabaseCopyAsCommand = new RelayCommand(async _ => await SaveDatabaseCopyAs(), o => CanSaveDatabaseCopyAs());
            CloseDatabaseCommand      = new RelayCommand(async _ => await CloseDatabase(), o => CanCloseDatabase());
            AddFileCommand            = new RelayCommand(async _ => await AddFile(), _ => CanAddFile());
            AddCollectionCommand      = new RelayCommand(async _ => await AddCollection(), _ => CanAddCollection());
            RefreshDatabaseCommand    = new RelayCommand(_ => RefreshDatabase(), _ => CanRefreshDatabase());
            RevealInExplorerCommand   = new RelayCommand(async _ => await RevealInExplorer(), _ => CanRevealInExplorer());
            RenameCollectionCommand   = new RelayCommand(async _ => await RenameCollection(), _ => CanRenameCollection());
            DropCollectionCommand     = new RelayCommand(async _ => await DropCollection(), _ => CanDropCollection());
            ExportCollectionCommand   = new RelayCommand(async _ => await ExportCollection(), _ => CanExportCollection());
            EditDbPropertiesCommand   = new RelayCommand(_ => EditDbProperties(), _ => CanEditDbProperties());
        }
コード例 #17
0
 public DatabaseInteractions(IApplicationInteraction applicationInteraction, IRecentFilesProvider recentFilesProvider)
 {
     _applicationInteraction = applicationInteraction;
     _recentFilesProvider    = recentFilesProvider;
 }
コード例 #18
0
 public DatabaseSettingsViewModel(IApplicationInteraction applicationInteraction)
 {
     _applicationInteraction    = applicationInteraction;
     DatabaseConnectionFileMode = Properties.Settings.Default.Database_ConnectionFileMode;
 }