Пример #1
0
        public static void PreviewShow(ResourceManagerTreeNode fileInfo)
        {
            if (FilePreviewWindow.showWindows.ContainsKey(fileInfo.Path.FullName))
            {
                FilePreviewWindow.showWindows[fileInfo.Path.FullName].Activate();
                return;
            }
            Application.Current.MainWindow.Cursor = Cursors.Wait;
            if (!(fileInfo.Path.Extension.Equals(".txt", StringComparison.OrdinalIgnoreCase)
                  ||  fileInfo.Path.Extension.Equals(".dat", StringComparison.OrdinalIgnoreCase)
                  || fileInfo.Path.Extension.Equals(".grd", StringComparison.OrdinalIgnoreCase)))
            {
                MessageWindow.Show(Application.Current.MainWindow,"只能预览txt/dat/grd文件!");
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
                return;
            }
            FilePreviewWindow fpw = new FilePreviewWindow(fileInfo.Path.FullName);
            fpw.Title = fileInfo.Path.Name;
            fpw.fileName.Text = fileInfo.Path.Name;
            fpw.fileName.ToolTip = fileInfo.Path.FullName;

                try
                {
                    using (var stream = new StreamReader(fileInfo.Path.FullName, Encoding.Default))
                    {
                        StringBuilder result = new StringBuilder(stream.ReadToEnd());
                        stream.Close();
                        fpw.Dispatcher.Invoke(
                            new Action(() =>
                            {
                                fpw.fileContent.AppendText(result.ToString());
                            }));
                    }
                }
                catch (Exception)
                {
                    fpw.Dispatcher.Invoke(
                            new Action(() =>
                            {
                                MessageWindow.Show(fpw, "读取文件失败!");
                                fpw.Close();
                            }));
                }
                fpw.Show();
                showWindows.Add(fileInfo.Path.FullName, fpw);
                Application.Current.MainWindow.Cursor = Cursors.Arrow;
        }
Пример #2
0
 public static void PreviewShow(ResourceManagerTreeNode grdFileInfo, int roundDecimals = 3, int colors = 90)
 {
     if (FilePreviewWindow.showWindows.ContainsKey(grdFileInfo.Path.FullName))
     {
         FilePreviewWindow.showWindows[grdFileInfo.Path.FullName].Activate();
         return;
     }
     GRDPreviewWindow gpw = new GRDPreviewWindow(grdFileInfo.Path.FullName);
     gpw.fileName.Text = grdFileInfo.Path.Name;
     SelectColorItem sci = (SelectColorItem)gpw.inputPath2.SelectedItem;
     gpw.colors = colors;
     gpw.Title = grdFileInfo.Path.Name;
     gpw.roundDecimals = roundDecimals;
     gpw.openSb.Completed += delegate
     {
         gpw.isOpen = true;
         gpw.inputPath2.SelectedIndex = -1;
         gpw.inputPath2.SelectedIndex = 0;
         gpw.round.SelectedIndex = 2;
     };
     gpw.Show();
     FilePreviewWindow.showWindows.Add(grdFileInfo.Path.FullName, gpw);
 }