Пример #1
0
        public static void Main(string [] args)
        {
            // TODO: Extract to a PreInit in Application, or something
#if WIN32
            string tomboy_path =
                Environment.GetEnvironmentVariable("TOMBOY_PATH_PREFIX");
            string tomboy_gtk_basepath =
                Environment.GetEnvironmentVariable("TOMBOY_GTK_BASEPATH");
            Environment.SetEnvironmentVariable("GTK_BASEPATH",
                                               tomboy_gtk_basepath ?? string.Empty);
            if (string.IsNullOrEmpty(tomboy_path))
            {
                string gtk_lib_path = null;
                try {
                    gtk_lib_path = (string)
                                   Microsoft.Win32.Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\GtkSharp",
                                                                     string.Empty,
                                                                     string.Empty);
                } catch (Exception e) {
                    Console.WriteLine("Exception while trying to get GTK# install path: " +
                                      e.ToString());
                }
                if (!string.IsNullOrEmpty(gtk_lib_path))
                {
                    tomboy_path =
                        gtk_lib_path.Replace("lib\\gtk-sharp-2.0", "bin");
                }
            }
            if (!string.IsNullOrEmpty(tomboy_path))
            {
                Environment.SetEnvironmentVariable("PATH",
                                                   tomboy_path +
                                                   Path.PathSeparator +
                                                   Environment.GetEnvironmentVariable("PATH"));
            }
#endif
            Catalog.Init("tomboy", Defines.GNOME_LOCALE_DIR);

            TomboyCommandLine cmd_line = new TomboyCommandLine(args);
            debugging   = cmd_line.Debug;
            uninstalled = cmd_line.Uninstalled;

            if (!RemoteControlProxy.FirstInstance)
            {
                if (!cmd_line.NeedsExecute)
                {
                    cmd_line = new TomboyCommandLine(new string [] { "--search" });
                }
                // Execute args at an existing tomboy instance...
                cmd_line.Execute();
                Console.WriteLine("Tomboy is already running.  Exiting...");
                return;
            }

            Logger.LogLevel = debugging ? Level.DEBUG : Level.INFO;
#if PANEL_APPLET
            is_panel_applet = cmd_line.UsePanelApplet;
#else
            is_panel_applet = false;
#endif

            // NOTE: It is important not to use the Preferences
            //       class before this call.
            Initialize("tomboy", "Tomboy", "tomboy", args);

            // Add private icon dir to search path
            icon_theme = Gtk.IconTheme.Default;
            icon_theme.AppendSearchPath(Path.Combine(Path.Combine(Defines.DATADIR, "tomboy"), "icons"));

            // Create the default note manager instance.
            string note_path = GetNotePath(cmd_line.NotePath);
            manager = new NoteManager(note_path);

            SetupGlobalActions();
            ActionManager am = Tomboy.ActionManager;

            // TODO: Instead of just delaying, lazy-load
            //       (only an issue for add-ins that need to be
            //       available at Tomboy startup, and restoring
            //       previously-opened notes)
            GLib.Timeout.Add(500, () => {
                manager.Initialize();
                SyncManager.Initialize();

                ApplicationAddin [] addins =
                    manager.AddinManager.GetApplicationAddins();
                foreach (ApplicationAddin addin in addins)
                {
                    addin.Initialize();
                }

                // Register the manager to handle remote requests.
                RegisterRemoteControl(manager);
                if (cmd_line.NeedsExecute)
                {
                    // Execute args on this instance
                    cmd_line.Execute();
                }
#if WIN32
                if (Environment.OSVersion.Platform == PlatformID.Win32NT)
                {
                    var os_version = Environment.OSVersion.Version;
                    if ((os_version.Major == 6 && os_version.Minor > 0) || os_version.Major > 6)
                    {
                        JumpListManager.CreateJumpList(manager);

                        manager.NoteAdded += delegate(object sender, Note changed) {
                            JumpListManager.CreateJumpList(manager);
                        };

                        manager.NoteRenamed += delegate(Note sender, string old_title) {
                            JumpListManager.CreateJumpList(manager);
                        };

                        manager.NoteDeleted += delegate(object sender, Note changed) {
                            JumpListManager.CreateJumpList(manager);
                        };
                    }
                }
#endif
                return(false);
            });

#if PANEL_APPLET
            if (is_panel_applet)
            {
                tray_icon_showing = true;

                // Show the Close item and hide the Quit item
                am ["CloseWindowAction"].Visible = true;
                am ["QuitTomboyAction"].Visible  = false;

                RegisterPanelAppletFactory();
                Logger.Debug("All done.  Ciao!");
                Exit(0);
            }
#endif
            RegisterSessionManagerRestart(
                Environment.GetEnvironmentVariable("TOMBOY_WRAPPER_PATH"),
                args,
                new string [] { "TOMBOY_PATH=" + note_path });                  // TODO: Pass along XDG_*?
            StartTrayIcon();

            Logger.Debug("All done.  Ciao!");
        }
Пример #2
0
        protected TomboyTray(NoteManager manager)
        {
            this.manager = manager;

            tray_menu = MakeTrayNotesMenu();
        }
Пример #3
0
 public TomboyTray(NoteManager manager, ITomboyTray tray)
     : this(manager)
 {
     this.tray = tray;
 }
        /// <summary>
        /// Determines the relative path between two exported files, can optionally be used
        /// by the subclass.
        /// </summary>
        /// <param name="title_from">
        /// The note we're finding the relative path from.
        /// </param>
        /// <param name="title_to">
        /// The title of the note we're finding the relative path to.
        /// </param>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public string ResolveRelativePath(Note note_from, string title_to)
        {
            NoteManager manager    = Tomboy.DefaultNoteManager;
            Note        note_to    = manager.Find(title_to);
            string      title_from = SanitizeNoteTitle(note_from.Title);

            title_to = SanitizeNoteTitle(note_to.Title);

            if (exporting_single_notebook)
            {
                //If there is only one notebook being exported
                if (NotebookManager.GetNotebookFromNote(note_from) == NotebookManager.GetNotebookFromNote(note_to))
                {
                    return(title_to + "." + export_file_suffix);
                }
                else
                {
                    return("");
                }
            }
            else
            {
                //If all notebooks are available
                if (NotebookManager.GetNotebookFromNote(note_from) == NotebookManager.GetNotebookFromNote(note_to))
                {
                    //Both notes are in the same notebook
                    return(title_to + "." + export_file_suffix);
                }
                else
                {
                    //Unfiled notes are a special case because they're in the root directory and will
                    // throw an exception from the notebookmanager
                    string notebook_from;
                    string notebook_to;
                    try {
                        notebook_from = NotebookManager.GetNotebookFromNote(note_from).NormalizedName;
                    } catch (Exception ex) {
                        notebook_from = "___NotebookManager___UnfiledNotes__Notebook___";                         //TODO: Ugly!
                    }
                    try {
                        notebook_to = NotebookManager.GetNotebookFromNote(note_to).NormalizedName;
                    } catch (Exception ex) {
                        notebook_to = "___NotebookManager___UnfiledNotes__Notebook___";
                    }

                    if (notebook_to == "___NotebookManager___UnfiledNotes__Notebook___")
                    {
                        return(".." + System.IO.Path.DirectorySeparatorChar + title_to + "." + export_file_suffix);
                    }
                    else if (notebook_from == "___NotebookManager___UnfiledNotes__Notebook___")
                    {
                        return(SanitizePath(notebook_to) + System.IO.Path.DirectorySeparatorChar
                               + title_to + "." + export_file_suffix);
                    }
                    else
                    {
                        return(".." + System.IO.Path.DirectorySeparatorChar + SanitizePath(notebook_to)
                               + System.IO.Path.DirectorySeparatorChar + title_to + "." + export_file_suffix);
                    }
                }
            }
        }