Inheritance: Window
Exemple #1
0
		public void TwoResponds ()
		{
			// When Respond is called twice before leaving an event handler, the last call is the good one

			using (var win = new Dialog ()) {
				Application.TimeoutInvoke (10, delegate {
					win.Respond (Command.Ok);
					win.Respond (Command.Apply);
					return false;
				});
				var cmd = win.Run ();
				Assert.AreEqual (Command.Apply, cmd);
			}
		}
Exemple #2
0
        public Windows()
        {
            Button b = new Button ("Show borderless window");
            PackStart (b);
            b.Clicked += delegate {
                Window w = new Window ();
                w.Decorated = false;
                Button c = new Button ("This is a window");
            //				c.Margin.SetAll (10);
                w.Content = c;
                c.Clicked += delegate {
                    w.Dispose ();
                };
                var bpos = b.ScreenBounds;
                w.Bounds = new Rectangle (bpos.X, bpos.Y + b.Size.Height, w.Bounds.Width, w.Bounds.Height);
                w.Show ();
            };
            b = new Button ("Show message dialog");
            PackStart (b);
            b.Clicked += delegate {
                MessageDialog.ShowMessage (ParentWindow, "Hi there!");
            };

            Button db = new Button ("Show custom dialog");
            PackStart (db);
            db.Clicked += delegate {
                Dialog d = new Dialog ();
                d.Title = "This is a dialog";
                Table t = new Table ();
                t.Attach (new Label ("Some field:"), 0, 1, 0, 1);
                t.Attach (new TextEntry (), 1, 2, 0, 1);
                t.Attach (new Label ("Another field:"), 0, 1, 1, 2);
                t.Attach (new TextEntry (), 1, 2, 1, 2);
                d.Content = t;

                Command custom = new Command ("Custom");
                d.Buttons.Add (new DialogButton (custom));
                d.Buttons.Add (new DialogButton ("Custom OK", Command.Ok));
                d.Buttons.Add (new DialogButton (Command.Cancel));
                d.Buttons.Add (new DialogButton (Command.Ok));

                var r = d.Run (this.ParentWindow);
                db.Label = "Result: " + r.Label;
                d.Dispose ();
            };
        }
Exemple #3
0
 void EditRuntimeClicked(object sender, EventArgs e)
 {
     using (var dlg = new Xwt.Dialog()) {
         dlg.Title  = GettextCatalog.GetString("Mono Runtime Settings");
         dlg.Width  = 700;
         dlg.Height = 500;
         var w       = new MonoExecutionParametersWidget();
         var mparams = config.MonoParameters.Clone();
         w.Load(mparams);
         w.ShowAll();
         dlg.Content = Surface.ToolkitEngine.WrapWidget(w);
         dlg.Buttons.Add(Command.Ok, Command.Cancel);
         dlg.TransientFor = ParentWindow;
         if (dlg.Run() == Command.Ok)
         {
             config.MonoParameters  = mparams;
             monoSettingsEntry.Text = config.MonoParameters.GenerateDescription();
         }
     }
 }
Exemple #4
0
		public void RespondDoesNotFireClose ()
		{
			// The close event is not fired after running a dialog

			bool closed = false, closing = false;
			using (var win = new Dialog ()) {
				win.Buttons.Add (new DialogButton (Command.Ok));
				win.CloseRequested += (sender, e) => closing = true;
				win.Closed += (sender, e) => closed = true;
				Application.TimeoutInvoke (10, delegate {
					win.Respond (Command.Apply);
					return false;
				});
				var cmd = win.Run ();
				Assert.IsFalse (closing, "CloseRequested event should not be fired");
				Assert.IsFalse (closed, "Close event should not be fired");
				Assert.AreEqual (Command.Apply, cmd);
			}
			Assert.IsFalse (closing, "CloseRequested event should not be fired when disposing");
			Assert.IsFalse (closed, "Close event should not be fired when disposing");
		}
Exemple #5
0
		public void Close ()
		{
			// The Close method can be used to stop running a dialog

			bool closing = false, closed = false, closeResult = false;
			using (var win = new Dialog ()) {
				win.Buttons.Add (new DialogButton (Command.Ok));
				win.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) {
					Assert.IsTrue (args.AllowClose);
					closing = true;
				};
				win.Closed += (sender, e) => closed = true;
				Application.TimeoutInvoke (10, delegate {
					closeResult = win.Close ();
					return false;
				});
				var cmd = win.Run ();
				Assert.IsNull (cmd);
				Assert.IsTrue (closing, "CloseRequested event not fired");
				Assert.IsTrue (closed, "Window not closed");
				Assert.IsTrue (closeResult, "Window not closed");
			}
		}
Exemple #6
0
        /// <summary>
        /// Initializes the context menu.
        /// </summary>
        void InitializeContextMenu()
        {
            contextMenu = new Menu();
            contextMenuFibertype = new Menu();

            contextMenu.Items.Add(new MenuItem { Label = "Fiber Type", SubMenu = contextMenuFibertype });

            MenuItem magnificationMenu = new MenuItem { Label = "Magnification..." };
            contextMenu.Items.Add(magnificationMenu);

            magnificationMenu.Clicked += delegate {
                Dialog d = new Dialog();
                d.Title = "Change magnification factor to...";
                d.Buttons.Add(new DialogButton(Command.Apply));
                d.Buttons.Add(new DialogButton(Command.Cancel));

                TextEntry newMagnification = new TextEntry { PlaceholderText = "Magnification factor" };
                d.Content = newMagnification;

                Command ret = d.Run();
                if (ret != null && ret.Id == Command.Apply.Id) {
                    TreeStore currentStore = DataSource as TreeStore;
                    foreach (TreePosition x in SelectedRows) {
                        string n = currentStore.GetNavigatorAt(x)
                            .GetValue(isFiltered ? nameColFilter : nameCol);

                        BaseScan found = scanCollection.Find(o => o.Name == n);
                        if (found != null) {
                            try {
                                found.Metadata["LensMagnification"] = float.Parse(newMagnification.Text);
                            } catch (Exception e) {
                                // TODO show error
                                Console.WriteLine(e.Message);
                                Console.WriteLine(e.StackTrace);
                            }
                        }
                    }
                }

                d.Dispose();
            };
        }
Exemple #7
0
        protected override void OnKeyPressed(KeyEventArgs args)
        {
            base.OnKeyPressed(args);
            switch (args.Key) {
            case Key.Delete:
                TreeStore currentStore = DataSource as TreeStore;

                if (currentStore != null) {
                    TreeNavigator selected = currentStore.GetNavigatorAt(SelectedRow);

                    if (selected != null) {
                        Dialog d = new Dialog();
                        d.Title = "Remove this scan";

                        VBox nameList = new VBox();
                        ScrollView nameListScroll = new ScrollView(nameList);

                        foreach (TreePosition selectPos in SelectedRows) {
                            nameList.PackStart(
                                new Label(currentStore.GetNavigatorAt(selectPos)
                                .GetValue(isFiltered ? nameColFilter : nameCol))
                            );
                        }
                        TextLayout text = new TextLayout();
                        text.Text = "M";
                        double textHeight = text.GetSize().Height;
                        text.Dispose();

                        nameListScroll.MinHeight = Math.Min(10, SelectedRows.Length) * textHeight;
                        d.Content = nameListScroll;
                        d.Buttons.Add(new DialogButton(Command.Delete));
                        d.Buttons.Add(new DialogButton(Command.Cancel));

                        Command r = d.Run();
                        if (r != null && r.Id == Command.Delete.Id) {
                            foreach (TreePosition selectPos in SelectedRows) {
                                string name = currentStore.GetNavigatorAt(selectPos)
                                    .GetValue(isFiltered ? nameColFilter : nameCol);
                                if (!string.IsNullOrEmpty(name)) {
                                    currentStore.GetNavigatorAt(selectPos).Remove();

                                    scanCollection.RemoveAll(scan => scan.Name == name);
                                }
                            }
                        }
                        d.Dispose();
                    }
                }
                break;
            }
        }
Exemple #8
0
        protected override void OnButtonPressed(ButtonEventArgs args)
        {
            base.OnButtonPressed(args);

            if (scanCollection == null) {
                return;
            }

            switch (args.Button) {
            case PointerButton.Left:
                if (args.MultiplePress >= 2) {
                    TreePosition selected = SelectedRow;
                    if (selected != null) {
                        string scanName = (DataSource as TreeStore).GetNavigatorAt(selected)
                            .GetValue(isFiltered ? nameColFilter : nameCol);
                        Image thumbnail = (DataSource as TreeStore).GetNavigatorAt(selected)
                            .GetValue(isFiltered ? thumbnailColFilter : thumbnailCol);
                        BaseScan scan = scanCollection.Find(((BaseScan obj) => obj.Name == scanName));

                        if (scan != null) {
                            MetadataDialog metaDialog = new MetadataDialog(scan, thumbnail);
                            Command r = metaDialog.Run();

                            if (r != null && r.Id == Command.Apply.Id) {
                                metaDialog.Save();
                            }

                            metaDialog.Dispose();

                        }
                    }
                }
                break;
            case PointerButton.Right:
                contextMenuFibertype.Items.Clear();

                TreeStore currentStore = DataSource as TreeStore;
                string currentFiberType;
                if (SelectedRow != null && currentStore != null) {
                    TreeNavigator row = currentStore.GetNavigatorAt(SelectedRow);

                    string name = row.GetValue(isFiltered ? nameColFilter : nameCol);
                    currentFiberType = scanCollection.Find(o => o.Name == name).FiberType;

                    foreach (string typeName in fiberTypeNodes.Keys) {
                        RadioButtonMenuItem radioButton = new RadioButtonMenuItem(typeName);
                        if (typeName == currentFiberType) {
                            radioButton.Checked = true;
                        }

                        radioButton.Clicked += delegate(object sender, EventArgs e) {
                            RadioButtonMenuItem r = sender as RadioButtonMenuItem;
                            if (r == null) {
                                return;
                            }

                            List<BaseScan> foundScan = new List<BaseScan>();
                            foreach (TreePosition x in SelectedRows) {
                                if (r != null) {
                                    string n = currentStore.GetNavigatorAt(x)
                                        .GetValue(isFiltered ? nameColFilter : nameCol);
                                    BaseScan found = scanCollection.Find(o => o.Name == n);
                                    if (found != null) {
                                        foundScan.Add(found);
                                    }
                                }
                            }

                            foreach (BaseScan found in foundScan) {
                                found.FiberType = r.Label;
                            }
                        };

                        contextMenuFibertype.Items.Add(radioButton);
                    }

                    // other fibertype
                    MenuItem otherFibertype = new MenuItem { Label = "Other..." };
                    contextMenuFibertype.Items.Add(new SeparatorMenuItem());
                    contextMenuFibertype.Items.Add(otherFibertype);
                    otherFibertype.Clicked += delegate {
                        Dialog d = new Dialog();
                        d.Title = "Change fiber type to...";
                        d.Buttons.Add(new DialogButton(Command.Apply));
                        d.Buttons.Add(new DialogButton(Command.Cancel));

                        TextEntry newFiberType = new TextEntry { PlaceholderText = "Fiber type name" };
                        d.Content = newFiberType;

                        Command ret = d.Run();
                        if (ret != null && ret.Id == Command.Apply.Id) {
                            List<BaseScan> foundScan = new List<BaseScan>();
                            foreach (TreePosition x in SelectedRows) {
                                string n = currentStore.GetNavigatorAt(x)
                                        .GetValue(isFiltered ? nameColFilter : nameCol);
                                BaseScan found = scanCollection.Find(o => o.Name == n);
                                if (found != null) {
                                    foundScan.Add(found);
                                }
                            }

                            foreach (BaseScan found in foundScan) {
                                found.FiberType = newFiberType.Text;
                            }
                        }

                        d.Dispose();
                    };

                    contextMenu.Popup();
                }
                break;
            }
        }
Exemple #9
0
        /// <summary>
        /// Gets called when a worksheet tab was closed.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event arguments.</param>
        void OnTabClose(object sender, CloseEventArgs e)
        {
            TabButton button = sender as TabButton;
            if (button != null) {
                Dialog d = new Dialog();
                d.Title = "Remove worksheet";

                d.Content = new Label(string.Format("Remove worksheet \"{0}\"?", button.Label));
                d.Buttons.Add(new DialogButton("Remove", Command.Ok));
                d.Buttons.Add(new DialogButton(Command.Cancel));

                Command r = d.Run();
                if (r != null && r.Id == Command.Ok.Id) {
                    pipelines.Remove(button.Label);

                    Log.Add(LogLevel.Info, this.GetType().Name,
                        "Removed worksheet \"" + button.Label + "\"");

                    PipelineView nextPipeline;
                    pipelines.TryGetValue(tabHost.SelectedItem.Label, out nextPipeline);

                    if (nextPipeline != null) {
                        CurrentPipeline = nextPipeline;
                    }

                    e.Close = true;
                } else {
                    e.Close = false;
                }

                d.Dispose();
            }
        }
		void EditRuntimeClicked (object sender, EventArgs e)
		{
			using (var dlg = new Xwt.Dialog ()) {
				dlg.Title = GettextCatalog.GetString ("Mono Runtime Settings");
				dlg.Width = 700;
				dlg.Height = 500;
				var w = new MonoExecutionParametersWidget ();
				var mparams = config.MonoParameters.Clone ();
				w.Load (mparams);
				w.ShowAll ();
				dlg.Content = Surface.ToolkitEngine.WrapWidget (w);
				dlg.Buttons.Add (Command.Ok, Command.Cancel);
				dlg.TransientFor = ParentWindow;
				if (dlg.Run () == Command.Ok) {
					config.MonoParameters = mparams;
					monoSettingsEntry.Text = config.MonoParameters.GenerateDescription ();
				}
			}
		}
Exemple #11
0
		public void RespondOnClosing ()
		{
			// Respond can be used in a CloseRequest handler to provide a result for the Run method

			using (var win = new Dialog ()) {
				bool closeResult = false;
				win.Buttons.Add (new DialogButton (Command.Ok));
				win.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) {
					win.Respond (Command.Apply);
				};
				Application.TimeoutInvoke (10, delegate {
					closeResult = win.Close ();
					return false;
				});
				var cmd = win.Run ();
				Assert.AreEqual (Command.Apply, cmd);
				Assert.IsTrue (closeResult);
			}
		}
        /// <summary>
        /// Set variable.
        /// </summary>
        void VariableButton_Clicked(object sender, EventArgs e)
        {
            // Test if variables are ready
            if (ParentList.ActiveScenario.customVariables.Count == 0)
            {
                MessageDialog.ShowError(Director.Properties.Resources.NoVariablesFound);
                return;
            }

            // Create Dialog window
            var expressionDialog = new Dialog()
            {
                InitialLocation = WindowLocation.CenterParent,
                Width = 370,
                Resizable = false
            };

            // Set Title
            expressionDialog.Title = Director.Properties.Resources.HeaderSettings;

            // Prepare content
            VBox t = new VBox()
            {
                ExpandHorizontal = true,
                ExpandVertical = true
            };

            // Text before
            TextBefore = new TextEntry();
            t.PackStart(new Label(Director.Properties.Resources.TextBefore + ":"));
            t.PackStart(TextBefore, false, true);

            // Variable
            Variables = new ComboBox();
            t.PackStart(new Label(Director.Properties.Resources.Variable + ":"));
            Variables.Items.Add("");
            foreach (String k in ParentList.ActiveScenario.customVariables.Keys)
                Variables.Items.Add(k);
            t.PackStart(Variables, false, true);

            // Text after
            TextAfter = new TextEntry();
            t.PackStart(new Label(Director.Properties.Resources.TextAfter + ":"));
            t.PackStart(TextAfter, false, true);

            // Example
            Example = new Label();
            t.PackStart(new Label(Director.Properties.Resources.Example + ":"));
            t.PackStart(Example, false, true);

            // Expression solver split by $$
            String value = ActiveHeader.Value;
            var arr = value.Split('$');

            if (arr.Length == 1)
            {
                TextBefore.Text = arr[0];
                Variables.SelectedIndex = 0;
                TextAfter.Text = "";
            }
            else if (arr.Length == 3)
            {
                TextBefore.Text = arr[0];
                TextAfter.Text = arr[2];
                try
                {
                    Variables.SelectedText = arr[1];
                }
                catch
                {
                    TextBefore.Text = value;
                    TextAfter.Text = "";
                    Variables.SelectedIndex = 0;
                }
            }
            else
            {
                TextBefore.Text = value;
                TextAfter.Text = "";
                Variables.SelectedIndex = 0;
            }
            Example.Text = value;

            // Set hooks
            TextBefore.Changed += ExpressionSolver;
            TextAfter.Changed += ExpressionSolver;
            Variables.SelectionChanged += ExpressionSolver;

            // Image
            HBox ContentBox = new HBox()
            {
                ExpandHorizontal = true,
                ExpandVertical = true
            };

            // Image view
            ImageView ImageIcon = new ImageView(Image.FromResource(DirectorImages.HEADER_EDIT_IMAGE))
            {
                WidthRequest = 32, HeightRequest = 32,
                Margin = 20
            };
            ContentBox.PackStart(ImageIcon, false, false);
            ContentBox.PackStart(t, true, true);

            // Set content
            expressionDialog.Content = ContentBox;

            // Prepare buttons
            expressionDialog.Buttons.Add(new DialogButton(Director.Properties.Resources.OkComand, Command.Ok));
            expressionDialog.Buttons.Add(new DialogButton(Director.Properties.Resources.Cancel, Command.Cancel));

            // Run?
            var result = expressionDialog.Run(this.ParentList.ParentWindow);

            if (result == Command.Ok)
                Values.Text = ActiveHeader.Value = Example.Text;

            // Dispose dialog
            expressionDialog.Dispose();
        }
Exemple #13
0
        /// <summary>
        /// Dialog to choose name for a worksheet
        /// </summary>
        /// <returns>The user chosed name of the worksheet.</returns>
        /// <param name="oldName">Optional old name of an existing worksheet</param>
        public Tuple<Command, string> WorksheetNameDialog(string oldName = "")
        {
            Dialog d = new Dialog();
            d.Title = "Choose name";
            TextEntry nameEntry = new TextEntry();
            nameEntry.PlaceholderText = "Name";

            bool createNew = true;
            if (!string.IsNullOrEmpty(oldName)) {
                nameEntry.Text = oldName;
                createNew = false;
            }

            d.Content = nameEntry;
            d.Buttons.Add(new DialogButton(createNew ? "Create Worksheet" : "Rename Worksheet", Command.Ok));
            d.Buttons.Add(new DialogButton(Command.Cancel));

            Command r;
            while ((r = d.Run()) != null &&
                   r.Id != Command.Cancel.Id &&
                   (nameEntry.Text.Length < 3 || pipelines.ContainsKey(nameEntry.Text))) {

                if (nameEntry.Text.Length < 3) {
                    MessageDialog.ShowMessage("Worksheets name must consist of at least 3 letters.");
                } else if (pipelines.ContainsKey(nameEntry.Text)) {
                    MessageDialog.ShowMessage("Worksheet name already taken.");
                }
            }

            string text = nameEntry.Text;
            d.Dispose();

            return new Tuple<Command, string>(r, text);
        }
Exemple #14
0
        public Windows()
        {
            Button b = new Button ("Show borderless window");
            PackStart (b);
            b.Clicked += delegate {
                Window w = new Window ();
                w.Decorated = false;
                Button c = new Button ("This is a window");
            //				c.Margin.SetAll (10);
                w.Content = c;
                c.Clicked += delegate {
                    w.Dispose ();
                };
                var bpos = b.ScreenBounds;
                w.ScreenBounds = new Rectangle (bpos.X, bpos.Y + b.Size.Height, w.Width, w.Height);
                w.Show ();
            };
            b = new Button ("Show message dialog");
            PackStart (b);
            b.Clicked += delegate {
                MessageDialog.ShowMessage (ParentWindow, "Hi there!");
            };

            Button db = new Button ("Show custom dialog");
            PackStart (db);
            db.Clicked += delegate {
                Dialog d = new Dialog ();
                d.Title = "This is a dialog";
                Table t = new Table ();
                t.Attach (new Label ("Some field:"), 0, 1, 0, 1);
                t.Attach (new TextEntry (), 1, 2, 0, 1);
                t.Attach (new Label ("Another field:"), 0, 1, 1, 2);
                t.Attach (new TextEntry (), 1, 2, 1, 2);
                d.Content = t;

                Command custom = new Command ("Custom");
                d.Buttons.Add (new DialogButton (custom));
                d.Buttons.Add (new DialogButton ("Custom OK", Command.Ok));
                d.Buttons.Add (new DialogButton (Command.Cancel));
                d.Buttons.Add (new DialogButton (Command.Ok));

                var r = d.Run (this.ParentWindow);
                db.Label = "Result: " + r.Label;
                d.Dispose ();
            };

            b = new Button ("Show Open File dialog");
            PackStart (b);
            b.Clicked += delegate {
                OpenFileDialog dlg = new OpenFileDialog ("Select a file");
                dlg.InitialFileName = "Some file";
                dlg.Multiselect = true;
                dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt"));
                dlg.Filters.Add (new FileDialogFilter ("All files", "*.*"));
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames));
            };

            b = new Button ("Show Save File dialog");
            PackStart (b);
            b.Clicked += delegate {
                SaveFileDialog dlg = new SaveFileDialog ("Select a file");
                dlg.InitialFileName = "Some file";
                dlg.Multiselect = true;
                dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt"));
                dlg.Filters.Add (new FileDialogFilter ("All files", "*.*"));
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames));
            };

            b = new Button ("Show Select Folder dialog (Multi select)");
            PackStart (b);
            b.Clicked += delegate {
                SelectFolderDialog dlg = new SelectFolderDialog ("Select some folder");
                dlg.Multiselect = true;
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders));
            };

            b = new Button ("Show Select Folder dialog (Single select)");
            PackStart (b);
            b.Clicked += delegate {
                SelectFolderDialog dlg = new SelectFolderDialog ("Select a folder");
                dlg.Multiselect = false;
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders));
            };

            b = new Button ("Show Select Color dialog");
            PackStart (b);
            b.Clicked += delegate {
                SelectColorDialog dlg = new SelectColorDialog ("Select a color");
                dlg.SupportsAlpha = true;
                dlg.Color = Xwt.Drawing.Colors.AliceBlue;
                if (dlg.Run (ParentWindow))
                    MessageDialog.ShowMessage ("A color has been selected!", dlg.Color.ToString ());
            };

            b = new Button("Show window shown event");
            PackStart(b);
            b.Clicked += delegate
            {
                Window w = new Window();
                w.Decorated = false;
                Button c = new Button("This is a window with events on");
                w.Content = c;
                c.Clicked += delegate
                {
                    w.Dispose();
                };
                w.Shown += (sender, args) => MessageDialog.ShowMessage("My Parent has been shown");
                w.Hidden += (sender, args) => MessageDialog.ShowMessage("My Parent has been hidden");

                w.Show();

            };
        }
Exemple #15
0
		public void RespondOnClosingWithCancel ()
		{
			// If Respond if called on a CloseRequest, but the close is canceled, the respose call is ignored

			using (var win = new Dialog ()) {
				bool closeCanceled = false, closeResult1 = false, closeResult2 = false;
				win.Buttons.Add (new DialogButton (Command.Ok));
				win.CloseRequested += HandleCloseRequested;
				Application.TimeoutInvoke (10, delegate {
					closeResult1 = win.Close ();
					Application.TimeoutInvoke (10, delegate {
						win.CloseRequested -= HandleCloseRequested;
						closeCanceled = true;
						closeResult2 = win.Close ();
						return false;
					});
					return false;
				});
				var cmd = win.Run ();
				Assert.IsTrue (closeCanceled, "Close not canceled");
				Assert.IsFalse (closeResult1, "First close should return false");
				Assert.IsTrue (closeResult2, "Second close should return true");
				Assert.IsNull (cmd);
			}
		}
Exemple #16
0
        /// <summary>
        /// Opens the option window.
        /// </summary>
        /// <param name="pNode">Pipeline node for which the option should be shown.</param>
        void OpenOptionWindow(PipelineNode pNode)
        {
            Dialog d = new Dialog();
            d.Title = String.Format("Option for \"{0}\"", pNode.algorithm);
            Table table = new Table();
            VBox contentBox = new VBox();

            int i = 0;
            Widget[] entries = new Widget[pNode.algorithm.Options.Count];
            foreach (BaseOption option in pNode.algorithm.Options) {
                table.Add(new Label(option.Name), 0, i);

                Widget entry = option.ToWidget();
                entries[i] = entry;
                table.Add(entry, 1, i);
                i++;
            }

            TextEntry commentEntry = new TextEntry();
            commentEntry.PlaceholderText = "Comments...";
            commentEntry.MultiLine = true;
            commentEntry.Text = pNode.userComment;

            contentBox.PackStart(table);
            contentBox.PackEnd(commentEntry);
            d.Content = contentBox;

            d.Buttons.Add(new DialogButton(Command.Cancel));
            d.Buttons.Add(new DialogButton(Command.Apply));

            var r = d.Run(this.ParentWindow);

            if (r != null && r.Id == Command.Apply.Id) {
                i = 0;
                foreach (BaseOption option in pNode.algorithm.Options) {
                    object value = option.ExtractValueFrom(entries[i]);
                    if (value != null) {
                        option.Value = value;
                    }

                    i++;
                }
                pNode.userComment = commentEntry.Text;
            }

            d.Dispose();
        }
Exemple #17
0
        /// <summary>
        /// Shows a dialog to configure this export algorithm.
        /// </summary>
        public void ShowDialog(List<PipelineNode> nodes)
        {
            if (dialog == null) {
                dialog = new Dialog();
                dialog.Title = "Export as " + this;
                dialog.Content = Options();

                dialog.Buttons.Add(new DialogButton("Export", Command.Save));
                dialog.Buttons.Add(new DialogButton(Command.Cancel));
            }

            dialog.Show();

            Command r = dialog.Run();
            if (r != null && r.Id == Command.Save.Id) {
                Log.Add(LogLevel.Info, "Exporter " + this.GetType().Name, "Start exporting results.");
                if (Run(nodes)) {
                    Log.Add(LogLevel.Info, "Exporter " + this.GetType().Name, "Finish exporting results.");
                    dialog.Hide();
                } else {
                    ShowDialog(nodes);
                }
            } else if (r != null && r.Id == Command.Cancel.Id) {
                dialog.Hide();
            }
        }
Exemple #18
0
        public static void HandleCrash(Exception e)
        {
            var path = TemporaryFilesManager.Instance.EmulatorTemporaryPath + TemporaryFilesManager.CrashSuffix;
            Directory.CreateDirectory(path);
            var filename = CustomDateTime.Now.ToString("yyyyMMddHHmmssfff");
            var ex = e;
            using(var file = File.CreateText(Path.Combine(path, filename)))
            {
                while(ex != null)
                {
                    file.WriteLine(ex.Message);
                    file.WriteLine(ex.StackTrace);
                    ex = ex.InnerException;
                    if(ex != null)
                    {
                        file.WriteLine("Inner exception:");
                    }
                }
            }

            ex = e;
            var dialog = new Dialog();
            dialog.Title = "Fatal error";
            var sb = new StringBuilder();
            while(ex != null)
            {
                sb.AppendLine(ex.Message);
                #if DEBUG
                sb.AppendLine(ex.StackTrace);
                #endif
                ex = ex.InnerException;
                if(ex != null)
                {
                    sb.AppendLine("Inner exception:");
                }
            }

            var markdown = new MarkdownView();
            markdown.Markdown = sb.ToString().Split(new [] { '\n' }).Select(x => "\t" + x).Aggregate((x, y) => x + "\n" + y);

            var copyButton = new Button("Copy to clipboard");
            copyButton.Clicked += (sender, ev) => Clipboard.SetText(sb.ToString());

            var box = new VBox();

            box.PackStart(new Label( String.Format("Got unhandled exception: `{0}`", e.GetType()) ) { Font = global::Xwt.Drawing.Font.SystemFont.WithSize(15).WithWeight(Xwt.Drawing.FontWeight.Bold) });
            box.PackStart(new ScrollView(markdown), true, true);
            box.PackStart(copyButton);

            dialog.Content = box;

            dialog.Buttons.Add(new DialogButton(Command.Ok));
            dialog.Width = 350;
            dialog.Height = 300;

            var mre = new ManualResetEvent(false);
            Console.WriteLine(sb);

            ApplicationExtensions.InvokeInUIThread(() => {
                dialog.Run();
                dialog.Dispose();

                mre.Set();
            });

            mre.WaitOne();

            Environment.Exit(-1);
        }
Exemple #19
0
        public Windows()
        {
            Button bp = new Button ("Show borderless window");
            PackStart (bp);
            bp.Clicked += delegate {
                Window w = new Window ();
                w.Decorated = false;
                Button c = new Button ("This is a window");
            //				c.Margin.SetAll (10);
                w.Content = c;
                c.Clicked += delegate {
                    w.Dispose ();
                };
                var bpos = bp.ScreenBounds;
                w.ScreenBounds = new Rectangle (bpos.X, bpos.Y + bp.Size.Height, w.Width, w.Height);
                w.Show ();
            };
            Button b = new Button ("Show message dialog");
            PackStart (b);
            b.Clicked += delegate {
                MessageDialog.ShowMessage (ParentWindow, "Hi there!");
            };

            Button db = new Button ("Show custom dialog");
            PackStart (db);
            db.Clicked += delegate {
                Dialog d = new Dialog ();
                d.Title = "This is a dialog";
                Table t = new Table ();
                t.Add (new Label ("Some field:"), 0, 0);
                t.Add (new TextEntry (), 1, 0);
                t.Add (new Label ("Another field:"), 0, 1);
                t.Add (new TextEntry (), 1, 1);
                d.Content = t;
                d.CloseRequested += delegate(object sender, CloseRequestedEventArgs args) {
                    args.AllowClose = MessageDialog.Confirm ("Really close?", Command.Close);
                };

                Command custom = new Command ("Custom");
                d.Buttons.Add (new DialogButton (custom));
                d.Buttons.Add (new DialogButton ("Custom OK", Command.Ok));
                d.Buttons.Add (new DialogButton (Command.Cancel));
                d.Buttons.Add (new DialogButton (Command.Ok));

                var r = d.Run (this.ParentWindow);
                db.Label = "Result: " + (r != null ? r.Label : "(Closed)");
                d.Dispose ();
            };

            b = new Button ("Show Open File dialog");
            PackStart (b);
            b.Clicked += delegate {
                OpenFileDialog dlg = new OpenFileDialog ("Select a file");
                dlg.InitialFileName = "Some file";
                dlg.Multiselect = true;
                dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt"));
                dlg.Filters.Add (new FileDialogFilter ("All files", "*.*"));
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames));
            };

            b = new Button ("Show Save File dialog");
            PackStart (b);
            b.Clicked += delegate {
                SaveFileDialog dlg = new SaveFileDialog ("Select a file");
                dlg.InitialFileName = "Some file";
                dlg.Multiselect = true;
                dlg.Filters.Add (new FileDialogFilter ("Xwt files", "*.xwt"));
                dlg.Filters.Add (new FileDialogFilter ("All files", "*.*"));
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Files have been selected!", string.Join ("\n", dlg.FileNames));
            };

            b = new Button ("Show Select Folder dialog (Multi select)");
            PackStart (b);
            b.Clicked += delegate {
                SelectFolderDialog dlg = new SelectFolderDialog ("Select some folder");
                dlg.Multiselect = true;
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders));
            };

            b = new Button ("Show Select Folder dialog (Single select)");
            PackStart (b);
            b.Clicked += delegate {
                SelectFolderDialog dlg = new SelectFolderDialog ("Select a folder");
                dlg.Multiselect = false;
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Folders have been selected!", string.Join ("\n", dlg.Folders));
            };

            b = new Button ("Show Select Folder dialog (Single select, allow creation)");
            PackStart (b);
            b.Clicked += delegate {
                SelectFolderDialog dlg = new SelectFolderDialog ("Select or create a folder");
                dlg.Multiselect = false;
                dlg.CanCreateFolders = true;
                if (dlg.Run ())
                    MessageDialog.ShowMessage ("Folders have been selected/created!", string.Join ("\n", dlg.Folders));
            };

            b = new Button ("Show Select Color dialog");
            PackStart (b);
            b.Clicked += delegate {
                SelectColorDialog dlg = new SelectColorDialog ("Select a color");
                dlg.SupportsAlpha = true;
                dlg.Color = Xwt.Drawing.Colors.AliceBlue;
                if (dlg.Run (ParentWindow))
                    MessageDialog.ShowMessage ("A color has been selected!", dlg.Color.ToString ());
            };

            b = new Button("Show window shown event");
            PackStart(b);
            b.Clicked += delegate
            {
                Window w = new Window();
                w.Decorated = false;
                Button c = new Button("This is a window with events on");
                w.Content = c;
                c.Clicked += delegate
                {
                    w.Dispose();
                };
                w.Shown += (sender, args) => MessageDialog.ShowMessage("My Parent has been shown");
                w.Hidden += (sender, args) => MessageDialog.ShowMessage("My Parent has been hidden");

                w.Show();

            };

            b = new Button("Show dialog with dynamically updating content");
            PackStart(b);
            b.Clicked += delegate
            {
                var dialog = new Dialog ();
                dialog.Content = new Label ("Hello World");
                Xwt.Application.TimeoutInvoke (TimeSpan.FromSeconds (2), () => {
                    dialog.Content = new Label ("Goodbye World");
                    return false;
                });
                dialog.Run ();
            };
        }
        private IEnumerable<Tile> LoadTiles()
        {
            yield return CreateTile("Visit ParkitectNexus", App.DImages["parkitectnexus_logo-64x64.png"],
                Color.FromBytes(0xf3, 0x77, 0x35), _website.Launch);

            if (OperatingSystem.Detect() == SupportedOperatingSystem.Linux)
                yield return
                    CreateTile("Download URL", App.DImages["appbar.browser.wire.png"], Color.FromBytes(0xf3, 0x77, 0x35),
                        () =>
                        {
                            var entry = new TextEntry();

                            var box = new HBox();
                            box.PackStart(new Label("URL:"));
                            box.PackStart(entry, true, true);

                            var dialog = new Dialog
                            {
                                Width = 300,
                                Icon = ParentWindow.Icon,
                                Title = "Enter URL to download",
                                Content = box
                            };
                            dialog.Buttons.Add(new DialogButton(Command.Cancel));
                            dialog.Buttons.Add(new DialogButton(Command.Ok));

                            var result = dialog.Run(ParentWindow);

                            NexusUrl url;
                            if (result.Label.ToLower() == "ok" && NexusUrl.TryParse(entry.Text, out url))
                                ObjectFactory.GetInstance<IApp>().HandleUrl(url);
                            dialog.Dispose();
                        });

            yield return
                CreateTile("Launch Parkitect", App.DImages["parkitect_logo.png"], Color.FromBytes(45, 137, 239),
                    () => { _parkitect.Launch(); });

            yield return CreateTile("Help", App.DImages["appbar.information.png"], Color.FromBytes(45, 137, 239), () =>
            {
                // Temporary help solution.
                Process.Start(
                    "https://parkitectnexus.com/forum/2/parkitectnexus-website-client/70/troubleshooting-mods-and-client");
            });

            yield return CreateTile("Donate!", App.DImages["appbar.thumbs.up.png"], Color.FromBytes(45, 137, 239), () =>
            {
                if (MessageDialog.AskQuestion("Maintaining this client and adding new features takes a lot of time.\n" +
                                              "If you appreciate our work, please consider sending a donation our way!\n" +
                                              "All donations will be used for further development of the ParkitectNexus Client and the website.\n" +
                                              "\nSelect Yes to visit PayPal and send a donation.", 1, Command.No,
                    Command.Yes) == Command.Yes)
                {
                    Process.Start("https://paypal.me/ikkentim");
                }
            });
        }
Exemple #21
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="_s"></param>
        /// <param name="_file"></param>
        public static bool ProcessApiaryFile(Server _s, String _file)
        {
            // Read file to variable
            String content = "";
            try
            {
                using (StreamReader sr = new StreamReader(_file))
                {
                    content = sr.ReadToEnd();
                }
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.CannotReadFromFile);
                return false;
            }

            // Parse content
            ApiaryServer s;
            try
            {
                s = JsonConvert.DeserializeObject<ApiaryServer>(content);
            }
            catch
            {
                MessageDialog.ShowError(Director.Properties.Resources.InvalidApiaryFile);
                return false;
            }

            // Set URL
            String url = "";
            while (true)
            {
                var d = new Dialog();
                d.Title = Director.Properties.Resources.FillEndPointUrl;
                d.Width = 340;
                d.Icon = Image.FromResource(DirectorImages.EDIT_ICON);

                VBox DialogContent = new VBox();
                DialogContent.PackStart(new Label(Director.Properties.Resources.FillEndPointUrl));
                TextEntry NewValidUrl = new TextEntry();
                if (url.Length == 0)
                    NewValidUrl.Text = "http://example.com";
                DialogContent.PackStart(NewValidUrl, true, true);

                d.Buttons.Add(new DialogButton(Director.Properties.Resources.ButtonOK, Command.Ok));
                d.Buttons.Add(new DialogButton(Director.Properties.Resources.ButtonStorno, Command.Cancel));
                d.Content = DialogContent;

                var c = d.Run();

                if (c == Command.Ok)
                {
                    Uri _newUri;

                    // Uri validation
                    if (Uri.TryCreate(NewValidUrl.Text, UriKind.Absolute, out _newUri))
                    {
                        url = _newUri.AbsoluteUri;
                        d.Dispose();
                        break;
                    }
                    else
                    {
                        MessageDialog.ShowError(Director.Properties.Resources.InvalidUrlError);
                    }
                }
                else
                {
                    d.Dispose();
                    return false;
                }
                d.Dispose();
            }

            // Fill data
            if (_s.Name == null || _s.Name.Length == 0)
                _s.Name = s.name;

            if (_s.Url == null || _s.Url.Length == 0)
                _s.Url = url;

            // Z resources group vyrobit scenare
            foreach (var group in s.resourceGroups)
            {
                var scNew = _s.CreateNewScenario();
                scNew.Name = group.name;

                // Z akcí - example vyrobit requesty
                foreach (var resource in group.resources)
                {
                    foreach (var action in resource.actions)
                    {
                        var reqNew = scNew.CreateNewRequest();
                        reqNew.Name = string.Format("{0}/{1}", resource.name, action.name);
                        reqNew.HTTP_METHOD = action.method;

                        // Create URL
                        if (resource.uriTemplate.StartsWith("/") && url.EndsWith("/"))
                        {
                            reqNew.Url = url.Substring(0, url.Length - 1) + resource.uriTemplate;
                        }
                        else
                            reqNew.Url = url + resource.uriTemplate;

                        // Get first request
                        var req = (action.examples.Count > 0 && action.examples[0].requests.Count > 0) ? action.examples[0].requests[0] : null;
                        var res = (action.examples.Count > 0 && action.examples[0].responses.Count > 0) ? action.examples[0].responses[0] : null;

                        if (req != null)
                        {
                            // Content type
                            reqNew.RequestTemplateType = ContentTypeUtils.GuessContentType (req.body);
                            reqNew.RequestTemplate = req.body;

                            // Headers
                            foreach (var h in req.headers)
                            {
                                reqNew.Headers.Add(new Header()
                                {
                                    Name = h.name, Value = h.value
                                });
                            }
                        }

                        if (res != null)
                        {
                            // Content type
                            reqNew.ResponseTemplateType = ContentTypeUtils.GuessContentType (res.body);
                            // Set body
                            reqNew.ResponseTemplate = res.body;
                        }
                    }
                }
            }

            return true;
        }
Exemple #22
0
		public DefaultSelectFontDialogBackend (WindowFrame parentWindow)
		{
			parent = parentWindow;

			fontDialog = new Dialog ();
			fontDialog.Width = 500;
			fontDialog.Height = 300;

			VBox box = new VBox ();
			fontSelector = new FontSelector ();
			fontSelector.FontChanged += (sender, e) => SelectedFont = fontSelector.SelectedFont;
			box.PackStart (fontSelector, true);

			fontDialog.Content = box;

			fontDialog.Buttons.Add (new DialogButton (Command.Cancel));
			fontDialog.Buttons.Add (new DialogButton (Command.Ok));
		}
Exemple #23
0
		public WizardDialog (IWizardDialogController controller)
		{
			Controller = controller;
			Dialog = new Dialog ();

			Dialog.Name = "wizard_dialog";
			Dialog.Resizable = false;
			Dialog.Padding = 0;

			if (string.IsNullOrEmpty (controller.Title))
				Dialog.Title = BrandingService.ApplicationName;
			else
				Dialog.Title = controller.Title;

			// FIXME: Gtk dialogs don't support ThemedImage
			//if (controller.Image != null)
			//	Dialog.Icon = controller.Image.WithSize (IconSize.Large);
			
			Dialog.ShowInTaskbar = false;
			Dialog.Shown += HandleDialogShown;
			Dialog.CloseRequested += HandleDialogCloseRequested;

			container = new VBox ();
			container.Spacing = 0;

			header = new MonoDevelop.Components.ExtendedHeaderBox (controller.Title, null, controller.Icon);
			header.BackgroundColor = Styles.Wizard.BannerBackgroundColor;
			header.TitleColor = Styles.Wizard.BannerForegroundColor;
			header.SubtitleColor = Styles.Wizard.BannerSecondaryForegroundColor;
			header.BorderColor = Styles.Wizard.BannerShadowColor;

			buttonBox = new HBox ();
			var buttonFrame = new FrameBox (buttonBox);
			buttonFrame.Padding = 20;
			buttonFrame.PaddingRight = 0;

			cancelButton = new Button (GettextCatalog.GetString ("Cancel"));
			cancelButton.Clicked += HandleCancelButtonClicked;
			backButton = new Button (GettextCatalog.GetString ("Back"));
			backButton.Clicked += HandleBackButtonClicked;
			nextButton = new Button (GettextCatalog.GetString ("Next"));
			nextButton.Clicked += HandleNextButtonClicked;
			statusImage = new ImageView (ImageService.GetIcon ("md-empty", Gtk.IconSize.Button));

			if (Toolkit.CurrentEngine.Type == ToolkitType.XamMac) {
				var s = cancelButton.Surface.GetPreferredSize ();
				cancelButton.MinWidth = Math.Max (s.Width + 16, 100);
				s = backButton.Surface.GetPreferredSize ();
				backButton.MinWidth = Math.Max (s.Width + 16, 100);
				s = nextButton.Surface.GetPreferredSize ();
				nextButton.MinWidth = Math.Max (s.Width + 16, 100);
				buttonBox.Spacing = 0;
				statusImage.MarginRight = 6;
				#if MAC
				var nativeNext = nextButton.Surface.NativeWidget as AppKit.NSButton;
				nativeNext.KeyEquivalent = "\r";
				#endif
			} else {
				cancelButton.MinWidth = 70;
				backButton.MinWidth = 70;
				nextButton.MinWidth = 70;
				statusImage.MarginRight = 3;
			}

			if (ImageService.IsAnimation ("md-spinner-18", Gtk.IconSize.Button)) {
				animatedStatusIcon = ImageService.GetAnimatedIcon ("md-spinner-18", Gtk.IconSize.Button);
			}

			buttonBox.PackStart (cancelButton, false, false);
			buttonBox.PackEnd (statusImage, false, false);
			buttonBox.PackEnd (nextButton, false, false);
			buttonBox.PackEnd (backButton, false, false);
			statusImage.VerticalPlacement = cancelButton.VerticalPlacement = nextButton.VerticalPlacement = backButton.VerticalPlacement = WidgetPlacement.Center;

			container.PackStart (header);

			var contentHBox = new HBox ();
			contentHBox.Spacing = 0;

			currentPageFrame = new FrameBox ();
			currentPageFrame.BackgroundColor = Styles.Wizard.PageBackgroundColor;
			contentHBox.PackStart (currentPageFrame, true, true);

			rightSideFrame = new FrameBox () { Visible = false };
			//rightSideFrame.BorderColor = Styles.Wizard.ContentSeparatorColor;
			//rightSideFrame.BorderWidthLeft = 1;
			rightSideFrame.WidthRequest = RightSideWidgetWidth;
			rightSideFrame.BackgroundColor = Styles.Wizard.RightSideBackgroundColor;
			contentHBox.PackEnd (rightSideFrame, false, true);
			rightSideFrame.VerticalPlacement = rightSideFrame.HorizontalPlacement = WidgetPlacement.Fill;

			var contentFrame = new FrameBox (contentHBox);
			contentFrame.Padding = 0;
			contentFrame.BorderColor = Styles.Wizard.ContentShadowColor;
			contentFrame.BorderWidth = 0;
			contentFrame.BorderWidthBottom = 1;

			container.PackStart (contentFrame, true, true);
			container.PackEnd (buttonFrame);

			Dialog.Content = container;

			if (Toolkit.CurrentEngine.Type == ToolkitType.Gtk) {
				var nativeNext = nextButton.Surface.NativeWidget as Gtk.Button;
				nativeNext.CanDefault = true;
				nativeNext.GrabDefault ();
			}

			CurrentPage = controller.CurrentPage;

			controller.PropertyChanged += HandleControllerPropertyChanged;
			controller.Completed += HandleControllerCompleted;
		}