// add MRU history, suggestions, and clipboard contents to the list of examples.
        public static IEnumerable <string> GetInputSuggestions(string currentSuggestion,
                                                               InputBoxHistory historyKey, PersistMostRecentlyUsedList history,
                                                               bool useClipboard, bool mustBeDirectory, string[] more)
        {
            List <string> suggestions = new List <string>();

            if (!string.IsNullOrEmpty(currentSuggestion))
            {
                suggestions.Add(currentSuggestion);
            }

            if (useClipboard && !string.IsNullOrEmpty(Utils.GetClipboard()) &&
                Utils.LooksLikePath(Utils.GetClipboard()) == mustBeDirectory)
            {
                // get from clipboard if the right type of string (path vs not path)
                suggestions.Add(Utils.GetClipboard());
            }

            if (historyKey != InputBoxHistory.None)
            {
                suggestions.AddRange(history.Get());
            }

            if (more != null)
            {
                suggestions.AddRange(more);
            }

            return(suggestions.Where(entry => !mustBeDirectory ||
                                     FilenameUtils.IsPathRooted(entry)));
        }
示例#2
0
        void OpenForm(ModeBase mode, InputBoxHistory mruKey)
        {
            var directory = AskUserForDirectory(mruKey);

            if (directory == null)
            {
                return;
            }

            ShowForm(new FormGallery(mode, directory));
        }
        public InputBoxForm(InputBoxHistory currentKey)
        {
            InitializeComponent();
            _mru = new PersistMostRecentlyUsedList(currentKey);
            this.StartPosition = FormStartPosition.CenterParent;
            this.Text          = " ";
            this.AllowDrop     = true;
            this._comboBox.Focus();

            // we don't use autocomplete, we just enable it
            // to get the Ctrl+Backspace shortcut
            this._comboBox.AutoCompleteMode = AutoCompleteMode.Append;
        }
示例#4
0
        private void doCustomEncode(string example, InputBoxHistory key)
        {
            var files = this.GetInputFiles(1);
            var cmd   = InputBoxForm.GetStrInput("Command for the ffmpeg encoder:", example,
                                                 key);

            if (String.IsNullOrEmpty(cmd))
            {
                return;
            }
            else if (!cmd.Contains("%in%") && !Utils.AskToConfirm("Did not see '%in%', " +
                                                                  "won't process input files. Continue?"))
            {
                return;
            }

            if (!Utils.AskToConfirm("Run the command right now? (or copy the command line to the clipboard)"))
            {
                var s = "";
                foreach (var file in files)
                {
                    s += "\r\n\"" + CsDownloadVidFilepaths.GetFfmpeg() + "\" ";
                    s += cmd.Replace("%in%", files[0]);
                }

                Clipboard.SetText(s);
                MessageBox.Show("Command was copied to the clipboard.");
                return;
            }

            RunToolHelper.RunAndCatch(() =>
            {
                var infos = new List <ProcessStartInfo>();
                foreach (var file in files)
                {
                    var info                    = new ProcessStartInfo();
                    info.FileName               = CsDownloadVidFilepaths.GetFfmpeg();
                    info.Arguments              = cmd.Replace("%in%", file);
                    info.CreateNoWindow         = true;
                    info.RedirectStandardError  = true;
                    info.RedirectStandardOutput = true;
                    info.UseShellExecute        = false;
                    infos.Add(info);
                }

                _runner.RunProcesses(infos.ToArray(), "Custom encode");
            });
        }
        // ask user for string input.
        public static string GetStrInput(string mesage, string currentSuggestion = null,
                                         InputBoxHistory historyKey = InputBoxHistory.None, string[] more = null,
                                         bool useClipboard          = true, bool mustBeDirectory = false, bool taller = false)
        {
            using (InputBoxForm form = new InputBoxForm(historyKey))
            {
                form._label.Text        = mesage;
                form._btnBrowse.Visible = mustBeDirectory;
                form._btnBrowse.Click  += (o, e) => form.OnBrowseClick();
                if (taller)
                {
                    form._comboBox.Top  += form.Height - 40;
                    form._btnOK.Top     += form.Height - 40;
                    form._btnCancel.Top += form.Height - 40;
                    form._label.Height  += form.Height - 40;
                    form.Height         *= 2;
                }

                // fill combo box with suggested input.
                form._comboBox.Items.Clear();
                var suggestions = GetInputSuggestions(currentSuggestion, historyKey, form._mru,
                                                      useClipboard, mustBeDirectory, more).ToArray();

                foreach (var s in suggestions)
                {
                    form._comboBox.Items.Add(s);
                }

                form._comboBox.Text = suggestions.Length > 0 ? suggestions[0] : "";
                form.ShowDialog();
                if (form.DialogResult != DialogResult.OK)
                {
                    return(null);
                }

                if (mustBeDirectory && !Directory.Exists(form._comboBox.Text))
                {
                    Utils.MessageBox("Directory does not exist");
                    return(null);
                }

                // save to history
                form._mru.AddToHistory(form._comboBox.Text);
                return(form._comboBox.Text);
            }
        }
        public static int?GetInteger(string message, int defaultInt = 0,
                                     InputBoxHistory historyKey     = InputBoxHistory.None)
        {
            int    fromClipboard        = 0;
            var    clipboardContainsInt = int.TryParse(Utils.GetClipboard(), out fromClipboard);
            string s = GetStrInput(message, defaultInt.ToString(), historyKey,
                                   useClipboard: clipboardContainsInt);

            if (string.IsNullOrEmpty(s) || !int.TryParse(s, out int result))
            {
                return(null);
            }
            else
            {
                return(result);
            }
        }
        public PersistMostRecentlyUsedList(InputBoxHistory historyKey,
                                           Configs configs = null, int maxHistoryEntries = 50)
        {
            _historyKey        = historyKey;
            _configs           = configs ?? Configs.Current;
            _maxHistoryEntries = maxHistoryEntries;
            _maxEntryLength    = 300;

            // find the corresponding ConfigKey for this InputBoxHistory
            if (_historyKey != InputBoxHistory.None)
            {
                if (!Enum.TryParse("MRU" + _historyKey.ToString(), out _configsKey))
                {
                    throw new CsDownloadVidException(
                              "unknown history key" + _historyKey.ToString());
                }
            }
        }
示例#8
0
 static string AskUserForDirectory(InputBoxHistory mruKey)
 {
     return(InputBoxForm.GetStrInput(
                "Enter directory:", null, mruKey, mustBeDirectory: true));
 }