Пример #1
0
        private static void DrawExportInfoDialog(string message, string jsonText)
        {
            var ok    = new Button("Ok");
            var entry = new Label(message)
            {
                X      = 1,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = 1
            };

            ok.Clicked += () => { Application.RequestStop(); };
            entry.Text  = message;
            var text = new TextField(jsonText)
            {
                X      = 1,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = 3
            };

            var dialog = new Dialog("Success", 60, 7, ok);

            dialog.Add(entry);
            dialog.Add(text);
            Application.Run(dialog);
        }
Пример #2
0
        private void SetupFailedLoginDialogPopUp()
        {
            // Clear text fields
            this.appViews.LoginScreen.UsernameField.Text = "";
            this.appViews.LoginScreen.PasswordField.Text = "";

            // Set cursor back to username TextField
            this.appViews.LoginScreen.SetFocus(this.appViews.LoginScreen.UsernameField);

            // Error dialog
            var d = new Dialog("Error",
                               50,
                               10,
                               new Button("Ok", is_default: true)
            {
                Clicked = () =>
                {
                    Application.RequestStop();
                }
            });

            var errorText = new Label(1, 2, "Wrong user or password!")
            {
                TextAlignment = TextAlignment.Centered,
                TextColor     = (int)Color.BrightGreen
            };

            d.Add(errorText);

            errorText = new Label(1, 3, "Try to login again..");
            d.Add(errorText);

            Application.Run(d);
        }
Пример #3
0
    static void OptionsDialog()
    {
        Dialog d = new Dialog(62, 15, "Options");

        d.Add(new Label(1, 1, "  Download Directory:"));
        d.Add(new Label(1, 3, "         Listen Port:"));
        d.Add(new Label(1, 5, "  Upload Speed Limit:"));
        d.Add(new Label(35, 5, "kB/s"));
        d.Add(new Label(1, 7, "Download Speed Limit:"));
        d.Add(new Label(35, 7, "kB/s"));

        Entry download_dir = new Entry(24, 1, 30, "~/Download");

        d.Add(download_dir);

        Entry listen_port = new Entry(24, 3, 6, "34");

        d.Add(listen_port);

        Entry upload_limit = new Entry(24, 5, 10, "1024");

        d.Add(upload_limit);

        Entry download_limit = new Entry(24, 7, 10, "1024");

        d.Add(download_limit);

        bool ok = false;

        Button b = new Button("Ok", true);

        b.Clicked += delegate { ok = true; b.Container.Running = false; };
        d.AddButton(b);

        b          = new Button("Cancel");
        b.Clicked += delegate { b.Container.Running = false; };
        d.AddButton(b);

        Application.Run(d);

        if (ok)
        {
            int v;

            if (!Int32.TryParse(listen_port.Text, out v))
            {
                Application.Error("Error", "The value `{0}' is not a valid port number", listen_port.Text);
                return;
            }

            if (!Directory.Exists(download_dir.Text))
            {
                Application.Error("Error", "The directory\n{0}\ndoes not exist", download_dir.Text);
                return;
            }
        }
    }
Пример #4
0
        private void EvaluateRuleCoverage()
        {
            _treeView.ClearObjects();

            var colliding   = new TreeNodeWithCount("Colliding Rules");
            var ignore      = new TreeNodeWithCount("Ignore Rules Used");
            var update      = new TreeNodeWithCount("Update Rules Used");
            var outstanding = new TreeNodeWithCount("Outstanding Failures");

            var allRules = Ignorer.Rules.Union(Updater.Rules).ToList();

            AddDuplicatesToTree(allRules);

            _treeView.AddObjects(new [] { colliding, ignore, update, outstanding });

            var cts = new CancellationTokenSource();

            var    btn        = new Button("Cancel");
            Action cancelFunc = () => { cts.Cancel(); };
            Action closeFunc  = () => { Application.RequestStop(); };

            btn.Clicked += cancelFunc;

            var dlg = new Dialog("Evaluating", MainWindow.DlgWidth, 6, btn);

            var stage = new Label("Evaluating Failures")
            {
                Width = Dim.Fill(), X = 0, Y = 0
            };
            var progress = new ProgressBar()
            {
                Height = 2, Width = Dim.Fill(), X = 0, Y = 1
            };
            var textProgress = new Label("0/0")
            {
                TextAlignment = TextAlignment.Right, Width = Dim.Fill(), X = 0, Y = 2
            };

            dlg.Add(stage);
            dlg.Add(progress);
            dlg.Add(textProgress);

            Task.Run(() => {
                EvaluateRuleCoverageAsync(stage, progress, textProgress, cts.Token, colliding, ignore, update, outstanding);
            }, cts.Token).ContinueWith((t) => {
                btn.Clicked -= cancelFunc;
                btn.Text     = "Done";
                btn.Clicked += closeFunc;
                dlg.SetNeedsDisplay();

                cts.Dispose();
            });;

            Application.Run(dlg);
        }
Пример #5
0
        static void RunQueryNow(object sender, EventArgs e)
        {
            var d = new Dialog(100, 100, "Run Query");

            d.Add(new Label(0, 0, "Query Options:"));
            var start = new Mono.Terminal.Entry(12, 0, 25, null);

            d.Add(start);

            _container.Add(d);
        }
Пример #6
0
        static Dialog BuildUninstallServiceDialog()
        {
            var cancel = new Button("Cancel");

            cancel.Clicked += () => { Application.RequestStop(); };

            Dialog dlg = new Dialog("Uninstall service", 50, 15, cancel)
            {
                Width = Dim.Percent(80), Height = Dim.Percent(80)
            };

            ServiceController[] scServices;

            scServices = ServiceController.GetServices();

            var jsdalLikeServices = scServices.Where(sc => sc.ServiceName.ToLower().Contains("jsdal")).ToList();
            var items             = jsdalLikeServices.Select(s => $"({s.Status})  {s.DisplayName}").ToArray();

            dlg.Add(new Label(1, 1, "Select a jsdal service to uninstall:"));

            for (var i = 0; i < items.Length; i++)
            {
                var local = i;

                var but = new Button(1, 3 + i, items[i]);

                but.Clicked += () =>
                {
                    var service = jsdalLikeServices[local];
                    int ret     = MessageBox.Query(80, 10, "Confirm action", $"Are you sure you want to uninstall '{service.ServiceName}'?", "Confirm", "Cancel");

                    if (ret == 0)
                    {
                        ManagementObject wmiService;

                        wmiService = new ManagementObject("Win32_Service.Name='" + service.ServiceName + "'");
                        wmiService.Get();
                        wmiService.Delete();


                        MessageBox.Query(30, 8, "", "Service uninstalled", "Ok");
                        Application.RequestStop();
                    }
                    else if (ret == 1)
                    {
                    }
                };

                dlg.Add(but);
            }

            return(dlg);
        }
Пример #7
0
        public InstallationDialog(SearchResult item)
            : base(item.PackageId, width: 80, height: 12)
        {
            var cancel = new Button(3, 14, "Cancel")
            {
                Clicked = () => Application.RequestStop()
            };
            var install = new Button(10, 14, "Install")
            {
                Clicked = () =>
                {
                    var resultText = new TextView
                    {
                        Text     = "Installing...",
                        ReadOnly = true,
                        Height   = 15
                    };

                    var resultDialog = new Dialog(
                        "Install package",
                        width: 80,
                        height: 30,
                        new Button("Ok")
                    {
                        Clicked = () => Application.RequestStop()
                    });

                    resultDialog.Add(resultText);

                    Application.MainLoop.Invoke(async() =>
                    {
                        var dotnet = new Dotnet();
                        var result = await dotnet.AddPackage(item.PackageId, item.Version);

                        resultText.Text = string.Join("\n", result.Output);
                    });

                    Application.Run(resultDialog);
                    Application.RequestStop();
                }
            };

            var details = $"Downloads: {FormatDownloads(item.TotalDownloads)}\n";

            details += $"Tags: {string.Join(", ", item.Tags)}\n";
            details += $"\n";
            details += $"Description:\n";
            details += item.Description;

            var text = new TextView
            {
                Text     = details,
                ReadOnly = true,
                Height   = 5
            };

            AddButton(cancel);
            AddButton(install);
            Add(text);
        }
Пример #8
0
        public DynamicStatusItem EnterStatusItem()
        {
            var valid = false;

            if (_statusItem == null)
            {
                var m = new DynamicStatusItem();
                _txtTitle.Text  = m.title;
                _txtAction.Text = m.action;
            }
            else
            {
                EditStatusItem(_statusItem);
            }

            var _btnOk = new Button("Ok")
            {
                IsDefault = true,
            };

            _btnOk.Clicked += () => {
                if (ustring.IsNullOrEmpty(_txtTitle.Text))
                {
                    MessageBox.ErrorQuery("Invalid title", "Must enter a valid title!.", "Ok");
                }
                else
                {
                    if (!ustring.IsNullOrEmpty(_txtShortcut.Text))
                    {
                        _txtTitle.Text = DynamicStatusBarSample.SetTitleText(
                            _txtTitle.Text, _txtShortcut.Text);
                    }
                    valid = true;
                    Application.RequestStop();
                }
            };
            var _btnCancel = new Button("Cancel");

            _btnCancel.Clicked += () => {
                _txtTitle.Text = ustring.Empty;
                Application.RequestStop();
            };
            var _dialog = new Dialog("Please enter the item details.", _btnOk, _btnCancel);

            Width  = Dim.Fill();
            Height = Dim.Fill() - 1;
            _dialog.Add(this);
            _txtTitle.SetFocus();
            _txtTitle.CursorPosition = _txtTitle.Text.Length;
            Application.Run(_dialog);

            if (valid)
            {
                return(new DynamicStatusItem(_txtTitle.Text, _txtAction.Text, _txtShortcut.Text));
            }
            else
            {
                return(null);
            }
        }
Пример #9
0
        private void Activate(OutstandingFailureNode ofn)
        {
            var ignore = new Button("Ignore");

            ignore.Clicked += () => { Ignore(ofn); Application.RequestStop(); };

            var update = new Button("Update");

            update.Clicked += () => { Update(ofn); Application.RequestStop(); };

            var cancel = new Button("Cancel");

            cancel.Clicked += () => { Application.RequestStop(); };

            var dlg = new Dialog("Failure", MainWindow.DlgWidth, MainWindow.DlgHeight, ignore, update, cancel);

            var lbl = new FailureView()
            {
                X              = 0,
                Y              = 0,
                Width          = Dim.Fill(),
                Height         = Dim.Fill(2),
                CurrentFailure = ofn.Failure
            };

            dlg.Add(lbl);

            Application.Run(dlg);
        }
Пример #10
0
        static string AskIP(int tatami)
        {
            var dialog = new Dialog("IP address", 30, 5);
            var t      = new TextField(0, 0, 15, txtServers[tatami - 1].Text);
            var oldIp  = t.Text;

            dialog.Add(t);

            dialog.AddButton(new Button("OK", true)
            {
                Clicked = () => {
                    txtServers[tatami - 1].Text   = t.Text;
                    btnStart[tatami - 1].CanFocus = false;
                    btnStop[tatami - 1].CanFocus  = true;
                    Application.MainLoop.Invoke(() =>
                    {
                        AddLogg($"Changed IP from {oldIp} to {t.Text} on tatami {tatami}");
                        SetStatus(tatami, Status.TRY_START);
                    });
                    tatamis[tatami - 1].Connect(t.Text.ToString());
                    dialog.Running = false;
                }
            });

            dialog.AddButton(new Button("CANCEL", false)
            {
                Clicked = () => {
                    dialog.Running = false;
                }
            });

            Application.Run(dialog);

            return("");
        }
Пример #11
0
        public override void Show(string title, string message)
        {
            GetDialogDimensions(out var w, out var h);

            var btn = new Button("Ok");

            btn.Clicked += () => Application.RequestStop();


            using (var dlg = new Dialog(title, w, h, btn)
            {
                Modal = true
            })
            {
                dlg.Add(new TextView()
                {
                    Width     = Dim.Fill(),
                    Height    = Dim.Fill(1),
                    Text      = message.Replace("\r\n", "\n"),
                    ReadOnly  = true,
                    AllowsTab = false
                });
                Application.Run(dlg);
            }
        }
Пример #12
0
        static int QueryFull(bool useErrorColors, int width, int height, string title, string message, params string[] buttons)
        {
            var textWidth = Label.MaxWidth(message, width);
            int clicked = -1, count = 0;

            var d = new Dialog(title, width, height);

            if (useErrorColors)
            {
                d.ColorScheme = Colors.Error;
            }

            foreach (var s in buttons)
            {
                var n = count++;
                var b = new Button(s);
                b.Clicked += delegate {
                    clicked   = n;
                    d.Running = false;
                };
                d.AddButton(b);
            }

            if (message != null)
            {
                var l = new Label((width - 4 - textWidth) / 2, 0, message);
                d.Add(l);
            }

            Application.Run(d);
            return(clicked);
        }
Пример #13
0
        public static void SortOrder()
        {
            Dialog     dialog     = new Dialog("Sort By", 25, 10);
            RadioGroup radioGroup = new RadioGroup(3, 1, new string[] { "Ascending", "Descending" }, (int)Utils.Settings.SortOrder);

            dialog.Add(radioGroup);

            Button btnOk = new Button("OK", true);

            btnOk.Clicked = delegate()
            {
                Utils.Settings.SortOrder = (Utils.SortOrder)radioGroup.Selected;
                Utils.Settings.Save();

                MyDrive.SortItems();

                dialog.Running = false;
                Application.Top.SetFocus(MyDrive.Window);
            };
            Button btnCancel = new Button("Cancel");

            btnCancel.Clicked = delegate()
            {
                dialog.Running = false;
                Application.Top.SetFocus(MyDrive.Window);
            };
            dialog.AddButton(btnOk);
            dialog.AddButton(btnCancel);

            Application.Run(dialog);
            Application.Refresh();
        }
Пример #14
0
        public static void ShowHelp()
        {
            Dialog aboutWin   = new Dialog("Help", 80, 20);
            Label  aboutLabel = new Label(@" 
All menu commands can be activated by hitting ALT + [highlighted_key].
If for some reason Alt refuses to work, you can activate the top level menu with F9.
Browsing tables is down with the left/right/up/down keys.
PageUp/PageDown switch between tables.
Hitting enter will edit the currently centered column and selected record.
Space will show a menu of columns on the currently selected record.

Adding/Removing columns, tables and records can all be done via menu commands.
Renaming and changing column order are supported as well, moving records is currently not.

[ESC] to close this window.
                ")
            {
                X      = 1,
                Y      = 1,
                Width  = Dim.Fill(1),
                Height = Dim.Fill(1),
            };

            aboutWin.Add(aboutLabel);
            Application.Run(aboutWin);
        }
Пример #15
0
    // This returns ResponseType.Yes, No, or Cancel
    ResponseType AskSave(string info)
    {
        if (Project == null)
        {
            return(ResponseType.No);
        }

        ResponseType response;

        Gtk.Dialog d = new Dialog("Save Project?", this,
                                  DialogFlags.DestroyWithParent,
                                  Gtk.Stock.Yes, ResponseType.Yes,
                                  Gtk.Stock.No, ResponseType.No,
                                  Gtk.Stock.Cancel, ResponseType.Cancel);
        Alignment a = new Alignment(1, 0.25f, 1, 0);

        a.SetSizeRequest(0, 50);
        a.Add(new Gtk.Label(info));
        d.Add(a);
        d.ShowAll();
        response = (ResponseType)d.Run();
        d.Destroy();
        if (response == ResponseType.Yes)
        {
            Project.Save();
        }

        return(response);
    }
Пример #16
0
        static void CreateNew()
        {
            string    dbName        = "temp.cdb";
            Dialog    getNameDialog = new Dialog("Enter new database name", 60, 10);
            TextField nameField     = new TextField("")
            {
                X = 1, Y = 1, Width = Dim.Fill(), Height = 1
            };
            Button confirmBtn = new Button("Confirm")
            {
                Clicked = () =>
                {
                    if (nameField.Text.Length > 5 && nameField.Text.EndsWith(".cdb"))
                    {
                        dbName = dbName = nameField.Text.ToString();
                        Application.RequestStop();
                    }
                }
            };

            getNameDialog.AddButton(confirmBtn);
            getNameDialog.Add(nameField);
            Application.Run(getNameDialog);

            currDB = new RookDB(dbName);
            PrintStatus("Created new database, unsaved.", StatusLevel.Warning);
            UpdateWindowName();
        }
        /// <summary>
        /// Starts this instance.
        /// </summary>
        public void Start()
        {
            if (IsStarted)
            {
                return;
            }

            IsStarted = true;

            dialog = new Dialog(applicationName, toplevel.Frame.Width - 2, toplevel.Frame.Height - 1);

            progress = new ProgressBar()
            {
                X      = Pos.Center(),
                Y      = Pos.Center(),
                Height = 1,
                Width  = Dim.Percent(50),
            };

            label = new Label(initialText)
            {
                X      = Pos.Center(),
                Y      = Pos.Center() + 1,
                Height = 1,
                Width  = Dim.Percent(50)
            };

            dialog.Add(progress, label);

            runState = Application.Begin(dialog);

            Application.RunLoop(runState, false);
        }
Пример #18
0
        // TODO does not work correctly yet
        public static string StringInput(Window parent_window, string title)
        {
            var dialog = new Dialog(title, parent_window, Gtk.DialogFlags.DestroyWithParent);

            dialog.Modal = true;

            Entry text_entry = new Entry("Name");

            text_entry.Visible = true;

            dialog.Add(text_entry);
            dialog.AddButton("OK", ResponseType.Ok);
            dialog.AddButton("Cancel", ResponseType.Cancel);

            ResponseType response = (ResponseType)dialog.Run();

            dialog.Destroy();

            if (response == ResponseType.Ok)
            {
                return(text_entry.Text);
            }
            else
            {
                return("");
            }
        }
Пример #19
0
        private void DoDisassembly()
        {
            using (var dasm = new Disassembler(_selectedFile))
            {
                if (File.Exists(_outputFile))
                {
                    File.Delete(_outputFile);
                }

                _statusLabel.Text = "Performing Disassembly...";
                var inputFile = dasm.Disassemble(_optionMinimal);

                //Apply Selected Analysis
                if (_optionMBBSAnalysis)
                {
                    _statusLabel.Text = "Performing Additional Analysis...";
                    Analysis.MBBS.Analyze(inputFile);
                }
                _progressBar.Fraction = .25f;


                var _stringRenderer = new StringRenderer(inputFile);

                _statusLabel.Text = "Processing Segment Information...";
                File.AppendAllText(_outputFile, _stringRenderer.RenderSegmentInformation());
                _progressBar.Fraction = .50f;


                _statusLabel.Text = "Processing Entry Table...";
                File.AppendAllText(_outputFile, _stringRenderer.RenderEntryTable());
                _progressBar.Fraction = .75f;



                _statusLabel.Text = "Processing Disassembly...";
                File.AppendAllText(_outputFile, _stringRenderer.RenderDisassembly(_optionMBBSAnalysis));
                _progressBar.Fraction = .85f;


                if (_optionStrings)
                {
                    _statusLabel.Text = "Processing Strings...";
                    File.AppendAllText(_outputFile, _stringRenderer.RenderStrings());
                }

                _statusLabel.Text     = "Done!";
                _progressBar.Fraction = 1f;
            }

            var d = new Dialog($"Disassembly Complete!", 50, 12);

            d.Add(new Label(0, 0, $"Output File: {_outputFile}"),
                  new Label(0, 1, $"Bytes Written: {new FileInfo(_outputFile).Length}")
                  );
            var okBtn = new Button("OK", true);

            okBtn.Clicked += () => { Application.RequestStop(); };
            d.AddButton(okBtn);
            Application.Run(d);
        }
Пример #20
0
        private bool GetText(string title, string label, string initialText, out string enteredText)
        {
            bool okPressed = false;

            var ok = new Button("Ok", is_default: true);

            ok.Clicked += () => { okPressed = true; Application.RequestStop(); };
            var cancel = new Button("Cancel");

            cancel.Clicked += () => { Application.RequestStop(); };
            var d = new Dialog(title, 60, 20, ok, cancel);

            var lbl = new Label()
            {
                X    = 0,
                Y    = 1,
                Text = label
            };

            var tf = new TextField()
            {
                Text  = initialText,
                X     = 0,
                Y     = 2,
                Width = Dim.Fill()
            };

            d.Add(lbl, tf);
            tf.SetFocus();

            Application.Run(d);

            enteredText = okPressed? tf.Text.ToString() : null;
            return(okPressed);
        }
Пример #21
0
        static Dialog BuildUI()
        {
            var d = new Dialog(40, 8, "Hello");

            d.Add(new Label(0, 0, "Hello World"));

            return(d);
        }
Пример #22
0
        public OResult Query(OResult flags, string errormsg, string condition, string file)
        {
            var s   = String.Format(condition, file);
            int len = Math.Min(s.Length, Terminal.Cols - 8);

            var d = new Dialog(len, 8, "Error");

            d.ErrorColors();
            d.Add(new Label(1, 1, errormsg));
            d.Add(new Label(1, 2, String.Format(condition, file.Ellipsize(len - condition.Length))));

            OResult result = OResult.Ignore;
            Button  b;

            if ((flags & OResult.Retry) == OResult.Retry)
            {
                b          = new Button(0, 0, "Retry", true);
                b.Clicked += delegate {
                    result    = OResult.Retry;
                    d.Running = false;
                };
                d.Add(b);
            }
            if ((flags & OResult.Ignore) == OResult.Ignore)
            {
                b          = new Button(0, 0, "Ignore", true);
                b.Clicked += delegate {
                    result    = OResult.Ignore;
                    d.Running = false;
                };
                d.Add(b);
            }
            if ((flags & OResult.Cancel) == OResult.Cancel)
            {
                b          = new Button(0, 0, "Cancel", true);
                b.Clicked += delegate {
                    result    = OResult.Cancel;
                    d.Running = false;
                };
                d.Add(b);
            }
            Terminal.Run(d);
            return(result);
        }
Пример #23
0
        public void Write_Do_Not_Change_On_ProcessKey()
        {
            var win = new Window();

            Application.Begin(win);
            ((FakeDriver)Application.Driver).SetBufferSize(20, 8);

            System.Threading.Tasks.Task.Run(() => {
                System.Threading.Tasks.Task.Delay(500).Wait();
                Application.MainLoop.Invoke(() => {
                    var lbl = new Label("Hello World")
                    {
                        X = Pos.Center()
                    };
                    var dlg = new Dialog("Test", new Button("Ok"));
                    dlg.Add(lbl);
                    Application.Begin(dlg);

                    var expected = @"
┌──────────────────┐
│┌ Test ─────────┐ │
││  Hello World  │ │
││               │ │
││               │ │
││     [ Ok ]    │ │
│└───────────────┘ │
└──────────────────┘
";

                    var pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
                    Assert.Equal(new Rect(0, 0, 20, 8), pos);

                    Assert.True(dlg.ProcessKey(new KeyEvent(Key.Tab, new KeyModifiers())));
                    dlg.Redraw(dlg.Bounds);

                    expected = @"
┌──────────────────┐
│┌ Test ─────────┐ │
││  Hello World  │ │
││               │ │
││               │ │
││     [ Ok ]    │ │
│└───────────────┘ │
└──────────────────┘
";

                    pos = GraphViewTests.AssertDriverContentsWithFrameAre(expected, output);
                    Assert.Equal(new Rect(0, 0, 20, 8), pos);

                    win.RequestStop();
                });
            });

            Application.Run(win);
            Application.Shutdown();
        }
Пример #24
0
        public Dialog MenuView(Window previousWin, Player player, Toplevel top)
        {
            var gameButton = new Button("Jeu", false)
            {
                X = x,
                Y = y,
            };

            gameButton.Clicked += () =>
            {
                ChoosePseudoToLaunchGame(player, previousWin);
            };

            var settingsButton = new Button("Options", false)
            {
                X = x,
                Y = Pos.Bottom(gameButton) + 1
            };

            settingsButton.Clicked += () =>
            {
                Settings(outputDevice, previousWin);
            };

            var helpButton = new Button("Aide Jeu", false)
            {
                X = x,
                Y = Pos.Bottom(settingsButton) + 1
            };

            helpButton.Clicked += () =>
            {
                HelpView(previousWin);
            };

            var creditButton = new Button("Credits", false)
            {
                X = x,
                Y = Pos.Bottom(helpButton) + 1
            };

            creditButton.Clicked += () =>
            {
                Credit(previousWin);
            };

            buttons = new Dialog("Menu");

            buttons.Add(
                gameButton,
                settingsButton,
                helpButton,
                creditButton);

            return(buttons);
        }
Пример #25
0
        void MakeButton(Dialog d, int x, int y, string text, System.Action action)
        {
            Button b = new Button(x, y, text);

            b.Clicked += delegate {
                action();
                d.Running = false;
            };
            d.Add(b);
        }
Пример #26
0
        public static string ShowDialogText(string title, string text, string defaultValue = "")
        {
            string response = "";
            var    dialog   = new Dialog(title, 50, 10, new Button("Ok")
            {
                Clicked = () => { response = _textField.Text.ToString(); Application.RequestStop(); }
            }, new Button("Cancel")
            {
                Clicked = () => { Application.RequestStop(); }
            });
            Label label = new Label(1, 1, text);

            dialog.Add(label);
            _textField      = new TextField(1, 1, 40, "");
            _textField.Text = defaultValue;
            dialog.Add(_textField);
            _textField.EnsureFocus();
            Application.Run(dialog);
            return(response);
        }
Пример #27
0
        private void Help_About()
        {
            var dialog = new Dialog("About", 30, 10);

            dialog.Add(new []
            {
                new Label(0, 0, "Stad.View.Console"),
                new Label(0, 1, "Version : 0.0.0")
            });
            Application.Run(dialog);
        }
Пример #28
0
        public static string ShowDialogList(string title, List <string> list)
        {
            var dialog = new Dialog(title, 50, 22, new Button("Close", true)
            {
                Clicked = () => { Application.RequestStop(); }
            });
            ListViewSelection listView = new ListViewSelection(new Rect(1, 1, 45, 16), list);

            dialog.Add(listView);
            Application.Run(dialog);
            return(listView.Selection);
        }
Пример #29
0
        public static T ShowDialogObjects <T>(string title, Dictionary <T, string> objects)
        {
            var dialog = new Dialog(title, 50, 22, new Button("Close", true)
            {
                Clicked = () => { Application.RequestStop(); }
            });
            ListViewObject <T> listView = new ListViewObject <T>(new Rect(1, 1, 45, 16), objects);

            dialog.Add(listView);
            Application.Run(dialog);
            return(listView.Selection);
        }
Пример #30
0
        private void EditCurrentCell(TableView.CellActivatedEventArgs e)
        {
            if (e.Table == null)
            {
                return;
            }
            var o = e.Table.Rows [e.Row] [e.Col];

            var title = o is uint u?GetUnicodeCategory(u) + $"(0x{o:X4})" : "Enter new value";

            var  oldValue  = e.Table.Rows[e.Row][e.Col].ToString();
            bool okPressed = false;

            var ok = new Button("Ok", is_default: true);

            ok.Clicked += () => { okPressed = true; Application.RequestStop(); };
            var cancel = new Button("Cancel");

            cancel.Clicked += () => { Application.RequestStop(); };
            var d = new Dialog(title, 60, 20, ok, cancel);

            var lbl = new Label()
            {
                X    = 0,
                Y    = 1,
                Text = e.Table.Columns[e.Col].ColumnName
            };

            var tf = new TextField()
            {
                Text  = oldValue,
                X     = 0,
                Y     = 2,
                Width = Dim.Fill()
            };

            d.Add(lbl, tf);
            tf.SetFocus();

            Application.Run(d);

            if (okPressed)
            {
                try {
                    e.Table.Rows[e.Row][e.Col] = string.IsNullOrWhiteSpace(tf.Text.ToString()) ? DBNull.Value : (object)tf.Text;
                }
                catch (Exception ex) {
                    MessageBox.ErrorQuery(60, 20, "Failed to set text", ex.Message, "Ok");
                }

                tableView.Update();
            }
        }
Пример #31
0
		public void TorrentControl (int selected)
		{
			Dialog d = new Dialog (60, 8, "Torrent Control");

			TorrentManager item = items [selected];
			
			d.Add (new TrimLabel (1, 1, 60-6, item.Torrent.Name));

			bool stopped = item.State == TorrentState.Stopped;
			Button bstartstop = new Button (stopped ? "Start" : "Stop");
			bstartstop.Clicked += delegate {
				if (stopped)
					item.Start();
				else
					item.Stop();
				d.Running = false;
				
			};
			d.AddButton (bstartstop);
			
			// Later, when we hook it up, look up the state
			
			bool paused = item.State == TorrentState.Paused;
			Button br = new Button (paused ? "Resume" : "Pause");
			br.Clicked += delegate {
				if (paused)
					item.Start();
				else
					item.Pause();
				d.Running = false;
			};
			d.AddButton (br);

			Button bd = new Button ("Delete");
			bd.Clicked += delegate {
				Application.Error ("Not Implemented",
						   "I have not implemented delete yet");
				d.Running = false;
			};
			d.AddButton (bd);
			
			Button bmap = new Button ("Map");
			bmap.Clicked += delegate {
				Application.Error ("Not Implemented",
						   "I have not implemented map yet");
				d.Running = false;
			};
			d.AddButton (bmap);

			Button bcancel = new Button ("Cancel");
			bcancel.Clicked += delegate {
				d.Running = false;
			};
			Application.Run (d);
			UpdateStatus ();
		}
Пример #32
0
	static void OptionsDialog ()
	{
		Dialog d = new Dialog (62, 15, "Options");

		d.Add (new Label (1, 1, "  Download Directory:"));
		d.Add (new Label (1, 3, "         Listen Port:"));
		d.Add (new Label (1, 5, "  Upload Speed Limit:"));
		d.Add (new Label (35,5, "kB/s"));
		d.Add (new Label (1, 7, "Download Speed Limit:"));
		d.Add (new Label (35,7, "kB/s"));

		Entry download_dir = new Entry (24, 1, 30, config.DownloadDir);
		d.Add (download_dir);

		Entry listen_port = new Entry (24, 3, 6, config.ListenPort.ToString ());
		d.Add (listen_port);

		Entry upload_limit = new Entry (24, 5, 10, RenderSpeed (config.UploadSpeed / 1024));
		d.Add (upload_limit);

		Entry download_limit = new Entry (24, 7, 10, RenderSpeed (config.DownloadSpeed / 1024));
		d.Add (download_limit);
		
		bool ok = false;
		
		Button b = new Button ("Ok", true);
		b.Clicked += delegate { ok = true; b.Container.Running = false; };
		d.AddButton (b);

		b = new Button ("Cancel");
		b.Clicked += delegate { b.Container.Running = false; };
		d.AddButton (b);
		
		Application.Run (d);

		if (ok){
			int v;
			
			if (!Int32.TryParse (listen_port.Text, out v)){
				Application.Error ("Error", "The value `{0}' is not a valid port number", listen_port.Text);
				return;
			}

			if (!Directory.Exists (download_dir.Text)){
				Application.Error ("Error", "The directory\n{0}\ndoes not exist", download_dir.Text);
				return;
			}

			if (!ValidateSpeed (upload_limit, out config.UploadSpeed))
				return;

			if (!ValidateSpeed (download_limit, out config.DownloadSpeed))
				return;

			config.DownloadDir = download_dir.Text;
			config.ListenPort = v;

			// The user enters in kB/sec, the engine expects bytes/sec
			config.UploadSpeed *= 1024;
			config.DownloadSpeed *= 1024;
			TorrentCurses.engine.Settings.GlobalMaxUploadSpeed = config.UploadSpeed;
			TorrentCurses.engine.Settings.GlobalMaxDownloadSpeed = config.DownloadSpeed;
		}
	}
Пример #33
0
	static void AddDialog ()
	{
		int cols = (int) (Application.Cols * 0.7);
		Dialog d = new Dialog (cols, 8, "Add");
		Entry e;
		string name = null;
		
		
		d.Add (new Label (1, 0, "Torrent file:"));
		e = new Entry (1, 1, cols - 6, Environment.CurrentDirectory);
		d.Add (e);

		// buttons
		Button b = new Button ("Ok", true);
		b.Clicked += delegate {
			b.Container.Running = false;
			name = e.Text;
		};
		d.AddButton (b);
		b = new Button ("Cancel");
		b.Clicked += delegate {
			b.Container.Running = false;
		};
		d.AddButton (b);
		
		Application.Run (d);

		if (name != null){
			if (!File.Exists (name)){
				Application.Error ("Missing File", "Torrent file:\n" + name + "\ndoes not exist");
				return;
			}
			torrent_list.Add (name);
		}
	}