public override IEnumerable<IEditorScript> GetScripts(ICSharpCode.AvalonEdit.Document.ITextSource text, int offset)
 {
   var item = GetCurrentItem(text, offset);
   if (item != null)
   {
     var generator = new ScriptMenuGenerator()
     {
       Conn = _conn,
       ConnData = _connData,
       Items = new[] { item }
     };
     return generator.GetScripts().Concat(Enumerable.Repeat(new EditorScriptExecute() {
       Name = "Transform: Criteria to Where Clause",
       Execute = () =>
       {
         var doc = text as IDocument;
         if (doc != null)
         {
           var segment = GetCurrentQuerySegment(text, offset);
           var elem = XElement.Load(text.CreateReader(segment.Offset, segment.Length));
           AmlTransforms.CriteriaToWhereClause(elem);
           doc.Replace(segment.Offset, segment.Length, elem.ToString());
         }
         return Task.FromResult(true);
       }
     }, 1));
   }
   return Enumerable.Empty<IEditorScript>();
 }
 public override IEnumerable<IEditorScript> GetScripts(ICSharpCode.AvalonEdit.Document.ITextSource text, int offset)
 {
   var item = GetCurrentItem(text, offset);
   if (item != null)
   {
     return GetScripts(_conn, item.Type, item.Id).Concat(Enumerable.Repeat(new EditorScriptExecute() {
       Name = "Transform: Criteria to Where Clause",
       Execute = () =>
       {
         var doc = text as IDocument;
         if (doc != null)
         {
           var segment = GetCurrentQuerySegment(text, offset);
           var elem = XElement.Load(text.CreateReader(segment.Offset, segment.Length));
           AmlTransforms.CriteriaToWhereClause(elem);
           doc.Replace(segment.Offset, segment.Length, elem.ToString());
         }
       }
     }, 1));
   }
   return Enumerable.Empty<IEditorScript>();
 }
Exemplo n.º 3
0
    private string GetId(ICSharpCode.AvalonEdit.Document.IDocument doc, ICSharpCode.AvalonEdit.Editing.Caret caret)
    {
      string amlQuery;
      var settings = new System.Xml.XmlReaderSettings();
      System.IO.TextReader reader;

      if (this.Helper == null)
      {
        reader = doc.CreateReader();
      }
      else
      {
        amlQuery = this.Helper.GetCurrentQuery(doc, caret.Offset);
        var loc = doc.GetLocation(doc.IndexOf(amlQuery, 0, doc.TextLength, StringComparison.Ordinal));
        reader = new System.IO.StringReader(amlQuery);
        settings.LineNumberOffset = loc.Line;
      }

      string lastItemId = null;
      string lastId = null;
      var elems = new Stack<string>();

      using (reader)
      using (var xmlReader = System.Xml.XmlReader.Create(reader))
      {
        var lineInfo = (System.Xml.IXmlLineInfo)xmlReader;
        while (xmlReader.Read())
        {
          switch (xmlReader.NodeType)
          {
            case System.Xml.XmlNodeType.Element:
            case System.Xml.XmlNodeType.EndElement:
              if (lineInfo.LineNumber > this.editor.TextArea.Caret.Line
                || (lineInfo.LineNumber == this.editor.TextArea.Caret.Line && (lineInfo.LinePosition - 1) > this.editor.TextArea.Caret.Column))
              {
                return lastId ?? lastItemId;
              }
              break;
          }

          switch (xmlReader.NodeType)
          {
            case System.Xml.XmlNodeType.Element:
              switch (xmlReader.LocalName)
              {
                case "Item":
                  lastItemId = xmlReader.GetAttribute("id");
                  lastId = xmlReader.GetAttribute("id");
                  break;
              }
              if (!xmlReader.IsEmptyElement) elems.Push(xmlReader.LocalName);
              break;
            case System.Xml.XmlNodeType.Text:
              if (xmlReader.Value.IsGuid())
              {
                switch (elems.Peek())
                {
                  case "id":
                    lastItemId = xmlReader.Value;
                    break;
                  default:
                    lastId = xmlReader.Value;
                    break;
                }
              }
              break;
            case System.Xml.XmlNodeType.EndElement:
              lastId = null;
              if (elems.Pop() == "Item")
              {
                lastItemId = null;
              }
              break;
          }
        }
      }

      return null;
    }
Exemplo n.º 4
0
		public void IndentLine(ICSharpCode.AvalonEdit.Document.TextDocument document, DocumentLine line, bool TakeCaret)
		{
			if (line.PreviousLine == null)
				return;

			if (!DSettings.Instance.EnableSmartIndentation)
			{
				var t = document.GetText(line);
				int c=0;
				for(;c<t.Length && (t[c] == ' ' || t[c] == '\t');c++);

				RawlyIndentLine(t.Length==0 ? string.Empty : t.Substring(0, c+1), document, line);

				return;
			}

			var tr=document.CreateReader();
			var newIndent = D_Parser.Formatting.Indent.IndentEngineWrapper.CalculateIndent(tr, line.LineNumber, dEditor.Editor.Options.ConvertTabsToSpaces, dEditor.Editor.Options.IndentationSize);
			tr.Close();

			RawlyIndentLine(newIndent, document, line);
		}
Exemplo n.º 5
0
		public ICompilationUnit Parse(IProjectContent projectContent, string fileName, ICSharpCode.SharpDevelop.ITextBuffer fileContent)
		{
			using (ICSharpCode.NRefactory.IParser p = ICSharpCode.NRefactory.ParserFactory.CreateParser(ICSharpCode.NRefactory.SupportedLanguage.VBNet, fileContent.CreateReader())) {
				return Parse(p, fileName, projectContent);
			}
		}