private void test1ToolStripMenuItem_CheckedChanged(object sender, EventArgs e)
        {
            ToolStripMenuItem item = sender as ToolStripMenuItem;

            ChameleonFeatures feature;

            Enum.TryParse <ChameleonFeatures>(item.Text, out feature);

            ChameleonFeatures perms = App.UserSettings.PermittedFeatures;

            if (item.Checked)
            {
                perms |= feature;
            }
            else
            {
                perms &= ~feature;
            }

            App.UserSettings.PermittedFeatures = perms;
            App.GlobalSettings.SaveSettings();
            App.UserSettings.SaveSettings();

            ShowPermittedUI();
        }
Example #2
0
        private void AddNewGroup(string groupName, ChameleonFeatures cf)
        {
            m_groups[groupName] = cf;

            ListViewItem lvi = lvGroups.Items.Add(groupName);

            lvi.Selected = true;
        }
Example #3
0
        private void lvGroups_SubItemEndEditing(object sender, LVE.SubItemEndEditingEventArgs e)
        {
            string newGroupName = e.DisplayText;

            if (m_prevGroupName != newGroupName)
            {
                ReplaceGroupName(m_prevGroupName, newGroupName);

                ChameleonFeatures cf = m_groups[m_prevGroupName];
                m_groups.Remove(m_prevGroupName);
                m_groups[newGroupName] = cf;
            }
        }
Example #4
0
        public static ChameleonFeatures ParsePermissions(string text)
        {
            string[]          items = text.Split('|');
            ChameleonFeatures cf    = (ChameleonFeatures)0;

            foreach (string item in items)
            {
                ChameleonFeatures flag;
                if (Enum.TryParse <ChameleonFeatures>(item, out flag))
                {
                    cf |= flag;
                }
            }

            return(cf);
        }
        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;
            }
        }
Example #6
0
        private void AddNewGroup()
        {
            string name = GetNextGroupName();

            while (m_groups.ContainsKey(name))
            {
                name = GetNextGroupName();
            }

            //SaveCurrentFeatures();

            m_groups[name] = new ChameleonFeatures();

            ListViewItem lvi = lvGroups.Items.Add(name);

            lvi.Selected = true;
        }
Example #7
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);
                }
            }
        }
Example #8
0
        private void SaveCurrentFeatures(string groupName)
        {
            ChameleonFeatures cf = new ChameleonFeatures();

            for (int i = 0; i < lbFeatures.Items.Count; i++)
            {
                bool flag = lbFeatures.GetItemChecked(i);

                if (flag)
                {
                    ChameleonFeatures cfResult;
                    Enum.TryParse <ChameleonFeatures>(lbFeatures.Items[i].ToString(), out cfResult);

                    cf |= cfResult;
                }
            }

            m_groups[groupName] = cf;
        }
Example #9
0
        private void lbFeatures_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            if (lvGroups.SelectedItems.Count == 1)
            {
                string            groupName = lvGroups.SelectedItems[0].Text;
                ChameleonFeatures cf        = m_groups[groupName];

                string featureName = lbFeatures.Items[e.Index].ToString();

                ChameleonFeatures feature;
                Enum.TryParse <ChameleonFeatures>(featureName, out feature);

                if (e.NewValue == CheckState.Checked)
                {
                    cf |= feature;
                }
                else
                {
                    cf ^= feature;
                }

                m_groups[groupName] = cf;
            }
        }
Example #10
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.ThreadException += ApplicationThreadException;

            //	show the splash form
            Splasher.Show();

            while (Splasher.MySplashForm == null)
            {
                Thread.Sleep(250);
            }

            Splasher.Status = "Starting up...";

            if (File.Exists("wyUpdate.exe"))
            {
                Splasher.Status = "Checking for updates...";

                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName        = "wyupdate.exe";
                psi.Arguments       = "-quickcheck -justcheck -noerr";
                psi.CreateNoWindow  = true;
                psi.UseShellExecute = true;

                Process proc = Process.Start(psi);

                proc.WaitForExit();

                int code = proc.ExitCode;
                proc.Close();

                // updates are available
                if (code == 2)
                {
                    Splasher.Status = "Updates available.  Launching updater...";
                    Thread.Sleep(1000);
                    Splasher.Close();

                    psi.Arguments = "-filetoexecute=Chameleon.exe";
                    proc          = Process.Start(psi);
                    Environment.Exit(1);
                }
            }

            string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

            Options.DataFolder = Path.Combine(appDataFolder, "Chameleon");

            // initialize the singleton
            Options options = App.GlobalSettings;



            if (!Directory.Exists(Options.DataFolder))
            {
                Directory.CreateDirectory(Options.DataFolder);
            }

            // debug helper - only called if in debug mode
            Program.SetDebugPermissionsLocation();

            Splasher.Status = "Checking for new features...";

            string permissionsText = ChameleonNetworking.Instance.GetFeaturePermissions();

            if (permissionsText == null)
            {
                // do nothing - leave PermittedFeatures at default/last saved
            }
            else if (!String.IsNullOrWhiteSpace(permissionsText))
            {
                ChameleonFeatures enabledFeatures = Permissions.ParsePermissions(permissionsText);
                App.UserSettings.PermittedFeatures = enabledFeatures;
            }

            Splasher.Status = "Starting Chameleon...";

            Thread.Sleep(1000);

            Form f = new ChameleonForm();

            //	if the form is still shown...
            Splasher.Close();

            Application.Run(f);

            Singleton <CtagsManagerWrapper> .Instance.CodeLiteParserEnd();
        }
Example #11
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();
        }
Example #12
0
        private void LoadSelectedFolder(FileInformation folder)
        {
            if (lvStudents.Items.Count > 0 || lvGroups.Items.Count > 0)
            {
                DialogResult dr = MessageBox.Show("Save current items before loading?", "Save Items?",
                                                  MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

                if (dr == DialogResult.Yes)
                {
                    SaveCurrentItems();
                }
                else if (dr == DialogResult.Cancel)
                {
                    return;
                }
            }

            if (folder.Location == FileLocation.Unknown)
            {
                return;
            }

            bool isRemote = folder.Location == FileLocation.Remote;

            if (isRemote && !m_networking.IsConnected)
            {
                MessageBox.Show("Can't load remote files if not connected!", "Connection Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            ClearAllItems();

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

            List <FileInformation> folderTextFiles = GetFolderTextFiles(folder);
            List <FileInformation> groupFiles      = GetGroupTextFiles(folderTextFiles);

            string fileContents = "";

            foreach (FileInformation groupFile in groupFiles)
            {
                string fileName  = groupFile.Filename.Name;
                string groupName = fileName.Substring(m_groupPrefix.Length);

                fileContents = "";
                if (!GetFileContents(groupFile, ref fileContents))
                {
                    continue;
                }

                ChameleonFeatures cf = Permissions.ParsePermissions(fileContents);
                AddNewGroup(groupName, cf);
            }

            List <FileInformation> studentFiles = (from fi in folderTextFiles
                                                   where fi.Filename.Name == "students"
                                                   select fi).ToList();

            if (studentFiles.Count == 0)
            {
                return;
            }

            FileInformation studentFile = studentFiles[0];

            if (!GetFileContents(studentFile, ref fileContents))
            {
                return;
            }

            Regex reNewlines = new Regex("\r\n?|\n");

            string[] studentLines = reNewlines.Split(fileContents);

            foreach (string s in studentLines)
            {
                string[] sg = s.Split(':');

                if (sg.Length != 2)
                {
                    continue;
                }

                string student = sg[0];
                string group   = sg[1];

                if (!m_groups.ContainsKey(group))
                {
                    group = "";
                }

                ListViewItem lvi = lvStudents.Items.Add(group);
                lvi.SubItems.Add(student);
            }

            if (lvGroups.Items.Count > 0)
            {
                lvGroups.SelectedIndices.Clear();
                lvGroups.Items[0].Selected = true;

                lvGroups.Focus();
            }
        }
Example #13
0
        private void AddNewGroup(string groupName)
        {
            ChameleonFeatures cf = new ChameleonFeatures();

            AddNewGroup(groupName, cf);
        }