Code Monkey home page Code Monkey logo

Comments (9)

Wuxriff avatar Wuxriff commented on September 6, 2024 1

I can try to implement this in a couple of days if @crackedmind isn't going to get ahead of me.

from remnantsaveguardian.

Razzmatazzz avatar Razzmatazzz commented on September 6, 2024 1

That would be amazing. For whoever gets to it first, here's a rundown of where things stand. Some of this is probably the absolute wrong way to do things.

The "view analyzer" context menu can be enabled by changing its visibility to Visible here:

<ui:MenuItem Name="menuAnalyze" Header="{lex:Loc World Analyzer}" Visibility="Collapsed">

When clicked, that menu option fires an event for the Backups page that provides the backup in question in the event arguments:

private void MenuAnalyze_Click(object sender, System.Windows.RoutedEventArgs e)
{
var backup = dataBackups.SelectedItem as SaveBackup;
if (backup == null)
{
return;
}
BackupSaveViewed?.Invoke(this, new() { SaveBackup = backup });
}

The main window listens for that event, and then attempts to add a new navigation item using a new instance the world analyzer page that loads the backup save's data:

private void BackupsPage_BackupSaveViewed(object? sender, BackupSaveViewedEventArgs e)
{
var pageTag = $"world-analyzer-{e.SaveBackup.SaveDate.Ticks}";
foreach (NavigationItem nav in ViewModel.NavigationItems)
{
if (nav.PageTag == pageTag)
{
RootNavigation.Navigate(pageTag);
return;
}
}
var viewM = Activator.CreateInstance(typeof(WorldAnalyzerViewModel)) as WorldAnalyzerViewModel;
object[] parameters = { viewM, e.SaveBackup.Save.SaveFolderPath };
var page = Activator.CreateInstance(typeof(WorldAnalyzerPage), parameters) as WorldAnalyzerPage;
var navItem = new NavigationItem()
{
Content = $"{Loc.T("World Analyzer")} - {e.SaveBackup.Name}",
ToolTip = $"{Loc.T("World Analyzer")} - {e.SaveBackup.Name}",
PageTag = pageTag,
Icon = SymbolRegular.GlobeClock24,
PageType = typeof(WorldAnalyzerPage),
};
navItem.ContextMenu = new();
var menuItem = new Wpf.Ui.Controls.MenuItem()
{
Header = Loc.T("Close"),
Icon = new SymbolIcon() { Symbol = SymbolRegular.Prohibited24 },
};
menuItem.Click += (clickSender, clickEvent) => {
foreach (NavigationItem nav in ViewModel.NavigationItems)
{
if (nav.PageTag == pageTag)
{
ViewModel.NavigationItems.Remove(navItem);
RootNavigation.Navigate("backups");
break;
}
}
};
navItem.ContextMenu.Items.Add(menuItem);
navItem.Click += (clickSender, clickEvent) =>
{
RootNavigation.NavigateExternal(page);
};
ViewModel.NavigationItems.Add(navItem);
//RootFrame.Navigate(page);
RootNavigation.NavigateExternal(page);
navItem.IsActive = true;
}

The main roadblock I've hit is that navigating to/from this new page seems buggy. Depending on how I try to do it, it appears to be just a duplicate of the existing world analyzer page or can't be selected. Or if I manage to select it via code, it's not possible to select it again after the user has navigated away from it.

from remnantsaveguardian.

Razzmatazzz avatar Razzmatazzz commented on September 6, 2024 1

@Wuxriff The fix only partially works. When you "open" an analzyer for a backup, it appears to open a new page titled with the save backup's name, but it's actually displaying the data for the active backup. It appears to be a full copy of the active save world analyzer page because if you navigate to the missing items tab on the backup analyzer page and then navigate to the active save analyzer page, the missing items tab is also active there.

from remnantsaveguardian.

Wuxriff avatar Wuxriff commented on September 6, 2024

Thx, will take a look 👀

from remnantsaveguardian.

Wuxriff avatar Wuxriff commented on September 6, 2024

Done 👀

from remnantsaveguardian.

Wuxriff avatar Wuxriff commented on September 6, 2024

This is something different. Will check for sure.

from remnantsaveguardian.

Wuxriff avatar Wuxriff commented on September 6, 2024

After some research I came to the conclusion that I don't know how to make the Wpf.Ui framework display the 'selected tab' style while using NavigateExternal method, seems like it's impossible. Since you are using it and MVVM for some reason, then we could rewrite everything to real MVVM with events, but I would not want to do this.

I propose to replace RootNavigation.Navigate(pageTag); to RootNavigation.NavigateExternal(page); (as it was) and postpone until some future huge refactorings.

from remnantsaveguardian.

Razzmatazzz avatar Razzmatazzz commented on September 6, 2024

That was the key! We can do RootNavigation.NavigateExternal(page) and navItem.IsActive = true and things function exactly how the user would expect. Thanks for taking a look at this!

Edit: only thing left is to figure out if there's a way to update the "breadcrumb" title on the main window when we navigate to a backup analyzer page.

Edit again: It's kind of ugly, but we can do a Navigate(pageTag) to set the breadcrumb and then a NavigateExternal(page) to actually set the page.

from remnantsaveguardian.

Wuxriff avatar Wuxriff commented on September 6, 2024

Yeah, we can, but it's against the framework - I tried to find a better solution and removed them in my pull request.
If you are satisfied with how it works now, then I think that this task can be closed as completed 😎

from remnantsaveguardian.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.