Example #1
0
        public static bool IsDropAllowed(string file, PrjExplorerNode dropNode)
        {
            if (string.IsNullOrEmpty(file))
            {
                return(false);
            }

            if (file.EndsWith(Solution.SolutionExtension))
            {
                return(true);
            }

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

            bool isPrj = false;

            AbstractLanguageBinding.SearchBinding(file, out isPrj);

            if (isPrj && dropNode is SolutionNode && !(dropNode as SolutionNode).Solution.ContainsProject(file))
            {
                return(true);
            }
            else if (isPrj)             // Ignore already existing projects
            {
                return(false);
            }

            if (dropNode is SolutionNode)
            {
                return(false);
            }

            /*
             * After checking for solution or project extension, check if 'file' is file or directory
             */
            bool IsDir   = Directory.Exists(file);
            var  fileDir = Path.GetDirectoryName(file);

            var dropFile = dropNode.AbsolutePath;
            var dropDir  = dropFile;

            if (!(dropNode is DirectoryNode))
            {
                dropDir = Path.GetDirectoryName(dropFile);
            }

            if (IsDir && file != dropDir && !dropDir.Contains(file))
            {
                return(true);
            }
            else if (fileDir != dropDir)           // Ensure the file gets moved either to an other directory or project
            {
                return(true);
            }

            return(false);
        }
Example #2
0
        public void SaveIDEStates()
        {
            try
            {
                // Save all files
                WorkbenchLogic.Instance.SaveAllFiles();

                // Save global settings
                GlobalProperties.Save();

                // Save language-specific settings
                foreach (var lang in LanguageLoader.Bindings)
                {
                    if (lang.CanUseSettings)
                    {
                        try
                        {
                            var fn = AbstractLanguageBinding.CreateSettingsFileName(lang);

                            if (File.Exists(fn))
                            {
                                File.Delete(fn);
                            }

                            lang.SaveSettings(fn);
                        }
                        catch (Exception ex)
                        {
                            ErrorLogger.Log(ex);
                        }
                    }
                }
            }
            catch (Exception ex) { ErrorLogger.Log(ex); }
        }
Example #3
0
            static bool InternalBuild(Project Project, bool Incrementally)
            {
                // Important: Reset error list's unbound build result
                LastSingleBuildResult = null;

                // Select appropriate language binding
                bool isPrj = false;
                var  lang  = AbstractLanguageBinding.SearchBinding(Project.FileName, out isPrj);

                // If binding is able to build..
                if (lang != null && isPrj && lang.CanBuild && lang.BuildSupport.CanBuildProject(Project))
                {
                    // If not building the project incrementally, cleanup project outputs first
                    if (!Incrementally)
                    {
                        CleanUpOutput(Project);
                    }

                    // Set debug support
                    if (lang.CanUseDebugging)
                    {
                        DebugManagement.CurrentDebugSupport = lang.DebugSupport;
                    }
                    else
                    {
                        DebugManagement.CurrentDebugSupport = null;
                    }

                    // Increment build number if the user enabled it
                    if (Project.AutoIncrementBuildNumber)
                    {
                        if (Project.LastBuildResult != null && Project.LastBuildResult.Successful)
                        {
                            Project.Version.IncrementBuild();
                        }
                        else                         //TODO: How to handle revision number?
                        {
                            Project.Version.Revision++;
                        }
                    }

                    // Build project
                    lang.BuildSupport.BuildProject(Project);

                    // Copy additional output files to target dir
                    if (Project.LastBuildResult.Successful)
                    {
                        Project.CopyCopyableOutputFiles();
                    }

                    if (Project.LastBuildResult.NoBuildNeeded)
                    {
                        ErrorLogger.Log("No project files were changed -- No compilation required", ErrorType.Information, ErrorOrigin.Build);
                    }

                    return(Project.LastBuildResult.Successful);
                }
                return(false);
            }
Example #4
0
            public static BuildResult BuildSingle()
            {
                AbstractEditorDocument ed = ed = Instance.CurrentEditor;

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

                // Save module
                ed.Save();

                // Select appropriate language binding
                string file      = ed.AbsoluteFilePath;
                bool   IsProject = false;
                var    lang      = AbstractLanguageBinding.SearchBinding(file, out IsProject);

                // Check if binding supports building
                if (lang == null || IsProject || !lang.CanBuild || !lang.BuildSupport.CanBuildFile(file))
                {
                    return(null);
                }

                // Set debug support
                if (lang.CanUseDebugging)
                {
                    DebugManagement.CurrentDebugSupport = lang.DebugSupport;
                }
                else
                {
                    DebugManagement.CurrentDebugSupport = null;
                }

                // Enable build menu
                IsBuilding = true;

                IDEManager.Instance.MainWindow.RefreshMenu();

                // Clear build output
                Instance.MainWindow.ClearLog();

                // Execute build
                var br = LastSingleBuildResult = lang.BuildSupport.BuildStandAlone(file);

                if (br.Successful && br.NoBuildNeeded)
                {
                    ErrorLogger.Log("File wasn't changed -- No compilation required", ErrorType.Information, ErrorOrigin.Build);
                }


                // Update error list, Disable build menu
                ErrorManagement.RefreshErrorList();
                IsBuilding = false;
                IDEManager.Instance.MainWindow.RefreshMenu();

                return(br);
            }
Example #5
0
        /// <summary>
        /// Note: We will be only allowed to COPY files, not move them
        /// </summary>
        /// <param name="file"></param>
        /// <param name="dropNode"></param>
        public void DoPaste(string file, DnDData dropNode)
        {
            // Solution
            if (file.EndsWith(Solution.SolutionExtension))
            {
                IDEManager.Instance.OpenFile(file);
                return;
            }

            // Project
            bool isPrj = false;

            AbstractLanguageBinding.SearchBinding(file, out isPrj);

            if (isPrj && dropNode.IsSln)
            {
                IDEManager.ProjectManagement.AddExistingProjectToSolution(dropNode.Solution, file);
            }
            else if (isPrj)             // Ignore already existing projects
            {
                return;
            }

            bool IsDir    = Directory.Exists(file);
            var  dropFile = dropNode.Path;

            // 'Pre-expand' our drop node - when the tree gets updated
            if (!dropNode.IsPrj)
            {
                _ExpandedNodes.Add(dropNode.Node.FullPath);
            }

            var dropDir = "";

            if (dropNode.IsDir)
            {
                dropDir = (dropNode.Node as DirectoryNode).RelativePath;
            }
            else if (dropNode.IsFile)
            {
                dropDir = Path.GetDirectoryName((dropNode.Node as FileNode).RelativeFilePath);
            }

            if (IsDir)
            {
                IDEManager.FileManagement.AddExistingDirectoryToProject(file, dropNode.Project, dropDir);
            }
            else
            {
                IDEManager.FileManagement.AddExistingSourceToProject(dropNode.Project, dropDir, file);
            }
        }
Example #6
0
            /// <summary>
            /// Creates a new project and adds it to the current solution
            /// </summary>
            public static Project AddNewProjectToSolution(Solution sln, AbstractLanguageBinding Binding, FileTemplate ProjectType, string Name, string BaseDir)
            {
                var prj = CreateNewProject(Binding, ProjectType, Name, BaseDir);

                if (prj != null)
                {
                    prj.Save();
                    sln.AddProject(prj);
                    sln.Save();
                }

                Instance.UpdateGUI();
                return(prj);
            }
Example #7
0
            /// <summary>
            /// Note: The current solution will not be touched
            /// </summary>
            public static Solution CreateNewProjectAndSolution(AbstractLanguageBinding Binding, FileTemplate ProjectType, string Name, string BaseDir, string SolutionName)
            {
                var baseDir = BaseDir.Trim('\\', ' ', '\t');
                var sln     = new Solution();

                sln.Name     = SolutionName;
                sln.FileName =
                    baseDir + "\\" +
                    Path.ChangeExtension(Util.PurifyFileName(Name), Solution.SolutionExtension);

                AddNewProjectToSolution(sln, Binding, ProjectType, Name, baseDir);

                return(sln);
            }
Example #8
0
            /// <summary>
            /// Creates a new project.
            /// Doesn't add it to the current solution.
            /// Doesn't modify the current solution.
            /// </summary>
            public static Project CreateNewProject(AbstractLanguageBinding Binding, FileTemplate ProjectType, string Name, string BaseDir)
            {
                /*
                 * Enforce the creation of a new project directory
                 */
                var baseDir = BaseDir.Trim('\\', ' ', '\t') + "\\" + Util.PurifyDirName(Name);

                if (Directory.Exists(baseDir))
                {
                    MessageBox.Show("Project directory " + baseDir + " exists already", "Project directory creation error");
                    return(null);
                }

                Util.CreateDirectoryRecursively(baseDir);

                var prj = Binding.CreateEmptyProject(Name, baseDir + "\\" +
                                                     Path.ChangeExtension(Util.PurifyFileName(Name), ProjectType.Extensions[0]), ProjectType);

                return(prj);
            }
Example #9
0
 /// <summary>
 /// Adds a new project to the current solution
 /// </summary>
 public static Project AddNewProjectToSolution(AbstractLanguageBinding Binding, FileTemplate ProjectType, string Name, string BaseDir)
 {
     return(AddNewProjectToSolution(CurrentSolution, Binding, ProjectType, Name, BaseDir));
 }
Example #10
0
        void ThreadedInit(object argsObj)
        {
            var args = argsObj as ReadOnlyCollection <string>;

            // Load language bindings
            LanguageLoader.Bindings.Add(new GenericFileBinding());
            try
            {
                LanguageLoader.LoadLanguageInterface(Util.ApplicationStartUpPath + "\\D-IDE.D.dll", "D_IDE.D.DLanguageBinding");

                LanguageLoader.LoadLanguageInterface(Util.ApplicationStartUpPath + "\\D-IDE.D.dll", "D_IDE.ResourceFiles.ResScriptFileBinding");
            }
            catch (Exception ex) { ErrorLogger.Log(ex); }

            // Load all language-specific settings
            foreach (var lang in LanguageLoader.Bindings)
            {
                try
                {
                    if (lang.CanUseSettings)
                    {
                        lang.LoadSettings(AbstractLanguageBinding.CreateSettingsFileName(lang));
                    }
                }
                catch (Exception ex)
                {
                    ErrorLogger.Log(ex);
                }
            }

            // Load last solution
            RootWindow.Dispatcher.BeginInvoke(new Action(() =>
            {
                // If given, iterate over all cmd line arguments
                if (args.Count > 0)
                {
                    foreach (var a in args)
                    {
                        IDEManager.Instance.OpenFile(a);
                    }
                }
                else
                {
                    // ... or load last project otherwise
                    try
                    {
                        if (GlobalProperties.Instance.OpenLastPrj && GlobalProperties.Instance.LastProjects.Count > 0)
                        {
                            IDEManager.Instance.OpenFile(GlobalProperties.Instance.LastProjects[0]);
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.Log(ex);
                    }

                    try
                    {
                        // Finally re-open all lastly edited files
                        if (GlobalProperties.Instance.OpenLastFiles)
                        {
                            foreach (var kv in GlobalProperties.Instance.LastOpenFiles)
                            {
                                if (File.Exists(kv.Key))
                                {
                                    var ed = OpenFile(kv.Key, kv.Value[0]);

                                    if (ed is EditorDocument)
                                    {
                                        (ed as EditorDocument).Editor.ScrollToVerticalOffset(kv.Value[1]);
                                    }
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        ErrorLogger.Log(ex);
                    }
                }
                RootWindow.RefreshGUI();
            }), System.Windows.Threading.DispatcherPriority.Background);

            if (RootWindow.splashScreen != null)
            {
                RootWindow.splashScreen.Close(TimeSpan.FromSeconds(0.5));
            }
        }
Example #11
0
        public override void BuildProject(Project prj)
        {
            var dprj = prj as DProject;

            if (dprj == null)
            {
                return;
            }

            DMDVersion = dprj.DMDVersion;

            dprj.LastBuildResult = new BuildResult()
            {
                SourceFile = dprj.FileName, TargetFile = dprj.OutputFile
            };

            // Build outputs/target paths
            string objectDirectory = dprj.BaseDirectory + "\\obj";

            Util.CreateDirectoryRecursively(objectDirectory);

            #region Compile d sources to object files
            var  objs = new List <string>();
            bool AllObjectsUnchanged = true;

            AbstractLanguageBinding lang = null;
            foreach (var f in dprj.CompilableFiles)
            {
                if (ShallStop)
                {
                    return;
                }
                bool _u = false;
                if (lang == null || !lang.CanHandleFile(f.FileName))
                {
                    lang = AbstractLanguageBinding.SearchBinding(f.FileName, out _u);
                }

                if (lang == null || _u || !lang.CanBuild || !lang.BuildSupport.CanBuildFile(f.FileName))
                {
                    continue;
                }

                lang.BuildSupport.BuildModule(f, objectDirectory, prj.BaseDirectory, !dprj.IsRelease, false);

                if (!f.LastBuildResult.Successful)
                {
                    return;
                }

                if (!f.LastBuildResult.NoBuildNeeded)
                {
                    AllObjectsUnchanged = false;
                }

                // To save command line space, make the targetfile relative to our objectDirectory
                objs.Add(dprj.ToRelativeFileName(f.LastBuildResult.TargetFile));
            }

            if (objs.Count < 1)
            {
                prj.LastBuildResult.Successful    = true;
                prj.LastBuildResult.NoBuildNeeded = true;
                ErrorLogger.Log("Project " + dprj.Name + " empty", ErrorType.Error, ErrorOrigin.Build);
                return;
            }
            #endregion

            // If no source has been changed, skip linkage
            if (AllObjectsUnchanged && File.Exists(dprj.OutputFile))
            {
                dprj.LastBuildResult.NoBuildNeeded = true;
                dprj.LastBuildResult.Successful    = true;
                return;
            }

            // Add default & project specific import libraries
            objs.AddRange(CurrentDMDConfig.DefaultLinkedLibraries);
            objs.AddRange(dprj.LinkedLibraries);

            // Link files to console-based application by default
            var linkerExe  = CurrentDMDConfig.ExeLinker;
            var args       = CurrentDMDConfig.BuildArguments(!dprj.IsRelease);
            var linkerArgs = args.ExeLinker;

            switch (dprj.OutputType)
            {
            case OutputTypes.CommandWindowLessExecutable:
                linkerExe  = CurrentDMDConfig.Win32ExeLinker;
                linkerArgs = args.Win32ExeLinker;
                break;

            case OutputTypes.DynamicLibary:
                linkerExe  = CurrentDMDConfig.DllLinker;
                linkerArgs = args.DllLinker;
                break;

            case OutputTypes.StaticLibrary:
                linkerExe  = CurrentDMDConfig.LibLinker;
                linkerArgs = args.LibLinker;
                break;
            }

            if (ShallStop)
            {
                return;
            }
            dprj.LastBuildResult = LinkFiles(CurrentDMDConfig, linkerExe, linkerArgs, dprj.BaseDirectory, dprj.OutputFile, !dprj.IsRelease, objs.ToArray());
        }