Example #1
0
        /// <summary>
        /// An event handler that parses add-in commandline args looking for commands relating to
        /// this class and executes them.
        /// </summary>
        void ParseArgs(object sender, EventArgs e)
        {
            if (cmdline_parsed)
            {
                return;                             //The event is sometimes fired twice
            }
            Logger.Debug(export_type_pretty_name + " exporter checking command line args");
            cmdline_parsed = true;

            TomboyCommandLine cmd_line = sender as TomboyCommandLine;

            for (int i = 0; i < cmd_line.Addin_argslist.Count; i++)
            {
                if (cmd_line.Addin_argslist[i] == "--addin:" + export_file_suffix + "-export-all" ||
                    cmd_line.Addin_argslist[i] == "--addin:" + export_file_suffix + "-export-all-quit")
                {
                    try {
                        if (cmd_line.Addin_argslist[i].StartsWith("\""))
                        {
                            //Path may include spaces, have to look for ending quotation mark
                            StringBuilder pathbuilder = new StringBuilder(cmd_line.Addin_argslist[i]);
                            for (int j = 1; j < cmd_line.Addin_argslist.Count; j++)
                            {
                                pathbuilder.Append(cmd_line.Addin_argslist[i + j]);
                                if (cmd_line.Addin_argslist[i + j].EndsWith("\""))
                                {
                                    break;
                                }
                            }
                            ExportAllNotes(SanitizePath(pathbuilder.ToString().Trim('"')));
                        }
                        else
                        {
                            //Expecting a whole path without spaces
                            ExportAllNotes(SanitizePath(cmd_line.Addin_argslist[i + 1]));
                        }
                    } catch (UnauthorizedAccessException) {
                        Logger.Error(Catalog.GetString("Could not export, access denied."));
                    } catch (DirectoryNotFoundException) {
                        Logger.Error(Catalog.GetString("Could not export, folder does not exist."));
                    } catch (IndexOutOfRangeException) {
                        Logger.Error(Catalog.GetString("Could not export, error with the path. (No ending \"?)"));
                    } catch (Exception ex) {
                        Logger.Error(Catalog.GetString("Could not export: {0}"), ex);
                    }
                    if (cmd_line.Addin_argslist[i] == "--addin:" + export_file_suffix + "-export-all-quit")
                    {
                        System.Environment.Exit(1);
                    }
                }
            }
        }
Example #2
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);
			manager.CommandLine = cmd_line;

			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!");
		}
Example #3
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);
            manager.CommandLine = cmd_line;

            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!");
        }