Author Topic: C::B newbie - changes I want to implement & questions.  (Read 6101 times)

lukeH

  • Guest
C::B newbie - changes I want to implement & questions.
« on: November 20, 2005, 12:09:04 pm »
Hi there.  Having recently discovered C::B, and started using it for all my coding (w/ Visual C++ Toolkit), I now want to change it!
It's the usual story - WOW! This is so great! I wish it did *blah*!

Basically I've got some ideas, and I think I know how to implement them, but I'm still feeling around a bit and getting used to open source, wxWindows and the C::B code structure.  So, I have a couple of questions; please bear with me :)

One (small) idea is: I want to add another macro for the command lines of the user-configured external tools.
This will be ${CUR_WORD}, replaced by the nearest word to the caret within the active editor.
I have made the required changes to my copy of macrosmanager.cpp.
Now I'd like to add a
Code
 wxString GetCurrentWord()
method, as this could be used by future plugins or interface classes, and saves repetition of the small block of code required.  The question I have is: WHERE?

I wondered if it should go in cbEditor, or wxScintilla, but it seemed a bit more like something to add in the control - so I guess that's wxScintilla.
Since I'm new to OpenSource, I thought I'd ask what people thought.
If it is added to wxScintilla, how often is C::B's version of wxScintilla updated?

There's more, but for now I'll leave the questions at that and keep reading code.
Cheers,
 - Luke



Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: C::B newbie - changes I want to implement & questions.
« Reply #1 on: November 20, 2005, 01:24:25 pm »
The correct place for this would be MacrosManager, as this is the class that expands those variables. The selection can be queried either using GetSelectedText() or WordStartPosition() with GetTextRange()from the editor control (which you get via GetControl()).

However, you should be careful with such modifications because MacrosManager also expands variables for the compiler, so whatever you add, it will be available to the compiler (and linker), too. Obviously, it makes little sense to have the currently selected word available in the compiler. First, it is not guaranteed that there is an editor open while compiling at all, second, you may have open a file from an entirely different target, and third, compilation runs asynchronously in respect to editing, so the selection is likely to change between the compilation of individual files. This would create a terrible mess (unless chaos is what is intended).

Yes, you may argue that someone would be crazy to use that variable in compiler settings, but experience shows that if there is a feature, then people *will* use it.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

lukeH

  • Guest
Re: C::B newbie - changes I want to implement & questions.
« Reply #2 on: November 21, 2005, 06:55:17 am »
Ah, I hadn't yet realized that the MacrosManager also does compile-time macros.  As I said I'm still learning my way around..
I have taken care to check that GetBuiltinActiveEditor *does* return something, so things should be okay on that score.
I don't suppose there's any isInCompile() method or similar?

Also, I was particularly wondering where to put a GetCurrentWord() method anyway. 
I thought that this method would be reusable and it would do the control calls:
GetSelectedText(), WordStartPosition(), GetTextRange() etc.

It doesn't make sense to put this in the macros manager, as it is a method which could be used anytime a plugin etc.. wants a copy of the 'current' word at the caret.  I just don't know which things the various editor classes are designed to be responsible for, and so where best to put it.

I suppose that, to some extent, one just has to put in somewhere. People can always move it if it's best moved, right?

Cheers,
 - Luke
« Last Edit: November 21, 2005, 06:57:39 am by lukeH »

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: C::B newbie - changes I want to implement & questions.
« Reply #3 on: November 21, 2005, 12:13:52 pm »
Also, I was particularly wondering where to put a GetCurrentWord() method anyway.
The likely best place for that would be cbEditor, although IMO it is generally not necessary to have such a function, as you can easily call GetControl() and GetSelectedText() - it is a mere convenience function.

Besides, are we even guaranteed that cbEditor actually has a current word? In theory, cbEditor could be anything, not necessarily a text editor. All we know for sure is it is an EditorBase (i.e. a better wxPanel) and it has some child of type wxControl. Not that I could think of an application where that would make sense (maybe an UML editor), but it is entirely possible that an editor does not know what a "word" is at all.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."