private void closeToolStripMenuItem_Click(object sender, EventArgs e) { try { if (codeTabControl.TabCount == 0) { return; } var currentTab = codeTabControl.SelectedTab; if (OpenedProject != null && OpenedProject.FilesChanged.ContainsKey(currentTab.Name) && OpenedProject.FilesChanged[currentTab.Name]) { switch (MessageBox.Show(this, "Save changes in module" + currentTab.Name + '?', "Confirm", MessageBoxButtons.YesNoCancel)) { case DialogResult.Yes: OpenedProject.SaveFile(currentTab.Name); break; case DialogResult.Cancel: return; } } codeTabControl.TabPages.Remove(currentTab); } catch (Exception exc) { MessageBox.Show(exc.Message); } }
/// <summary> /// Close tab when user press on close button in tabs /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void codeTabControl_MouseClick(object sender, MouseEventArgs e) { try { System.Drawing.Font font = codeTabControl.Font; int margin = 3; for (int i = 0; i < codeTabControl.TabCount; i++) { Rectangle tabRect = codeTabControl.GetTabRect(i); RectangleF btnRect = new RectangleF(tabRect.Right - margin - tabCloseButtonSize.Width, tabRect.Top + margin, tabCloseButtonSize.Width, tabCloseButtonSize.Height); if (btnRect.Contains(e.Location)) { if (OpenedProject != null && OpenedProject.FilesChanged.ContainsKey(codeTabControl.TabPages[i].Name) && OpenedProject.FilesChanged[codeTabControl.TabPages[i].Name]) { switch (MessageBox.Show(this, "Save changes in module " + codeTabControl.TabPages[i].Name + '?', "Confirm", MessageBoxButtons.YesNoCancel)) { case DialogResult.Yes: OpenedProject.SaveFile(codeTabControl.TabPages[i].Name); break; case DialogResult.Cancel: return; } } codeTabControl.TabPages.RemoveAt(i); return; } } } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { try { if (codeTabControl.TabCount == 0) { return; } TabPage currentTab = codeTabControl.SelectedTab; string methodName = currentTab.Name; DataGridView dg = (DataGridView)(currentTab.Controls.Find("codeGridView" + methodName, true)[0]); char[,] table = new char[16, 16]; for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { table[i, j] = dg.Rows[i].Cells[j].Value.ToString()[0]; } } OpenedProject.ChangeSource(methodName, table); OpenedProject.SaveFile(methodName); } catch (Exception exc) { MessageBox.Show(exc.Message); } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { try { if (codeTabControl.TabCount == 0) { return; } string name = codeTabControl.SelectedTab.Name; if (name.Length != 1 || !OpenedProject.Sources.ContainsKey(name)) { return; } bool success; string oldName = name; string path = ChooseMethodNameAndPath(ref name, out success); if (success) { OpenedProject.RenameMethod(oldName, name); OpenedProject.FileNames[name] = path; projectExplorerBox.Items.Clear(); foreach (var k in OpenedProject.FileNames) { projectExplorerBox.Items.Add("Module " + k.Key); } codeTabControl.TabPages.RemoveAt(codeTabControl.SelectedIndex); foreach (TabPage a in codeTabControl.TabPages) { this.LoadCodeToTab(a); } this.OpenTab(name); OpenedProject.SaveFile(name); } } catch (Exception exc) { MessageBox.Show(exc.Message); } }