示例#1
0
        public int SaveProject(winForms.RichTextBox htmlTextBox, winForms.RichTextBox csstextBox)
        {
            int check = 0;

            if (save == false)
            {
                Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();

                sfd.DefaultExt = ".html";
                sfd.Filter     = "HTML File (.html)|*.html";
                if (sfd.ShowDialog() == true && sfd.FileName.Length > 0)
                {
                    File.WriteAllText(sfd.FileName, htmlTextBox.Text);
                    savepath = sfd.FileName.ToString();
                    save     = true;
                    check    = 1;

                    //Saving auto main.css
                    int    temp       = sfd.FileName.ToString().LastIndexOf("\\");
                    String cssdestDir = sfd.FileName.Substring(0, temp) + "\\main.css";



                    //creating main.css
                    var cssFile = File.Create(cssdestDir);
                    cssFile.Close();
                    File.WriteAllText(cssdestDir, csstextBox.Text);
                    csssavepath = cssdestDir;
                    //winForms.MessageBox.Show(csssavepath);
                    save = true;



                    //moving images videos and bootstrap stuff
                    String destDir = sfd.FileName.Substring(0, temp) + "\\media";

                    /*if (!Directory.Exists(destDir))
                     *  {
                     *  Directory.CreateDirectory(destDir);
                     * }
                     */



                    string srcDir = winForms.Application.StartupPath + @"\dnd\media";



                    DirectoryCopy(srcDir, destDir, true);



                    //Deleting Eveything from the directory
                    System.IO.DirectoryInfo di = new DirectoryInfo(srcDir + "\\images");



                    foreach (FileInfo file in di.GetFiles())
                    {
                        file.Delete();
                    }



                    di = new DirectoryInfo(srcDir + "\\videos");



                    foreach (FileInfo file in di.GetFiles())
                    {
                        file.Delete();
                    }



                    //moving bootstrap related files
                    String bootstrapDest = sfd.FileName.Substring(0, temp) + "\\bootstrap";
                    string bootstrapSrc  = winForms.Application.StartupPath + @"\dnd\bootstrap";
                    DirectoryCopy(bootstrapSrc, bootstrapDest, true);
                }



                //sfd.DefaultExt = ".css";
                //sfd.Filter = "CSS File (.css)|*.css";
                //sfd.FileName = "";

                //if (sfd.ShowDialog() == true && sfd.FileName.Length > 0)
                //{
                //    File.WriteAllText(sfd.FileName, csstextBox.Text);
                //    csssavepath = sfd.FileName.ToString();
                //    save = true;

                //    int temp = sfd.FileName.ToString().LastIndexOf("\\");
                //    String destDir = sfd.FileName.Substring(0, temp) + "\\media";
                //    /*if (!Directory.Exists(destDir))
                //    {
                //        Directory.CreateDirectory(destDir);
                //    }*/
                //    //winForms.MessageBox.Show(destDir);

                //    string srcDir = winForms.Application.StartupPath + @"\dnd\media";

                //    DirectoryCopy(srcDir, destDir, true);

                //    //Deleting Eveything from the directory
                //    System.IO.DirectoryInfo di = new DirectoryInfo(srcDir + "\\images");

                //    foreach (FileInfo file in di.GetFiles())
                //    {
                //        file.Delete();
                //    }

                //    di = new DirectoryInfo(srcDir + "\\videos");

                //    foreach (FileInfo file in di.GetFiles())
                //    {
                //        file.Delete();
                //    }
                //}


                ///*string newpath = savepath.LastIndexOf("/");
                //Console.WriteLine(savepath + "\n" + newpath);
                ////copying media folder to dest file
                ////CloneDirectory(winForms.Application.StartupPath + @"\dnd\media\", sfd.Get);*/

                ////trying to find if there are images and moving them\
                ///
            }
            else
            {
                if (savepath != "")
                {
                    File.WriteAllText(savepath, htmlTextBox.Text);
                    check = 2;
                }
                if (csssavepath != "")
                {
                    File.WriteAllText(csssavepath, csstextBox.Text);



                    int temp = savepath.ToString().LastIndexOf("\\");



                    //moving images videos and bootstrap stuff
                    String destDir = savepath.Substring(0, temp) + "\\media";

                    /*if (!Directory.Exists(destDir))
                     *  {
                     *  Directory.CreateDirectory(destDir);
                     * }
                     */



                    string srcDir = winForms.Application.StartupPath + @"\dnd\media";



                    DirectoryCopy(srcDir, destDir, true);



                    //Deleting Eveything from the directory
                    System.IO.DirectoryInfo di = new DirectoryInfo(srcDir + "\\images");



                    foreach (FileInfo file in di.GetFiles())
                    {
                        file.Delete();
                    }



                    di = new DirectoryInfo(srcDir + "\\videos");



                    foreach (FileInfo file in di.GetFiles())
                    {
                        file.Delete();
                    }



                    //moving bootstrap related files
                    String bootstrapDest = savepath.Substring(0, temp) + "\\bootstrap";
                    string bootstrapSrc  = winForms.Application.StartupPath + @"\dnd\bootstrap";
                    DirectoryCopy(bootstrapSrc, bootstrapDest, true);
                }
            }

            //validation
            //stop single line grammercheck firing
            MainWindow.htmlfire = false;
            MainWindow.fire     = false;
            //creating objects to simulate validation
            htmltextBoxClass htb = new htmltextBoxClass();
            csstextBoxClass  ctb = new csstextBoxClass();


            //Overriding Paste Functionality
            //Showing busy work with mouse
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            try
            {
                htb.ValidateTags(htmlTextBox);
                ctb.clipboardGrammerCheck(csstextBox);
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
            MainWindow.htmlfire = true;
            MainWindow.fire     = true;

            return(check);
        }
示例#2
0
        public void OpenProject(winForms.RichTextBox htmlTextBox, winForms.RichTextBox csstextBox, MenuItem SaveProject, CefSharp.Wpf.ChromiumWebBrowser mwb)
        {
            if (SaveProject.IsEnabled == true)
            {
                MessageBoxResult msgBoxRes = MessageBox.Show("Do you want to save content or not?", "Save File", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (msgBoxRes == MessageBoxResult.Yes)
                {
                    Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog();
                    sfd.DefaultExt = ".html";
                    sfd.Filter     = "HTML File (.html)|*.html";
                    if (sfd.ShowDialog() == true && sfd.FileName.Length > 0)
                    {
                        File.WriteAllText(sfd.FileName, htmlTextBox.Text);
                        savepath = sfd.FileName.ToString();
                        save     = true;
                    }

                    //Open the respective css file
                    sfd.DefaultExt = ".css";
                    sfd.Filter     = "CSS File (.css)|*.css";
                    if (sfd.ShowDialog() == true && sfd.FileName.Length > 0)
                    {
                        File.WriteAllText(sfd.FileName, csstextBox.Text);
                        csssavepath = sfd.FileName.ToString();
                        save        = true;
                    }
                }
            }
            Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog();
            ofd.DefaultExt = ".html";
            ofd.Filter     = "HTML File (.html)|*.html|ALL Files (.)|*.*";
            if (ofd.ShowDialog() == true && ofd.CheckFileExists)
            {
                StreamReader sr1 = new StreamReader(ofd.FileName, Encoding.Default);
                htmlTextBox.Text = sr1.ReadToEnd();
                save             = true;
                savepath         = ofd.FileName.ToString();
            }

            ofd.Title      = "Open CSS file";
            ofd.DefaultExt = ".css";
            ofd.Filter     = "CSS File (.css)|*.css|ALL Files (.)|*.*";
            if (ofd.ShowDialog() == true && ofd.CheckFileExists)
            {
                StreamReader sr1 = new StreamReader(ofd.FileName, Encoding.Default);
                csstextBox.Text = sr1.ReadToEnd();
                save            = true;
                csssavepath     = ofd.FileName.ToString();
            }


            //validation
            //stop single line grammercheck firing
            MainWindow.htmlfire = false;
            MainWindow.fire     = false;
            //creating objects to simulate validation
            htmltextBoxClass htb = new htmltextBoxClass();
            csstextBoxClass  ctb = new csstextBoxClass();


            //Overriding Paste Functionality
            //Showing busy work with mouse
            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
            try
            {
                htb.ValidateTags(htmlTextBox);
                ctb.clipboardGrammerCheck(csstextBox);

                this.mw.Dispatcher.Invoke(() =>
                {
                    Regex singlelinepattern = new Regex(@"\s*?(\r\n|\n|\r)\s*");
                    String htmlH            = htmlTextBox.Text;
                    String singleLineString = singlelinepattern.Replace(htmlH, "");
                    //winForms.MessageBox.Show(singleLineString);
                    IFrame frame = mwb.GetMainFrame();
                    frame.ExecuteJavaScriptAsync(String.Format("testFunc(`{0}`)", htmlH));
                });
            }
            finally
            {
                Mouse.OverrideCursor = null;
            }
            MainWindow.htmlfire = true;
            MainWindow.fire     = true;


            SaveProject.IsEnabled = false;
            save = true;
        }