You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the app I’m building with Watson, the moment I had a second window (in my case, a Welcome window), it made sense to pull out most of the functionality from MainWindow into an abstract BaseWindow class.
This is actually something I considered before but my concern is that I don’t want to over-complicate the generated project and possibly create more work for people who don’t want/need the base class.
That said, with a BaseWindow class, the MainWindow class would feel much more like a blank canvas.
The way I’ve implemented it in my project is to have a template method:
protectedabstractvoid create_layout ();
That’s called during construction:
// This constructor will be called every time an instance of this class is created.
construct {
// State preservation: save window dimensions and location on window close.// See: https://docs.elementary.io/hig/user-workflow/closing
set_up_state_preservation ();
// State preservation: restore window dimensions and location from last run.// See https://docs.elementary.io/hig/user-workflow/normal-launch#state
restore_window_state ();
// Create window layout.
_create_layout ();
// Set up actions (with accelerators) for full screen, quit, etc.
set_up_actions ();
// Make all widgets (the interface) visible.
show_all ();
}
// Layout.// Template method. Implement this in your subclasses to layout your views.protectedabstractvoid create_layout ();
privatevoid _create_layout () {
// Unlike GTK, in Handy, the header bar is added to the window’s content area.// See https://gnome.pages.gitlab.gnome.org/libhandy/doc/1-latest/HdyHeaderBar.html
toolbar =newComet.Widgets.HeaderBar ();
grid =newGtk.Grid ();
grid.attach (toolbar, 0, 0);
// Call the template method so subclasses can instantiate their own unique views.
create_layout ();
add (grid);
}
With that, MainWindow simply becomes:
namespace MyApp {
public class MainWindow : MyApp.BaseWindow {
public MainWindow (Comet.Application application) {
base (application);
}
protected override void create_layout () {
// Instantiate your view here.
// You can attach your components to the grid property.
show_all ();
}
}
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
In the app I’m building with Watson, the moment I had a second window (in my case, a Welcome window), it made sense to pull out most of the functionality from
MainWindowinto an abstractBaseWindowclass.This is actually something I considered before but my concern is that I don’t want to over-complicate the generated project and possibly create more work for people who don’t want/need the base class.
That said, with a BaseWindow class, the
MainWindowclass would feel much more like a blank canvas.The way I’ve implemented it in my project is to have a template method:
That’s called during construction:
With that,
MainWindowsimply becomes:Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions