Esempio n. 1
0
 public void AddWindow(System.Type ttsformtype, string workspace = null, TTSFormState state = null)
 {
     if (!ttsformtype.IsSubclassOf(typeof(TTSForm)))
     {
         throw new System.Exception("Invalid window type.");
     }
     if (!this.IsWindowAllowed(ttsformtype))
     {
         return;
     }
     workspace = (workspace ?? this.CurrentWorkspace);
     if (state == null)
     {
         WorkspaceItem.WindowItem windowItem = this.Workspaces[workspace].WindowItems.FindLast((WorkspaceItem.WindowItem x) => x.Window.GetType() == ttsformtype);
         if (windowItem != null && System.Windows.Forms.Control.ModifierKeys != System.Windows.Forms.Keys.Shift)
         {
             this.LastFocusedType.Enqueue(ttsformtype);
             if (this.LastFocusedType.Count > 2)
             {
                 System.Type lastformtype = this.LastFocusedType.Dequeue();
                 if (this.LastFocusedType.All((System.Type x) => x == lastformtype))
                 {
                     ((Client)ThreadHelper.MainThread).ShowInfo("Additional Windows", "Hold [Shift] when clicking a menu item to open additional copies of the same window.");
                 }
             }
             windowItem.Window.Activate();
             return;
         }
     }
     TTSForm form = (TTSForm)System.Activator.CreateInstance(ttsformtype, new object[]
     {
         state
     });
     form.MdiParent = this.MDIParent;
     TTSToolStripMenuItem menuitem = new TTSToolStripMenuItem(form.Text, null, delegate(object sender, System.EventArgs e)
     {
         form.Focus();
     });
     form.FormClosed += delegate(object sender, System.Windows.Forms.FormClosedEventArgs e)
     {
         this.WindowDropDown.DropDownItems.Remove(menuitem);
         this.Workspaces[workspace].WindowItems.RemoveAll((WorkspaceItem.WindowItem x) => x.Window == form);
         this.WindowDropDown.Text = string.Format("Windows ({0})", this.Workspaces[workspace].WindowItems.Count);
     };
     form.Activated += delegate(object sender, System.EventArgs e)
     {
         menuitem.Checked = true;
     };
     form.Deactivate += delegate(object sender, System.EventArgs e)
     {
         menuitem.Checked = false;
     };
     this.Workspaces[workspace].WindowItems.Add(new WorkspaceItem.WindowItem
     {
         Window = form,
         WindowMenuItem = menuitem
     });
     this.WindowDropDown.Text = string.Format("Windows ({0})", this.Workspaces[workspace].WindowItems.Count);
     if (workspace == this.CurrentWorkspace)
     {
         this.WindowDropDown.DropDownItems.Add(menuitem);
         form.Show();
     }
 }
Esempio n. 2
0
 public void AddWorkspace(string name, bool select = false)
 {
     name = name.Trim();
     if (string.IsNullOrWhiteSpace(name) || this.Workspaces.ContainsKey(name))
     {
         throw new System.Exception("Invalid workspace name.");
     }
     TTSToolStripMenuItem tTSToolStripMenuItem = new TTSToolStripMenuItem(name, null, delegate(object sender, System.EventArgs e)
     {
         System.Windows.Forms.Form[] mdiChildren = this.MDIParent.MdiChildren;
         System.Windows.Forms.Form form;
         for (int i = 0; i < mdiChildren.Length; i++)
         {
             form = mdiChildren[i];
             if (form is TTSForm)
             {
                 if (this.Workspaces[name].WindowItems.Exists((WorkspaceItem.WindowItem x) => x.Window == form))
                 {
                     form.Show();
                 }
                 else
                 {
                     form.Hide();
                 }
             }
         }
         foreach (System.Windows.Forms.ToolStripItem toolStripItem in this.WorkspaceDropDown.DropDownItems)
         {
             if (toolStripItem is TTSToolStripMenuItem)
             {
                 ((TTSToolStripMenuItem)toolStripItem).Checked = false;
             }
         }
         foreach (WorkspaceItem.WindowItem current in this.Workspaces[this.CurrentWorkspace].WindowItems)
         {
             this.WindowDropDown.DropDownItems.Remove(current.WindowMenuItem);
         }
         foreach (WorkspaceItem.WindowItem current2 in this.Workspaces[name].WindowItems)
         {
             this.WindowDropDown.DropDownItems.Add(current2.WindowMenuItem);
         }
         ((TTSToolStripMenuItem)sender).Checked = true;
         this.CurrentWorkspace = name;
         this.WindowDropDown.Text = string.Format("Windows ({0})", this.Workspaces[name].WindowItems.Count);
         this.WorkspaceDropDown.Text = name;
     });
     this.WorkspaceDropDown.DropDownItems.Add(tTSToolStripMenuItem);
     this.Workspaces.Add(name, new WorkspaceItem
     {
         WorkspaceMenuItem = tTSToolStripMenuItem
     });
     if (select)
     {
         tTSToolStripMenuItem.PerformClick();
     }
 }