17
17
static bool is_panel_applet = false;
18
18
static PreferencesDialog prefs_dlg;
19
19
static SyncDialog sync_dlg;
21
21
static RemoteControl remote_control;
24
public static void Main (string [] args)
24
public static void Main (string [] args)
26
26
// Initialize GETTEXT
27
27
Catalog.Init ("tomboy", Defines.GNOME_LOCALE_DIR);
29
29
TomboyCommandLine cmd_line = new TomboyCommandLine (args);
31
#if ENABLE_DBUS // Run command-line earlier with DBus enabled
31
#if ENABLE_DBUS // Run command-line earlier with DBus enabled
32
32
if (cmd_line.NeedsExecute) {
33
33
// Execute args at an existing tomboy instance...
34
34
cmd_line.Execute ();
39
39
Initialize ("tomboy", "Tomboy", "tomboy", args);
41
// PluginManager.CheckPluginUnloading = cmd_line.CheckPluginUnloading;
41
// PluginManager.CheckPluginUnloading = cmd_line.CheckPluginUnloading;
43
43
// Create the default note manager instance.
44
44
string note_path = GetNotePath (cmd_line.NotePath);
49
49
// Register the manager to handle remote requests.
50
50
RegisterRemoteControl (manager);
52
52
SetupGlobalActions ();
53
ActionManager am = Tomboy.ActionManager;
55
if (cmd_line.NeedsExecute) {
59
ActionManager am = Tomboy.ActionManager;
61
55
ApplicationAddin [] addins =
62
manager.AddinManager.GetApplicationAddins ();
56
manager.AddinManager.GetApplicationAddins ();
63
57
foreach (ApplicationAddin addin in addins) {
64
58
addin.Initialize ();
62
if (cmd_line.NeedsExecute) {
67
67
if (cmd_line.UsePanelApplet) {
68
68
tray_icon_showing = true;
69
69
is_panel_applet = true;
75
75
RegisterPanelAppletFactory ();
77
77
RegisterSessionManagerRestart (
78
Environment.GetEnvironmentVariable ("TOMBOY_WRAPPER_PATH"),
80
new string [] { "TOMBOY_PATH=" + note_path });
78
Environment.GetEnvironmentVariable ("TOMBOY_WRAPPER_PATH"),
80
new string [] { "TOMBOY_PATH=" + note_path });
84
84
Logger.Log ("All done. Ciao!");
87
87
static string GetNotePath (string override_path)
89
89
// Default note location, as specified in --note-path or $TOMBOY_PATH
91
(override_path != null) ?
93
Environment.GetEnvironmentVariable ("TOMBOY_PATH");
91
(override_path != null) ?
93
Environment.GetEnvironmentVariable ("TOMBOY_PATH");
94
94
if (note_path == null)
95
95
note_path = "~/.tomboy";
179
179
am ["ShowSearchAllNotesAction"].Activated += OpenSearchAll;
180
180
am ["NoteSynchronizationAction"].Activated += OpenNoteSyncWindow;
183
183
static void OnNewNoteAction (object sender, EventArgs args)
186
186
Note new_note = manager.Create ();
187
187
new_note.Window.Show ();
188
188
} catch (Exception e) {
189
HIGMessageDialog dialog =
190
new HIGMessageDialog (
193
Gtk.MessageType.Error,
195
Catalog.GetString ("Cannot create new note"),
189
HIGMessageDialog dialog =
190
new HIGMessageDialog (
193
Gtk.MessageType.Error,
195
Catalog.GetString ("Cannot create new note"),
198
198
dialog.Destroy ();
202
202
static void OpenNoteSyncWindow (object sender, EventArgs args)
204
204
if (sync_dlg == null) {
205
205
sync_dlg = new SyncDialog ();
206
206
sync_dlg.Response += OnSyncDialogResponse;
209
209
sync_dlg.Present ();
212
212
static void OnSyncDialogResponse (object sender, Gtk.ResponseArgs args)
214
214
((Gtk.Widget) sender).Destroy ();
218
static void OnQuitTomboyAction (object sender, EventArgs args)
218
static void OnQuitTomboyAction (object sender, EventArgs args)
220
220
if (Tomboy.IsPanelApplet)
221
221
return; // Ignore the quit action
238
238
((Gtk.Widget) sender).Destroy ();
239
239
prefs_dlg = null;
242
242
static void OnShowHelpAction (object sender, EventArgs args)
244
244
// Pass in null for the screen when we're running as a panel applet
245
245
GuiUtils.ShowHelp("tomboy.xml", null,
246
tray_icon == null ? null : tray_icon.TomboyTray.Screen,
246
tray_icon == null ? null : tray_icon.TomboyTray.Screen,
250
250
static void OnShowAboutAction (object sender, EventArgs args)
252
252
string [] authors = new string [] {
256
256
"David Trowbridge <trowbrds@gmail.com>",
257
257
"Ryan Lortie <desrt@desrt.ca>",
258
258
"Sandy Armstrong <sanfordarmstrong@gmail.com>",
259
"Sebastian Rittau <srittau@jroger.in-berlin.de>"
259
"Sebastian Rittau <srittau@jroger.in-berlin.de>",
260
"Kevin Kubasik <kevin@kubasik.net>"
262
263
string [] documenters = new string [] {
271
272
about.Name = "Tomboy";
272
273
about.Version = Defines.VERSION;
273
274
about.Logo = GuiUtils.GetIcon ("tomboy", 48);
275
Catalog.GetString ("Copyright \xa9 2004-2007 Alex Graveley");
276
Catalog.GetString ("Copyright \xa9 2004-2007 Alex Graveley");
276
277
about.Comments = Catalog.GetString ("A simple and easy to use desktop " +
277
"note-taking application.");
278
"note-taking application.");
278
279
about.Website = Defines.TOMBOY_WEBSITE;
279
280
about.WebsiteLabel = Catalog.GetString("Homepage");
280
281
about.Authors = authors;
285
286
about.Destroy ();
288
289
static void OpenSearchAll (object sender, EventArgs args)
290
291
NoteRecentChanges.GetInstance (manager).Present ();
293
294
public static NoteManager DefaultNoteManager
295
get { return manager; }
298
301
public static bool TrayIconShowing
300
get { return tray_icon_showing; }
304
return tray_icon_showing;
303
308
public static bool IsPanelApplet
305
get { return is_panel_applet; }
311
return is_panel_applet;
308
315
public static TomboyTray Tray
345
356
public bool UsePanelApplet
347
get { return panel_applet; }
350
363
public bool NeedsExecute
354
open_note_name != null ||
355
open_note_uri != null ||
358
open_external_note_path != null;
367
open_note_name != null ||
368
open_note_uri != null ||
371
open_external_note_path != null;
362
375
public string NotePath
364
get { return note_path; }
367
// public bool CheckPluginUnloading
369
// get { return check_plugin_unloading; }
382
// public bool CheckPluginUnloading
384
// get { return check_plugin_unloading; }
372
public static void PrintAbout ()
387
public static void PrintAbout ()
376
"Tomboy: A simple, easy to use desktop note-taking " +
378
"Copyright (C) 2004-2006 Alex Graveley " +
379
"<alex@beatniksoftware.com>\n\n");
391
"Tomboy: A simple, easy to use desktop note-taking " +
393
"Copyright (C) 2004-2006 Alex Graveley " +
394
"<alex@beatniksoftware.com>\n\n");
381
396
Console.Write (about);
384
public static void PrintUsage ()
399
public static void PrintUsage ()
389
" --version\t\t\tPrint version information.\n" +
390
" --help\t\t\tPrint this usage message.\n" +
391
" --note-path [path]\t\tLoad/store note data in this " +
393
" --search [text]\t\tOpen the search all notes window with " +
394
"the search text.\n");
404
" --version\t\t\tPrint version information.\n" +
405
" --help\t\t\tPrint this usage message.\n" +
406
" --note-path [path]\t\tLoad/store note data in this " +
408
" --search [text]\t\tOpen the search all notes window with " +
409
"the search text.\n");
399
" --new-note\t\t\tCreate and display a new note.\n" +
400
" --new-note [title]\t\tCreate and display a new note, " +
402
" --open-note [title/url]\tDisplay the existing note " +
403
"matching title.\n" +
404
" --start-here\t\t\tDisplay the 'Start Here' note.\n" +
405
" --highlight-search [text]\tSearch and highlight text " +
406
"in the opened note.\n");
414
" --new-note\t\t\tCreate and display a new note.\n" +
415
" --new-note [title]\t\tCreate and display a new note, " +
417
" --open-note [title/url]\tDisplay the existing note " +
418
"matching title.\n" +
419
" --start-here\t\t\tDisplay the 'Start Here' note.\n" +
420
" --highlight-search [text]\tSearch and highlight text " +
421
"in the opened note.\n");
409
424
// TODO: Restore this functionality with addins
411
// Catalog.GetString (
412
// " --check-plugin-unloading\tCheck if plugins are " +
413
// "unloaded properly.\n");
426
// Catalog.GetString (
427
// " --check-plugin-unloading\tCheck if plugins are " +
428
// "unloaded properly.\n");
416
431
usage += Catalog.GetString ("D-BUS remote control disabled.\n");
419
434
Console.WriteLine (usage);
430
445
bool quit = false;
432
447
switch (args [idx]) {
434
449
case "--new-note":
435
450
// Get optional name for new note...
436
451
if (idx + 1 < args.Length
437
&& args [idx + 1] != null
438
&& args [idx + 1] != String.Empty
439
&& args [idx + 1][0] != '-') {
452
&& args [idx + 1] != null
453
&& args [idx + 1] != String.Empty
454
&& args [idx + 1][0] != '-') {
440
455
new_note_name = args [++idx];
446
461
case "--open-note":
447
462
// Get required name for note to open...
448
463
if (idx + 1 >= args.Length ||
449
(args [idx + 1] != null
450
&& args [idx + 1] != String.Empty
451
&& args [idx + 1][0] == '-')) {
464
(args [idx + 1] != null
465
&& args [idx + 1] != String.Empty
466
&& args [idx + 1][0] == '-')) {
458
473
// If the argument looks like a Uri, treat it like a Uri.
459
474
if (args [idx].StartsWith ("note://tomboy/"))
460
475
open_note_uri = args [idx];
474
489
case "--highlight-search":
475
490
// Get required search string to highlight
476
491
if (idx + 1 >= args.Length ||
477
(args [idx + 1] != null
478
&& args [idx + 1] != String.Empty
479
&& args [idx + 1][0] == '-')) {
492
(args [idx + 1] != null
493
&& args [idx + 1] != String.Empty
494
&& args [idx + 1][0] == '-')) {
485
500
highlight_search = args [idx];
488
503
case "--new-note":
489
504
case "--open-note":
490
505
case "--start-here":
491
506
case "--highlight-search":
494
"Tomboy: unsupported option '{0}'\n" +
495
"Try 'tomboy --help' for more " +
497
"D-BUS remote control disabled.");
509
"Tomboy: unsupported option '{0}'\n" +
510
"Try 'tomboy --help' for more " +
512
"D-BUS remote control disabled.");
498
513
Console.WriteLine (unknown_opt, args [idx]);
501
#endif // ENABLE_DBUS
516
#endif // ENABLE_DBUS
503
518
case "--panel-applet":
504
519
panel_applet = true;
507
522
case "--note-path":
508
if (idx + 1 >= args.Length ||
509
(args [idx + 1] != null
510
&& args [idx + 1] != String.Empty
511
&& args [idx + 1][0] == '-')) {
523
if (idx + 1 >= args.Length ||
524
(args [idx + 1] != null
525
&& args [idx + 1] != String.Empty
526
&& args [idx + 1][0] == '-')) {
529
544
// Get optional search text...
530
545
if (idx + 1 < args.Length
531
&& args [idx + 1] != null
532
&& args [idx + 1] != String.Empty
533
&& args [idx + 1][0] != '-') {
546
&& args [idx + 1] != null
547
&& args [idx + 1] != String.Empty
548
&& args [idx + 1][0] != '-') {
534
549
search_text = args [++idx];
537
552
open_search = true;
540
// case "--check-plugin-unloading":
541
// check_plugin_unloading = true;
555
// case "--check-plugin-unloading":
556
// check_plugin_unloading = true;
544
559
case "--version":
598
613
if (open_note_name != null)
599
614
open_note_uri = remote.FindNote (open_note_name);
601
616
if (open_note_uri != null) {
602
617
if (highlight_search != null)
603
remote.DisplayNoteWithSearch (open_note_uri,
618
remote.DisplayNoteWithSearch (open_note_uri,
606
621
remote.DisplayNote (open_note_uri);
609
624
if (open_external_note_path != null) {
610
625
string note_id = Path.GetFileNameWithoutExtension (open_external_note_path);
611
626
if (note_id != null && note_id != string.Empty) {
612
627
// Attempt to load the note, assuming it might already
613
628
// be part of our notes list.
614
629
if (remote.DisplayNote (
615
string.Format ("note://tomboy/{0}", note_id)) == false) {
630
string.Format ("note://tomboy/{0}", note_id)) == false) {
617
632
StreamReader sr = File.OpenText (open_external_note_path);
618
633
if (sr != null) {
619
634
string noteTitle = null;
620
635
string noteXml = sr.ReadToEnd ();
622
637
// Make sure noteXml is parseable
623
638
XmlDocument xmlDoc = new XmlDocument ();
625
640
xmlDoc.LoadXml (noteXml);
630
if (noteXml != null) {
645
if (noteXml != null) {
631
646
noteTitle = NoteArchiver.Instance.GetTitleFromNoteXml (noteXml);
632
647
if (noteTitle != null) {
633
648
// Check for conflicting titles
634
649
string baseTitle = (string)noteTitle.Clone ();
635
650
for (int i = 1; remote.FindNote (noteTitle) != string.Empty; i++)
636
651
noteTitle = baseTitle + " (" + i.ToString() + ")";
638
653
string note_uri = remote.CreateNamedNote (noteTitle);
640
655
// Update title in the note XML
641
656
noteXml = NoteArchiver.Instance.GetRenamedNoteXml (noteXml, baseTitle, noteTitle);
655
670
if (open_search) {
656
671
if (search_text != null)
657
672
remote.DisplaySearchWithText (search_text);
659
674
remote.DisplaySearch ();
662
677
if (open_search) {
663
678
NoteRecentChanges recent_changes =
664
NoteRecentChanges.GetInstance (Tomboy.DefaultNoteManager);
679
NoteRecentChanges.GetInstance (Tomboy.DefaultNoteManager);
665
680
if (recent_changes == null)
668
683
if (search_text != null)
669
684
recent_changes.SearchText = search_text;
671
686
recent_changes.Present ();
673
#endif // ENABLE_DBUS
688
#endif // ENABLE_DBUS