implement Recent Documents list in start page and main menu
This commit is contained in:
parent
9e2d5b2b93
commit
d762f59ae7
@ -22,6 +22,12 @@
|
||||
<property name="stock">gtk-open</property>
|
||||
<property name="icon_size">3</property>
|
||||
</object>
|
||||
<object class="GtkTreeStore" id="tmRecentDocuments">
|
||||
<columns>
|
||||
<!-- column-name colDocumentFileName -->
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkWindow">
|
||||
<property name="can_focus">False</property>
|
||||
<child type="titlebar">
|
||||
@ -187,15 +193,27 @@
|
||||
<property name="can_focus">True</property>
|
||||
<property name="shadow_type">in</property>
|
||||
<child>
|
||||
<object class="GtkTreeView">
|
||||
<object class="GtkTreeView" id="tvRecentDocuments">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">tmRecentDocuments</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection"/>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkTreeViewColumn" id="chFileName">
|
||||
<property name="resizable">True</property>
|
||||
<property name="sizing">autosize</property>
|
||||
<property name="title" translatable="yes">File name</property>
|
||||
<property name="clickable">True</property>
|
||||
<property name="reorderable">True</property>
|
||||
<property name="sort_column_id">0</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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<string>("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<string>("FileName");
|
||||
if (fileName != null)
|
||||
{
|
||||
(ParentWindow as MainWindow).OpenFile(fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void cmdCreateNewProject_Click(object sender, EventArgs e)
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user