Exemple #1
0
        static void Main(string[] args)
        {
            Application.Init();
            var menu = new MenuBar(new MenuBarItem [] {
                new MenuBarItem("_File", new MenuItem [] {
                    new MenuItem("_New...", LocMan.Get("New CommonSecrets file..."), () =>
                    {
                        var createNew = NewFileDialog.CreateNewFileDialog(() => Application.RequestStop(), () => Application.RequestStop());
                        Application.Run(createNew);
                    }),
                    new MenuItem("_Open...", LocMan.Get("Open existing CommonSecrets file..."), () => OpenCommonSecretsFile()),
                    new MenuItem("_Save", "Save CommonSecrets file", () => {}),
                    new MenuItem("Save As...", "Save CommonSecrets file as...", () => SaveCommonSecretsFileAs()),
                    new MenuItem("_Close", "Close file", () => {}),
                    new MenuItem("_Quit", "Quit", () => {
                        Application.RequestStop();
                    })
                }),

                new MenuBarItem("_Edit", new MenuItem[] {
                }),

                new MenuBarItem("_Tools", new MenuItem[] {
                    new MenuItem("_Generate Random Password...", LocMan.Get("Generate a new random password...."), () =>
                    {
                        var createPasswordSelection = PasswordGeneratorDialog.CreateDialog(() => Application.RequestStop());
                        Application.Run(createPasswordSelection);
                    }),
                }),
            });

            var win = new Window("Hello")
            {
                X      = 0,
                Y      = 1,
                Width  = Dim.Fill(),
                Height = Dim.Fill() - 1
            };

            //LoginInformationsWindow.CreateLoginInformationsDialog(win);
            TabView tabView = new TabView()
            {
                X      = 0,
                Y      = 0,
                Width  = Dim.Fill(),
                Height = Dim.Fill(1)
            };

            tabView.AddTab(new TabView.Tab("Login informations", LoginInformationsView.CreateView()), true);
            tabView.AddTab(new TabView.Tab("Notes", new ListView()), false);
            tabView.AddTab(new TabView.Tab("Files", new ListView()), false);
            tabView.AddTab(new TabView.Tab("Contacts", new ListView()), false);
            tabView.AddTab(new TabView.Tab("Payment cards", new ListView()), false);
            win.Add(tabView);

            // Add both menu and win in a single call
            Application.Top.Add(menu, win);
            Application.Run();
        }
        public static Dialog CreateDialog(Action okAction)
        {
            PasswordGeneratorState state = new PasswordGeneratorState();

            var ok = new Button(3, 14, LocMan.Get("Ok"));

            ok.Clicked += () => { okAction.Invoke(); };

            var dialog = new Dialog(LocMan.Get("🎲 Random Password Generator"), 60, 20, ok);

            var passwordLengthLabel = new Label(1, 1, LocMan.Get("Password length:"));

            var positiveNumbersOnlyProvider = new TextRegexProvider("^[1-9]+[0-9]$")
            {
                ValidateOnInput = true
            };
            var passwordLengthTextField = new TextValidateField(positiveNumbersOnlyProvider)
            {
                X      = 1,
                Y      = 2,
                Width  = 4,
                Height = 1
            };

            passwordLengthTextField.Text = state.PasswordLength.ToString();


            var useUppercase = new CheckBox(1, 4, "Upper-case latin characters (e.g. A, C, K, Z)", state.IncludeUpperCaseLatinLetters);

            useUppercase.Toggled += (bool old) => { state.IncludeUpperCaseLatinLetters = !old; };

            var useLowercase = new CheckBox(1, 5, "Lower-case latin characters (e.g. a, c, k, z)", state.IncludeLowerCaseLatinLetters);

            useLowercase.Toggled += (bool old) => { state.IncludeLowerCaseLatinLetters = !old; };

            var useDigits = new CheckBox(1, 6, "Digits (e.g. 4, 6, 9)", state.IncludeDigits);

            useDigits.Toggled += (bool old) => { state.IncludeDigits = !old; };

            var useSpecialASCII = new CheckBox(1, 7, "Special characters ASCII", state.IncludeSpecialCharactersASCII);

            useSpecialASCII.Toggled += (bool old) => { state.IncludeSpecialCharactersASCII = !old; };

            var useBasicEmojis = new CheckBox(1, 8, "Basic emoji (e.g. 😊)", state.IncludeEmojis);

            useBasicEmojis.Toggled += (bool old) => { state.IncludeEmojis = !old; };


            var generatedPasswordLabel = new Label(1, 10, LocMan.Get("Generated password:"******"")
            {
                ReadOnly = true,
                X        = 1,
                Y        = 11,
                Width    = Dim.Fill(),
                Height   = 1
            };


            var copyToClipboardButton = new Button(3, 12, LocMan.Get("Copy to Clipboard"));

            var generateButton = new Button(25, 12, LocMan.Get("Generate"));

            generateButton.Clicked += () => { GenerateRandomPassword(state); generatedPasswordField.Text = state.GeneratedPassword; };

            dialog.Add(passwordLengthLabel, passwordLengthTextField, useUppercase, useLowercase, useDigits, useSpecialASCII, useBasicEmojis, generatedPasswordLabel, generatedPasswordField, copyToClipboardButton, generateButton);

            return(dialog);
        }
        public static Dialog CreateNewFileDialog(Action okAction, Action cancelAction)
        {
            var ok = new Button(3, 14, LocMan.Get("Ok"));

            ok.Clicked += () => { okAction.Invoke(); };

            var cancel = new Button(10, 14, LocMan.Get("Cancel"));

            cancel.Clicked += () => { cancelAction.Invoke(); };

            var dialog = new Dialog(LocMan.Get("Pbkdf2 settings"), 60, 20, ok, cancel);


            var enterPasswordLabel = new Label(1, 1, LocMan.Get("Enter password:"******"")
            {
                Secret = true,
                X      = 1,
                Y      = 2,
                Width  = Dim.Fill(),
                Height = 1
            };


            var confirmPasswordLabel = new Label(1, 4, LocMan.Get("Confirm password:"******"")
            {
                Secret = true,
                X      = 1,
                Y      = 5,
                Width  = Dim.Fill(),
                Height = 1
            };


            var prfLabel = new Label(1, 7, LocMan.Get("Pseudo-Random Function:"));

            var prfRadioSelection = new RadioGroup(1, 8, prfArray);


            var iterationsLabel = new Label(1, 11, LocMan.Get("How many iterations:"));

            var positiveNumbersOnlyProvider = new TextRegexProvider("^[1-9]+[0-9]*$")
            {
                ValidateOnInput = true
            };
            var iterationsAmount = new TextValidateField(positiveNumbersOnlyProvider)
            {
                X      = 1,
                Y      = 12,
                Width  = Dim.Fill(),
                Height = 1
            };

            iterationsAmount.Text = suggestedIterations.ToString();


            dialog.Add(enterPasswordLabel, passwordFirstTime, confirmPasswordLabel, passwordSecondTime, prfLabel, prfRadioSelection, iterationsLabel, iterationsAmount);

            return(dialog);
        }