}                                                        //选择主题

        public MainViewModel()
        {
            LanguageList = new List <string>();
            ThemeList    = new List <string>();
            FontSizeList = new List <int>();
            FontList     = new List <string>();

            Init(Application.StartupPath + @"\Configuration\Configuration.xml");

            SelectedFont     = "Consolas";
            SelectedLanguage = "Python";
            SelectedFontSize = 12;
            SelectedTheme    = "Dark";

            InputFolderCommand = new Command(() =>
            {
                FolderBrowserDialog openFileDialog = new FolderBrowserDialog(); //选择文件夹

                if (openFileDialog.ShowDialog() == DialogResult.OK)             //注意,此处一定要手动引入System.Window.Forms空间,否则你如果使用默认的DialogResult会发现没有OK属性
                {
                    InputFolderPath = openFileDialog.SelectedPath;

                    List <FileInformation> list = new List <FileInformation>();
                    FileInformation temp;
                    //遍历文件夹
                    DirectoryInfo theFolder = new DirectoryInfo(InputFolderPath);
                    FileInfo[] thefileInfo  = theFolder.GetFiles("*" + FilenameExtensionDic[SelectedLanguage], SearchOption.TopDirectoryOnly);
                    foreach (FileInfo NextFile in thefileInfo) //遍历文件
                    {
                        temp = new FileInformation
                        {
                            Selected = true,
                            FileName = NextFile.Name,
                            EditTime = NextFile.LastWriteTime.ToString(),
                            Size     = NextFile.Length.ToString(),
                            FullPath = NextFile.DirectoryName
                        };

                        list.Add(temp);
                    }

                    //  暂时不包含子文件夹
                    //遍历子文件夹
                    DirectoryInfo[] dirInfo = theFolder.GetDirectories();
                    foreach (DirectoryInfo NextFolder in dirInfo)
                    {
                        //list.Add(NextFolder.ToString());
                        FileInfo[] fileInfo = NextFolder.GetFiles("*.py", SearchOption.AllDirectories);
                        foreach (FileInfo NextFile in fileInfo) //遍历文件
                        {
                            temp = new FileInformation
                            {
                                Selected = true,
                                FileName = NextFile.Name,
                                EditTime = NextFile.LastWriteTime.ToString(),
                                Size     = NextFile.Length.ToString(),
                                FullPath = NextFile.DirectoryName
                            };

                            list.Add(temp);
                        }
                    }

                    FileList = list;
                }
            }, () => { return(true); });

            OutputFolderCommand = new Command(() =>
            {
                FolderBrowserDialog openFileDialog = new FolderBrowserDialog();  //选择文件夹

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    OutputFolderPath = openFileDialog.SelectedPath;
                }
            }, () => { return(true); });

            OpenInputFolderCommand = new Command(() =>
            {
                ShellExecute(IntPtr.Zero, "open", InputFolderPath, "", "", 4);
            }, () => { return(true); });

            OpenOutputFolderCommand = new Command(() =>
            {
                ShellExecute(IntPtr.Zero, "open", OutputFolderPath, "", "", 4);
            }, () => { return(true); });

            GenerateCommand = new Command(() =>
            {
                ProgressWindow progressWindow = new ProgressWindow(SelectedLanguage, SelectedFont, SelectedFontSize.ToString(), SelectedTheme, OutputFolderPath, FileList);
                progressWindow.Show();
            }, () => { return(true); });

            SelectThemeCommand = new Command(() =>
            {
                ThemeImage = "/Themes/" + SelectedLanguage + "_" + SelectedTheme + ".PNG";
            }, () => { return(true); });
        }
Beispiel #2
0
 public void RBTextChanged(object o)
 {
     ((RichTextBox)o).Selection.ApplyPropertyValue(TextElement.FontSizeProperty, SelectedFontSize.ToString());
     ((RichTextBox)o).Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, SelectedFontFamily);
     if (IsBolded)
     {
         ((RichTextBox)o).Selection.ApplyPropertyValue(Inline.FontWeightProperty, FontWeights.Bold);
     }
     else
     {
         ((RichTextBox)o).Selection.ApplyPropertyValue(Inline.FontWeightProperty, FontWeights.Normal);
     }
     if (IsItalic)
     {
         ((RichTextBox)o).Selection.ApplyPropertyValue(Inline.FontStyleProperty, FontStyles.Italic);
     }
     else
     {
         ((RichTextBox)o).Selection.ApplyPropertyValue(Inline.FontStyleProperty, FontStyles.Normal);
     }
     if (IsUnderlined)
     {
         ((RichTextBox)o).Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, TextDecorations.Underline);
     }
     else
     {
         TextDecorationCollection textDecorations;
         (((RichTextBox)o).Selection.GetPropertyValue(Inline.TextDecorationsProperty) as TextDecorationCollection).TryRemove(TextDecorations.Underline, out textDecorations);
         ((RichTextBox)o).Selection.ApplyPropertyValue(Inline.TextDecorationsProperty, textDecorations);
     }
 }