示例#1
0
        public TaskGenAritWindow(TextViewList textviews)
            : base("TaskGen Arithmetics Window")
        {
            this.textviews = textviews;

            Table table = new Table(5, 2, true);

            Label labelMinimum   = new Label("Minimum:");
            Label labelMaximum   = new Label("Maximum:");
            Label labelVariables = new Label("Number of variables: ");
            Label labelNoT       = new Label("Number of tasks:");

            SpinButton spinbuttonMinimum       = new SpinButton(1, 100, 1);
            SpinButton spinbuttonMaximum       = new SpinButton(1, 100, 1);
            SpinButton spinbuttonVariables     = new SpinButton(2, 5, 1);
            SpinButton spinbuttonNumberOfTasks = new SpinButton(1, 5, 1);

            spinbuttonMaximum.Value = 20;

            Button buttonOk     = new Button("Ok");
            Button buttonCancel = new Button("Cancel");

            //Sets the table
            table.Attach(labelMinimum, 0, 1, 0, 1);
            table.Attach(spinbuttonMinimum, 1, 2, 0, 1);
            table.Attach(labelMaximum, 0, 1, 1, 2);
            table.Attach(spinbuttonMaximum, 1, 2, 1, 2);
            table.Attach(labelVariables, 0, 1, 2, 3);
            table.Attach(spinbuttonVariables, 1, 2, 2, 3);
            table.Attach(labelNoT, 0, 1, 3, 4);
            table.Attach(spinbuttonNumberOfTasks, 1, 2, 3, 4);
            table.Attach(buttonCancel, 0, 1, 4, 5);
            table.Attach(buttonOk, 1, 2, 4, 5);

            buttonCancel.Clicked += (sender, e) =>
            {
                this.Destroy();
            };

            // Generates a number of tasks based on the users input
            buttonOk.Clicked += (sender, e) =>
            {
                for (int generatedTaskes = 0; generatedTaskes < spinbuttonNumberOfTasks.Value; generatedTaskes++)
                {
                    TaskGenLib.Task t = TaskGenLib.TaskGen.MakeCalcTask((int)spinbuttonMinimum.Value, (int)spinbuttonMaximum.Value, (int)spinbuttonVariables.Value);
                    textviews.InsertTaskGenTextView(t.TaskDescription);

                    textviews.InsertResult("", t.Solution);
                }

                this.Destroy();
            };

            Add(table);
            ShowAll();
        }
        // Loads the selected assignment up in the workspace
        void LoadWorkspace(string completed)
        {
            List <MetaType> metaTypeList = ImEx.Import.DeserializeString <List <MetaType> >(completed);

            this.textviews.castextviews.Clear();

            foreach (var metaItem in metaTypeList)
            {
                if (metaItem.type == typeof(MovableCasCalcView))
                {
                    textviews.InsertCalcView(metaItem.metastring, metaItem.locked);
                }
                else if (metaItem.type == typeof(MovableCasCalcMulitlineView))
                {
                    textviews.InsertCalcMultilineView(metaItem.metastring, metaItem.locked);
                }
                else if (metaItem.type == typeof(MovableCasResult))
                {
                    CasResult.FacitContainer facitcontainer = Import.DeserializeString <CasResult.FacitContainer>(metaItem.metastring);
                    textviews.InsertResult(facitcontainer.answer, facitcontainer.facit);
                }
                else if (metaItem.type == typeof(MovableCasTextView))
                {
                    textviews.InsertTextView(metaItem.metastring, metaItem.locked, -1);
                }
            }

            this.textviews.castextviews.Reverse();

            this.textviews.Clear();
            this.textviews.Redraw();
            this.textviews.Reevaluate();
            this.textviews.ShowAll();

            Destroy();
        }
示例#3
0
 // Inserts the resultview when clicked
 void OnActivated()
 {
     textviews.InsertResult("", "");
 }
示例#4
0
        // Opens the file when clicked
        public void OpenFile()
        {
            OperatingSystem os  = Environment.OSVersion;
            PlatformID      pid = os.Platform;

            string file = String.Empty;

            bool hasOpenedAnything = false;

            switch (pid)
            {
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
            case PlatformID.Win32NT:     // <- if one, this is the one we really need
            {
                var filechooser = new System.Windows.Forms.OpenFileDialog();

                filechooser.InitialDirectory = "c:\\";
                filechooser.Filter           = "cas files (*.cas)|*.cas";
                filechooser.FilterIndex      = 2;
                filechooser.RestoreDirectory = true;

                if (filechooser.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    file = System.IO.File.ReadAllText(filechooser.FileName);
                    hasOpenedAnything = true;
                }

                break;
            }

            case PlatformID.Unix:
            case PlatformID.MacOSX:
            {
                Object[]          parameters  = { "Cancel", ResponseType.Cancel, "Open", ResponseType.Accept };
                FileChooserDialog filechooser = new FileChooserDialog("Open file...", null, FileChooserAction.Open, parameters);

                filechooser.Filter = new FileFilter();
                filechooser.Filter.AddPattern("*.cas");

                if (filechooser.Run() == (int)ResponseType.Accept)
                {
                    file = System.IO.File.ReadAllText(filechooser.Filename);
                    hasOpenedAnything = true;
                }

                filechooser.Destroy();

                break;
            }

            default:
                break;
            }

            // If anything has been opened, deserializes the content, and rebuilds the workspace with the opened widgets
            if (hasOpenedAnything == true)
            {
                List <MetaType> metaTypeList = new List <MetaType>();

                metaTypeList = ImEx.Import.DeserializeString <List <MetaType> >(file);

                textviews.castextviews.Clear();

                foreach (var item in metaTypeList)
                {
                    if (item.type == typeof(MovableCasTextView) && user.privilege == 1)
                    {
                        textviews.InsertTextView(item.metastring, item.locked, -1);
                    }
                    else if (item.type == typeof(MovableCasCalcView))
                    {
                        textviews.InsertCalcView(item.metastring, item.locked);
                    }
                    else if (item.type == typeof(MovableCasResult))
                    {
                        CasResult.FacitContainer container = new CasResult.FacitContainer();
                        container = Import.DeserializeString <CasResult.FacitContainer>(item.metastring);

                        textviews.InsertResult(container.answer, container.facit);
                    }
                    else if (item.type == typeof(MovableCasCalcMulitlineView))
                    {
                        textviews.InsertCalcMultilineView(item.metastring, item.locked);
                    }
                    else if (item.type == typeof(MovableCasTextView))
                    {
                        textviews.InsertTextView(item.metastring, item.locked, -1);
                    }
                }

                textviews.castextviews.Reverse();

                textviews.Clear();
                textviews.Redraw();
                textviews.Reevaluate();
                textviews.ShowAll();
            }
        }