예제 #1
0
        /// <summary>
        /// 0 = assign; 1 = comment; 2 = while/dowhile; 3 = for; 4 = if; 5 = module call; 6 =
        /// return; 7 = switch;
        /// </summary>
        public static IDropableInstruction createInstruction(int type)
        {
            switch (type)
            {
            case 0:
            {
                var result = new Editor.Assign();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 1:
            {
                var result = new Editor.Comment();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 2:
            {
                var result = new Editor.While();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 3:
            {
                var result = new Editor.For();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 4:
            {
                var result = new Editor.If();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 5:
            {
                var result = new Editor.ModuleCall();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 6:
            {
                var result = new Editor.Return();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            case 7:
            {
                var result = new Editor.Switch();
                if (EditInstruction(result))
                {
                    return(result);
                }
                else
                {
                    return(null);
                }
            }

            default:
                return(null);
            }
        }
예제 #2
0
 public static Control GetInstructionControl(Instruction instru)
 {
     if (instru is Assign)
     {
         var res = new Editor.Assign();
         res.InternalInstruction = instru as Assign;
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is Comment)
     {
         var res = new Editor.Comment();
         res.InternalComment = instru as Comment;
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is DoWhile)
     {
         var loop = instru as DoWhile;
         var res  = new Editor.DoWhile();
         res.InternalInstruction = loop;
         foreach (var item in loop.Instructions)
         {
             res.instructions.Children.Add(GetInstructionControl(item));
         }
         res.instructions.Children.Add(res.EndInstruction);
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is For)
     {
         var loop = instru as For;
         var res  = new Editor.For();
         res.InternalInstruction = loop;
         foreach (var item in loop.Instructions)
         {
             res.instructions.Children.Add(GetInstructionControl(item));
         }
         res.instructions.Children.Add(res.EndInstruction);
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is If)
     {
         var block = instru as If;
         var res   = new Editor.If();
         var font  = res.comment.FontFamily;
         res.InternalInstruction = block;
         foreach (var item in block.IfInstructions)
         {
             res.ifInstructions.Children.Add(GetInstructionControl(item));
         }
         res.ifInstructions.Children.Add(res.EndInstruction);
         foreach (var item in block.ElseInstructions)
         {
             res.elseInstructions.Children.Add(GetInstructionControl(item));
         }
         res.elseInstructions.Children.Add(res.ElseEndInstruction);
         foreach (var elif in block.Elif)
         {
             var elifStruct = new Editor.If.Elif();
             elifStruct.EndInstruction = new Editor.DummyInstruction();
             var firstLine = new StackPanel {
                 Orientation = Orientation.Horizontal, IsHitTestVisible = false
             };
             firstLine.Children.Add(new TextBlock
             {
                 Text       = "sinon si ",
                 Foreground = App.KeywordColorBrush,
                 FontFamily = font,
                 Margin     = new System.Windows.Thickness(21, 0, 0, 0)
             });
             elifStruct.condition = new ContentControl();
             firstLine.Children.Add(elifStruct.condition);
             firstLine.Children.Add(new TextBlock
             {
                 Text       = " alors",
                 Foreground = App.KeywordColorBrush,
                 FontFamily = font
             });
             elifStruct.comment = new TextBlock
             {
                 Foreground = commentsColorBrush,
                 FontFamily = font,
                 FontStyle  = System.Windows.FontStyles.Italic,
                 Margin     = new System.Windows.Thickness(5, 0, 0, 0)
             };
             firstLine.Children.Add(elifStruct.comment);
             var mainFlow = new StackPanel();
             mainFlow.Children.Add(firstLine);
             var instruGrid = new Grid();
             mainFlow.Children.Add(instruGrid);
             instruGrid.Children.Add(new System.Windows.Shapes.Rectangle
             {
                 Width = 1,
                 Fill  = new SolidColorBrush(Colors.Gray),
                 HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                 Margin = new System.Windows.Thickness(12, 0, 0, 0)
             });
             elifStruct.instructions = new StackPanel {
                 Margin = new System.Windows.Thickness(25, 0, 0, 0)
             };
             elifStruct.instructions.Tag = res;
             foreach (var item in elif.Item2)
             {
                 elifStruct.instructions.Children.Add(GetInstructionControl(item));
             }
             elifStruct.instructions.Children.Add(elifStruct.EndInstruction);
             instruGrid.Children.Add(elifStruct.instructions);
             res.elifs.Children.Add(mainFlow);
             res.elifList.Add(elifStruct);
         }
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is ModuleCall)
     {
         var res = new Editor.ModuleCall();
         res.InternalInstruction = instru as ModuleCall;
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is Return)
     {
         var res = new Editor.Return();
         res.InternalInstruction = instru as Return;
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is ILANET.Switch)
     {
         var block = instru as ILANET.Switch;
         var res   = new Editor.Switch();
         var font  = res.comment.FontFamily;
         res.InternalInstruction = block;
         foreach (var item in block.Default)
         {
             res.defaultInstructions.Children.Add(GetInstructionControl(item));
         }
         res.defaultInstructions.Children.Add(res.EndInstruction);
         foreach (var cas in block.Cases)
         {
             var caseStruct = new Editor.Switch.Case();
             caseStruct.EndInstruction = new Editor.DummyInstruction();
             var firstLine = new DockPanel {
                 Margin = new System.Windows.Thickness(25, 0, 0, 0)
             };
             caseStruct.conditions = new StackPanel
             {
                 IsHitTestVisible = false,
                 Orientation      = Orientation.Horizontal
             };
             firstLine.Children.Add(caseStruct.conditions);
             firstLine.Children.Add(new TextBlock
             {
                 Text       = " : ",
                 Foreground = App.SymbolColorBrush,
                 FontFamily = font
             });
             caseStruct.instructions = new StackPanel();
             firstLine.Children.Add(caseStruct.instructions);
             var mainGrid = new Grid();
             mainGrid.Children.Add(firstLine);
             mainGrid.Children.Add(new System.Windows.Shapes.Rectangle
             {
                 Width = 1,
                 Fill  = new SolidColorBrush(Colors.Gray),
                 HorizontalAlignment = System.Windows.HorizontalAlignment.Left,
                 Margin = new System.Windows.Thickness(30, 16, 0, 0)
             });
             caseStruct.instructions.Tag = res;
             foreach (var item in cas.Item2)
             {
                 caseStruct.instructions.Children.Add(GetInstructionControl(item));
             }
             caseStruct.instructions.Children.Add(caseStruct.EndInstruction);
             res.casesList.Children.Add(mainGrid);
             res.Cases.Add(caseStruct);
         }
         res.UpdateVisuals();
         return(res);
     }
     else if (instru is While)
     {
         var loop = instru as While;
         var res  = new Editor.While();
         res.InternalInstruction = loop;
         foreach (var item in loop.Instructions)
         {
             res.instructions.Children.Add(GetInstructionControl(item));
         }
         res.instructions.Children.Add(res.EndInstruction);
         res.UpdateVisuals();
         return(res);
     }
     else
     {
         return(null);
     }
 }