Esempio n. 1
0
        private void ShowPermittedUI()
        {
            ChameleonFeatures perms = App.UserSettings.PermittedFeatures;

            // clear out toolbar items after the basics
            int indexAfterSave = toolStrip1.Items.IndexOf(btnSave) + 2;
            int remainingItems = toolStrip1.Items.Count - (indexAfterSave);

            for (int i = 0; i < remainingItems; i++)
            {
                toolStrip1.Items.RemoveAt(indexAfterSave);
            }

            splitSnippetsEditor.Panel1Collapsed = !perms.HasFlag(ChameleonFeatures.DragDropSnippets);

            if (perms.HasFlag(ChameleonFeatures.Compiler))
            {
                toolStrip1.Items.Add(btnCompile);
                toolStrip1.Items.Add(new ToolStripSeparator());
            }
            else
            {
                tabControl1.TabPages.Remove(m_tabCompilerErrors);
            }

            if (perms.HasFlag(ChameleonFeatures.SimpleRunProgram))
            {
                toolStrip1.Items.Add(btnRun);
                toolStrip1.Items.Add(new ToolStripSeparator());
            }

            if (perms.HasFlag(ChameleonFeatures.Debugger))
            {
                toolStrip1.Items.Add(btnDebugStart);
                toolStrip1.Items.Add(btnDebugContinue);
                toolStrip1.Items.Add(btnDebugStop);
                toolStrip1.Items.Add(btnDebugStepNext);
                toolStrip1.Items.Add(btnDebugStepOver);
                toolStrip1.Items.Add(btnDebugStepOut);
                toolStrip1.Items.Add(new ToolStripSeparator());
            }

            if (!App.UserSettings.PermittedFeatures.HasFlag(ChameleonFeatures.FileTemplates))
            {
                btnNewSplit.DropDownButtonWidth = 0;
            }
        }
Esempio n. 2
0
        private void CheckFeatures(string groupName)
        {
            ChameleonFeatures        cf       = m_groups[groupName];
            List <ChameleonFeatures> cfValues = GetCFValues();

            for (int i = 0; i < cfValues.Count; i++)
            {
                bool flag = cf.HasFlag(cfValues[i]);

                string name  = cfValues[i].ToString();
                int    index = lbFeatures.Items.IndexOf(name);

                if (index > -1)
                {
                    lbFeatures.SetItemChecked(index, flag);
                }
            }
        }
Esempio n. 3
0
        private void SaveCurrentItems()
        {
            List <string> groups = m_groups.Keys.ToList();
            Dictionary <string, string> groupFiles = new Dictionary <string, string>();

            bool anyInvalid = false;
            char badChar    = ' ';

            foreach (string group in groups)
            {
                string filename = String.Format("{0}{1}.txt", m_groupPrefix, group);
                groupFiles[group] = filename;

                if (!IsValidFilename(filename, ref badChar))
                {
                    anyInvalid = true;

                    string charString = badChar.ToString();
                    int    charValue  = (int)badChar;

                    if (charValue <= 31)
                    {
                        charString = "[ASCII]" + charValue;
                    }

                    string message = string.Format("Group '{0}' contains characters not allowed in a filename. " +
                                                   "Please remove this character: '{1}'", filename, charString);
                    MessageBox.Show(message, "Invalid Group Names", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }

            if (anyInvalid)
            {
                return;
            }

            string path = m_currentFolder.Filename.GetFullPath();

            if (path == "" || m_currentFolder.Location == FileLocation.Unknown)
            {
                string message = "Where should these settings be saved?";

                List <string> buttons = new List <string>();
                buttons.Add("Locally (on the computer you're using)");
                buttons.Add("Remotely (on the server)");
                buttons.Add("Cancel");


                int button = cTaskDialog.ShowCommandBox("Save File Location", message, "",
                                                        string.Join("|", buttons), false);
                FileLocation location = (FileLocation)button;

                if (location == FileLocation.Unknown)
                {
                    // canceled
                    return;
                }

                FileInformation folder = null;

                if (location == FileLocation.Remote)
                {
                    folder = SelectRemoteFolder();
                }
                else
                {
                    folder = SelectLocalFolder();
                }

                if (folder == null)
                {
                    return;
                }

                m_currentFolder = folder;
            }

            bool isRemote = (m_currentFolder.Location == FileLocation.Remote);
            List <FileInformation> textFiles      = GetFolderTextFiles(m_currentFolder);
            List <FileInformation> groupTextFiles = GetGroupTextFiles(textFiles);

            if (isRemote)
            {
                DeleteOldRemoteSettings(groupTextFiles);
            }
            else
            {
                DeleteOldLocalSettings(groupTextFiles);
            }

            List <FileInformation> finalGroupFiles = groupFiles.Keys.ToList().ConvertAll <FileInformation>
                                                         (groupName =>
            {
                FileInformation fi = new FileInformation();
                fi.Filename.Assign(m_currentFolder.Filename.GetFullPath(), groupName, m_currentFolder.Filename.Format);
                fi.Location = m_currentFolder.Location;

                return(fi);
            });

            foreach (string group in groups)
            {
                string          groupFilename = groupFiles[group];
                FileInformation fi            = new FileInformation();
                fi.Filename.Assign(m_currentFolder.Filename.GetFullPath(), groupFilename, m_currentFolder.Filename.Format);
                fi.Location = m_currentFolder.Location;

                ChameleonFeatures cf            = m_groups[group];
                List <string>     selectedFlags = new List <string>();


                foreach (ChameleonFeatures flag in Enum.GetValues(typeof(ChameleonFeatures)))
                {
                    if (cf.HasFlag(flag))
                    {
                        string name = Enum.GetName(typeof(ChameleonFeatures), flag);
                        selectedFlags.Add(name);
                    }
                }

                string groupFileContents = string.Join("|", selectedFlags);

                WriteFileContents(fi, groupFileContents);
            }

            List <string> studentStrings = new List <string>();

            foreach (ListViewItem lvi in lvStudents.Items)
            {
                // listview shows group:student, but the file format needs student:group
                string line = string.Format("{0}:{1}", lvi.SubItems[1].Text, lvi.Text);
                studentStrings.Add(line);
            }

            string studentFileContents = string.Join("\r\n", studentStrings);

            FileInformation studentFile = new FileInformation();

            studentFile.Filename.Assign(m_currentFolder.Filename.GetFullPath(), "students.txt", m_currentFolder.Filename.Format);
            studentFile.Location = m_currentFolder.Location;

            WriteFileContents(studentFile, studentFileContents);

            txtSelectedFolder.Text = m_currentFolder.Filename.GetFullPath();
        }