示例#1
0
 void Init(IViewContent view)
 {
     this.view         = view;
     editable          = view.GetService <IEditable>();
     textEditor        = view.GetService <ITextEditor>();
     textEditorOptions = textEditor.Options;
 }
		void Init(IViewContent view)
		{
			this.view = view;
			editable = view.GetService<IEditable>();
			textEditor = view.GetService<ITextEditor>();
			textEditorOptions = textEditor.Options;
		}
 public bool CanAttachTo(IViewContent content)
 {
     if (Path.GetExtension(content.PrimaryFileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase))
     {
         IEditable editable = content.GetService <IEditable>();
         if (editable != null)
         {
             try {
                 XmlTextReader r = new XmlTextReader(editable.CreateSnapshot().CreateReader());
                 r.XmlResolver        = null;
                 r.WhitespaceHandling = WhitespaceHandling.None;
                 while (r.NodeType != XmlNodeType.Element && r.Read())
                 {
                     ;
                 }
                 if (r.LocalName == "ResourceDictionary" || r.LocalName == "Application" || r.LocalName == "Activity")
                 {
                     return(false);
                 }
             } catch (XmlException) {
                 return(true);
             }
             return(true);
         }
     }
     return(false);
 }
示例#4
0
        void WorkbenchActiveContentChanged(object sender, EventArgs e)
        {
            IViewContent view = WorkbenchSingleton.Workbench.ActiveViewContent;

            if (view != null)
            {
                IOutlineContentHost content = view.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost;
                if (content != null)
                {
                    contentControl.SetContent(content.OutlineContent, content);
                    return;
                }
            }

            ITextEditorProvider provider = WorkbenchSingleton.Workbench.ActiveViewContent as ITextEditorProvider;

            if (provider != null)
            {
                IOutlineContentHost content = provider.TextEditor.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost;
                if (content != null)
                {
                    contentControl.SetContent(content.OutlineContent, content);
                    return;
                }
            }
            contentControl.SetContent(StringParser.Parse("${res:MainWindow.Windows.OutlinePad.NoContentAvailable}"));
        }
        Task <ResolveResult> ResolveAtCaretAsync(ParseInformationEventArgs e)
        {
            IWorkbenchWindow window = SD.Workbench.ActiveWorkbenchWindow;

            if (window == null)
            {
                return(Task.FromResult <ResolveResult>(null));
            }
            IViewContent viewContent = window.ActiveViewContent;

            if (viewContent == null)
            {
                return(Task.FromResult <ResolveResult>(null));
            }
            ITextEditor editor = viewContent.GetService <ITextEditor>();

            if (editor == null)
            {
                return(Task.FromResult <ResolveResult>(null));
            }

            // e might be null when this is a manually triggered update
            // don't resolve when an unrelated file was changed
            if (e != null && editor.FileName != e.FileName)
            {
                return(Task.FromResult <ResolveResult>(null));
            }

            return(SD.ParserService.ResolveAsync(editor.FileName, editor.Caret.Location, editor.Document));
        }
		public static void SetPosition(IViewContent viewContent, int markerStartLine, int markerStartColumn, int markerEndLine, int markerEndColumn)
		{
			if (viewContent == null)
				return;
			ITextEditor editor = viewContent.GetService<ITextEditor>();
			if (editor != null) {
				SetPosition(editor.FileName, editor.Document, markerStartLine, markerStartColumn, markerEndLine, markerEndColumn);
			}
		}
        static void ShowCodeCoverage(IViewContent view)
        {
            ITextEditor textEditor = view.GetService <ITextEditor>();

            if (textEditor != null && view.PrimaryFileName != null)
            {
                ShowCodeCoverage(textEditor, view.PrimaryFileName);
            }
        }
示例#8
0
        ITextEditor GetTextEditor(string fileName)
        {
            IViewContent viewContent = FileService.GetOpenFile(fileName);

            if (viewContent != null)
            {
                return(viewContent.GetService <ITextEditor>());
            }
            return(null);
        }
示例#9
0
		internal static Document FromWindow(IViewContent viewContent)
		{
			if (viewContent == null)
				return null;
			ITextEditor editor = viewContent.GetService(typeof(ITextEditor)) as ITextEditor;
			if (editor != null) {
				return new Document(viewContent, editor.Document);
			} else {
				return null;
			}
		}
示例#10
0
        public static void SetPosition(IViewContent viewContent, int markerStartLine, int markerStartColumn, int markerEndLine, int markerEndColumn)
        {
            if (viewContent == null)
            {
                return;
            }
            ITextEditor editor = viewContent.GetService <ITextEditor>();

            if (editor != null)
            {
                SetPosition(editor.FileName, editor.Document, markerStartLine, markerStartColumn, markerEndLine, markerEndColumn);
            }
        }
        static Properties GetMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent.GetService <IMementoCapable>();

            if (mementoCapable == null)
            {
                return(null);
            }
            else
            {
                return(mementoCapable.CreateMemento());
            }
        }
        public virtual void JumpToCurrentLine(string sourceFullFilename, int startLine, int startColumn, int endLine, int endColumn)
        {
            IViewContent viewContent = FileService.OpenFile(sourceFullFilename);

            if (viewContent != null)
            {
                IPositionable positionable = viewContent.GetService <IPositionable>();
                if (positionable != null)
                {
                    positionable.JumpTo(startLine, startColumn);
                }
            }
        }
示例#13
0
        public override void JumpToCurrentLine(string sourceFullFilename, int startLine, int startColumn, int endLine, int endColumn)
        {
            IViewContent viewContent = FileService.OpenFile(sourceFullFilename);

            if (viewContent != null)
            {
                IPositionable positionable = viewContent.GetService <IPositionable>();
                if (positionable != null)
                {
                    positionable.JumpTo(startLine, startColumn);
                }
            }
            CurrentLineBookmark.SetPosition(viewContent, startLine, startColumn, endLine, endColumn);
        }
示例#14
0
        void WorkbenchActiveContentChanged(object sender, EventArgs e)
        {
            IViewContent view = SD.Workbench.ActiveViewContent;

            if (view != null)
            {
                IOutlineContentHost content = view.GetService(typeof(IOutlineContentHost)) as IOutlineContentHost;
                if (content != null)
                {
                    SD.WinForms.SetContent(contentControl, content.OutlineContent, view);
                    return;
                }
            }
            SD.WinForms.SetContent(contentControl, StringParser.Parse("${res:MainWindow.Windows.OutlinePad.NoContentAvailable}"));
        }
示例#15
0
        internal static Document FromWindow(IViewContent viewContent)
        {
            if (viewContent == null)
            {
                return(null);
            }
            ITextEditor editor = viewContent.GetService(typeof(ITextEditor)) as ITextEditor;

            if (editor != null)
            {
                return(new Document(viewContent, editor.Document));
            }
            else
            {
                return(null);
            }
        }
示例#16
0
        CodeEditor GetActiveTypeScriptCodeEditor()
        {
            IViewContent view = SD.Workbench.ActiveViewContent;

            if (view != null)
            {
                CodeEditor editor = view.GetService <CodeEditor>();
                if (editor != null)
                {
                    if (TypeScriptParser.IsTypeScriptFileName(editor.FileName))
                    {
                        return(editor);
                    }
                }
            }
            return(null);
        }
示例#17
0
		internal static void Save(IViewContent content)
		{
			if (content != null && content.IsDirty) {
				var customizedCommands = content.GetService<ICustomizedCommands>();
				if (customizedCommands != null && customizedCommands.SaveCommand()) {
					return;
				}
				if (content.IsViewOnly) {
					return;
				}
				
				foreach (OpenedFile file in content.Files.ToArray()) {
					if (file.IsDirty)
						Save(file);
				}
			}
		}
示例#18
0
        public bool CanAttachTo(IViewContent viewContent)
        {
            ITextEditor textEditor = viewContent.GetService <ITextEditor>();

            if (textEditor == null)
            {
                return(false);
            }
            FileName fileName = viewContent.PrimaryFileName;

            if (fileName == null)
            {
                return(false);
            }

            var parsedFile  = SD.ParserService.ParseFile(fileName, textEditor.Document);
            var compilation = SD.ParserService.GetCompilationForFile(fileName);

            return(IsDesignable(parsedFile, compilation));
        }
示例#19
0
        /// <summary>
        /// Stores the memento for the view content.
        /// Such mementos are automatically loaded in ShowView().
        /// </summary>
        public void StoreMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent.GetService <IMementoCapable>();

            if (mementoCapable != null && LoadDocumentProperties)
            {
                if (viewContent.PrimaryFileName == null)
                {
                    return;
                }

                string key = GetMementoKeyName(viewContent);
                LoggingService.Debug("Saving memento of '" + viewContent.ToString() + "' to key '" + key + "'");

                Properties memento = mementoCapable.CreateMemento();
                Properties p       = this.LoadOrCreateViewContentMementos();
                p.SetNestedProperties(key, memento);
                FileUtility.ObservedSave(new NamedFileOperationDelegate(p.Save), this.ViewContentMementosFileName, FileErrorPolicy.Inform);
            }
        }
示例#20
0
		public bool CanAttachTo(IViewContent content)
		{
			if (Path.GetExtension(content.PrimaryFileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase)) {
				IEditable editable = content.GetService<IEditable>();
				if (editable != null) {
					try {
						XmlTextReader r = new XmlTextReader(editable.CreateSnapshot().CreateReader());
						r.XmlResolver = null;
						r.WhitespaceHandling = WhitespaceHandling.None;
						while (r.NodeType != XmlNodeType.Element && r.Read());
						if (r.LocalName == "ResourceDictionary" || r.LocalName == "Application" || r.LocalName == "Activity")
							return false;
					} catch (XmlException) {
						return true;
					}
					return true;
				}
			}
			return false;
		}
示例#21
0
        void LoadViewContentMemento(IViewContent viewContent)
        {
            IMementoCapable mementoCapable = viewContent.GetService <IMementoCapable>();

            if (mementoCapable != null && LoadDocumentProperties)
            {
                if (viewContent.PrimaryFileName == null)
                {
                    return;
                }

                try {
                    string key = GetMementoKeyName(viewContent);
                    LoggingService.Debug("Trying to restore memento of '" + viewContent.ToString() + "' from key '" + key + "'");

                    mementoCapable.SetMemento(this.LoadOrCreateViewContentMementos().NestedProperties(key));
                } catch (Exception e) {
                    MessageService.ShowException(e, "Can't get/set memento");
                }
            }
        }
示例#22
0
        /// <inheritdoc/>
        public IViewContent JumpToFilePosition(FileName fileName, int line, int column)
        {
            LoggingService.InfoFormatted("FileService\n\tJumping to File Position:  [{0} : {1}x{2}]", fileName, line, column);

            if (fileName == null)
            {
                return(null);
            }

            NavigationService.SuspendLogging();
            bool loggingResumed = false;

            try {
                IViewContent  content      = OpenFile(fileName);
                IPositionable positionable = content != null?content.GetService <IPositionable>() : null;

                if (positionable != null)
                {
                    content.WorkbenchWindow.ActiveViewContent = content;
                    NavigationService.ResumeLogging();
                    loggingResumed = true;
                    positionable.JumpTo(Math.Max(1, line), Math.Max(1, column));
                }
                else
                {
                    NavigationService.ResumeLogging();
                    loggingResumed = true;
                    NavigationService.Log(content);
                }

                return(content);
            } finally {
                LoggingService.InfoFormatted("FileService\n\tJumped to File Position:  [{0} : {1}x{2}]", fileName, line, column);

                if (!loggingResumed)
                {
                    NavigationService.ResumeLogging();
                }
            }
        }
示例#23
0
        static void GoToDefinition(DefinitionInfo definition)
        {
            if (!definition.HasFileName())
            {
                return;
            }

            IViewContent view = FileService.OpenFile(definition.fileName);

            if (view == null)
            {
                return;
            }

            ITextEditor textEditor = view.GetService <ITextEditor>();

            if (textEditor != null)
            {
                TextLocation location = textEditor.Document.GetLocation(definition.minChar);
                FileService.JumpToFilePosition(definition.fileName, location.Line, location.Column);
            }
        }
示例#24
0
        public override void Run()
        {
            IViewContent vc = SD.Workbench.ActiveViewContent;

            if (vc == null)
            {
                return;
            }
            var codeEditor = vc.GetService <CodeEditor>();

            if (codeEditor != null)
            {
                ChooseEncodingDialog dlg = new ChooseEncodingDialog();
                dlg.Owner    = SD.Workbench.MainWindow;
                dlg.Encoding = codeEditor.PrimaryTextEditor.Encoding;
                if (dlg.ShowDialog() == true)
                {
                    codeEditor.PrimaryTextEditor.Encoding = dlg.Encoding;
                    SharpDevelop.Commands.SaveFile.Save(vc.PrimaryFile);
                }
            }
        }
示例#25
0
        internal static void Save(IViewContent content)
        {
            if (content != null && content.IsDirty)
            {
                var customizedCommands = content.GetService <ICustomizedCommands>();
                if (customizedCommands != null && customizedCommands.SaveCommand())
                {
                    return;
                }
                if (content.IsViewOnly)
                {
                    return;
                }

                foreach (OpenedFile file in content.Files.ToArray())
                {
                    if (file.IsDirty)
                    {
                        Save(file);
                    }
                }
            }
        }
        public void Update(Diagnostic[] diagnostics, FileName fileName)
        {
            SD.MainThread.InvokeIfRequired(() => {
                ClearTasksForFileName(fileName);

                IViewContent view = FileService.GetOpenFile(fileName);
                if (view == null)
                {
                    return;
                }

                ITextEditor textEditor = view.GetService <ITextEditor>();
                if (textEditor == null)
                {
                    return;
                }

                List <TypeScriptTask> tasks = diagnostics
                                              .Select(diagnostic => TypeScriptTask.Create(fileName, diagnostic, textEditor.Document))
                                              .ToList();

                TaskService.AddRange(tasks);
            });
        }
 bool IsViewTextEditorProvider(IViewContent view)
 {
     return(view.GetService <ITextEditor>() != null);
 }
        string GetText(IViewContent view)
        {
            ITextEditor textEditor = view.GetService <ITextEditor>();

            return(textEditor.Document.Text);
        }
示例#29
0
 static Properties GetMemento(IViewContent viewContent)
 {
     IMementoCapable mementoCapable = viewContent.GetService<IMementoCapable>();
     if (mementoCapable == null) {
         return null;
     } else {
         return mementoCapable.CreateMemento();
     }
 }
		bool IsViewTextEditorProvider(IViewContent view)
		{
			return view.GetService<ITextEditor>() != null;
		}
		public bool CanAttachTo(IViewContent viewContent)
		{
			ITextEditor textEditor = viewContent.GetService<ITextEditor>();
			if (textEditor == null)
				return false;
			FileName fileName = viewContent.PrimaryFileName;
			if (fileName == null)
				return false;
			
			var parsedFile = SD.ParserService.ParseFile(fileName, textEditor.Document);
			var compilation = SD.ParserService.GetCompilationForFile(fileName);
			return IsDesignable(parsedFile, compilation);
		}
示例#32
0
        public override Task <Script> InsertWithCursor(string operation, ITypeDefinition parentType, Func <Script, RefactoringContext, IList <AstNode> > nodeCallback)
        {
            // TODO : Use undo group
            var tcs = new TaskCompletionSource <Script>();

            if (parentType == null)
            {
                return(tcs.Task);
            }
            IUnresolvedTypeDefinition part = null;

            foreach (var p in parentType.Parts)
            {
                if (part == null || EntityModelContextUtils.IsBetterPart(p, part, ".cs"))
                {
                    part = p;
                }
            }

            if (part == null)
            {
                return(tcs.Task);
            }

            var          fileName = new ICSharpCode.Core.FileName(part.Region.FileName);
            IViewContent document = SD.FileService.OpenFile(fileName);
            var          area     = document.GetService <TextArea>();

            if (area == null)
            {
                return(tcs.Task);
            }

            var          loc           = part.Region.Begin;
            var          parsedFile    = SD.ParserService.ParseFile(fileName, area.Document, cancellationToken: context.CancellationToken);
            var          declaringType = parsedFile.GetInnermostTypeDefinition(loc);
            EditorScript script;

            if (area.Document != context.Document)
            {
                script = new EditorScript(area.GetService <ITextEditor>(), SDRefactoringContext.Create(fileName, area.Document, loc, context.CancellationToken), FormattingOptions);
                startedScripts.Add(script);
            }
            else
            {
                script = this;
            }
            var nodes           = nodeCallback(script, script.context);
            var insertionPoints = InsertionPoint.GetInsertionPoints(area.Document, part);

            if (insertionPoints.Count == 0)
            {
                SD.MessageService.ShowErrorFormatted("No valid insertion point can be found in type '{0}'.", part.Name);
                return(tcs.Task);
            }

            var layer = new InsertionCursorLayer(area, operation, insertionPoints);

            area.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)area.TextView.InvalidateVisual);

            if (declaringType.Kind == TypeKind.Enum)
            {
                foreach (var node in nodes.Reverse())
                {
                    int indentLevel = GetIndentLevelAt(area.Document.GetOffset(declaringType.BodyRegion.Begin));
                    var output      = OutputNode(indentLevel, node);
                    var point       = insertionPoints[0];
                    var offset      = area.Document.GetOffset(point.Location);
                    var text        = output.Text + ",";
                    var delta       = point.Insert(area.Document, text);
                    output.RegisterTrackedSegments(script, delta + offset);
                }
                tcs.SetResult(script);
                return(tcs.Task);
            }
            InsertWithCursorOnLayer(script, layer, tcs, nodes, area.Document);
            return(tcs.Task);
        }
		string GetText(IViewContent view)
		{
			ITextEditor textEditor = view.GetService<ITextEditor>();
			return textEditor.Document.Text;
		}
示例#34
0
		void LoadViewContentMemento(IViewContent viewContent)
		{
			IMementoCapable mementoCapable = viewContent.GetService<IMementoCapable>();
			if (mementoCapable != null && LoadDocumentProperties) {
				if (viewContent.PrimaryFileName == null)
					return;
				
				try {
					string key = GetMementoKeyName(viewContent);
					LoggingService.Debug("Trying to restore memento of '" + viewContent.ToString() + "' from key '" + key + "'");
					
					mementoCapable.SetMemento(this.LoadOrCreateViewContentMementos().NestedProperties(key));
				} catch (Exception e) {
					MessageService.ShowException(e, "Can't get/set memento");
				}
			}
		}
		static void ShowCodeCoverage(IViewContent view)
		{
			ITextEditor textEditor = view.GetService<ITextEditor>();
			if (textEditor != null && view.PrimaryFileName != null) {
				ShowCodeCoverage(textEditor, view.PrimaryFileName);
			}
		}
示例#36
0
		/// <summary>
		/// Stores the memento for the view content.
		/// Such mementos are automatically loaded in ShowView().
		/// </summary>
		public void StoreMemento(IViewContent viewContent)
		{
			IMementoCapable mementoCapable = viewContent.GetService<IMementoCapable>();
			if (mementoCapable != null && LoadDocumentProperties) {
				if (viewContent.PrimaryFileName == null)
					return;
				
				string key = GetMementoKeyName(viewContent);
				LoggingService.Debug("Saving memento of '" + viewContent.ToString() + "' to key '" + key + "'");
				
				Properties memento = mementoCapable.CreateMemento();
				Properties p = this.LoadOrCreateViewContentMementos();
				p.SetNestedProperties(key, memento);
				FileUtility.ObservedSave(new NamedFileOperationDelegate(p.Save), this.ViewContentMementosFileName, FileErrorPolicy.Inform);
			}
		}
示例#37
0
        void startEvent(object sender, System.EventArgs e)
        {
            items = new List <Report>();
            total = null;

            switch (((ComboBox)ControlDictionary["locationComboBox"]).SelectedIndex)
            {
            case 0: {                            // current file
                IViewContent viewContent = SD.Workbench.ActiveViewContent;
                if (viewContent != null)
                {
                    IEditable editable = viewContent.GetService <IEditable>();
                    if (editable == null)
                    {
                        MessageService.ShowWarning("${res:Dialog.WordCountDialog.IsNotTextFile}");
                    }
                    else
                    {
                        Report r = GetReport(viewContent, editable.CreateSnapshot().CreateReader());
                        if (r != null)
                        {
                            items.Add(r);
                        }
                    }
                }
                break;
            }

            case 1: {                            // all open files
                if (SD.Workbench.ViewContentCollection.Count > 0)
                {
                    total = new Report(StringParser.Parse("${res:Dialog.WordCountDialog.TotalText}"), 0, 0, 0);
                    foreach (IViewContent content in SD.Workbench.ViewContentCollection)
                    {
                        IEditable editable = content.GetService <IEditable>();
                        if (editable != null)
                        {
                            Report r = GetReport(content, editable.CreateSnapshot().CreateReader());
                            if (r != null)
                            {
                                total += r;
                                items.Add(r);
                            }
                        }
                    }
                }
                break;
            }

            case 2: {                            // whole project
                if (ProjectService.CurrentProject == null)
                {
                    MessageService.ShowError("${res:Dialog.WordCountDialog.MustBeInProtectedModeWarning}");
                    break;
                }
                total = new Report(StringParser.Parse("${res:Dialog.WordCountDialog.TotalText}"), 0, 0, 0);
                CountProject(ProjectService.CurrentProject, ref total);
                break;
            }

            case 3: {                             // whole solution
                if (ProjectService.OpenSolution == null)
                {
                    MessageService.ShowError("${res:Dialog.WordCountDialog.MustBeInProtectedModeWarning}");
                    break;
                }
                total = new Report(StringParser.Parse("${res:Dialog.WordCountDialog.TotalText}"), 0, 0, 0);
                CountSolution(ProjectService.OpenSolution, ref total);
                break;
            }
            }
            UpdateList(0);
        }