Exemple #1
0
        //When text is changed in one of the editor tabs.
        private void tabTextChanged(object sender, EventArgs e)
        {
            //If text is changed, and the "NOSAVE" indicator isn't there, put it there.
            if (!editorTabs.TabPages[editorTabs.SelectedIndex].Text.EndsWith("*"))
            {
                //Grab the EditorTabInfo.
                EditorTabInfo info = (EditorTabInfo)editorTabs.TabPages[editorTabs.SelectedIndex].Tag;

                //Disable savedLatest (changes have been made).
                info.SavedLatest = false;

                //Append the nosave text.
                editorTabs.TabPages[editorTabs.SelectedIndex].Text += "*";
            }
        }
Exemple #2
0
        //When the "Run" button is pressed in the "Run" toolstrip.
        private void runAlgoScriptToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Get the currently opened script's location.
            int tab = editorTabs.SelectedIndex;

            if (tab == -1)
            {
                return;
            }
            EditorTabInfo info = (EditorTabInfo)editorTabs.TabPages[tab].Tag;

            //Script open?
            if (info.FileLocation == "")
            {
                Error err = new Error("No file is open to run.");
                return;
            }

            //Yes, open a console and execute.
            FileInfo fi = new FileInfo(info.FileLocation);

            //Check it's an algo file (can be executed).
            if (fi.Extension != ".ag")
            {
                Error err = new Error("You can only execute Algo scripts using Rhythm (your file must have the \".ag\" extension).");
                return;
            }

            string strCmdText;

            strCmdText = "/K algo " + fi.Name;

            //Disable form.
            this.Enabled = false;

            //Start console process.
            Process p = new Process();

            p.StartInfo.FileName         = "cmd.exe";
            p.StartInfo.WorkingDirectory = fi.DirectoryName;
            p.StartInfo.Arguments        = strCmdText;
            p.Start();
            p.WaitForExit();

            //Re-enable form.
            this.Enabled = true;
        }
Exemple #3
0
        //When the "Save As" button is pressed in the "File" toolstrip.
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Get the selected tab, clear the file path, then "save" as normal.
            int tab = editorTabs.SelectedIndex;

            //Check a tab is selected.
            if (tab == -1)
            {
                return;
            }

            //Get the editor info and clear the file.
            EditorTabInfo info = (EditorTabInfo)editorTabs.TabPages[tab].Tag;

            info.FileLocation            = "";
            editorTabs.TabPages[tab].Tag = info;

            //Save normally.
            saveToolStripMenuItem_Click(this, null);
        }
Exemple #4
0
        //When the selected tab is changed in the editor.
        private void tabChanged(object sender, EventArgs e)
        {
            //Get the index of the tab, check a tab is selected.
            int tab = editorTabs.SelectedIndex;

            if (tab == -1)
            {
                return;
            }

            //Get the tab info.
            EditorTabInfo info = (EditorTabInfo)editorTabs.TabPages[tab].Tag;

            if (!info.FileName.EndsWith(".ag"))
            {
                return;
            }

            //Get tab TextArea.
            Scintilla textArea = GetTextAreaFromTab(tab);

            //Bind the AutoComplete window to this tab.
            autoComplete.TargetControlWrapper = new ScintillaWrapper(textArea);
        }
Exemple #5
0
        //When the "Save" button is pressed in the "File" toolstrip.
        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Get the currently open tab, check if a save has already been completed.
            int tab = editorTabs.SelectedIndex;

            //Check a tab is loaded.
            if (tab <= -1)
            {
                return;
            }

            EditorTabInfo tabInfo  = (EditorTabInfo)editorTabs.TabPages[tab].Tag;
            Scintilla     textArea = GetTextAreaFromTab(tab);

            //If it's not been saved, then get a new saveLoc, otherwise use the old one.
            string saveLocation = "";

            if (tabInfo.FileLocation == "")
            {
                //NOT SAVED ALREADY
                //Open a Save dialog.
                using (SaveFileDialog dialog = new SaveFileDialog())
                {
                    dialog.Filter           = "Algo files (*.ag)|*.ag|All files (*.*)|*.*";
                    dialog.FilterIndex      = 2;
                    dialog.RestoreDirectory = true;

                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        //Set the save location.
                        saveLocation = dialog.FileName;
                    }
                    else
                    {
                        return;
                    }
                }
            }
            else
            {
                //Just re-save to the location.
                saveLocation = tabInfo.FileLocation;
            }

            //Saving file, setting proper tab information.
            try
            {
                File.WriteAllText(saveLocation, textArea.Text);
            }
            catch (Exception ex)
            {
                Error err = new Error("Failed to save to that location. You may not have write permissions for that file/folder (" + ex.Message + ").");
                return;
            }

            tabInfo.FileLocation         = saveLocation;
            tabInfo.FileName             = new FileInfo(saveLocation).Name;
            tabInfo.SavedLatest          = true;
            editorTabs.TabPages[tab].Tag = tabInfo;

            //Set the title to the correct information.
            editorTabs.TabPages[tab].Text = tabInfo.FileName;

            //Get the extension of the file, set highlighting.
            string ext = new FileInfo(saveLocation).Extension;

            ScintillaUtils.SetHighlighting(ext, textArea);
        }
Exemple #6
0
        //When the "Open" button is pressed in the "File" toolstrip.
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //Create an open dialog, get the location to open from.
            string openLocation = "";

            using (var selectFileDialog = new OpenFileDialog())
            {
                if (selectFileDialog.ShowDialog() == DialogResult.OK)
                {
                    openLocation = selectFileDialog.FileName;
                }
                else
                {
                    return;
                }
            }

            //Get file info, read all text from file.
            FileInfo fi     = new FileInfo(openLocation);
            string   toLoad = "";

            try
            {
                toLoad = File.ReadAllText(openLocation);
            } catch (Exception ex)
            {
                Error err = new Error("Failed to load the provided file. You may be lacking file read permissions for this file (" + ex.Message + ").");
                return;
            }

            //Only create a new tab if the latest one isn't just untitled.
            TabPage tab;

            if (editorTabs.TabPages.Count < 1 || editorTabs.TabPages[editorTabs.TabPages.Count - 1].Text != "Untitled*")
            {
                //Create a new tab.
                newToolStripMenuItem_Click(this, null);
            }

            //Get the text area to modify for highlighting and to add the text.
            Scintilla textArea = GetTextAreaFromTab(editorTabs.TabPages.Count - 1);

            textArea.Text = toLoad;

            //For that tab, set the file name and information.
            tab      = editorTabs.TabPages[editorTabs.TabPages.Count - 1];
            tab.Text = fi.Name;
            EditorTabInfo tabInfo = (EditorTabInfo)tab.Tag;

            tabInfo.FileLocation = fi.FullName;
            tabInfo.FileName     = fi.Name;
            tabInfo.SavedLatest  = true;
            tab.Tag = tabInfo;
            editorTabs.TabPages[editorTabs.TabPages.Count - 1] = tab;

            //Set the highlighting based on extension.
            ScintillaUtils.SetHighlighting(fi.Extension, textArea);

            //Set autocomplete based on extension.
            tabChanged(this, null);
        }