/// <summary> /// Applies the selected options and closes the form /// </summary> private void btnApply_Click(object sender, EventArgs e) { string name; SymbologyType type; if (!get_CurrentNameAndType(out name, out type)) { return; } if (type == SymbologyType.Default) { name = ""; } MapWinGIS.Map map = m_legend.Map; if (map != null) { int handle = m_layer.Handle; string description = ""; if (map.LoadLayerOptions(handle, name, ref description)) { m_legend.Map.Redraw(); m_legend.Refresh(); } else { Globals.MessageBoxError("Error while loading options"); } } }
/// <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; frmAddOptions form = new frmAddOptions(); form.Text = "Rename options"; form.txtName.Text = newName; form.txtDescription.Text = this.txtDescription.Text; if (form.ShowDialog(this) == DialogResult.OK) { newName = form.txtName.Text.Trim(); this.txtDescription.Text = form.txtDescription.Text; try { string oldFileame = m_layer.FileName + "." + name + ".mwsymb"; System.IO.File.Delete(oldFileame); MapWinGIS.Map map = m_legend.Map; map.SaveLayerOptions(map.get_LayerHandle(0), newName, true, txtDescription.Text); } catch { Globals.MessageBoxError("Failed to rename file"); return; } // updating the list listView1.SelectedItems[0].Text = newName; } form.Dispose(); }
/// <summary> /// Removes all the available options for the layer /// </summary> private void btnClear_Click(object sender, EventArgs e) { if (listView1.Items.Count == 0) { return; } MapWinGIS.Map map = m_legend.Map; if (map != null) { if (MessageBox.Show("Do you want to remove all option sets for the layer?", LegendControl.Legend.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { int errorCount = 0; for (int row = 0; row < listView1.Items.Count; row++) { string name = listView1.Items[row].ToString(); SymbologyType type = (SymbologyType)listView1.Items[row].Tag; if (type == SymbologyType.Default) { name = ""; } if (!map.RemoveLayerOptions(m_layer.Handle, name)) { errorCount++; } } // redrawing Globals.FillSymbologyList(listView1, m_layer.FileName, true, ref m_noEvents); dgv_CurrentCellChanged(null, null); if (errorCount > 0) { Globals.MessageBoxError("Failed to remove options: " + errorCount + Environment.NewLine + "Reason: " + map.get_ErrorMsg(map.LastErrorCode)); } } } RefreshControlsState(); }
/// <summary> /// Saves the current state of the layer /// </summary> private void btnSave_Click(object sender, EventArgs e) { frmAddOptions form = new frmAddOptions(); // some values can be set there form.txtName.Text = ""; form.txtDescription.Text = ""; if (form.ShowDialog(this) == DialogResult.OK) { string value = form.txtName.Text; txtDescription.Text = form.txtDescription.Text; if (listView1.Items.Count == 0) { this.LoadLayer(); } // in case file exists, let's ask the user if we are to overwrite it string name = m_layer.FileName + "." + value + ".mwsymb"; if (System.IO.File.Exists(name)) { if (MessageBox.Show("Set of options with such name already exists." + Environment.NewLine + "Do you want to rewrite it?", LegendControl.Legend.AppName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) { return; } } MapWinGIS.Map map = m_legend.Map; map.SaveLayerOptions(m_handle, value, true, txtDescription.Text); // updating the list Globals.FillSymbologyList(listView1, m_layer.FileName, true, ref m_noEvents); dgv_CurrentCellChanged(null, null); RefreshControlsState(); } form.Dispose(); }
/// <summary> /// Applies a given set of options to the layer /// </summary> private void btnOk_Click(object sender, EventArgs e) { MapWinGIS.Map map = m_legend.Map; if (map != null) { if (listView1.SelectedItems.Count > 0) { if (listView1.SelectedItems[0].Index > 0) // otherwise that's random options { int row = listView1.SelectedItems[0].Index; string name = listView1.SelectedItems[0].Text; SymbologyType type = (SymbologyType)listView1.SelectedItems[0].Tag; if (type == SymbologyType.Default) { name = ""; } string description = ""; bool res = map.LoadLayerOptions(m_handle, name, ref description); } } } }