/// <summary> /// Called when the user chooses "Export All" from the menu, allows user to select destination via GUI. /// </summary> /// <param name="sender"> void ExportAllNotesViaGUI() { Logger.Info("Activated export all to " + export_type_pretty_name); exporting_single_notebook = false; //Opens the folder selection dialog ExportMultipleDialog dialog = new ExportMultipleDialog(String.Format(Catalog.GetString("All Notes {0} Export"), export_type_pretty_name), export_type_pretty_name); int response = dialog.Run(); if (response != (int)Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy(); return; } string output_folder = SanitizePath(dialog.Filename); try { ExportAllNotes(output_folder); //Successful export: clean up and inform. dialog.SavePreferences(); ShowSuccessDialog(output_folder); } catch (UnauthorizedAccessException) { Logger.Error(Catalog.GetString("Could not export, access denied.")); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Access denied.")); return; } catch (DirectoryNotFoundException) { Logger.Error(Catalog.GetString("Could not export, folder does not exist.")); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Folder does not exist.")); return; } catch (Exception ex) { Logger.Error(Catalog.GetString("Could not export: {0}"), ex); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Unknown error.")); return; } finally { if (dialog != null) { dialog.Destroy(); dialog = null; } } }
/// <summary> /// Shows an error dialog if things go wrong. /// </summary> /// <param name="output_folder"> /// A <see cref="System.String"/> with the name of the folder /// that couldn't be exported to. /// </param> /// <param name="dialog"> /// The parent <see cref="ExportMultipleDialog"/>. /// </param> /// <param name="error_message"> /// A <see cref="System.String"/> with an error description. /// </param> private static void ShowErrorDialog(string output_folder, ExportMultipleDialog dialog, string error_message) { string msg = String.Format( Catalog.GetString("Could not save the files in \"{0}\""), output_folder); HIGMessageDialog msg_dialog = new HIGMessageDialog( dialog, Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, msg, error_message); msg_dialog.Run(); msg_dialog.Destroy(); dialog.Destroy(); Logger.Error(error_message); }
/// <summary> /// Shows an error dialog if things go wrong. /// </summary> /// <param name="output_folder"> /// A <see cref="System.String"/> with the name of the folder /// that couldn't be exported to. /// </param> /// <param name="dialog"> /// The parent <see cref="ExportMultipleDialog"/>. /// </param> /// <param name="error_message"> /// A <see cref="System.String"/> with an error description. /// </param> private static void ShowErrorDialog (string output_folder, ExportMultipleDialog dialog, string error_message) { string msg = String.Format ( Catalog.GetString ("Could not save the files in \"{0}\""), output_folder); HIGMessageDialog msg_dialog = new HIGMessageDialog ( dialog, Gtk.DialogFlags.DestroyWithParent, Gtk.MessageType.Error, Gtk.ButtonsType.Ok, msg, error_message); msg_dialog.Run (); msg_dialog.Destroy (); dialog.Destroy (); Logger.Error (error_message); }
/// <summary> /// Called when the user chooses "Export Notebook" /// (Even when "All Notes or "Unfiled Notes" are /// selected.) /// </summary> void ExportNotebookButtonClicked (object sender, EventArgs args) { string output_folder = null; ExportMultipleDialog dialog = null; Logger.Info ("Activated export notebook to " + export_file_suffix); Notebook notebook = NoteRecentChanges.GetInstance (Tomboy.DefaultNoteManager).GetSelectedNotebook (); try { //Handling the two special notebooks string notebook_name = notebook.NormalizedName; if (notebook_name == "___NotebookManager___AllNotes__Notebook___") { Logger.Info ("This notebook includes all notes, activating Export All"); ExportAllNotesViaGUI (); return; } else if (notebook_name == "___NotebookManager___UnfiledNotes__Notebook___") { dialog = new ExportMultipleDialog (Catalog.GetString ("Unfiled Notes"), export_type_pretty_name); int response = dialog.Run (); output_folder = SanitizePath (dialog.Filename); if (response != (int) Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy (); return; } exporting_single_notebook = true; Logger.Debug ("Creating an export folder in: " + output_folder); System.IO.Directory.CreateDirectory (output_folder); ExportNotesInList (ListUnfiledNotes (), output_folder); } else { //Ordinary notebooks dialog = new ExportMultipleDialog (notebook_name, export_type_pretty_name); int response = dialog.Run (); output_folder = SanitizePath (dialog.Filename); if (response != (int) Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy (); return; } exporting_single_notebook = true; Logger.Debug ("Creating an export folder in: " + output_folder); System.IO.Directory.CreateDirectory (output_folder); ExportNotesInList (notebook.Tag.Notes, output_folder); } //Successful export: clean up and inform. dialog.SavePreferences (); ShowSuccessDialog (output_folder); } catch (UnauthorizedAccessException) { Logger.Error (Catalog.GetString ("Could not export, access denied.")); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Access denied.")); return; } catch (DirectoryNotFoundException) { Logger.Error (Catalog.GetString ("Could not export, folder does not exist.")); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Folder does not exist.")); return; } catch (Exception ex) { Logger.Error (Catalog.GetString ("Could not export: {0}"), ex); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Unknown error.")); return; } finally { if (dialog != null) { dialog.Destroy (); dialog = null; } } }
/// <summary> /// Called when the user chooses "Export All" from the menu, allows user to select destination via GUI. /// </summary> /// <param name="sender"> void ExportAllNotesViaGUI () { Logger.Info ("Activated export all to " + export_type_pretty_name); exporting_single_notebook = false; //Opens the folder selection dialog ExportMultipleDialog dialog = new ExportMultipleDialog (String.Format (Catalog.GetString ("All Notes {0} Export"), export_type_pretty_name), export_type_pretty_name); int response = dialog.Run (); if (response != (int) Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy (); return; } string output_folder = SanitizePath (dialog.Filename); try { ExportAllNotes (output_folder); //Successful export: clean up and inform. dialog.SavePreferences (); ShowSuccessDialog (output_folder); } catch (UnauthorizedAccessException) { Logger.Error (Catalog.GetString ("Could not export, access denied.")); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Access denied.")); return; } catch (DirectoryNotFoundException) { Logger.Error (Catalog.GetString ("Could not export, folder does not exist.")); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Folder does not exist.")); return; } catch (Exception ex) { Logger.Error (Catalog.GetString ("Could not export: {0}"), ex); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Unknown error.")); return; } finally { if (dialog != null) { dialog.Destroy (); dialog = null; } } }
/// <summary> /// Called when the user chooses "Export Notebook" /// (Even when "All Notes or "Unfiled Notes" are /// selected.) /// </summary> void ExportNotebookButtonClicked(object sender, EventArgs args) { string output_folder = null; ExportMultipleDialog dialog = null; Logger.Info("Activated export notebook to " + export_file_suffix); Notebook notebook = NoteRecentChanges.GetInstance(Tomboy.DefaultNoteManager).GetSelectedNotebook(); try { //Handling the two special notebooks string notebook_name = notebook.NormalizedName; if (notebook_name == "___NotebookManager___AllNotes__Notebook___") { Logger.Info("This notebook includes all notes, activating Export All"); ExportAllNotesViaGUI(); return; } else if (notebook_name == "___NotebookManager___UnfiledNotes__Notebook___") { dialog = new ExportMultipleDialog(Catalog.GetString("Unfiled Notes"), export_type_pretty_name); int response = dialog.Run(); output_folder = SanitizePath(dialog.Filename); if (response != (int)Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy(); return; } exporting_single_notebook = true; Logger.Debug("Creating an export folder in: " + output_folder); System.IO.Directory.CreateDirectory(output_folder); ExportNotesInList(ListUnfiledNotes(), output_folder); } else { //Ordinary notebooks dialog = new ExportMultipleDialog(notebook_name, export_type_pretty_name); int response = dialog.Run(); output_folder = SanitizePath(dialog.Filename); if (response != (int)Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy(); return; } exporting_single_notebook = true; Logger.Debug("Creating an export folder in: " + output_folder); System.IO.Directory.CreateDirectory(output_folder); ExportNotesInList(notebook.Tag.Notes, output_folder); } //Successful export: clean up and inform. dialog.SavePreferences(); ShowSuccessDialog(output_folder); } catch (UnauthorizedAccessException) { Logger.Error(Catalog.GetString("Could not export, access denied.")); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Access denied.")); return; } catch (DirectoryNotFoundException) { Logger.Error(Catalog.GetString("Could not export, folder does not exist.")); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Folder does not exist.")); return; } catch (Exception ex) { Logger.Error(Catalog.GetString("Could not export: {0}"), ex); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Unknown error.")); return; } finally { if (dialog != null) { dialog.Destroy(); dialog = null; } } }
/// <summary> /// Called when the user chooses "Export All" /// </summary> /// <param name="sender"> void ExportAllNotes () { Logger.Info ("Activated export all to " + export_type_pretty_name); exporting_single_notebook = false; //Opens the folder selection dialog ExportMultipleDialog dialog = new ExportMultipleDialog (String.Format (Catalog.GetString ("All Notes {0} Export"), export_type_pretty_name), export_type_pretty_name); int response = dialog.Run (); if (response != (int) Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy (); return; } string output_folder = SanitizePath (dialog.Filename); try { Logger.Debug ("Creating an export folder in: " + output_folder); System.IO.Directory.CreateDirectory (output_folder); //Iterate through notebooks Notebooks.Notebook notebook; string notebook_folder; foreach (Tag tag in TagManager.AllTags) { // Skip over tags that aren't notebooks notebook = NotebookManager.GetNotebookFromTag (tag); if (notebook == null) continue; Logger.Debug ("Exporting notebook " + notebook.Name); notebook_folder = SanitizePath (output_folder + System.IO.Path.DirectorySeparatorChar + notebook.NormalizedName); System.IO.Directory.CreateDirectory (notebook_folder); ExportNotesInList (notebook.Tag.Notes, notebook_folder); } //Finally we have to export all unfiled notes. Logger.Debug ("Exporting Unfiled Notes"); ExportNotesInList (ListUnfiledNotes (), output_folder); //Successful export: clean up and inform. dialog.SavePreferences (); ShowSuccessDialog (output_folder); } catch (UnauthorizedAccessException) { Logger.Error (Catalog.GetString ("Could not export, access denied.")); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Access denied.")); return; } catch (DirectoryNotFoundException) { Logger.Error (Catalog.GetString ("Could not export, folder does not exist.")); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Folder does not exist.")); return; } catch (Exception ex) { Logger.Error (Catalog.GetString ("Could not export: {0}"), ex); ShowErrorDialog (output_folder, dialog, Catalog.GetString ("Unknown error.")); return; } finally { if (dialog != null) { dialog.Destroy (); dialog = null; } } }
/// <summary> /// Called when the user chooses "Export All" /// </summary> /// <param name="sender"> void ExportAllNotes() { Logger.Info("Activated export all to " + export_type_pretty_name); exporting_single_notebook = false; //Opens the folder selection dialog ExportMultipleDialog dialog = new ExportMultipleDialog(String.Format(Catalog.GetString("All Notes {0} Export"), export_type_pretty_name), export_type_pretty_name); int response = dialog.Run(); if (response != (int)Gtk.ResponseType.Ok) { Logger.Debug("User clicked cancel."); dialog.Destroy(); return; } string output_folder = SanitizePath(dialog.Filename); try { Logger.Debug("Creating an export folder in: " + output_folder); System.IO.Directory.CreateDirectory(output_folder); //Iterate through notebooks Notebooks.Notebook notebook; string notebook_folder; foreach (Tag tag in TagManager.AllTags) { // Skip over tags that aren't notebooks notebook = NotebookManager.GetNotebookFromTag(tag); if (notebook == null) { continue; } Logger.Debug("Exporting notebook " + notebook.Name); notebook_folder = SanitizePath(output_folder + System.IO.Path.DirectorySeparatorChar + notebook.NormalizedName); System.IO.Directory.CreateDirectory(notebook_folder); ExportNotesInList(notebook.Tag.Notes, notebook_folder); } //Finally we have to export all unfiled notes. Logger.Debug("Exporting Unfiled Notes"); ExportNotesInList(ListUnfiledNotes(), output_folder); //Successful export: clean up and inform. dialog.SavePreferences(); ShowSuccessDialog(output_folder); } catch (UnauthorizedAccessException) { Logger.Error(Catalog.GetString("Could not export, access denied.")); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Access denied.")); return; } catch (DirectoryNotFoundException) { Logger.Error(Catalog.GetString("Could not export, folder does not exist.")); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Folder does not exist.")); return; } catch (Exception ex) { Logger.Error(Catalog.GetString("Could not export: {0}"), ex); ShowErrorDialog(output_folder, dialog, Catalog.GetString("Unknown error.")); return; } finally { if (dialog != null) { dialog.Destroy(); dialog = null; } } }