public TextKeyViewModel(string textKey, bool isFullKey, TreeViewItemViewModel parent, MainViewModel mainWindowVM)
            : base(parent, false)
        {
            CultureTextVMs = new ObservableCollection<CultureTextViewModel>();
            TextKey = textKey;
            IsFullKey = isFullKey;

            MainWindowVM = mainWindowVM;

            UpdateIcon();
        }
		public SuggestionViewModel(MainViewModel mainWindowVM)
		{
			MainWindowVM = mainWindowVM;
		}
示例#3
0
        protected override void OnStartup(StartupEventArgs e)
        {
            base.OnStartup(e);

            // Fix WPF's built-in themes
            if (OSInfo.IsWindows8OrNewer)
            {
                ReAddResourceDictionary("/Resources/RealWindows8.xaml");
            }

            // Initialise and show the main window

            CommandLineHelper cmdLine = new CommandLineHelper();
            var scanOption = cmdLine.RegisterOption("scan", 1).Alias("s");

            try
            {
                cmdLine.Parse();
            }
            catch (Exception ex)
            {
                App.ErrorMessage("Command line error.", ex, "Parsing command line");
                Application.Current.Shutdown();
            }

            List<string> filesToLoad = new List<string>();
            bool error = false;
            foreach (string fileNameArg in cmdLine.FreeArguments)
            {
                if (!string.IsNullOrWhiteSpace(fileNameArg))
                {
                    // File name
                    if (File.Exists(fileNameArg))
                    {
                        // File exists, open it
                        string fileName = fileNameArg;
                        if (!Path.IsPathRooted(fileName))
                        {
                            fileName = Path.GetFullPath(fileName);
                        }
                        filesToLoad.Add(fileName);
                    }
                    else if (Directory.Exists(fileNameArg))
                    {
                        // Directory specified, collect all files
                        foreach (string fileName in Directory.GetFiles(fileNameArg, "*.txd"))
                        {
                            filesToLoad.Add(fileName);
                        }
                        if (filesToLoad.Count == 0)
                        {
                            // Nothing found, try older XML file names
                            foreach (string fileName in Directory.GetFiles(fileNameArg, "*.xml"))
                            {
                                if (FileNameHelper.GetCulture(fileName) != null)
                                {
                                    filesToLoad.Add(fileName);
                                }
                            }
                        }
                    }
                    else
                    {
                        FL.Error("File/directory not found", fileNameArg);
                        error = true;
                    }
                }
            }
            if (error)
            {
                App.ErrorMessage("At least one of the files or directories specified at the command line could not be found.");
            }

            // Scan for other files near the selected files
            // (Currently only active if a single file is specified)
            //if (filesToLoad.Count == 1)
            //{
            //    foreach (string fileName in filesToLoad.Distinct().ToArray())
            //    {
            //        if (fileName.ToLowerInvariant().EndsWith(".txd") && File.Exists(fileName))
            //        {
            //            // Existing .txd file
            //            // Scan same directory for other .txd files
            //            string[] otherFiles = Directory.GetFiles(Path.GetDirectoryName(fileName), "*.txd");
            //            // otherFiles should contain fileName and may contain additional files
            //            if (otherFiles.Length > 1)
            //            {
            //                if (App.YesNoQuestion("Other Tx dictionary files are located in the same directory as the selected file. Should they also be loaded?"))
            //                {
            //                    // Duplicates will be removed later
            //                    filesToLoad.AddRange(otherFiles);
            //                }
            //            }
            //        }
            //    }
            //}
            // NOTE: Loading multiple txd files is not supported. (Only scan for more cultures of version 1 files. - Done)

            if (!FileNameHelper.FindOtherCultures(filesToLoad))
                Application.Current.Shutdown();

            // Create main window and view model
            var view = new MainWindow();
            var viewModel = new MainViewModel();

            if (filesToLoad.Count == 0 && scanOption.IsSet)
            {
                viewModel.ScanDirectory = scanOption.Value;
            }

            view.DataContext = viewModel;

            // Load selected files
            if (filesToLoad.Count > 0)
            {
                viewModel.LoadFiles(filesToLoad);
            }

            // Show the main window
            view.Show();
        }