Author Topic: Code Snippets  (Read 9429 times)

0 Members and 1 Guest are viewing this topic.

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Code Snippets
« Reply #15 on: December 27, 2006, 09:27:44 PM »
Someone want to test this ... ?
kwbGetInteger.snippet
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <SnippetTypes>
        <SnippetType>Expansion</SnippetType>
      </SnippetTypes>
      <Title>GetInteger</Title>
      <Shortcut>kwbGetInteger</Shortcut>
      <Description>User input for an integer.</Description>
      <Author>kwb 2006Dec</Author>
    </Header>
    <Snippet>
      <Declarations>
        <Literal Editable="true">
          <ID>Editor</ID>
          <ToolTip>ACAD commandLine object</ToolTip>
          <Default>ed</Default>
        </Literal>
        <Literal Editable="true">
          <ID>intOpt</ID>
          <ToolTip>parameters of the prompt</ToolTip>
          <Default>getIntOpt</Default>
        </Literal>
        <Literal Editable="true">
          <ID>intRes</ID>
          <ToolTip>result of a prompt that returns</ToolTip>
          <Default>getIntRes</Default>
        </Literal>
        <Literal Editable="true">
          <ID>promptMsgString</ID>
          <ToolTip>prompt message to be displayed</ToolTip>
          <Default>\nNeed an integer dude ?</Default>
        </Literal>
        <Literal Editable="true">
          <ID>cancelMsg</ID>
          <ToolTip>User has canceled.</ToolTip>
          <Default>\nUser canceled.</Default>
        </Literal>
        <Literal Editable="true">
          <ID>errorMsg</ID>
          <ToolTip>Oooops, User input error.</ToolTip>
          <Default>\nUser input error.</Default>
        </Literal>
      </Declarations>
      <Code Language="CSharp" Format="CData" Kind="type decl" Delimiter="$"><![CDATA[// Prompt for an integer
PromptIntegerOptions $intOpt$ = new PromptIntegerOptions("$promptMsgString$");
int intResultValue;
PromptIntegerResult $intRes$ = $Editor$.GetInteger($intOpt$);
switch($intRes$.Status)
{
case PromptStatus.Cancel:
    $Editor$.WriteMessage("$cancelMsg$");
    return;
    break;
case PromptStatus.Error:
    $Editor$.WriteMessage("$errorMsg$");
    return;
    break;
case PromptStatus.OK:
        intResultValue = getIntRes.Value;
        ed.WriteMessage("\nInteger was " + intResultValue.ToString());
        // all's well, so add Mojo here
        $selected$ $end$
    break;
}]]></Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: Code Snippets
« Reply #16 on: December 27, 2006, 10:03:33 PM »
Very nice Kerry, :-)
I wonder if you can have something like
Code: [Select]
//getIntOpt.AllowNone = false;
//getIntOpt.AllowZero = true;
Pre-commented and highlighted that way you could just uncomment and modify the property if you wanted to use it
….Just a thought.
« Last Edit: December 27, 2006, 10:04:41 PM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Code Snippets
« Reply #17 on: December 27, 2006, 10:14:52 PM »
Hi Daniel
I have been looking at that, it's easier to remove lines not required than to add them :-)

.. for instance , the
ed.WriteMessage("\nInteger was " + intResultValue.ToString());
is intended as a debug aid only.

I am continuing to see a lot of potential here.
.. have sketched out heaps of stuff I intend to 'snippet'


added:
The piccy above shows code that requires about 8 words to be typed .... not bad, heh !


« Last Edit: December 27, 2006, 10:18:11 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: Code Snippets
« Reply #18 on: December 27, 2006, 10:38:35 PM »
I have been looking at that, it's easier to remove lines not required than to add them :-)

Yep that’s exactly what I was thinking.

I guess I will need to transfer all my stuff from treepad to snippets

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Code Snippets
« Reply #19 on: December 27, 2006, 10:39:59 PM »
Daniel,
I think the default for AllowZero is true,
so the optional code would be ;
Code: [Select]
//getIntOpt.AllowZero = false;.. yes ?


might be interesting to play with defaults too.
... and keywords.
[ aside: now there is a subject for a tutorial :-) ]
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: Code Snippets
« Reply #20 on: December 27, 2006, 10:53:33 PM »
Daniel,
I think the default for AllowZero is true,
so the optional code would be ;
Code: [Select]
//getIntOpt.AllowZero = false;.. yes ?


might be interesting to play with defaults too.
... and keywords.
[ aside: now there is a subject for a tutorial :-) ]

Your right, I just threw that in there, But you got where I was going with the idea.   :-)
« Last Edit: December 27, 2006, 11:26:27 PM by Danielm103 »

Kerry

  • Mesozoic relic
  • Seagull
  • Posts: 11654
  • class keyThumper<T>:ILazy<T>
Re: Code Snippets
« Reply #21 on: December 27, 2006, 10:57:17 PM »
Daniel, That TreePad piccy looks interesting .. is it a code Library ?


added:
DUH .. trust me to ask the obvious 
http://www.treepad.com/treepadfreeware/
« Last Edit: December 27, 2006, 10:59:01 PM by Kerry Brown »
kdub, kdub_nz in other timelines.
Perfection is not optional.
Everything will work just as you expect it to, unless your expectations are incorrect.
Discipline: None at all.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 8728
  • AKA Daniel
Re: Code Snippets
« Reply #22 on: December 27, 2006, 11:25:15 PM »
It’s just something I was using to get me by until Troy
Is done with his project. Hint Hint…   :-D

See
http://www.theswamp.org/index.php?topic=13126.0

Dan

Glenn R

  • Guest
Re: Code Snippets
« Reply #23 on: February 01, 2007, 11:40:29 PM »
I'd forgotten about these in the pursuit of coding nirvana...nice work there Kerry.