static void openButton_Clicked(object sender, EventArgs e) { FileChooserDialog fcd = new FileChooserDialog("Open page...", (Window)((Widget)sender).Toplevel, FileChooserAction.Open); fcd.AddButton(Stock.Cancel, ResponseType.Cancel); fcd.AddButton(Stock.Open, ResponseType.Ok); fcd.DefaultResponse = ResponseType.Ok; fcd.Filter = new FileFilter(); fcd.Filter.AddPattern("*.aspx"); fcd.SelectMultiple = false; ResponseType response = (ResponseType)fcd.Run( ); fcd.Hide(); if (response == ResponseType.Ok && fcd.Filename != null) { using (FileStream fileStream = new FileStream(fcd.Filename, FileMode.Open)) { if (fileStream == null) { return; } host.Reset(); host.Load(fileStream, fcd.Filename); host.Activate(); } } fcd.Destroy(); }
public void Initialise(string document, string fileName) { DispatchService.AssertGuiThread(); System.Diagnostics.Trace.WriteLine("Loading document into DesignerHost"); if (document != null) { host.Load(document, fileName); } else { host.NewFile(); } System.Diagnostics.Trace.WriteLine("Loaded document into DesignerHost"); host.Activate(); System.Diagnostics.Trace.WriteLine("DesignerHost activated; getting designer view"); IRootDesigner rootDesigner = (IRootDesigner)host.GetDesigner(host.RootComponent); designerView = (RootDesignerView)rootDesigner.GetView(ViewTechnology.Passthrough); designerView.Realized += delegate { System.Diagnostics.Trace.WriteLine("Designer view realized"); }; }
public void Initialise() { DispatchService.AssertGuiThread(); System.Diagnostics.Trace.WriteLine("Loading document into DesignerHost"); designerHost.LoadDocument(); System.Diagnostics.Trace.WriteLine("Loaded document into DesignerHost"); designerHost.Activate(); System.Diagnostics.Trace.WriteLine("DesignerHost activated; getting designer view"); IRootDesigner rootDesigner = (IRootDesigner)designerHost.GetDesigner(designerHost.RootComponent); designerView = (RootDesignerView)rootDesigner.GetView(ViewTechnology.Default); // designerView.Realized += delegate { // System.Diagnostics.Trace.WriteLine ("Designer view realized"); // }; designerView.Realized += new EventHandler(designerHost.RootDesignerView_Realized); }
static void Main() { #if TRACE System.Diagnostics.TextWriterTraceListener listener = new System.Diagnostics.TextWriterTraceListener (System.Console.Out); System.Diagnostics.Trace.Listeners.Add (listener); #endif Application.Init (); #region Packing and layout Window window = new Window ("AspNetEdit Host Sample"); window.SetDefaultSize (1000, 700); window.DeleteEvent += new DeleteEventHandler (window_DeleteEvent); VBox outerBox = new VBox (); window.Add (outerBox); HPaned leftBox = new HPaned (); outerBox.PackEnd (leftBox, true, true, 0); HPaned rightBox = new HPaned (); leftBox.Add2 (rightBox); geckoFrame = new Frame (); geckoFrame.Shadow = ShadowType.In; rightBox.Pack1 (geckoFrame, true, false); #endregion #region Toolbar // * Save/Open Toolbar buttons = new Toolbar (); outerBox.PackStart (buttons, false, false, 0); ToolButton saveButton = new ToolButton (Stock.Save); buttons.Add (saveButton); saveButton.Clicked += new EventHandler (saveButton_Clicked); ToolButton openButton = new ToolButton(Stock.Open); buttons.Add(openButton); openButton.Clicked += new EventHandler(openButton_Clicked); buttons.Add (new SeparatorToolItem()); // * Clipboard ToolButton undoButton = new ToolButton (Stock.Undo); buttons.Add (undoButton); undoButton.Clicked +=new EventHandler (undoButton_Clicked); ToolButton redoButton = new ToolButton (Stock.Redo); buttons.Add (redoButton); redoButton.Clicked += new EventHandler (redoButton_Clicked); ToolButton cutButton = new ToolButton (Stock.Cut); buttons.Add (cutButton); cutButton.Clicked += new EventHandler (cutButton_Clicked); ToolButton copyButton = new ToolButton (Stock.Copy); buttons.Add (copyButton); copyButton.Clicked += new EventHandler (copyButton_Clicked); ToolButton pasteButton = new ToolButton (Stock.Paste); buttons.Add (pasteButton); pasteButton.Clicked += new EventHandler (pasteButton_Clicked); buttons.Add (new SeparatorToolItem()); // * Text style ToolButton boldButton = new ToolButton (Stock.Bold); buttons.Add (boldButton); boldButton.Clicked += new EventHandler (boldButton_Clicked); ToolButton italicButton = new ToolButton (Stock.Italic); buttons.Add (italicButton); italicButton.Clicked += new EventHandler (italicButton_Clicked); ToolButton underlineButton = new ToolButton (Stock.Underline); buttons.Add (underlineButton); underlineButton.Clicked += new EventHandler (underlineButton_Clicked); ToolButton indentButton = new ToolButton (Stock.Indent); buttons.Add (indentButton); indentButton.Clicked += new EventHandler (indentButton_Clicked); ToolButton unindentButton = new ToolButton (Stock.Unindent); buttons.Add (unindentButton); unindentButton.Clicked += new EventHandler (unindentButton_Clicked); buttons.Add (new SeparatorToolItem()); // * Toolbox ToolButton toolboxAddButton = new ToolButton (Stock.Add); buttons.Add (toolboxAddButton); toolboxAddButton.Clicked += new EventHandler (toolboxAddButton_Clicked); #endregion #region Designer services and host //set up the services ServiceContainer services = new ServiceContainer (); services.AddService (typeof (INameCreationService), new NameCreationService ()); services.AddService (typeof (ISelectionService), new SelectionService ()); services.AddService (typeof (IEventBindingService), new EventBindingService (window)); services.AddService (typeof (ITypeResolutionService), new TypeResolutionService ()); ExtenderListService extListServ = new AspNetEdit.Editor.ComponentModel.ExtenderListService (); services.AddService (typeof (IExtenderListService), extListServ); services.AddService (typeof (IExtenderProviderService), extListServ); services.AddService (typeof (ITypeDescriptorFilterService), new TypeDescriptorFilterService ()); toolboxService = new ToolboxService (); services.AddService (typeof (IToolboxService), toolboxService); //create our host host = new DesignerHost(services); host.NewFile(); host.Activate(); #endregion #region Designer UI and panels IRootDesigner rootDesigner = (IRootDesigner) host.GetDesigner (host.RootComponent); RootDesignerView designerView = (RootDesignerView) rootDesigner.GetView (ViewTechnology.Passthrough); geckoFrame.Add (designerView); PropertyGrid p = new PropertyGrid (services); p.WidthRequest = 200; rightBox.Pack2 (p, false, false); Toolbox toolbox = new Toolbox (services); leftBox.Pack1 (toolbox, false, false); toolboxService.PopulateFromAssembly (System.Reflection.Assembly.GetAssembly (typeof (System.Web.UI.Control))); toolboxService.AddToolboxItem (new TextToolboxItem ("<table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>", "Table"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<div style=\"width: 100px; height: 100px;\"></div>", "Div"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<hr />", "Horizontal Rule"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<select><option></option></select>", "Select"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<img src=\"\" />", "Image"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<textarea cols=\"20\" rows=\"2\"></textarea>", "Textarea"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"hidden\" />", "Input [Hidden]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"radio\" />", "Input [Radio]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"checkbox\" />", "Input [Checkbox]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"password\" />", "Input [Password]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"file\" />", "Input [File]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"text\" />", "Input [Text]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"submit\" value=\"submit\" />", "Input [Submit]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"reset\" value=\"reset\" />", "Input [Reset]"), "Html"); toolboxService.AddToolboxItem (new TextToolboxItem ("<input type=\"button\" value=\"button\" />", "Input [Button]"), "Html"); toolbox.Refresh (); #endregion window.ShowAll (); Application.Run (); }
static void Main() { #if TRACE System.Diagnostics.TextWriterTraceListener listener = new System.Diagnostics.TextWriterTraceListener(System.Console.Out); System.Diagnostics.Trace.Listeners.Add(listener); #endif Application.Init(); #region Packing and layout Window window = new Window("AspNetEdit Host Sample"); window.SetDefaultSize(1000, 700); window.DeleteEvent += new DeleteEventHandler(window_DeleteEvent); VBox outerBox = new VBox(); window.Add(outerBox); HPaned leftBox = new HPaned(); outerBox.PackEnd(leftBox, true, true, 0); HPaned rightBox = new HPaned(); leftBox.Add2(rightBox); geckoFrame = new Frame(); geckoFrame.Shadow = ShadowType.In; rightBox.Pack1(geckoFrame, true, false); #endregion #region Toolbar // * Save/Open Toolbar buttons = new Toolbar(); outerBox.PackStart(buttons, false, false, 0); ToolButton saveButton = new ToolButton(Stock.Save); buttons.Add(saveButton); saveButton.Clicked += new EventHandler(saveButton_Clicked); ToolButton openButton = new ToolButton(Stock.Open); buttons.Add(openButton); openButton.Clicked += new EventHandler(openButton_Clicked); buttons.Add(new SeparatorToolItem()); // * Clipboard ToolButton undoButton = new ToolButton(Stock.Undo); buttons.Add(undoButton); undoButton.Clicked += new EventHandler(undoButton_Clicked); ToolButton redoButton = new ToolButton(Stock.Redo); buttons.Add(redoButton); redoButton.Clicked += new EventHandler(redoButton_Clicked); ToolButton cutButton = new ToolButton(Stock.Cut); buttons.Add(cutButton); cutButton.Clicked += new EventHandler(cutButton_Clicked); ToolButton copyButton = new ToolButton(Stock.Copy); buttons.Add(copyButton); copyButton.Clicked += new EventHandler(copyButton_Clicked); ToolButton pasteButton = new ToolButton(Stock.Paste); buttons.Add(pasteButton); pasteButton.Clicked += new EventHandler(pasteButton_Clicked); buttons.Add(new SeparatorToolItem()); // * Text style ToolButton boldButton = new ToolButton(Stock.Bold); buttons.Add(boldButton); boldButton.Clicked += new EventHandler(boldButton_Clicked); ToolButton italicButton = new ToolButton(Stock.Italic); buttons.Add(italicButton); italicButton.Clicked += new EventHandler(italicButton_Clicked); ToolButton underlineButton = new ToolButton(Stock.Underline); buttons.Add(underlineButton); underlineButton.Clicked += new EventHandler(underlineButton_Clicked); ToolButton indentButton = new ToolButton(Stock.Indent); buttons.Add(indentButton); indentButton.Clicked += new EventHandler(indentButton_Clicked); ToolButton unindentButton = new ToolButton(Stock.Unindent); buttons.Add(unindentButton); unindentButton.Clicked += new EventHandler(unindentButton_Clicked); buttons.Add(new SeparatorToolItem()); // * Toolbox ToolButton toolboxAddButton = new ToolButton(Stock.Add); buttons.Add(toolboxAddButton); toolboxAddButton.Clicked += new EventHandler(toolboxAddButton_Clicked); #endregion #region Designer services and host //set up the services ServiceContainer services = new ServiceContainer(); services.AddService(typeof(INameCreationService), new NameCreationService()); services.AddService(typeof(ISelectionService), new SelectionService()); services.AddService(typeof(IEventBindingService), new EventBindingService(window)); services.AddService(typeof(ITypeResolutionService), new TypeResolutionService()); ExtenderListService extListServ = new AspNetEdit.Editor.ComponentModel.ExtenderListService(); services.AddService(typeof(IExtenderListService), extListServ); services.AddService(typeof(IExtenderProviderService), extListServ); services.AddService(typeof(ITypeDescriptorFilterService), new TypeDescriptorFilterService()); toolboxService = new ToolboxService(); services.AddService(typeof(IToolboxService), toolboxService); //create our host host = new DesignerHost(services); host.NewFile(); host.Activate(); #endregion #region Designer UI and panels IRootDesigner rootDesigner = (IRootDesigner)host.GetDesigner(host.RootComponent); RootDesignerView designerView = (RootDesignerView)rootDesigner.GetView(ViewTechnology.Passthrough); geckoFrame.Add(designerView); PropertyGrid p = new PropertyGrid(services); p.WidthRequest = 200; rightBox.Pack2(p, false, false); Toolbox toolbox = new Toolbox(services); leftBox.Pack1(toolbox, false, false); toolboxService.PopulateFromAssembly(System.Reflection.Assembly.GetAssembly(typeof(System.Web.UI.Control))); toolboxService.AddToolboxItem(new TextToolboxItem("<table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>", "Table"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<div style=\"width: 100px; height: 100px;\"></div>", "Div"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<hr />", "Horizontal Rule"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<select><option></option></select>", "Select"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<img src=\"\" />", "Image"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<textarea cols=\"20\" rows=\"2\"></textarea>", "Textarea"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"hidden\" />", "Input [Hidden]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"radio\" />", "Input [Radio]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"checkbox\" />", "Input [Checkbox]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"password\" />", "Input [Password]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"file\" />", "Input [File]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"text\" />", "Input [Text]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"submit\" value=\"submit\" />", "Input [Submit]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"reset\" value=\"reset\" />", "Input [Reset]"), "Html"); toolboxService.AddToolboxItem(new TextToolboxItem("<input type=\"button\" value=\"button\" />", "Input [Button]"), "Html"); toolbox.Refresh(); #endregion window.ShowAll(); Application.Run(); }
private void Initialize() { IDesignerHost host; Form form; IRootDesigner rootDesigner; Control view; // Initialise service container and designer host serviceContainer = new ServiceContainer(); serviceContainer.AddService(typeof(INameCreationService), new NameCreationService()); serviceContainer.AddService(typeof(IUIService), new UIService(this)); host = new DesignerHost(serviceContainer); // Add toolbox service serviceContainer.AddService(typeof(IToolboxService), lstToolbox); lstToolbox.designPanel = pnlViewHost; PopulateToolbox(lstToolbox); // Add menu command service menuService = new MenuCommandService(); serviceContainer.AddService(typeof(IMenuCommandService), menuService); // Start the designer host off with a Form to design form = (Form)host.CreateComponent(typeof(Form)); form.TopLevel = false; form.Text = "Form1"; // Get the root designer for the form and add its design view to this form rootDesigner = (IRootDesigner)host.GetDesigner(form); view = (Control)rootDesigner.GetView(ViewTechnology.WindowsForms); view.Dock = DockStyle.Fill; pnlViewHost.Controls.Add(view); // Subscribe to the selectionchanged event and activate the designer ISelectionService s = (ISelectionService)serviceContainer.GetService(typeof(ISelectionService)); s.SelectionChanged += new EventHandler(OnSelectionChanged); host.Activate(); }