/// <summary> /// Tabs a file based on c style syntax /// </summary> /// <param name="text">Action string</param> /// <param name="tabcount">Number of tabs to assume for base.</param> private static string TabRightCold(string text, int tabcount) { SettingsObtainer obt = SettingsObtainer.CreateInstance(); string tabstr = obt.TabString; text = Regex.Replace(text, @"\n\s*", String.Empty).Replace("{", "{\n").Replace("}", "\n}\n").Replace(";", ";\n"); string[] rows = text.Split('\n'); for (int i = 0; i < rows.Length; i++) { if (Regex.IsMatch(rows[i], @"^\s*//")) { continue; //#if its a commented line, skip it } rows[i] = Regex.Replace(Regex.Replace(rows[i], @"\s+$", ""), @"^\s+", ""); if (rows[i].Length > 0 && rows[i].StartsWith("}")) { tabcount--; } for (int t = 0; t < tabcount; t++) { rows[i] = tabstr + rows[i]; } if (rows[i].Length > 0 && rows[i].EndsWith("{")) { tabcount++; } } return(String.Join("\n", rows)); }
private void saveButton_Click(object sender, EventArgs e) { SettingsObtainer obtainer = SettingsObtainer.CreateInstance(); obtainer.UdfLocation = udfLocation.Text; obtainer.SnippetsLocation = snippetsLocation.Text; obtainer.ClosesOnExit = !hideAtX.Checked; obtainer.RawTabString = tabStringBox.Text; this.Close(); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { SettingsObtainer obt = SettingsObtainer.CreateInstance(); if (!obt.ClosesOnExit) { e.Cancel = true; MinimizeForm(); } }
public static Store GetInstance() { SettingsObtainer obt = SettingsObtainer.CreateInstance(); if (File.Exists(obt.RecentCommandsLocation)) { return(new FileStore(obt.RecentCommandsLocation)); } return(new RegistryStore()); }
private void OptionsForm_Load(object sender, EventArgs e) { SettingsObtainer obtainer = SettingsObtainer.CreateInstance(); udfLocation.Text = obtainer.UdfLocation; snippetsLocation.Text = obtainer.SnippetsLocation; tabStringBox.Text = obtainer.RawTabString; bool closeOnExit = obtainer.ClosesOnExit; closeAtX.Checked = closeOnExit; hideAtX.Checked = !closeOnExit; }
public override void Edit() { //get rid of spaces in between tags var text = InitializeSpaces(); string[] lines = text.Split('\n'); int tabcount = 0; bool inCommentOrCdata = false; SettingsObtainer obt = SettingsObtainer.CreateInstance(); string tabstr = obt.TabString; for (int line = 0; line < lines.Length; line++) { /* * if prev tag is not closer and I'm not a closer and I'm not a comment * ++ * if I'm a closer * -- */ if (inCommentOrCdata) { if (EndOfCommentOrCdata(lines[line])) { inCommentOrCdata = false; } } else { inCommentOrCdata = StartsCommentOrCdata(lines[line]); } if (lines[line].StartsWith("</") && !inCommentOrCdata) { tabcount--; if (tabcount < 0) { tabcount = 0; } } lines[line] = tabstr.Times(tabcount) + lines[line]; if (ShouldIncrementTabCount(lines, inCommentOrCdata, line)) { tabcount++; } } SourceData = String.Join("\n", lines); }
/// <summary> /// Tabs a file based on Visual Basic style syntax /// </summary> /// <param name="tabcount">Number of tabs to assume for base</param> private static string TabRightVB(string text, int tabcount) { text = Regex.Replace(text, @"_\s*\n\s*", " "); text = Regex.Replace(text, @"else\s*('.+)", "else\n$1", RegexOptions.IgnoreCase); text = Regex.Replace(text, @"then\s*('.+)", "Then\n$1", RegexOptions.IgnoreCase); Regex tplus = new Regex(@"^(while|for|if|elseif|class|function|sub|select\s+case|do|(private\s+|public\s+|friend\s+|protected\s+)?(shared\s+|mustinherit\s+|sealed\s+)?(function|class|sub|property|module))[\s]", RegexOptions.IgnoreCase); Regex singleLineIf = new Regex("then$", RegexOptions.IgnoreCase); Regex tabBecauseIf = new Regex(@"^if", RegexOptions.IgnoreCase); //Regex negateIf2 = new Regex(@"then$", RegexOptions.IgnoreCase); Regex tminus = new Regex(@"^(wend|until|loop|next|elseif|end\s+(if|function|sub|class|select|property))[\s]?", RegexOptions.IgnoreCase); Regex isLabel = new Regex(@"[^\s]:$"); Regex elif = new Regex(@"^elseif.+then$", RegexOptions.IgnoreCase); //special instructions for "select case" statements Regex casebound = new Regex(@"^(select case|end select)", RegexOptions.IgnoreCase); Regex caseitem = new Regex(@"^case\s", RegexOptions.IgnoreCase); SettingsObtainer obt = SettingsObtainer.CreateInstance(); string tabstr = obt.TabString; bool incase = false; //get rid of multiline rows text = Regex.Replace(text, "_[ \t]+\n[ \t]*", " "); string[] rows = text.Split('\n'); for (int ii = 0; ii < rows.Length; ii++) { int currTabc = 0; rows[ii] = Regex.Replace(Regex.Replace(rows[ii], @"\s+$", ""), @"^\s+", ""); rows[ii] = rows[ii].Replace("\n", "").Replace("\r", ""); if (casebound.IsMatch(rows[ii])) { if (incase) { tabcount--; incase = false; } else { incase = true; tabcount++; //I know I'm doubling the tab count, I want to } } if (tminus.IsMatch(rows[ii]) && !isLabel.IsMatch(rows[ii])) { tabcount--; } if (tabcount < 0) { tabcount = 0; } currTabc = tabcount; string currentLine = ""; //if (incase && !caseitem.IsMatch(rows[ii])) { // currTabc += 1; //} if (isLabel.IsMatch(rows[ii])) { currentLine = rows[ii]; } else if (incase && caseitem.IsMatch(rows[ii]) && tabcount > 0) { currentLine = tabstr.Times(tabcount - 1) + rows[ii]; } else if (rows[ii].ToLower().Trim() == "else" && tabcount > 0) { currentLine = tabstr.Times(tabcount - 1) + rows[ii]; } else { currentLine = tabstr.Times(currTabc) + rows[ii]; } if (tplus.IsMatch(rows[ii]) && !isLabel.IsMatch(rows[ii])) { if (tabBecauseIf.IsMatch(rows[ii])) { if (singleLineIf.IsMatch(rows[ii])) { tabcount++; } } else { tabcount++; } } currTabc = tabcount; if (currTabc < 0) { currTabc = 0; } rows[ii] = currentLine; } return(Regex.Replace(String.Join("\n", rows), "(\t| )Select\\s+Case", "Select Case", RegexOptions.IgnoreCase)); }
//were going to have to create a lexer for this guy private static string TabRightC(string code, int tabcount) { string[] keywords = { "abstract", "as", "base", "break", "case", "catch", "checked", "continue", "default", "delegate", "do", "else", "event", "explicit", "extern", "false", "finally", "fixed", "for", "foreach", "goto", "if", "implicit", "in", "interface", "internal", "is", "lock", "namespace", "new", "null", "object", "operator", "out", "override", "params", "private", "protected", "public", "readonly", "ref", "return", "sealed", "sizeof", "stackalloc", "switch", "this", "throw", "true", "try", "typeof", "unchecked", "unsafe", "using", "virtual", "while" }; string[] types = { "bool", "byte", "char", "class", "const", "decimal", "double", "enum", "float", "int", "long", "sbyte", "short", "static", "string", "struct", "uint", "ulong", "ushort", "void" }; bool inString = false; bool inComment = false; bool blockString = false; bool blockComment = false; string prevChar = String.Empty; string setPrvChr = String.Empty; SettingsObtainer obt = SettingsObtainer.CreateInstance(); string tabstr = obt.TabString; StringReader sr = new StringReader(code); StringBuilder codeOut = new StringBuilder(); string line; while ((line = sr.ReadLine()) != null) { int subtracttab = 0; StringBuilder buildLine = new StringBuilder(); if (!blockString && !blockComment) { line.Trim(); } prevChar = "\r\n"; for (int i = 0; i < line.Length; i++) { char c = line[i]; setPrvChr = c.ToString(); #region strings if (c == '"' || blockString) { buildLine.Append(c); inString = true; if (prevChar == "@") { blockString = true; int concurrentQuot = 0; while (++i < line.Length) { if (line[i] == '"') { concurrentQuot++; buildLine.Append(line[i]); } else if (concurrentQuot > 0) { if (concurrentQuot % 2 == 1) { i--; inString = false; blockString = false; break; } else { buildLine.Append(line[i]); } concurrentQuot = 0; } else { buildLine.Append(line[i]); } } } else //simple string { int concurrentSlash = 0; while (++i < line.Length) { buildLine.Append(line[i]); if (line[i] == '\\') { concurrentSlash++; } else { if (line[i] == '"') { if (concurrentSlash % 2 == 0) { inString = false; break; } } concurrentSlash = 0; } } } } #endregion #region block comments else if ((prevChar == "/" && c == '*') || blockComment) { buildLine.Append(c); if (!blockComment) { i++; prevChar = "*"; } inComment = true; blockComment = true; while (++i < line.Length) { buildLine.Append(line[i]); if (line[i] == '/' && prevChar == "*") { inComment = false; blockComment = false; break; } prevChar = line[i].ToString(); } } #endregion #region comments else if (prevChar == "/" && c == '/') { buildLine.Append(c); while (++i < line.Length) { buildLine.Append(line[i]); } } #endregion else if (c == '{' && !inComment && !inString) { buildLine.Append(c + "\n"); tabcount++; //subtracttab--; } else if (c == '}' && !inComment && !inString) { tabcount--; buildLine.AppendFormat("\n{0}{1}\n", tabstr.Times(tabcount), c); } else if (c == ';' && !inComment && !inString) { buildLine.AppendFormat("{0}\n", c); } else { buildLine.Append(c); } prevChar = setPrvChr; } if (blockString || blockComment) { subtracttab = tabcount * -1; } codeOut.AppendFormat("{0}{1}\n", tabstr.Times(tabcount + subtracttab), buildLine.ToString()); } string output = codeOut.ToString(); output = Regex.Replace(output, "\n+", "\n"); return(output); //return TabRightCold(code, tabcount); }
public UserFunctionsList() { _settings = SettingsObtainer.CreateInstance(); InitFunctions(); }