[Mono-docs-list] store/restore editing settings
Ben Maurer
bmaurer@users.sourceforge.net
Wed, 24 Sep 2003 21:12:06 -0400
--=-D8yQW1mllcbH6YrgBXzM
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
Ok, made a patch,
On Wed, 2003-09-24 at 19:42, Miguel de Icaza wrote:
> I would like to use ~/.etc/monodoc instead of ~/.monodoc
I am using what i get from
Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData)
If we want to change that, then it will change for monodoc (I actually
think that might be a cool idea).
> The code should create the directory if it is not existant.
Done.
> The settings should be a serializer on the Settings class, not
> on bool, so we can easily add more information.
Done. This turns in to a sorta funky singleton design (but is sorta cool
too!). I also integrated some functions with the editing stuff.
Also, changes take affect right after they are made, the display is
refreshed to add/remove [edit]. Editing on is now the default.
-- Ben
--=-D8yQW1mllcbH6YrgBXzM
Content-Disposition: attachment; filename=editsettings.diff
Content-Type: text/x-patch; name=editsettings.diff; charset=UTF-8
Content-Transfer-Encoding: 7bit
? browser.gladep
Index: Makefile.am
===================================================================
RCS file: /cvs/public/monodoc/browser/Makefile.am,v
retrieving revision 1.36
diff -u -r1.36 Makefile.am
--- Makefile.am 8 Sep 2003 03:40:37 -0000 1.36
+++ Makefile.am 25 Sep 2003 01:17:01 -0000
@@ -6,7 +6,7 @@
CSC=mcs
-monodoc_sources = $(srcdir)/man-provider.cs $(srcdir)/monohb-provider.cs $(srcdir)/xhtml-provider.cs $(srcdir)/ecma-provider.cs $(srcdir)/simple-provider.cs $(srcdir)/html-helper.cs $(srcdir)/provider.cs $(srcdir)/index.cs $(srcdir)/error-provider.cs $(srcdir)/ecmaspec-provider.cs $(srcdir)/editing.cs
+monodoc_sources = $(srcdir)/man-provider.cs $(srcdir)/monohb-provider.cs $(srcdir)/xhtml-provider.cs $(srcdir)/ecma-provider.cs $(srcdir)/simple-provider.cs $(srcdir)/html-helper.cs $(srcdir)/provider.cs $(srcdir)/index.cs $(srcdir)/error-provider.cs $(srcdir)/ecmaspec-provider.cs $(srcdir)/editing.cs $(srcdir)/settings.cs
assembler_sources = $(srcdir)/assembler.cs
dump_sources = $(srcdir)/dump.cs
Index: browser.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/browser.cs,v
retrieving revision 1.65
diff -u -r1.65 browser.cs
--- browser.cs 14 Sep 2003 19:18:04 -0000 1.65
+++ browser.cs 25 Sep 2003 01:17:01 -0000
@@ -87,7 +87,6 @@
Glade.XML ui;
Gtk.Window MainWindow;
Style bar_style;
- private bool editable = false;
[Glade.Widget] public Window window1;
[Glade.Widget] TreeView reference_tree;
@@ -95,6 +94,7 @@
[Glade.Widget] Statusbar statusbar;
[Glade.Widget] Button back_button, forward_button;
[Glade.Widget] Entry index_entry;
+ [Glade.Widget] CheckMenuItem editing1;
//
// Editor
@@ -170,6 +170,9 @@
help_tree = RootTree.LoadTree ();
tree_browser = new TreeBrowser (help_tree, reference_tree, this);
+
+ // restore the editing setting
+ editing1.Active = Settings.EnableEditing;
//
// Setup the HTML rendering area
@@ -210,11 +213,6 @@
public enum Mode {
Viewer, Editor
}
-
- public bool IsEditable
- {
- get { return editable; }
- }
public Mode BrowserMode {
get {
@@ -396,7 +394,10 @@
void OnEditingActivate (object o, EventArgs args)
{
- editable = !editable;
+ Settings.EnableEditing = editing1.Active;
+ // refresh, so we can see the [edit] things
+ if (history != null) // catch the case when we are currently loading
+ history.ActivateCurrent ();
}
void OnCollapseActivate (object o, EventArgs args)
Index: ecma-provider.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/ecma-provider.cs,v
retrieving revision 1.69
diff -u -r1.69 ecma-provider.cs
--- ecma-provider.cs 7 Sep 2003 16:36:44 -0000 1.69
+++ ecma-provider.cs 25 Sep 2003 01:17:02 -0000
@@ -1061,18 +1061,9 @@
}
}
-
- static bool editing = false;
-
- static ExtensionObject ()
- {
- if (Environment.GetEnvironmentVariable ("MONODOC_EDITING") != null)
- editing = true;
- }
-
public bool MonoEditing ()
{
- return editing;
+ return Settings.EnableEditing;
}
}
Index: editing.cs
===================================================================
RCS file: /cvs/public/monodoc/browser/editing.cs,v
retrieving revision 1.4
diff -u -r1.4 editing.cs
--- editing.cs 7 Sep 2003 16:36:45 -0000 1.4
+++ editing.cs 25 Sep 2003 01:17:02 -0000
@@ -136,8 +136,7 @@
public class GlobalChangeset {
#region Load/Save
static XmlSerializer serializer = new XmlSerializer (typeof (GlobalChangeset));
- static string settingsPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), ".monodoc");
- static string changesetFile = Path.Combine (settingsPath, "changeset.xml");
+ static string changesetFile = Path.Combine (Settings.SettingsPath, "changeset.xml");
public static GlobalChangeset Load ()
{
@@ -154,7 +153,7 @@
public void Save ()
{
- VerifyDirectoryExists (new DirectoryInfo (settingsPath));
+ Settings.EnsureSettingsDirectory ();
serializer.Serialize (File.Create (changesetFile), this);
}
Index: settings.cs
===================================================================
RCS file: settings.cs
diff -N settings.cs
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ settings.cs 25 Sep 2003 01:17:02 -0000
@@ -0,0 +1,55 @@
+using System;
+using System.IO;
+using System.Xml;
+using System.Xml.Serialization;
+
+namespace Monodoc {
+ public class Settings {
+ #region Loading/Saving
+ static string settingsFile;
+ static XmlSerializer settingsSerializer = new XmlSerializer (typeof (Settings));
+ static Settings Instance;
+
+ static Settings ()
+ {
+ SettingsPath = Path.Combine (Environment.GetFolderPath (Environment.SpecialFolder.ApplicationData), ".monodoc");
+ settingsFile = Path.Combine (SettingsPath, "settings.xml");
+ if (File.Exists (settingsFile))
+ Instance = (Settings) settingsSerializer.Deserialize (new XmlTextReader (settingsFile));
+ else
+ Instance = new Settings ();
+ }
+
+ public static void Save ()
+ {
+ EnsureSettingsDirectory ();
+ settingsSerializer.Serialize (File.Create (settingsFile), Instance);
+ }
+
+ // these can be used for other types of settings too
+ public static string SettingsPath;
+ public static void EnsureSettingsDirectory ()
+ {
+ DirectoryInfo d = new DirectoryInfo (SettingsPath);
+ if (!d.Exists)
+ d.Create ();
+ }
+
+ #endregion
+
+ // public to allow serialization
+ public bool enableEditing = true;
+
+ public static bool EnableEditing {
+ get {
+ return Instance.enableEditing;
+ }
+ set {
+ if (Instance.enableEditing != value) {
+ Instance.enableEditing = value;
+ Save ();
+ }
+ }
+ }
+ }
+}
--=-D8yQW1mllcbH6YrgBXzM--