예제 #1
0
        /// <summary>
        /// Renames selected set of options (including file)
        /// </summary>
        private void btnRename_Click(object sender, EventArgs e)
        {
            string name; SymbologyType type;

            if (!get_CurrentNameAndType(out name, out type))
            {
                return;
            }

            if (type == SymbologyType.Default)
            {
                return;
            }

            string newName = name;

            var form = new AddOptionsForm
            {
                Text           = "Rename options",
                txtName        = { Text = newName },
                txtDescription = { Text = txtDescription.Text }
            };

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                newName             = form.txtName.Text.Trim();
                txtDescription.Text = form.txtDescription.Text;

                try
                {
                    string oldFileame = _layer.Filename + "." + name + ".mwsymb";
                    File.Delete(oldFileame);

                    var map = _legend.Map;
                    map.Layers[0].SaveOptions(newName, true, txtDescription.Text);
                }
                catch
                {
                    MessageService.Current.Warn("Failed to rename file");
                    return;
                }

                // updating the list
                listView1.SelectedItems[0].Text = newName;
            }
            form.Dispose();
        }
예제 #2
0
        /// <summary>
        /// Saves the current state of the layer
        /// </summary>
        private void btnSave_Click(object sender, EventArgs e)
        {
            var form = new AddOptionsForm {
                txtName = { Text = "" }, txtDescription = { Text = "" }
            };

            if (form.ShowDialog(this) == DialogResult.OK)
            {
                string value = form.txtName.Text;
                txtDescription.Text = form.txtDescription.Text;

                if (listView1.Items.Count == 0)
                {
                    LoadLayer();
                }

                // in case file exists, let's ask the user if we are to overwrite it
                string name = _layer.Filename + "." + value + ".mwsymb";
                if (File.Exists(name))
                {
                    if (!MessageService.Current.Ask("Set of options with such name already exists." + Environment.NewLine + "Do you want to rewrite it?"))
                    {
                        return;
                    }
                }

                var map = _legend.Map;
                map.GetLayer(_handle).SaveOptions(value, true, txtDescription.Text);

                // updating the list
                listView1.FillSymbologyList(_layer.Filename, true, ref _noEvents);
                dgv_CurrentCellChanged(null, null);

                RefreshControlsState();
            }
            form.Dispose();
        }