Ejemplo n.º 1
0
        /// <summary>
        /// Gets the primary display binding for the specified file name.
        /// </summary>
        public static IDisplayBinding GetBindingPerFileName(string filename)
        {
            WorkbenchSingleton.AssertMainThread();
            DisplayBindingDescriptor codon = GetDefaultCodonPerFileName(filename);

            return(codon == null ? null : codon.Binding);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Attach secondary view contents to the view content.
        /// </summary>
        /// <param name="viewContent">The view content to attach to</param>
        /// <param name="isReattaching">This is a reattaching pass</param>
        public static void AttachSubWindows(IViewContent viewContent, bool isReattaching)
        {
            WorkbenchSingleton.AssertMainThread();
            if (viewContent == null)
            {
                throw new ArgumentNullException("viewContent");
            }

            foreach (DisplayBindingDescriptor binding in bindings)
            {
                if (binding.IsSecondary && binding.CanOpenFile(viewContent.PrimaryFileName))
                {
                    ISecondaryDisplayBinding displayBinding = binding.SecondaryBinding;
                    if (displayBinding != null &&
                        (!isReattaching || displayBinding.ReattachWhenParserServiceIsReady) &&
                        displayBinding.CanAttachTo(viewContent))
                    {
                        IViewContent[] subViewContents = binding.SecondaryBinding.CreateSecondaryViewContent(viewContent);
                        if (subViewContents != null)
                        {
                            Array.ForEach(subViewContents, viewContent.SecondaryViewContents.Add);
                        }
                        else
                        {
                            MessageService.ShowError("Can't attach secondary view content. " + binding.SecondaryBinding + " returned null for " + viewContent + ".\n(should never happen)");
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Runs the specified custom tool on the base item.
        /// </summary>
        public static void RunCustomTool(FileProjectItem baseItem, ICustomTool customTool, bool showMessageBoxOnErrors)
        {
            if (baseItem == null)
            {
                throw new ArgumentNullException("baseItem");
            }
            if (customTool == null)
            {
                throw new ArgumentNullException("customTool");
            }
            WorkbenchSingleton.AssertMainThread();

            string fileName = baseItem.FileName;

            if (toolRuns.Any(run => FileUtility.IsEqualFileName(run.file, fileName)))
            {
                // file already in queue, do not enqueue it again
                return;
            }
            CustomToolContext context = new CustomToolContext(baseItem.Project);

            context.OutputNamespace = baseItem.GetEvaluatedMetadata("CustomToolNamespace");
            if (string.IsNullOrEmpty(context.OutputNamespace))
            {
                context.OutputNamespace = GetDefaultNamespace(baseItem.Project, baseItem.FileName);
            }
            RunCustomTool(new CustomToolRun(context, fileName, baseItem, customTool, showMessageBoxOnErrors));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Saves project preferences (currently opened files, bookmarks etc.) to the
        /// a property container.
        /// </summary>
        public virtual Properties CreateMemento()
        {
            WorkbenchSingleton.AssertMainThread();

            Properties properties = new Properties();

            properties.Set("bookmarks", ICSharpCode.SharpDevelop.Bookmarks.BookmarkManager.GetProjectBookmarks(this).ToArray());
            List <string> files = new List <string>();

            foreach (string fileName in FileService.GetOpenFiles())
            {
                if (fileName != null && IsFileInProject(fileName))
                {
                    files.Add(fileName);
                }
            }
            properties.Set("files", files.ToArray());

            var webOptions = WebProjectsOptions.Instance.GetWebProjectOptions(Name);

            if (webOptions != null)
            {
                properties.Set("WebProjectOptions", webOptions);
            }

            return(properties);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Called by derived classes when a single test run
        /// is finished.
        /// </summary>
        protected void TestsFinished()
        {
            WorkbenchSingleton.AssertMainThread();

            // Read the rest of the file just in case.
            testResultsMonitor.Stop();
            testResultsMonitor.Read();
            StopMonitoring();

            projects.Remove(currentProject);
            if (projects.Count > 0)
            {
                currentProject = projects[0];
                Run(currentProject, null, null, null);
            }
            else
            {
                runningTestCommand = null;
                UpdateUnitTestsPadToolbar();
                if (TaskService.SomethingWentWrong && ErrorListPad.ShowAfterBuild)
                {
                    ShowErrorList();
                }
                OnAfterRunTests();
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Starts to run a build inside the SharpDevelop GUI.
 /// Only one build can run inside the GUI at one time.
 /// </summary>
 /// <param name="project">The project/solution to build.</param>
 /// <param name="options">The build options.</param>
 public static void BuildInGui(IBuildable project, BuildOptions options)
 {
     if (project == null)
     {
         throw new ArgumentNullException("project");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     WorkbenchSingleton.AssertMainThread();
     if (guiBuildProgressMonitor != null)
     {
         BuildResults results = new BuildResults();
         results.Add(new BuildError(null, Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning")));
         results.Result = BuildResultCode.MSBuildAlreadyRunning;
         if (options.Callback != null)
         {
             options.Callback(results);
         }
     }
     else
     {
         guiBuildProgressMonitor = new CancellableProgressMonitor(StatusBarService.CreateProgressMonitor());
         Gui.WorkbenchSingleton.Workbench.GetPad(typeof(Gui.CompilerMessageView)).BringPadToFront();
         GuiBuildStarted.RaiseEvent(null, new BuildEventArgs(project, options));
         StartBuild(project, options,
                    new MessageViewSink(TaskService.BuildMessageViewCategory),
                    guiBuildProgressMonitor);
     }
 }
Ejemplo n.º 7
0
        public void WriteCodeDomToFile(FileProjectItem baseItem, string outputFileName, CodeCompileUnit ccu)
        {
            WorkbenchSingleton.AssertMainThread();
            CodeDomProvider      provider = project.LanguageProperties.CodeDomProvider;
            CodeGeneratorOptions options  = new CodeDOMGeneratorUtility().CreateCodeGeneratorOptions;

            string codeOutput;

            using (StringWriter writer = new StringWriter()) {
                if (provider == null)
                {
                    writer.WriteLine("No CodeDom provider was found for this language.");
                }
                else
                {
                    provider.GenerateCodeFromCompileUnit(ccu, writer, options);
                }
                codeOutput = writer.ToString();
            }

            FileUtility.ObservedSave(delegate(string fileName) {
                File.WriteAllText(fileName, codeOutput, Encoding.UTF8);
            },
                                     outputFileName, FileErrorPolicy.Inform);
            EnsureOutputFileIsInProject(baseItem, outputFileName);
            ParserService.EnqueueForParsing(outputFileName, codeOutput);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Starts to run a build inside the SharpDevelop GUI.
 /// Only one build can run inside the GUI at one time.
 /// </summary>
 /// <param name="project">The project/solution to build.</param>
 /// <param name="options">The build options.</param>
 public static void BuildInGui(IBuildable project, BuildOptions options)
 {
     if (project == null)
     {
         throw new ArgumentNullException("project");
     }
     if (options == null)
     {
         throw new ArgumentNullException("options");
     }
     WorkbenchSingleton.AssertMainThread();
     if (guiBuildCancellation != null)
     {
         BuildResults results = new BuildResults();
         WorkbenchSingleton.StatusBar.SetMessage(Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning"));
         BuildError error = new BuildError(null, Core.ResourceService.GetString("MainWindow.CompilerMessages.MSBuildAlreadyRunning"));
         results.Add(error);
         TaskService.Add(new Task(error));
         results.Result = BuildResultCode.MSBuildAlreadyRunning;
         if (options.Callback != null)
         {
             options.Callback(results);
         }
     }
     else
     {
         guiBuildCancellation = new CancellationTokenSource();
         IProgressMonitor progressMonitor = WorkbenchSingleton.StatusBar.CreateProgressMonitor(guiBuildCancellation.Token);
         guiBuildTrackedFeature = AnalyticsMonitorService.TrackFeature("ICSharpCode.SharpDevelop.Project.BuildEngine.Build");
         WorkbenchSingleton.StatusBar.SetMessage(StringParser.Parse("${res:MainWindow.CompilerMessages.BuildVerb}..."));
         ProjectService.RaiseEventBuildStarted(new BuildEventArgs(project, options));
         StartBuild(project, options,
                    new MessageViewSink(TaskService.BuildMessageViewCategory, progressMonitor, WorkbenchSingleton.StatusBar));
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the default primary display binding for the specified file name.
        /// </summary>
        public static DisplayBindingDescriptor GetDefaultCodonPerFileName(string filename)
        {
            WorkbenchSingleton.AssertMainThread();

            string defaultCommandID = displayBindingServiceProperties.Get("Default" + Path.GetExtension(filename).ToLowerInvariant()) as string;

            if (!string.IsNullOrEmpty(defaultCommandID))
            {
                foreach (DisplayBindingDescriptor binding in bindings)
                {
                    if (binding.Id == defaultCommandID)
                    {
                        if (IsPrimaryBindingValidForFileName(binding, filename))
                        {
                            return(binding);
                        }
                    }
                }
            }

            foreach (DisplayBindingDescriptor binding in bindings)
            {
                if (IsPrimaryBindingValidForFileName(binding, filename))
                {
                    return(binding);
                }
            }
            return(null);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Loads the assembly represented by the project content. Returns null on failure.
        /// </summary>
        public Assembly LoadAssembly(IProjectContent pc)
        {
            WorkbenchSingleton.AssertMainThread();
            // prevent StackOverflow when project contents have cyclic dependencies
            // Very popular example of cyclic dependency: System <-> System.Xml
            if (!projectContentsCurrentlyLoadingAssembly.Add(pc))
            {
                return(null);
            }

            Assembly sdAssembly;

            if (IsSharpDevelopAssembly(pc, out sdAssembly))
            {
                return(sdAssembly);
            }

            try {
                // load dependencies of current assembly
                foreach (IProjectContent rpc in pc.ThreadSafeGetReferencedContents())
                {
                    if (rpc is ParseProjectContent)
                    {
                        LoadAssembly(rpc);
                    }
                    else if (rpc is ReflectionProjectContent)
                    {
                        ReflectionProjectContent rrpc = (ReflectionProjectContent)rpc;
                        if (!rrpc.IsGacAssembly)
                        {
                            LoadAssembly(rpc);
                        }
                    }
                }
            } finally {
                projectContentsCurrentlyLoadingAssembly.Remove(pc);
            }

            if (pc.Project != null)
            {
                return(LoadAssembly(((IProject)pc.Project).OutputAssemblyFullPath));
            }
            else if (pc is ReflectionProjectContent)
            {
                ReflectionProjectContent rpc = (ReflectionProjectContent)pc;
                if (rpc.IsGacAssembly)
                {
                    return(LoadAssembly(new AssemblyName(rpc.AssemblyFullName), false));
                }
                else
                {
                    return(LoadAssembly(rpc.AssemblyLocation));
                }
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Cancels the build currently running inside the SharpDevelop GUI.
 /// This method does nothing if no build is running.
 /// </summary>
 public static void CancelGuiBuild()
 {
     WorkbenchSingleton.AssertMainThread();
     if (guiBuildProgressMonitor != null)
     {
         guiBuildProgressMonitor.Cancel();
     }
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Cancels the build currently running inside the SharpDevelop GUI.
 /// This method does nothing if no build is running.
 /// </summary>
 public static void CancelGuiBuild()
 {
     WorkbenchSingleton.AssertMainThread();
     if (guiBuildCancellation != null)
     {
         guiBuildCancellation.Cancel();
     }
 }
Ejemplo n.º 13
0
        void SetWatcher()
        {
            WorkbenchSingleton.AssertMainThread();

            if (watcher != null)
            {
                watcher.EnableRaisingEvents = false;
            }

            if (!enabled)
            {
                return;
            }
            if (globalDisableCount > 0)
            {
                return;
            }
            if (DetectExternalChangesOption == false)
            {
                return;
            }

            string fileName = file.FileName;

            if (string.IsNullOrEmpty(fileName))
            {
                return;
            }
            if (FileUtility.IsUrl(fileName))
            {
                return;
            }
            if (!Path.IsPathRooted(fileName))
            {
                return;
            }

            try {
                if (watcher == null)
                {
                    watcher = new FileSystemWatcher();
                    watcher.SynchronizingObject = WorkbenchSingleton.MainForm;
                    watcher.Changed            += OnFileChangedEvent;
                    watcher.Created            += OnFileChangedEvent;
                    watcher.Renamed            += OnFileChangedEvent;
                }
                watcher.Path   = Path.GetDirectoryName(fileName);
                watcher.Filter = Path.GetFileName(fileName);
                watcher.EnableRaisingEvents = true;
            } catch (PlatformNotSupportedException) {
                if (watcher != null)
                {
                    watcher.Dispose();
                }
                watcher = null;
            }
        }
Ejemplo n.º 14
0
 public static void RaiseEventStartBuild()
 {
     WorkbenchSingleton.AssertMainThread();
     building = true;
     if (StartBuild != null)
     {
         StartBuild(null, EventArgs.Empty);
     }
 }
Ejemplo n.º 15
0
 public static void RaiseEventEndBuild(BuildEventArgs e)
 {
     WorkbenchSingleton.AssertMainThread();
     building = false;
     if (EndBuild != null)
     {
         EndBuild(null, e);
     }
 }
Ejemplo n.º 16
0
 public static void DisableAllChangeWatchers()
 {
     WorkbenchSingleton.AssertMainThread();
     globalDisableCount++;
     foreach (FileChangeWatcher w in activeWatchers)
     {
         w.SetWatcher();
     }
 }
        public ProjectChangeWatcher(string fileName)
        {
            this.fileName = fileName;

            WorkbenchSingleton.AssertMainThread();
            activeWatchers.Add(this);

            WorkbenchSingleton.MainWindow.Activated += MainFormActivated;
        }
Ejemplo n.º 18
0
 public static void Clear()
 {
     WorkbenchSingleton.AssertMainThread();
     while (bookmarks.Count > 0)
     {
         SDBookmark b = bookmarks[bookmarks.Count - 1];
         bookmarks.RemoveAt(bookmarks.Count - 1);
         OnRemoved(new BookmarkEventArgs(b));
     }
 }
Ejemplo n.º 19
0
        public virtual void Dispose()
        {
            WorkbenchSingleton.AssertMainThread();

            isDisposed = true;
            if (Disposed != null)
            {
                Disposed(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Raises the <see cref="BuildFinished"/> event.
 ///
 /// You do not need to call this method if you use BuildEngine.BuildInGui - the build
 /// engine will call these events itself.
 /// </summary>
 public static void RaiseEventBuildFinished(BuildEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     WorkbenchSingleton.AssertMainThread();
     building = false;
     BuildFinished.RaiseEvent(null, e);
 }
Ejemplo n.º 21
0
 public static void DisableAllChangeWatchers()
 {
     WorkbenchSingleton.AssertMainThread();
     globalDisableCount++;
     foreach (FileChangeWatcher w in activeWatchers)
     {
         w.SetWatcher();
     }
     //ICSharpCode.SharpDevelop.Project.ProjectChangeWatcher.OnAllChangeWatchersDisabledChanged();//by hanz
 }
Ejemplo n.º 22
0
 Action AfterCommand(string nodeFileName, AbstractProjectBrowserTreeNode node)
 {
     return(delegate {
         WorkbenchSingleton.AssertMainThread();
         // and then refresh the project browser:
         GitStatusCache.ClearCachedStatus(nodeFileName);
         OverlayIconManager.EnqueueRecursive(node);
         OverlayIconManager.EnqueueParents(node);
     });
 }
Ejemplo n.º 23
0
        protected virtual void ChangeFileName(FileName newValue)
        {
            WorkbenchSingleton.AssertMainThread();

            fileName = newValue;

            if (FileNameChanged != null)
            {
                FileNameChanged(this, EventArgs.Empty);
            }
        }
Ejemplo n.º 24
0
 public object GetControl()
 {
     WorkbenchSingleton.AssertMainThread();
     if (resultsTreeViewInstance == null)
     {
         resultsTreeViewInstance = new ResultsTreeView();
     }
     rootNode.GroupResultsByFile(ResultsTreeView.GroupResultsByFile);
     resultsTreeViewInstance.ItemsSource = new object[] { rootNode };
     return(resultsTreeViewInstance);
 }
Ejemplo n.º 25
0
 public static void DisableAllChangeWatchers()
 {
     WorkbenchSingleton.AssertMainThread();
     globalDisableCount++;
     foreach (FileChangeWatcher w in activeWatchers)
     {
         w.SetWatcher();
     }
     //TODO: Uncomment
     //Project.ProjectChangeWatcher.OnAllChangeWatchersDisabledChanged();
 }
Ejemplo n.º 26
0
        public static DisplayBindingDescriptor AddExternalProcessDisplayBinding(ExternalProcessDisplayBinding binding)
        {
            WorkbenchSingleton.AssertMainThread();
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            DisplayBindingDescriptor descriptor = AddExternalProcessDisplayBindingInternal(binding);

            SaveExternalProcessDisplayBindings();
            return(descriptor);
        }
 internal static void RegisterAddInHighlightingDefinitions()
 {
     WorkbenchSingleton.AssertMainThread();
     if (!addInHighlightingDefinitionsRegistered)
     {
         foreach (AddInTreeSyntaxMode syntaxMode in AddInTree.BuildItems <AddInTreeSyntaxMode>(SyntaxModeDoozer.Path, null, false))
         {
             syntaxMode.Register(HighlightingManager.Instance);
         }
         addInHighlightingDefinitionsRegistered = true;
     }
 }
Ejemplo n.º 28
0
        /// <summary>
        /// Gets the primary display binding for the specified file name.
        /// </summary>
        public static IDisplayBinding GetBindingPerFileName(string filename)
        {
            WorkbenchSingleton.AssertMainThread();
            if (FileUtility.IsUrl(filename))
            {
                // The normal display binding dispatching code can't handle URLs (e.g. because it uses Path.GetExtension),
                // so we'll directly return the browser display binding.
                return(new BrowserDisplayBinding.BrowserDisplayBinding());
            }
            DisplayBindingDescriptor codon = GetDefaultCodonPerFileName(filename);

            return(codon == null ? null : codon.Binding);
        }
Ejemplo n.º 29
0
        public virtual void SetMemento(Properties memento)
        {
            WorkbenchSingleton.AssertMainThread();

            foreach (ICSharpCode.SharpDevelop.Bookmarks.SDBookmark mark in memento.Get("bookmarks", new ICSharpCode.SharpDevelop.Bookmarks.SDBookmark[0]))
            {
                ICSharpCode.SharpDevelop.Bookmarks.BookmarkManager.AddMark(mark);
            }
            foreach (string fileName in memento.Get("files", new string[0]))
            {
                filesToOpenAfterSolutionLoad.Add(fileName);
            }
        }
Ejemplo n.º 30
0
 public static void EnableAllChangeWatchers()
 {
     WorkbenchSingleton.AssertMainThread();
     if (globalDisableCount == 0)
     {
         throw new InvalidOperationException();
     }
     globalDisableCount--;
     foreach (FileChangeWatcher w in activeWatchers)
     {
         w.SetWatcher();
     }
 }