private void mnuSetVariable_Click(object sender, EventArgs e)
        {
            var varName = InputBoxForm.GetStrInput("Name of variable:", "$base");

            if (!string.IsNullOrEmpty(varName) && varName.StartsWith("$"))
            {
                var val = InputBoxForm.GetStrInput("Value of variable:", "");
                if (!string.IsNullOrEmpty(val))
                {
                    this.m_variables[varName] = val;
                }
            }

            // Refresh UI
            this.listBoxConfigs_SelectedIndexChanged(null, null);
        }
Beispiel #2
0
        // ask user for string input.
        public static string GetStrInput(string mesage, string currentSuggestion = null,
                                         string[] more     = null,
                                         bool useClipboard = true, bool mustBeDirectory = false, bool taller = false)
        {
            using (InputBoxForm form = new InputBoxForm())
            {
                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,
                                                      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);
                }

                return(form._comboBox.Text);
            }
        }
        private void mnuSetDeletedPath_Click(object sender, EventArgs e)
        {
            var prevDir  = this.m_globalSettings.m_directoryForDeletedFiles ?? "c:\\";
            var sNewName = InputBoxForm.GetStrInput("Please enter a directory where manually deleted files will be moved, or enter no text to disable this feature:", prevDir);

            if (string.IsNullOrEmpty(sNewName))
            {
                return;
            }
            else if (!Directory.Exists(sNewName))
            {
                MessageBox.Show("Directory does not exist");
                return;
            }
            else
            {
                this.m_globalSettings.m_directoryForDeletedFiles = sNewName;
                RbcpyGlobalSettings.Serialize(this.m_globalSettings, "configs/globalconfig.xml");
            }
        }
        private void mnuSaveAs_Click(object sender, EventArgs e)
        {
            var currentName = GetCurrentConfigName();

            currentName = currentName != null ? "" : currentName;
            var sNewName = InputBoxForm.GetStrInput("Choose a name:", currentName);

            if (sNewName == null)
            {
                return;
            }
            if (sNewName.Contains("\\") || sNewName.Contains("/") || sNewName.Contains("."))
            {
                MessageBox.Show("Invalid character in name.");
                return;
            }

            var newFilename = "configs/" + sNewName + ".xml";

            if (File.Exists(newFilename))
            {
                MessageBox.Show("A configuration already exists with this name.");
                return;
            }

            SyncConfiguration.Serialize(this.GetCurrentConfigFromUI(), newFilename);
            this.CreateSyncMain_Load(null, null);

            var justName = Path.GetFileNameWithoutExtension(newFilename);

            foreach (var item in listBoxConfigs.Items)
            {
                if ((item as SavedConfigForListbox).m_filename == justName)
                {
                    listBoxConfigs.SelectedItem = item;
                    break;
                }
            }
        }