3
using System.Collections.Generic;
11
public class PreferencesDialog : Gtk.Dialog
13
Gtk.ListStore syncAddinStore;
14
Dictionary<string, Gtk.TreeIter> syncAddinIters;
15
Gtk.ComboBox syncAddinCombo;
16
SyncServiceAddin selectedSyncAddin;
17
Gtk.VBox syncAddinPrefsContainer;
18
Gtk.Widget syncAddinPrefsWidget;
19
Gtk.Button resetSyncAddinButton;
20
Gtk.Button saveSyncAddinButton;
21
Gtk.CheckButton autosyncCheck;
22
Gtk.SpinButton autosyncSpinner;
23
Gtk.ComboBox rename_behavior_combo;
24
readonly AddinManager addin_manager;
26
Gtk.Button font_button;
30
Mono.Addins.Gui.AddinTreeWidget addin_tree;
32
Gtk.Button enable_addin_button;
33
Gtk.Button disable_addin_button;
34
Gtk.Button addin_prefs_button;
35
Gtk.Button addin_info_button;
37
private Gtk.RadioButton promptOnConflictRadio;
38
private Gtk.RadioButton renameOnConflictRadio;
39
private Gtk.RadioButton overwriteOnConflictRadio;
42
/// Keep track of the opened addin prefs dialogs so other windows
43
/// can be interacted with (as opposed to opening these as modal
46
/// Key = Mono.Addins.Addin.Id
48
Dictionary<string, Gtk.Dialog> addin_prefs_dialogs;
51
/// Used to keep track of open AddinInfoDialogs.
52
/// Key = Mono.Addins.Addin.Id
54
Dictionary<string, Gtk.Dialog> addin_info_dialogs;
56
public PreferencesDialog (AddinManager addin_manager)
59
this.addin_manager = addin_manager;
65
Title = Catalog.GetString ("Tomboy Preferences");
67
ActionArea.Layout = Gtk.ButtonBoxStyle.End;
70
new Dictionary<string, Gtk.Dialog> ();
72
new Dictionary<string, Gtk.Dialog> ();
74
// Notebook Tabs (Editing, Hotkeys)...
76
Gtk.Notebook notebook = new Gtk.Notebook ();
77
notebook.TabPos = Gtk.PositionType.Top;
80
notebook.AppendPage (MakeEditingPane (),
81
new Gtk.Label (Catalog.GetString ("Editing")));
82
if (! (Services.Keybinder is NullKeybinder))
83
notebook.AppendPage (MakeHotkeysPane (),
84
new Gtk.Label (Catalog.GetString ("Hotkeys")));
85
notebook.AppendPage (MakeSyncPane (),
86
new Gtk.Label (Catalog.GetString ("Synchronization")));
87
notebook.AppendPage (MakeAddinsPane (),
88
new Gtk.Label (Catalog.GetString ("Add-ins")));
90
// TODO: Figure out a way to have these be placed in a specific order
91
foreach (PreferenceTabAddin tabAddin in addin_manager.GetPreferenceTabAddins ()) {
92
Logger.Debug ("Adding preference tab addin: {0}", tabAddin.GetType ().Name);
96
if (tabAddin.GetPreferenceTabWidget (this, out tabName, out tabWidget) == true) {
97
notebook.AppendPage (tabWidget, new Gtk.Label (tabName));
99
} catch (Exception e) {
100
Logger.Warn ("Problems adding preferences tab addin: {0}", tabAddin.GetType ().Name);
101
Logger.Debug ("{0}:\n{1}", e.Message, e.StackTrace);
105
VBox.PackStart (notebook, true, true, 0);
107
addin_manager.ApplicationAddinListChanged += OnAppAddinListChanged;
112
Gtk.Button button = new Gtk.Button (Gtk.Stock.Close);
113
button.CanDefault = true;
116
Gtk.AccelGroup accel_group = new Gtk.AccelGroup ();
117
AddAccelGroup (accel_group);
119
button.AddAccelerator ("activate",
121
(uint) Gdk.Key.Escape,
125
AddActionWidget (button, Gtk.ResponseType.Close);
126
DefaultResponse = Gtk.ResponseType.Close;
128
Preferences.SettingChanged += HandlePreferencesSettingChanged;
131
void HandlePreferencesSettingChanged (object sender, NotifyEventArgs args)
133
if (args.Key == Preferences.NOTE_RENAME_BEHAVIOR) {
134
int rename_behavior = (int) args.Value;
135
if (rename_behavior < 0 || rename_behavior > 2) {
137
Preferences.Set (Preferences.NOTE_RENAME_BEHAVIOR, rename_behavior);
139
if (rename_behavior_combo.Active != rename_behavior)
140
rename_behavior_combo.Active = rename_behavior;
141
} else if (args.Key == Preferences.SYNC_AUTOSYNC_TIMEOUT) {
142
int timeout = (int) args.Value;
143
if (timeout <= 0 && autosyncCheck.Active)
144
autosyncCheck.Active = false;
145
else if (timeout > 0) {
146
timeout = (timeout >= 5 && timeout < 1000) ? timeout : 5;
147
if (!autosyncCheck.Active)
148
autosyncCheck.Active = true;
149
if ((int) autosyncSpinner.Value != timeout)
150
autosyncSpinner.Value = timeout;
156
// List of editing options
157
public Gtk.Widget MakeEditingPane ()
160
Gtk.CheckButton check;
162
IPropertyEditorBool peditor, font_peditor, bullet_peditor;
164
Gtk.VBox options_list = new Gtk.VBox (false, 12);
165
options_list.BorderWidth = 12;
166
options_list.Show ();
172
if (NoteSpellChecker.GtkSpellAvailable) {
173
check = MakeCheckButton (
174
Catalog.GetString ("_Spell check while typing"));
175
options_list.PackStart (check, false, false, 0);
177
peditor = Services.Factory.CreatePropertyEditorToggleButton (
178
Preferences.ENABLE_SPELLCHECKING,
180
SetupPropertyEditor (peditor);
182
label = MakeTipLabel (
183
Catalog.GetString ("Misspellings will be underlined " +
184
"in red, with correct spelling " +
185
"suggestions shown in the context " +
187
options_list.PackStart (label, false, false, 0);
194
check = MakeCheckButton (Catalog.GetString ("Highlight _WikiWords"));
195
options_list.PackStart (check, false, false, 0);
197
peditor = Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_WIKIWORDS,
199
SetupPropertyEditor (peditor);
201
label = MakeTipLabel (
202
Catalog.GetString ("Enable this option to highlight " +
203
"words <b>ThatLookLikeThis</b>. " +
204
"Clicking the word will create a " +
205
"note with that name."));
206
options_list.PackStart (label, false, false, 0);
208
// Auto bulleted list
209
check = MakeCheckButton (Catalog.GetString ("Enable auto-_bulleted lists"));
210
options_list.PackStart (check, false, false, 0);
212
Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_AUTO_BULLETED_LISTS,
214
SetupPropertyEditor (bullet_peditor);
217
Gtk.HBox font_box = new Gtk.HBox (false, 0);
218
check = MakeCheckButton (Catalog.GetString ("Use custom _font"));
219
font_box.PackStart (check);
222
Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_CUSTOM_FONT,
224
SetupPropertyEditor (font_peditor);
226
font_button = MakeFontButton ();
227
font_button.Sensitive = check.Active;
228
font_box.PackStart (font_button);
230
options_list.PackStart (font_box, false, false, 0);
232
font_peditor.AddGuard (font_button);
234
// Note renaming bahvior
235
Gtk.HBox rename_behavior_box = new Gtk.HBox (false, 0);
236
label = MakeLabel (Catalog.GetString ("When renaming a linked note: "));
237
rename_behavior_box.PackStart (label);
238
rename_behavior_combo = new Gtk.ComboBox (new string [] {
239
Catalog.GetString ("Ask me what to do"),
240
Catalog.GetString ("Never rename links"),
241
Catalog.GetString ("Always rename links")});
242
int rename_behavior = (int) Preferences.Get (Preferences.NOTE_RENAME_BEHAVIOR);
243
if (rename_behavior < 0 || rename_behavior > 2) {
245
Preferences.Set (Preferences.NOTE_RENAME_BEHAVIOR, rename_behavior);
247
rename_behavior_combo.Active = rename_behavior;
248
rename_behavior_combo.Changed += (o, e) =>
249
Preferences.Set (Preferences.NOTE_RENAME_BEHAVIOR,
250
rename_behavior_combo.Active);
251
rename_behavior_box.PackStart (rename_behavior_combo);
252
rename_behavior_box.ShowAll ();
253
options_list.PackStart (rename_behavior_box, false, false, 0);
256
// Translators: This is 'New Note' Template, not New 'Note Template'
257
label = MakeLabel (Catalog.GetString ("New Note Template"));
258
options_list.PackStart (label, false, false, 0);
260
label = MakeTipLabel (
261
Catalog.GetString ("Use the new note template to specify the text " +
262
"that should be used when creating a new note."));
263
options_list.PackStart (label, false, false, 0);
265
align = new Gtk.Alignment (0.5f, 0.5f, 0.4f, 1.0f);
267
options_list.PackStart (align, false, false, 0);
269
Gtk.Button open_template_button = new Gtk.Button ();
270
open_template_button.Label = Catalog.GetString ("Open New Note Template");
272
open_template_button.Clicked += OpenTemplateButtonClicked;
273
open_template_button.Show ();
274
align.Add (open_template_button);
279
Gtk.Button MakeFontButton ()
281
Gtk.HBox font_box = new Gtk.HBox (false, 0);
284
font_face = new Gtk.Label (null);
285
font_face.UseMarkup = true;
287
font_box.PackStart (font_face, true, true, 0);
289
Gtk.VSeparator sep = new Gtk.VSeparator ();
291
font_box.PackStart (sep, false, false, 0);
293
font_size = new Gtk.Label (null);
296
font_box.PackStart (font_size, false, false, 0);
298
Gtk.Button button = new Gtk.Button ();
299
button.Clicked += OnFontButtonClicked;
300
button.Add (font_box);
303
string font_desc = (string) Preferences.Get (Preferences.CUSTOM_FONT_FACE);
304
UpdateFontButton (font_desc);
310
// List of Hotkey options
311
public Gtk.Widget MakeHotkeysPane ()
314
Gtk.CheckButton check;
317
IPropertyEditorBool keybind_peditor;
318
IPropertyEditor peditor;
320
Gtk.VBox hotkeys_list = new Gtk.VBox (false, 12);
321
hotkeys_list.BorderWidth = 12;
322
hotkeys_list.Show ();
327
check = MakeCheckButton (Catalog.GetString ("Listen for _Hotkeys"));
328
hotkeys_list.PackStart (check, false, false, 0);
331
Services.Factory.CreatePropertyEditorToggleButton (Preferences.ENABLE_KEYBINDINGS,
333
SetupPropertyEditor (keybind_peditor);
335
label = MakeTipLabel (
336
Catalog.GetString ("Hotkeys allow you to quickly access " +
337
"your notes from anywhere with a keypress. " +
338
"Example Hotkeys: " +
339
"<b><Control><Shift>F11</b>, " +
340
"<b><Alt>N</b>"));
341
hotkeys_list.PackStart (label, false, false, 0);
343
align = new Gtk.Alignment (0.5f, 0.5f, 0.0f, 1.0f);
345
hotkeys_list.PackStart (align, false, false, 0);
347
Gtk.Table table = new Gtk.Table (4, 2, false);
348
table.ColumnSpacing = 6;
349
table.RowSpacing = 6;
354
// Show notes menu keybinding...
356
label = MakeLabel (Catalog.GetString ("Show notes _menu"));
357
table.Attach (label, 0, 1, 0, 1);
359
entry = new Gtk.Entry ();
360
label.MnemonicWidget = entry;
362
table.Attach (entry, 1, 2, 0, 1);
364
peditor = Services.Factory.CreatePropertyEditorEntry (Preferences.KEYBINDING_SHOW_NOTE_MENU,
366
SetupPropertyEditor (peditor);
368
keybind_peditor.AddGuard (entry);
371
// Open Start Here keybinding...
373
label = MakeLabel (Catalog.GetString ("Open \"_Start Here\""));
374
table.Attach (label, 0, 1, 1, 2);
376
entry = new Gtk.Entry ();
377
label.MnemonicWidget = entry;
379
table.Attach (entry, 1, 2, 1, 2);
381
peditor = Services.Factory.CreatePropertyEditorEntry (Preferences.KEYBINDING_OPEN_START_HERE,
383
SetupPropertyEditor (peditor);
385
keybind_peditor.AddGuard (entry);
388
// Create new note keybinding...
390
label = MakeLabel (Catalog.GetString ("Create _new note"));
391
table.Attach (label, 0, 1, 2, 3);
393
entry = new Gtk.Entry ();
394
label.MnemonicWidget = entry;
396
table.Attach (entry, 1, 2, 2, 3);
398
peditor = Services.Factory.CreatePropertyEditorEntry (Preferences.KEYBINDING_CREATE_NEW_NOTE,
400
SetupPropertyEditor (peditor);
402
keybind_peditor.AddGuard (entry);
405
// Open Search All Notes window keybinding...
407
label = MakeLabel (Catalog.GetString ("Open \"Search _All Notes\""));
408
table.Attach (label, 0, 1, 3, 4);
410
entry = new Gtk.Entry ();
411
label.MnemonicWidget = entry;
413
table.Attach (entry, 1, 2, 3, 4);
415
peditor = Services.Factory.CreatePropertyEditorEntry (
416
Preferences.KEYBINDING_OPEN_RECENT_CHANGES,
418
SetupPropertyEditor (peditor);
420
keybind_peditor.AddGuard (entry);
426
public Gtk.Widget MakeSyncPane ()
428
Gtk.VBox vbox = new Gtk.VBox (false, 0);
430
vbox.BorderWidth = 8;
432
Gtk.HBox hbox = new Gtk.HBox (false, 4);
434
Gtk.Label label = new Gtk.Label (Catalog.GetString ("Ser_vice:"));
437
hbox.PackStart (label, false, false, 0);
439
// Populate the store with all the available SyncServiceAddins
440
syncAddinStore = new Gtk.ListStore (typeof (SyncServiceAddin));
441
syncAddinIters = new Dictionary<string,Gtk.TreeIter> ();
442
SyncServiceAddin [] addins = Tomboy.DefaultNoteManager.AddinManager.GetSyncServiceAddins ();
443
Array.Sort (addins, CompareSyncAddinsByName);
444
foreach (SyncServiceAddin addin in addins) {
445
Gtk.TreeIter iter = syncAddinStore.Append ();
446
syncAddinStore.SetValue (iter, 0, addin);
447
syncAddinIters [addin.Id] = iter;
450
syncAddinCombo = new Gtk.ComboBox (syncAddinStore);
451
label.MnemonicWidget = syncAddinCombo;
452
Gtk.CellRendererText crt = new Gtk.CellRendererText ();
453
syncAddinCombo.PackStart (crt, true);
454
syncAddinCombo.SetCellDataFunc (crt,
455
new Gtk.CellLayoutDataFunc (ComboBoxTextDataFunc));
457
// Read from Preferences which service is configured and select it
458
// by default. Otherwise, just select the first one in the list.
459
string addin_id = Preferences.Get (
460
Preferences.SYNC_SELECTED_SERVICE_ADDIN) as String;
462
Gtk.TreeIter active_iter;
463
if (addin_id != null && syncAddinIters.ContainsKey (addin_id)) {
464
active_iter = syncAddinIters [addin_id];
465
syncAddinCombo.SetActiveIter (active_iter);
467
if (syncAddinStore.GetIterFirst (out active_iter) == true) {
468
syncAddinCombo.SetActiveIter (active_iter);
472
syncAddinCombo.Changed += OnSyncAddinComboChanged;
474
syncAddinCombo.Show ();
475
hbox.PackStart (syncAddinCombo, true, true, 0);
478
vbox.PackStart (hbox, false, false, 0);
480
// Get the preferences GUI for the Sync Addin
481
if (active_iter.Stamp != Gtk.TreeIter.Zero.Stamp)
482
selectedSyncAddin = syncAddinStore.GetValue (active_iter, 0) as SyncServiceAddin;
484
if (selectedSyncAddin != null)
485
syncAddinPrefsWidget = selectedSyncAddin.CreatePreferencesControl (OnSyncAddinPrefsChanged);
486
if (syncAddinPrefsWidget == null) {
487
Gtk.Label l = new Gtk.Label (Catalog.GetString ("Not configurable"));
490
syncAddinPrefsWidget = l;
492
if (syncAddinPrefsWidget != null && addin_id != null &&
493
syncAddinIters.ContainsKey (addin_id) && selectedSyncAddin.IsConfigured)
494
syncAddinPrefsWidget.Sensitive = false;
496
syncAddinPrefsWidget.Show ();
497
syncAddinPrefsContainer = new Gtk.VBox (false, 0);
498
syncAddinPrefsContainer.PackStart (syncAddinPrefsWidget, false, false, 0);
499
syncAddinPrefsContainer.Show ();
500
vbox.PackStart (syncAddinPrefsContainer, true, true, 10);
502
// Autosync preference
503
int timeout = (int) Preferences.Get (Preferences.SYNC_AUTOSYNC_TIMEOUT);
504
if (timeout > 0 && timeout < 5) {
506
Preferences.Set (Preferences.SYNC_AUTOSYNC_TIMEOUT, 5);
508
Gtk.HBox autosyncBox = new Gtk.HBox (false, 5);
509
// Translators: This is and the next string go together.
510
// Together they look like "Automatically Sync in Background Every [_] Minutes",
511
// where "[_]" is a GtkSpinButton.
513
new Gtk.CheckButton (Catalog.GetString ("Automaticall_y Sync in Background Every"));
514
autosyncSpinner = new Gtk.SpinButton (5, 1000, 1);
515
autosyncSpinner.Value = timeout >= 5 ? timeout : 10;
516
Gtk.Label autosyncExtraText =
517
// Translators: See above comment for details on
519
new Gtk.Label (Catalog.GetString ("Minutes"));
520
autosyncCheck.Active = autosyncSpinner.Sensitive = timeout >= 5;
521
EventHandler updateTimeoutPref = (o, e) => {
522
Preferences.Set (Preferences.SYNC_AUTOSYNC_TIMEOUT,
523
autosyncCheck.Active ? (int) autosyncSpinner.Value : -1);
525
autosyncCheck.Toggled += (o, e) => {
526
autosyncSpinner.Sensitive = autosyncCheck.Active;
527
updateTimeoutPref (o, e);
529
autosyncSpinner.ValueChanged += updateTimeoutPref;
531
autosyncBox.PackStart (autosyncCheck);
532
autosyncBox.PackStart (autosyncSpinner);
533
autosyncBox.PackStart (autosyncExtraText);
534
vbox.PackStart (autosyncBox, false, true, 0);
536
Gtk.HButtonBox bbox = new Gtk.HButtonBox ();
538
bbox.LayoutStyle = Gtk.ButtonBoxStyle.End;
540
// "Advanced..." button to bring up extra sync config dialog
541
Gtk.Button advancedConfigButton = new Gtk.Button (Catalog.GetString ("_Advanced..."));
542
advancedConfigButton.Clicked += OnAdvancedSyncConfigButton;
543
advancedConfigButton.Show ();
544
bbox.PackStart (advancedConfigButton, false, false, 0);
545
bbox.SetChildSecondary (advancedConfigButton, true);
547
resetSyncAddinButton = new Gtk.Button (Gtk.Stock.Clear);
548
resetSyncAddinButton.Clicked += OnResetSyncAddinButton;
549
resetSyncAddinButton.Sensitive =
550
(selectedSyncAddin != null &&
551
addin_id == selectedSyncAddin.Id &&
552
selectedSyncAddin.IsConfigured);
553
resetSyncAddinButton.Show ();
554
bbox.PackStart (resetSyncAddinButton, false, false, 0);
556
// TODO: Tabbing should go directly from sync prefs widget to here
557
// TODO: Consider connecting to "Enter" pressed in sync prefs widget
558
saveSyncAddinButton = new Gtk.Button (Gtk.Stock.Save);
559
saveSyncAddinButton.Clicked += OnSaveSyncAddinButton;
560
saveSyncAddinButton.Sensitive =
561
(selectedSyncAddin != null &&
562
(addin_id != selectedSyncAddin.Id || !selectedSyncAddin.IsConfigured));
563
saveSyncAddinButton.Show ();
564
bbox.PackStart (saveSyncAddinButton, false, false, 0);
566
syncAddinCombo.Sensitive =
567
(selectedSyncAddin == null ||
568
addin_id != selectedSyncAddin.Id ||
569
!selectedSyncAddin.IsConfigured);
572
vbox.PackStart (bbox, false, false, 0);
578
private int CompareSyncAddinsByName (SyncServiceAddin addin1, SyncServiceAddin addin2)
580
return addin1.Name.CompareTo (addin2.Name);
583
private void ComboBoxTextDataFunc (Gtk.CellLayout cell_layout, Gtk.CellRenderer cell,
584
Gtk.TreeModel tree_model, Gtk.TreeIter iter)
586
Gtk.CellRendererText crt = cell as Gtk.CellRendererText;
587
SyncServiceAddin addin = tree_model.GetValue (iter, 0) as SyncServiceAddin;
589
crt.Text = string.Empty;
591
crt.Text = addin.Name;
596
// Extension Preferences
597
public Gtk.Widget MakeAddinsPane ()
599
Gtk.VBox vbox = new Gtk.VBox (false, 6);
600
vbox.BorderWidth = 6;
601
Gtk.Label l = new Gtk.Label (Catalog.GetString (
602
"The following add-ins are installed"));
605
vbox.PackStart (l, false, false, 0);
607
Gtk.HBox hbox = new Gtk.HBox (false, 6);
609
// TreeView of Add-ins
610
Gtk.TreeView tree = new Gtk.TreeView ();
611
addin_tree = new Mono.Addins.Gui.AddinTreeWidget (tree);
615
Gtk.ScrolledWindow sw = new Gtk.ScrolledWindow ();
616
sw.HscrollbarPolicy = Gtk.PolicyType.Automatic;
617
sw.VscrollbarPolicy = Gtk.PolicyType.Automatic;
618
sw.ShadowType = Gtk.ShadowType.In;
621
Gtk.LinkButton get_more_link =
622
new Gtk.LinkButton ("http://live.gnome.org/Tomboy/PluginList",
623
Catalog.GetString ("Get More Add-Ins..."));
624
get_more_link.Show ();
625
Gtk.VBox tree_box = new Gtk.VBox (false, 0);
627
tree_box.PackEnd (get_more_link, false, false, 5);
629
hbox.PackStart (tree_box, true, true, 0);
631
// Action Buttons (right of TreeView)
632
Gtk.VButtonBox button_box = new Gtk.VButtonBox ();
633
button_box.Spacing = 4;
634
button_box.Layout = Gtk.ButtonBoxStyle.Start;
636
// TODO: In a future version, add in an "Install Add-ins..." button
638
// TODO: In a future version, add in a "Repositories..." button
640
enable_addin_button =
641
new Gtk.Button (Catalog.GetString ("_Enable"));
642
enable_addin_button.Sensitive = false;
643
enable_addin_button.Clicked += OnEnableAddinButton;
644
enable_addin_button.Show ();
646
disable_addin_button =
647
new Gtk.Button (Catalog.GetString ("_Disable"));
648
disable_addin_button.Sensitive = false;
649
disable_addin_button.Clicked += OnDisableAddinButton;
650
disable_addin_button.Show ();
653
new Gtk.Button (Gtk.Stock.Preferences);
654
addin_prefs_button.Sensitive = false;
655
addin_prefs_button.Clicked += OnAddinPrefsButton;
656
addin_prefs_button.Show ();
659
new Gtk.Button (Gtk.Stock.Info);
660
addin_info_button.Sensitive = false;
661
addin_info_button.Clicked += OnAddinInfoButton;
662
addin_info_button.Show ();
664
button_box.PackStart (enable_addin_button);
665
button_box.PackStart (disable_addin_button);
666
button_box.PackStart (addin_prefs_button);
667
button_box.PackStart (addin_info_button);
670
hbox.PackStart (button_box, false, false, 0);
673
vbox.PackStart (hbox, true, true, 0);
676
tree.Selection.Changed += OnAddinTreeSelectionChanged;
682
void OnAddinTreeSelectionChanged (object sender, EventArgs args)
684
UpdateAddinButtons ();
688
/// Set the sensitivity of the buttons based on what is selected
690
void UpdateAddinButtons ()
692
Mono.Addins.Addin sinfo =
693
addin_tree.ActiveAddinData as Mono.Addins.Addin;
696
enable_addin_button.Sensitive = false;
697
disable_addin_button.Sensitive = false;
698
addin_prefs_button.Sensitive = false;
699
addin_info_button.Sensitive = false;
701
enable_addin_button.Sensitive = !sinfo.Enabled;
702
disable_addin_button.Sensitive = sinfo.Enabled;
703
addin_prefs_button.Sensitive = addin_manager.IsAddinConfigurable (sinfo);
704
addin_info_button.Sensitive = true;
710
object s = addin_tree.SaveStatus ();
713
foreach (Mono.Addins.Addin ainfo in addin_manager.GetAllAddins ()) {
714
addin_tree.AddAddin (
715
Mono.Addins.Setup.SetupService.GetAddinHeader (ainfo),
721
addin_tree.RestoreStatus (s);
722
UpdateAddinButtons ();
725
void OnEnableAddinButton (object sender, EventArgs args)
727
Mono.Addins.Addin sinfo =
728
addin_tree.ActiveAddinData as Mono.Addins.Addin;
733
EnableAddin (sinfo, true);
736
void OnDisableAddinButton (object sender, EventArgs args)
738
Mono.Addins.Addin sinfo =
739
addin_tree.ActiveAddinData as Mono.Addins.Addin;
744
EnableAddin (sinfo, false);
747
void EnableAddin (Mono.Addins.Addin addin, bool enable)
749
addin.Enabled = enable;
753
void OnAddinPrefsButton (object sender, EventArgs args)
755
Gtk.Dialog dialog = null;
756
Mono.Addins.Addin addin =
757
addin_tree.ActiveAddinData as Mono.Addins.Addin;
762
if (addin_prefs_dialogs.ContainsKey (addin.Id) == false) {
763
// A preference dialog isn't open already so create a new one
765
new Gtk.Image (Gtk.Stock.Preferences, Gtk.IconSize.Dialog);
766
Gtk.Label caption = new Gtk.Label ();
767
caption.Markup = string.Format (
768
"<span size='large' weight='bold'>{0} {1}</span>",
769
addin.Name, addin.Version);
771
caption.UseMarkup = true;
772
caption.UseUnderline = false;
774
Gtk.Widget pref_widget =
775
addin_manager.CreateAddinPreferenceWidget (addin);
777
if (pref_widget == null)
778
pref_widget = new Gtk.Label (Catalog.GetString ("Not Implemented"));
780
Gtk.HBox hbox = new Gtk.HBox (false, 6);
781
Gtk.VBox vbox = new Gtk.VBox (false, 6);
782
vbox.BorderWidth = 6;
784
hbox.PackStart (icon, false, false, 0);
785
hbox.PackStart (caption, true, true, 0);
786
vbox.PackStart (hbox, false, false, 0);
788
vbox.PackStart (pref_widget, true, true, 0);
791
dialog = new Gtk.Dialog (
792
string.Format (Catalog.GetString ("{0} Preferences"),
795
Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.NoSeparator,
796
Gtk.Stock.Close, Gtk.ResponseType.Close);
798
dialog.VBox.PackStart (vbox, true, true, 0);
799
dialog.DeleteEvent += AddinPrefDialogDeleted;
800
dialog.Response += AddinPrefDialogResponse;
802
// Store this dialog off in the dictionary so it can be
803
// presented again if the user clicks on the preferences button
804
// again before closing the preferences dialog.
805
dialog.Data ["AddinId"] = addin.Id;
806
addin_prefs_dialogs [addin.Id] = dialog;
808
// It's already opened so just present it again
809
dialog = addin_prefs_dialogs [addin.Id];
815
[GLib.ConnectBeforeAttribute]
816
void AddinPrefDialogDeleted (object sender, Gtk.DeleteEventArgs args)
818
// Remove the addin from the addin_prefs_dialogs Dictionary
819
Gtk.Dialog dialog = sender as Gtk.Dialog;
822
if (dialog.Data.ContainsKey ("AddinId")) {
823
addin_prefs_dialogs.Remove (dialog.Data ["AddinId"] as String);
829
void AddinPrefDialogResponse (object sender, Gtk.ResponseArgs args)
831
AddinPrefDialogDeleted (sender, null);
834
void OnAddinInfoButton (object sender, EventArgs args)
836
Mono.Addins.Addin addin =
837
addin_tree.ActiveAddinData as Mono.Addins.Addin;
842
Gtk.Dialog dialog = null;
843
if (addin_info_dialogs.ContainsKey (addin.Id) == false) {
844
dialog = new AddinInfoDialog (
845
Mono.Addins.Setup.SetupService.GetAddinHeader (addin),
847
dialog.DeleteEvent += AddinInfoDialogDeleted;
848
dialog.Response += AddinInfoDialogResponse;
850
// Store this dialog off in a dictionary so it can be presented
851
// again if the user clicks on the Info button before closing
852
// the original dialog.
853
dialog.Data ["AddinId"] = addin.Id;
854
addin_info_dialogs [addin.Id] = dialog;
856
// It's already opened so just present it again
857
dialog = addin_info_dialogs [addin.Id];
863
[GLib.ConnectBeforeAttribute]
864
void AddinInfoDialogDeleted (object sender, Gtk.DeleteEventArgs args)
866
// Remove the addin from the addin_prefs_dialogs Dictionary
867
Gtk.Dialog dialog = sender as Gtk.Dialog;
870
if (dialog.Data.ContainsKey ("AddinId")) {
871
addin_info_dialogs.Remove (dialog.Data ["AddinId"] as String);
877
void AddinInfoDialogResponse (object sender, Gtk.ResponseArgs args)
879
AddinInfoDialogDeleted (sender, null);
882
void SetupPropertyEditor (IPropertyEditor peditor)
884
// Ensure the key exists
885
Preferences.Get (peditor.Key);
891
static Gtk.Label MakeLabel (string label_text, params object[] args)
894
label_text = String.Format (label_text, args);
896
Gtk.Label label = new Gtk.Label (label_text);
898
label.UseMarkup = true;
899
label.Justify = Gtk.Justification.Left;
900
label.SetAlignment (0.0f, 0.5f);
906
static Gtk.CheckButton MakeCheckButton (string label_text)
908
Gtk.Label label = MakeLabel (label_text);
910
Gtk.CheckButton check = new Gtk.CheckButton ();
917
static Gtk.Label MakeTipLabel (string label_text)
919
Gtk.Label label = MakeLabel ("<small>{0}</small>", label_text);
920
label.LineWrap = true;
925
// Font Change handler
927
void OnFontButtonClicked (object sender, EventArgs args)
929
Gtk.FontSelectionDialog font_dialog =
930
new Gtk.FontSelectionDialog (
931
Catalog.GetString ("Choose Note Font"));
933
string font_name = (string)
934
Preferences.Get (Preferences.CUSTOM_FONT_FACE);
935
font_dialog.SetFontName (font_name);
937
if ((int) Gtk.ResponseType.Ok == font_dialog.Run ()) {
938
if (font_dialog.FontName != font_name) {
939
Preferences.Set (Preferences.CUSTOM_FONT_FACE,
940
font_dialog.FontName);
942
UpdateFontButton (font_dialog.FontName);
946
font_dialog.Destroy ();
949
void UpdateFontButton (string font_desc)
951
Pango.FontDescription desc =
952
Pango.FontDescription.FromString (font_desc);
954
// Set the size label
955
font_size.Text = (desc.Size / Pango.Scale.PangoScale).ToString ();
957
desc.UnsetFields (Pango.FontMask.Size);
959
// Set the font name label
960
font_face.Markup = String.Format ("<span font_desc='{0}'>{1}</span>",
965
private void OnAdvancedSyncConfigButton (object sender, EventArgs args)
967
// Get saved behavior
968
SyncTitleConflictResolution savedBehavior = SyncTitleConflictResolution.Cancel;
969
object dlgBehaviorPref = Preferences.Get (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR);
970
if (dlgBehaviorPref != null && dlgBehaviorPref is int) // TODO: Check range of this int
971
savedBehavior = (SyncTitleConflictResolution)dlgBehaviorPref;
974
Gtk.Dialog advancedDlg =
975
new Gtk.Dialog (Catalog.GetString ("Other Synchronization Options"),
977
Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.Modal | Gtk.DialogFlags.NoSeparator,
978
Gtk.Stock.Close, Gtk.ResponseType.Close);
981
new Gtk.Label (Catalog.GetString ("When a conflict is detected between " +
982
"a local note and a note on the configured " +
983
"synchronization server:"));
987
promptOnConflictRadio =
988
new Gtk.RadioButton (Catalog.GetString ("Always ask me what to do."));
989
promptOnConflictRadio.Toggled += OnConflictOptionToggle;
991
renameOnConflictRadio =
992
new Gtk.RadioButton (promptOnConflictRadio, Catalog.GetString ("Rename my local note."));
993
renameOnConflictRadio.Toggled += OnConflictOptionToggle;
995
overwriteOnConflictRadio =
996
new Gtk.RadioButton (promptOnConflictRadio, Catalog.GetString ("Replace my local note with the server's update."));
997
overwriteOnConflictRadio.Toggled += OnConflictOptionToggle;
999
switch (savedBehavior) {
1000
case SyncTitleConflictResolution.RenameExistingNoUpdate:
1001
renameOnConflictRadio.Active = true;
1003
case SyncTitleConflictResolution.OverwriteExisting:
1004
overwriteOnConflictRadio.Active = true;
1007
promptOnConflictRadio.Active = true;
1011
Gtk.VBox vbox = new Gtk.VBox ();
1012
vbox.BorderWidth = 18;
1014
vbox.PackStart (promptOnConflictRadio);
1015
vbox.PackStart (renameOnConflictRadio);
1016
vbox.PackStart (overwriteOnConflictRadio);
1018
advancedDlg.VBox.PackStart (label, false, false, 6);
1019
advancedDlg.VBox.PackStart (vbox, false, false, 0);
1021
advancedDlg.ShowAll ();
1025
advancedDlg.Destroy ();
1028
private void OnConflictOptionToggle (object sender, EventArgs args)
1030
SyncTitleConflictResolution newBehavior = SyncTitleConflictResolution.Cancel;
1032
if (renameOnConflictRadio.Active)
1033
newBehavior = SyncTitleConflictResolution.RenameExistingNoUpdate;
1034
else if (overwriteOnConflictRadio.Active)
1035
newBehavior = SyncTitleConflictResolution.OverwriteExisting;
1037
Preferences.Set (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR,
1041
private void OnAppAddinListChanged (object sender, EventArgs args)
1043
SyncServiceAddin [] newAddinsArray = Tomboy.DefaultNoteManager.AddinManager.GetSyncServiceAddins ();
1044
Array.Sort (newAddinsArray, CompareSyncAddinsByName);
1045
List<SyncServiceAddin> newAddins = new List<SyncServiceAddin> (newAddinsArray);
1047
// Build easier-to-navigate list if addins currently in the combo
1048
List<SyncServiceAddin> currentAddins = new List<SyncServiceAddin> ();
1049
foreach (object [] currentRow in syncAddinStore) {
1050
SyncServiceAddin currentAddin = currentRow [0] as SyncServiceAddin;
1051
if (currentAddin != null)
1052
currentAddins.Add (currentAddin);
1056
// TODO: Would be nice to insert these alphabetically instead
1057
foreach (SyncServiceAddin newAddin in newAddins) {
1058
if (!currentAddins.Contains (newAddin)) {
1059
Gtk.TreeIter iter = syncAddinStore.Append ();
1060
syncAddinStore.SetValue (iter, 0, newAddin);
1061
syncAddinIters [newAddin.Id] = iter;
1065
// Remove deleted addins
1066
foreach (SyncServiceAddin currentAddin in currentAddins) {
1067
if (!newAddins.Contains (currentAddin)) {
1068
Gtk.TreeIter iter = syncAddinIters [currentAddin.Id];
1069
syncAddinStore.Remove (ref iter);
1070
syncAddinIters.Remove (currentAddin.Id);
1072
// FIXME: Lots of hacky stuff in here...rushing before freeze
1073
if (currentAddin == selectedSyncAddin) {
1074
if (syncAddinPrefsWidget != null &&
1075
!syncAddinPrefsWidget.Sensitive)
1076
OnResetSyncAddinButton (null, null);
1078
Gtk.TreeIter active_iter;
1079
if (syncAddinStore.GetIterFirst (out active_iter) == true) {
1080
syncAddinCombo.SetActiveIter (active_iter);
1082
OnSyncAddinComboChanged (null, null);
1089
void OnSyncAddinComboChanged (object sender, EventArgs args)
1091
if (syncAddinPrefsWidget != null) {
1092
syncAddinPrefsContainer.Remove (syncAddinPrefsWidget);
1093
syncAddinPrefsWidget.Hide ();
1094
syncAddinPrefsWidget.Destroy ();
1095
syncAddinPrefsWidget = null;
1099
if (syncAddinCombo.GetActiveIter (out iter)) {
1100
SyncServiceAddin newAddin =
1101
syncAddinStore.GetValue (iter, 0) as SyncServiceAddin;
1102
if (newAddin != null) {
1103
selectedSyncAddin = newAddin;
1104
syncAddinPrefsWidget = selectedSyncAddin.CreatePreferencesControl (OnSyncAddinPrefsChanged);
1105
if (syncAddinPrefsWidget == null) {
1106
Gtk.Label l = new Gtk.Label (Catalog.GetString ("Not configurable"));
1109
syncAddinPrefsWidget = l;
1112
syncAddinPrefsWidget.Show ();
1113
syncAddinPrefsContainer.PackStart (syncAddinPrefsWidget, false, false, 0);
1115
resetSyncAddinButton.Sensitive = false;
1116
saveSyncAddinButton.Sensitive = false;
1119
selectedSyncAddin = null;
1120
resetSyncAddinButton.Sensitive = false;
1121
saveSyncAddinButton.Sensitive = false;
1126
void OnResetSyncAddinButton (object sender, EventArgs args)
1128
if (selectedSyncAddin == null)
1131
// User doesn't get a choice if this is invoked by disabling the addin
1132
// FIXME: null sender check is lame!
1133
if (sender != null) {
1134
// Prompt the user about what they're about to do since
1135
// it's not really recommended to switch back and forth
1136
// between sync services.
1137
HIGMessageDialog dialog =
1138
new HIGMessageDialog (null,
1139
Gtk.DialogFlags.Modal,
1140
Gtk.MessageType.Question,
1141
Gtk.ButtonsType.YesNo,
1142
Catalog.GetString ("Are you sure?"),
1144
"Clearing your synchronization settings is not recommended. " +
1145
"You may be forced to synchronize all of your notes again " +
1146
"when you save new settings."));
1147
int response = dialog.Run ();
1149
if (response != (int) Gtk.ResponseType.Yes)
1151
} else { // FIXME: Weird place for this to go. User should be able to cancel disabling of addin, anyway
1152
HIGMessageDialog dialog =
1153
new HIGMessageDialog (null,
1154
Gtk.DialogFlags.Modal,
1155
Gtk.MessageType.Info,
1157
Catalog.GetString ("Resetting Synchronization Settings"),
1159
"You have disabled the configured synchronization service. " +
1160
"Your synchronization settings will now be cleared. " +
1161
"You may be forced to synchronize all of your notes again " +
1162
"when you save new settings."));
1168
selectedSyncAddin.ResetConfiguration ();
1169
} catch (Exception e) {
1170
Logger.Debug ("Error calling {0}.ResetConfiguration: {1}\n{2}",
1171
selectedSyncAddin.Id, e.Message, e.StackTrace);
1175
Preferences.SYNC_SELECTED_SERVICE_ADDIN,
1178
// Reset conflict handling behavior
1180
Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR,
1181
Preferences.GetDefault (Preferences.SYNC_CONFIGURED_CONFLICT_BEHAVIOR));
1183
SyncManager.ResetClient ();
1185
syncAddinCombo.Sensitive = true;
1186
resetSyncAddinButton.Sensitive = false;
1187
saveSyncAddinButton.Sensitive = true;
1188
if (syncAddinPrefsWidget != null)
1189
syncAddinPrefsWidget.Sensitive = true;
1193
/// Attempt to save/test the connection to the sync addin.
1195
void OnSaveSyncAddinButton (object sender, EventArgs args)
1197
if (selectedSyncAddin == null)
1201
string errorMsg = null;
1203
GdkWindow.Cursor = new Gdk.Cursor (Gdk.CursorType.Watch);
1204
GdkWindow.Display.Flush ();
1205
saved = selectedSyncAddin.SaveConfiguration ();
1206
} catch (TomboySyncException syncEx) {
1207
errorMsg = syncEx.Message;
1208
} catch (Exception e) {
1209
Logger.Debug ("Unexpected error calling {0}.SaveConfiguration: {1}\n{2}",
1210
selectedSyncAddin.Id, e.Message, e.StackTrace);
1212
GdkWindow.Cursor = null;
1213
GdkWindow.Display.Flush ();
1216
HIGMessageDialog dialog;
1219
Preferences.SYNC_SELECTED_SERVICE_ADDIN,
1220
selectedSyncAddin.Id);
1222
syncAddinCombo.Sensitive = false;
1223
syncAddinPrefsWidget.Sensitive = false;
1224
resetSyncAddinButton.Sensitive = true;
1225
saveSyncAddinButton.Sensitive = false;
1227
SyncManager.ResetClient ();
1229
// Give the user a visual letting them know that connecting
1231
// TODO: Replace Yes/No with Sync/Close
1233
new HIGMessageDialog (this,
1234
Gtk.DialogFlags.Modal,
1235
Gtk.MessageType.Info,
1236
Gtk.ButtonsType.YesNo,
1237
Catalog.GetString ("Connection successful"),
1239
"Tomboy is ready to synchronize your notes. Would you like to synchronize them now?"));
1240
int response = dialog.Run ();
1243
if (response == (int) Gtk.ResponseType.Yes)
1244
// TODO: Put this voodoo in a method somewhere
1245
Tomboy.ActionManager ["NoteSynchronizationAction"].Activate ();
1247
// TODO: Change the SyncServiceAddin API so the call to
1248
// SaveConfiguration has a way of passing back an exception
1249
// or other text so it can be displayed to the user.
1251
Preferences.SYNC_SELECTED_SERVICE_ADDIN,
1254
syncAddinCombo.Sensitive = true;
1255
syncAddinPrefsWidget.Sensitive = true;
1256
resetSyncAddinButton.Sensitive = false;
1257
saveSyncAddinButton.Sensitive = true;
1259
// Give the user a visual letting them know that connecting
1261
if (errorMsg == null) {
1262
errorMsg = Catalog.GetString ("Please check your information and " +
1263
"try again. The log file {0} may " +
1264
"contain more information about the error.");
1265
string logPath = System.IO.Path.Combine (Services.NativeApplication.LogDirectory,
1267
errorMsg = String.Format (errorMsg, logPath);
1270
new HIGMessageDialog (this,
1271
Gtk.DialogFlags.Modal,
1272
Gtk.MessageType.Warning,
1273
Gtk.ButtonsType.Close,
1274
Catalog.GetString ("Error connecting"),
1281
void OnSyncAddinPrefsChanged (object sender, EventArgs args)
1283
// Enable/disable the save button based on required fields
1284
if (selectedSyncAddin != null)
1285
saveSyncAddinButton.Sensitive = selectedSyncAddin.AreSettingsValid;
1288
void OpenTemplateButtonClicked (object sender, EventArgs args)
1290
NoteManager manager = Tomboy.DefaultNoteManager;
1291
Note template_note = manager.GetOrCreateTemplateNote ();
1293
// Open the template note
1294
template_note.Window.Show ();
1298
// TODO: Figure out how to use Mono.Addins.Gui.AddinInfoDialog here instead.
1299
// The class here is adapted directly from Mono.Addins.Gui.AddinInfoDialog.
1300
class AddinInfoDialog : Gtk.Dialog
1302
Mono.Addins.Setup.AddinHeader info;
1303
Gtk.Label info_label;
1305
public AddinInfoDialog (
1306
Mono.Addins.Setup.AddinHeader info,
1310
Gtk.DialogFlags.DestroyWithParent | Gtk.DialogFlags.NoSeparator,
1311
Gtk.Stock.Close, Gtk.ResponseType.Close)
1315
// TODO: Change this icon to be an addin/package icon
1317
new Gtk.Image (Gtk.Stock.DialogInfo, Gtk.IconSize.Dialog);
1320
info_label = new Gtk.Label ();
1321
info_label.Xalign = 0;
1322
info_label.Yalign = 0;
1323
info_label.UseMarkup = true;
1324
info_label.UseUnderline = false;
1325
info_label.Wrap = true;
1327
Gtk.HBox hbox = new Gtk.HBox (false, 6);
1328
Gtk.VBox vbox = new Gtk.VBox (false, 12);
1329
hbox.BorderWidth = 12;
1330
vbox.BorderWidth = 6;
1332
hbox.PackStart (icon, false, false, 0);
1333
hbox.PackStart (vbox, true, true, 0);
1335
vbox.PackStart (info_label, true, true, 0);
1339
VBox.PackStart (hbox, true, true, 0);
1346
StringBuilder sb = new StringBuilder ();
1347
sb.Append ("<b><big>" + info.Name + "</big></b>\n\n");
1349
if (info.Description != string.Empty)
1350
sb.Append (info.Description + "\n\n");
1352
sb.Append ("<small>");
1354
sb.Append (string.Format (
1357
Catalog.GetString ("Version:"),
1360
if (info.Author != string.Empty)
1361
sb.Append (string.Format (
1364
Catalog.GetString ("Author:"),
1367
if (info.Copyright != string.Empty)
1368
sb.Append (string.Format (
1371
Catalog.GetString ("Copyright:"),
1374
if (info.Dependencies.Count > 0) {
1375
sb.Append (string.Format (
1377
Catalog.GetString ("Add-in Dependencies:")));
1378
foreach (Mono.Addins.Description.Dependency dep in info.Dependencies) {
1379
sb.Append (dep.Name + "\n");
1383
sb.Append ("</small>");
1385
info_label.Markup = sb.ToString ();