public MainWindow() : base(WindowType.Toplevel) { GardenData.LoadedData = GardenData.LoadedData = new GardenData("new project"); Title = "Garden project '" + GardenData.LoadedData.Name + "'"; //GardenData.LoadedData = GardenPlanner.MainClass.TestData(); PlantSideVPaned.Add1(FamilyPlantVarietySelector); PlantAreaInfoVPaned.Add1(PlantBox); PlantAreaInfoVPaned.Add2(AreaInfo); PlantSideVPaned.Add2(PlantAreaInfoVPaned); TopPanedToolboxVPaned.Add1(GraphicsSidebarHPaned); TopPanedToolboxVPaned.Add2(ToolBox); Frame frame; PlantBox.Add(PlantAddButton); PlantBox.Add(PlantInfoButton); PlantBox.Add(PlantEditButton); ToolBox.Add(AreaNewButton); ToolBox.Add(AreaCancelButton); ToolBox.Add(AreaTypeComboBox); ToolBox.Add(AreaEditButton); ToolBox.Add(AreaDeleteButton); frame = new Frame("Zoom"); frame.Add(ZoomButton); ToolBox.Add(frame); frame = new Frame("Date"); VButtonBox buttonBox = new VButtonBox(); //yearButton = new SpinButton(GardenData.GetFirstYear(), GardenData.GetLastYear(), 1); yearButton = new SpinButton(settings.MinYear, settings.MaxYear, 1); buttonBox.Add(yearButton); buttonBox.Add(monthButton); frame.Add(buttonBox); ToolBox.Add(frame); foreach (Widget w in TopVBox.Children) { TopVBox.Remove(w); } TopVBox.Add(MenuBar); TopVBox.Add(TopPanedToolboxVPaned); if (this.Child == null) { this.Add(TopVBox); } ResetForNewData(); FamilyPlantVarietySelector.SetSizeRequest(100, 400); AreaInfo.WrapMode = WrapMode.Word; AreaInfo.Editable = false; PlantAddButton.Sensitive = false; PlantAddButton.Clicked += (sender, e) => { GardenDrawingArea area = GardenDrawingArea.ActiveInstance; if (area.SelectedArea is Planting planting && SelectedEntry is PlantVariety variety) { EditPlantingInfoWindow.ShowPlantingInfoWindow((PlantingInfo plantingInfo) => { planting.AddVariety(variety, plantingInfo); GardenDrawingArea.ActiveInstance.Draw(); ShowAreaSelectionInfo(area.SelectedArea); }, planting, variety.Name); } ; }; PlantInfoButton.Clicked += (object sender, System.EventArgs e) => { if (SelectedEntry is PlantFamily family) { InfoPlantFamilyWindow.ShowWindow(family, false); } else if (SelectedEntry is Plant plant) { InfoPlantWindow.ShowWindow(plant, false); } else if (SelectedEntry is PlantVariety variety) { InfoPlantVarietyWindow.ShowWindow(variety, false); } }; PlantEditButton.Clicked += (object sender, System.EventArgs e) => { if (SelectedEntry is PlantFamily family) { EditPlantFamilyWindow.ShowWindow(family); } else if (SelectedEntry is Plant plant) { EditPlantWindow.ShowWindow(plant); } else if (SelectedEntry is PlantVariety variety) { EditPlantVarietyWindow.ShowWindow(variety); } }; ZoomButton.Value = GardenDrawingArea.Zoom; ZoomButton.Events = Gdk.EventMask.ButtonPressMask | Gdk.EventMask.ButtonReleaseMask | Gdk.EventMask.KeyPressMask | Gdk.EventMask.KeyReleaseMask; ZoomButton.TooltipText = "Zoom"; AreaNewButton.Clicked += (object sender, System.EventArgs e) => { if (AreaCancelButtonClicked) { AreaCancelButtonClicked = false; AreaCancelButton.Sensitive = false; if (GardenDrawingArea.ActiveInstance != null) { GardenDrawingArea.ActiveInstance.UndoSelection(); GardenDrawingArea.ActiveInstance.NewPoints.Clear(); GardenDrawingArea.ActiveInstance.Draw(); } } else if (!AreaNewButton.Active)//deactivated { AreaCancelButton.Sensitive = false; if (GardenDrawingArea.ActiveInstance != null) { List <GardenPoint> points = GardenDrawingArea.ActiveInstance.NewPoints; switch (AreaTypeComboBox.Active) { case 0: //garden if (GardenDrawingArea.ActiveInstance.Garden.Shape.GetPoints().Count == 0) { GardenDrawingArea.ActiveInstance.Garden.Shape.AddPoints(points); GardenDrawingArea.ActiveInstance.Garden.Shape.FinishPoints(); GardenDrawingArea.ActiveInstance.NewPoints.Clear(); GardenDrawingArea.ActiveInstance.Draw(); } break; case 1: //planting PlantingCreationDialog.ShowPlantingCreationDialog(new List <GardenPoint>(points), (Planting planting) => { GardenDrawingArea.ActiveInstance.NewPoints.Clear(); GardenDrawingArea.ActiveInstance.Draw(); GardenDrawingArea.ActiveInstance.Garden.AddPlanting(GardenData.GenID(planting.Name), planting); }); break; case 2: //method area GardenAreaCreationDialog.ShowGardenAreaCreationDialog(new List <GardenPoint>(points), (GardenArea area) => { GardenDrawingArea.ActiveInstance.NewPoints.Clear(); GardenDrawingArea.ActiveInstance.Draw(); GardenDrawingArea.ActiveInstance.Garden.AddMethodArea(GardenData.GenID(area.Name), area); }); break; } } } else //activated { if (AreaTypeComboBox.Active == 0) //garden { if (GardenDrawingArea.ActiveInstance == null || GardenDrawingArea.ActiveInstance.Garden.Shape.GetPoints().Count > 0) { AreaNewButton.Active = false; GardenCreationDialog.ShowGardenCreationDialog(new List <GardenPoint>(), ((Garden garden) => { GardenData.LoadedData.AddGarden(GardenData.GenID(garden.Name), garden); this.ResetForNewData(); GardenBedBook.Page = GardenBedBook.NPages - 1; AreaNewButton.Active = true; })); } } AreaCancelButton.Sensitive = true; } }; AreaCancelButton.Sensitive = false; AreaCancelButton.Clicked += (object sender, System.EventArgs e) => { AreaCancelButtonClicked = true; AreaCancelButton.Sensitive = false; AreaNewButton.Active = false; }; AreaTypeComboBox.Active = 0; AreaTypeComboBox.Changed += (object sender, System.EventArgs e) => { switch (AreaTypeComboBox.Active) { case 0: AreaNewButton.Label = "New Garden"; break; case 1: AreaNewButton.Label = "New Planting"; break; case 2: AreaNewButton.Label = "New Method Area"; break; } }; AreaEditButton.Clicked += (object sender, System.EventArgs e) => { GardenDrawingArea gardenDrawingArea = GardenDrawingArea.ActiveInstance; if (gardenDrawingArea == null || gardenDrawingArea.Garden == null || gardenDrawingArea.SelectedArea == null) { return; } if (gardenDrawingArea.SelectedArea is Planting planting) { PlantingCreationDialog.ShowPlantingEditDialog(planting); } else if (gardenDrawingArea.SelectedArea is Garden) { GardenAreaCreationDialog.ShowGardenAreaEditDialog(gardenDrawingArea.SelectedArea); } else { GardenAreaCreationDialog.ShowGardenAreaEditDialog(gardenDrawingArea.SelectedArea); } }; AreaDeleteButton.Clicked += (object sender, System.EventArgs e) => { GardenDrawingArea gardenDrawingArea = GardenDrawingArea.ActiveInstance; if (gardenDrawingArea == null || gardenDrawingArea.Garden == null) { return; } string name = gardenDrawingArea.SelectedArea != null ? gardenDrawingArea.SelectedArea.Name : gardenDrawingArea.Garden.Name; Dialog dialog = new MessageDialog(this, DialogFlags.Modal, MessageType.Warning, ButtonsType.OkCancel, "Do you want to delete '" + name + "'?", new { }); int response = dialog.Run(); //System.Console.WriteLine("response " + result); if (response == (int)ResponseType.Cancel) { } else if (response == (int)ResponseType.Ok) { if (gardenDrawingArea.Garden != null && (gardenDrawingArea.SelectedArea == null || gardenDrawingArea.SelectedArea is Garden)) { var garden = gardenDrawingArea.Garden; GardenData.LoadedData.Gardens.Remove(garden.ID); GardenBedBook.Remove(GardenBedBook.GetNthPage(GardenBedBook.CurrentPage)); //System.Console.WriteLine("delete garden"); GardenDrawingArea.ActiveInstance = null; gardenDrawingArea.UndoSelection(); SelectGardenEntry(null); if (GardenBedBook.Page >= 0 && GardenBedBook.GetNthPage(GardenBedBook.Page) is GardenDrawingArea drawingArea) { GardenDrawingArea.ActiveInstance = drawingArea; drawingArea.Draw(); } GardenData.unsaved = true; } else if (gardenDrawingArea.SelectedArea is Planting planting) { gardenDrawingArea.Garden.RemovePlanting(planting); gardenDrawingArea.UndoSelection(); SelectGardenEntry(null); gardenDrawingArea.Draw(); GardenData.unsaved = true; } else if (gardenDrawingArea.SelectedArea is GardenArea area) { gardenDrawingArea.Garden.RemoveMethodArea(area); gardenDrawingArea.UndoSelection(); SelectGardenEntry(null); gardenDrawingArea.Draw(); GardenData.unsaved = true; } } dialog.Destroy(); }; int yearValue = yearButton.ValueAsInt; yearButton.ValueChanged += (sender, e) => { if (yearButton.ValueAsInt > yearValue) { monthButton.Value = 1; } else { monthButton.Value = 12; } yearValue = yearButton.ValueAsInt; DateChanged(); }; monthButton.Changed += (sender, e) => { DateChanged(); }; void DateChanged() { GardenDrawingArea gardenDrawingArea = GardenDrawingArea.ActiveInstance; if (gardenDrawingArea == null) { return; } if (gardenDrawingArea.SelectedArea != null && (!gardenDrawingArea.SelectedArea.CheckDate(GetYear(), GetMonth()) || !gardenDrawingArea.Garden.CheckDate(GetYear(), GetMonth()))) { gardenDrawingArea.UndoSelection(); } gardenDrawingArea.Draw(); ShowAreaSelectionInfo(gardenDrawingArea.SelectedArea); } //FamilyPlantVarietySelector.Add1(PopulateFamilies(GardenData.LoadedData)); //RepopulateGrowables(); //Build(); this.DeleteEvent += (object o, DeleteEventArgs args) => { TryToClose(); args.RetVal = true; }; this.Destroyed += (sender, e) => { GardenPlannerSettings.Save(); Application.Quit(); }; }
public static Widget show_chat_form() { //新建窗体,标题是Hello World var win = new Gtk.Window("聊天"); win.SetDefaultSize(800, 600); //win.SetSizeRequest(800, 600); //窗体关闭后退出应用 //win.DeleteEvent += (s, e) => //{ // Gtk.Application.Quit(); //}; win.WindowPosition = WindowPosition.Center; //win.Resizable = false; win.BorderWidth = 10; var paned1 = new VPaned(); win.Add(paned1); var paned2 = new HPaned(); paned1.SetSizeRequest(200, -1); paned2.SetSizeRequest(200, -1); paned1.Add(paned2); var button1 = new Button("按钮一"); paned1.Pack1(button1, true, false); var button2 = new Button("按钮二"); paned2.Pack1(button2, true, false); var paned3 = new VPaned(); paned3.SetSizeRequest(200, -1); paned2.Pack2(paned3, true, false); //var button3 = new Button("按钮三"); RecvChatWidget = new TextView(); var recvScrollView = new ScrolledWindow(); recvScrollView.Add(RecvChatWidget); //RecvChatWidget.SizeAllocated += new SizeAllocatedHandler(ScrollToBottom); paned3.Pack1(recvScrollView, true, false); //var button4 = new Button("按钮四"); SendChatWidget = new TextView(); var sendScrollView = new ScrolledWindow(); sendScrollView.Add(SendChatWidget); var vbox = new VBox(false, 0); var hbox = new VBox(true, 0); var sendMsgBtn = new Button("发送消息"); sendMsgBtn.Clicked += (s, e) => { TextIter start, end; RecvChatWidget.Buffer.GetBounds(out start, out end); RecvChatWidget.Buffer.Insert(ref end, SendChatWidget.Buffer.Text); RecvChatWidget.Buffer.Insert(ref end, "\n"); RecvChatWidget.ScrollToIter(RecvChatWidget.Buffer.EndIter, 0.0, false, 0.0, 0.0); }; hbox.PackStart(sendMsgBtn, false, false, 0); vbox.PackStart(hbox, false, false, 0); vbox.PackEnd(sendScrollView, true, true, 0); paned3.Pack2(vbox, true, false); win.ShowAll(); return(paned1); }