Exemple #1
0
        private void AddNewTabPage(IEnumerable <PListDefinition> definitions)
        {
            TabPage tabPage;

            _NewTabPageCounter++;
            string header = "new " + _NewTabPageCounter;
            string tabKey = "_" + header;

            tabPage = new TabPage(header);

            PListControl control = new PListControl(tabKey);

            if (definitions != null)
            {
                control.Update(definitions);
            }

            control.Dock = DockStyle.Fill;

            control.Saved        += new EventHandler <EventArgs>(control_Saved);
            control.Duplicate    += new EventHandler <DuplicateEventArgs>(control_Duplicate);
            control.CloseRequest += new EventHandler <EventArgs>(control_CloseRequest);

            tabPage.Controls.Add(control);

            _TabPages.Add(tabKey, tabPage);

            _TabControl.TabPages.Add(tabPage);
            _TabControl.SelectedTab = tabPage;

            SaveUserSettings();
        }
Exemple #2
0
        private void CloseTab(PListControl control)
        {
            _TabControl.TabPages.Remove(_TabPages[control.TabKey]);
            _TabPages.Remove(control.TabKey);

            control.Dispose();
        }
Exemple #3
0
        void control_CloseRequest(object sender, EventArgs e)
        {
            PListControl control = sender as PListControl;

            if (control != null)
            {
                if (!File.Exists(control.TabKey) ||
                    control.IsDirty)
                {
                    switch (MessageBox.Show("Do you want to save changes?", "Save Changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information))
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        if (control.Save())
                        {
                            CloseTab(control);
                        }
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        CloseTab(control);
                        break;
                    }
                }
                else
                {
                    CloseTab(control);
                }
            }
        }
Exemple #4
0
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (_TabControl.SelectedTab != null &&
         _TabControl.SelectedTab.Controls.Count > 0)
     {
         PListControl control = _TabControl.SelectedTab.Controls[0] as PListControl;
         if (control != null)
         {
             control.Save();
         }
     }
 }
Exemple #5
0
        private void LoadTabPage(FileInfo fileInfo)
        {
            if (_TabPages.ContainsKey(fileInfo.FullName))
            {
                BindingList <PListDefinition> list = XmlSerializationHelper <BindingList <PListDefinition> > .ConvertFromFile(fileInfo.FullName);

                if (list != null)
                {
                    PListControl control = _TabControl.SelectedTab.Controls[0] as PListControl;
                    if (control != null)
                    {
                        control.Update(list);
                    }
                }
                else
                {
                    MessageBox.Show("Unable to load definition file " + fileInfo.FullName + ".", "Load Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                _TabControl.SelectedTab = _TabPages[fileInfo.FullName];
                return;
            }
            else
            {
                BindingList <PListDefinition> list = XmlSerializationHelper <BindingList <PListDefinition> > .ConvertFromFile(fileInfo.FullName);

                if (list != null)
                {
                    TabPage      tabPage = new TabPage(fileInfo.Name);
                    PListControl control = new PListControl(list, fileInfo, fileInfo.FullName);
                    control.Dock = DockStyle.Fill;

                    control.Saved        += new EventHandler <EventArgs>(control_Saved);
                    control.Duplicate    += new EventHandler <DuplicateEventArgs>(control_Duplicate);
                    control.CloseRequest += new EventHandler <EventArgs>(control_CloseRequest);

                    tabPage.Controls.Add(control);

                    _TabPages.Add(fileInfo.FullName, tabPage);

                    _TabControl.TabPages.Add(tabPage);
                    _TabControl.SelectedTab = tabPage;

                    SaveUserSettings();
                }
                else
                {
                    MessageBox.Show("Unable to load definition file " + fileInfo.FullName + ".", "Load Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Exemple #6
0
        void control_Saved(object sender, EventArgs e)
        {
            PListControl control = sender as PListControl;

            if (control != null)
            {
                if (control.TabKey != control.FileInfo.FullName)
                {// new item
                    if (_TabPages.ContainsKey(control.FileInfo.FullName))
                    {
                        _TabControl.TabPages.Remove(_TabPages[control.TabKey]);
                        _TabPages.Remove(control.TabKey);
                        LoadTabPage(control.FileInfo);
                    }
                    else
                    {
                        _TabPages.Add(control.FileInfo.FullName, _TabPages[control.TabKey]);
                        _TabPages.Remove(control.TabKey);
                        _TabPages[control.FileInfo.FullName].Text = control.FileInfo.Name;
                        control.TabKey = control.FileInfo.FullName;
                    }
                }
            }
        }