예제 #1
0
            public static PromptGroup Parse(Object aParent, XmlElement anXmlElement)
            {
                if (!(aParent is Template))
                {
                    throw new IllegalParentException("Illegal type! Expected instance of type: Template");
                }

                Template tParent = aParent as Template;

                String tName       = getRequiredAttribute(anXmlElement, "name");
                String tRepeatable = getRequiredAttribute(anXmlElement, "repeatable");
                String tMaxRepeats = getOptionalAttribute(anXmlElement, "maxRepeats", "");

                PromptGroup tPromptGroup = new PromptGroup();

                tPromptGroup.Name = tName;
                tPromptGroup.SetRepeatableFromString(tRepeatable);
                tPromptGroup.SetMaxRepeatsFromString(tMaxRepeats);

                //Process prompts
                foreach (XmlNode tNode in anXmlElement.ChildNodes)
                {
                    if (tNode is XmlElement)
                    {
                        XmlElement     tElement = tNode as XmlElement;
                        AbstractPrompt tPrompt  = AbstractPrompt.Factory.Parse(tPromptGroup, tElement);
                        tPromptGroup.AddPrompt(tPrompt);
                    }
                }

                return(tPromptGroup);
            }
예제 #2
0
 private void mnuPromptGroup_MoveDown_Click(object sender, EventArgs e)
 {
     try {
         TreeNode  node   = leftTabs_DocumentTree.SelectedNode;
         Hashtable idPack = node.Tag as Hashtable;
         if ((string)idPack["Type"] == "prompt")
         {
             AbstractPrompt prompt = (AbstractPrompt)idPack["Data"];
             if (prompt.Parent.MoveDownPrompt(prompt))
             {
                 refreshTreeView();
             }
         }
         else if ((string)idPack["Type"] == "promptgroup")
         {
             PromptGroup promptGroup = (PromptGroup)idPack["Data"];
             if (promptGroup.Parent.MoveDownPromptGroup(promptGroup))
             {
                 refreshTreeView();
             }
         }
     } catch (Exception ex) {
         MessageBox.Show("Error moving down prompt group: " + ex.Message);
     }
 }
예제 #3
0
 public static void Prompt_Click(object data)
 {
     if (data is PromptText)
     {
         PromptText castedObject = data as PromptText;
         editor_pg.SelectedObject = castedObject;
     }
     else if (data is PromptMultiline)
     {
         PromptMultiline castedObject = data as PromptMultiline;
         editor_pg.SelectedObject = castedObject;
     }
     else if (data is PromptDate)
     {
         PromptDate castedObject = data as PromptDate;
         editor_pg.SelectedObject = castedObject;
     }
     else if (data is PromptCheckbox)
     {
         PromptCheckbox castedObject = data as PromptCheckbox;
         editor_pg.SelectedObject = castedObject;
     }
     else if (data is PromptUserDefined)
     {
         PromptUserDefined castedObject = data as PromptUserDefined;
         editor_pg.SelectedObject = castedObject;
     }
     else
     {
         AbstractPrompt castedObject = data as AbstractPrompt;
         editor_pg.SelectedObject = castedObject;
     }
 }
예제 #4
0
            private static AbstractPrompt producePrompt(PromptGroup aParent, XmlElement anXmlElement)
            {
                AbstractPrompt tPrompt      = null;
                String         tName        = null;
                String         tDescription = null;

                foreach (XmlNode tPromptNode in anXmlElement.ChildNodes)
                {
                    String tType = null;

                    if (tPromptNode.Name == "type")
                    {
                        tType = tPromptNode.InnerText;
                    }
                    else if (tPromptNode.Name == "name")
                    {
                        tName = tPromptNode.InnerText;
                    }
                    else if (tPromptNode.Name == "description")
                    {
                        tDescription = tPromptNode.InnerText;
                    }

                    if (tType == AbstractPrompt.FIELD_TEXT)
                    {
                        tPrompt = PromptText.Factory.Parse(aParent, anXmlElement);
                    }
                    else if (tType == AbstractPrompt.FIELD_MULTILINE)
                    {
                        tPrompt = PromptMultiline.Factory.Parse(anXmlElement);
                    }
                    else if (tType == AbstractPrompt.FIELD_NUMBER)
                    {
                        tPrompt = PromptNumber.Factory.Parse(anXmlElement);
                    }
                    else if (tType == AbstractPrompt.FIELD_DATE)
                    {
                        tPrompt = PromptDate.Factory.Parse(anXmlElement);
                    }
                    else if (tType == AbstractPrompt.FIELD_CHECKBOX)
                    {
                        tPrompt = PromptCheckbox.Factory.Parse(anXmlElement);
                    }
                    else if (tType == AbstractPrompt.FIELD_USERDEFINED)
                    {
                        tPrompt = PromptUserDefined.Factory.Parse(anXmlElement);
                    }
                }

                if (tPrompt != null)
                {
                    tPrompt.Name        = tName;
                    tPrompt.Description = tDescription;
                }

                return(tPrompt);
            }
예제 #5
0
        private void handleBeforePromptDelete(AbstractPrompt prompt)
        {
            if (String.IsNullOrEmpty(template.TemplateText))
            {
                return;
            }
            string oldVariableName = prompt.VariableName;

            template.TemplateText = template.TemplateText.Replace(oldVariableName, "");
            refreshTemplateText();
        }
예제 #6
0
        private void handlePromptRename(AbstractPrompt prompt, string newName)
        {
            string oldVariableName = prompt.VariableName;
            string newVariableName = prompt.GetVariableName(prompt.Parent, newName);

            template.TemplateText = template.TemplateText.Replace(oldVariableName, newVariableName);
            refreshTemplateText();
            Object tObject = leftTabs_Properties.SelectedObject;

            TreeViewClickHandler.Prompt_Click(tObject);
        }
예제 #7
0
        private void mnuPrompt_InsertVariable_Click(object sender, EventArgs e)
        {
            TreeNode node = leftTabs_DocumentTree.SelectedNode;

            try {
                Hashtable idPack = node.Tag as Hashtable;
                if ((string)idPack["Type"] == "prompt")
                {
                    AbstractPrompt prompt = (AbstractPrompt)idPack["Data"];
                    insertIntoTemplateEditor(this.topTabs_TemplateEditor.ActiveTextAreaControl.TextArea, this.topTabs_TemplateEditor.ActiveTextAreaControl.TextArea.Caret.Offset, prompt.VariableName);
                }
            } catch { }
        }
예제 #8
0
        private void mnuPrompt_CopyAs_Click(object sender, EventArgs e)
        {
            TreeNode node = leftTabs_DocumentTree.SelectedNode;

            try {
                Hashtable idPack = node.Tag as Hashtable;
                if ((string)idPack["Type"] == "prompt")
                {
                    AbstractPrompt prompt = (AbstractPrompt)idPack["Data"];
                    prompt.Parent.AddPrompt(prompt.Clone());
                    refreshTreeView();
                }
            } catch { }
        }
예제 #9
0
        private void produceAndAddPrompt(PromptGroup aPromptGroup, Type aType, AbstractPrompt aReferencePrompt)
        {
            AbstractPrompt newPrompt = AbstractPrompt.Factory.CreateInstance(aType);

            if (aReferencePrompt != null)
            {
                aPromptGroup.AddPromptAfter(newPrompt, aReferencePrompt);
            }
            else
            {
                aPromptGroup.AddPrompt(newPrompt);
            }
            refreshTreeView();
        }
예제 #10
0
 private void CreatePromptHandler(Type aType)
 {
     try {
         TreeNode  node   = leftTabs_DocumentTree.SelectedNode;
         Hashtable idPack = node.Tag as Hashtable;
         if ((string)idPack["Type"] == "prompt")
         {
             AbstractPrompt tPrompt      = (AbstractPrompt)idPack["Data"];
             PromptGroup    tPromptGroup = tPrompt.Parent;
             produceAndAddPrompt(tPromptGroup, aType, tPrompt);
         }
     } catch (Exception ex) {
         MessageBox.Show("Error creating prompt from Prompt menu: " + ex.Message);
     }
 }
예제 #11
0
 private void mnuPrompt_Delete_Click(object sender, EventArgs e)
 {
     try {
         TreeNode  node   = leftTabs_DocumentTree.SelectedNode;
         Hashtable idPack = node.Tag as Hashtable;
         if ((string)idPack["Type"] == "prompt")
         {
             AbstractPrompt prompt = (AbstractPrompt)idPack["Data"];
             prompt.Remove();
             refreshTreeView();
         }
     } catch (Exception ex) {
         MessageBox.Show("Error creating prompt: " + ex.Message);
     }
 }
예제 #12
0
        private void leftTabs_DocumentTree_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            // Point where the mouse is clicked.
            Point p = new Point(e.X, e.Y);

            // Get the node that the user has clicked.
            TreeNode node = leftTabs_DocumentTree.GetNodeAt(p);

            try {
                Hashtable idPack = node.Tag as Hashtable;
                if ((string)idPack["Type"] == "prompt")
                {
                    AbstractPrompt prompt = (AbstractPrompt)idPack["Data"];
                    insertIntoTemplateEditor(this.topTabs_TemplateEditor.ActiveTextAreaControl.TextArea, this.topTabs_TemplateEditor.ActiveTextAreaControl.TextArea.Caret.Offset, prompt.VariableName);
                }
            } catch { }
        }
예제 #13
0
        public bool MoveUpPrompt(AbstractPrompt prompt)
        {
            bool isChanged  = false;
            bool foundLower = false;

            _prompts.ForEach(delegate(AbstractPrompt p) { if (p.OrderKey == prompt.OrderKey - 1)
                                                          {
                                                              p.OrderKey = prompt.OrderKey; foundLower = true;
                                                          }
                             });
            if (foundLower)
            {
                prompt.OrderKey = prompt.OrderKey - 1;
                isChanged       = true;
            }
            return(isChanged);
        }
예제 #14
0
 private void mnuPrompt_MoveUp_Click(object sender, EventArgs e)
 {
     try {
         TreeNode  node   = leftTabs_DocumentTree.SelectedNode;
         Hashtable idPack = node.Tag as Hashtable;
         if ((string)idPack["Type"] == "prompt")
         {
             AbstractPrompt prompt = (AbstractPrompt)idPack["Data"];
             if (prompt.Parent.MoveUpPrompt(prompt))
             {
                 refreshTreeView();
             }
             ;
         }
     } catch (Exception ex) {
         MessageBox.Show("Error reordering: " + ex.Message);
     }
 }
예제 #15
0
        private void topTabs_TemplateEditor_DragDrop(object sender, DragEventArgs e)
        {
            TreeNode node = (TreeNode)e.Data.GetData(typeof(TreeNode));

            ICSharpCode.TextEditor.TextArea textArea = (ICSharpCode.TextEditor.TextArea)sender;
            try {
                Hashtable idPack = node.Tag as Hashtable;
                switch (idPack["Type"] as string)
                {
                case "promptgroup":
                    return;

                case "prompt":
                    break;
                }

                //Build the variable to insert here
                AbstractPrompt prompt = idPack["Data"] as AbstractPrompt;

                Point p = textArea.PointToClient(new Point(e.X, e.Y));
                textArea.BeginUpdate();
                textArea.Document.UndoStack.StartUndoGroup();

                int offset = textArea.Caret.Offset;
                if (e.Data.GetDataPresent(typeof(DefaultSelection)))
                {
                    ISelection sel = (ISelection)e.Data.GetData(typeof(DefaultSelection));
                    if (sel.ContainsPosition(textArea.Caret.Position))
                    {
                        return;
                    }
                    int len = sel.Length;
                    textArea.Document.Remove(sel.Offset, len);
                    if (sel.Offset < offset)
                    {
                        offset -= len;
                    }
                }
                insertIntoTemplateEditor(textArea, offset, prompt.VariableName);
            } finally {
                textArea.Document.UndoStack.EndUndoGroup();
                textArea.EndUpdate();
            }
        }
예제 #16
0
        public void AddPromptAfter(AbstractPrompt aNewPrompt, AbstractPrompt aPrompt)
        {
            aNewPrompt.Parent   = this;
            aNewPrompt.OrderKey = aPrompt.OrderKey;

            int count = _prompts.Count;

            foreach (AbstractPrompt p in _prompts)
            {
                p.OrderKey = p.OrderKey - count;
                if (p == aPrompt)
                {
                    break;
                }
            }

            _prompts.Add(aNewPrompt);
            renumberPrompts();
        }
예제 #17
0
            public static AbstractPrompt Parse(PromptGroup aParent, XmlElement anXmlElement)
            {
                AbstractPrompt tPrompt = producePrompt(aParent, anXmlElement);

                return(tPrompt);
            }
예제 #18
0
 public void AddPrompt(AbstractPrompt aPrompt)
 {
     aPrompt.Parent   = this;
     aPrompt.OrderKey = _prompts.Count + 1;
     _prompts.Add(aPrompt);
 }
예제 #19
0
 public void RemovePrompt(AbstractPrompt aPrompt)
 {
     _prompts.Remove(aPrompt);
     renumberPrompts();
 }