public static CloserTabLabel InsertTabPage (Notebook book, Widget page, string label) { var tab = new CloserTabLabel () { Text = label }; tab.Closer.Pressed += (sender, e) => { MainWindow.OnCloseSourceFile (tab.CloseKeyData); book.Remove (page); }; book.InsertPage (page, tab, book.NPages); tab.ShowAll (); return tab; }
void CreatePageWidget (SectionPage page) { List<PanelInstance> boxPanels = new List<PanelInstance> (); List<PanelInstance> tabPanels = new List<PanelInstance> (); foreach (PanelInstance pi in page.Panels) { if (pi.Widget == null) { pi.Widget = pi.Panel.CreatePanelWidget (); //HACK: work around bug 469427 - broken themes match on widget names if (pi.Widget.Name.IndexOf ("Panel") > 0) pi.Widget.Name = pi.Widget.Name.Replace ("Panel", "_"); } else if (pi.Widget.Parent != null) ((Gtk.Container) pi.Widget.Parent).Remove (pi.Widget); if (pi.Node.Grouping == PanelGrouping.Tab) tabPanels.Add (pi); else boxPanels.Add (pi); } // Try to fit panels with grouping=box or auto in the main page. // If they don't fit. Move auto panels to its own tab page. int mainPageSize; bool fits; do { PanelInstance lastAuto = null; mainPageSize = 0; foreach (PanelInstance pi in boxPanels) { if (pi.Node.Grouping == PanelGrouping.Auto) lastAuto = pi; // HACK: This we are parenting/unparenting the widget here as a workaround // for a layout issue. To properly calculate the size of the widget, the widget // needs to have the style that it will have when added to the window. pi.Widget.Parent = this; mainPageSize += pi.Widget.SizeRequest ().Height + 6; pi.Widget.Unparent (); } fits = mainPageSize <= pageFrame.Allocation.Height; if (!fits) { if (lastAuto != null && boxPanels.Count > 1) { boxPanels.Remove (lastAuto); tabPanels.Insert (0, lastAuto); } else { fits = true; } } } while (!fits); Gtk.VBox box = new VBox (false, 12); box.Show (); for (int n=0; n<boxPanels.Count; n++) { if (n != 0) { HSeparator sep = new HSeparator (); sep.Show (); box.PackStart (sep, false, false, 0); } PanelInstance pi = boxPanels [n]; box.PackStart (pi.Widget, pi.Node.Fill, pi.Node.Fill, 0); pi.Widget.Show (); } box.BorderWidth = 12; if (tabPanels.Count > 0) { /* SquaredNotebook nb = new SquaredNotebook (); nb.Show (); nb.AddTab (box, GettextCatalog.GetString ("General")); foreach (PanelInstance pi in tabPanels) { Gtk.Alignment a = new Alignment (0, 0, 1, 1); a.BorderWidth = 9; a.Show (); a.Add (pi.Widget); nb.AddTab (a, GettextCatalog.GetString (pi.Node.Label)); pi.Widget.Show (); }*/ Gtk.Notebook nb = new Notebook (); nb.Show (); Gtk.Label blab = new Gtk.Label (GettextCatalog.GetString ("General")); blab.Show (); box.BorderWidth = 9; nb.InsertPage (box, blab, -1); foreach (PanelInstance pi in tabPanels) { Gtk.Label lab = new Gtk.Label (GettextCatalog.GetString (pi.Node.Label)); lab.Show (); Gtk.Alignment a = new Alignment (0, 0, 1, 1); a.BorderWidth = 9; a.Show (); a.Add (pi.Widget); nb.InsertPage (a, lab, -1); pi.Widget.Show (); } page.Widget = nb; nb.BorderWidth = 12; } else { page.Widget = box; } }
/// <summary> /// Adds the tab from file. Use this method only if you want to save a file to a new filename. /// </summary> /// <param name='_nb'> /// The notebook. /// </param> /// <param name='_fileNameNew'> /// The new Filename /// </param> /// <param name='_pageindex'> /// The index of the page. /// </param> public static void AddTabFromFile(Notebook _nb, string _fileNameNew, int _pageindex) { try { if (System.IO.File.Exists (_fileNameNew)) { //FileName = FileNameNew; //Fixme: If nothing happens, change this comment. libTerminus.cRegex newregex; if (g_tmp != null) { newregex = g_tmp; g_tmp = null; } else { newregex = new cRegex (_fileNameNew); } _nb.InsertPage (newregex, new Label (new FileInfo (_fileNameNew).Name, ref _nb, newregex), _pageindex); _nb.ShowAll (); g_files.Add (_fileNameNew); } else { libTerminus.cRegex newregex = new cRegex (_fileNameNew); _nb.InsertPage (newregex, new Label (Catalog.GetString ("New Phrase"), ref _nb, newregex), _pageindex); _nb.ShowAll (); g_files.Add (_fileNameNew); } } catch (Exception ex) { MessageBox.Show ("error: " + ex.Message, cTerminus.g_programName, ButtonsType.Close, MessageType.Error); } }