Menu

MDI many tasks

Help
gyry
2008-11-13
2013-04-26
  • gyry

    gyry - 2008-11-13

    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.

     
    • OVZH

      OVZH - 2008-11-14

      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

       
      • gyry

        gyry - 2008-11-14

        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

         
        • gyry

          gyry - 2008-11-14

          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.

           
          • OVZH

            OVZH - 2008-11-15

            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

             
            • gyry

              gyry - 2008-11-15

              Thank you for your help and  great framework.

              Roman.

               
    • Robert O.

      Robert O. - 2008-12-29

      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]

       
      • OVZH

        OVZH - 2009-01-26

        Hello,

        Please elaborate more on what you're trying to achieve...

        Thanks,
        --
        Oleg Zhukov

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.