示例#1
0
        private void RefreshRecentProjectsList()
        {
            openRecentToolStripMenuItem.DropDownItems.Clear();

            if (Properties.Settings.Default.RecentProjects != null && Properties.Settings.Default.RecentProjects.Count > 0)
            {
                foreach (var fileName in Properties.Settings.Default.RecentProjects)
                {
                    if (fileName == _editor.Level.Settings.LevelFilePath)   // Skip currently loaded level
                    {
                        continue;
                    }

                    var item = new ToolStripMenuItem()
                    {
                        Name = fileName, Text = fileName
                    };
                    item.Click += (s, e) => EditorActions.OpenLevel(this, ((ToolStripMenuItem)s).Text);
                    openRecentToolStripMenuItem.DropDownItems.Add(item);
                }
            }

            // Add "Clear recent files" option
            openRecentToolStripMenuItem.DropDownItems.Add(new ToolStripSeparator());
            var item2 = new ToolStripMenuItem()
            {
                Name = "clearRecentMenuItem", Text = "Clear recent file list"
            };

            item2.Click += (s, e) => { Properties.Settings.Default.RecentProjects.Clear(); RefreshRecentProjectsList(); Properties.Settings.Default.Save(); };
            openRecentToolStripMenuItem.DropDownItems.Add(item2);

            // Disable menu item, if list is empty
            openRecentToolStripMenuItem.Enabled = openRecentToolStripMenuItem.DropDownItems.Count > 2;
        }
示例#2
0
        protected override void WndProc(ref Message message)
        {
            switch (message.Msg)
            {
            case SingleInstanceManagement.WM_COPYDATA:
                var fileName = SingleInstanceManagement.Catch(ref message);
                if (fileName != null && Path.GetExtension(fileName) == ".prj2")
                {
                    SingleInstanceManagement.RestoreWindowState(this);

                    if (_editor.Level.Settings.LevelFilePath != fileName)
                    {
                        // Try to open file only if main window is opened, otherwise try to close everything.
                        for (int i = Application.OpenForms.Count - 1; i >= 0; i--)
                        {
                            if (Application.OpenForms[i].Name != Name && !(Application.OpenForms[i] is PopUpInfo))
                            {
                                Application.OpenForms[i].Close();
                            }
                        }

                        EditorActions.OpenLevel(this, fileName);
                    }
                }
                break;

            case SingleInstanceManagement.WM_SHOWWINDOW:
                SingleInstanceManagement.RestoreWindowState(this);
                break;

            default:
                base.WndProc(ref message);
                break;
            }
        }
示例#3
0
        public static void Main(string[] args)
        {
            string           startFile      = null;
            string           batchFile      = null;
            bool             doBatchCompile = false;
            BatchCompileList batchList      = null;

            if (args.Length >= 1)
            {
                // Open files on start
                if (args[0].EndsWith(".prj2", StringComparison.InvariantCultureIgnoreCase))
                {
                    startFile = args[0];
                }

                // Batch-compile levels
                if (args[0].EndsWith(".xml", StringComparison.InvariantCultureIgnoreCase))
                {
                    batchFile      = args[0];
                    batchList      = BatchCompileList.ReadFromXml(batchFile);
                    doBatchCompile = batchList?.Files.Count > 0;
                }
            }

            // Load configuration
            var initialEvents = new List <LogEventInfo>();
            var configuration = new Configuration().LoadOrUseDefault <Configuration>(initialEvents);

            // Update DarkUI configuration
            Colors.Brightness = configuration.UI_FormColor_Brightness / 100.0f;

            if (configuration.Editor_AllowMultipleInstances || doBatchCompile ||
                mutex.WaitOne(TimeSpan.Zero, true))
            {
                // Setup logging
                using (var log = new Logging(configuration.Log_MinLevel, configuration.Log_WriteToFile, configuration.Log_ArchiveN, initialEvents))
                {
                    // Create configuration file
                    configuration.SaveTry();

                    // Setup application
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
                    Application.ThreadException += (sender, e) =>
                    {
                        log.HandleException(e.Exception);
                        using (var dialog = new ThreadExceptionDialog(e.Exception))
                            if (dialog.ShowDialog() == DialogResult.Abort)
                            {
                                Environment.Exit(1);
                            }
                    };
                    Application.AddMessageFilter(new ControlScrollFilter());
                    SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext());

                    if (!File.Exists(Application.StartupPath + "\\Catalogs\\TrCatalog.xml") ||
                        !File.Exists(Application.StartupPath + "\\Catalogs\\NgCatalog.xml"))
                    {
                        MessageBox.Show("One of the catalog files is missing.\nMake sure you have TrCatalog.xml and NgCatalog.xml in /Catalogs/ subfolder.");
                        Environment.Exit(1);
                    }

                    // Load catalogs
                    TrCatalog.LoadCatalog(Application.StartupPath + "\\Catalogs\\TrCatalog.xml");
                    NgCatalog.LoadCatalog(Application.StartupPath + "\\Catalogs\\NgCatalog.xml");

                    // Run
                    Editor editor = new Editor(SynchronizationContext.Current, configuration);
                    Editor.Instance = editor;

                    // Run editor normally if no batch compile is pending.
                    // Otherwise, don't load main form and jump straight to batch-compiling levels.

                    if (!doBatchCompile)
                    {
                        using (FormMain form = new FormMain(editor))
                        {
                            form.Show();

                            if (!string.IsNullOrEmpty(startFile)) // Open files on start
                            {
                                if (startFile.EndsWith(".prj", StringComparison.InvariantCultureIgnoreCase))
                                {
                                    EditorActions.OpenLevelPrj(form, startFile);
                                }
                                else
                                {
                                    EditorActions.OpenLevel(form, startFile);
                                }
                            }
                            else if (editor.Configuration.Editor_OpenLastProjectOnStartup)
                            {
                                if (Properties.Settings.Default.RecentProjects != null && Properties.Settings.Default.RecentProjects.Count > 0 &&
                                    File.Exists(Properties.Settings.Default.RecentProjects[0]))
                                {
                                    EditorActions.OpenLevel(form, Properties.Settings.Default.RecentProjects[0]);
                                }
                            }
                            Application.Run(form);
                        }
                    }
                    else
                    {
                        EditorActions.BuildInBatch(editor, batchList, batchFile);
                    }
                }
            }
            else if (startFile != null) // Send opening file to existing editor instance
            {
                SingleInstanceManagement.Send(Process.GetCurrentProcess(), new List <string>()
                {
                    ".prj2"
                }, startFile);
            }
            else // Just bring editor to top, if user tries to launch another copy
            {
                SingleInstanceManagement.Bump(Process.GetCurrentProcess());
            }
        }