public void OpenScript(NWN2GameScript script) { if (script == null) { throw new ArgumentNullException("script"); } LaunchFlip(); if (window.AskWhetherToSaveCurrentScript() == MessageBoxResult.Cancel) { return; } script.Demand(); try { FlipScript flipScript = scriptHelper.GetFlipScript(script, Attachment.Ignore); if (flipScript == null) { throw new InvalidOperationException("Script could not be understood as a Flip script."); } TriggerControl trigger; try { trigger = scriptHelper.GetTrigger(script); } catch (ArgumentException) { trigger = null; } ScriptTriggerTuple tuple = new ScriptTriggerTuple(flipScript, trigger); window.OpenFlipScript(tuple); //ActivityLog.Write(new Activity("OpenedScript","ScriptName",script.Name,"Event",triggerTextForLog)); if (trigger != null) { Log.WriteAction(LogAction.opened, "script", script.Name + " (attached to '" + trigger.GetLogText() + "')"); } else { Log.WriteAction(LogAction.opened, "script", script.Name); } } catch (Exception x) { throw new ApplicationException("Failed to open script '" + script.Name + "'.", x); } }
protected void OpenSelectedScript() { TriggerControl t = scriptsListBox.SelectedItem as TriggerControl; if (t == null) { MessageBox.Show("Select a script to open."); } else { // HACK // Should actually be adding ScriptTriggerTuple directly // to the ListBox and representing it with a DataTemplate // so that only the TriggerControl is displayed, but // that's too finicky to get into just now, so add the // TriggerControl directly and search for the ScriptSlotTuple // that possesses it. selected = GetOwner(t); try { if (selected.Trigger is BlankTrigger) { selected.Trigger = null; } window.OpenFlipScript(selected.DeepCopy()); if (selected.Trigger != null) { Log.WriteAction(LogAction.opened, "script", selected.Script.Name + " (attached to '" + selected.Trigger.GetLogText() + "')"); } else { Log.WriteAction(LogAction.opened, "script", selected.Script.Name); } Close(); } catch (Exception x) { MessageBox.Show("Something went wrong when opening script.\n" + x); } } }