This is already implemented. if you select an object in the 3D view, there will be three arrows pointing into each axis. Between these arrows are "squares" that if you click on them, will constrain the object's movement to the axis the "square" is aligned to.

You can also click on the arrows themselves to constrain the movement to the linear axis.


Code:
void main()
{
    cout << "I am MrCode,";
    cout << "hear me roar!";
    system("PAUSE");
}