Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

DSGraphEdit: A Reasonable Facsimile of Microsoft's GraphEdit in .NET

, 20 Dec 2007 CPOL
A library for adding DirectShow GraphEdit-like abilities to .NET applications.
dsgrapheditdemo.zip
WeifenLuo.WinFormsUI.Docking.dll
DaggerLib.dll
DaggerLib.DSGraphEdit.dll
DaggerLib.UI.Windows.dll
DirectShowLib-2005.dll
DSGraphEdit.exe
MediaFoundation.dll
dsgrapheditsrc.zip
DSGraphEdit
bin
Release
DSIcon.ico
Properties
Settings.settings
Referenced Libs
WeifenLuo.WinFormsUI.Docking.dll
RemoteGraphTile.jpg
DaggerLib
bin
Release
Core
Interfaces
Properties
SetGeneric
UI
DaggerLib.DSGraphEdit
DMOParameterControls
DSFilterTreeView
DSGraphEditControls
lib
Properties
ReferencedLibs
DirectShowLib-2005.dll
MediaFoundation.dll
DaggerLib.UI.Windows
AStar
bin
Debug
DaggerPropertyGrid
PropertyGridEx
Properties
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace DaggerLib.DSGraphEdit
{
    public partial class URLDialog : Form
    {
        public URLDialog()
        {
            InitializeComponent();
            _okButton.DialogResult = DialogResult.OK;
            _cancelButton.DialogResult = DialogResult.Cancel;
            
            // (re)populate the combobox with previous URLS
            comboBox1.Items.AddRange(URLItemsSingleton.Instance.Items.ToArray());
            if (comboBox1.Items.Count != 0)
            {
                comboBox1.SelectedIndex = 0;
            }

            this.FormClosing += new FormClosingEventHandler(URLDialog_FormClosing);
        }

        void URLDialog_FormClosing(object sender, FormClosingEventArgs e)
        {
            // store the chosen URL in the URLItemsSingleton
            if (this.DialogResult == DialogResult.OK)
            {
                if (!URLItemsSingleton.Instance.Items.Contains(comboBox1.Text))
                {
                    URLItemsSingleton.Instance.Items.Add(comboBox1.Text);
                }
            }
        }

        public string URL
        {
            get
            {
                return comboBox1.Text;
            }
        }
    }

    /// <summary>
    /// A singleton pattern to store URLS in the running App instance and maintain them across
    /// different instances of URLDialogs.  It is most definitely not thread-safe though.
    /// </summary>
    internal sealed class URLItemsSingleton
    {
        static URLItemsSingleton instance = null;
        static private List<string> items;

        /// <summary>
        /// we only want the contructor available to the static Instance property
        /// </summary>
        private URLItemsSingleton()
        {
            if(items == null)
            {
                items = new List<string>();

                // see if there are any items stored in the registry
                RegistryKey MyKey = Registry.CurrentUser.OpenSubKey(@"Software\DSGraphEdit\URLS\");
                if (MyKey != null)
                {
                    try
                    {
                        string[] urls = MyKey.GetValueNames();
                        for (int i = 0; i < urls.Length; i++)
                        {
                            items.Add((string)MyKey.GetValue(urls[i]));
                        }
                    }
                    catch { }
                    finally
                    {
                        MyKey.Close();
                    }
                }
            }
        }

        /// <summary>
        /// Destructor - Store the items in the registry
        /// </summary>
        ~URLItemsSingleton()
        {
            if (items.Count == 0)
            {
                return;
            }

            // store at most 10 items in the Registry
            if (items.Count > 10)
            {
                items = items.GetRange(items.Count - 10, 10);
            }

            // store them under CurrentUser\Software\DSGraphEdit\URLS
            RegistryKey MyKey = Registry.CurrentUser.CreateSubKey(@"Software\DSGraphEdit\URLS\");
            if (MyKey != null)
            {
                try
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        MyKey.SetValue(i.ToString(), items[i]);
                    }
                }
                catch { }
                finally
                {
                    MyKey.Close();
                }                
            }
        }

        /// <summary>
        /// Static property to get the actual Instance of of the class
        /// </summary>
        public static URLItemsSingleton Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new URLItemsSingleton();
                }
                return instance;
            }
        }

        /// <summary>
        /// Get the Items stored in the singleton
        /// </summary>
        public List<string> Items
        {
            get
            {
                return items;
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

JohnnyLocust
Software Developer (Senior) Haivision Network Video
United States United States
AKA Rich Insley.
 
I have over 25 years experience in programming, and I'm completely self taught. (Except for one year at California State University Fresno where I had to learn the God awful language Miranda (http://miranda.org.uk/). I've spent 10 years as a Paratrooper in the US Army during the Clinton Administration.
Follow on   LinkedIn

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.1411023.1 | Last Updated 20 Dec 2007
Article Copyright 2007 by JohnnyLocust
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid