Beispiel #1
0
        /// <summary>
        /// While the main window is open, show the Index open or create view.
        /// That allows the user to select an index or create a new one.
        /// </summary>
        protected void OpenCreateIndexView_method(object sender, EventArgs e)
        {
            SelectCreateIndexWindow selectCreateIndexWindow = new SelectCreateIndexWindow();

            selectCreateIndexWindow.ShowDialog();
            string indexFile = selectCreateIndexWindow.IndexFileToOpen;

            if (indexFile == null || indexFile == "")
            {
                return;
            }
            try
            {
                System.IO.FileInfo fInfo = new System.IO.FileInfo(indexFile);
                if (!fInfo.Exists)
                {
                    MessageBox.Show(string.Format("Could not find file \"{0}\"!", indexFile), "CodeXCavator - Searcher...", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }
            }
            catch
            {
            }
            if (OpenIndexFile(indexFile))
            {
                //Success!
            }
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();
            CodeXCavator.UI.MRUHandler.OpenCreateIndexViewMethod += new EventHandler(OpenCreateIndexView_method);
            // Read and initialize user settings
            var userSettings = new UI.UserSettings();

            new Engine.RegistryUserSettingsStorageProvider().Restore("CodeXCavator", userSettings);
            srcSearcher.UserSettings = userSettings;
            // Initialize the search control with the list of available indexes.
            IEnumerable <IIndex> indexes = ((App)Application.Current).Indexes;

            srcSearcher.Indexes = indexes;

            //If there are no indexes on the command line argument, then reopen the last one,
            //if the user has checked that option.
            if (userSettings.ReOpenLastFile != null && userSettings.ReOpenLastFile == "true" &&
                userSettings.LastSelectedIndex != null && userSettings.LastSelectedIndex != "")
            {
                string path      = userSettings.LastSelectedIndex;
                string indexFile = CodeXCavator.UI.MRUHandler.GetFileWithPath(path);
                if (OpenIndexFile(indexFile))
                {
                    indexes = srcSearcher.Indexes;
                    srcSearcher.SetReOpenNextTimeCheckBox();
                }
                else
                {
                    userSettings.ReOpenLastFile = "false";
                    MessageBox.Show(string.Format("Could not reopen previous index file for \"{0}\"!", path), "CodeXCavator - Searcher...", MessageBoxButton.OK, MessageBoxImage.Information);
                    new Engine.RegistryUserSettingsStorageProvider().Store("CodeXCavator", srcSearcher.UserSettings);
                }
            }

            // If there are no indices, open up the select or create new index view.
            if (!indexes.Any())
            {
                SelectCreateIndexWindow selectCreateIndexWindow = new SelectCreateIndexWindow();
                selectCreateIndexWindow.ShowDialog();
                //The above window may have changed entries, so refresh our settings.
                userSettings = new UI.UserSettings();
                new Engine.RegistryUserSettingsStorageProvider().Restore("CodeXCavator", userSettings);
                srcSearcher.UserSettings = userSettings;

                string indexFile = selectCreateIndexWindow.IndexFileToOpen;
                if (OpenIndexFile(indexFile))
                {
                    indexes = srcSearcher.Indexes;
                }
                else if (indexFile != null && indexFile != "")
                {
                    MessageBox.Show(string.Format("Could not initialize index from configuration file \"{0}\"!", indexFile), "CodeXCavator - Searcher...", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            // Still no indices? Then exit.
            if (!indexes.Any())
            {
                Application.Current.Shutdown();
            }

            // Refresh restore bounds from previous window opening
            IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForAssembly();

            try
            {
                using (IsolatedStorageFileStream stream = new IsolatedStorageFileStream(windowLocationFilename, FileMode.Open, storage))
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        // Read restore bounds value from file
                        Rect restoreBounds = Rect.Parse(reader.ReadLine());
                        this.Left   = restoreBounds.Left;
                        this.Top    = restoreBounds.Top;
                        this.Width  = restoreBounds.Width;
                        this.Height = restoreBounds.Height;
                    }
            }
            catch (FileNotFoundException /*ex*/)
            {
                // Handle when file is not found in isolated storage, which is when:
                // * This is first application session
                // * The file has been deleted
            }
        }