private void btnOpen_Click(object sender, EventArgs e) { // Treat all files to be opened. We'll have to do the same // as when initial loading with a list of filenames. FileSelector fs = (FileSelector)lstProjects.SelectedItem; if (fs == null) { return; } string file = fs.CompletePath; TemplateCache.Instance().Clear(true); try { TemplateMain.Instance().InitializeApplication(new string[] { file }); Close(); } catch (ApplicationException aex) { OptionsSettings.Instance().UnRegisterLastUsedProject(file); lstProjects.Items.Remove(fs); MessageBox.Show(aex.Message, "Open project error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Browse for the project /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnProject_Click(object sender, EventArgs e) { openFileDialog.Multiselect = false; openFileDialog.CheckFileExists = true; openFileDialog.Title = "Select NextGen project to open"; openFileDialog.Filter = "NextGen projects (*.xmp)|*.xmp"; openFileDialog.RestoreDirectory = false; if (openFileDialog.ShowDialog(this) != DialogResult.OK) { return; } // Treat all files to be opened. We'll have to do the same // as when initial loading with a list of filenames. string file = openFileDialog.FileName; string[] files = new string[] { file }; TemplateCache.Instance().Clear(true); try { TemplateMain.Instance().InitializeApplication(files); Close(); } catch (ApplicationException aex) { OptionsSettings.Instance().UnRegisterLastUsedProject(file); MessageBox.Show(aex.Message, "Open project error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Voeg de appliesto class to als een variabele in de lijst. /// </summary> private void AddAppliesToVar() { XmlNode appliestonode = m_currenttype.SelectSingleNode("appliesto"); Debug.Assert(appliestonode != null, "Appliestonode kon niet gevonden worden"); String appliesto = appliestonode.InnerText; XmlNode t = TemplateCache.Instance().GetValueFor("TypeDefs", appliesto); AddConceptPartsToVar(t, -1, appliesto); }
private void btnDefinition_Click(object sender, EventArgs e) { FileSelector fs = (FileSelector)lstProjects.SelectedItem; if (fs == null) { return; } string file = fs.CompletePath; // Laad het project bestand. // Zoek de solution op die erbij hoort // Pluis uit waar de solution gedefinieerd is // En open dat project XmlDocument d = new XmlDocument(); try { d.Load(file); string solution_file = ""; string solution = d.SelectSingleNode("project/solution").InnerText; XmlNode location = d.SelectSingleNode("project/solutionfilename"); if (location != null) { solution_file = location.InnerText; } else { solution_file = solution; } solution_file = Generator.Utility.TemplateUtil.Instance().CombineAndCompact(file, solution_file); d.Load(solution_file); XmlNode sourceproject = d.SelectSingleNode("solution/sourceproject"); if (sourceproject == null) { throw new ApplicationException("Could not find sourceproject for solution '" + solution + "'"); } file = sourceproject.InnerText; file = Generator.Utility.TemplateUtil.Instance().CombineAndCompact(solution_file, file); TemplateCache.Instance().Clear(true); TemplateMain.Instance().InitializeApplication(new string[] { file }); Close(); } catch (ApplicationException aex) { MessageBox.Show(aex.Message, "Open definition project error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected bool IsClassnameKnown(string name) { if (name == "Decimal" || name == "String" || name == "Boolean") { return(true); } if (Array.IndexOf(TemplateCache.Instance().GetTypenamesList("TypeDefs"), name) >= 0) { return(true); } return(false); }
/// <summary> /// Constructor voor library files. Zonder type. /// </summary> /// <param name="name"></param> public TemplateFileEditorV2(string name) { InitializeComponent(); m_libraryeditor = true; m_currenttype = null; m_type_definition = null; m_filename = name; m_displayedtype = "Library"; Text = "Library: " + name; txtText.Lines = new String[0]; m_templatefilename = TemplateCache.Instance().SolutionLocation + "\\TemplateFile\\" + name; FinishLoading(); }
public TemplateFileEditorV2(string name, string type) { InitializeComponent(); m_libraryeditor = false; m_currenttype = TemplateCache.Instance().GetValueFor(type, name).CloneNode(true); m_type_definition = TemplateCache.Instance().GetTemplateType(type); m_filename = m_currenttype.Attributes["sourcefile"].Value; m_displayedtype = type; Text = "Templatefile: " + name; txtText.Lines = new String[0]; XmlNode templatefilenamenode = m_currenttype.SelectSingleNode("templatefilename"); if (templatefilenamenode != null) { string f = templatefilenamenode.InnerText; m_templatefilename = Path.Combine(Path.GetDirectoryName(m_filename), f); } FinishLoading(); }
private void btnTemplates_Click(object sender, EventArgs e) { FileSelector fs = (FileSelector)lstProjects.SelectedItem; string file = fs.CompletePath; // Laad het project bestand. // Zoek de solution op die erbij hoort // Instrueer de cache dat we een project hebben dat een solution 'na doet' // Zodat als er wat gevraagd wordt, (lijst met types e.d.) dit juist // geinterpreteerd wordt. TemplateCache.Instance().Clear(true); try { TemplateCache.Instance().LoadProjectFile(file, true); TemplateMain.Instance().InitializeApplication(null); Close(); } catch (ApplicationException aex) { OptionsSettings.Instance().UnRegisterLastUsedProject(file); lstProjects.Items.Remove(fs); MessageBox.Show(aex.Message, "Open template project error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Inspect the template to process and construct the input and output file /// names from it. Together with the info from the datatype to process. /// </summary> private void ConstructInputOutputFilenames() { string templatefilename = GetXmlValue(m_templateDefinition.SelectSingleNode("templatefilename"), ""); if (templatefilename == "") { throw new ApplicationException("templatefilename is mandatory in template definitions file"); } string directory_expression = ""; // We maken een LineProcessor voor het interpreteren van de tekst van de directory en filenaam. LineProcessor lp = new LineProcessor(m_current, new Hashtable(), new Hashtable(), new StringCollection(), new StringCollection(), m_log, m_KeepInfo, m_FunctionInfo, GetCurrentTemplatename(), null); lp.AddObserver(this); try { directory_expression = m_templateDefinition.SelectSingleNode("directory").InnerText; if (directory_expression.Contains("@")) { m_outputfilename = lp.ProcessLine(directory_expression); } else { m_outputfilename = directory_expression; } } catch (Exception ex) { throw new ApplicationException("Directory expression '" + directory_expression + "' results in error: " + ex.Message); } if (m_outputfilename == "") { throw new ApplicationException("Directory expression '" + directory_expression + "' results in empty directoryname for template: " + m_templateDefinition.SelectSingleNode("name").InnerText); } if (!m_outputfilename.EndsWith(@"\")) { m_outputfilename += @"\"; } string filename_expression = m_templateDefinition.SelectSingleNode("filename").InnerText; string filename = ""; try { filename = lp.ProcessLine(filename_expression); } catch (Exception ex) { throw new ApplicationException("Filename expression '" + filename_expression + "' results in error: " + ex.Message); } if (filename == "") { throw new ApplicationException("Filename expression '" + filename_expression + "' results in empty filename for template: " + m_templateDefinition.SelectSingleNode("name").InnerText); } m_outputfilename += filename; m_inputfilename = TemplateCache.Instance().SolutionLocation + @"\TemplateFile\" + m_templateDefinition.SelectSingleNode("templatefilename").InnerText; }
private void btnNew_Click(object sender, EventArgs e) { FileSelector fs = (FileSelector)lstSolutions.SelectedItem; if (fs == null) { return; } string file = fs.CompletePath; TemplateCache.Instance().Clear(true); try { TemplateCache.Instance().LoadSolutionFile(file, false); } catch (ApplicationException aex) { OptionsSettings.Instance().UnRegisterLastUsedSolution(file); lstSolutions.Items.Remove(fs); MessageBox.Show(aex.Message, "Load solution error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } openFileDialog.Multiselect = false; openFileDialog.CheckFileExists = false; openFileDialog.Title = "Create projectfile"; openFileDialog.DefaultExt = ".xmp"; openFileDialog.Filter = "NextGen projects (*.xmp)|*.xmp"; openFileDialog.RestoreDirectory = false; openFileDialog.FileName = ""; if (openFileDialog.ShowDialog(this) != DialogResult.OK) { return; } // Treat all files to be opened. We'll have to do the same // as when initial loading with a list of filenames. file = openFileDialog.FileName; XmlDocument d = new XmlDocument(); d.AppendChild(d.CreateElement("project")); XmlElement elm = d.CreateElement("solution"); elm.AppendChild(d.CreateTextNode(TemplateCache.Instance().Solution)); d.DocumentElement.AppendChild(elm); elm = d.CreateElement("solutionfilename"); elm.AppendChild(d.CreateTextNode(TemplateCache.Instance().SolutionFilename)); d.DocumentElement.AppendChild(elm); d.Save(file); string[] args = new string[] { file }; try { TemplateMain.Instance().InitializeApplication(args); Close(); } catch (ApplicationException aex) { OptionsSettings.Instance().UnRegisterLastUsedProject(file); MessageBox.Show(aex.Message, "New project error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Create a panel with the contents filled from the given Value XmlNode /// The name of the panel is the sequence-number of the panel /// (derived from the number of panels current in this form). /// The name will be fixed and will never change. /// </summary> /// <param name="Value"></param> /// <returns></returns> private Panel FillOne(XmlNode Value) { // Keep 2 pixels on the left free, and keep track of the maximum // height of all controls on the panel, to be able to size the panel // right. int left = 2; int maxheight = 0; // Create the panel and give it its name. Panel pnlAttr = new Panel(); pnlAttr.Name = m_panelrowcount.ToString(); pnlAttr.TabIndex = m_panelrowcount; // Top will be calculated on basis of ordering and current position // of the scroll bar. Initially is it the currenttop pnlAttr.Top = m_currenttop; pnlAttr.Left = 0; // Width can increase when more space is needed, depending on the // number of elements defined per item. pnlAttr.Width = 100; // On entering, eventually attributesets initialisation, // and on leaving storing the results in the value. pnlAttr.Enter += new System.EventHandler(this.pnlAttr_Enter); pnlAttr.Leave += new System.EventHandler(this.pnlAttr_Leave); pnlAttr.MouseDown += new System.Windows.Forms.MouseEventHandler(this.pnlAttr_MouseDown); pnlAttr.DragEnter += new System.Windows.Forms.DragEventHandler(this.pnlAttr_DragEnter); pnlAttr.DragLeave += new System.EventHandler(this.pnlAttr_DragLeave); pnlAttr.DragDrop += new System.Windows.Forms.DragEventHandler(this.pnlAttr_DragDrop); pnlAttr.AllowDrop = true; //pnlAttr.BorderStyle = BorderStyle.FixedSingle; // Store the value we're displaying on this panel on the x-th element // in the m_Value list. m_Value.Add(Value); int defindex = 0; foreach (XmlNode element in m_definitions.SelectNodes("element")) { XmlAttribute name = element.Attributes["name"]; XmlAttribute lines = element.Attributes["lines"]; XmlAttribute size = element.Attributes["size"]; XmlAttribute length = element.Attributes["length"]; XmlAttribute type = element.Attributes["type"]; XmlAttribute def_val = element.Attributes["default"]; if (name == null) // || name.InnerText == "name") { continue; } Control c = null; // Get the current string value, if available. string stringValue = ""; XmlNode valueNode = Value.SelectSingleNode(name.Value); if (valueNode != null) { stringValue = valueNode.InnerText; } else if (def_val != null) { stringValue = def_val.InnerText; } if ((type == null) || (type.Value == "Name") || (type.Value == "Number") || (type.Value == "LoopField") || (type.Value == "Text")) { TextBox t = new TextBox(); c = t; int nLines = 0; if (lines != null) { nLines = Int32.Parse(lines.Value); } else { nLines = 1; } t.Multiline = (nLines != 1); t.AcceptsReturn = t.Multiline; t.Height = nLines * 13 + 8; if (length != null) { t.MaxLength = Int32.Parse(length.Value); } t.Text = stringValue; if (type != null && type.Value == "Name") { m_NameControls.Add(t); t.TextChanged += new System.EventHandler(this.txtName_TextLeave); } if (type != null && type.Value == "LoopField") { ArrayList ttparts = new ArrayList(); foreach (XmlNode e in element.SelectNodes("element")) { ttparts.Add(e.Attributes["name"].Value); } string ttt; if (ttparts.Count > 1) { char partsep = TemplateGenerator.DEFAULT_PART_SEPERATOR; if (element.Attributes["partsep"] != null) { partsep = element.Attributes["partsep"].Value[0]; } String[] ttstrings = (ttparts.ToArray(typeof(String)) as String[]); ttt = String.Join(partsep.ToString(), ttstrings); } else if (ttparts.Count > 0) { ttt = ttparts[0].ToString(); } else { ttt = ""; } char fieldsep = TemplateGenerator.DEFAULT_FIELD_SEPERATOR; if (element.Attributes["fieldsep"] != null) { fieldsep = element.Attributes["fieldsep"].Value[0]; } ttt = ttt + fieldsep.ToString() + ttt; m_tt.SetToolTip(t, ttt); } t.TextChanged += new EventHandler(m_owner.Mark_Dirty); } else if (type.Value == "Order") { NumericUpDown t = new NumericUpDown(); t.Maximum = 999; c = t; t.TextAlign = HorizontalAlignment.Right; if (Value.ChildNodes.Count == 0) { // Find largest order value in all ordering controls Decimal maxOrder = 0; foreach (NumericUpDown n in m_OrderControls) { if (n.Value > maxOrder) { maxOrder = n.Value; } } t.Text = (maxOrder + 1).ToString(); } else { t.Text = stringValue; } t.Leave += new System.EventHandler(this.txtOrder_Leave); t.ValueChanged += new EventHandler(m_owner.Mark_Dirty); m_OrderControls.Add(c); } else if (type.Value == "Checkbox") { CheckBox t = new CheckBox(); t.ThreeState = false; t.Checked = (stringValue == "1"); t.Height -= 4; c = t; t.CheckedChanged += new EventHandler(m_owner.Mark_Dirty); } else if (type.Value == "Combobox") { // Get the values in the list from the child element // and put these in the combo ComboBox t = new ComboBox(); t.DropDownStyle = ComboBoxStyle.DropDownList; t.Items.Add(""); foreach (XmlNode x in element.SelectNodes("element")) { t.Items.Add(x.Attributes["name"].InnerText); } t.Text = stringValue; c = t; t.SelectedValueChanged += new EventHandler(m_owner.Mark_Dirty); } else if (type.Value == "Table") { // Get the values in the list from the cache with all tablenames // and put these in the combo ComboBox t = new ComboBox(); t.DropDownStyle = ComboBoxStyle.DropDownList; t.Sorted = true; t.Items.Add(""); t.Items.AddRange(TemplateCache.Instance().GetTypenamesList("TableDefinition")); t.Text = stringValue; c = t; t.SelectedValueChanged += new EventHandler(m_owner.Mark_Dirty); } else if (type.Value == "AttributeCombobox") { // Get the values in the list from all attribute panels // and put these in the combo. Select the right one // according to the id of the attribute. ComboBox t = new ComboBox(); t.Sorted = true; t.DropDownStyle = ComboBoxStyle.DropDownList; t.Items.Add(""); XmlAttribute id = Value.Attributes["refid"]; if (id == null) { id = Value.OwnerDocument.CreateAttribute("refid"); Value.Attributes.Append(id); } //t.Items.Add(""); foreach (Control tb in m_attributespanel.NameControls) { if (tb.Text.Trim() == "") { continue; } t.Items.Add(tb.Text); // If no id connected yet, set it when value conforms if (id.Value == tb.Parent.Name) { stringValue = tb.Text; } else if (id.Value == "" && stringValue == tb.Text) { id.Value = tb.Parent.Name; } } t.Text = stringValue; c = t; if (m_attributespanel != this) { m_NameControls.Add(t); t.SelectedIndexChanged += new System.EventHandler(this.txtName_TextLeave); t.Leave += new System.EventHandler(this.txtName_UpdateTextId); } t.SelectedValueChanged += new EventHandler(m_owner.Mark_Dirty); } else if (type.Value == "AttributeSet") { // Keep in attributesets[i] an element // where the attributes in the specific set // are kept. Keep in that element not the names of the // attributes but the number of the panel (the immutable id for // this session) to avoid renaming over and over again. XmlNode x = null; if (Value != null) { x = Value.SelectSingleNode(name.Value); } if (x == null) { x = Value.OwnerDocument.CreateElement(name.Value); Value.AppendChild(x); } c = null; } else { // It must almost be a combobox with references to other types. // Find the right directory ComboBox t = new ComboBox(); t.DropDownStyle = ComboBoxStyle.DropDownList; t.Sorted = true; t.Items.Add(""); t.Items.AddRange(TemplateCache.Instance().GetTypenamesList(type.Value)); t.Text = stringValue; TemplateMain.Instance().CreateLinkContextMenu(t, type.Value); c = t; t.SelectedValueChanged += new EventHandler(m_owner.Mark_Dirty); } if (defindex >= m_AttributeControls.Count) { m_AttributeControls.Add(new ArrayList()); } if (c != null) { if (m_LabelControls.Count > defindex) { Label label = m_LabelControls[defindex] as Label; if (label != null) { left = label.Left; } } c.Name = name.Value; c.Top = 2; c.Left = left; int sizeval = 10; if (size != null) { sizeval = int.Parse(size.Value); } else if (length != null) { sizeval = int.Parse(length.Value); } c.Width = sizeval * 8 + 4; pnlAttr.Controls.Add(c); ArrayList al = m_AttributeControls[defindex] as ArrayList; al.Add(c); if (al.Count > m_definitions_fixed && m_HScroll != null && al.Count - m_definitions_fixed <= m_HScroll.Value) { c.Visible = false; } else { left += 4 + c.Width; } if (c.Top + c.Height > maxheight) { maxheight = c.Top + c.Height; } } // Make sure it is wide enough if (pnlAttr.Width < left) { pnlAttr.Width = left + 2; } // increase index of processed attribute definition defindex++; } pnlAttr.Height = maxheight + 2; pnlAttr.Top = m_currenttop; // - (maxheight + 2) * (m_VScroll.Value); // Empty <attributes/> element does not count too, so test for > 1 SetPanelVisible(pnlAttr, (Value.ChildNodes.Count > 1)); m_panel.Controls.Add(pnlAttr); m_currenttop += pnlAttr.Height; return(pnlAttr); }