private void MainWindow_FileClosed(object sender, KeePass.Forms.FileClosedEventArgs e)
 {
     try
     {
         RefreshState();
     }
     catch (Exception ex)
     {
         ShowError(null, ex);
     }
 }
        void MainWindow_FileClosed(object sender, KeePass.Forms.FileClosedEventArgs e)
        {
            Debug.WriteLine("File closed");
            // remove the event listeners of those Search Controllers whose databases have been closed
            PwDatabase[] databases = new PwDatabase[this.dictionary.Count];
            this.dictionary.Keys.CopyTo(databases, 0);
            //bool isDatabaseOpen
            bool disableQSControl = true;

            foreach (PwDatabase database in databases)
            {
                if (database.IsOpen == false)
                {
                    SearchController controller;
                    this.dictionary.TryGetValue(database, out controller);
                    this.qsControl.TextChanged -=
                        controller.TextUpdateHandler;

                    //this.qsControl.comboBoxSearch.TextChanged -=
                    //controller.TextUpdateHandler;

                    this.dictionary.Remove(database);
                }
                else // database is open
                {
                    disableQSControl = false;
                }
            }
            if (disableQSControl)
            {
                this.qsControl.Text = String.Empty;
            }
            //to be improved once access to closed database is implemented in Keepass
            //dictionary.Clear();
            //foreach (PwDocument document in host.MainWindow.DocumentManager.Documents)
            //{
            //    if (document.Database.IsOpen)
            //    dictionary.Add(document.Database, new SearchController(this.qsControl, document.Database, GetMainListViewControl()));
            //}
        }