In this update, a little code cleanup, a "Need to be Saved" indicator, and new minimum app window width and height settings.
Remember, the latest version of the code is available on GitHub.
A little code cleanup
Given all the refactoring work I'd done on the WPF version of this app (.NETpad), I was never super comfortable with the quick and dirty approach I was taking to WinUIpad. But this was born of necessity: The Windows App SDK isn't just new to me, it's terrible, all kinds of terrible, and lots of things that just work in WPF don't work here. So this really is a rewrite in so many ways, and I've pushed forward in my unsophisticated way, hoping to brute force this thing into a basic app that actually works. But the goal has always been to clean up the code once it does work. And I've been trying to stamp down that annoying part of my brain that doesn't want to wait on doing that.
But after I posted the previous update, timo47 provided me with some very useful feedback, some of which touches on my quick and dirty approach with the Windows App SDK. (And thanks again for that.) I would have gone through it regardless, but because this had been bothering me anyway, I was more eager to do so than I might have been otherwise.
To be clear, I haven't cleaned up the entire program. But before I pushed the previous code update to GitHub, I had been experimenting with different types of state checks (it's possible I'm obsessed with app state), and though I knew that an unnecessary App-level state property I had created and then used in several places was still in there, I had let it go, figuring I would simply remove all that on the next pass.
In making that change, I discovered that my use of this new property in the FileOpMenu_Click() event handler had caused an error that prevented the user from opening a document. So I pushed that change to GitHub as soon as I was sure I had reverted it correctly.
Among other things, timo47 asked me why I was calling the (Main) Window's Close() event handler from the AppWindow's OnClosing() event handler. I wish I could answer that accurately, but it came out of what is now a familiar experience when working with the Windows App SDK: Nothing ever works, and so I find myself adding more and more code to try to get around whatever issue. And then I forget why I went down that particular rabbit hole.
In this case, I was hoping to just create a single method that ran each time the user tried to close the app window, one that would check whether the document needed to be saved and, if so, then save (or save as) the document as needed or back out if the user cancelled. This proved impossible as I wrote in the previous post. And so I settled on two primary event handlers for app closing: OnClosing() in AppWindow and ExitMenu_Click().
I went through too many permutations of each to count or remember, but I did temporarily leave some commented out code in each that was from previous attempts. And...
With technology shaping our everyday lives, how could we not dig deeper?
Thurrott Premium delivers an honest and thorough perspective about the technologies we use and rely on everyday. Discover deeper content as a Premium member.