Beispiel #1
0
        public static void output(cForm form, string outputfile)
        {
            Size         s = new Size();
            StreamWriter w = new StreamWriter(outputfile);

            //******************************************************************************
            // WPF has a different width - adjust our panel width
            //******************************************************************************
            s        = form.size;
            s.Width += 18;
            //******************************************************************************
            // Write the XAML header information plus window specifications
            //******************************************************************************
            w.WriteLine("<Window x:Class=\"" + form.sNameSpace + "." + form.name + "\"");
            w.WriteLine("\txmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"");
            w.WriteLine("\txmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\"");
            w.WriteLine("\tTitle=\"" + encodeText(form.text) + "\" Height=\"" + s.Height +
                        "\" Width=\"" + s.Width + "\">");
            //******************************************************************************
            // Create a Grid and add each control we found...
            //******************************************************************************
            w.WriteLine("\t<Grid>");
            foreach (cBase b in form.controls)
            {
                b.xaml(w, s);
            }
            w.WriteLine("\t</Grid>");
            //******************************************************************************
            // Close up and return
            //******************************************************************************
            w.WriteLine("</Window>");
            w.Close();
        }
Beispiel #2
0
 //**********************************************************************************
 // This method will walk through the base Form source file and convert it to
 // the XAML source file equivalent.
 //**********************************************************************************
     public static void convertFormFile(cForm form, FileInfo source_project,
                                                    FileInfo destination_project)
     {
         string src = source_project.DirectoryName + "\\" + form.definition_file;
         string dst = destination_project.DirectoryName + "\\" + 
                      Project.formFile(form.definition_file, ".xaml.cs");
     //******************************************************************************
         StreamReader r        = new StreamReader(src);
         StreamWriter w        = new StreamWriter(dst);
         bool         found_ns = false;
     //******************************************************************************
     // Walk through source file
     //******************************************************************************
         while (r.EndOfStream == false)
         {
             string line = r.ReadLine();
         //**************************************************************************
         // Look for MessageBox from Windows.Forms
         //**************************************************************************
             if (line.Contains(" MessageBox.Show("))
             {
             //**********************************************************************
             // Add System.Windows.Forms prefix.
             //**********************************************************************
                 line = line.Replace(" MessageBox.Show(", " System.Windows.Forms.MessageBox.Show(");
                 w.WriteLine(line);
             }
         //**************************************************************************
         // Look for DialogResult from Windows.Forms
         //**************************************************************************
             else if (line.Contains(" DialogResult."))
             {
             //**********************************************************************
             // Add System.Windows.Forms prefix.
             //**********************************************************************
                 line = line.Replace(" DialogResult.", " System.Windows.Forms.DialogResult.");
                 w.WriteLine(line);
             }
         //**************************************************************************
         // Look for namespace declaration
         //**************************************************************************
             else if (line.Contains("namespace " + form.sNameSpace) && 
                      found_ns == false)
             {
             //**********************************************************************
             // Add WPF references...
             //**********************************************************************
                 w.WriteLine("using System.Windows;");
                 w.WriteLine("using System.Windows.Controls;");
                 w.WriteLine("using System.Windows.Data;");
                 w.WriteLine("using System.Windows.Documents;");
                 w.WriteLine("using System.Windows.Input;");
                 w.WriteLine("using System.Windows.Media;");
                 w.WriteLine("using System.Windows.Media.Imaging;");
                 w.WriteLine("using System.Windows.Navigation;");
                 w.WriteLine("using System.Windows.Shapes;");
             //**********************************************************************
             // Write namespace declaration out also...
             //**********************************************************************
                 w.WriteLine();
                 w.WriteLine(line);
                 found_ns = true;
             }
         //**************************************************************************
         // Look for class definition
         //**************************************************************************
             else if (line.Contains("partial class " + form.name))
             {
                 int len = line.IndexOf(':');
             //**********************************************************************
             // Change "Form" parent class to "Window" parent class
             //**********************************************************************
                 line = line.Substring(0, len);
                 line += ": Window";
             //**********************************************************************
             // Write out line...
             //**********************************************************************
                 w.WriteLine(line);
             }
         //**************************************************************************
         // Just write out line...
         //**************************************************************************
             else 
             {
                 string nl = form.convert(line);
                 w.WriteLine(nl);
             }
         }
     //******************************************************************************
         r.Close();
         w.Close();
     }
Beispiel #3
0
        //**********************************************************************************
        private void createForm(cForm form)
        {
            string sText;
            string fn = source_project.DirectoryName + "\\" +
                        form.designer_file;
            StreamReader  file        = new System.IO.StreamReader(fn);
            StringBuilder source_text = new StringBuilder();
            string        filename    = form.definition_file;

            //******************************************************************************
            // Walk through the designer file looking for known controls
            //******************************************************************************
            while (file.EndOfStream == false)
            {
                string line = file.ReadLine();
                if (line == null)
                {
                    break;
                }
                source_text.Append(line);
                if (cButton.findControl(line))              // Button Control
                {
                    cButton b = new cButton(line, filename);
                    form.controls.Add(b);
                }
                else if (cLabel.findControl(line))          // Label Control
                {
                    cLabel b = new cLabel(line, filename);
                    form.controls.Add(b);
                }
                else if (cListBox.findControl(line))        // ListBox Control
                {
                    cListBox b = new cListBox(line, filename);
                    form.controls.Add(b);
                }
                else if (cTextBox.findControl(line))        // TextBox Control
                {
                    cTextBox b = new cTextBox(line, filename);
                    form.controls.Add(b);
                }
                else if (cComboBox.findControl(line))       // ComboBox Control
                {
                    cComboBox b = new cComboBox(line, filename);
                    form.controls.Add(b);
                }
                else if (cCheckbox.findControl(line))       // CheckBox Control
                {
                    cCheckbox b = new cCheckbox(line, filename);
                    form.controls.Add(b);
                }
                else if (cRichTextBox.findControl(line))    // RichTextBox Control
                {
                    cRichTextBox b = new cRichTextBox(line, filename);
                    form.controls.Add(b);
                }
                else if (cDataGridView.findControl(line))   // DataGridView Control
                {
                    cDataGridView b = new cDataGridView(line, filename);
                    form.controls.Add(b);
                }
            }
            //******************************************************************************
            file.Close();
            //******************************************************************************
            // Create a string of the source code file
            //   This is so we don't have to read the file again while parsing settings.
            //******************************************************************************
            sText = source_text.ToString();
            form.Settings(sText);
            //******************************************************************************
            // Parse the control settings
            //******************************************************************************
            foreach (cBase b in form.controls)
            {
                b.Settings(sText);
            }
        }
Beispiel #4
0
 //**********************************************************************************
 private void copyProjectfiles(Project p)
 {
     //******************************************************************************
     // Make sure there are forms in this project
     //******************************************************************************
     if (p.forms.Count == 0)
     {
         //#TODO - return error
     }
     else
     {
         //****************************************************************************
         // Select first form as the default window.
         //   Improvement - ask user which form or try to determine it.
         //****************************************************************************
         if (p.forms.Count > 0)
         {
             cForm f = (cForm)p.forms[0];
             p.default_form = Project.formFile(f.definition_file, ".xaml");
         }
     }
     //******************************************************************************
     // Walk project files and output to new project file...
     //******************************************************************************
     foreach (string f in p.files)
     {
         //**************************************************************************
         // skip form files
         //**************************************************************************
         if (p.isForm(f))
         {
             continue;
         }
         //**************************************************************************
         // skip only form-based designer files
         //**************************************************************************
         if (f.Contains(".Designer.cs") &&
             f.Contains("Properties\\") == false)
         {
             continue;
         }
         //**************************************************************************
         string   sfn = source_project.DirectoryName + "//" + f;
         string   dfn = destination_project.DirectoryName + "//" + f;
         FileInfo sfi = new FileInfo(sfn);
         FileInfo dfi = new FileInfo(dfn);
         //**************************************************************************
         // Copy this file to destination - also make sure the directory exists.
         //**************************************************************************
         if (dfi.Directory.Exists == false)
         {
             dfi.Directory.Create();
         }
         sfi.CopyTo(dfi.FullName, true);
     }
     //******************************************************************************
     // Create new XAML application files based on our default files
     //******************************************************************************
     change_default_ns(p, ".\\App.xaml.cs.txt",
                       destination_project.DirectoryName + "\\App.xaml.cs");
     change_default_ns(p, ".\\App.xaml.txt",
                       destination_project.DirectoryName + "\\App.xaml");
 }
Beispiel #5
0
        //**********************************************************************************
        private bool analyzeProject(Project project)
        {
            bool      project_error  = false;
            ArrayList designer_files = new ArrayList();

            //******************************************************************************
            // Search through children nodes...
            //******************************************************************************
            foreach (cfgNode c in project.children)
            {
                if (project_error)
                {
                    break;                              // stop parsing
                }
                if (c.name != "ItemGroup")
                {
                    continue;
                }
                //**************************************************************************
                // Found "ItemGroup" node
                //**************************************************************************
                foreach (cfgNode item in c.children)
                {
                    //**********************************************************************
                    // Look for source files and WPF indicators...
                    //**********************************************************************
                    switch (item.name)
                    {
                    //******************************************************************
                    // #TODO - need to determine files in a project to copy.
                    //******************************************************************
                    case "None":
                    case "Content":
                    case "EmbeddedResource":
                        //**************************************************************
                        // Find the source file name...
                        //**************************************************************
                        foreach (attribute a in item.attributes)
                        {
                            if (a.name == "Include")
                            {
                                project.files.Add(a.value);
                            }
                        }
                        break;

                    //******************************************************************
                    // Compile statements refer to source files...
                    //******************************************************************
                    case "Compile":
                        string filename = String.Empty;
                        //**************************************************************
                        // Find the source file name...
                        //**************************************************************
                        foreach (attribute a in item.attributes)
                        {
                            if (a.name == "Include")
                            {
                                filename = a.value;
                                //******************************************************
                                // Add project file...
                                //******************************************************
                                if (project.addSourceFile(filename) == false)
                                {
                                    project_error = true;
                                    break;
                                }
                                //******************************************************
                                // Is it a designer file?
                                //******************************************************
                                if (a.value.Contains(".Designer.") &&
                                    a.value.Contains("\\") == false)        // skip subdirectories
                                {
                                    designer_files.Add(a.value);
                                }
                            }
                        }
                        //**************************************************************
                        // Determine if this a "Form" source file
                        //   - Node contains a "SubType" element of "Form"
                        //**************************************************************
                        foreach (cfgNode s in item.children)
                        {
                            if (s.name == "SubType")
                            {
                                if (s.text == "Form")
                                {
                                    cForm form = new cForm();
                                    form.definition_file = filename;
                                    project.forms.Add(form);
                                }
                            }
                        }
                        break;

                    //******************************************************************
                    // Check if WPF components already in Project file...
                    //******************************************************************
                    case "Page":
                    case "ApplicationDefinition":
                        project.status = "Contains WPF project - cannot convert";
                        project_error  = true;
                        break;
                    }
                }
            }
            //******************************************************************************
            // Try to match designer files with Forms...
            //******************************************************************************
            foreach (cForm f in project.forms)
            {
                string df = Project.formFile(f.definition_file, ".Designer.cs");
                foreach (string s in designer_files)
                {
                    if (df == s)
                    {
                        f.designer_file = s;
                        break;
                    }
                }
            }
            //******************************************************************************
            // Return WPF project status
            //******************************************************************************
            return(project_error);
        }