public PreferencesDialog (NoteManager manager) : base(Gtk.WindowType.Toplevel)
		{
			this.addin_manager = manager.AddinManager;
			
			IconName = "tomboy";
			BorderWidth = 5;
			Resizable = true;
			Title = Catalog.GetString ("Tomboy Preferences");
			WindowPosition = WindowPosition.Center;
			
			addin_prefs_dialogs = new Dictionary<string, Gtk.Dialog> ();
			addin_info_dialogs = new Dictionary<string, Gtk.Dialog> ();
			
			// Notebook Tabs (Editing, Hotkeys)...
			
			Gtk.Notebook notebook = new Gtk.Notebook ();
			notebook.TabPos = Gtk.PositionType.Top;
			notebook.Show ();
			
			notebook.AppendPage (MakeEditingPane (), new Gtk.Label (Catalog.GetString ("Editing")));
			
			if (!(Services.Keybinder is NullKeybinder))
				notebook.AppendPage (MakeHotkeysPane (), new Gtk.Label (Catalog.GetString ("Hotkeys")));
			
			notebook.AppendPage (MakeSyncPane (), new Gtk.Label (Catalog.GetString ("Synchronization")));
			notebook.AppendPage (MakeAddinsPane (), new Gtk.Label (Catalog.GetString ("Add-ins")));
			
			// TODO: Figure out a way to have these be placed in a specific order
			foreach (PreferenceTabAddin tabAddin in addin_manager.GetPreferenceTabAddins ()) {
				Logger.Debug ("Adding preference tab addin: {0}", tabAddin.GetType ().Name);
				try {
					string tabName;
					Gtk.Widget tabWidget;
					if (tabAddin.GetPreferenceTabWidget (this, out tabName, out tabWidget) == true) {
						notebook.AppendPage (tabWidget, new Gtk.Label (tabName));
					}
				} catch (Exception e) {
					Logger.Warn ("Problems adding preferences tab addin: {0}", tabAddin.GetType ().Name);
					Logger.Debug ("{0}:\n{1}", e.Message, e.StackTrace);
				}
			}
			Gtk.VBox VBox = new Gtk.VBox ();
			VBox.PackStart (notebook, true, true, 0);
			
			addin_manager.ApplicationAddinListChanged += OnAppAddinListChanged;
			
			// Close Button
			Gtk.Button button = new Gtk.Button (Gtk.Stock.Close);
			button.CanDefault = true;
			button.Label = "Close";
			button.Clicked += OnClickedClose;
			VBox.Add (button);
			button.Show ();
			
			Gtk.AccelGroup accel_group = new Gtk.AccelGroup ();
			AddAccelGroup (accel_group);
			
			button.AddAccelerator ("activate", accel_group, (uint)Gdk.Key.Escape, 0, 0);
			
			this.Add (VBox);
			if ((this.Child != null)) {
				this.Child.ShowAll ();
			}
			this.Show ();
			Preferences.SettingChanged += HandlePreferencesSettingChanged;
		}
Exemple #2
0
        public void Initialize()
        {
            notes = new List <Note> ();

            string conf_dir = Services.NativeApplication.ConfigurationDirectory;

            string old_notes_dir    = null;
            bool   migration_needed = false;

            bool first_run = FirstRun();

            if (first_run)
            {
                old_notes_dir    = Services.NativeApplication.PreOneDotZeroNoteDirectory;
                migration_needed = DirectoryExists(old_notes_dir);
            }
            CreateNotesDir();
            if (!Directory.Exists(conf_dir))
            {
                Directory.CreateDirectory(conf_dir);
            }

            if (migration_needed)
            {
                // Copy notes
                foreach (string noteFile in Directory.GetFiles(old_notes_dir, "*.note"))
                {
                    File.Copy(noteFile, Path.Combine(notes_dir, Path.GetFileName(noteFile)));
                }

                // Copy deleted notes
                string old_backup = Path.Combine(old_notes_dir, "Backup");
                if (DirectoryExists(old_backup))
                {
                    Directory.CreateDirectory(backup_dir);
                    foreach (string noteFile in Directory.GetFiles(old_backup, "*.note"))
                    {
                        File.Copy(noteFile, Path.Combine(backup_dir, Path.GetFileName(noteFile)));
                    }
                }

                // Copy configuration data
                // NOTE: Add-in configuration data copied by AddinManager
                string sync_manifest_name     = "manifest.xml";
                string old_sync_manifest_path =
                    Path.Combine(old_notes_dir, sync_manifest_name);
                if (File.Exists(old_sync_manifest_path))
                {
                    File.Copy(old_sync_manifest_path,
                              Path.Combine(conf_dir, sync_manifest_name));
                }


                // NOTE: Not copying cached data

                first_run = false;
            }

            trie_controller = CreateTrieController();
            addin_mgr       = new AddinManager(conf_dir,
                                               migration_needed ? old_notes_dir : null);

            if (first_run)
            {
                // First run. Create "Start Here" notes.
                CreateStartNotes();
            }
            else
            {
                LoadNotes();
            }

            if (migration_needed)
            {
                // Create migration notification note
                // Translators: The title of the data migration note
                string base_migration_note_title = Catalog.GetString("Your Notes Have Moved!");
                string migration_note_title      = base_migration_note_title;

                // NOTE: Uncomment to generate a title suitable for
                //       putting in the note collection
//				int count = 1;
//				while (Find (migration_note_title) != null) {
//					migration_note_title = base_migration_note_title +
//						string.Format (" ({0})", ++count);
//				}

                string migration_note_content_template = Catalog.GetString(
// Translators: The contents (not including the title) of the data migration note. {0}, {1}, {2}, {3}, and {4} are replaced by directory paths and should not be changed
                    @"In the latest version of Tomboy, your note files have moved.  You have probably never cared where your notes are stored, and if you still don't care, please go ahead and <bold>delete this note</bold>.  :-)

Your old note directory is still safe and sound at <link:url>{0}</link:url> . If you go back to an older version of Tomboy, it will look for notes there.

But we've copied your notes and configuration info into new directories, which will be used from now on:

<list><list-item dir=""ltr"">Notes can now be found at <link:url>{1}</link:url>
</list-item><list-item dir=""ltr"">Configuration is at <link:url>{2}</link:url>
</list-item><list-item dir=""ltr"">You can install add-ins at <link:url>{3}</link:url>
</list-item><list-item dir=""ltr"">Log files can be found at <link:url>{4}</link:url></list-item></list>

Ciao!");
                string migration_note_content =
                    "<note-content version=\"1.0\">" +
                    migration_note_title + "\n\n" +
                    string.Format(migration_note_content_template,
                                  old_notes_dir + Path.DirectorySeparatorChar,
                                  notes_dir + Path.DirectorySeparatorChar,
                                  conf_dir + Path.DirectorySeparatorChar,
                                  Path.Combine(conf_dir, "addins") + Path.DirectorySeparatorChar,
                                  Services.NativeApplication.LogDirectory + Path.DirectorySeparatorChar) +
                    "</note-content>";

                // NOTE: Uncomment to create a Tomboy note and
                //       show it to the user
//				Note migration_note = Create (migration_note_title,
//				                              migration_note_content);
//				migration_note.QueueSave (ChangeType.ContentChanged);
//				migration_note.Window.Show ();

                // Place file announcing migration in old note directory
                try {
                    using (var writer = File.CreateText(Path.Combine(old_notes_dir,
                                                                     migration_note_title.ToUpper().Replace(" ", "_"))))
                        writer.Write(migration_note_content);
                } catch {}
            }

            Tomboy.ExitingEvent += OnExitingEvent;
            Initialized          = true;
        }