SettingsManager 0.1

September 24th, 2008 by Andrew Vos

SettingsManager is a library that dynamically generates a form to allow the client to edit settings.

Take for example a class that contains the following property:

private bool someBoolean1 = true;
public bool SomeBoolean1 { get { return this.someBoolean1; } set { this.someBoolean1 = value; } }
 

To allow the client to edit this property we would typically create a Form and put some checkboxes, labels etc. on it.

With SettingsManager, we just inherit from the SettingsBase class, and apply a SettingAttribute to the property:

public class MySettings : SettingsBase {
  private bool someBoolean1 = true;
  [Setting("Demo Category", "Booleans", "Please check this box.", typeof(BooleanEditor))]
  public bool SomeBoolean1 { get { return this.someBoolean1; } set { this.someBoolean1 = value; } }
}

And show a Settings form:

MySettings settings = SettingsBase.Load<MySettings>("C:\\settings.xml");
TabbedSettingsForm settingsForm = new TabbedSettingsForm(settings);
settingsForm.ShowDialog();


And we get this:

SettingsManager

Creating custom editors

You may have noticed that the SettingAttribute constructor takes a Type. This we can use to make custom editors for types. Let’s take a look at the source for the DateEditor type.

public class DateEditor : SettingEditorBase {

  DateTimePicker datePicker;

  public DateEditor(string text, object settingValue)
    : base(text, settingValue) {

    this.AddLabel(text);

    this.datePicker = new DateTimePicker();
    this.datePicker.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right;

    this.datePicker.Value = (DateTime)settingValue;
    this.datePicker.ValueChanged += new EventHandler(datePicker_ValueChanged);
    this.Controls.Add(datePicker);
  }

  private void datePicker_ValueChanged(object sender, EventArgs e) {
    this.OnSettingChanged(this.datePicker.Value);
  }
}

Notice that we inherit from SettingEditorBase, which is an abstract class. Basically all that is important in this code is that we call OnSettingChanged when the value is changed. This allows the Settings form to enable the Apply button.

Creating custom Settings forms

Creating custom Settings forms is fairly easy. We inherit from SettingsFormBase, and override the InitializeEditors method. All our controls are placed on the contentPanel that is passed in as a parameter.

In InitializeEditors, we loop though this.Categories, and in turn loop through each categories’ group. We then add each editor to the form.

The Ok, Cancel and Apply buttons are all taken care of in SettingsFormBase.

public class TabbedSettingsForm : SettingsFormBase {
  TabControl tabControl;
  public TabbedSettingsForm(SettingsBase settings)
    : base(settings) {
    this.Padding = new Padding(10);
  }

  public override void InitializeEditors(Panel contentPanel) {
    this.tabControl = new TabControl();
    this.tabControl.Dock = DockStyle.Fill;
    contentPanel.Controls.Add(this.tabControl);

    foreach (SettingCategory category in this.Categories) {
      TabPage tabPage = new TabPage(category.Name);
      tabPage.AutoSize = true;
      this.tabControl.TabPages.Add(tabPage);

      TableLayoutPanel content = new TableLayoutPanel();
      content.Dock = DockStyle.Fill;
      content.AutoScroll = true;
      tabPage.Controls.Add(content);

      foreach (SettingGroup group in category.Groups) {
        content.Controls.Add(new GroupTitle(group.Name));
        foreach (SettingEditorBase editor in group.Editors) {
          content.Controls.Add(editor);
        }
      }
    }
  }
}
 

Popularity: 1% [?]

Posted in .NET Framework, C#, Code Projects, Coding, Download, Downloads having no comments »

The first Google Android Phone!

September 23rd, 2008 by Andrew Vos

The first Google Android phone is out! It’s called the G1 and it’s made by HTC.

G1

Popularity: 1% [?]

Posted in Google Android, News, Phone having no comments »

[comic] - Intervention

September 5th, 2008 by Andrew Vos

New comic up

Popularity: 1% [?]

Posted in Comic having no comments »

GoogleSearchButtons

July 2nd, 2008 by Andrew Vos

My first Firefox extension, a simple toolbar that shows Google search buttons like the Google Toolbar.

EDIT: Maybe I wasn’t clear, these buttons search the current web page text and highlight occurrences of the string.

GoogleSearchButtons

Useful because I’ve taken to using the main search box included with Firefox, but still wanted those buttons.

Click View/Toolbars/Google Search Buttons to hide or show the toolbar.

Download

Popularity: 4% [?]

Posted in Code Projects, Coding, Download, Downloads, Firefox, Plugin having no comments »

SMBC is the shit

June 22nd, 2008 by Andrew Vos

If you don’t check out every new SMBC comic, then you’re stupid.

This attachment sets a random SMBC comic every time you run it.

Download it!

Popularity: 4% [?]

Posted in Comedy having no comments »

[comic] - Ways to break up with someone #42

June 19th, 2008 by Andrew Vos

New Comic Here

Popularity: 4% [?]

Posted in Comic having no comments »

Smallest XP Virtual Machine?

June 9th, 2008 by Andrew Vos

I’ve been getting a little XP VM set up for web dev, so I can test multiple sites on different browsers. Also, I wanted to put it on a flash drive. I’m using Microsoft Virtual PC 2007.

Before you do anything, if you want a really small install, I would suggest using nLite. nLite takes an original xp cd, and allows you to remove unwanted stuff from it. You get an iso which you can capture in Virtual PC. You can easily save a couple hundred mb here.

1. Install any applications you may need. (For this setup I have installed IE6, IE7, Safara, Opera and Firefox)

2. Remove unneeded applications. Also, remove everything you don’t need from windows.

3. Run nCleaner, and remove pretty much everything you can.

TIP: Try run CCleaner first. I don’t know how much of a difference this will make though, because nCleaner removed +100mb after CCleaner was run.

4. Compress the entire drive using NTFS compression. (Right click system drive, then properties, then check “Compress drive to save disk space”.

5. Get this free disk defragger, which performs a far more aggressive defrag than other options. After installing it, run it in a command prompt like this:

defrag.exe -d c: -B
 

6. Run the Precompactor (capture “C:\Program Files (x86)\Microsoft Virtual PC\Virtual Machine Additions\Virtual Disk Precompactor.iso”, then navigate to My Computer and double click the cd drive to run it).

7. Compact the drive using Virtual PC’s Virtual Disk Wizard.

And we’re done. I’ve got a 618mb Virtual Machine which fits perfectly on a flash drive.

Anyone know of something like TrueCrypt, but just for compression, so I can compress the system drive?

One other thing, if you need even more compression, try using 7Zip on the virtual disk!

NOTE: Some more information can be found here:

http://www.codinghorror.com/blog/archives/000639.html

Popularity: 100% [?]

Posted in Tips, Virtual Machine, Web Design having no comments »

Theme mods coming

May 29th, 2008 by Andrew Vos

I’m changing the Wordpress theme here a bit. I need to make the page fluid. I can’t even find shit on here cause it’s so damn small on my screen.

If anything looks broken, come back later, or never.

Popularity: 5% [?]

Posted in Web Design, WordPress having no comments »

My picture is on The Daily WTF

May 29th, 2008 by Andrew Vos

http://thedailywtf.com/Articles/Recommended-Upgrade.aspx

The second one. (My name isn’t Adrian V)

Popularity: 9% [?]

Posted in Sweet having no comments »

Tag Galaxy

May 27th, 2008 by Andrew Vos

Holy shit.

 

Just take a look at this, seriously. Go now. (It searches Flickr, so search for something imagey)

Popularity: 6% [?]

Posted in Ideas, Links, Sweet, Web Software having no comments »