private void btnEditComponent_Click(object sender, EventArgs e) { var it = lstInstances.SelectedItems[0]; ISymbolInstance symRef = (ISymbolInstance)it.Tag; var c = CreateSymbolDefinitionEditor(symRef); c.Dock = DockStyle.Fill; using (var ed = new EditorTemplateForm()) { ed.Text = Strings.EditSymbolDefinition; ed.ItemPanel.Controls.Add(c); ed.ManualSizeManagement = true; ed.Width = 800; ed.Height = 600; if (ed.ShowDialog() == System.Windows.Forms.DialogResult.OK) { _edSvc.HasChanged(); } } }
private void EditButton_Click(object sender, EventArgs e) { UserControl uc = null; if (m_owner.SelectedClass == null) { MessageBox.Show(Strings.NoFeatureClassAssigned); return; } ILayerStylePreviewable prev = new LayerStylePreviewable(m_owner.EditorService.EditedResourceID, this.PreviewScale, 80, 40, "PNG", //NOXLATE this.ThemeCategory); //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be //easy to understand. Each primitive basic style (that's not a label) has 3 actions. // - Commit (When user clicks OK on dialog) // - Rollback (When user clicks Cancel on dialog) // - Edit Commit (When user invokes refresh) //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes //to be reflected when we do the GETLEGENDIMAGE call // //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API var factory = (ILayerElementFactory)m_owner.Editor.GetEditedResource(); Action commit = null; Action rollback = null; if (isLabel) { m_origLabel = m_label; m_editLabel = (m_label == null) ? null : (ITextSymbol)m_label.Clone(); uc = new FontStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId); ((FontStyleEditor)uc).Item = m_editLabel; } else if (isW2dSymbol) { m_origPoint = m_point; m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone(); var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, m_w2dsymbol, prev); uc = pfse; pfse.Item = m_editPoint; Action editCommit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_editPoint = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_editPoint; m_w2dsymbol = w2d; }; pfse.SetEditCommit(editCommit); commit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_point = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_point; m_w2dsymbol = w2d; }; rollback = () => { ((IPointRule)m_parent).PointSymbolization2D = m_origPoint; }; } else if (isPoint) { m_origPoint = m_point; m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone(); var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev); uc = pfse; pfse.Item = m_editPoint; Action editCommit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_editPoint = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_editPoint; m_w2dsymbol = w2d; }; pfse.SetEditCommit(editCommit); commit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_point = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_point; m_w2dsymbol = w2d; }; rollback = () => { ((IPointRule)m_parent).PointSymbolization2D = m_origPoint; }; } else if (isLine) { m_origLine = m_line; m_editLine = (m_line == null) ? new List<IStroke>() : LayerElementCloningUtil.CloneStrokes(m_line); var lfse = new LineFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, factory, prev); uc = lfse; lfse.Item = m_editLine; Action editCommit = () => { m_editLine = lfse.Item; ((ILineRule)m_parent).SetStrokes(m_editLine); }; lfse.SetEditCommit(editCommit); commit = () => { m_line = lfse.Item; ((ILineRule)m_parent).SetStrokes(m_line); }; rollback = () => { ((ILineRule)m_parent).SetStrokes(m_origLine); }; } else if (isArea) { m_origArea = m_area; m_editArea = (m_area == null) ? null : (IAreaSymbolizationFill)m_area.Clone(); var afse = new AreaFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev); uc = afse; afse.Item = m_editArea; Action editCommit = () => { m_editArea = afse.Item; ((IAreaRule)m_parent).AreaSymbolization2D = m_editArea; }; commit = () => { m_area = afse.Item; ((IAreaRule)m_parent).AreaSymbolization2D = m_area; }; rollback = () => { ((IAreaRule)m_parent).AreaSymbolization2D = m_origArea; }; afse.SetEditCommit(editCommit); } else if (isComp) { var diag = new SymbolInstancesDialog(m_owner.Editor, m_comp, m_owner.SelectedClass, m_owner.GetFdoProvider(), m_owner.FeatureSourceId, prev); diag.ShowDialog(); //HACK: Assume edits made Owner.RaiseResourceChanged(); return; } if (uc != null) { EditorTemplateForm dlg = new EditorTemplateForm(); dlg.ItemPanel.Controls.Add(uc); uc.Dock = DockStyle.Fill; dlg.RefreshSize(); var res = dlg.ShowDialog(this); if (res == DialogResult.OK) { if (commit != null) { commit.Invoke(); } if (isLabel) { m_label = ((FontStyleEditor)uc).Item; if (m_parent as IPointRule != null) ((IPointRule)m_parent).Label = m_label; else if (m_parent as ILineRule != null) ((ILineRule)m_parent).Label = m_label; else if (m_parent as IAreaRule != null) ((IAreaRule)m_parent).Label = m_label; if (ItemChanged != null) ItemChanged(m_label, null); } else if (isPoint || isW2dSymbol) { if (ItemChanged != null) ItemChanged(m_point, null); } else if (isLine) { if (ItemChanged != null) ItemChanged(m_line, null); } else if (isArea) { if (ItemChanged != null) ItemChanged(m_area, null); } this.Refresh(); } else if (res == DialogResult.Cancel) { if (rollback != null) rollback.Invoke(); } } }
private void EditButton_Click(object sender, EventArgs e) { UserControl uc = null; if (m_owner.SelectedClass == null) { MessageBox.Show(Strings.NoFeatureClassAssigned); return; } ILayerStylePreviewable prev = new LayerStylePreviewable(m_owner.EditorService.EditedResourceID, this.PreviewScale, 80, 40, "PNG", //NOXLATE _themeOffset + this.ThemeCategory); //TODO: This is obviously a mess and could do with some future cleanup, but the idea here should be //easy to understand. Each primitive basic style (that's not a label) has 3 actions. // - Commit (When user clicks OK on dialog) // - Rollback (When user clicks Cancel on dialog) // - Edit Commit (When user invokes refresh) //Those that support GETLEGENDIMAGE-based previews will be passed an edit commit action. Invoking the //edit commit action will update the session-based layer with this edit-copy rule, allowing for the changes //to be reflected when we do the GETLEGENDIMAGE call // //Labels are exempt as those previews can be sufficiently simulated with System.Drawing API var factory = (ILayerElementFactory)m_owner.Editor.GetEditedResource(); Action commit = null; Action rollback = null; if (isLabel) { m_origLabel = m_label; m_editLabel = (m_label == null) ? null : (ITextSymbol)m_label.Clone(); uc = new FontStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId); ((FontStyleEditor)uc).Item = m_editLabel; } else if (isW2dSymbol) { m_origPoint = m_point; m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone(); var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, m_w2dsymbol, prev); uc = pfse; pfse.Item = m_editPoint; Action editCommit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_editPoint = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_editPoint; m_w2dsymbol = w2d; }; pfse.SetEditCommit(editCommit); commit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_point = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_point; m_w2dsymbol = w2d; }; rollback = () => { ((IPointRule)m_parent).PointSymbolization2D = m_origPoint; }; } else if (isPoint) { m_origPoint = m_point; m_editPoint = (m_point == null) ? null : (IPointSymbolization2D)m_point.Clone(); var pfse = new PointFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev); uc = pfse; pfse.Item = m_editPoint; Action editCommit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_editPoint = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_editPoint; m_w2dsymbol = w2d; }; pfse.SetEditCommit(editCommit); commit = () => { //We need to update this boolean state var w2d = pfse.W2DSymbolPreviewImage; this.isPoint = (w2d == null); this.isW2dSymbol = (w2d != null); m_point = pfse.Item; ((IPointRule)m_parent).PointSymbolization2D = m_point; m_w2dsymbol = w2d; }; rollback = () => { ((IPointRule)m_parent).PointSymbolization2D = m_origPoint; }; } else if (isLine) { m_origLine = m_line; m_editLine = (m_line == null) ? new List <IStroke>() : LayerElementCloningUtil.CloneStrokes(m_line); var lfse = new LineFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, factory, prev); uc = lfse; lfse.Item = m_editLine; Action editCommit = () => { m_editLine = lfse.Item; ((ILineRule)m_parent).SetStrokes(m_editLine); }; lfse.SetEditCommit(editCommit); commit = () => { m_line = lfse.Item; ((ILineRule)m_parent).SetStrokes(m_line); }; rollback = () => { ((ILineRule)m_parent).SetStrokes(m_origLine); }; } else if (isArea) { m_origArea = m_area; m_editArea = (m_area == null) ? null : (IAreaSymbolizationFill)m_area.Clone(); var afse = new AreaFeatureStyleEditor(m_owner.Editor, m_owner.SelectedClass, m_owner.FeatureSourceId, prev); uc = afse; afse.Item = m_editArea; Action editCommit = () => { m_editArea = afse.Item; ((IAreaRule)m_parent).AreaSymbolization2D = m_editArea; }; commit = () => { m_area = afse.Item; ((IAreaRule)m_parent).AreaSymbolization2D = m_area; }; rollback = () => { ((IAreaRule)m_parent).AreaSymbolization2D = m_origArea; }; afse.SetEditCommit(editCommit); } else if (isComp) { var diag = new SymbolInstancesDialog(m_owner.Editor, m_comp, m_owner.SelectedClass, m_owner.GetFdoProvider(), m_owner.FeatureSourceId, prev); diag.ShowDialog(); //HACK: Assume edits made Owner.RaiseResourceChanged(); return; } if (uc != null) { EditorTemplateForm dlg = new EditorTemplateForm(); dlg.ItemPanel.Controls.Add(uc); uc.Dock = DockStyle.Fill; dlg.RefreshSize(); var res = dlg.ShowDialog(this); if (res == DialogResult.OK) { if (commit != null) { commit.Invoke(); } if (isLabel) { m_label = ((FontStyleEditor)uc).Item; if (m_parent as IPointRule != null) { ((IPointRule)m_parent).Label = m_label; } else if (m_parent as ILineRule != null) { ((ILineRule)m_parent).Label = m_label; } else if (m_parent as IAreaRule != null) { ((IAreaRule)m_parent).Label = m_label; } ItemChanged?.Invoke(m_label, null); } else if (isPoint || isW2dSymbol) { ItemChanged?.Invoke(m_point, null); } else if (isLine) { ItemChanged?.Invoke(m_line, null); } else if (isArea) { ItemChanged?.Invoke(m_area, null); } this.Refresh(); } else if (res == DialogResult.Cancel) { if (rollback != null) { rollback.Invoke(); } } } }