void IDialogViewEvents.OnAddClicked()
        {
            var search = userDefinedSearches.AddNew();

            if (!searchEditorDialog.Open(search))
            {
                userDefinedSearches.Delete(search);
            }
        }
        public Presenter(
            IView view,
            ISearchManager searchManager,
            ISearchHistory searchHistory,
            IUserDefinedSearches userDefinedSearches,
            ILogSourcesManager sourcesManager,
            IFiltersFactory filtersFactory,
            ISearchResultsPanelView searchResultsPanelView,
            LoadedMessages.IPresenter loadedMessagesPresenter,
            SearchResult.IPresenter searchResultPresenter,
            StatusReports.IPresenter statusReportFactory,
            SearchEditorDialog.IPresenter searchEditorDialog,
            SearchesManagerDialog.IPresenter searchesManagerDialog,
            IAlertPopup alerts
            )
        {
            this.view                    = view;
            this.searchManager           = searchManager;
            this.searchHistory           = searchHistory;
            this.filtersFactory          = filtersFactory;
            this.searchResultsPanelView  = searchResultsPanelView;
            this.loadedMessagesPresenter = loadedMessagesPresenter;
            this.searchResultPresenter   = searchResultPresenter;
            this.statusReportFactory     = statusReportFactory;
            this.sourcesManager          = sourcesManager;
            this.searchesManagerDialog   = searchesManagerDialog;
            this.alerts                  = alerts;
            this.quickSearchPresenter    = new QuickSearchTextBox.Presenter(view.SearchTextBox);
            this.searchEditorDialog      = searchEditorDialog;

            InvalidateSearchHistoryList();
            searchHistory.OnChanged += (sender, args) => InvalidateSearchHistoryList();

            sourcesManager.OnLogSourceAdded   += (sender, e) => UpdateSearchControls();
            sourcesManager.OnLogSourceRemoved += (sender, e) => UpdateSearchControls();

            UpdateSearchControls();
            UpdateUserDefinedSearchDependentControls(false);

            view.SetPresenter(this);

            quickSearchPresenter.OnSearchNow += (sender, args) =>
            {
                if (quickSearchPresenter.Text != "")
                {
                    DoSearch(reverseDirection: args.ReverseSearchModifier);
                }
            };
            quickSearchPresenter.OnCancelled += (sender, args) =>
            {
                bool searchCancelled = false;
                foreach (var r in searchManager.Results.Where(r => r.Status == SearchResultStatus.Active))
                {
                    r.Cancel();
                    searchCancelled = true;
                }
                if (!searchCancelled && InputFocusAbandoned != null)
                {
                    InputFocusAbandoned(this, EventArgs.Empty);
                }
            };
            quickSearchPresenter.SetSuggestionsHandler((sender, e) =>
            {
                if (e.Etag == searchListEtag)
                {
                    return;
                }
                foreach (var i in searchHistory.Items)
                {
                    var description = new StringBuilder();
                    GetUserFriendlySearchHistoryEntryDescription(i, description);
                    e.AddItem(new QuickSearchTextBox.SuggestionItem()
                    {
                        DisplayString = description.ToString(),
                        SearchString  = (i as ISimpleSearchHistoryEntry)?.Options.Template,
                        Category      = "recent searches",
                        Data          = i
                    });
                }
                foreach (var i in userDefinedSearches.Items)
                {
                    var description = new StringBuilder();
                    GetUserFriendlySearchHistoryEntryDescription(i, description);
                    e.AddItem(new QuickSearchTextBox.SuggestionItem()
                    {
                        DisplayString = description.ToString(),
                        LinkText      = "edit",
                        Category      = "Filters",
                        Data          = i
                    });
                }
                e.ConfigureCategory("Filters", linkText: "manage", alwaysVisible: true);
                e.Etag = searchListEtag;
            });
            quickSearchPresenter.OnCurrentSuggestionChanged += (sender, e) =>
            {
                var datum = quickSearchPresenter.CurrentSuggestion?.Data;
                var searchHistoryEntry = datum as ISimpleSearchHistoryEntry;
                if (searchHistoryEntry != null)
                {
                    ReadControlsFromSelectedHistoryEntry(searchHistoryEntry);
                }
                UpdateUserDefinedSearchDependentControls(
                    datum is IUserDefinedSearch || datum is IUserDefinedSearchHistoryEntry);
            };
            quickSearchPresenter.OnSuggestionLinkClicked += (sender, e) =>
            {
                var uds = e.Suggestion.Data as IUserDefinedSearch;
                if (uds == null)
                {
                    return;
                }
                searchEditorDialog.Open(uds);
            };
            quickSearchPresenter.OnCategoryLinkClicked += (sender, e) =>
            {
                HandleSearchesManagerDialog();
            };
            userDefinedSearches.OnChanged += (sender, e) =>
            {
                InvalidateSearchHistoryList();
            };
        }