How to access Gtk.Window in another class? - gtk

This is how the window is constructed:
namespace App {
public class Window : Gtk.ApplicationWindow {
private Granite.ModeSwitch stick_switch;
public Window (Gtk.Application app) {
Object (
application: app,
icon_name: Constants.APP_ICON,
resizable: false
);
// There is more code below this
I want to access this window in another class. How do I do it??
When I initialize it within the constructor of another class using this: var main_window = new App.Window ();, an error is displayed saying that it is missing arguments.
What and how do I need to provide the argument?

You have to pass an Gtk.Application to the construcor:
var main_window = new App.Window(new Gtk.Application("foo.your.app.name", Gtk.ApplicationFlags.FLAGS_NONE);
"foo.your.app.name" is the application ID.
Gtk.ApplicationFlags.FLAGS_NONE are some flags to specify the behavior of the application link, e.g. whether this application is a service or a launcher,....

Related

How to create a custom class in NestJS and work with the instance of the class

I'm trying to create a helper class in NestJS which i can use in every file.
I tried to create the following class:
export class Logging {
public status: string;
private currentLog: Model<LogDocument>;
constructor(#InjectModel(Log.name) readonly log?: Model<LogDocument>) {
// Create a new log item when new instance of class is created
this.currentLog = new this.log({
title: 'New Log',
status: SyncStatusType.IN_PROGRESS,
startTime: new Date(),
});
}
public addCrashLog() {
// Update current log
}
public addSuccessLog() {
// Update current log
}
public finish() {
// Set status and update log
}
}
I want to be able to use this class in every other file and create a new instance of the class if necessary.
const newLog = new Logging();
newLog.addCrashLog();
....
Does someone have an idea how I can archive that with NestJS? Because I'm always having problems with dependency injection in NestJS when I'm trying to create a custom class.
First off, don't add the Logging class to any providers array, as that's what will tell Nest to create the instance. Next, if you're passing the values yourself, you don't need the #InjectModel() there's no need, as you're creating the class yourself. Lastly, just use the class as your example already shows, using the new keyword and handling the instantiation yourself. That should be all there is to it

How to access window.opener while using gwt.jsinterop

I want to access the javascript window.opener via gwt.jsinterop. So i defined my interface like this:
#JsType(isNative=true, namespace=JsPackage.GLOBAL, name="window")
public class Window {
#JsProperty
public static native Window getOpener();
}
But this does not work. It seems i have to define:
#JsType(isNative=true, namespace=JsPackage.GLOBAL)
public class Window {
#JsProperty
public native Window getOpener();
}
But how can i access the basic instance "window" of "Window"? (See different case)
Thanks

CLSA AddChild Default values

I'm using CSLA latest release and trying to add a row with default items to the collection. What I've noticed is the default constructor of the Foo class is called instead of the AddNewCore in the FooList Class. I am unable to get the AddNewCore or the Child_Create methods to get invoked when a new row is added in a XamDataGrid row. (A row is added, but it is from the default constructor of the FooLine Class--i.e. no default values and no MarkAsChild attribute.) Here is the code snippet that is in the FooList class:
protected override FooItem AddNewCore()
{
var item = DataPortal.CreateChild<FooItem>();
MarkAsChild();
Add(item);
return base.AddNewCore();
}
protected override void Child_Create()
{
var item = DataPortal.CreateChild<FooItem>();
MarkAsChild();
Add(item);
base.Child_Create();
}
What am I doing wrong?
AddNewCore() method exists in client side CSLA class 'ExtendedBindingList' with 'void' return type and same method is exists in server side class 'ObservableBindingList' with return type 'ListClass'. So we required to call run time client side method from server side.
Please refer below code for the same.
#if SILVERLIGHT
protected override void AddNewCore()
{
var item = DataPortal.CreateChild<FooItem>();
Add(item);
}
#endif
For information: The reason the above code does not work has to do with the way WPF invokes the New method. Typically, in other frameworks it is possible to hook on to that event, intercept it, and return with default data. With WPF, it is necessary to check the RecordAdding, or RecordAdded trigger events and process the invocations by hand.
In my case, the WPF would look like:
<i:Interaction.Triggers>'
i:EventTrigger EventName="RecordAdded">
<ei:CallMethodAction TargetObject="{Binding}"
MethodName="CreateDefaultAddressValuesCommand" />
</i:EventTrigger>
In the view model:
var idx = FooInformation.FooAddressList.Count - 1;
var address = await FooAddress.CreateAsync();
FooListing.FooAddressList[idx] = address;

GWT null has no properties

I have an issue when I compile the user interface, when i add a method messages.usuario(), Firebug show the error : TypeError: null has no properties
lblUsuario = new Label_2(null.nullMethod()); this is the code of my class :
public class AdministradorMVP implements EntryPoint {
private MessageConstants messages;
#Inject
public void setMensajes(MessageConstants mensajes) {
this.messages = mensajes;
}
private final MyWidgetGinjector injector = GWT.create(MyWidgetGinjector.class);
private Place defaultPlace = new SignInPlace("Admin");
private SimplePanel appWidget = new SimplePanel();
/**
* This is the entry point method.
*/
Label lblUsuario = new Label(messages.usuario());
Label lblNombre = new Label(messages.nombre());
so I can't find the source of the problem, thank you
The GWT compiler generates null.nullMethod() whenever it can statically determine that a particular method is always called on a null reference. In this case, messages has been determined to always be null (either setMensajes is called with a null value or it's not called at all), so messages.usuario() would always throw a NullPointerException, and this is translated into a null.nullMethod() in the generated JavaScript code.
From your code I'm missing the 'boostrap the injection' (see JavaDoc of Ginjector). In other words, you need to trigger the initial inject to take place. Creating MyWidgetGinjector is not enough.
One solution is to add a method void inject(AdministradorMVP entryPoint); to the interface MyWidgetGinjector and in the class AdministradorMVP in onModuleLoad call as (one of) the first statements: injector.inject(this);.

how to parametrize an import in a View?

I am looking for some help and I hope that some good soul out there will be able to give me a hint :)
I am building a new application by using MVVM Light. In this application, when a View is created, it instantiates the corresponding ViewModel by using the MEF import.
Here is some code:
public partial class ContractEditorView : Window
{
public ContractEditorView ()
{
InitializeComponent();
CompositionInitializer.SatisfyImports(this);
}
[Import(ViewModelTypes.ContractEditorViewModel)]
public object ViewModel
{
set
{
DataContext = value;
}
}
}
And here is the export for the ViewModel:
[PartCreationPolicy(CreationPolicy.NonShared)]
[Export(ViewModelTypes.ContractEditorViewModel)]
public class ContractEditorViewModel: ViewModelBase
{
public ContractEditorViewModel()
{
_contract = new Models.Contract();
}
}
Now, this works if I want to open a new window in order to create a new contract... or in other words, it is perfect if I don't need to pass the ID of an existing contract.
However let's suppose I want to use the same View in order to edit an existing contract. In this case I would add a new constructor to the same View, which accepts either a model ID or a model object.
"Unfortunately" the ViewModel is created always in the same way:
[Import(ViewModelTypes.ContractEditorViewModel)]
public object ViewModel
{
set
{
DataContext = value;
}
}
As far as I know, this invokes the standard/no-parameters constructor of the corresponding ViewModel at composition-time.
So what I would like to know is how to differentiate this behavior? How can I call a specific constructor during composition time? Or how can I pass some parameters during the Import?
I really apologize if this question sounds silly, but I have only recently started to use MEF!
Thanks in advance,
Cheers,
Gianluca.
You CAN do this. Check out the Messenger implementation in MVVM-Light. You can pass a NotificationMessage(Of Integer) to send the right ID to the view model. The view model has to register for that type of message, and load it when a message is sent.
MEF Imports by default only have a parameterless constructor.