#!/usr/bin/perl
#use Mooix::Thing;
run sub {
	my $this=shift;
	%_=@_;
	my $session=$_{session};
	
	# Make sure that this command is not spoofed, just in case.
        if ($_{avatar} != $this) {
		fail "No!"; 
	}
	
	if (exists $_{direct_object} && exists $_{quote}) {
		# Add shortcut.
		my $object=$_{direct_object};
		my $name=$_{quote};
	
		if (-l $this->shortcuts->id."/$name") {
			unless ($this->shortcuts->remove(object => $this->shortcuts->$name)) {
				fail "Could not remove the old link!";
			}
		}
	
		unless ($this->shortcuts->add(object => $object, hint => $name)) {
			fail "Could not add the object!";
		}
	}
	elsif (exists $_{direct_object}) {
		# Remove shortcut. Called by unshortcut.cmd.
		unless ($this->shortcuts->remove(object => $_{direct_object})) {
			fail "Could not remove the shortcut.";
		}
	}

	my @ret;
	my $maxlen=0;
	my $dir=$this->shortcuts->id;
	foreach my $file ($this->shortcuts->rellist) {
		my $obj=Mooix::Thing->get("$dir/$file");
		if ($maxlen < length $file) {
			$maxlen=length $file;
		}
		push @ret, [ "mooix:$file", "(mooix:".$obj->id.")" ];
	}
	@ret = map { "\t".$_->[0].(' ' x (2 + length("mooix:") + $maxlen - length($_->[0]))).$_->[1] } @ret;
	if (@ret) {
		$session->page("Your shortcuts:", @ret);
	}
	else {
		$session->page("You have no shortcuts.");
	}
}
