Exemple #1
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); }
        }
        /// <summary>
        /// Globally initializes all settings and essential properties
        /// </summary>
        public static void Init()
        {
			try
			{
				Instance = Load();
			}
			catch (Exception ex) { ErrorLogger.Log(ex); }

			if (Instance == null)
				Instance = new GlobalProperties();
        }
        /// <summary>
        /// Globally initializes all settings and essential properties
        /// </summary>
        public static void Init()
        {
            try
            {
                Instance = Load();
            }
            catch (Exception ex) { ErrorLogger.Log(ex); }

            if (Instance == null)
            {
                Instance = new GlobalProperties();
            }
        }
        public static GlobalProperties Load(string fn)
        {
            if (!File.Exists(fn))
            {
                return(new GlobalProperties()
                {
                    IsFirstTimeStart = true
                });
            }

            try
            {
                var stream = File.Open(fn, FileMode.Open);

                var xr = new XmlTextReader(stream);
                var p  = new GlobalProperties();

                while (xr.Read())// now 'settings' should be the current node
                {
                    if (xr.NodeType == XmlNodeType.Element)
                    {
                        switch (xr.LocalName)
                        {
                        default: break;

                        case "firstTime":
                            p.IsFirstTimeStart = true;
                            break;

                        case "CommonEditorSettings":
                            CommonEditorSettings.Instance.LoadFromXml(xr.ReadSubtree());
                            break;

                        case "codetemplates":
                            //CodeTemplate.Load(xr);
                            break;

                        case "recentprojects":
                            if (xr.IsEmptyElement)
                            {
                                break;
                            }
                            while (xr.Read())
                            {
                                if (xr.LocalName == "f")
                                {
                                    try
                                    {
                                        p.LastProjects.Add(xr.ReadString());
                                    }
                                    catch { }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;

                        case "recentfiles":
                            if (xr.IsEmptyElement)
                            {
                                break;
                            }
                            while (xr.Read())
                            {
                                if (xr.LocalName == "f")
                                {
                                    try
                                    {
                                        p.LastFiles.Add(xr.ReadString());
                                    }
                                    catch { }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;

                        case "lastopenedfiles":
                            if (xr.IsEmptyElement)
                            {
                                break;
                            }
                            while (xr.Read())
                            {
                                if (xr.LocalName == "f")
                                {
                                    int offset       = 0,
                                        scrollOffset = 0;

                                    Int32.TryParse(xr.GetAttribute("offset"), out offset);
                                    Int32.TryParse(xr.GetAttribute("scrolloffset"), out scrollOffset);
                                    try
                                    {
                                        p.LastOpenFiles.Add(xr.ReadString(), new[] { offset, scrollOffset });
                                    }
                                    catch { }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;


                        case "openlastprj":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.OpenLastPrj = xr.Value == "1";
                            }
                            break;

                        case "openlastfiles":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.OpenLastFiles = xr.Value == "1";
                            }
                            break;

                        case "windowstate":
                            if (xr.MoveToAttribute("value"))
                            {
                                try { p.lastFormState = (WindowState)Convert.ToInt32(xr.Value); }
                                catch { }
                            }
                            break;

                        case "windowsize":
                            p.lastFormSize = new Size();
                            if (xr.MoveToAttribute("x"))
                            {
                                try { p.lastFormSize.Width = Convert.ToInt32(xr.Value); }
                                catch { }
                            }
                            if (xr.MoveToAttribute("y"))
                            {
                                try { p.lastFormSize.Height = Convert.ToInt32(xr.Value); }
                                catch { }
                            }
                            break;

                        case "retrievenews":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.RetrieveNews = xr.Value == "1";
                            }
                            break;

                        case "externaldbg":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.UseExternalDebugger = xr.Value == "1";
                            }
                            break;

                        case "lastselectedribbontab":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.LastSelectedRibbonTab = Convert.ToInt32(xr.Value);
                            }
                            break;

                        case "watchforupdates":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.WatchForUpdates = xr.Value == "1";
                            }
                            break;

                        case "defprjdir":
                            p.DefaultProjectDirectory = xr.ReadString();
                            break;

                        case "debugger":
                            if (xr.IsEmptyElement)
                            {
                                break;
                            }
                            while (xr.Read())
                            {
                                if (xr.LocalName == "bin")
                                {
                                    p.ExternalDebugger_Bin = xr.ReadString();
                                }
                                else if (xr.LocalName == "args")
                                {
                                    p.ExternalDebugger_Arguments = xr.ReadString();
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;

                        case "lastsearchdir":
                            p.lastSearchDir = xr.ReadString();
                            break;

                        case "verbosedbgoutput":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.VerboseDebugOutput = xr.Value == "1";
                            }
                            break;

                        case "skipunknowncode":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.SkipUnknownCode = xr.Value == "1";
                            }
                            break;

                        case "verbosebuild":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.VerboseBuildOutput = xr.Value == "1";
                            }
                            break;

                        case "autosave":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.DoAutoSaveOnBuilding = xr.Value == "1";
                            }
                            break;

                        case "EnableIncrementalBuild":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.EnableIncrementalBuild = xr.Value == "1";
                            }
                            break;

                        case "DefaultBinDirectory":
                            p.DefaultBinariesPath = xr.ReadString();
                            break;

                        case "highlightings":
                            if (xr.IsEmptyElement)
                            {
                                break;
                            }
                            while (xr.Read())
                            {
                                if (xr.LocalName == "f")
                                {
                                    try
                                    {
                                        string ext = xr.GetAttribute("ext");
                                        p.SyntaxHighlightingEntries.Add(ext, xr.ReadString());
                                    }
                                    catch { }
                                }
                                else
                                {
                                    break;
                                }
                            }
                            break;

                        case "shownewconsolewhenexecuting":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.ShowDebugConsole = xr.Value == "1";
                            }
                            break;

                        case "ShowSpeedInfo":
                            if (xr.MoveToAttribute("value"))
                            {
                                p.ShowSpeedInfo = xr.Value == "true";
                            }
                            break;
                        }
                    }
                }

                xr.Close();
                return(p);
            }
            catch {  }
            return(null);
        }
		public static GlobalProperties Load(string fn)
		{
			if (!File.Exists(fn)) { return new GlobalProperties() { IsFirstTimeStart=true }; }

            try
            {
                var stream = File.Open(fn, FileMode.Open);

                var xr = new XmlTextReader(stream);
                var p = new GlobalProperties();

                while (xr.Read())// now 'settings' should be the current node
                {
                    if (xr.NodeType == XmlNodeType.Element)
                    {
                        switch (xr.LocalName)
                        {
                            default: break;

							case "firstTime":
								p.IsFirstTimeStart = true;
								break;

							case "CommonEditorSettings":
								CommonEditorSettings.Instance.LoadFromXml(xr.ReadSubtree());
								break;
                                
                            case "codetemplates":
                                //CodeTemplate.Load(xr);
                                break;

                            case "recentprojects":
                                if (xr.IsEmptyElement) break;
                                while (xr.Read())
                                {
                                    if (xr.LocalName == "f")
                                    {
                                        try
                                        {
                                            p.LastProjects.Add(xr.ReadString());
                                        }
                                        catch { }
                                    }
                                    else break;
                                }
                                break;

                            case "recentfiles":
                                if (xr.IsEmptyElement) break;
                                while (xr.Read())
                                {
                                    if (xr.LocalName == "f")
                                    {
                                        try
                                        {
                                            p.LastFiles.Add(xr.ReadString());
                                        }
                                        catch { }
                                    }
                                    else break;
                                }
                                break;

                            case "lastopenedfiles":
                                if (xr.IsEmptyElement) break;
                                while (xr.Read())
                                {
                                    if (xr.LocalName == "f")
                                    {
										int offset=0,
											scrollOffset=0;

										Int32.TryParse(xr.GetAttribute("offset"), out offset);
										Int32.TryParse(xr.GetAttribute("scrolloffset"), out scrollOffset);
                                        try
                                        {
                                            p.LastOpenFiles.Add(xr.ReadString(),new[]{offset, scrollOffset});
                                        }
                                        catch { }
                                    }
                                    else break;
                                }
                                break;


                            case "openlastprj":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.OpenLastPrj = xr.Value == "1";
                                }
                                break;

                            case "openlastfiles":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.OpenLastFiles = xr.Value == "1";
                                }
                                break;

                            case "windowstate":
                                if (xr.MoveToAttribute("value"))
                                {
                                    try { p.lastFormState = (WindowState)Convert.ToInt32(xr.Value); }
                                    catch { }
                                }
                                break;

                            case "windowsize":
								p.lastFormSize = new Size();
                                if (xr.MoveToAttribute("x"))
                                {
                                    try { p.lastFormSize.Width = Convert.ToInt32(xr.Value); }
                                    catch { }
                                }
                                if (xr.MoveToAttribute("y"))
                                {
                                    try { p.lastFormSize.Height = Convert.ToInt32(xr.Value); }
                                    catch { }
                                }
                                break;

                            case "retrievenews":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.RetrieveNews = xr.Value == "1";
                                }
                                break;

                            case "externaldbg":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.UseExternalDebugger = xr.Value == "1";
                                }
                                break;

							case "lastselectedribbontab":
								if (xr.MoveToAttribute("value"))
								{
									p.LastSelectedRibbonTab=Convert.ToInt32(xr.Value);
								}
								break;

                            case "watchforupdates":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.WatchForUpdates = xr.Value == "1";
                                }
                                break;

                            case "defprjdir":
                                p.DefaultProjectDirectory = xr.ReadString();
                                break;

                            case "debugger":
                                if (xr.IsEmptyElement) break;
                                while (xr.Read())
                                {
                                    if (xr.LocalName == "bin")
                                    {
                                        p.ExternalDebugger_Bin = xr.ReadString();
                                    }
                                    else if (xr.LocalName == "args")
                                    {
                                        p.ExternalDebugger_Arguments = xr.ReadString();
                                    }
                                    else break;
                                }
                                break;

                            case "lastsearchdir":
                                p.lastSearchDir = xr.ReadString();
                                break;

                            case "verbosedbgoutput":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.VerboseDebugOutput = xr.Value == "1";
                                }
                                break;

                            case "skipunknowncode":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.SkipUnknownCode = xr.Value == "1";
                                }
                                break;

							case "verbosebuild":
								if (xr.MoveToAttribute("value"))
								{
									p.VerboseBuildOutput = xr.Value == "1";
								}
								break;

                            case "autosave":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.DoAutoSaveOnBuilding = xr.Value == "1";
                                }
                                break;

							case "EnableIncrementalBuild":
								if (xr.MoveToAttribute("value"))
									p.EnableIncrementalBuild = xr.Value == "1";
								break;

							case "DefaultBinDirectory":
								p.DefaultBinariesPath = xr.ReadString();
								break;

                            case "highlightings":
                                if (xr.IsEmptyElement) break;
                                while (xr.Read())
                                {
                                    if (xr.LocalName == "f")
                                    {
                                        try
                                        {
                                            string ext = xr.GetAttribute("ext");
                                            p.SyntaxHighlightingEntries.Add(ext, xr.ReadString());
                                        }
                                        catch { }
                                    }
                                    else break;
                                }
                                break;

                            case "shownewconsolewhenexecuting":
                                if (xr.MoveToAttribute("value"))
                                {
                                    p.ShowDebugConsole = xr.Value == "1";
                                }
                                break;

							case "ShowSpeedInfo":
								if (xr.MoveToAttribute("value"))
									p.ShowSpeedInfo = xr.Value == "true";
								break;
                        }
                    }
                }

                xr.Close();
				return p;

            }
            catch {  }
            return null;
		}
Exemple #6
0
        public MainWindow(ReadOnlyCollection <string> args)
        {
            if (!Debugger.IsAttached)
            {
                splashScreen = new SplashScreen("Resources/d-ide_256.png");
                splashScreen.Show(false, true);
            }

            // Init Manager
            WorkbenchLogic.Instance = new WorkbenchLogic(this);
            IDEManager.Instance     = new IDEManager(this);

            // Load global settings
            try
            {
                GlobalProperties.Init();
            }
            catch { }

            InitializeComponent();

            encoding_DropDown.ItemsSource = new[] {
                Encoding.ASCII,
                Encoding.UTF8,
                Encoding.Unicode,
                Encoding.UTF32
            };

            // Init logging support
            ErrorLogger.Instance = new IDELogger(this);

            // Showing the window is required because the DockMgr has to init all panels first before being able to restore last layouts
            Show();

            #region Init panels and their layouts
            Panel_Locals.Name        = "LocalsPanel";
            Panel_Locals.HideOnClose = true;

            StartPage             = new Controls.Panels.StartPage();
            StartPage.Name        = "IDEStartPage";
            StartPage.HideOnClose = true;

            // Note: To enable the docking manager saving&restoring procedures it's needed to name all the panels
            Panel_ProjectExplorer.Name        = "ProjectExplorer";
            Panel_ProjectExplorer.HideOnClose = true;

            Panel_Log.Name           = "Output";
            Panel_Log.DockableStyle |= DockableStyle.AutoHide;

            Panel_ErrorList.Name           = "ErrorList";
            Panel_ErrorList.HideOnClose    = true;
            Panel_ErrorList.DockableStyle |= DockableStyle.AutoHide;

            RestoreDefaultPanelLayout();
            #endregion

            try
            {
                var layoutFile = Path.Combine(IDEInterface.ConfigDirectory, GlobalProperties.LayoutFile);

                // Exclude this call in develop (debug) time
                if (                //!System.Diagnostics.Debugger.IsAttached&&
                    File.Exists(layoutFile))
                {
                    var fcontent = File.ReadAllText(layoutFile);
                    if (!string.IsNullOrWhiteSpace(fcontent))
                    {
                        var s = new StringReader(fcontent);
                        DockMgr.RestoreLayout(s);
                        s.Close();
                    }
                }
            }
            catch (Exception ex) { ErrorLogger.Log(ex); }

            WorkbenchLogic.Instance.InitializeEnvironment(args);

            /*
             * if (GlobalProperties.Instance.IsFirstTimeStart)
             * {
             *      if(splashScreen!=null)
             *              splashScreen.Close(TimeSpan.FromSeconds( 0));
             *      if (MessageBox.Show("D-IDE seems to be launched for the first time. Start configuration now?", "First time startup", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.Yes) == MessageBoxResult.Yes)
             *              new GlobalSettingsDlg() { Owner = this }.ShowDialog();
             * }*/
        }