Snippet Manager

v1.8 now available!

  • (11 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »

157 Replies - 29806 Views - Last Post: 02 March 2009 - 11:13 AM

#56 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: Snippet Manager

Posted 27 August 2008 - 03:30 PM

View Postgabehabe, on 27 Aug, 2008 - 04:42 PM, said:

I don't want to use it, since I'm aiming to do this all by myself


Lol, no worries, I completely understand. I'd feel the same way. The puzzle just appealed to me and I thought the results might help. ( I usually just file away the puzzles DIC offers, if the won't help the person asking the question. )

I'm afraid it got more complex than I'd intended, I was having fun. There are may be some of good tricks hidden in there, though. I recall I used a Reflection technique for creating the custom types from the XML; I don't know if that's well documented anywhere.
Was This Post Helpful? 0
  • +
  • -

#57 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 27 August 2008 - 03:34 PM

Don't get me wrong, it'll definitely help~

I looked at a few projects on CodeProject, but yours looks the easiest to understand, it's pretty well structured, too.

Now I'm off to learn to format XML documents through C# so I can store the clipboard ring each time the program gets closed (so it's not empty at startup)
Was This Post Helpful? 0
  • +
  • -

#58 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 27 August 2008 - 03:52 PM

@Psycho:
How's your dog?
Was This Post Helpful? 0
  • +
  • -

#59 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Snippet Manager

Posted 27 August 2008 - 04:46 PM

Well I got it to refresh! I ended up using a Delegate with a custom event handler, Here's how I did it

My custom event handler

public class CustomTreeEventArgs
{
    TreeView view;
    public CustomTreeEventArgs(TreeView tv)
    {
        view = tv;
    }

    public TreeView TView
    {
        get { return view; }
    }
}



In the AddCategory Form I created a new Delegate and a new Event

//this goes before the declaration of the class and after
//the namespace declaration
public delegate void CustomTreeEventHandler(object sender, CustomTreeEventArgs e);



After the class declaration of the form I added

public static event CustomTreeEventHandler CustomTV;
private TreeView tView = new TreeView();



In Form1 I changed the public Form1() to look like this

public Form1()
{
    InitializeComponent();
    AddCategory.CustomTV += new CustomTreeEventHandler(treeViewHandler_CustomTreeViewHandler);
}



And treeViewHandler_CustomTreeViewHandler looks like this

private void treeViewHandler_CustomTreeViewHandler(object sender,  CustomTreeEventArgs e)
{
    LoadSnippetCategories();
}



LoadSnippetCategories() looks like this

public void LoadSnippetCategories()
{
    string xmlFile = "Categories.xml";
    this.tvLanguages.Nodes.Clear();
    CategoriesManager.LoadCategoriesIntoTreeView(ref xmlFile, this.tvLanguages);
}



Finally in the "Add Category" button click event in the AddCategory form I have this

private void cmdAdd_Click(object sender, EventArgs e)
{
    
    string file = "Categories.xml";
    string name = cboCategories.Text;
    string tag = cboCategories.SelectedValue.ToString();
    if (!(CategoriesManager.AddNewCategory(ref name, ref tag, ref file)))
    {
        MessageBox.Show(CategoriesManager.ReturnMessage);
    }
    else
    {
        CustomTV(this, new CustomTreeEventArgs(tView));             
        this.Hide();
    }
}



gabehabe you are more than welcome to use this code, which works perfectly for reloading the TreeView from a different form :)
Was This Post Helpful? 0
  • +
  • -

#60 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 28 August 2008 - 03:26 AM

Thanks Psycho :^:
I might use something similar in a later update, but for now, I'll stick with what I've got.

As for me, I'm gonna start working on making it customisable today :)
Was This Post Helpful? 0
  • +
  • -

#61 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Snippet Manager

Posted 28 August 2008 - 11:28 AM

Well got the syntax highlighting and formatting complete. Right now it's only working for C#, PHP and C++ as I need to add more config files for more languages. I went with storing the language details in config files (.syntax) for extensibility purposes, it allows me to add more languages as I go.

I have a print preview option and print option, now I need to work on adding and saving snippets in the format I want them in. Ill upload the demo once I get more done.
Was This Post Helpful? 0
  • +
  • -

#62 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 28 August 2008 - 11:48 AM

Time for my thread to be hijacked :(
Was This Post Helpful? 0
  • +
  • -

#63 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1663
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Snippet Manager

Posted 28 August 2008 - 11:55 AM

Ill stop now gabehabe, Ive never hijacked one until now and Im truly sorry :(

I just thought we could feed off each other and learn from each ohter. I'll start my own thread now :) Please forgive me
Was This Post Helpful? 0
  • +
  • -

#64 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 28 August 2008 - 12:43 PM

Don't worry about it Psycho, I was joking... This is just a learning experience for me anyway~

Seriously, keep going. I'm learning from your code anyway ^_^

I have a question actually.
What's the simplest way to capture a key state? I want to do line numbering, and I figured the best way to do it would be with a keystate of "Keys.Return" :unsure:

Basically, is there a C# equivalent to C++ "GetAsyncKeyState()" ?
Was This Post Helpful? 0
  • +
  • -

#65 no2pencil   User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6968
  • View blog
  • Posts: 31,958
  • Joined: 10-May 07

Re: Snippet Manager

Posted 28 August 2008 - 12:43 PM

View PostPsychoCoder, on 28 Aug, 2008 - 02:55 PM, said:

Ill stop now gabehabe, Ive never hijacked one until now and Im truly sorry :(

It's awesome. I do it all the time, in fact I'm doing it now.

View PostPsychoCoder, on 28 Aug, 2008 - 02:55 PM, said:

I just thought we could feed off each other

Cannibals...
Was This Post Helpful? 0
  • +
  • -

#66 marcells23   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 143
  • Joined: 22-August 07

Re: Snippet Manager

Posted 28 August 2008 - 12:50 PM

i wouldnt use GetAsyncKeyState..it is possible in c# but it would probably be more accurate to count the number of newlines. this way if the user hits delete your line count wont be off
Was This Post Helpful? 0
  • +
  • -

#67 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 28 August 2008 - 12:54 PM

True. The main thing I wanted to avoid was something like:
if (code.Text[code.Selectionstart-1] == '\n')
Because then, if you moved the cursor to somewhere after a new line, it would screw up.

Problem is, when the text in the RTB gets longer, the loop to count the new line characters will get longer, and if the user types fast, (which I do) it will freeze, because it won't have enough time to loop. It did it to me before, I had to minimise it.
Was This Post Helpful? 0
  • +
  • -

#68 marcells23   User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 143
  • Joined: 22-August 07

Re: Snippet Manager

Posted 28 August 2008 - 12:56 PM

View Postgabehabe, on 28 Aug, 2008 - 03:54 PM, said:

True. The main thing I wanted to avoid was something like:
if (code.Text[code.Selectionstart-1] == '\n')
Because then, if you moved the cursor to somewhere after a new line, it would screw up.

I never thought of simply scanning through the rich text box :-S


Yes scanning through the text would work fine as long as your snippets dont get REALLY Long. The longer the snippet, the slower the scan would be.
Was This Post Helpful? 0
  • +
  • -

#69 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 28 August 2008 - 01:21 PM

OK, I think I might have a faster, more efficient idea. I'll give it a go, then let you know

I did it! I just need to make it scroll with the text box, which should be possible~

		while (code.Lines.Length > currentLine)
			{
				currentLine++;
				lineNumbers.Text += "\n" + currentLine;
			}


Now just to add scrolling, then I'll upload the latest version!
Was This Post Helpful? 0
  • +
  • -

#70 gabehabe   User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1440
  • View blog
  • Posts: 11,025
  • Joined: 06-February 08

Re: Snippet Manager

Posted 28 August 2008 - 03:48 PM

@Psycho: You're welcome to continue hijacking my thread, I honestly don't mind. Come join the party! I'm really intrigued to see your current version, I haven't even seen one glimpse of it yet!

Done it!

Here's a screenshot:
http://www.dreamincode.net/forums/index.php?act=Attach&type=post&id=8135

The only bug I've come across is that it won't update them when you scroll the rich text box~ only when you type. I need to look into event handling a little better, I guess :P

Got a couple of little updates to make, then I'll upload it tomorrow. Stand by!

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

  • (11 Pages)
  • +
  • « First
  • 3
  • 4
  • 5
  • 6
  • 7
  • Last »