コード例 #1
0
ファイル: MainForm.cs プロジェクト: alexandrebaker/Eto
		Control MainContent()
		{
			contentContainer = new Panel();

			// set focus when the form is shown
			Shown += delegate
			{
				SectionList.Focus();
			};
			SectionList.SelectedItemChanged += (sender, e) =>
			{
				try
				{
					var item = SectionList.SelectedItem;
					Control content = item != null ? item.CreateContent() : null;

					if (navigation != null)
					{
						if (content != null)
							navigation.Push(content, item != null ? item.Text : null);
					}
					else
					{
						contentContainer.Content = content;
					}
				}
				catch (Exception ex)
				{
					Log.Write(this, "Error loading section: {0}", ex.GetBaseException());
					contentContainer.Content = null;
				}

				#if DEBUG
				GC.Collect();
				GC.WaitForPendingFinalizers();
				#endif
			};

			if (Splitter.IsSupported())
			{
				var splitter = new Splitter
				{
					Position = 200,
					FixedPanel = SplitterFixedPanel.Panel1,
					Panel1 = SectionList.Control,
#if MOBILE
					// for now, don't show log in mobile
					Panel2 = contentContainer
#else
					Panel2 = RightPane()
#endif
				};
				return splitter;
			}
			if (Navigation.IsSupported())
			{
				navigation = new Navigation(SectionList.Control, "Eto.Test");
				return navigation;
			}
			throw new EtoException("Platform must support splitter or navigation");

		}

		Control RightPane()
		{
			return new Splitter
			{
				Orientation = SplitterOrientation.Vertical,
				FixedPanel = SplitterFixedPanel.Panel2,
				Panel1 = contentContainer,
				Panel2 = EventLogSection()
			};
		}

		Control EventLogSection()
		{
			var layout = new DynamicLayout { Size = new Size(100, 120) };
			
			layout.BeginHorizontal();
			layout.Add(EventLog, true);
			
			layout.BeginVertical();
			layout.Add(ClearButton());
			layout.Add(null);
			layout.EndVertical();
			layout.EndHorizontal();
			return layout;
		}

		Control ClearButton()
		{
			var control = new Button
			{
				Text = "Clear"
			};
			control.Click += (sender, e) => EventLog.Text = string.Empty;
			return control;
		}

		void GenerateMenuToolBar()
		{
			var about = new Actions.About();
			var quit = new Actions.Quit();

#if DESKTOP
			var menu = new MenuBar();
			// create standard system menu (e.g. for OS X)
			Application.Instance.CreateStandardMenu(menu.Items);

			// add our own items to the menu

			var file = menu.Items.GetSubmenu("&File", 100);
			menu.Items.GetSubmenu("&Edit", 200);
			menu.Items.GetSubmenu("&Window", 900);
			var help = menu.Items.GetSubmenu("&Help", 1000);

			if (Generator.IsMac)
			{
				// have a nice OS X style menu
				var main = menu.Items.GetSubmenu(Application.Instance.Name, 0);
				main.Items.Add(about, 0);
				main.Items.Add(quit, 1000);
			}
			else
			{
				// windows/gtk style window
				file.Items.Add(quit);
				help.Items.Add(about);
			}

			// optional, removes empty submenus and duplicate separators
			menu.Items.Trim();

			Menu = menu;
#endif

			// generate and set the toolbar
			var toolBar = new ToolBar();
			toolBar.Items.Add(quit);
			toolBar.Items.Add(new ButtonToolItem(about));

			ToolBar = toolBar;
		}
コード例 #2
0
        Control MainContent()
        {
            contentContainer = new Panel();

            // set focus when the form is shown
            Shown += delegate
            {
                SectionList.Focus();
            };
            SectionList.SelectedItemChanged += (sender, e) =>
            {
                try
                {
                    var     item    = SectionList.SelectedItem;
                    Control content = item != null?item.CreateContent() : null;

                    if (navigation != null)
                    {
                        if (content != null)
                        {
                            navigation.Push(content, item != null ? item.Text : null);
                        }
                    }
                    else
                    {
                        contentContainer.Content = content;
                    }
                }
                catch (Exception ex)
                {
                    Log.Write(this, "Error loading section: {0}", ex.GetBaseException());
                    contentContainer.Content = null;
                }

                                #if DEBUG
                GC.Collect();
                GC.WaitForPendingFinalizers();
                                #endif
            };

            if (Splitter.IsSupported())
            {
                var splitter = new Splitter
                {
                    Position   = 200,
                    FixedPanel = SplitterFixedPanel.Panel1,
                    Panel1     = SectionList.Control,
#if MOBILE
                    // for now, don't show log in mobile
                    Panel2 = contentContainer
#else
                    Panel2 = RightPane()
#endif
                };
                return(splitter);
            }
            if (Navigation.IsSupported())
            {
                navigation = new Navigation(SectionList.Control, "Eto.Test");
                return(navigation);
            }
            throw new EtoException("Platform must support splitter or navigation");
        }

        Control RightPane()
        {
            return(new Splitter
            {
                Orientation = SplitterOrientation.Vertical,
                FixedPanel = SplitterFixedPanel.Panel2,
                Panel1 = contentContainer,
                Panel2 = EventLogSection()
            });
        }

        Control EventLogSection()
        {
            var layout = new DynamicLayout {
                Size = new Size(100, 120)
            };

            layout.BeginHorizontal();
            layout.Add(EventLog, true);

            layout.BeginVertical();
            layout.Add(ClearButton());
            layout.Add(null);
            layout.EndVertical();
            layout.EndHorizontal();
            return(layout);
        }

        Control ClearButton()
        {
            var control = new Button
            {
                Text = "Clear"
            };

            control.Click += (sender, e) => EventLog.Text = string.Empty;
            return(control);
        }

        void GenerateMenuToolBar()
        {
            var about = new Actions.About();
            var quit  = new Actions.Quit();

#if DESKTOP
            var menu = new MenuBar();
            // create standard system menu (e.g. for OS X)
            Application.Instance.CreateStandardMenu(menu.Items);

            // add our own items to the menu

            var file = menu.Items.GetSubmenu("&File", 100);
            menu.Items.GetSubmenu("&Edit", 200);
            menu.Items.GetSubmenu("&Window", 900);
            var help = menu.Items.GetSubmenu("&Help", 1000);

            if (Generator.IsMac)
            {
                // have a nice OS X style menu
                var main = menu.Items.GetSubmenu(Application.Instance.Name, 0);
                main.Items.Add(about, 0);
                main.Items.Add(quit, 1000);
            }
            else
            {
                // windows/gtk style window
                file.Items.Add(quit);
                help.Items.Add(about);
            }

            // optional, removes empty submenus and duplicate separators
            menu.Items.Trim();

            Menu = menu;
#endif

            // generate and set the toolbar
            var toolBar = new ToolBar();
            toolBar.Items.Add(quit);
            toolBar.Items.Add(new ButtonToolItem(about));

            ToolBar = toolBar;
        }