Index: xword/XWikiLib/Logging/UserNotifier.cs
===================================================================
--- xword/XWikiLib/Logging/UserNotifier.cs (revision 0)
+++ xword/XWikiLib/Logging/UserNotifier.cs (revision 0)
@@ -0,0 +1,131 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows.Forms;
+
+namespace XWiki.Logging
+{
+ ///
+ /// Simple utility class for user notifications.
+ ///
+ public class UserNotifier
+ {
+ private static string MESSAGE_TITLE = "XWord";
+
+ ///
+ /// Displays a simple message to the user.
+ ///
+ /// Text message to display.
+ public static void Message(string text)
+ {
+ Show(text, MESSAGE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Information);
+ }
+
+ ///
+ /// Displays a message to the user and two Retry/Cancel buttons.
+ ///
+ /// Message to display.
+ /// A DialogResult
containing the button clicked by the user.
+ public static DialogResult RetryCancelQuestion(string text)
+ {
+ return Show(text, MESSAGE_TITLE, MessageBoxButtons.RetryCancel, MessageBoxIcon.Question);
+ }
+
+ ///
+ /// Asks the user a question and provides Yes/No buttons.
+ ///
+ /// Question to ask.
+ /// A DialogResult
containing the button clicked by the user.
+ public static DialogResult YesNoQuestion(string text)
+ {
+ return Show(text, MESSAGE_TITLE, MessageBoxButtons.YesNo, MessageBoxIcon.Question);
+ }
+
+ ///
+ /// Asks the user a question and provides Yes/No/Cancel buttons.
+ ///
+ /// Question to ask.
+ /// A DialogResult
containing the button clicked by the user.
+ public static DialogResult YesNoCancelQuestion(string text)
+ {
+ return Show(text, MESSAGE_TITLE, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
+ }
+
+ ///
+ /// Displays an exclamation message.
+ ///
+ /// Text to be displayed
+ public static void Exclamation(string text)
+ {
+ Show(text, MESSAGE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ }
+ ///
+ /// Shows a warning message.
+ ///
+ /// Warning message text.
+ /// A DialogResult
containing the button clicked by the user.
+ public static DialogResult Warning(string text)
+ {
+ return Show(text, MESSAGE_TITLE, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
+ }
+
+ ///
+ /// Shows an error message.
+ /// Used to inform the user that an error has occured.
+ ///
+ /// Error message text.
+ public static void Error(string text)
+ {
+ Show(text, MESSAGE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+
+ ///
+ /// Shows a stop message.
+ /// Used to inform the user that an action will not execute.
+ ///
+ /// Stop message text
+ public static void StopHand(string text)
+ {
+ Show(text,MESSAGE_TITLE, MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ }
+
+ private static DialogResult Show(string text)
+ {
+ return MessageBox.Show(text);
+ }
+
+ private static DialogResult Show(string text, string caption)
+ {
+ return MessageBox.Show(text, caption);
+ }
+
+ private static DialogResult Show(string text, string caption, MessageBoxButtons buttons)
+ {
+ return MessageBox.Show(text, caption, buttons);
+ }
+
+ private static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon)
+ {
+ return MessageBox.Show(text, caption, buttons, icon);
+ }
+
+ private static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
+ {
+ return MessageBox.Show(text, caption, buttons, icon, defaultButton);
+ }
+
+ private static DialogResult Show(string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options)
+ {
+ return MessageBox.Show(text, caption, buttons, icon, defaultButton, options);
+ }
+
+ ///
+ /// Private constructor to avoid instancing and inheritance.
+ ///
+ private UserNotifier()
+ {
+
+ }
+ }
+}
Index: xword/XWikiLib/XWikiLib.csproj
===================================================================
--- xword/XWikiLib/XWikiLib.csproj (revision 20475)
+++ xword/XWikiLib/XWikiLib.csproj (working copy)
@@ -60,6 +60,7 @@
+
True
Index: xword/XWord/AddinActions.cs
===================================================================
--- xword/XWord/AddinActions.cs (revision 20475)
+++ xword/XWord/AddinActions.cs (working copy)
@@ -16,6 +16,7 @@
using Word = Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;
using XWord.VstoExtensions;
+using XWiki.Logging;
namespace XWord
{
@@ -137,7 +138,7 @@
bool operationCompleted = false; ;
if (addin.Application.ActiveDocument == null)
{
- MessageBox.Show("This command is not available because no document is open.", "XWord");
+ UserNotifier.Message("This command is not available because no document is open.");
}
try
{
@@ -221,7 +222,7 @@
{
if(IsOpened(pageFullName))
{
- MessageBox.Show("You are already editing this page.", "XWord");
+ UserNotifier.Message("You are already editing this page.");
return;
}
if (!this.Client.LoggedIn)
@@ -232,7 +233,7 @@
{
String message = "You cannot edit this page." + Environment.NewLine;
message += "This page contains scrips that provide functionality to the wiki.";
- MessageBox.Show(message, "XWord", MessageBoxButtons.OK, MessageBoxIcon.Stop);
+ UserNotifier.StopHand(message);
return;
}
LoadingDialog loadingDialog = new LoadingDialog("Opening page...");
@@ -301,7 +302,7 @@
}
catch (IOException ex)
{
- MessageBox.Show(ex.Message);
+ UserNotifier.Error(ex.Message);
}
}
@@ -339,7 +340,7 @@
if (!Client.SavePageHTML(pageName, pageContent, syntax))
{
Log.Error("Failed to save page " + pageName + "on server " + addin.serverURL);
- MessageBox.Show("There was an error on the server when trying to save the page");
+ UserNotifier.Error("There was an error on the server when trying to save the page");
}
else
{
@@ -401,7 +402,7 @@
{
if (addin.currentPageFullName == "" || addin.currentPageFullName == null)
{
- MessageBox.Show("You are not currently editing a wiki page", "XWord", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
+ UserNotifier.Exclamation("You are not currently editing a wiki page") ;
return;
}
bool continueWithSaving = ShowSwitchSyntaxDialog();
@@ -439,14 +440,12 @@
(addin.AddinStatus.Syntax.ToLower().IndexOf("xhtml") < 0))
{
DialogResult dr;
- string infoMessage, caption;
+ string infoMessage;
infoMessage = "This page contains elements that can not properly be saved inXWiki 2.0 syntax.";
infoMessage += Environment.NewLine;
infoMessage += "Would you like to switch to XHTML syntax?";
- caption = "Feature Not Yet Implemented";
-
- dr = System.Windows.Forms.MessageBox.Show(infoMessage, caption, MessageBoxButtons.YesNoCancel,
- MessageBoxIcon.Question, MessageBoxDefaultButton.Button1);
+
+ dr = UserNotifier.YesNoCancelQuestion(infoMessage);
if (dr == DialogResult.Yes)
{
@@ -475,7 +474,7 @@
String tempExportFileName = currentFileName + "_TempExport.html";
if (!ShadowCopyDocument(addin.ActiveDocumentInstance, tempExportFileName, addin.SaveFormat))
{
- MessageBox.Show("There was an error when trying to save the page.", "XWord");
+ UserNotifier.Error("There was an error when trying to save the page.");
return;
}
contentFilePath = tempExportFileName;
@@ -522,7 +521,7 @@
string message = "An internal Word error appeared when trying to save your file.";
message += Environment.NewLine + ex.Message;
Log.Exception(ex);
- MessageBox.Show(message, "XWord");
+ UserNotifier.Error(message);
}
}
@@ -637,7 +636,7 @@
}
catch (IOException ex)
{
- MessageBox.Show(ex.Message);
+ UserNotifier.Error(ex.Message);
}
}
@@ -680,19 +679,19 @@
if (content.Contains(HTTPResponses.NO_PROGRAMMING_RIGHTS))
{
Log.Error("Server " + addin.serverURL + " has no programming rights on getPageservice");
- MessageBox.Show("There was an error on the server. The pages in MSOffice space don't have programming rights");
+ UserNotifier.Error("There was an error on the server. The pages in MSOffice space don't have programming rights");
hasErrors = true;
}
else if(content.Contains(HTTPResponses.WRONG_REQUEST))
{
Log.Error("Server " + addin.serverURL + " wrong request");
- MessageBox.Show("Error: Wrong request");
+ UserNotifier.Error("Server error: Wrong request");
hasErrors = true;
}
else if(content.Contains(HTTPResponses.NO_EDIT_RIGHTS))
{
Log.Information("User tried to edit a page on " + addin.serverURL + " whithout edit rights");
- MessageBox.Show("You dont have the right to edit this page");
+ UserNotifier.Error("You dont have the right to edit this page");
hasErrors = true;
}
else if(content.Contains(HTTPResponses.NO_GROOVY_RIGHTS))
@@ -700,7 +699,7 @@
Log.Error("Server " + addin.serverURL + " error on parsing groovy - no groovy rights");
String message = "There was an error on the server." + Environment.NewLine;
message += "Please contact your server adminitrator. Error on executing groovy page in MSOffice space";
- MessageBox.Show(message);
+ UserNotifier.Error(message);
hasErrors = true;
}
else if(content.Contains(HTTPResponses.INSUFFICIENT_MEMMORY))
@@ -708,7 +707,7 @@
Log.Error("Server " + addin.serverURL + " reported OutOfMemmoryException");
String message = "There was an error on the server." + Environment.NewLine;
message += "The server has insufficient memmory to execute the current tasks.";
- MessageBox.Show(message);
+ UserNotifier.Error(message);
hasErrors = true;
}
else if(content.Contains(HTTPResponses.VELOCITY_PARSER_ERROR))
@@ -716,7 +715,7 @@
Log.Error("Server " + addin.serverURL + " error when parsing page. ");
String message = "There was an error on the server" + Environment.NewLine;
message += "'Error while parsing velocity page'";
- MessageBox.Show(message);
+ UserNotifier.Error(message);
hasErrors = true;
}
return hasErrors;
@@ -791,7 +790,7 @@
catch (IOException ioex)
{
Log.Exception(ioex);
- MessageBox.Show(ioex.Message);
+ UserNotifier.Error(ioex.Message);
return false;
}
Index: xword/XWord/AddinSettingsForm.cs
===================================================================
--- xword/XWord/AddinSettingsForm.cs (revision 20475)
+++ xword/XWord/AddinSettingsForm.cs (working copy)
@@ -7,6 +7,7 @@
using System.Diagnostics;
using System.Windows.Forms;
using XWiki.Clients;
+using XWiki.Logging;
namespace XWord
{
@@ -337,7 +338,7 @@
bool isValid = ValidatePath(txtPagesRepo.Text);
if (!isValid)
{
- MessageBox.Show("The path you provided is not valid. Please select a valid path");
+ UserNotifier.Error("The path you provided is not valid. Please select a valid path");
}
}
@@ -351,7 +352,7 @@
bool isValid = ValidatePath(txtAttachmentsRepo.Text);
if (!isValid)
{
- MessageBox.Show("The path you provided is not valid. Please select a valid path");
+ UserNotifier.Error("The path you provided is not valid. Please select a valid path");
}
}
@@ -379,7 +380,7 @@
}
else
{
- MessageBox.Show("The selected value is not valid.", "XWord", MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ UserNotifier.StopHand("The selected value is not valid.");
}
}
}
Index: xword/XWord/AddPageForm.cs
===================================================================
--- xword/XWord/AddPageForm.cs (revision 20475)
+++ xword/XWord/AddPageForm.cs (working copy)
@@ -9,6 +9,7 @@
using System.Windows.Forms;
using System.Runtime.InteropServices;
using XWiki;
+using XWiki.Logging;
namespace XWord
{
@@ -162,7 +163,7 @@
catch (COMException) { }
catch (Exception ex)
{
- MessageBox.Show(ex.Message, "XWord", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ UserNotifier.Error(ex.Message);
}
}
}
@@ -215,7 +216,7 @@
}
else
{
- MessageBox.Show(err, "XWord", MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ UserNotifier.StopHand(err);
}
return isValid;
}
Index: xword/XWord/XWikiAddIn.cs
===================================================================
--- xword/XWord/XWikiAddIn.cs (revision 20475)
+++ xword/XWord/XWikiAddIn.cs (working copy)
@@ -35,6 +35,7 @@
using XWord.VstoExtensions;
using XWiki.Clients;
using XWiki;
+using XWiki.Logging;
namespace XWord
{
@@ -346,7 +347,7 @@
}
else
{
- MessageBox.Show(ex.Message);
+ UserNotifier.Error(ex.Message);
}
}
}
@@ -485,7 +486,7 @@
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+ UserNotifier.Error(ex.Message);
}
}
Index: xword/XWord/XWikiNavigationPane.cs
===================================================================
--- xword/XWord/XWikiNavigationPane.cs (revision 20475)
+++ xword/XWord/XWikiNavigationPane.cs (working copy)
@@ -13,6 +13,7 @@
using XWiki;
using XWiki.Clients;
using System.Diagnostics;
+using XWiki.Logging;
namespace XWord
{
@@ -383,7 +384,7 @@
}
else
{
- MessageBox.Show("Download finised.", "XWord");
+ UserNotifier.Message("Download finised.");
}
}
}
@@ -400,7 +401,7 @@
bool finished = Globals.XWikiAddIn.AddinActions.AttachCurrentFile(page);
if (finished)
{
- MessageBox.Show("Upload finished.", "XWord");
+ UserNotifier.Message("Upload finished.");
}
}
@@ -508,7 +509,7 @@
}
catch (InvalidOperationException)
{
- MessageBox.Show("This operation is already in progress");
+ UserNotifier.Error("This operation is already in progress");
}
}
@@ -532,21 +533,21 @@
}
catch (Win32Exception ex)
{
- MessageBox.Show(ex.Message, "XWord", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ UserNotifier.Error(ex.Message);
}
catch (WebException webex)
{
- MessageBox.Show(webex.Message, "XWord", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ UserNotifier.Error(webex.Message);
}
}
else
{
- MessageBox.Show("No page is selected");
+ UserNotifier.Exclamation("No page is selected");
}
}
else
{
- MessageBox.Show("Please select a page in the Wiki Explorer first.");
+ UserNotifier.Exclamation("Please select a page in the Wiki Explorer first.");
}
}
@@ -622,7 +623,7 @@
}
catch (Exception ex)
{
- MessageBox.Show(ex.Message);
+ UserNotifier.Error(ex.Message);
Log.Exception(ex);
}
}
@@ -724,7 +725,7 @@
treeView.Nodes.Clear();
loadingWikiData = false;
Log.Exception(ex);
- MessageBox.Show(ex.Message, "XWord", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ UserNotifier.Error(ex.Message);
}
}
backgroundWorker.ReportProgress(100, e.Argument);
Index: xword/XWord/XWikiRibbon.cs
===================================================================
--- xword/XWord/XWikiRibbon.cs (revision 20475)
+++ xword/XWord/XWikiRibbon.cs (working copy)
@@ -6,6 +6,7 @@
using Word = Microsoft.Office.Interop.Word;
using VSTO = Microsoft.Office.Tools;
using XWord.VstoExtensions;
+using XWiki.Logging;
namespace XWord
{
@@ -119,17 +120,17 @@
String page = Globals.XWikiAddIn.AddinStatus.TaskPaneSelectedPage.Get("page");
if (page == null)
{
- MessageBox.Show("You need to select a pege in the wiki explorer first.");
+ UserNotifier.Exclamation("You need to select a pege in the wiki explorer first.");
return;
}
bool finished = Globals.XWikiAddIn.AddinActions.AttachCurrentFile(page);
if (finished)
{
- MessageBox.Show("Upload finished.", "XWord");
+ UserNotifier.Message("Upload finished.");
}
else
{
- MessageBox.Show("Upload failed. Make sure you have selected a page before uploading");
+ UserNotifier.Error("Upload failed. Make sure you have selected a page before uploading");
}
}
@@ -154,7 +155,7 @@
}
catch(NullReferenceException)
{
- MessageBox.Show("You are not currently editing a wiki page", "XWord", MessageBoxButtons.OK ,MessageBoxIcon.Exclamation);
+ UserNotifier.Exclamation("You are not currently editing a wiki page");
}
}
@@ -184,12 +185,12 @@
if (path != null)
{
FileInfo attachmentInfo = Addin.AddinActions.DownloadAttachment(page, attachmentName, path);
- MessageBox.Show("Download finised.", "XWord");
+ UserNotifier.Message("Download finised.");
}
}
else
{
- MessageBox.Show("You need to select an attachment in the wiki explorer.", "XWord");
+ UserNotifier.Exclamation("You need to select an attachment in the wiki explorer.");
}
}
@@ -208,7 +209,7 @@
}
else
{
- MessageBox.Show("You need to select an attachment in the wiki explorer.", "XWord");
+ UserNotifier.Exclamation("You need to select an attachment in the wiki explorer.");
}
}
@@ -255,7 +256,7 @@
}
else
{
- MessageBox.Show("Invalid syntax selected", "XWord", MessageBoxButtons.OK, MessageBoxIcon.Hand);
+ UserNotifier.StopHand("Invalid syntax selected");
}
}