Ejemplo n.º 1
0
 private void Save(TabInfo tab)
 {
     if (tab != null) {
         if (tab.filepath == null) {
             SaveAs(tab);
             return;
         }
         while (parserRunning) {
             System.Threading.Thread.Sleep(1); //Avoid stomping on files while the parser is running
         }
         System.IO.File.WriteAllText(tab.filepath, tab.textEditor.Text, System.Text.Encoding.ASCII);
         tab.changed = false;
         SetTabText(tab.index);
     }
 }
Ejemplo n.º 2
0
 private void ParseMessages(TabInfo ti)
 {
     ti.messages.Clear();
     char[] split = new char[] { '}' };
     for (int i = 0; i < ti.msgFileTab.textEditor.Document.TotalNumberOfLines; i++) {
         string[] line = ti.msgFileTab.textEditor.Document.GetText(ti.msgFileTab.textEditor.Document.GetLineSegment(i)).Split(split, StringSplitOptions.RemoveEmptyEntries);
         if (line.Length != 3)
             continue;
         for (int j = 0; j < 3; j += 2) {
             line[j] = line[j].Trim();
             if (line[j].Length == 0 || line[j][0] != '{')
                 continue;
             line[j] = line[j].Substring(1);
         }
         int index;
         if (!int.TryParse(line[0], out index))
             continue;
         ti.messages[index] = line[2];
     }
 }
Ejemplo n.º 3
0
        public TabInfo Open(string file, OpenType type, bool addToMRU = true, bool alwaysNew = false)
        {
            if (type == OpenType.File) {
                if (!Path.IsPathRooted(file)) {
                    file = Path.GetFullPath(file);
                }
                //Add this file to the recent files list
                if (addToMRU) {
                    Settings.AddRecentFile(file);
                }
                UpdateRecentList();
                //If this is an int, decompile
                if (string.Compare(Path.GetExtension(file), ".int", true) == 0) {
                    var compiler = new Compiler();
                    string decomp = compiler.Decompile(file);
                    if (decomp == null) {
                        MessageBox.Show("Decompilation of '" + file + "' was not successful", "Error");
                        return null;
                    } else {
                        file = decomp;
                        type = OpenType.Text;
                    }
                } else {
                    //Check if the file is already open
                    for (int i = 0; i < tabs.Count; i++) {
                        if (string.Compare(tabs[i].filepath, file, true) == 0) {
                            tabControl1.SelectTab(i);
                            return tabs[i];
                        }
                    }
                }
            }
            //Create the text editor and set up the tab
            ICSharpCode.TextEditor.TextEditorControl te = new ICSharpCode.TextEditor.TextEditorControl();
            te.ShowVRuler = false;
            te.Document.FoldingManager.FoldingStrategy = new CodeFolder();
            te.IndentStyle = IndentStyle.Smart;
            te.ConvertTabsToSpaces = Settings.tabsToSpaces;
            te.TabIndent = Settings.tabSize;
            te.Document.TextEditorProperties.IndentationSize = Settings.tabSize;
            if (type == OpenType.File)
                te.LoadFile(file, false, true);
            else if (type == OpenType.Text)
                te.Text = file;
            if (type == OpenType.File && string.Compare(Path.GetExtension(file), ".msg", true) == 0)
                te.SetHighlighting("msg");
            else
                te.SetHighlighting("ssl"); // Activate the highlighting, use the name from the SyntaxDefinition node.
            te.TextChanged += textChanged;
            te.ActiveTextAreaControl.TextArea.MouseDown += delegate(object a1, MouseEventArgs a2) {
                if (a2.Button == MouseButtons.Left)
                    UpdateEditorToolStripMenu();
                lbAutocomplete.Hide();
            };
            te.ActiveTextAreaControl.TextArea.KeyPress += KeyPressed;
            te.HorizontalScroll.Visible = false;

            te.ActiveTextAreaControl.TextArea.PreviewKeyDown += delegate(object sender, PreviewKeyDownEventArgs a2) {
                if (lbAutocomplete.Visible) {
                    if ((a2.KeyCode == Keys.Down || a2.KeyCode == Keys.Up || a2.KeyCode == Keys.Tab)) {
                        lbAutocomplete.Focus();
                        lbAutocomplete.SelectedIndex = 0;
                    } else if (a2.KeyCode == Keys.Escape) {
                        lbAutocomplete.Hide();
                    }
                } else {
                    if (toolTipAC.Active && a2.KeyCode != Keys.Left && a2.KeyCode != Keys.Right)
                        toolTipAC.Hide(panel1);
                }
            };

            TabInfo ti = new TabInfo();
            ti.textEditor = te;
            ti.changed = false;
            if (type == OpenType.File && !alwaysNew) {
                ti.filepath = file;
                ti.filename = Path.GetFileName(file);
            } else {
                ti.filepath = null;
                ti.filename = unsaved;
            }
            ti.index = tabControl1.TabCount;
            te.ActiveTextAreaControl.TextArea.ToolTipRequest += new ToolTipRequestEventHandler(TextArea_ToolTipRequest);
            te.ContextMenuStrip = editorMenuStrip;

            tabs.Add(ti);
            TabPage tp = new TabPage(ti.filename);
            tp.Controls.Add(te);
            te.Dock = DockStyle.Fill;

            tabControl1.TabPages.Add(tp);
            if (type == OpenType.File & !alwaysNew) {
                tp.ToolTipText = ti.filepath;
                System.String ext = Path.GetExtension(file).ToLower();
                if (ext == ".ssl" || ext == ".h") {
                    ti.shouldParse = true;
                    ti.needsParse = true;
                    if (Settings.autoOpenMsgs && ti.filepath != null)
                        AssossciateMsg(ti, false);
                }
            }
            if (tabControl1.TabPages.Count > 1) {
                tabControl1.SelectTab(tp);
            } else {
                tabControl1_Selected(null, null);
            }
            return ti;
        }
Ejemplo n.º 4
0
 private void Close(TabInfo tab)
 {
     if (tab == null | tab.index == -1) {
         return;
     }
     if (tab.changed) {
         switch (MessageBox.Show("Save changes to " + tab.filename + "?", "Message", MessageBoxButtons.YesNoCancel)) {
             case DialogResult.Yes:
                 Save(tab);
                 if (tab.changed)
                     return;
                 break;
             case DialogResult.No:
                 break;
             default:
                 return;
         }
     }
     int i = tab.index;
     if (tabControl1.TabPages.Count > 2 && i == tabControl1.SelectedIndex) {
         if (previousTabIndex != -1) {
             tabControl1.SelectedIndex = previousTabIndex;
         } else {
             tabControl1.SelectedIndex = tabControl1.TabCount - 2;
         }
     }
     tabControl1.TabPages.RemoveAt(i);
     tabs.RemoveAt(i);
     for (int j = i; j < tabs.Count; j++)
         tabs[j].index--;
     for (int j = 0; j < tabs.Count; j++) {
         if (tabs[j].msgFileTab == tab) {
             tabs[j].msgFileTab = null;
             tabs[j].messages.Clear();
         }
     }
     tab.index = -1;
     if (tabControl1.TabPages.Count == 1) {
         tabControl1_Selected(null, null);
     }
 }
Ejemplo n.º 5
0
 private bool Compile(TabInfo tab, out string msg, bool showMessages = true, bool preprocess = false)
 {
     msg = "";
     if (Settings.outputDir == null) {
         if (showMessages)
             MessageBox.Show("No output path selected.\nPlease select your scripts directory before compiling", "Error");
         return false;
     }
     Save(tab);
     if (tab.changed || tab.filepath == null)
         return false;
     if (string.Compare(Path.GetExtension(tab.filename), ".msg", true) == 0) {
         if (showMessages)
             MessageBox.Show("You cannot compile message files");
         return false;
     }
     List<Error> errors = new List<Error>();
     var compiler = new Compiler();
     bool success = compiler.Compile(currentTab.filepath, out msg, errors, preprocess);
     foreach (ErrorType et in new ErrorType[] { ErrorType.Error, ErrorType.Warning, ErrorType.Message }) {
         foreach (Error e in errors) {
             if (e.type == et)
                 dgvErrors.Rows.Add(e.type.ToString(), Path.GetFileName(e.fileName), e.line, e);
         }
     }
     if (!success) {
         tabControl2.SelectedIndex = 1;
     } else {
         parserLabel.Text = "Successfully compiled " + currentTab.filename + " at " + DateTime.Now.ToString();
     }
     if (!success && Settings.warnOnFailedCompile) {
         if (showMessages)
             MessageBox.Show("Script " + tab.filename + " failed to compile. See the output window for details", "Error");
     }
     return success;
 }
Ejemplo n.º 6
0
 public WorkerArgs(string text, TabInfo tab)
 {
     this.text = text;
     this.tab = tab;
 }
Ejemplo n.º 7
0
 private void AssossciateMsg(TabInfo tab, bool create)
 {
     if (Settings.outputDir == null || tab.filepath == null || tab.msgFileTab != null)
         return;
     string path = Path.Combine(Settings.outputDir, "..\\text\\" + Settings.language + "\\dialog\\");
     if (!Directory.Exists(path)) {
         MessageBox.Show("Failed to open or create associated message file; directory data\\text\\" + Settings.language + "\\dialog does not exist", "Error");
         return;
     }
     path = Path.Combine(path, Path.ChangeExtension(tab.filename, ".msg"));
     if (!File.Exists(path)) {
         if (!create)
             return;
         else
             File.Create(path).Close();
     }
     tab.msgFileTab = Open(path, OpenType.File, false);
 }
Ejemplo n.º 8
0
 private void tabControl1_Selected(object sender, TabControlEventArgs e)
 {
     if (tabControl1.SelectedIndex == -1) {
         currentTab = null;
         parserLabel.Text = "Parser: No file";
     } else {
         if (currentTab != null) {
             previousTabIndex = currentTab.index;
         }
         currentTab = tabs[tabControl1.SelectedIndex];
         if (currentTab.msgFileTab != null)
             ParseMessages(currentTab);
         if (currentTab.shouldParse) {
             if (currentTab.needsParse) {
                 parserLabel.Text = "Parser: Out of date";
                 timerNext = DateTime.Now + TimeSpan.FromSeconds(1);
                 if (!timer.Enabled)
                     timer.Start();
             } else {
                 parserLabel.Text = "Parser: Up to date";
                 UpdateNames();
             }
         } else {
             parserLabel.Text = "Parser: Not an ssl";
             UpdateNames();
         }
     }
 }
Ejemplo n.º 9
0
 private void SearchForAll(TabInfo tab, Regex regex, DataGridView dgv, List<int> offsets, List<int> lengths)
 {
     int start, len, line, lastline = -1;
     int offset = 0;
     while (Search(tab.textEditor.Text, sf.tbSearch.Text, regex, offset, false, out start, out len)) {
         offset = start + 1;
         line = tab.textEditor.Document.OffsetToPosition(start).Line;
         if (offsets != null) {
             offsets.Add(start);
             lengths.Add(len);
         }
         if (line != lastline) {
             lastline = line;
             var message = TextUtilities.GetLineAsString(tab.textEditor.Document, line);
             Error error = new Error(message, tab.filepath, line + 1);
             dgv.Rows.Add(tab.filename, error.line.ToString(), error);
         }
     }
 }
Ejemplo n.º 10
0
 private bool SearchAndScroll(TabInfo tab, Regex regex)
 {
     int start, len;
     if (Search(tab.textEditor.Text, sf.tbSearch.Text, regex, tab.textEditor.ActiveTextAreaControl.Caret.Offset + 1, true, out start, out len)) {
         TextLocation locstart = tab.textEditor.Document.OffsetToPosition(start);
         TextLocation locend = tab.textEditor.Document.OffsetToPosition(start + len);
         tab.textEditor.ActiveTextAreaControl.SelectionManager.SetSelection(locstart, locend);
         tab.textEditor.ActiveTextAreaControl.Caret.Position = locstart;
         tab.textEditor.ActiveTextAreaControl.ScrollToCaret();
         return true;
     }
     return false;
 }
Ejemplo n.º 11
0
 private void SaveAs(TabInfo tab)
 {
     if (tab != null && sfdScripts.ShowDialog() == DialogResult.OK) {
         tab.filepath = sfdScripts.FileName;
         tab.filename = System.IO.Path.GetFileName(tab.filepath);
         Save(tab);
         Settings.AddRecentFile(tab.filepath);
         System.String ext = Path.GetExtension(tab.filepath).ToLower();
         if (ext == ".ssl" || ext == ".h") {
             tab.shouldParse = true;
             tab.needsParse = true;
             parserLabel.Text = "Parser: Out of date";
             timerNext = DateTime.Now + TimeSpan.FromSeconds(1);
             if (!timer.Enabled)
                 timer.Start();
         }
     }
 }
Ejemplo n.º 12
0
 public WorkerArgs(string text, TabInfo tab)
 {
     this.text = text;
     this.tab  = tab;
 }