private void PopulateMenu() { DropDownItems.Clear(); if (EnableRepeatEffectMenuItem && LastEffect != null) { string repeatFormat = PdnResources.GetString("Effects.RepeatMenuItem.Format"); string menuName = string.Format(repeatFormat, LastEffect.Name); PdnMenuItem pmi = new PdnMenuItem(menuName, LastEffect.Image, RepeatEffectMenuItem_Click) { Name = "RepeatEffect(" + LastEffect.GetType().FullName + ")", ShortcutKeys = Keys.Control | Keys.F }; DropDownItems.Add(pmi); ToolStripSeparator tss = new ToolStripSeparator(); DropDownItems.Add(tss); } AddEffectsToMenu(); Triple <Assembly, Type, Exception>[] errors = Effects.GetLoaderExceptions(); for (int i = 0; i < errors.Length; ++i) { AppWorkspace.ReportEffectLoadError(errors[i]); } MenuPopulated = true; }
private void RepeatEffectMenuItem_Click(object sender, EventArgs e) { Exception exception = null; Effect effect = null; DocumentWorkspace activeDW = AppWorkspace.ActiveDocumentWorkspace; if (activeDW != null) { using (new PushNullToolMode(activeDW)) { Surface copy = activeDW.BorrowScratchSurface(GetType() + ".RepeatEffectMenuItem_Click() utilizing scratch for rendering"); try { using (new WaitCursorChanger(AppWorkspace)) { copy.CopySurface(((BitmapLayer)activeDW.ActiveLayer).Surface); } PdnRegion selectedRegion = activeDW.Selection.CreateRegion(); EffectEnvironmentParameters eep = new EffectEnvironmentParameters( AppWorkspace.AppEnvironment.PrimaryColor, AppWorkspace.AppEnvironment.SecondaryColor, AppWorkspace.AppEnvironment.PenInfo.Width, selectedRegion, copy); effect = (Effect)Activator.CreateInstance(LastEffect.GetType()); effect.EnvironmentParameters = eep; EffectConfigToken token = LastEffectToken == null ? null : (EffectConfigToken)LastEffectToken.Clone(); DoEffect(effect, token, selectedRegion, selectedRegion, copy, out exception); } finally { activeDW.ReturnScratchSurface(copy); } } } if (exception != null) { HandleEffectException(AppWorkspace, effect, exception); } }