btnEnableAllNotifications_Click ( object sender, EventArgs e ) { AssertValid(); NotificationUserSettings oNotificationUserSettings = new NotificationUserSettings(); oNotificationUserSettings.EnableAllNotifications(); oNotificationUserSettings.Save(); }
//************************************************************************* // Method: AutomateThisWorkbook() // /// <summary> /// Runs a specified set of tasks on one NodeXL workbook. /// </summary> /// /// <param name="thisWorkbook"> /// The NodeXL workbook to run the tasks on. /// </param> /// /// <param name="tasksToRun"> /// The tasks to run, as an ORed combination of <see /// cref="AutomationTasks" /> flags. /// </param> /// /// <param name="ribbon"> /// The workbook's Ribbon. /// </param> //************************************************************************* public static void AutomateThisWorkbook( ThisWorkbook thisWorkbook, AutomationTasks tasksToRun, Ribbon ribbon ) { Debug.Assert(thisWorkbook != null); Debug.Assert(ribbon != null); Microsoft.Office.Interop.Excel.Workbook oWorkbook = thisWorkbook.InnerObject; if ( (tasksToRun & AutomationTasks.MergeDuplicateEdges) != 0 ) { // In general, automation is best performed by simulating a click // of a Ribbon button, thus avoiding any duplicate code. if ( !ribbon.OnMergeDuplicateEdgesClick(false) ) { return; } } if ( (tasksToRun & AutomationTasks.CalculateGraphMetrics) != 0 ) { // In this case, clicking the corresponding Ribbon button opens a // GraphMetricsDialog, which allows the user to edit the graph // metric settings before calculating the graph metrics. The // actual calculations are done by CalculateGraphMetricsDialog, so // just use that dialog directly. CalculateGraphMetricsDialog oCalculateGraphMetricsDialog = new CalculateGraphMetricsDialog( oWorkbook, new GraphMetricUserSettings() ); if (oCalculateGraphMetricsDialog.ShowDialog() != DialogResult.OK) { return; } } if ( (tasksToRun & AutomationTasks.AutoFillWorkbook) != 0 ) { // In this case, clicking the corresponding Ribbon button opens an // AutoFillWorkbookDialog, which allows the user to edit the // autofill settings before autofilling the workbook. The actual // autofilling is done by WorkbookAutoFiller, so just use that // class directly. try { WorkbookAutoFiller.AutoFillWorkbook( oWorkbook, new AutoFillUserSettings(oWorkbook) ); ribbon.OnWorkbookAutoFilled(false); } catch (Exception oException) { ErrorUtil.OnException(oException); return; } } if ( (tasksToRun & AutomationTasks.CreateSubgraphImages) != 0 ) { ribbon.OnCreateSubgraphImagesClick( CreateSubgraphImagesDialog.DialogMode.Automate); } if ( (tasksToRun & AutomationTasks.CalculateClusters) != 0 ) { if ( !ribbon.OnCalculateClustersClick() ) { return; } } if ( (tasksToRun & AutomationTasks.ReadWorkbook) != 0 ) { // If the vertex X and Y columns were autofilled, the layout type // was set to LayoutType.Null. This will cause // TaskPane.ReadWorkbook() to display a warning. Temporarily turn // the warning off. NotificationUserSettings oNotificationUserSettings = new NotificationUserSettings(); Boolean bOldLayoutTypeIsNull = oNotificationUserSettings.LayoutTypeIsNull; oNotificationUserSettings.LayoutTypeIsNull = false; oNotificationUserSettings.Save(); if ( (tasksToRun & AutomationTasks.SaveGraphImageFile) != 0 ) { if ( String.IsNullOrEmpty(thisWorkbook.Path) ) { throw new InvalidOperationException( WorkbookNotSavedMessage); } // After the workbook is read and the graph is laid out, save // an image of the graph to a file. GraphLaidOutEventHandler oGraphLaidOutEventHandler = null; oGraphLaidOutEventHandler = delegate(Object sender, GraphLaidOutEventArgs e) { // This delegate remains forever, even when the dialog // class is destroyed. Prevent it from being called again. thisWorkbook.GraphLaidOut -= oGraphLaidOutEventHandler; SaveGraphImageFile(e.NodeXLControl, thisWorkbook.FullName); }; thisWorkbook.GraphLaidOut += oGraphLaidOutEventHandler; } ribbon.OnReadWorkbookClick(); oNotificationUserSettings.LayoutTypeIsNull = bOldLayoutTypeIsNull; oNotificationUserSettings.Save(); } }
//************************************************************************* // Method: ShowLayoutTypeIsNullNotification() // /// <summary> /// Notifies the user that the layout is LayoutType.Null. /// </summary> /// /// <returns> /// true if the user wants to read the workbook even though the layout is /// LayoutType.Null, false if he wants to cancel. /// </returns> /// /// <remarks> /// Call this when the user attempts to read the workbook when the layout /// is LayoutType.Null. /// </remarks> //************************************************************************* protected Boolean ShowLayoutTypeIsNullNotification() { AssertValid(); NotificationUserSettings oNotificationUserSettings = new NotificationUserSettings(); if (!oNotificationUserSettings.LayoutTypeIsNull) { // The user doesn't want to be notified. return (true); } Boolean bReturn = true; const String Message = "The Layout is set to None. If the graph has never been laid" + " out, all the vertices will be placed at the upper-left corner" + " of the graph pane." + "\r\n\r\n" + "If you want to lay out the graph, click No and select a" + " different Layout. " + HowToSetLayoutType + "\r\n\r\n" + "Do you want to read the workbook?" ; NotificationDialog oNotificationDialog = new NotificationDialog( "Layout is None", SystemIcons.Warning, Message); if (oNotificationDialog.ShowDialog() != DialogResult.Yes) { bReturn = false; } if (oNotificationDialog.DisableFutureNotifications) { oNotificationUserSettings.LayoutTypeIsNull = false; oNotificationUserSettings.Save(); } return (bReturn); }
AutomateThisWorkbook ( ThisWorkbook thisWorkbook, AutomationTasks tasksToRun, Ribbon ribbon ) { Debug.Assert(thisWorkbook != null); Debug.Assert(ribbon != null); Microsoft.Office.Interop.Excel.Workbook oWorkbook = thisWorkbook.InnerObject; if ((tasksToRun & AutomationTasks.MergeDuplicateEdges) != 0) { // In general, automation is best performed by simulating a click // of a Ribbon button, thus avoiding any duplicate code. if (!ribbon.OnMergeDuplicateEdgesClick(false)) { return; } } if ((tasksToRun & AutomationTasks.CalculateGraphMetrics) != 0) { // In this case, clicking the corresponding Ribbon button opens a // GraphMetricsDialog, which allows the user to edit the graph // metric settings before calculating the graph metrics. The // actual calculations are done by CalculateGraphMetricsDialog, so // just use that dialog directly. CalculateGraphMetricsDialog oCalculateGraphMetricsDialog = new CalculateGraphMetricsDialog(oWorkbook, new GraphMetricUserSettings()); if (oCalculateGraphMetricsDialog.ShowDialog() != DialogResult.OK) { return; } } if ((tasksToRun & AutomationTasks.AutoFillWorkbook) != 0) { // In this case, clicking the corresponding Ribbon button opens an // AutoFillWorkbookDialog, which allows the user to edit the // autofill settings before autofilling the workbook. The actual // autofilling is done by WorkbookAutoFiller, so just use that // class directly. try { WorkbookAutoFiller.AutoFillWorkbook( oWorkbook, new AutoFillUserSettings(oWorkbook)); ribbon.OnWorkbookAutoFilled(false); } catch (Exception oException) { ErrorUtil.OnException(oException); return; } } if ((tasksToRun & AutomationTasks.CreateSubgraphImages) != 0) { ribbon.OnCreateSubgraphImagesClick( CreateSubgraphImagesDialog.DialogMode.Automate); } if ((tasksToRun & AutomationTasks.CalculateClusters) != 0) { if (!ribbon.OnCalculateClustersClick()) { return; } } if ((tasksToRun & AutomationTasks.ReadWorkbook) != 0) { // If the vertex X and Y columns were autofilled, the layout type // was set to LayoutType.Null. This will cause // TaskPane.ReadWorkbook() to display a warning. Temporarily turn // the warning off. NotificationUserSettings oNotificationUserSettings = new NotificationUserSettings(); Boolean bOldLayoutTypeIsNull = oNotificationUserSettings.LayoutTypeIsNull; oNotificationUserSettings.LayoutTypeIsNull = false; oNotificationUserSettings.Save(); if ((tasksToRun & AutomationTasks.SaveGraphImageFile) != 0) { if (String.IsNullOrEmpty(thisWorkbook.Path)) { throw new InvalidOperationException( WorkbookNotSavedMessage); } // After the workbook is read and the graph is laid out, save // an image of the graph to a file. GraphLaidOutEventHandler oGraphLaidOutEventHandler = null; oGraphLaidOutEventHandler = delegate(Object sender, GraphLaidOutEventArgs e) { // This delegate remains forever, even when the dialog // class is destroyed. Prevent it from being called again. thisWorkbook.GraphLaidOut -= oGraphLaidOutEventHandler; SaveGraphImageFile(e.NodeXLControl, thisWorkbook.FullName); }; thisWorkbook.GraphLaidOut += oGraphLaidOutEventHandler; } ribbon.OnReadWorkbookClick(); oNotificationUserSettings.LayoutTypeIsNull = bOldLayoutTypeIsNull; oNotificationUserSettings.Save(); } }