diff --git a/Content/UniversalEditor.Content.PlatformIndependent/Panels/StartPage.glade b/Content/UniversalEditor.Content.PlatformIndependent/Panels/StartPage.glade index 7d2c90f4..bfd8f485 100644 --- a/Content/UniversalEditor.Content.PlatformIndependent/Panels/StartPage.glade +++ b/Content/UniversalEditor.Content.PlatformIndependent/Panels/StartPage.glade @@ -22,6 +22,12 @@ gtk-open 3 + + + + + + False @@ -187,15 +193,27 @@ True in - + True True + tmRecentDocuments + True + autosize File name + True + True + 0 + + + + 0 + + diff --git a/Libraries/UniversalEditor.UserInterface/Engine.cs b/Libraries/UniversalEditor.UserInterface/Engine.cs index 9cbbc8a4..c59fad33 100644 --- a/Libraries/UniversalEditor.UserInterface/Engine.cs +++ b/Libraries/UniversalEditor.UserInterface/Engine.cs @@ -150,6 +150,7 @@ namespace UniversalEditor.UserInterface // Initialize Recent File Manager Engine.CurrentEngine.RecentFileManager.DataFileName = ((UIApplication)Application.Instance).DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "RecentItems.xml"; Engine.CurrentEngine.RecentFileManager.Load(); + RefreshRecentFilesList(); // Initialize Bookmarks Manager Engine.CurrentEngine.BookmarksManager.DataFileName = ((UIApplication)Application.Instance).DataPath + System.IO.Path.DirectorySeparatorChar.ToString() + "Bookmarks.xml"; @@ -166,6 +167,35 @@ namespace UniversalEditor.UserInterface } + private void AddRecentMenuItem(string FileName) + { + Command mnuFileRecentFiles = ((UIApplication)Application.Instance).Commands["FileRecentFiles"]; + + Command mnuFileRecentFile = new Command(); + mnuFileRecentFile.ID = "FileRecentFile_" + FileName; + mnuFileRecentFile.Title = System.IO.Path.GetFileName(FileName); + // mnuFileRecentFile.ToolTipText = FileName; + ((UIApplication)Application.Instance).Commands.Add(mnuFileRecentFile); + + CommandReferenceCommandItem tsmi = new CommandReferenceCommandItem("FileRecentFile_" + FileName); + mnuFileRecentFiles.Items.Add(tsmi); + } + private void RefreshRecentFilesList() + { + Command mnuFileRecentFiles = ((UIApplication)Application.Instance).Commands["FileRecentFiles"]; + mnuFileRecentFiles.Items.Clear(); + foreach (string fileName in Engine.CurrentEngine.RecentFileManager.FileNames) + { + AddRecentMenuItem(fileName); + } + + Command mnuFileRecentProjects = ((UIApplication)Application.Instance).Commands["FileRecentProjects"]; + + mnuFileRecentFiles.Visible = (mnuFileRecentFiles.Items.Count > 0); + mnuFileRecentProjects.Visible = (mnuFileRecentProjects.Items.Count > 0); + // mnuFileSep3.Visible = ((mnuFileRecentFiles.DropDownItems.Count > 0) || (mnuFileRecentProjects.DropDownItems.Count > 0)); + } + void Application_BeforeShutdown(object sender, System.ComponentModel.CancelEventArgs e) { for (int i = 0; i < ((UIApplication)Application.Instance).Windows.Count; i++) @@ -906,6 +936,20 @@ namespace UniversalEditor.UserInterface protected virtual void InitializeBranding() { + // FIXME: Possible race condition bug, if there is a MessageDialog popped while another thread is fucking around, + // it + NotificationPopup nip = new NotificationPopup(); + nip.Actions.Add(new ActionCommandItem("id1", "Ignore", delegate(object sender, EventArgs e) + { + })); + nip.Actions.Add(new ActionCommandItem("id2", "Show Message Dialog", delegate (object sender, EventArgs e) + { + MessageDialog.ShowDialog("This message dialog being displayed will crash the program. Wait for it...\r\n\r\n Closing the message dialog before the end will avoid this issue."); + })); + nip.Content = "please fix this race condition as soon as possible. if there is a MessageDialog present while another thread is running calling Application.DoEvents may crash the program"; + nip.Summary = "race warning : click button to demonstrate"; + nip.Show(); + // I don't know why this ever was WindowsFormsEngine-specific... // First, attempt to load the branding from Branding.uxt diff --git a/Libraries/UniversalEditor.UserInterface/MainWindow.cs b/Libraries/UniversalEditor.UserInterface/MainWindow.cs index 809e4361..491b7236 100644 --- a/Libraries/UniversalEditor.UserInterface/MainWindow.cs +++ b/Libraries/UniversalEditor.UserInterface/MainWindow.cs @@ -1048,6 +1048,16 @@ namespace UniversalEditor.UserInterface try { InitEditorPage(doc); + + if (doc.Accessor is FileAccessor) + { + // FIXME: support Accessors other than FileAccessor + string fileName = (doc.Accessor as FileAccessor).FileName; + if (!Engine.CurrentEngine.RecentFileManager.FileNames.Contains(fileName)) + { + Engine.CurrentEngine.RecentFileManager.FileNames.Add(fileName); + } + } } catch (System.UnauthorizedAccessException ex) { @@ -1571,35 +1581,6 @@ namespace UniversalEditor.UserInterface return ((UIApplication)Application.Instance).ShowSettingsDialog(); } - private void AddRecentMenuItem(string FileName) - { - Command mnuFileRecentFiles = ((UIApplication)Application.Instance).Commands["FileRecentFiles"]; - - Command mnuFileRecentFile = new Command(); - mnuFileRecentFile.ID = "FileRecentFile_" + FileName; - mnuFileRecentFile.Title = System.IO.Path.GetFileName(FileName); - // mnuFileRecentFile.ToolTipText = FileName; - ((UIApplication)Application.Instance).Commands.Add(mnuFileRecentFile); - - CommandReferenceCommandItem tsmi = new CommandReferenceCommandItem("FileRecentFile_" + FileName); - mnuFileRecentFiles.Items.Add(tsmi); - } - private void RefreshRecentFilesList() - { - Command mnuFileRecentFiles = ((UIApplication)Application.Instance).Commands["FileRecentFiles"]; - mnuFileRecentFiles.Items.Clear(); - foreach (string fileName in Engine.CurrentEngine.RecentFileManager.FileNames) - { - AddRecentMenuItem(fileName); - } - - Command mnuFileRecentProjects = ((UIApplication)Application.Instance).Commands["FileRecentProjects"]; - - mnuFileRecentFiles.Visible = (mnuFileRecentFiles.Items.Count > 0); - mnuFileRecentProjects.Visible = (mnuFileRecentProjects.Items.Count > 0); - // mnuFileSep3.Visible = ((mnuFileRecentFiles.DropDownItems.Count > 0) || (mnuFileRecentProjects.DropDownItems.Count > 0)); - } - public void UpdateStatus(string statusText) { throw new NotImplementedException(); diff --git a/Libraries/UniversalEditor.UserInterface/Pages/StartPage.cs b/Libraries/UniversalEditor.UserInterface/Pages/StartPage.cs index 0f9ca6bd..0d6dd481 100644 --- a/Libraries/UniversalEditor.UserInterface/Pages/StartPage.cs +++ b/Libraries/UniversalEditor.UserInterface/Pages/StartPage.cs @@ -22,6 +22,7 @@ using System; using MBS.Framework; using MBS.Framework.UserInterface; using MBS.Framework.UserInterface.Controls; +using MBS.Framework.UserInterface.Controls.ListView; using MBS.Framework.UserInterface.Layouts; namespace UniversalEditor.UserInterface.Panels @@ -36,6 +37,7 @@ namespace UniversalEditor.UserInterface.Panels private ImageView imgHeader; private Label lblHeader; private Label lblNewsTitle; + private ListViewControl tvRecentDocuments; public StartPage() { @@ -63,6 +65,29 @@ namespace UniversalEditor.UserInterface.Panels ctHeaderImage.Visible = false; ctHeaderText.Visible = true; } + + foreach (string fileName in Engine.CurrentEngine.RecentFileManager.FileNames) + { + TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[] + { + new TreeModelRowColumn(tvRecentDocuments.Model.Columns[0], System.IO.Path.GetFileName(fileName)) + }); + row.SetExtraData("FileName", fileName); + tvRecentDocuments.Model.Rows.Add(row); + } + } + + [EventHandler(nameof(tvRecentDocuments), nameof(ListViewControl.RowActivated))] + private void tvRecentDocuments_RowActivated(object sender, ListViewRowActivatedEventArgs e) + { + if (e.Row != null) + { + string fileName = e.Row.GetExtraData("FileName"); + if (fileName != null) + { + (ParentWindow as MainWindow).OpenFile(fileName); + } + } } private void cmdCreateNewProject_Click(object sender, EventArgs e) diff --git a/Libraries/UniversalEditor.UserInterface/RecentFileManager.cs b/Libraries/UniversalEditor.UserInterface/RecentFileManager.cs index bf484bc4..596de803 100644 --- a/Libraries/UniversalEditor.UserInterface/RecentFileManager.cs +++ b/Libraries/UniversalEditor.UserInterface/RecentFileManager.cs @@ -36,7 +36,7 @@ namespace UniversalEditor.UserInterface if (!System.IO.File.Exists(mvarDataFileName)) return; - Document doc = new Document(mom, xml, new FileAccessor(mvarDataFileName)); + Document.Load(mom, xml, new FileAccessor(mvarDataFileName, false, false, true)); MarkupTagElement tagRecentItems = (mom.Elements["RecentItems"] as MarkupTagElement); if (tagRecentItems == null) return;