Is there possible to have MDI interface with many tasks?
I've played a little with WindowsFormsExample, so there's MainTask with MainView as a MDI parent form.
I've added another task to the project ClientTask, and a new Client form as a view, and I could not have the new form inside MDI...
Any hints?
Regards,
Roman.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You may try to declare the child task's view as an ordinary (non-mdi child) view, but then to assign its MdiParent property in the ActivateView(..) override:
public void override ActivateView(..)
{
this.MdiParent = Controller.Task.ParentTask.MainView as Form;
}
I haven't tried this, so please let me know whether it works or not.
Best Wishes,
--
Oleg Zhukov
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
But .. I'm quite new to the framework, and probably I do sth. wrong.
Let me explain exactly what I do:
1.
On MainForm I've added menu item for a new form. I've added new method to MainViewController:
public void OpenClientForm()
{
Task.TasksManager.StartTask(typeof(ClientTask));
}
2. Client task is like that:
public class ClientTask : TaskBase
{
[IPoint(typeof(ControllerBase), IsCommonTarget = true)]
public const string ClientForm = "Client Form";
public override void OnStart(object param)
{
Navigator.NavigateDirectly(ClientForm);
}
}
3. Client form is as simple as:
[WinformsView(typeof(ClientTask), "Client Form", MdiParent = "Main View")]
public partial class ClientForm : WinFormView<ClientController>
{
public ClientForm()
{
InitializeComponent();
}
}
4. And so I don't know how from the ClientForm get the reference to the MainView....
Do I have to use my overloaded WinformsViewManager? Or probably pass the reference to the main form when I create client task?
I can feel that the solution must be simple, so forgive me my ignorance.
Regards,
Roman
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Ok, so I've found the solution, but I don't think it's good one:
1. The client form is like that:
[WinformsView(typeof(ClientTask), "Client Form")]
public partial class ClientForm : WinFormView<ClientController>
{
public ClientForm()
{
InitializeComponent();
}
public override void Activate(bool activate)
{
MdiParent = Controller.Task.MainVC.View as Form;
base.Activate(activate);
}
}
2. The client task:
public class ClientTask : TaskBase
{
[IPoint(typeof(ClientController), IsCommonTarget = true)]
public const string ClientForm = "Client Form";
public MainViewController MainVC;
public override void OnStart(object param)
{
MainVC = (MainViewController)param;
Navigator.NavigateDirectly(ClientForm);
}
}
3. And the invocation in MainViewController:
public void OpenClientForm()
{
Task.TasksManager.StartTask(typeof(ClientTask), this);
}
What do you think Oleg? Would be better to have an abstract task of "MdiChildTask"?
Regards,
Roman.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This is quite right solution. If later you need to reuse such functionality you will probably refactor it by extracting a parent abstract "MdiChildTask" class.
The only advice from my side is to merely pass the main view (instead of its controller) to the ClientTask... And one more - you could use the Initialize() override instead of Activate(..) in the ClientForm class (my fault - I should have said this earlier).
Best Regards,
--
Oleg Zhukov
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This handles a list it MDI form windows. If a view an MDIpartent demands a window digs it out from this list.
Override WinformViewsManager class:
public class BaseWinformsViewsManager
: WinformsViewsManager
{
protected static Hashtable mdiViews = new Hashtable();
protected override void InitializeFormView(System.Windows.Forms.Form form, MVCSharp.Winforms.Configuration.WinformsViewInfo viewInf)
{
base.InitializeFormView(form, viewInf);
if (form.IsMdiContainer)
{
if (!mdiViews.Contains(viewInf.ViewName))
{
mdiViews[viewInf.ViewName] = form;
form.Disposed += form_Disposed;
}
}
else if (form.MdiParent == null && !String.IsNullOrEmpty(viewInf.MdiParent))
{
form.MdiParent = mdiViews[viewInf.MdiParent] as System.Windows.Forms.Form;
}
}
private static void form_Disposed(object sender, EventArgs e)
{
// memory leak possible?
if (sender is Form)
(sender as Form).Disposed -= form_Disposed;
if (!(sender is IView)) return;
mdiViews.Remove((sender as IView).ViewName);
}
}
and start application with my class:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
TasksManager tasksManager = new TasksManager(WinformsViewsManager.GetDefaultConfig());
tasksManager.Config.ViewsManagerType = typeof(BaseWinformsViewsManager);
tasksManager.StartTask(typeof(MainTask));
Application.Run(Application.OpenForms[0]);
}
}
that likes?
[sorry my english]
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
Is there possible to have MDI interface with many tasks?
I've played a little with WindowsFormsExample, so there's MainTask with MainView as a MDI parent form.
I've added another task to the project ClientTask, and a new Client form as a view, and I could not have the new form inside MDI...
Any hints?
Regards,
Roman.
Hi Roman,
You may try to declare the child task's view as an ordinary (non-mdi child) view, but then to assign its MdiParent property in the ActivateView(..) override:
public void override ActivateView(..)
{
this.MdiParent = Controller.Task.ParentTask.MainView as Form;
}
I haven't tried this, so please let me know whether it works or not.
Best Wishes,
--
Oleg Zhukov
Thank you for reply!
But .. I'm quite new to the framework, and probably I do sth. wrong.
Let me explain exactly what I do:
1.
On MainForm I've added menu item for a new form. I've added new method to MainViewController:
public void OpenClientForm()
{
Task.TasksManager.StartTask(typeof(ClientTask));
}
2. Client task is like that:
public class ClientTask : TaskBase
{
[IPoint(typeof(ControllerBase), IsCommonTarget = true)]
public const string ClientForm = "Client Form";
public override void OnStart(object param)
{
Navigator.NavigateDirectly(ClientForm);
}
}
3. Client form is as simple as:
[WinformsView(typeof(ClientTask), "Client Form", MdiParent = "Main View")]
public partial class ClientForm : WinFormView<ClientController>
{
public ClientForm()
{
InitializeComponent();
}
}
4. And so I don't know how from the ClientForm get the reference to the MainView....
Do I have to use my overloaded WinformsViewManager? Or probably pass the reference to the main form when I create client task?
I can feel that the solution must be simple, so forgive me my ignorance.
Regards,
Roman
Ok, so I've found the solution, but I don't think it's good one:
1. The client form is like that:
[WinformsView(typeof(ClientTask), "Client Form")]
public partial class ClientForm : WinFormView<ClientController>
{
public ClientForm()
{
InitializeComponent();
}
public override void Activate(bool activate)
{
MdiParent = Controller.Task.MainVC.View as Form;
base.Activate(activate);
}
}
2. The client task:
public class ClientTask : TaskBase
{
[IPoint(typeof(ClientController), IsCommonTarget = true)]
public const string ClientForm = "Client Form";
public MainViewController MainVC;
public override void OnStart(object param)
{
MainVC = (MainViewController)param;
Navigator.NavigateDirectly(ClientForm);
}
}
3. And the invocation in MainViewController:
public void OpenClientForm()
{
Task.TasksManager.StartTask(typeof(ClientTask), this);
}
What do you think Oleg? Would be better to have an abstract task of "MdiChildTask"?
Regards,
Roman.
Roman,
This is quite right solution. If later you need to reuse such functionality you will probably refactor it by extracting a parent abstract "MdiChildTask" class.
The only advice from my side is to merely pass the main view (instead of its controller) to the ClientTask... And one more - you could use the Initialize() override instead of Activate(..) in the ClientForm class (my fault - I should have said this earlier).
Best Regards,
--
Oleg Zhukov
Thank you for your help and great framework.
Roman.
Hi All!
This handles a list it MDI form windows. If a view an MDIpartent demands a window digs it out from this list.
Override WinformViewsManager class:
public class BaseWinformsViewsManager
: WinformsViewsManager
{
protected static Hashtable mdiViews = new Hashtable();
protected override void InitializeFormView(System.Windows.Forms.Form form, MVCSharp.Winforms.Configuration.WinformsViewInfo viewInf)
{
base.InitializeFormView(form, viewInf);
if (form.IsMdiContainer)
{
if (!mdiViews.Contains(viewInf.ViewName))
{
mdiViews[viewInf.ViewName] = form;
form.Disposed += form_Disposed;
}
}
else if (form.MdiParent == null && !String.IsNullOrEmpty(viewInf.MdiParent))
{
form.MdiParent = mdiViews[viewInf.MdiParent] as System.Windows.Forms.Form;
}
}
private static void form_Disposed(object sender, EventArgs e)
{
// memory leak possible?
if (sender is Form)
(sender as Form).Disposed -= form_Disposed;
if (!(sender is IView)) return;
mdiViews.Remove((sender as IView).ViewName);
}
}
and start application with my class:
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
TasksManager tasksManager = new TasksManager(WinformsViewsManager.GetDefaultConfig());
tasksManager.Config.ViewsManagerType = typeof(BaseWinformsViewsManager);
tasksManager.StartTask(typeof(MainTask));
Application.Run(Application.OpenForms[0]);
}
}
that likes?
[sorry my english]
Hello,
Please elaborate more on what you're trying to achieve...
Thanks,
--
Oleg Zhukov