Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 Refactor: Move inline data to named constant
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Mordachai
Tomato Guru

USA
224 Posts

Posted - Jun 09 2010 :  11:40:36 AM  Show Profile  Reply with Quote
I have a literal bit of data (an int, a string, etc.) which I am going to need to use more than once. Usually I end up typing the value inline, and then later extracting it as a constant for that translation module.

e.g.:
	RegistryKey keyOpenWith(keyClass.OpenSubKey(_T("OpenWithProgids"), KEY_READ));
	CStringArray openwiths;
	keyOpenWith.EnumerateValueNames(openwiths);
	for (int j = 0; j < openwiths.GetCount(); ++j)
		if (Contains(our_progids, openwiths[j], case_insensitive_equal_to))
			our_openwiths.push_back(std::make_pair(classes[iClass], openwiths[j]));

It would be great to have a Refactor: Extract constant.

That would simply allow me to name it (and set its type - much like extracting a method), and then it would move the definition to the file header? or just before the method/function body? Or perhaps give me a scope option as to whether to make it visible only in this function, or translation module, or class, etc.

I envision something like this:

const TCHAR kOpenWithProgids[] = _T("OpenWithProgids");

And further down in the code...
	RegistryKey keyOpenWith(keyClass.OpenSubKey(kOpenWithProgids, KEY_READ));
	CStringArray openwiths;
	keyOpenWith.EnumerateValueNames(openwiths);
	for (int j = 0; j < openwiths.GetCount(); ++j)
		if (Contains(our_progids, openwiths[j], case_insensitive_equal_to))
			our_openwiths.push_back(std::make_pair(classes[iClass], openwiths[j]));

feline
Whole Tomato Software

United Kingdom
19020 Posts

Posted - Jun 14 2010 :  11:10:41 AM  Show Profile  Reply with Quote
We are looking into adding a feature like this at some point:

case=1492

At first it might just extract a local variable, but it will be fairly quick and easy to convert this local variable into a const, if required.

zen is the art of being at one with the two'ness
Go to Top of Page

peterchen
Tomato Guru

126 Posts

Posted - Jun 22 2010 :  03:52:50 AM  Show Profile  Reply with Quote
I wish(ed) for this, too, and yes, just making the extraction to a local variable would solve the "tricky" part. Fixing the constness, moving it to another place etc. is easy in the editor.
Go to Top of Page

Mordachai
Tomato Guru

USA
224 Posts

Posted - Jun 22 2010 :  10:54:46 AM  Show Profile  Reply with Quote
It would be really sweet if it would automatically replace all occurrences of the selected data with the newly named & created variable. ;)
Go to Top of Page

sean
Whole Tomato Software

USA
2817 Posts

Posted - Nov 07 2014 :  10:08:15 AM  Show Profile  Reply with Quote
case=1492 is implemented in build 2052
Go to Top of Page

Mordachai
Tomato Guru

USA
224 Posts

Posted - Nov 07 2014 :  10:54:12 AM  Show Profile  Reply with Quote
You guys rock! :D
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000