コード例 #1
0
		public static IDocumentIndentEngine CreateEngine (string text)
		{
			var sb = new StringBuilder ();
			int offset = 0;
			for (int i = 0; i < text.Length; i++) {
				var ch = text [i];
				if (ch == '$') {
					offset = i;
					continue;
				}
				sb.Append (ch);
			}

			var tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			tww.ViewContent = content;
			content.ContentName = "/a.json";
			content.Data.MimeType = "application/json";

			content.Data.Text = sb.ToString ();
			var doc = new MonoDevelop.Ide.Gui.Document (tww);

			var csi = new JSonIndentEngine (content.Data, doc);
			var result = new CacheIndentEngine (csi);
			result.Update (content.Data, offset);
			return result;
		}
コード例 #2
0
		public OverridesImplementsDialog (MonoDevelop.Ide.Gui.Document editor, IType cls)
		{
			this.Build();
			this.editor = editor;
			this.cls = cls;

			// FIXME: title
			Title = GettextCatalog.GetString ("Override and/or implement members");

			store = new TreeStore (typeof (bool), typeof (Gdk.Pixbuf), typeof (string), typeof (bool), typeof (IMember));

			// Column #1
			TreeViewColumn nameCol = new TreeViewColumn ();
			nameCol.Title = GettextCatalog.GetString ("Name");
			nameCol.Expand = true;
			nameCol.Resizable = true;

			CellRendererToggle cbRenderer = new CellRendererToggle ();
			cbRenderer.Activatable = true;
			cbRenderer.Toggled += OnSelectToggled;
			nameCol.PackStart (cbRenderer, false);
			nameCol.AddAttribute (cbRenderer, "active", colCheckedIndex);

			CellRendererPixbuf iconRenderer = new CellRendererPixbuf ();
			nameCol.PackStart (iconRenderer, false);
			nameCol.AddAttribute (iconRenderer, "pixbuf", colIconIndex);

			CellRendererText nameRenderer = new CellRendererText ();
			nameRenderer.Ellipsize = Pango.EllipsizeMode.End;
			nameCol.PackStart (nameRenderer, true);
			nameCol.AddAttribute (nameRenderer, "text", colNameIndex);

			treeview.AppendColumn (nameCol);

			// Column #2
			CellRendererToggle explicitRenderer = new CellRendererToggle ();
			explicitRenderer.Activatable = true;
			explicitRenderer.Xalign = 0.0f;
			explicitRenderer.Toggled += OnExplicitToggled;
			TreeViewColumn explicitCol = new TreeViewColumn ();
			explicitCol.Title = GettextCatalog.GetString ("Explicit");
			explicitCol.PackStart (explicitRenderer, true);
			explicitCol.SetCellDataFunc (explicitRenderer, new TreeCellDataFunc (RenderExplicitCheckbox));
			explicitCol.AddAttribute (explicitRenderer, "active", colExplicitIndex);
			treeview.AppendColumn (explicitCol);

			store.SetSortColumnId (colNameIndex, SortType.Ascending);
			treeview.Model = store;

			buttonCancel.Clicked += OnCancelClicked;
			buttonOk.Clicked += OnOKClicked;
			buttonSelectAll.Clicked += delegate { SelectAll (true); };
			buttonUnselectAll.Clicked += delegate { SelectAll (false); };

			refactorer = IdeApp.Workspace.GetCodeRefactorer (IdeApp.ProjectOperations.CurrentSelectedSolution);
			ambience = AmbienceService.GetAmbienceForFile (cls.CompilationUnit.FileName);
			PopulateTreeView ();
			UpdateOKButton ();
		}
コード例 #3
0
		public static CompletionDataList CreateProvider (string text, string extension, bool isCtrlSpace)
		{
			string parsedText;
			string editorText;
			int cursorPosition = text.IndexOf ('$');
			int endPos = text.IndexOf ('$', cursorPosition + 1);
			if (endPos == -1)
				parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1);
			else {
				parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1);
				editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1);
				cursorPosition = endPos - 1; 
			}
			var tww = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow ();
			var sev = new MonoDevelop.CSharpBinding.Tests.TestViewContent ();
			var project = new AspNetAppProject ("C#");
			project.FileName = UnitTests.TestBase.GetTempFile (".csproj");
			
			string file = UnitTests.TestBase.GetTempFile (extension);
			project.AddFile (file);
			
			ProjectDomService.Load (project);
			ProjectDom dom = ProjectDomService.GetProjectDom (project);
			dom.ForceUpdate (true);
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			ProjectDomService.Parse (project, file, delegate { return parsedText; });
			
			sev.Project = project;
			sev.ContentName = file;
			sev.Text = editorText;
			sev.CursorPosition = cursorPosition;
			tww.ViewContent = sev;
			var doc = new MonoDevelop.Ide.Gui.Document (tww);
			doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser ().Parse (null, sev.ContentName, parsedText);
			foreach (var e in doc.ParsedDocument.Errors)
				Console.WriteLine (e);
			
			var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension ();
			Initialize (textEditorCompletion, doc);
			
			int triggerWordLength = 1;
			CodeCompletionContext ctx = new CodeCompletionContext ();
			ctx.TriggerOffset = sev.CursorPosition;
			int line, column;
			sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column);
			ctx.TriggerLine = line;
			ctx.TriggerLineOffset = column - 1;
			
			if (isCtrlSpace)
				return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList;
			else
				return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList;
		}
コード例 #4
0
		public ContextActionWidget (ContextActionEditorExtension ext, MonoDevelop.Ide.Gui.Document document, DomLocation loc, List<ContextAction> fixes)
		{
			this.ext = ext;
			this.document = document;
			this.loc = loc;
			this.fixes = fixes;
			Events = Gdk.EventMask.AllEventsMask;
			icon = ImageService.GetPixbuf ("md-text-quickfix", Gtk.IconSize.Menu);
			this.SetSizeRequest (Math.Max ((int)document.Editor.LineHeight , icon.Width) + 4, (int)document.Editor.LineHeight + 4);
			ShowAll ();
			document.Editor.Parent.EditorOptionsChanged += HandleDocumentEditorParentEditorOptionsChanged;
			;
		}
コード例 #5
0
        public override void CompleteStatement(MonoDevelop.Ide.Gui.Document doc)
        {
            var file          = doc.Editor;
            var caretLocation = file.Caret.Location;

            int pos = file.LocationToOffset(caretLocation.Line + 1, 1);
            var line = new StringBuilder();
            int lineNr = caretLocation.Line + 1, column = 1, maxColumn = 1, lastPos = pos;

            if (true)
            {
                while (lineNr == caretLocation.Line + 1)
                {
                    maxColumn = column;
                    lastPos   = pos;
                    line.Append(file.GetCharAt(pos));
                    pos++;
                    var loc = file.OffsetToLocation(pos);
                    lineNr = loc.Line;
                    column = loc.Column;
                }
            }
            string trimmedline = line.ToString().Trim();
            string indent      = line.ToString().Substring(0, line.Length - line.ToString().TrimStart(' ', '\t').Length);

            if (trimmedline.EndsWith(";") || trimmedline.EndsWith("{"))
            {
                file.Caret.Location = caretLocation;
                return;
            }
            int caretLine   = caretLocation.Line;
            int caretColumn = caretLocation.Column;

            if (trimmedline.StartsWith("if") ||
                trimmedline.StartsWith("while") ||
                trimmedline.StartsWith("switch") ||
                trimmedline.StartsWith("for") ||
                trimmedline.StartsWith("foreach"))
            {
                if (!trimmedline.EndsWith(")"))
                {
                    file.Insert(lastPos, " () {" + file.EolMarker + indent + file.Options.IndentationString + file.EolMarker + indent + "}");
                    caretColumn = maxColumn + 1;
                }
                else
                {
                    file.Insert(lastPos, " {" + file.EolMarker + indent + file.Options.IndentationString + file.EolMarker + indent + "}");
                    caretColumn = indent.Length + 1;
                    caretLine++;
                }
            }
            else if (trimmedline.StartsWith("do"))
            {
                file.Insert(lastPos, " {" + file.EolMarker + indent + file.Options.IndentationString + file.EolMarker + indent + "} while ();");
                caretColumn = indent.Length + 1;
                caretLine++;
            }
            else
            {
                file.Insert(lastPos, ";" + file.EolMarker + indent);
                caretColumn = indent.Length;
                caretLine++;
            }
            file.Caret.Location = new DocumentLocation(caretLine, caretColumn);
        }
コード例 #6
0
 public static void Format(MonoDevelop.Ide.Gui.Document data, TextLocation startLocation, TextLocation endLocation, bool exact = true)
 {
     Format(data, data.Editor.LocationToOffset(startLocation), data.Editor.LocationToOffset(endLocation), exact);
 }
コード例 #7
0
        public override void AddLocalNamespaceImport(MonoDevelop.Ide.Gui.Document doc, string nsName, TextLocation caretLocation)
        {
            var parsedDocument = doc.ParsedDocument;
            var unit           = parsedDocument.GetAst <SyntaxTree> ();

            if (unit == null)
            {
                return;
            }

            var nsDecl = unit.GetNodeAt <NamespaceDeclaration> (caretLocation);

            if (nsDecl == null)
            {
                AddGlobalNamespaceImport(doc, nsName);
                return;
            }

            var policy = doc.Project != null?doc.Project.Policies.Get <PlayScriptFormattingPolicy> () : null;

            if (policy == null)
            {
                policy = Policy;
            }


            var node = SearchUsingInsertionPoint(nsDecl);

            var text  = new StringBuilder();
            int lines = 0;

            if (InsertUsingAfter(node))
            {
                lines = policy.BlankLinesBeforeUsings + 1;
                while (lines-- > 0)
                {
                    text.Append(doc.Editor.EolMarker);
                }
            }

            string indent = doc.Editor.GetLineIndent(nsDecl.StartLocation.Line) + "\t";

            text.Append(indent);
            text.Append("using ");
            text.Append(nsName);
            text.Append(";");

            int          offset;
            TextLocation loc;

            if (node != null)
            {
                loc = InsertUsingAfter(node) ? node.EndLocation : node.StartLocation;
            }
            else
            {
                loc = nsDecl.LBraceToken.EndLocation;
            }
            offset = doc.Editor.LocationToOffset(loc);

            lines  = policy.BlankLinesAfterUsings;
            lines -= CountBlankLines(doc, doc.Editor.OffsetToLineNumber(offset) + 1);
            if (lines > 0)
            {
                text.Append(doc.Editor.EolMarker);
            }
            while (lines-- > 0)
            {
                text.Append(doc.Editor.EolMarker);
            }

            doc.Editor.Insert(offset, text.ToString());
        }
コード例 #8
0
        static FormattingChanges GetFormattingChanges(PolicyContainer policyParent, IEnumerable <string> mimeTypeChain, MonoDevelop.Ide.Gui.Document document, string input, DomRegion formattingRegion, ref int formatStartOffset, ref int formatLength, bool formatLastStatementOnly)
        {
            using (var stubData = TextEditorData.CreateImmutable(input)) {
                stubData.Document.FileName = document.FileName;
                var  parser          = document.HasProject ? new PlayScriptParser(TypeSystemParser.GetCompilerArguments(document.Project)) : new PlayScriptParser();
                var  compilationUnit = parser.Parse(stubData);
                bool hadErrors       = parser.HasErrors;
                if (hadErrors)
                {
                    using (var stubData2 = TextEditorData.CreateImmutable(input + "}")) {
                        compilationUnit = parser.Parse(stubData2);
                        hadErrors       = parser.HasErrors;
                    }
                }
                // try it out, if the behavior is better when working only with correct code.
                if (hadErrors)
                {
                    return(null);
                }

                var policy = policyParent.Get <PlayScriptFormattingPolicy> (mimeTypeChain);

                var formattingVisitor = new ICSharpCode.NRefactory.PlayScript.CSharpFormatter(policy.CreateOptions(), document.Editor.CreateNRefactoryTextEditorOptions());
                formattingVisitor.FormattingMode = FormattingMode.Intrusive;
                formattingVisitor.AddFormattingRegion(formattingRegion);


                var changes = formattingVisitor.AnalyzeFormatting(stubData.Document, compilationUnit);

                if (formatLastStatementOnly)
                {
                    AstNode node = compilationUnit.GetAdjacentNodeAt <Statement> (stubData.OffsetToLocation(formatStartOffset + formatLength - 1));
                    if (node != null)
                    {
                        while (node.Role == Roles.EmbeddedStatement || node.Role == IfElseStatement.TrueRole || node.Role == IfElseStatement.FalseRole)
                        {
                            node = node.Parent;
                        }
                        // include indentation if node starts in new line
                        var formatNode = node.GetPrevNode();
                        if (formatNode.Role != Roles.NewLine)
                        {
                            formatNode = node;
                        }
                        var start = stubData.LocationToOffset(formatNode.StartLocation);
                        if (start > formatStartOffset)
                        {
                            var end = stubData.LocationToOffset(node.EndLocation);
                            formatStartOffset = start;
                            formatLength      = end - start;
                        }
                    }
                }
                return(changes);
            }
        }
コード例 #9
0
 public static void Format(MonoDevelop.Ide.Gui.Document data)
 {
     Format(data, 0, data.Editor.Length);
 }
コード例 #10
0
        public void InsertAtCaret(MonoDevelop.Ide.Gui.Document document)
        {
            var tag = GetTextWithDirective(document, true);

            document.Editor.InsertAtCaret(tag);
        }
コード例 #11
0
ファイル: Commands.cs プロジェクト: tpetrina/LiveCode
		void BindActiveDoc (object sender, EventArgs e)
		{
			var doc = IdeApp.Workbench.ActiveDocument;
			if (boundDoc == doc) {
				return;
			}
			if (boundDoc != null) {				
				boundDoc.DocumentParsed -= ActiveDoc_DocumentParsed;
			}
			boundDoc = doc;
			if (boundDoc != null) {
				boundDoc.DocumentParsed += ActiveDoc_DocumentParsed;
			}
		}
コード例 #12
0
ファイル: CodeAction.cs プロジェクト: zheref/monodevelop
 /// <summary>
 /// Performs the specified code action in document at loc.
 /// </summary>
 public abstract void Run(MonoDevelop.Ide.Gui.Document document, TextLocation loc);
コード例 #13
0
ファイル: CodeAction.cs プロジェクト: zheref/monodevelop
 public override void Run(MonoDevelop.Ide.Gui.Document document, TextLocation loc)
 {
     act(document, loc);
 }
コード例 #14
0
        public IEnumerable <MemberReference> FindInDocument(MonoDevelop.Ide.Gui.Document doc)
        {
            if (string.IsNullOrEmpty(memberName))
            {
                return(Enumerable.Empty <MemberReference> ());
            }
            var editor         = doc.Editor;
            var parsedDocument = doc.ParsedDocument;

            if (parsedDocument == null)
            {
                return(Enumerable.Empty <MemberReference> ());
            }
            var unit   = parsedDocument.GetAst <SyntaxTree> ();
            var file   = parsedDocument.ParsedFile as CSharpUnresolvedFile;
            var result = new List <MemberReference> ();

            foreach (var obj in searchedMembers)
            {
                if (obj is IEntity)
                {
                    var entity = (IEntity)obj;

                    // May happen for anonymous types since empty constructors are always generated.
                    // But there is no declaring type definition for them - we filter out this case.
                    if (entity.EntityType == EntityType.Constructor && entity.DeclaringTypeDefinition == null)
                    {
                        continue;
                    }

                    refFinder.FindReferencesInFile(refFinder.GetSearchScopes(entity), file, unit, doc.Compilation, (astNode, r) => {
                        if (IsNodeValid(obj, astNode))
                        {
                            result.Add(GetReference(doc.Project, r, astNode, unit, editor.FileName, editor));
                        }
                    }, CancellationToken.None);
                }
                else if (obj is IVariable)
                {
                    refFinder.FindLocalReferences((IVariable)obj, file, unit, doc.Compilation, (astNode, r) => {
                        if (IsNodeValid(obj, astNode))
                        {
                            result.Add(GetReference(doc.Project, r, astNode, unit, editor.FileName, editor));
                        }
                    }, CancellationToken.None);
                }
                else if (obj is ITypeParameter)
                {
                    refFinder.FindTypeParameterReferences((ITypeParameter)obj, file, unit, doc.Compilation, (astNode, r) => {
                        if (IsNodeValid(obj, astNode))
                        {
                            result.Add(GetReference(doc.Project, r, astNode, unit, editor.FileName, editor));
                        }
                    }, CancellationToken.None);
                }
                else if (obj is INamespace)
                {
                    var entity = (INamespace)obj;
                    refFinder.FindReferencesInFile(refFinder.GetSearchScopes(entity), file, unit, doc.Compilation, (astNode, r) => {
                        if (IsNodeValid(obj, astNode))
                        {
                            result.Add(GetReference(doc.Project, r, astNode, unit, editor.FileName, editor));
                        }
                    }, CancellationToken.None);
                }
            }
            return(result);
        }
コード例 #15
0
 public virtual void OnTheFlyFormat(MonoDevelop.Ide.Gui.Document doc, int startOffset, int endOffset)
 {
     throw new NotSupportedException();
 }
コード例 #16
0
				public TestRunner (MonoDevelop.Ide.Gui.Document doc, string testCase, bool debug)
				{
					this.doc = doc;
					this.testCase = testCase;
					this.debug = debug;
				}
コード例 #17
0
			public UnitTestMarker(NUnitVisitor.UnitTest unitTest, MonoDevelop.Ide.Gui.Document doc)
			{
				this.unitTest = unitTest;
				this.doc = doc;
			}
コード例 #18
0
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     return(doc.IsFile && DLanguageBinding.IsDFile(doc.FileName));
 }
コード例 #19
0
			public MdNodeOutputAction (MonoDevelop.Ide.Gui.Document doc, int offset, int removedChars, NodeOutput output) : base (offset, removedChars, output)
			{
				if (doc == null)
					throw new ArgumentNullException ("doc");
				if (output == null)
					throw new ArgumentNullException ("output");
				this.doc = doc;
			}
コード例 #20
0
 public UnitTestMarker(NUnitVisitor.UnitTest unitTest, MonoDevelop.Ide.Gui.Document doc)
 {
     this.unitTest = unitTest;
     this.doc      = doc;
 }
コード例 #21
0
		public CSharpSelectionSurroundingProvider (MonoDevelop.Ide.Gui.Document document)
		{
			this.document = document;
		}
コード例 #22
0
 public EncapsulateFieldDialog(MonoDevelop.Ide.Gui.Document editor, ITypeResolveContext ctx, IType declaringType)
     : this(editor, declaringType, null)
 {
 }
コード例 #23
0
		private EncapsulateFieldDialog (MonoDevelop.Ide.Gui.Document editor, IType declaringType, IField field)
		{
			this.editor = editor;
			this.declaringType = declaringType;
			this.Build ();

			Title = GettextCatalog.GetString ("Encapsulate Fields");
			buttonOk.Sensitive = true;
			store = new ListStore (typeof (bool), typeof(string), typeof (string), typeof (string), typeof (bool), typeof (IField));
			visibilityStore = new ListStore (typeof (string));

			// Column #1
			CellRendererToggle cbRenderer = new CellRendererToggle ();
			cbRenderer.Activatable = true;
			cbRenderer.Toggled += OnSelectedToggled;
			TreeViewColumn cbCol = new TreeViewColumn ();
			cbCol.Title = "";
			cbCol.PackStart (cbRenderer, false);
			cbCol.AddAttribute (cbRenderer, "active", colCheckedIndex);
			treeview.AppendColumn (cbCol);

			// Column #2
			CellRendererText fieldRenderer = new CellRendererText ();
			fieldRenderer.Weight = (int) Pango.Weight.Bold;
			TreeViewColumn fieldCol = new TreeViewColumn ();
			fieldCol.Title = GettextCatalog.GetString ("Field");
			fieldCol.Expand = true;
			fieldCol.PackStart (fieldRenderer, true);
			fieldCol.AddAttribute (fieldRenderer, "text", colFieldNameIndex);
			treeview.AppendColumn (fieldCol);

			// Column #3
			CellRendererText propertyRenderer = new CellRendererText ();
			propertyRenderer.Editable = true;
			propertyRenderer.Edited += new EditedHandler (OnPropertyEdited);
			TreeViewColumn propertyCol = new TreeViewColumn ();
			propertyCol.Title = GettextCatalog.GetString ("Property");
			propertyCol.Expand = true;
			propertyCol.PackStart (propertyRenderer, true);
			propertyCol.AddAttribute (propertyRenderer, "text", colPropertyNameIndex);
			propertyCol.SetCellDataFunc (propertyRenderer, new TreeCellDataFunc (RenderPropertyName));
			treeview.AppendColumn (propertyCol);

			// Column #4
			CellRendererCombo visiComboRenderer = new CellRendererCombo ();
			visiComboRenderer.Model = visibilityStore;
			visiComboRenderer.Editable = true;
			visiComboRenderer.Edited += new EditedHandler (OnVisibilityEdited);
			visiComboRenderer.HasEntry = false;
			visiComboRenderer.TextColumn = 0;

			TreeViewColumn visiCol = new TreeViewColumn ();
			visiCol.Title = GettextCatalog.GetString ("Visibility");
			visiCol.PackStart (visiComboRenderer, false);
			visiCol.AddAttribute (visiComboRenderer, "text", colVisibilityIndex);
			treeview.AppendColumn (visiCol);

			// Column #5
			CellRendererToggle roRenderer = new CellRendererToggle ();
			roRenderer.Activatable = true;
			roRenderer.Xalign = 0.0f;
			roRenderer.Toggled += new ToggledHandler (OnReadOnlyToggled);
			TreeViewColumn roCol = new TreeViewColumn ();
			roCol.Title = GettextCatalog.GetString ("Read only");
			roCol.PackStart (roRenderer, false);
			roCol.AddAttribute (roRenderer, "active", colReadOnlyIndex);
			treeview.AppendColumn (roCol);

			visibilityStore.AppendValues ("Public");
			visibilityStore.AppendValues ("Private");
			visibilityStore.AppendValues ("Protected");
			visibilityStore.AppendValues ("Internal");

			treeview.Model = store;

			foreach (IField ifield in declaringType.Fields) {
				bool enabled = field != null && (field.Name == ifield.Name);
				string propertyName = GeneratePropertyName (ifield.Name);
				store.AppendValues (enabled, ifield.Name, propertyName,
				                    "Public", ifield.IsReadonly || ifield.IsLiteral, ifield);

				if (enabled)
					CheckAndUpdateConflictMessage (propertyName, false);
			}

			store.SetSortColumnId (colFieldNameIndex, SortType.Ascending);
			buttonSelectAll.Clicked += OnSelectAllClicked;
			buttonUnselectAll.Clicked += OnUnselectAllClicked;
			buttonOk.Clicked += OnOKClicked;
			buttonCancel.Clicked += OnCancelClicked;

			UpdateOKButton ();
		}
コード例 #24
0
 public EncapsulateFieldDialog(MonoDevelop.Ide.Gui.Document editor, ITypeResolveContext ctx, IField field)
     : this(editor, field.DeclaringType, field)
 {
 }
コード例 #25
0
 public override void Run(MonoDevelop.Ide.Gui.Document document, TextLocation loc)
 {
     Action.Fix();
 }
コード例 #26
0
        private EncapsulateFieldDialog(MonoDevelop.Ide.Gui.Document editor, IType declaringType, IField field)
        {
            this.editor        = editor;
            this.declaringType = declaringType;
            this.Build();

            Title = GettextCatalog.GetString("Encapsulate Fields");
            buttonOk.Sensitive = true;
            store           = new ListStore(typeof(bool), typeof(string), typeof(string), typeof(string), typeof(bool), typeof(IField));
            visibilityStore = new ListStore(typeof(string));

            // Column #1
            CellRendererToggle cbRenderer = new CellRendererToggle();

            cbRenderer.Activatable = true;
            cbRenderer.Toggled    += OnSelectedToggled;
            TreeViewColumn cbCol = new TreeViewColumn();

            cbCol.Title = "";
            cbCol.PackStart(cbRenderer, false);
            cbCol.AddAttribute(cbRenderer, "active", colCheckedIndex);
            treeview.AppendColumn(cbCol);

            // Column #2
            CellRendererText fieldRenderer = new CellRendererText();

            fieldRenderer.Weight = (int)Pango.Weight.Bold;
            TreeViewColumn fieldCol = new TreeViewColumn();

            fieldCol.Title  = GettextCatalog.GetString("Field");
            fieldCol.Expand = true;
            fieldCol.PackStart(fieldRenderer, true);
            fieldCol.AddAttribute(fieldRenderer, "text", colFieldNameIndex);
            treeview.AppendColumn(fieldCol);

            // Column #3
            CellRendererText propertyRenderer = new CellRendererText();

            propertyRenderer.Editable = true;
            propertyRenderer.Edited  += new EditedHandler(OnPropertyEdited);
            TreeViewColumn propertyCol = new TreeViewColumn();

            propertyCol.Title  = GettextCatalog.GetString("Property");
            propertyCol.Expand = true;
            propertyCol.PackStart(propertyRenderer, true);
            propertyCol.AddAttribute(propertyRenderer, "text", colPropertyNameIndex);
            propertyCol.SetCellDataFunc(propertyRenderer, new TreeCellDataFunc(RenderPropertyName));
            treeview.AppendColumn(propertyCol);

            // Column #4
            CellRendererCombo visiComboRenderer = new CellRendererCombo();

            visiComboRenderer.Model      = visibilityStore;
            visiComboRenderer.Editable   = true;
            visiComboRenderer.Edited    += new EditedHandler(OnVisibilityEdited);
            visiComboRenderer.HasEntry   = false;
            visiComboRenderer.TextColumn = 0;

            TreeViewColumn visiCol = new TreeViewColumn();

            visiCol.Title = GettextCatalog.GetString("Visibility");
            visiCol.PackStart(visiComboRenderer, false);
            visiCol.AddAttribute(visiComboRenderer, "text", colVisibilityIndex);
            treeview.AppendColumn(visiCol);

            // Column #5
            CellRendererToggle roRenderer = new CellRendererToggle();

            roRenderer.Activatable = true;
            roRenderer.Xalign      = 0.0f;
            roRenderer.Toggled    += new ToggledHandler(OnReadOnlyToggled);
            TreeViewColumn roCol = new TreeViewColumn();

            roCol.Title = GettextCatalog.GetString("Read only");
            roCol.PackStart(roRenderer, false);
            roCol.AddAttribute(roRenderer, "active", colReadOnlyIndex);
            treeview.AppendColumn(roCol);

            visibilityStore.AppendValues("Public");
            visibilityStore.AppendValues("Private");
            visibilityStore.AppendValues("Protected");
            visibilityStore.AppendValues("Internal");

            treeview.Model = store;

            foreach (IField ifield in declaringType.Fields)
            {
                bool   enabled      = field != null && (field.Name == ifield.Name);
                string propertyName = GeneratePropertyName(ifield.Name);
                store.AppendValues(enabled, ifield.Name, propertyName,
                                   "Public", ifield.IsReadonly || ifield.IsLiteral, ifield);

                if (enabled)
                {
                    CheckAndUpdateConflictMessage(propertyName, false);
                }
            }

            store.SetSortColumnId(colFieldNameIndex, SortType.Ascending);
            buttonSelectAll.Clicked   += OnSelectAllClicked;
            buttonUnselectAll.Clicked += OnUnselectAllClicked;
            buttonOk.Clicked          += OnOKClicked;
            buttonCancel.Clicked      += OnCancelClicked;

            UpdateOKButton();
        }
コード例 #27
0
        public static void Format(PolicyContainer policyParent, IEnumerable <string> mimeTypeChain, MonoDevelop.Ide.Gui.Document data, int startOffset, int endOffset, bool exact, bool formatLastStatementOnly = false)
        {
            if (data.ParsedDocument == null)
            {
                return;
            }
            var ext = data.GetContent <CSharpCompletionTextEditorExtension> ();

            if (ext == null)
            {
                return;
            }
            string    text;
            int       formatStartOffset, formatLength, realTextDelta;
            DomRegion formattingRegion = DomRegion.Empty;
            int       startDelta       = 1;

            if (exact)
            {
                text = data.Editor.Text;
                var seg  = ext.typeSystemSegmentTree.GetMemberSegmentAt(startOffset);
                var seg2 = ext.typeSystemSegmentTree.GetMemberSegmentAt(endOffset);
                if (seg != null && seg == seg2)
                {
                    var member = seg.Entity;
                    if (member == null || member.Region.IsEmpty || member.BodyRegion.End.IsEmpty)
                    {
                        return;
                    }

                    text             = BuildStub(data, seg, startOffset, endOffset, out formatStartOffset);
                    startDelta       = startOffset - seg.Offset;
                    formatLength     = endOffset - startOffset + startDelta;
                    realTextDelta    = seg.Offset - formatStartOffset;
                    formattingRegion = new DomRegion(data.Editor.OffsetToLocation(formatStartOffset), data.Editor.OffsetToLocation(endOffset));
                }
                else
                {
                    formatStartOffset = startOffset;
                    formatLength      = endOffset - startOffset;
                    realTextDelta     = 0;
                    formattingRegion  = new DomRegion(data.Editor.OffsetToLocation(startOffset), data.Editor.OffsetToLocation(endOffset));
                }
            }
            else
            {
                var seg = ext.typeSystemSegmentTree.GetMemberSegmentAt(startOffset - 1);
                if (seg == null)
                {
                    return;
                }
                var member = seg.Entity;
                if (member == null)
                {
                    return;
                }

                // Build stub
                text             = BuildStub(data, seg, startOffset, endOffset, out formatStartOffset);
                formattingRegion = new DomRegion(data.Editor.OffsetToLocation(formatStartOffset), data.Editor.OffsetToLocation(endOffset));

                formatLength  = endOffset - seg.Offset;
                realTextDelta = seg.Offset - formatStartOffset;
            }
            // Get changes from formatting visitor
            var changes = GetFormattingChanges(policyParent, mimeTypeChain, data, text, formattingRegion, ref formatStartOffset, ref formatLength, formatLastStatementOnly);

            if (changes == null)
            {
                return;
            }

            // Do the actual formatting
//			var originalVersion = data.Editor.Document.Version;

            using (var undo = data.Editor.OpenUndoGroup()) {
                try {
                    changes.ApplyChanges(formatStartOffset + startDelta, Math.Max(0, formatLength - startDelta - 1), delegate(int replaceOffset, int replaceLength, string insertText) {
                        int translatedOffset = realTextDelta + replaceOffset;
                        data.Editor.Document.CommitLineUpdate(data.Editor.OffsetToLineNumber(translatedOffset));
                        data.Editor.Replace(translatedOffset, replaceLength, insertText);
                    }, (replaceOffset, replaceLength, insertText) => {
                        int translatedOffset = realTextDelta + replaceOffset;
                        if (translatedOffset < 0 || translatedOffset + replaceLength > data.Editor.Length)
                        {
                            return(true);
                        }
                        return(data.Editor.GetTextAt(translatedOffset, replaceLength) == insertText);
                    });
                } catch (Exception e) {
                    LoggingService.LogError("Error in on the fly formatter", e);
                }

//				var currentVersion = data.Editor.Document.Version;
//				data.Editor.Caret.Offset = originalVersion.MoveOffsetTo (currentVersion, caretOffset, ICSharpCode.NRefactory.Editor.AnchorMovementType.Default);
            }
        }
コード例 #28
0
 /// <summary>
 /// Gets all the code actions in document at given location.
 /// </summary>
 public abstract IEnumerable <CodeAction> GetActions(MonoDevelop.Ide.Gui.Document document, object refactoringContext, TextLocation loc, CancellationToken cancellationToken);
コード例 #29
0
 public static void Format(MonoDevelop.Ide.Gui.Document data, TextLocation location)
 {
     Format(data, location, location, false);
 }
コード例 #30
0
			public UnitTestMarker(UnitTestLocation unitTest, MonoDevelop.Ide.Gui.Document doc)
			{
				this.unitTest = unitTest;
				this.doc = doc;
			}
コード例 #31
0
        /// <summary>
        /// Builds a compileable stub file out of an entity.
        /// </summary>
        /// <returns>
        /// A string representing the stub
        /// </returns>
        /// <param name='memberStartOffset'>
        /// The offset where the member starts in the returned text.
        /// </param>
        static string BuildStub(MonoDevelop.Ide.Gui.Document data, CSharpCompletionTextEditorExtension.TypeSystemTreeSegment seg, int startOffset, int endOffset, out int memberStartOffset)
        {
            var pf = data.ParsedDocument.ParsedFile as CSharpUnresolvedFile;

            if (pf == null)
            {
                memberStartOffset = 0;
                return(null);
            }

            var sb = new StringBuilder();

            int closingBrackets = 0;
            // use the member start location to determine the using scope, because this information is in sync, the position in
            // the file may have changed since last parse run (we have up 2 date locations from the type segment tree).
            var scope = pf.GetUsingScope(seg.Entity.Region.Begin);

            while (scope != null && !string.IsNullOrEmpty(scope.NamespaceName))
            {
                // Hack: some syntax errors lead to invalid namespace names.
                if (scope.NamespaceName.EndsWith("<invalid>", StringComparison.Ordinal))
                {
                    scope = scope.Parent;
                    continue;
                }
                sb.Append("namespace Stub {");
                sb.Append(data.Editor.EolMarker);
                closingBrackets++;
                while (scope.Parent != null && scope.Parent.Region == scope.Region)
                {
                    scope = scope.Parent;
                }
                scope = scope.Parent;
            }

            var parent = seg.Entity.DeclaringTypeDefinition;

            while (parent != null)
            {
                sb.Append("class " + parent.Name + " {");
                sb.Append(data.Editor.EolMarker);
                closingBrackets++;
                parent = parent.DeclaringTypeDefinition;
            }

            memberStartOffset = sb.Length;
            var text = data.Editor.GetTextBetween(seg.Offset, endOffset);

            sb.Append(text);

            var lex = new CSharpCompletionEngineBase.MiniLexer(text);

            lex.Parse(ch => {
                if (lex.IsInString || lex.IsInChar || lex.IsInVerbatimString || lex.IsInSingleComment || lex.IsInMultiLineComment || lex.IsInPreprocessorDirective)
                {
                    return;
                }
                if (ch == '{')
                {
                    closingBrackets++;
                }
                else if (ch == '}')
                {
                    closingBrackets--;
                }
            });


            // Insert at least caret column eol markers otherwise the reindent of the generated closing bracket
            // could interfere with the current indentation.
            var endLocation = data.Editor.OffsetToLocation(endOffset);

            for (int i = 0; i <= endLocation.Column; i++)
            {
                sb.Append(data.Editor.EolMarker);
            }
            sb.Append(data.Editor.EolMarker);
            sb.Append(new string ('}', closingBrackets));
            return(sb.ToString());
        }
コード例 #32
0
 public override void OnTheFlyFormat(MonoDevelop.Ide.Gui.Document doc, int startOffset, int endOffset)
 {
     OnTheFlyFormatter.Format(doc, startOffset, endOffset);
 }
コード例 #33
0
        public override string GetShortTypeString(MonoDevelop.Ide.Gui.Document doc, IType type)
        {
            var shortType = CreateShortType(doc.Compilation, doc.ParsedDocument.ParsedFile as CSharpUnresolvedFile, doc.Editor.Caret.Location, type);

            return(OutputNode(doc, shortType));
        }
コード例 #34
0
ファイル: CodeTemplate.cs プロジェクト: zheref/monodevelop
        /// <summary>
        /// Don't use this unless you're implementing ICodeTemplateWidget. Use Insert instead.
        /// </summary>
        public TemplateResult InsertTemplateContents(MonoDevelop.Ide.Gui.Document document)
        {
            Mono.TextEditor.TextEditorData data = document.Editor;

            int offset = data.Caret.Offset;
//			string leadingWhiteSpace = GetLeadingWhiteSpace (editor, editor.CursorLine);

            var context = new TemplateContext {
                Template       = this,
                Document       = document,
                ParsedDocument = document.ParsedDocument != null ? document.ParsedDocument.ParsedFile : null,
                InsertPosition = data.Caret.Location,
                LineIndent     = data.Document.GetLineIndent(data.Caret.Line),
                TemplateCode   = Code
            };

            if (data.IsSomethingSelected)
            {
                int start = data.SelectionRange.Offset;
                while (Char.IsWhiteSpace(data.Document.GetCharAt(start)))
                {
                    start++;
                }
                int end = data.SelectionRange.EndOffset;
                while (Char.IsWhiteSpace(data.Document.GetCharAt(end - 1)))
                {
                    end--;
                }
                context.LineIndent   = data.Document.GetLineIndent(data.Document.OffsetToLineNumber(start));
                context.SelectedText = RemoveIndent(data.Document.GetTextBetween(start, end), context.LineIndent);
                data.Remove(start, end - start);
                offset = start;
            }
            else
            {
                string word = GetWordBeforeCaret(data).Trim();
                if (word.Length > 0)
                {
                    offset = DeleteWordBeforeCaret(data);
                }
            }

            TemplateResult template = FillVariables(context);

            template.InsertPosition = offset;
            document.Editor.Insert(offset, template.Code);

            int newoffset;

            if (template.CaretEndOffset >= 0)
            {
                newoffset = offset + template.CaretEndOffset;
            }
            else
            {
                newoffset = offset + template.Code.Length;
            }

            document.Editor.Caret.Location = document.Editor.OffsetToLocation(newoffset);

/*			if (PropertyService.Get ("OnTheFlyFormatting", false)) {
 *                              string mt = DesktopService.GetMimeTypeForUri (document.FileName);
 *                              var formatter = MonoDevelop.Ide.CodeFormatting.CodeFormatterService.GetFormatter (mt);
 *                              if (formatter != null && formatter.SupportsOnTheFlyFormatting) {
 *                                      document.Editor.Document.BeginAtomicUndo ();
 *                                      formatter.OnTheFlyFormat (document.Project != null ? document.Project.Policies : null,
 *                                              document.Editor, offset, offset + length);
 *                                      document.Editor.Document.EndAtomicUndo ();
 *                              }
 *                      }*/
            return(template);
        }
コード例 #35
0
			public MdTextReplaceAction (MonoDevelop.Ide.Gui.Document doc, int offset, int removedChars, string insertedText) : base (offset, removedChars, insertedText)
			{
				if (doc == null)
					throw new ArgumentNullException ("doc");
				this.doc = doc;
			}
コード例 #36
0
 public UnitTestMarker(UnitTestLocation unitTest, MonoDevelop.Ide.Gui.Document doc)
 {
     this.unitTest = unitTest;
     this.doc      = doc;
 }
コード例 #37
0
			public MdNodeSelectionAction (MonoDevelop.Ide.Gui.Document doc, AstNode node) : base (node)
			{
				if (doc == null)
					throw new ArgumentNullException ("doc");
				this.doc = doc;
			}
コード例 #38
0
ファイル: ViMode.cs プロジェクト: csammis/VimAddin
 public ViEditMode( MonoDevelop.Ide.Gui.Document doc )
 {
     saveableDocument = doc;
 }
コード例 #39
0
 public CSharpCompletionTextEditorExtension(MonoDevelop.Ide.Gui.Document doc, bool addEventHandlersInInitialization = true)
 {
     this.addEventHandlersInInitialization = addEventHandlersInInitialization;
     Initialize(doc.Editor, doc);
 }
コード例 #40
0
 internal static HighlightUsagesExtension GetHighlightUsageExtension(MonoDevelop.Ide.Gui.Document doc)
 {
     return(doc.GetContent <HighlightUsagesExtension> ());
 }
コード例 #41
0
 public virtual void SuppressWithAttribute(MonoDevelop.Ide.Gui.Document document, DocumentLocation loc)
 {
     throw new NotSupportedException();
 }
コード例 #42
0
 public override System.Collections.Generic.IEnumerable <CodeAction> GetActions(MonoDevelop.Ide.Gui.Document document, object refactoringContext, TextLocation loc, CancellationToken cancellationToken)
 {
     yield return(new AnalysisCodeAction(Action, Result)
     {
         DocumentRegion = Action.DocumentRegion
     });
 }
コード例 #43
0
 public TestRunner(MonoDevelop.Ide.Gui.Document doc, string testCase, bool debug)
 {
     //					this.doc = doc;
     this.testCase = testCase;
     this.debug    = debug;
 }
コード例 #44
0
 public override bool ExtendsEditor(MonoDevelop.Ide.Gui.Document doc, IEditableTextBuffer editor)
 {
     //can only attach if there is not already an attached BaseXmlEditorExtension
     return(doc.GetContent <BaseXmlEditorExtension> () == null);
 }