Skip to content

Commit

Permalink
title show current editor display name
Browse files Browse the repository at this point in the history
  • Loading branch information
MikiraSora committed Oct 26, 2024
1 parent 376e63d commit eb0958c
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 55 deletions.
8 changes: 3 additions & 5 deletions OngekiFumenEditor/AppBootstrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,12 +257,10 @@ public async void OnStartupForGUI(object sender, StartupEventArgs e)
if (CheckIfAdminPermission())
{
Log.LogWarn("Program is within admin permission.");
IoC.Get<WindowTitleHelper>().TitleContent = "(以管理员权限运行)";
}
else
{
IoC.Get<WindowTitleHelper>().TitleContent = "";
var prevSuffix = IoC.Get<WindowTitleHelper>().TitleSuffix;
IoC.Get<WindowTitleHelper>().TitleSuffix = prevSuffix + "(以管理员权限运行)";
}
IoC.Get<WindowTitleHelper>().UpdateWindowTitle();

IoC.Get<IShell>().ToolBars.Visible = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ private async Task OpenRecentFileByEditorDocument(RecentRecordInfo info)
}

var doc = pickEditorProvider.Create();
var viewAware = (IViewAware)doc;
viewAware.ViewAttached += (sender, e) =>
var docName = info.DisplayName;
doc.DisplayName = docName;

var viewAware = (IViewAware)doc;
viewAware.ViewAttached += (sender, e) =>
{
var frameworkElement = (FrameworkElement)e.View;

Expand All @@ -104,9 +107,7 @@ private async Task OpenRecentFileByEditorDocument(RecentRecordInfo info)
{
frameworkElement.Loaded -= loadedHandler;
await pickEditorProvider.Open(doc, info.FileName);
var docName = info.DisplayName;

doc.DisplayName = docName;
IoC.Get<IEditorRecentFilesManager>().PostRecord(new(info.FileName, docName, RecentOpenType.CommandOpen));
};
frameworkElement.Loaded += loadedHandler;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Caliburn.Micro;
using Microsoft.CodeAnalysis.Differencing;
using OngekiFumenEditor.Kernel.Scheduler;
using OngekiFumenEditor.Modules.FumenVisualEditor.ViewModels;
using OngekiFumenEditor.Utils;
Expand Down Expand Up @@ -39,6 +40,8 @@ private set
var old = currentActivatedEditor;
currentActivatedEditor = value;
OnActivateEditorChanged?.Invoke(value, old);

IoC.Get<WindowTitleHelper>().UpdateWindowTitleByEditor(value);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ void setupFumen(OngekiFumen cur, OngekiFumen prev)
}

setupFumen(editorProjectData?.Fumen, prevFumen);

if (EditorManager.CurrentActivatedEditor == this)
IoC.Get<WindowTitleHelper>().UpdateWindowTitleByEditor(this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,10 @@ public async void LoadFumen(OngekiFumenDiff diff)

var fumenProvider = IoC.Get<IFumenVisualEditorProvider>();
var editor = IoC.Get<IFumenVisualEditorProvider>().Create();
var viewAware = (IViewAware)editor;
var docName = $"[{Resources.FastOpen}] {diff.RefSet.Title}";
editor.DisplayName = docName;

var viewAware = (IViewAware)editor;
viewAware.ViewAttached += (sender, e) =>
{
var frameworkElement = (FrameworkElement)e.View;
Expand All @@ -310,9 +313,7 @@ public async void LoadFumen(OngekiFumenDiff diff)
{
frameworkElement.Loaded -= loadedHandler;
await fumenProvider.Open(editor, newProj);
var docName = $"[{Resources.FastOpen}] {diff.RefSet.Title}";

editor.DisplayName = docName;
IoC.Get<IEditorRecentFilesManager>().PostRecord(new(diff.FilePath, docName, RecentOpenType.CommandOpen));
};
frameworkElement.Loaded += loadedHandler;
Expand Down
8 changes: 4 additions & 4 deletions OngekiFumenEditor/Utils/DocumentOpenHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ public static async Task<bool> TryOpenOgkrFileAsDocument(string ogkrFilePath)
var newProj = await TryCreateEditorProjectDataModel(ogkrFilePath);
if (newProj is null)
return false;
var docName = await TryFormatOpenFileName(ogkrFilePath);

var fumenProvider = IoC.Get<IFumenVisualEditorProvider>();
var editor = IoC.Get<IFumenVisualEditorProvider>().Create();
editor.DisplayName = docName;

var viewAware = (IViewAware)editor;
viewAware.ViewAttached += (sender, e) =>
{
Expand All @@ -56,10 +58,8 @@ public static async Task<bool> TryOpenOgkrFileAsDocument(string ogkrFilePath)
loadedHandler = async (sender2, e2) =>
{
frameworkElement.Loaded -= loadedHandler;
await fumenProvider.Open(editor, newProj);
var docName = await TryFormatOpenFileName(ogkrFilePath);
await IoC.Get<IFumenVisualEditorProvider>().Open(editor, newProj);

editor.DisplayName = docName;
IoC.Get<IEditorRecentFilesManager>().PostRecord(new(ogkrFilePath, docName, RecentOpenType.CommandOpen));
};
frameworkElement.Loaded += loadedHandler;
Expand Down
111 changes: 72 additions & 39 deletions OngekiFumenEditor/Utils/WindowTitleHelper.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,78 @@
using Gemini.Framework.Services;
using Caliburn.Micro;
using Gemini.Framework.Services;
using OngekiFumenEditor.Modules.FumenVisualEditor.ViewModels;
using System.ComponentModel.Composition;
using System.Windows.Media;

namespace OngekiFumenEditor.Utils
{
[Export(typeof(WindowTitleHelper))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class WindowTitleHelper
{
[Import(typeof(IMainWindow))]
private IMainWindow window = default;

public string TitlePrefix { get; set; } = "Ongeki Fumen Editor";

public string TitleContent
{
get
{
return window.Title;
}
set
{
var title = value;
if (!(title?.StartsWith(TitlePrefix) ?? false))
{
title = TitlePrefix + (string.IsNullOrWhiteSpace(title) ? string.Empty : (" - " + title));
}
window.Title = title;
}
}

public ImageSource Icon
{
get
{
return window.Icon;
}
set
{
window.Icon = value;
}
}
}
[Export(typeof(WindowTitleHelper))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class WindowTitleHelper
{
[Import(typeof(IMainWindow))]
private IMainWindow window = default;

private string titlePrefix = "Ongeki Fumen Editor";
public string TitlePrefix
{
get => titlePrefix;
set
{
titlePrefix = value;
UpdateWindowTitle();
}
}

private string titleSuffix = string.Empty;
public string TitleSuffix
{
get => titleSuffix;
set
{
titleSuffix = value;
UpdateWindowTitle();
}
}

private string titleContent = string.Empty;
public string TitleContent
{
get
{
return titleContent;
}
set
{
titleContent = value;
UpdateWindowTitle();
}
}

public string ActualFormattedWindowTitle => window.Title;

public ImageSource Icon
{
get
{
return window.Icon;
}
set
{
window.Icon = value;
}
}

public void UpdateWindowTitle()
{
var actualTitle = TitlePrefix + TitleContent + TitleSuffix;
window.Title = actualTitle;
}

public void UpdateWindowTitleByEditor(FumenVisualEditorViewModel editor)
{
var titleContent = editor != null ? $" - {editor.DisplayName} " : string.Empty;
TitleContent = titleContent;
}
}
}

0 comments on commit eb0958c

Please sign in to comment.