Esempio n. 1
0
        public StudentGetAssignmentWindow(User user, ref TextViewList textviews, string Filename)
            : base("Get Assignment")
        {
            this.user      = user;
            this.textviews = textviews;
            this.Filename  = Filename;

            SetSizeRequest(300, 300);
            string assignment = this.user.student.GetAssignment(this.Filename);

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

            this.textviews.castextviews.Clear();

            // Loads each element into the workspace

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

            this.textviews.castextviews.Reverse();

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

            MessageDialog ms = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Info, ButtonsType.Close, "Got assignment");

            ms.Run();
            ms.Destroy();

            Destroy();
        }
        // 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();
        }
Esempio n. 3
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();
            }
        }