restructuring for gtk-sharp/gnome-sharp split
svn path=/trunk/gtk-sharp/; revision=63087
This commit is contained in:
parent
e54d850625
commit
b755ca4574
31 changed files with 0 additions and 2378 deletions
|
@ -1,116 +0,0 @@
|
|||
// EditorShell.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public class EditorNotSupportedException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
public class InvalidGladeKeyException : Exception
|
||||
{
|
||||
public InvalidGladeKeyException (string control_name) : base ("No such glade entry \"" + control_name + "\"")
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class EditorShell
|
||||
{
|
||||
ArrayList editors = new ArrayList ();
|
||||
Hashtable by_key = new Hashtable ();
|
||||
Glade.XML gxml;
|
||||
GConf.ChangeSet cs = null;
|
||||
|
||||
public EditorShell (Glade.XML gxml)
|
||||
{
|
||||
this.gxml = gxml;
|
||||
}
|
||||
|
||||
public EditorShell (Glade.XML gxml, GConf.ChangeSet cs)
|
||||
{
|
||||
this.gxml = gxml;
|
||||
this.cs = cs;
|
||||
}
|
||||
|
||||
public void Add (PropertyEditor editor)
|
||||
{
|
||||
editors.Add (editor);
|
||||
if (cs != null)
|
||||
editor.ChangeSet = cs;
|
||||
editor.Setup ();
|
||||
}
|
||||
|
||||
public void Add (string key, string control_name)
|
||||
{
|
||||
Add (key, control_name, null, null);
|
||||
}
|
||||
|
||||
public void Add (string key, string control_name, Type enum_type, int[] enum_values)
|
||||
{
|
||||
PropertyEditor editor;
|
||||
Gtk.Widget control = gxml[control_name];
|
||||
|
||||
if (control == null)
|
||||
throw new InvalidGladeKeyException (control_name);
|
||||
|
||||
//if (control is Gnome.ColorPicker)
|
||||
//editor = new PropertyEditorColorPicker (key, (Gnome.ColorPicker) control);
|
||||
else if (control is Gnome.FileEntry)
|
||||
editor = new PropertyEditorFileEntry (key, (Gnome.FileEntry) control);
|
||||
else if (control is Gtk.SpinButton)
|
||||
editor = new PropertyEditorSpinButton (key, (Gtk.SpinButton) control);
|
||||
else if (control is Gtk.RadioButton)
|
||||
editor = new PropertyEditorRadioButton (key, (Gtk.RadioButton) control, enum_type, enum_values);
|
||||
else if (control is Gtk.ToggleButton)
|
||||
editor = new PropertyEditorToggleButton (key, (Gtk.ToggleButton) control);
|
||||
else if (control is Gtk.Entry)
|
||||
editor = new PropertyEditorEntry (key, (Gtk.Entry) control);
|
||||
/*else if (control is Gtk.OptionMenu)
|
||||
editor = new PropertyEditorOptionMenu (key, (Gtk.OptionMenu) control, enum_type, enum_values);*/
|
||||
else
|
||||
throw new EditorNotSupportedException ();
|
||||
|
||||
by_key.Add (key, editor);
|
||||
Add (editor);
|
||||
}
|
||||
|
||||
public void Add (string key, string control_name, Type enum_type)
|
||||
{
|
||||
Add (key, control_name, enum_type, null);
|
||||
}
|
||||
|
||||
public void AddGuard (string key, string control_name)
|
||||
{
|
||||
if (!by_key.Contains (key))
|
||||
return;
|
||||
Gtk.Widget control = gxml[control_name];
|
||||
if (control == null)
|
||||
throw new InvalidGladeKeyException (control_name);
|
||||
|
||||
PropertyEditorBool editor = by_key[key] as PropertyEditorBool;
|
||||
if (editor == null)
|
||||
throw new EditorNotSupportedException ();
|
||||
|
||||
editor.AddGuard (control);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
if ENABLE_GNOME
|
||||
TARGET=$(ASSEMBLY)
|
||||
else
|
||||
TARGET=
|
||||
endif
|
||||
|
||||
ASSEMBLY = $(ASSEMBLY_NAME).dll
|
||||
ASSEMBLY_NAME = gconf-sharp-peditors
|
||||
noinst_DATA = $(TARGET) $(POLICY_ASSEMBLIES)
|
||||
CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb gtk-sharp.snk $(POLICY_ASSEMBLIES) $(POLICY_CONFIGS)
|
||||
|
||||
POLICY_ASSEMBLIES = $(addsuffix .$(ASSEMBLY), $(addprefix policy., $(POLICY_VERSIONS)))
|
||||
POLICY_CONFIGS = $(addsuffix .config, $(addprefix policy., $(POLICY_VERSIONS)))
|
||||
|
||||
EXTRA_DIST = \
|
||||
PropertyEditorColorPicker.cs \
|
||||
$(sources)
|
||||
|
||||
references = \
|
||||
/r:../../glib/glib-sharp.dll /r:../../pango/pango-sharp.dll /r:../../atk/atk-sharp.dll /r:../../gdk/gdk-sharp.dll /r:../../gtk/gtk-sharp.dll /r:../../art/art-sharp.dll /r:../../gnome/gnome-sharp.dll /r:../../glade/glade-sharp.dll /r:../GConf/gconf-sharp.dll
|
||||
|
||||
sources = \
|
||||
PropertyEditor.cs \
|
||||
PropertyEditorBool.cs \
|
||||
PropertyEditorEnum.cs \
|
||||
PropertyEditorEntry.cs \
|
||||
PropertyEditorFileEntry.cs \
|
||||
PropertyEditorOptionMenu.cs \
|
||||
PropertyEditorRadioButton.cs \
|
||||
PropertyEditorSpinButton.cs \
|
||||
PropertyEditorToggleButton.cs \
|
||||
EditorShell.cs
|
||||
|
||||
build_sources = $(addprefix $(srcdir)/, $(sources)) ../../AssemblyInfo.cs
|
||||
|
||||
gtk-sharp.snk: $(top_srcdir)/gtk-sharp.snk
|
||||
cp $(top_srcdir)/gtk-sharp.snk .
|
||||
|
||||
if PLATFORM_WIN32
|
||||
GAPI_CDECL_INSERT=$(top_srcdir)/gapi-cdecl-insert --keyfile=gtk-sharp.snk $(ASSEMBLY)
|
||||
else
|
||||
GAPI_CDECL_INSERT=
|
||||
endif
|
||||
|
||||
$(ASSEMBLY): $(build_sources) gtk-sharp.snk
|
||||
@rm -f $(ASSEMBLY).mdb
|
||||
$(CSC) $(CSFLAGS) /out:$(ASSEMBLY) /target:library $(references) $(build_sources)
|
||||
$(GAPI_CDECL_INSERT)
|
||||
|
||||
$(POLICY_ASSEMBLIES): $(top_builddir)/policy.config gtk-sharp.snk
|
||||
@for i in $(POLICY_VERSIONS); do \
|
||||
echo "Creating policy.$$i.$(ASSEMBLY)"; \
|
||||
sed -e "s/@ASSEMBLY_NAME@/$(ASSEMBLY_NAME)/" -e "s/@POLICY@/$$i/" $(top_builddir)/policy.config > policy.$$i.config; \
|
||||
$(AL) -link:policy.$$i.config -out:policy.$$i.$(ASSEMBLY) -keyfile:gtk-sharp.snk; \
|
||||
done
|
||||
|
||||
install-data-local:
|
||||
@if test -n '$(TARGET)'; then \
|
||||
echo "$(GACUTIL) /i $(ASSEMBLY) /f $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /i $(ASSEMBLY) /f $(GACUTIL_FLAGS) || exit 1; \
|
||||
if test -n '$(POLICY_VERSIONS)'; then \
|
||||
for i in $(POLICY_VERSIONS); do \
|
||||
echo "$(GACUTIL) /i policy.$$i.$(ASSEMBLY) /f $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /i policy.$$i.$(ASSEMBLY) /f $(GACUTIL_FLAGS) || exit 1; \
|
||||
done \
|
||||
fi \
|
||||
fi
|
||||
|
||||
uninstall-local:
|
||||
@if test -n '$(TARGET)'; then \
|
||||
echo "$(GACUTIL) /u $(ASSEMBLY_NAME) $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /u $(ASSEMBLY_NAME) $(GACUTIL_FLAGS) || exit 1; \
|
||||
if test -n '$(POLICY_VERSIONS)'; then \
|
||||
for i in $(POLICY_VERSIONS); do \
|
||||
echo "$(GACUTIL) /u policy.$$i.$(ASSEMBLY_NAME) $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /u policy.$$i.$(ASSEMBLY_NAME) $(GACUTIL_FLAGS) || exit 1; \
|
||||
done \
|
||||
fi \
|
||||
fi
|
||||
|
|
@ -1,96 +0,0 @@
|
|||
// PropertyEditor.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
|
||||
public abstract class PropertyEditor
|
||||
{
|
||||
protected abstract void ValueChanged (object sender, NotifyEventArgs args);
|
||||
protected abstract void ConnectHandlers ();
|
||||
|
||||
string key;
|
||||
Client client;
|
||||
ChangeSet cs;
|
||||
Widget control;
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return key; }
|
||||
}
|
||||
|
||||
public Widget Control
|
||||
{
|
||||
get { return control; }
|
||||
}
|
||||
|
||||
protected object Get ()
|
||||
{
|
||||
ClientBase c = (cs != null) ? (ClientBase) cs : (ClientBase) client;
|
||||
try {
|
||||
return c.Get (key);
|
||||
} catch (NoSuchKeyException e) {
|
||||
}
|
||||
|
||||
if (cs != null)
|
||||
{
|
||||
try {
|
||||
return client.Get (key);
|
||||
} catch (NoSuchKeyException e) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected virtual void Set (object val)
|
||||
{
|
||||
ClientBase c = (cs != null) ? (ClientBase) cs : (ClientBase) client;
|
||||
c.Set (key, val);
|
||||
}
|
||||
|
||||
public virtual void Setup ()
|
||||
{
|
||||
if (client == null)
|
||||
client = new Client ();
|
||||
|
||||
ValueChanged (client, new NotifyEventArgs (key, Get ()));
|
||||
ConnectHandlers ();
|
||||
client.AddNotify (key, new NotifyEventHandler (ValueChanged));
|
||||
}
|
||||
|
||||
public Client Client
|
||||
{
|
||||
get { return client; }
|
||||
set { client = value; }
|
||||
}
|
||||
|
||||
public ChangeSet ChangeSet
|
||||
{
|
||||
get { return cs; }
|
||||
set { cs = value; }
|
||||
}
|
||||
|
||||
public PropertyEditor (string key, Widget control)
|
||||
{
|
||||
this.key = key;
|
||||
this.control = control;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
// PropertyEditorBool.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
public abstract class PropertyEditorBool : PropertyEditor
|
||||
{
|
||||
ArrayList guards = new ArrayList ();
|
||||
|
||||
public void AddGuard (Widget control)
|
||||
{
|
||||
guards.Add (control);
|
||||
control.Sensitive = (bool) Get ();
|
||||
}
|
||||
|
||||
protected override void Set (object val)
|
||||
{
|
||||
bool val_bool = (bool) val;
|
||||
|
||||
foreach (Widget control in guards)
|
||||
control.Sensitive = val_bool;
|
||||
|
||||
base.Set (val);
|
||||
}
|
||||
|
||||
public PropertyEditorBool (string key, Widget control) : base (key, control)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
// PropertyEditorColorPicker.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using Gnome;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
public class PropertyEditorColorPicker : PropertyEditor
|
||||
{
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
if (val == null)
|
||||
return;
|
||||
|
||||
ColorPicker picker = (ColorPicker) Control;
|
||||
Color color = ColorTranslator.FromHtml ((string) val);
|
||||
picker.SetI8 (color.R, color.G, color.B, color.A);
|
||||
}
|
||||
|
||||
byte ToByte (uint val)
|
||||
{
|
||||
return (byte) (val >> 8);
|
||||
}
|
||||
|
||||
void Changed (object obj, Gnome.ColorSetArgs args)
|
||||
{
|
||||
ColorPicker picker = (ColorPicker) Control;
|
||||
Color color = Color.FromArgb (ToByte (picker.Red), ToByte (picker.Green), ToByte (picker.Blue));
|
||||
Set (ColorTranslator.ToHtml (color));
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
ColorPicker picker = (ColorPicker) Control;
|
||||
picker.ColorSet += new Gnome.ColorSetHandler (Changed);
|
||||
}
|
||||
|
||||
public PropertyEditorColorPicker (string key, ColorPicker picker) : base (key, picker)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
// PropertyEditorEntry.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using System;
|
||||
|
||||
public class PropertyEditorEntry : PropertyEditor
|
||||
{
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
if (val == null)
|
||||
return;
|
||||
Entry entry = (Entry) Control;
|
||||
entry.Text = (string) val;
|
||||
}
|
||||
|
||||
void Changed (object obj, EventArgs args)
|
||||
{
|
||||
Entry entry = (Entry) Control;
|
||||
Set (entry.Text);
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
Entry entry = (Entry) Control;
|
||||
entry.Changed += new EventHandler (Changed);
|
||||
}
|
||||
|
||||
public PropertyEditorEntry (string key, Entry entry) : base (key, entry)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
// PropertyEditorEnum.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using System;
|
||||
|
||||
public abstract class PropertyEditorEnum : PropertyEditor
|
||||
{
|
||||
Type enum_type = null;
|
||||
int[] enum_values;
|
||||
bool is_int = false;
|
||||
|
||||
protected int ValueToInt (object val)
|
||||
{
|
||||
if (val is int)
|
||||
{
|
||||
is_int = true;
|
||||
return (int) val;
|
||||
}
|
||||
else if (val is string && enum_type != null)
|
||||
{
|
||||
object enum_val;
|
||||
try {
|
||||
enum_val = Enum.Parse (enum_type, (string) val);
|
||||
} catch (Exception e) {
|
||||
enum_val = 0;
|
||||
}
|
||||
|
||||
int history = -1;
|
||||
for (int i = 0; i < enum_values.Length; i++)
|
||||
{
|
||||
if (enum_values[i] == (int) enum_val)
|
||||
{
|
||||
history = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return history;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Set (object val)
|
||||
{
|
||||
if (is_int)
|
||||
base.Set ((int) val);
|
||||
else if (enum_type != null)
|
||||
{
|
||||
int enum_val = enum_values[(int) val];
|
||||
base.Set (Enum.GetName (enum_type, enum_val));
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyEditorEnum (string key, Gtk.Widget control) : base (key, control)
|
||||
{
|
||||
}
|
||||
|
||||
void InitValues ()
|
||||
{
|
||||
Array values = Enum.GetValues (enum_type);
|
||||
enum_values = new int[values.Length];
|
||||
|
||||
int i = 0;
|
||||
foreach (object val in values)
|
||||
{
|
||||
enum_values[i] = (int) val;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
public PropertyEditorEnum (string key, Gtk.Widget control, Type enum_type, int[] enum_values) : base (key, control)
|
||||
{
|
||||
this.enum_type = enum_type;
|
||||
if (enum_values == null)
|
||||
InitValues ();
|
||||
}
|
||||
|
||||
public PropertyEditorEnum (string key, Gtk.Widget control, Type enum_type) : base (key, control)
|
||||
{
|
||||
this.enum_type = enum_type;
|
||||
InitValues ();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
// PropertyEditorFileEntry.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using Gnome;
|
||||
using System;
|
||||
|
||||
public class PropertyEditorFileEntry : PropertyEditor
|
||||
{
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
if (val == null)
|
||||
return;
|
||||
FileEntry entry = (FileEntry) Control;
|
||||
entry.Filename = (string) val;
|
||||
}
|
||||
|
||||
void Changed (object obj, EventArgs args)
|
||||
{
|
||||
FileEntry entry = (FileEntry) Control;
|
||||
string filename = entry.Filename;
|
||||
if (filename == null)
|
||||
filename = String.Empty;
|
||||
Set (filename);
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
FileEntry entry = (FileEntry) Control;
|
||||
entry.Changed += new EventHandler (Changed);
|
||||
}
|
||||
|
||||
public PropertyEditorFileEntry (string key, FileEntry entry) : base (key, entry)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
// PropertyEditorOptionMenu.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
|
||||
public class PropertyEditorOptionMenu : PropertyEditorEnum
|
||||
{
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
OptionMenu menu = (OptionMenu) Control;
|
||||
menu.SetHistory ((uint) ValueToInt (val));
|
||||
}
|
||||
|
||||
void Changed (object obj, EventArgs args)
|
||||
{
|
||||
OptionMenu menu = (OptionMenu) Control;
|
||||
int history = menu.History;
|
||||
Set (history);
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
OptionMenu menu = (OptionMenu) Control;
|
||||
menu.Changed += new EventHandler (Changed);
|
||||
}
|
||||
|
||||
public PropertyEditorOptionMenu (string key, OptionMenu menu) : base (key, menu)
|
||||
{
|
||||
}
|
||||
|
||||
public PropertyEditorOptionMenu (string key, OptionMenu menu, Type enum_type, int[] enum_values) : base (key, menu, enum_type, enum_values)
|
||||
{
|
||||
}
|
||||
|
||||
public PropertyEditorOptionMenu (string key, OptionMenu menu, Type enum_type) : base (key, menu, enum_type)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,80 +0,0 @@
|
|||
// PropertyEditorRadioButton.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
|
||||
public class PropertyEditorRadioButton : PropertyEditorEnum
|
||||
{
|
||||
GLib.SList group = null;
|
||||
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
int selected = ValueToInt (val);
|
||||
int i = group.Count - 1;
|
||||
foreach (RadioButton button in group)
|
||||
{
|
||||
if (i == selected)
|
||||
{
|
||||
button.Active = true;
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
void Changed (object obj, EventArgs args)
|
||||
{
|
||||
int i = group.Count - 1;
|
||||
foreach (RadioButton button in group)
|
||||
{
|
||||
if (button.Active)
|
||||
{
|
||||
Set (i);
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
foreach (RadioButton button in group)
|
||||
button.Toggled += new EventHandler (Changed);
|
||||
}
|
||||
|
||||
public PropertyEditorRadioButton (string key, RadioButton button) : base (key, button)
|
||||
{
|
||||
group = button.Group;
|
||||
}
|
||||
|
||||
public PropertyEditorRadioButton (string key, RadioButton button, Type enum_type, int[] enum_values) : base (key, button, enum_type, enum_values)
|
||||
{
|
||||
group = button.Group;
|
||||
}
|
||||
|
||||
public PropertyEditorRadioButton (string key, RadioButton button, Type enum_type) : base (key, button, enum_type)
|
||||
{
|
||||
group = button.Group;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
// PropertyEditorSpinButton.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using GtkSharp;
|
||||
using System;
|
||||
|
||||
public class PropertyEditorSpinButton : PropertyEditor
|
||||
{
|
||||
bool is_int;
|
||||
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
SpinButton spin = (SpinButton) Control;
|
||||
is_int = val is int;
|
||||
|
||||
if (is_int)
|
||||
spin.Value = (double) (int) val;
|
||||
else
|
||||
spin.Value = (double) val;
|
||||
}
|
||||
|
||||
void Changed (object obj, EventArgs args)
|
||||
{
|
||||
Adjustment adj = (Adjustment) obj;
|
||||
if (is_int)
|
||||
Set ((int) adj.Value);
|
||||
else
|
||||
Set (adj.Value);
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
SpinButton spin = (SpinButton) Control;
|
||||
spin.Adjustment.ValueChanged += new EventHandler (Changed);
|
||||
}
|
||||
|
||||
public PropertyEditorSpinButton (string key, SpinButton spin) : base (key, spin)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
// PropertyEditorToggleButton.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf.PropertyEditors
|
||||
{
|
||||
using Gtk;
|
||||
using System;
|
||||
|
||||
public class PropertyEditorToggleButton : PropertyEditorBool
|
||||
{
|
||||
protected override void ValueChanged (object sender, NotifyEventArgs args)
|
||||
{
|
||||
object val = args.Value;
|
||||
ToggleButton checkbox = (ToggleButton) Control;
|
||||
checkbox.Active = (bool) val;
|
||||
}
|
||||
|
||||
void Toggled (object obj, EventArgs args)
|
||||
{
|
||||
ToggleButton checkbox = (ToggleButton) Control;
|
||||
Set (checkbox.Active);
|
||||
}
|
||||
|
||||
protected override void ConnectHandlers ()
|
||||
{
|
||||
ToggleButton checkbox = (ToggleButton) Control;
|
||||
checkbox.Toggled += new EventHandler (Toggled);
|
||||
}
|
||||
|
||||
public PropertyEditorToggleButton (string key, ToggleButton checkbox) : base (key, checkbox)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
// ChangeSet.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class ChangeSet : ClientBase, IDisposable
|
||||
{
|
||||
IntPtr Raw = IntPtr.Zero;
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_change_set_new ();
|
||||
|
||||
public ChangeSet ()
|
||||
{
|
||||
Initialize ();
|
||||
Raw = gconf_change_set_new ();
|
||||
}
|
||||
|
||||
internal ChangeSet (IntPtr raw) : base ()
|
||||
{
|
||||
Initialize ();
|
||||
Raw = raw;
|
||||
}
|
||||
|
||||
~ChangeSet ()
|
||||
{
|
||||
Dispose ();
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_change_set_unref (IntPtr cs);
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
if (Raw != IntPtr.Zero)
|
||||
{
|
||||
gconf_change_set_unref (Raw);
|
||||
Raw = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
internal IntPtr Handle {
|
||||
get {
|
||||
return Raw;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_change_set_set (IntPtr cs, string key, IntPtr val);
|
||||
|
||||
internal override void SetValue (string key, Value val)
|
||||
{
|
||||
gconf_change_set_set (Raw, key, val.Handle);
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_change_set_check_value (IntPtr cs, string key, out IntPtr val);
|
||||
|
||||
public override object Get (string key)
|
||||
{
|
||||
IntPtr raw_val;
|
||||
if (gconf_change_set_check_value (Raw, key, out raw_val) && raw_val != IntPtr.Zero) {
|
||||
Value val = new Value (raw_val);
|
||||
val.Managed = false;
|
||||
return val.Get ();
|
||||
} else {
|
||||
throw new NoSuchKeyException ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,158 +0,0 @@
|
|||
// Client.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Client : ClientBase
|
||||
{
|
||||
IntPtr Raw = IntPtr.Zero;
|
||||
Hashtable dirs = new Hashtable ();
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_client_get_default ();
|
||||
|
||||
public Client ()
|
||||
{
|
||||
Initialize ();
|
||||
Raw = gconf_client_get_default ();
|
||||
}
|
||||
|
||||
internal Client (IntPtr raw)
|
||||
{
|
||||
Initialize ();
|
||||
Raw = raw;
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_client_set (IntPtr client, string key, IntPtr val, out IntPtr err);
|
||||
|
||||
internal override void SetValue (string key, Value val)
|
||||
{
|
||||
IntPtr err;
|
||||
gconf_client_set (Raw, key, val.Handle, out err);
|
||||
if (err != IntPtr.Zero)
|
||||
throw new GLib.GException (err);
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_client_get (IntPtr client, string key, out IntPtr err);
|
||||
|
||||
public override object Get (string key)
|
||||
{
|
||||
if (key == null)
|
||||
throw new ArgumentNullException ("key");
|
||||
|
||||
IntPtr err;
|
||||
IntPtr raw = gconf_client_get (Raw, key, out err);
|
||||
if (err != IntPtr.Zero)
|
||||
throw new GLib.GException (err);
|
||||
|
||||
if (raw == IntPtr.Zero)
|
||||
throw new NoSuchKeyException (key);
|
||||
|
||||
Value val = new Value (raw);
|
||||
return val.Get ();
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern uint gconf_client_add_dir (IntPtr client, string dir, int preload, out IntPtr err);
|
||||
|
||||
DirectoryConnections GetConnections (string dir)
|
||||
{
|
||||
if (dirs.Contains (dir))
|
||||
return dirs [dir] as DirectoryConnections;
|
||||
|
||||
IntPtr err;
|
||||
gconf_client_add_dir (Raw, dir, 0, out err);
|
||||
if (err != IntPtr.Zero)
|
||||
throw new GLib.GException (err);
|
||||
|
||||
DirectoryConnections result = new DirectoryConnections (this, dir);
|
||||
dirs.Add (dir, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
class DirectoryConnections {
|
||||
|
||||
string path;
|
||||
IntPtr handle;
|
||||
Hashtable connections = new Hashtable ();
|
||||
|
||||
public DirectoryConnections (Client client, string dir)
|
||||
{
|
||||
handle = client.Raw;
|
||||
path = dir;
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern uint gconf_client_notify_add (IntPtr client, string dir, NotifyFuncNative func, IntPtr user_data, IntPtr destroy_notify, out IntPtr err);
|
||||
|
||||
public void Add (NotifyEventHandler notify)
|
||||
{
|
||||
IntPtr error;
|
||||
uint id = gconf_client_notify_add (handle, path, NotifyWrapper.Wrap (notify), IntPtr.Zero, IntPtr.Zero, out error);
|
||||
if (error != IntPtr.Zero)
|
||||
throw new GLib.GException (error);
|
||||
|
||||
connections [id] = notify;
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_client_notify_remove (IntPtr client, uint cnxn);
|
||||
|
||||
public void Remove (NotifyEventHandler notify)
|
||||
{
|
||||
ArrayList removes = new ArrayList ();
|
||||
foreach (uint id in connections.Keys)
|
||||
if (connections [id] == notify)
|
||||
removes.Add (id);
|
||||
foreach (uint id in removes) {
|
||||
gconf_client_notify_remove (handle, id);
|
||||
connections.Remove (id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddNotify (string dir, NotifyEventHandler notify)
|
||||
{
|
||||
GetConnections (dir).Add (notify);
|
||||
}
|
||||
|
||||
public void RemoveNotify (string dir, NotifyEventHandler notify)
|
||||
{
|
||||
GetConnections (dir).Remove (notify);
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_client_suggest_sync (IntPtr client, out IntPtr err);
|
||||
|
||||
public void SuggestSync ()
|
||||
{
|
||||
IntPtr err;
|
||||
gconf_client_suggest_sync (Raw, out err);
|
||||
if (err != IntPtr.Zero)
|
||||
throw new GLib.GException (err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
// ClientBase.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public abstract class ClientBase
|
||||
{
|
||||
public abstract object Get (string key);
|
||||
internal abstract void SetValue (string key, Value val);
|
||||
|
||||
public void Set (string key, object val)
|
||||
{
|
||||
SetValue (key, new Value (val));
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_is_initialized ();
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_init (int argc, IntPtr argv, out IntPtr err);
|
||||
|
||||
internal void Initialize ()
|
||||
{
|
||||
if (!gconf_is_initialized ())
|
||||
{
|
||||
IntPtr err;
|
||||
gconf_init (0, IntPtr.Zero, out err);
|
||||
if (err != IntPtr.Zero)
|
||||
throw new GLib.GException (err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,104 +0,0 @@
|
|||
// Engine.cs - configureation engine wrapper
|
||||
//
|
||||
// Author: Mike Kestner <mkestner@novell.com>
|
||||
//
|
||||
// Copyright (c) 2004 Novell, Inc.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
public class Engine : IDisposable
|
||||
{
|
||||
IntPtr handle = IntPtr.Zero;
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_is_initialized ();
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_init (int argc, IntPtr argv, out IntPtr err);
|
||||
|
||||
static Engine ()
|
||||
{
|
||||
if (!gconf_is_initialized ()) {
|
||||
IntPtr err;
|
||||
gconf_init (0, IntPtr.Zero, out err);
|
||||
if (err != IntPtr.Zero)
|
||||
throw new GLib.GException (err);
|
||||
}
|
||||
}
|
||||
|
||||
private Engine (IntPtr handle)
|
||||
{
|
||||
this.handle = handle;
|
||||
}
|
||||
|
||||
~Engine ()
|
||||
{
|
||||
Dispose ();
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_engine_unref (IntPtr cs);
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
if (handle != IntPtr.Zero) {
|
||||
gconf_engine_unref (handle);
|
||||
handle = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_engine_get_default ();
|
||||
|
||||
static Engine default_engine;
|
||||
public static Engine Default {
|
||||
get {
|
||||
if (default_engine == null)
|
||||
default_engine = new Engine (gconf_engine_get_default ());
|
||||
|
||||
return default_engine;
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_engine_commit_change_set (IntPtr handle, IntPtr cs, bool remove, out IntPtr err);
|
||||
|
||||
public void CommitChangeSet (ChangeSet cs, bool remove_committed)
|
||||
{
|
||||
IntPtr err_handle;
|
||||
if (!gconf_engine_commit_change_set (handle, cs.Handle, remove_committed, out err_handle))
|
||||
throw new GLib.GException (err_handle);
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_engine_reverse_change_set (IntPtr handle, IntPtr cs, out IntPtr err);
|
||||
|
||||
public ChangeSet ReverseChangeSet (ChangeSet cs)
|
||||
{
|
||||
IntPtr err_handle;
|
||||
ChangeSet result = new ChangeSet (gconf_engine_reverse_change_set (handle, cs.Handle, out err_handle));
|
||||
if (err_handle != IntPtr.Zero)
|
||||
throw new GLib.GException (err_handle);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,84 +0,0 @@
|
|||
if ENABLE_GNOME
|
||||
TARGET = $(ASSEMBLY) $(ASSEMBLY).config
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = gconf-sharp-2.0.pc
|
||||
else
|
||||
TARGET =
|
||||
endif
|
||||
noinst_DATA = $(TARGET) $(POLICY_ASSEMBLIES)
|
||||
CLEANFILES = $(ASSEMBLY) $(ASSEMBLY).mdb gtk-sharp.snk $(POLICY_ASSEMBLIES) $(POLICY_CONFIGS)
|
||||
DISTCLEANFILES = gconf-sharp-2.0.pc $(ASSEMBLY).config
|
||||
|
||||
POLICY_ASSEMBLIES = $(addsuffix .$(ASSEMBLY), $(addprefix policy., $(POLICY_VERSIONS)))
|
||||
POLICY_CONFIGS = $(addsuffix .config, $(addprefix policy., $(POLICY_VERSIONS)))
|
||||
|
||||
ASSEMBLY = $(ASSEMBLY_NAME).dll
|
||||
ASSEMBLY_NAME = gconf-sharp
|
||||
|
||||
EXTRA_DIST = \
|
||||
$(sources) \
|
||||
$(ASSEMBLY).config.in \
|
||||
gconf-sharp-2.0.pc.in
|
||||
|
||||
references = \
|
||||
/r:../../glib/glib-sharp.dll
|
||||
|
||||
sources = \
|
||||
ClientBase.cs \
|
||||
Client.cs \
|
||||
ChangeSet.cs \
|
||||
Engine.cs \
|
||||
_Entry.cs \
|
||||
NoSuchKeyException.cs \
|
||||
NotifyEventArgs.cs \
|
||||
NotifyEventHandler.cs \
|
||||
NotifyWrapper.cs \
|
||||
Value.cs
|
||||
|
||||
build_sources = $(addprefix $(srcdir)/, $(sources)) ../../AssemblyInfo.cs
|
||||
|
||||
if PLATFORM_WIN32
|
||||
GAPI_CDECL_INSERT=$(top_srcdir)/gapi-cdecl-insert --keyfile=gtk-sharp.snk $(ASSEMBLY)
|
||||
else
|
||||
GAPI_CDECL_INSERT=
|
||||
endif
|
||||
|
||||
gtk-sharp.snk: $(top_srcdir)/gtk-sharp.snk
|
||||
cp $(top_srcdir)/gtk-sharp.snk .
|
||||
|
||||
$(ASSEMBLY): $(build_sources) gtk-sharp.snk
|
||||
@rm -f $(ASSEMBLY).mdb
|
||||
$(CSC) $(CSFLAGS) /out:$(ASSEMBLY) /target:library $(references) $(build_sources)
|
||||
$(GAPI_CDECL_INSERT)
|
||||
|
||||
$(POLICY_ASSEMBLIES): $(top_builddir)/policy.config gtk-sharp.snk
|
||||
@for i in $(POLICY_VERSIONS); do \
|
||||
echo "Creating policy.$$i.$(ASSEMBLY)"; \
|
||||
sed -e "s/@ASSEMBLY_NAME@/$(ASSEMBLY_NAME)/" -e "s/@POLICY@/$$i/" $(top_builddir)/policy.config > policy.$$i.config; \
|
||||
$(AL) -link:policy.$$i.config -out:policy.$$i.$(ASSEMBLY) -keyfile:gtk-sharp.snk; \
|
||||
done
|
||||
|
||||
install-data-local:
|
||||
@if test -n '$(TARGET)'; then \
|
||||
echo "$(GACUTIL) /i $(ASSEMBLY) /f $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /i $(ASSEMBLY) /f $(GACUTIL_FLAGS) || exit 1; \
|
||||
if test -n '$(POLICY_VERSIONS)'; then \
|
||||
for i in $(POLICY_VERSIONS); do \
|
||||
echo "$(GACUTIL) /i policy.$$i.$(ASSEMBLY) /f $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /i policy.$$i.$(ASSEMBLY) /f $(GACUTIL_FLAGS) || exit 1; \
|
||||
done \
|
||||
fi \
|
||||
fi
|
||||
|
||||
uninstall-local:
|
||||
@if test -n '$(TARGET)'; then \
|
||||
echo "$(GACUTIL) /u $(ASSEMBLY_NAME) $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /u $(ASSEMBLY_NAME) $(GACUTIL_FLAGS) || exit 1; \
|
||||
if test -n '$(POLICY_VERSIONS)'; then \
|
||||
for i in $(POLICY_VERSIONS); do \
|
||||
echo "$(GACUTIL) /u policy.$$i.$(ASSEMBLY_NAME) $(GACUTIL_FLAGS)"; \
|
||||
$(GACUTIL) /u policy.$$i.$(ASSEMBLY_NAME) $(GACUTIL_FLAGS) || exit 1; \
|
||||
done \
|
||||
fi \
|
||||
fi
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
// NoSuchKeyException.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
|
||||
public class NoSuchKeyException : Exception
|
||||
{
|
||||
public NoSuchKeyException ()
|
||||
: base ("The requested GConf key was not found")
|
||||
{
|
||||
}
|
||||
|
||||
public NoSuchKeyException (string key)
|
||||
: base ("Key '" + key + "' not found in GConf")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,44 +0,0 @@
|
|||
// NotifyEventArgs.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
public class NotifyEventArgs : System.EventArgs
|
||||
{
|
||||
string key;
|
||||
object val;
|
||||
|
||||
public NotifyEventArgs (string key, object val)
|
||||
{
|
||||
this.key = key;
|
||||
this.val = val;
|
||||
}
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return key; }
|
||||
}
|
||||
|
||||
public object Value
|
||||
{
|
||||
get { return val; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,23 +0,0 @@
|
|||
// NotifyEventHandler.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
public delegate void NotifyEventHandler (object sender, NotifyEventArgs args);
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
// NotifyWrapper.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
|
||||
internal delegate void NotifyFuncNative (IntPtr client_ptr, uint id, IntPtr entry_ptr, IntPtr user_data);
|
||||
|
||||
internal class NotifyWrapper
|
||||
{
|
||||
static ArrayList refs = new ArrayList ();
|
||||
NotifyEventHandler notify;
|
||||
NotifyFuncNative native;
|
||||
|
||||
void NotifyCB (IntPtr client_ptr, uint id, IntPtr entry_ptr, IntPtr user_data)
|
||||
{
|
||||
Client client = new Client (client_ptr);
|
||||
_Entry entry = new _Entry (entry_ptr);
|
||||
if (entry.ValuePtr == IntPtr.Zero) {
|
||||
notify (client, new NotifyEventArgs (entry.Key, null));
|
||||
return;
|
||||
}
|
||||
Value val = new Value (entry.ValuePtr);
|
||||
val.Managed = false;
|
||||
notify (client, new NotifyEventArgs (entry.Key, val.Get ()));
|
||||
}
|
||||
|
||||
public NotifyWrapper (NotifyEventHandler notify)
|
||||
{
|
||||
this.notify = notify;
|
||||
this.native = new NotifyFuncNative (this.NotifyCB);
|
||||
}
|
||||
|
||||
public static NotifyFuncNative Wrap (NotifyEventHandler notify)
|
||||
{
|
||||
NotifyWrapper wrapper = new NotifyWrapper (notify);
|
||||
refs.Add (wrapper);
|
||||
return wrapper.native;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,296 +0,0 @@
|
|||
// Value.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal enum ValueType
|
||||
{
|
||||
Invalid,
|
||||
String,
|
||||
Int,
|
||||
Float,
|
||||
Bool,
|
||||
Schema,
|
||||
List,
|
||||
Pair
|
||||
};
|
||||
|
||||
internal struct NativeValue
|
||||
{
|
||||
public ValueType type;
|
||||
}
|
||||
|
||||
internal class InvalidValueTypeException : Exception
|
||||
{
|
||||
}
|
||||
|
||||
internal class Value : IDisposable
|
||||
{
|
||||
IntPtr Raw = IntPtr.Zero;
|
||||
ValueType val_type = ValueType.Invalid;
|
||||
bool managed = true;
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_value_set_string (IntPtr value, string data);
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_value_set_int (IntPtr value, int data);
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_value_set_float (IntPtr value, double data);
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_value_set_bool (IntPtr value, bool data);
|
||||
|
||||
ValueType LookupType (object data)
|
||||
{
|
||||
if (data is string) {
|
||||
return ValueType.String;
|
||||
} else if (data is int) {
|
||||
return ValueType.Int;
|
||||
} else if (data is double) {
|
||||
return ValueType.Float;
|
||||
} else if (data is bool) {
|
||||
return ValueType.Bool;
|
||||
} else if (data is ICollection) {
|
||||
return ValueType.List;
|
||||
} else {
|
||||
return ValueType.Invalid;
|
||||
}
|
||||
}
|
||||
|
||||
public void Set (object data)
|
||||
{
|
||||
if (data == null)
|
||||
throw new NullReferenceException ();
|
||||
|
||||
ValueType type = LookupType (data);
|
||||
Set (data, type);
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_value_set_list_nocopy (IntPtr value, IntPtr list);
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_value_set_list_type (IntPtr value, ValueType vtype);
|
||||
|
||||
void Set (object data, ValueType type)
|
||||
{
|
||||
if (data == null)
|
||||
throw new NullReferenceException ();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case ValueType.String:
|
||||
gconf_value_set_string (Raw, (string) data);
|
||||
break;
|
||||
case ValueType.Int:
|
||||
gconf_value_set_int (Raw, (int) data);
|
||||
break;
|
||||
case ValueType.Float:
|
||||
gconf_value_set_float (Raw, (double) data);
|
||||
break;
|
||||
case ValueType.Bool:
|
||||
gconf_value_set_bool (Raw, (bool) data);
|
||||
break;
|
||||
case ValueType.List:
|
||||
ValueType listType;
|
||||
GLib.SList list = GetListFromCollection ((ICollection) data, out listType);
|
||||
gconf_value_set_list_type (Raw, listType);
|
||||
gconf_value_set_list_nocopy (Raw, list.Handle);
|
||||
break;
|
||||
default:
|
||||
throw new InvalidValueTypeException ();
|
||||
}
|
||||
}
|
||||
|
||||
GLib.SList GetListFromCollection (ICollection data, out ValueType listType)
|
||||
{
|
||||
object [] arr = (object []) Array.CreateInstance (typeof (object), data.Count);
|
||||
data.CopyTo (arr, 0);
|
||||
|
||||
listType = ValueType.Invalid;
|
||||
GLib.SList list = new GLib.SList (IntPtr.Zero);
|
||||
GC.SuppressFinalize (list);
|
||||
|
||||
foreach (object o in arr) {
|
||||
ValueType type = LookupType (o);
|
||||
if (listType == ValueType.Invalid)
|
||||
listType = type;
|
||||
|
||||
if (listType == ValueType.Invalid || type != listType)
|
||||
throw new InvalidValueTypeException ();
|
||||
|
||||
Value v = new Value (o);
|
||||
GC.SuppressFinalize (v);
|
||||
list.Append (v.Raw);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_value_get_string (IntPtr value);
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern int gconf_value_get_int (IntPtr value);
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern double gconf_value_get_float (IntPtr value);
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern bool gconf_value_get_bool (IntPtr value);
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_value_get_list (IntPtr value);
|
||||
|
||||
public object Get ()
|
||||
{
|
||||
switch (val_type)
|
||||
{
|
||||
case ValueType.String:
|
||||
return GLib.Marshaller.Utf8PtrToString (gconf_value_get_string (Raw));
|
||||
case ValueType.Int:
|
||||
return gconf_value_get_int (Raw);
|
||||
case ValueType.Float:
|
||||
return gconf_value_get_float (Raw);
|
||||
case ValueType.Bool:
|
||||
return gconf_value_get_bool (Raw);
|
||||
case ValueType.List:
|
||||
GLib.SList list = new GLib.SList (gconf_value_get_list (Raw), typeof (Value));
|
||||
Array result = Array.CreateInstance (GetListType (), list.Count);
|
||||
int i = 0;
|
||||
foreach (Value v in list) {
|
||||
((IList) result) [i] = v.Get ();
|
||||
v.managed = false; // This is the trick to prevent a crash
|
||||
i++;
|
||||
}
|
||||
|
||||
return result;
|
||||
default:
|
||||
throw new InvalidValueTypeException ();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern ValueType gconf_value_get_list_type (IntPtr value);
|
||||
|
||||
Type GetListType ()
|
||||
{
|
||||
ValueType vt = gconf_value_get_list_type (Raw);
|
||||
switch (vt) {
|
||||
case ValueType.String:
|
||||
return typeof (string);
|
||||
case ValueType.Int:
|
||||
return typeof (int);
|
||||
case ValueType.Float:
|
||||
return typeof (float);
|
||||
case ValueType.Bool:
|
||||
return typeof (bool);
|
||||
case ValueType.List:
|
||||
return typeof (GLib.SList);
|
||||
default:
|
||||
throw new InvalidValueTypeException ();
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern IntPtr gconf_value_new (ValueType type);
|
||||
|
||||
public Value (ValueType type)
|
||||
{
|
||||
Raw = gconf_value_new (type);
|
||||
}
|
||||
|
||||
void Initialize (object val, ValueType type)
|
||||
{
|
||||
Raw = gconf_value_new (type);
|
||||
val_type = type;
|
||||
Set (val, type);
|
||||
}
|
||||
|
||||
public Value (IntPtr raw)
|
||||
{
|
||||
Raw = raw;
|
||||
NativeValue val = (NativeValue) Marshal.PtrToStructure (raw, typeof (NativeValue));
|
||||
val_type = val.type;
|
||||
}
|
||||
/*
|
||||
public Value (string val)
|
||||
{
|
||||
Initialize (val, ValueType.String);
|
||||
}
|
||||
|
||||
public Value (int val)
|
||||
{
|
||||
Initialize (val, ValueType.Int);
|
||||
}
|
||||
|
||||
public Value (double val)
|
||||
{
|
||||
Initialize (val, ValueType.Float);
|
||||
}
|
||||
|
||||
public Value (bool val)
|
||||
{
|
||||
Initialize (val, ValueType.Bool);
|
||||
}
|
||||
*/
|
||||
public Value (object val)
|
||||
{
|
||||
Initialize (val, LookupType (val));
|
||||
}
|
||||
public bool Managed
|
||||
{
|
||||
get { return managed; }
|
||||
set { managed = value; }
|
||||
}
|
||||
|
||||
[DllImport("gconf-2")]
|
||||
static extern void gconf_value_free (IntPtr value);
|
||||
|
||||
~Value ()
|
||||
{
|
||||
Dispose (false);
|
||||
}
|
||||
|
||||
public void Dispose ()
|
||||
{
|
||||
Dispose (true);
|
||||
GC.SuppressFinalize (this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose (bool disposing)
|
||||
{
|
||||
if (managed && Raw != IntPtr.Zero)
|
||||
{
|
||||
gconf_value_free (Raw);
|
||||
Raw = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
public IntPtr Handle
|
||||
{
|
||||
get {
|
||||
return Raw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,50 +0,0 @@
|
|||
// Entry_.cs -
|
||||
//
|
||||
// Author: Rachel Hestilow <hestilow@nullenvoid.com>
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the Lesser GNU General
|
||||
// Public License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this program; if not, write to the
|
||||
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
// Boston, MA 02111-1307, USA.
|
||||
|
||||
|
||||
namespace GConf
|
||||
{
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
internal struct _NativeEntry
|
||||
{
|
||||
public string key;
|
||||
public IntPtr value;
|
||||
}
|
||||
|
||||
internal class _Entry
|
||||
{
|
||||
_NativeEntry native;
|
||||
|
||||
public _Entry (IntPtr raw)
|
||||
{
|
||||
native = (_NativeEntry) Marshal.PtrToStructure (raw, typeof (_NativeEntry));
|
||||
}
|
||||
|
||||
public string Key
|
||||
{
|
||||
get { return native.key; }
|
||||
}
|
||||
|
||||
internal IntPtr ValuePtr
|
||||
{
|
||||
get { return native.value; }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
prefix=${pcfiledir}/../..
|
||||
exec_prefix=${prefix}
|
||||
libdir=${exec_prefix}/lib
|
||||
|
||||
|
||||
Name: GConf#
|
||||
Description: GConf# - GConf .NET Binding
|
||||
Version: @VERSION@
|
||||
Requires: gnome-sharp-2.0
|
||||
Libs: -r:${libdir}/mono/@PACKAGE_VERSION@/gconf-sharp.dll -r:${libdir}/mono/@PACKAGE_VERSION@/gconf-sharp-peditors.dll
|
|
@ -1,3 +0,0 @@
|
|||
<configuration>
|
||||
<dllmap dll="gconf-2" target="libgconf-2@LIB_PREFIX@.4@LIB_SUFFIX@"/>
|
||||
</configuration>
|
|
@ -1 +0,0 @@
|
|||
SUBDIRS = GConf GConf.PropertyEditors tools doc
|
|
@ -1 +0,0 @@
|
|||
EXTRA_DIST = intro.html
|
|
@ -1,207 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE html
|
||||
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Using GConf#</title>
|
||||
</head>
|
||||
<body>
|
||||
<p align="center">
|
||||
<font size="+3">Using GConf#</font></p>
|
||||
<h1>Introduction</h1>
|
||||
<p>Using GConf directly from an application is often inconvenient.
|
||||
Because the configuration key system effectively represents a
|
||||
string-based API, accessing GConf values leaves your application
|
||||
open to runtime errors from a single typo. Even if you store your
|
||||
keys in constants (as is recommended), you still wind up maintaining
|
||||
two lists of keys: one in the schema, and one in your app.</p>
|
||||
<p>Another problem is that the GConf value types are very limited:
|
||||
string, float, int, bool, and list. When storing common value types
|
||||
such as colors or enumerations, one has to serialize these values
|
||||
to and from strings.</p>
|
||||
<p>Finally, providing graphical dialogs for your settings can be a very
|
||||
tedious process. For each config element exposed in your UI, you have
|
||||
to manually hook up the "changed" signal on the UI to a custom handler
|
||||
setting the GConf value. Inversely, one must initially populate the
|
||||
dialog based on previously-set GConf values. Complicating all of this
|
||||
is the GNOME HIG, which specifies that all preference dialogs be
|
||||
instant-apply if possible.</p>
|
||||
<p>GConf# addresses these issues with two new utilities: SchemaGen, and
|
||||
the GConf.PropertyEditors library.</p>
|
||||
|
||||
<h1>SchemaGen</h1>
|
||||
<p>SchemaGen is a new tool which generates a custom API for the settings
|
||||
in a gconf schema file. Given a schema, it generates two classes,
|
||||
<b>Settings</b> and <b>SettingKeys</b>. <b>Settings</b> provides static
|
||||
properties for each specified gconf setting. These properties map
|
||||
directly to the values in the gconf database. <b>Settings</b> also
|
||||
specifies static events for each setting indicating when the setting
|
||||
has changed, and a generic Changed event which notifies when any
|
||||
of your settings have changed. Finally, for every property in
|
||||
<b>Settings</b>, SchemaGen creates a read-only property of the same
|
||||
name in <b>SettingKeys</b> specifying the GConf key used to access
|
||||
this property. <b>SettingKeys</b> is not needed if you are only using
|
||||
the <b>Settings</b> class, but it is very useful when attaching
|
||||
PropertyEditors, or when accessing GConf directly.</p>
|
||||
<p>SchemaGen also provides for limited marshalling to and from the
|
||||
GConf value types. It currently defines marshallers for
|
||||
System.Drawing.Color and for enumerations. This is done by specifying
|
||||
a <b>cstype</b> directive in the GConf schema.</p>
|
||||
<h2>Example</h2>
|
||||
<p>First, we need to write a GConf schema specifying our settings.</p>
|
||||
<pre>
|
||||
<gconfschema>
|
||||
<schemalist>
|
||||
<schema>
|
||||
<key>/schemas/apps/gconfsharp/sample_app/toolbar_alignment</key>
|
||||
<applyto>/apps/gconfsharp/sample_app/toolbar_alignment</applyto>
|
||||
<owner>sample_app</owner>
|
||||
<b> <type>string</type></b>
|
||||
<b> <cstype class="Sample.Alignment">enum</cstype></b>
|
||||
<locale name="C">
|
||||
<short>Toolbar alignment</short>
|
||||
<long>Where the toolbar should be. Can be one of Top, Bottom, Left, Rigt.</long>
|
||||
</locale>
|
||||
<default>Top</default>
|
||||
</schema>
|
||||
<schema>
|
||||
<key>/schemas/apps/gconfsharp/sample_app/text_color</key>
|
||||
<applyto>/apps/gconfsharp/sample_app/text_color</applyto>
|
||||
<owner>sample_app</owner>
|
||||
<b> <type>string</type></b>
|
||||
<b> <cstype>color</cstype></b>
|
||||
<locale name="C">
|
||||
<short>Text color</short>
|
||||
<long>Text color</long>
|
||||
</locale>
|
||||
<default>#000000</default>
|
||||
</schema>
|
||||
<schema>
|
||||
<key>/schemas/apps/gconfsharp/sample_app/enable_text_color</key>
|
||||
<applyto>/apps/gconfsharp/sample_app/enable_text_color</applyto>
|
||||
<owner>sample_app</owner>
|
||||
<type>bool</type>
|
||||
<locale name="C">
|
||||
<short>Show colored text</short>
|
||||
<long>Show colored text</long>
|
||||
</locale>
|
||||
<default>#000000</default>
|
||||
</schema>
|
||||
</schemalist>
|
||||
</gconfschemafile>
|
||||
</pre>
|
||||
<p>Note how we specify both the cstype and type for the enum and color.
|
||||
This is because GConf doesn't know anything about cstype.</p>
|
||||
<p>We save this to sample.schema, and install it with the command:</p>
|
||||
<pre>env GCONF_CONFIG_SOURCE="" gconftool-2 --makefile-install-rule sample.schema</pre>
|
||||
<p>GConf generates a warning because it doesn't recognize cstype, but
|
||||
it is nothing to worry about.</p>
|
||||
<p>We're now ready to run SchemaGen. Installing the schema before running
|
||||
SchemaGen is not required, but you should make sure to install it before
|
||||
running your application, because GConf# will throw an exception if
|
||||
GConf can't find your settings.</p>
|
||||
<p>SchemaGen's full executable name is <b>gconfsharp-schemagen</b>. It
|
||||
takes a namespace and the schema filename as parameters, and outputs
|
||||
to the console. Here is the command used to generate Settings.cs for
|
||||
sample.schema:</p>
|
||||
<pre>gconfsharp-schemagen Sample sample.schema > Settings.cs</pre>
|
||||
<p>Now we're ready to write a small program using our new settings.</p>
|
||||
<pre>
|
||||
namespace Sample
|
||||
{
|
||||
using System;
|
||||
using System.Drawing;
|
||||
|
||||
public enum Alignment
|
||||
{
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right
|
||||
}
|
||||
|
||||
class X
|
||||
{
|
||||
public static void Main (string args[])
|
||||
{
|
||||
Alignment align = Settings.ToolbarAlignment;
|
||||
Console.WriteLine ("Alignment is: {0}", align);
|
||||
Settings.ToolbarAlignment = Left;
|
||||
Console.WriteLine ("Color is: {0}", Settings.TextColor);
|
||||
Console.WriteLine ("Color is enabled: {0}", Settings.TextEnableColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
<p>As you can see, our GConf settings are now nicely encapsulated, and
|
||||
are as easy to access as any other .NET properties.</p>
|
||||
<h1>Property Editors</h1>
|
||||
<p>Property Editors are objects which act as intermediaries between
|
||||
GConf and Gtk+ widgets. They are analoguous to the Controller of the MVC
|
||||
design pattern. Property editors do two things:
|
||||
<ul>
|
||||
<li>They listen to GConf notifications, and update the widget
|
||||
to reflect any changes in a GConf setting.
|
||||
<li>They connect to the various "changed" signals on a widget,
|
||||
and update GConf to reflect the widget's current state.</li>
|
||||
</ul>
|
||||
This means that the widget and GConf are always in sync, no matter
|
||||
if the value is set through Gtk+ or through GConf. GConf# defines a
|
||||
number of Property Editors which correspond to common widget/setting
|
||||
combinations -- for example, a CheckButton representing a boolean
|
||||
setting.
|
||||
</p>
|
||||
<p>GConf# also provides a utility class called <b>EditorShell</b>.
|
||||
EditorShell exposes a simple API to automatically construct
|
||||
PropertyEditors for a Glade UI.</p>
|
||||
<p>As a historical note, and in the interests of giving credit where
|
||||
credit is due, it should be noted that GConf Property Editors are
|
||||
not unique to GConf#. They were originally conceived and implemented
|
||||
by Bradford Hovinen for use in the GNOME Control Center. Although
|
||||
the APIs are somewhat similar, the original version was written in
|
||||
C and was limited to internal use in the Control Center.</p>
|
||||
<h2>Example</h2>
|
||||
<p>For this example we'll assume you have written a Glade UI for
|
||||
the settings in the previous example. It employs three elements:
|
||||
an option menu named "toolbar_menu", a checkbox named "enable_check",
|
||||
and a color picker named "colorpicker". Given our Glade.XML object,
|
||||
all we have to do is set up the EditorShell.</p>
|
||||
<pre>
|
||||
Glade.XML gxml = <i>...</i>
|
||||
GConf.PropertyEditors.EditorShell shell = new GConf.PropertyEditors.EditorShell (gxml);
|
||||
|
||||
shell.Add (SettingKeys.ToolbarAlignment, "toolbar_menu", typeof (Sample.Alignment));
|
||||
shell.Add (SettingKeys.EnableTextColor, "enable_check");
|
||||
shell.Add (SettingKeys.TextColor, "colorpicker");
|
||||
</pre>
|
||||
<p>That's all that is needed to implement the preferences dialog. Note
|
||||
how we didn't have to specify what type of property editor to use.
|
||||
The EditorShell uses introspection to create the correct Property
|
||||
Editor for all the types of widgets it knows about. Also note that
|
||||
because ToolbarAlignment is an enum, we had to pass its type in so that
|
||||
the Property Editor can store its value correctly. By default,
|
||||
Property Editors assume that the order of elements in an OptionMenu
|
||||
(or RadioButton) correspond to the order of values in an enum. If
|
||||
this is not the case, you can pass in an additional parameter to
|
||||
Add: an array of integers, each array element being the integer
|
||||
representation of an enum value. This array represents the order of
|
||||
values in your GUI element.
|
||||
</p>
|
||||
<p>Now, a really good preference dialog would "ghost out" the
|
||||
color picker if the "Enable text color" option is disabled. This
|
||||
requires a small addition to our previous code:</p>
|
||||
<pre>
|
||||
shell.AddGuard (SettingKeys.EnableTextColor, "color_box");
|
||||
</pre>
|
||||
<p>Again, for the purposes of the example, "color_box" is the name of the
|
||||
HBox containing the label and color picker corresponding to TextColor.</p>
|
||||
<h1></h1>
|
||||
<p>
|
||||
<font size=-1>
|
||||
<i>Last updated: October 19th, 2002 <br />
|
||||
Rachel Hestilow <a href="mailto:hestilow@ximian.com">(hestilow@ximian.com)</a></i>
|
||||
</font>
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||
assemblydir = $(prefix)/lib/gtk-sharp-2.0
|
||||
assembly_DATA = gconfsharp-schemagen.exe
|
||||
bin_SCRIPTS = gconfsharp2-schemagen
|
||||
CLEANFILES = gconfsharp-schemagen.exe
|
||||
DISTCLEANFILES = gconfsharp2-schemagen
|
||||
|
||||
EXTRA_DIST = \
|
||||
schemagen.cs \
|
||||
gconfsharp2-schemagen.in
|
||||
|
||||
gconfsharp-schemagen.exe: $(srcdir)/schemagen.cs
|
||||
$(CSC) /out:gconfsharp-schemagen.exe $(srcdir)/schemagen.cs
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
a=`which "$0"`
|
||||
d=`dirname "$a"`
|
||||
|
||||
@RUNTIME@ $d/../lib/gtk-sharp-2.0/gconfsharp-schemagen.exe "$@"
|
|
@ -1,276 +0,0 @@
|
|||
namespace GConf.Tools
|
||||
{
|
||||
using GConf;
|
||||
using System;
|
||||
using System.Xml;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
class SchemaGen
|
||||
{
|
||||
private Hashtable keys = new Hashtable ();
|
||||
private Hashtable classes = new Hashtable ();
|
||||
|
||||
static void Die (string error)
|
||||
{
|
||||
Console.WriteLine (error);
|
||||
Environment.Exit (1);
|
||||
}
|
||||
|
||||
void DieInvalid (string filename)
|
||||
{
|
||||
Die (filename + " is an invalid schema");
|
||||
}
|
||||
|
||||
void Parse (string filename)
|
||||
{
|
||||
XmlDocument doc = new XmlDocument ();
|
||||
try {
|
||||
Stream stream = File.OpenRead (filename);
|
||||
doc.Load (stream);
|
||||
stream.Close ();
|
||||
} catch (XmlException e) {
|
||||
Die ("Could not parse " + filename);
|
||||
}
|
||||
|
||||
XmlElement root = doc.DocumentElement;
|
||||
if (!(root != null && root.HasChildNodes && root.Name == "gconfschemafile"))
|
||||
DieInvalid (filename);
|
||||
|
||||
foreach (XmlNode slist in root.ChildNodes)
|
||||
{
|
||||
if (!(slist != null && slist.Name == "schemalist"))
|
||||
continue;
|
||||
|
||||
foreach (XmlNode schema_node in slist.ChildNodes)
|
||||
{
|
||||
XmlElement schema = schema_node as XmlElement;
|
||||
if (!(schema != null && schema.Name == "schema"))
|
||||
continue;
|
||||
|
||||
XmlElement key = schema["applyto"];
|
||||
XmlElement type = schema["cstype"];
|
||||
if (type == null)
|
||||
type = schema["type"];
|
||||
if (key == null || type == null)
|
||||
DieInvalid (filename);
|
||||
keys.Add (key.InnerText, type.InnerText);
|
||||
|
||||
if (type.HasAttribute ("class"))
|
||||
classes.Add (key.InnerText, type.GetAttribute ("class"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string ExtractPrefix ()
|
||||
{
|
||||
string path = null;
|
||||
|
||||
foreach (string key in keys.Keys)
|
||||
{
|
||||
int slash = key.LastIndexOf ('/');
|
||||
if (slash < 0)
|
||||
continue;
|
||||
|
||||
string new_path = key.Substring (0, slash + 1);
|
||||
if (path == null || new_path.Length < path.Length)
|
||||
path = new_path;
|
||||
}
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
string BaseName (string key)
|
||||
{
|
||||
int slash = key.LastIndexOf ('/');
|
||||
if (slash < 0)
|
||||
return key;
|
||||
return key.Substring (slash + 1);
|
||||
}
|
||||
|
||||
string PropertyName (string key)
|
||||
{
|
||||
string basename = BaseName (key);
|
||||
StringBuilder sb = new StringBuilder ();
|
||||
|
||||
bool needs_caps = true;
|
||||
foreach (char orig in basename)
|
||||
{
|
||||
char c = orig;
|
||||
if (c == '_' || c == '-')
|
||||
{
|
||||
needs_caps = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (needs_caps)
|
||||
{
|
||||
c = c.ToString ().ToUpper ()[0];
|
||||
needs_caps = false;
|
||||
}
|
||||
|
||||
sb.Append (c);
|
||||
}
|
||||
|
||||
return sb.ToString ();
|
||||
}
|
||||
|
||||
string CSType (string key, string type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "float":
|
||||
return "double";
|
||||
case "string":
|
||||
return "string";
|
||||
case "int":
|
||||
return "int";
|
||||
case "bool":
|
||||
return "bool";
|
||||
case "color":
|
||||
return "System.Drawing.Color";
|
||||
case "enum":
|
||||
if (classes.Contains (key))
|
||||
return (string) classes[key];
|
||||
else
|
||||
return "string";
|
||||
case "list":
|
||||
return "System.Array";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
void GenerateSimpleProperty (TextWriter sw, string key, string key_str, string type, string cstype)
|
||||
{
|
||||
sw.WriteLine ("\t\t\tget {");
|
||||
sw.WriteLine ("\t\t\t\treturn ({0}) client.Get ({1});", cstype, key_str);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
|
||||
sw.WriteLine ("\t\t\tset {");
|
||||
sw.WriteLine ("\t\t\t\tclient.Set ({0}, value);", key_str);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
}
|
||||
|
||||
void GenerateColorProperty (TextWriter sw, string key, string key_str, string type, string cstype)
|
||||
{
|
||||
sw.WriteLine ("\t\t\tget {");
|
||||
sw.WriteLine ("\t\t\t\treturn System.Drawing.ColorTranslator.FromHtml ((string) client.Get ({0}));", key_str);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
|
||||
sw.WriteLine ("\t\t\tset {");
|
||||
sw.WriteLine ("\t\t\t\tclient.Set ({0}, System.Drawing.ColorTranslator.ToHtml (value));", key_str);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
}
|
||||
|
||||
void GenerateEnumProperty (TextWriter sw, string key, string key_str, string type, string cstype)
|
||||
{
|
||||
sw.WriteLine ("\t\t\tget {");
|
||||
sw.WriteLine ("\t\t\t\ttry {");
|
||||
sw.WriteLine ("\t\t\t\t\treturn ({0}) System.Enum.Parse (typeof ({0}), (string) client.Get ({1}));", cstype, key_str);
|
||||
sw.WriteLine ("\t\t\t\t} catch (System.Exception e) {");
|
||||
sw.WriteLine ("\t\t\t\t\treturn ({0}) 0;", cstype);
|
||||
sw.WriteLine ("\t\t\t\t}");
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
|
||||
sw.WriteLine ("\t\t\tset {");
|
||||
sw.WriteLine ("\t\t\t\tclient.Set ({0}, System.Enum.GetName (typeof ({1}), value));", key_str, cstype);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
}
|
||||
|
||||
void GenerateEvent (TextWriter sw, string name, string key_str)
|
||||
{
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic static event GConf.NotifyEventHandler {0}Changed", name);
|
||||
sw.WriteLine ("\t\t{");
|
||||
sw.WriteLine ("\t\t\tadd {");
|
||||
sw.WriteLine ("\t\t\t\tclient.AddNotify ({0}, value);", key_str);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
sw.WriteLine ("\t\t\tremove{");
|
||||
sw.WriteLine ("\t\t\t\tclient.RemoveNotify ({0}, value);", key_str);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
sw.WriteLine ("\t\t}");
|
||||
}
|
||||
|
||||
void Generate (string ns_str)
|
||||
{
|
||||
string path = ExtractPrefix ();
|
||||
TextWriter sw = Console.Out;
|
||||
|
||||
sw.WriteLine ("namespace {0}", ns_str);
|
||||
sw.WriteLine ("{");
|
||||
|
||||
sw.WriteLine ("\tpublic class Settings");
|
||||
sw.WriteLine ("\t{");
|
||||
sw.WriteLine ("\t\tstatic GConf.Client client = new GConf.Client ();");
|
||||
|
||||
GenerateEvent (sw, "", "\"" + path.Substring (0, path.Length - 1) + "\"");
|
||||
|
||||
foreach (string key in keys.Keys)
|
||||
{
|
||||
string type = (string) keys[key];
|
||||
string cstype = CSType (key, type);
|
||||
string key_str = "\"" + key + "\"";
|
||||
|
||||
if (cstype == null)
|
||||
{
|
||||
Console.Error.WriteLine ("Warning: unknown type \"{0}\" for key {1}", type, key);
|
||||
continue;
|
||||
}
|
||||
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\t\tpublic static {0} {1}", cstype, PropertyName (key));
|
||||
sw.WriteLine ("\t\t{");
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "color":
|
||||
GenerateColorProperty (sw, key, key_str, type, cstype);
|
||||
break;
|
||||
case "enum":
|
||||
GenerateEnumProperty (sw, key, key_str, type, cstype);
|
||||
break;
|
||||
default:
|
||||
GenerateSimpleProperty (sw, key, key_str, type, cstype);
|
||||
break;
|
||||
}
|
||||
|
||||
sw.WriteLine ("\t\t}");
|
||||
|
||||
GenerateEvent (sw, PropertyName (key), key_str);
|
||||
}
|
||||
|
||||
sw.WriteLine ("\t}");
|
||||
sw.WriteLine ();
|
||||
sw.WriteLine ("\tpublic class SettingKeys");
|
||||
sw.WriteLine ("\t{");
|
||||
|
||||
foreach (string key in keys.Keys)
|
||||
{
|
||||
sw.WriteLine ("\t\tpublic static string {0}", PropertyName (key));
|
||||
sw.WriteLine ("\t\t{");
|
||||
sw.WriteLine ("\t\t\tget {");
|
||||
sw.WriteLine ("\t\t\t\t return \"{0}\";", key);
|
||||
sw.WriteLine ("\t\t\t}");
|
||||
sw.WriteLine ("\t\t}");
|
||||
}
|
||||
|
||||
sw.WriteLine ("\t}");
|
||||
sw.WriteLine ("}");
|
||||
}
|
||||
|
||||
public static void Main (string[] args)
|
||||
{
|
||||
if (args.Length < 2)
|
||||
Die ("Usage: gconfsharp-schemagen namespace schemafile");
|
||||
string ns = args[0];
|
||||
string filename = args[1];
|
||||
|
||||
SchemaGen gen = new SchemaGen ();
|
||||
gen.Parse (filename);
|
||||
gen.Generate (ns);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Reference in a new issue