Example #1
0
            public BreakpointMarker(EditorDocument EditorDoc, BreakpointWrapper breakPoint)
                : base(EditorDoc.MarkerStrategy, EditorDoc.Editor.Document.GetOffset(breakPoint.Line, 0), true)
            {
                this.Breakpoint = breakPoint;

                MarkerType      = TextMarkerType.None;
                BackgroundColor = Colors.DarkRed;
                ForegroundColor = Colors.White;
            }
Example #2
0
            public static ErrorMarker Create(EditorDocument EditorDoc, GenericError Error)
            {
                var em = new ErrorMarker(EditorDoc, Error);

                em.ForegroundColor = Error.ForegroundColor;
                em.BackgroundColor = Error.BackgroundColor;
                if (Error.MarkerColor.HasValue)
                {
                    em.MarkerColor = Error.MarkerColor.Value;
                }

                // Init offsets manually
                try
                {
                    if (Error.Line >= EditorDoc.Editor.Document.LineCount)
                    {
                        return(null);
                    }

                    if (Error.Line == EditorDoc.Editor.Document.LineCount - 1 &&
                        EditorDoc.Editor.Document.Lines[Error.Line].Length > Error.Column)
                    {
                        return(null);
                    }

                    em.StartOffset = EditorDoc.Editor.Document.GetOffset(Error.Line, Error.Column);
                }
                catch
                {
                    return(null);
                }

                if (Error.Length > 0)
                {
                    em.Length = Error.Length;
                }
                else
                {
                    em.CalculateWordOffset(em.StartOffset, false);
                }

                return(em);
            }
Example #3
0
		/// <summary>
		/// Central method to open a file/project/solution
		/// </summary>
		/// <returns>Editor instance (if a source file was opened)</returns>
		public AbstractEditorDocument OpenFile(string FileName)
		{
			if (string.IsNullOrWhiteSpace(FileName))
				return null;
			/*
			 * 1) Solution check
			 * 2) Project file check
			 * 3) Normal file check
			 */
			var ext = Path.GetExtension(FileName);

			// 1)
			if (ext == Solution.SolutionExtension)
			{
				if (!File.Exists(FileName))
				{
					ErrorLogger.Log("Solution " + FileName + " not found!", ErrorType.Error, ErrorOrigin.System);
					return null;
				}

				// Before load a new solution, close all related edited files
				if (IDEManager.CurrentSolution != null)
					WorkbenchLogic.Instance. CloseFilesRelatedTo(IDEManager.CurrentSolution);

				/*
				 * - Load solution
				 * - Load all of its projects
				 * - Open last opened files
				 */
				var sln = IDEManager.CurrentSolution = new Solution(FileName);

				AdjustLastFileList(FileName, true);

				foreach (var f in sln.ProjectFiles)
					if (File.Exists(sln.ToAbsoluteFileName(f)))
						Project.LoadProjectFromFile(sln, f);

				foreach (var prj in sln)
					if (prj != null && prj.LastOpenedFiles.Count > 0)
						foreach (var fn in prj.LastOpenedFiles)
							OpenFile(fn);

				RootWindow.RefreshGUI();
				RootWindow.Panel_ProjectExplorer.MainTree.ExpandAll();
				return null;
			}

			// 2)
			var langs = LanguageLoader.Bindings.Where(l => l.CanHandleProject(FileName)).ToArray();
			if (langs.Length > 0)
			{
				if (!File.Exists(FileName))
				{
					ErrorLogger.Log("Project " + FileName + " not found!", ErrorType.Error, ErrorOrigin.System);
					return null;
				}

				/* 
				 * - Load project
				 * - Create anonymous solution that holds the project virtually
				 * - Open last opened files
				 */
				var _oldSln = IDEManager.CurrentSolution;
				IDEManager.CurrentSolution = new Solution();
				IDEManager.CurrentSolution.FileName = Path.ChangeExtension(FileName, Solution.SolutionExtension);

				var LoadedPrj = langs[0].OpenProject(IDEManager.CurrentSolution, FileName);
				if (LoadedPrj != null)
				{
					AdjustLastFileList(FileName, true);
					IDEManager.CurrentSolution.Name = LoadedPrj.Name;
					IDEManager.CurrentSolution.AddProject(LoadedPrj);

					foreach (var prj in IDEManager.CurrentSolution)
						if (prj != null && prj.LastOpenedFiles.Count > 0)
							foreach (var fn in prj.LastOpenedFiles)
								OpenFile(prj.ToAbsoluteFileName(fn));
					IDEManager.Instance.UpdateGUI();
				}
				else IDEManager.CurrentSolution = _oldSln;
				return null;
			}

			//3)

			// Try to resolve owner project
			// - useful if relative path was given - enables
			Project _prj = null;
			if (IDEManager.CurrentSolution != null)
				foreach (var p in IDEManager.CurrentSolution.ProjectCache)
					if (p.ContainsFile(FileName))
					{
						_prj = p;
						break;
					}

			// Make file path absolute
			var absPath = _prj != null ? _prj.ToAbsoluteFileName(FileName) : FileName;

			// Add file to recently used files
			AdjustLastFileList(absPath, false);

			// Check if file already open -- Allow only one open instance of a file!
			foreach (var doc in Instance.RootWindow.DockManager.Documents)
				if (doc is AbstractEditorDocument && (doc as AbstractEditorDocument).AbsoluteFilePath == absPath)
				{
					// Activate the wanted item and return it
					doc.Activate();
					RootWindow.DockManager.ActiveDocument = doc;
					return doc as AbstractEditorDocument;
				}

			EditorDocument newEd = null;

			foreach (var lang in LanguageLoader.Bindings)
				if (lang.SupportsEditor(absPath))
				{
					newEd = lang.OpenFile(_prj, absPath);
					break;
				}

			if (newEd == null)
				newEd = new EditorDocument(absPath);

			// Set read only state if e.g. debugging currently
			newEd.Editor.IsReadOnly = AllDocumentsReadOnly;
			newEd.Show(RootWindow.DockManager);

			try
			{
				Instance.RootWindow.DockManager.ActiveDocument = newEd;
				newEd.Activate();
			}
			catch
			{

			}
			IDEManager.Instance.UpdateGUI();
			newEd.Editor.Focus();
			return newEd;
		}
Example #4
0
 public CodeSymbolMarker(EditorDocument EditorDoc, ISyntaxRegion Id, CodeLocation Location, int length)
     : this(EditorDoc, Id, EditorDoc.Editor.Document.GetOffset(Location.Line, Location.Column), length)
 {
 }
Example #5
0
 public CodeSymbolMarker(EditorDocument EditorDoc, ISyntaxRegion Id, int StartOffset, int Length)
     : base(EditorDoc.MarkerStrategy, StartOffset, Length)
 {
     this.EditorDocument = EditorDoc;
     this.Id = Id;
     Init();
 }
Example #6
0
		/// <summary>
		/// Create a source file that is unrelated to any open project or solution
		/// </summary>
		private void NewSource(object sender, RoutedEventArgs e)
		{
			var sdlg = new NewSrcDlg();
			if (sdlg.ShowDialog().Value)
			{
				foreach (var lang in LanguageLoader.Bindings)
					if (lang.CanHandleFile(sdlg.FileName))
					{
						var ed = lang.OpenFile(null, sdlg.FileName);

						// If language won't handle file anyway, just put it inside a neutral document
						if (ed == null)
							ed = new EditorDocument(sdlg.FileName);

						ed.Show(DockMgr);
						ed.Activate();
						return;
					}

				var _ed = new EditorDocument(sdlg.FileName);
				_ed.Show(DockMgr);
				_ed.Activate();
			}
		}
Example #7
0
 ErrorMarker(EditorDocument EditorDoc, GenericError Error)
     : base(EditorDoc.MarkerStrategy)
 {
     this.EditorDocument = EditorDoc;
     this.Error          = Error;
 }
Example #8
0
			public BreakpointMarker(EditorDocument EditorDoc, BreakpointWrapper breakPoint)
				:base(EditorDoc.MarkerStrategy,EditorDoc.Editor.Document.GetOffset(breakPoint.Line,0),true)
			{
				this.Breakpoint = breakPoint;

				MarkerType = TextMarkerType.None;
				BackgroundColor = Colors.DarkRed;
				ForegroundColor = Colors.White;
			}
Example #9
0
			ErrorMarker(EditorDocument EditorDoc, GenericError Error)
				:base(EditorDoc.MarkerStrategy)
			{
				this.EditorDocument = EditorDoc;
				this.Error = Error;
			}
Example #10
0
			public static ErrorMarker Create(EditorDocument EditorDoc, GenericError Error)
			{
				var em = new ErrorMarker(EditorDoc, Error);

				em.ForegroundColor = Error.ForegroundColor;
				em.BackgroundColor = Error.BackgroundColor;
				if (Error.MarkerColor.HasValue)
					em.MarkerColor = Error.MarkerColor.Value;

				// Init offsets manually
				try
				{
					if (Error.Line >= EditorDoc.Editor.Document.LineCount)
						return null;

					if (Error.Line == EditorDoc.Editor.Document.LineCount-1 &&
						EditorDoc.Editor.Document.Lines[Error.Line].Length > Error.Column)
						return null;

					em.StartOffset = EditorDoc.Editor.Document.GetOffset(Error.Line, Error.Column);
				}
				catch
				{
					return null;
				}

				if (Error.Length > 0)
					em.Length = Error.Length;
				else
					em.CalculateWordOffset(em.StartOffset, false);

				return em;
			}