SlickEdit Community
SlickEdit Product Discussion => SlickEditĀ® => Slick-CĀ® Macro Programming => Topic started by: wconley on January 14, 2019, 02:10:54 PM
-
I would like to create a macro to insert a function header comment block that includes the author's name. Not sure how to globally set the authors name that I can access each time the macro is executed. Any suggestions?
-
You should be able to call the function getAuthor() if the userid will do.
-
Hi Dan,
I'm looking for the full name string. I created a simple form with a text box and button. The idea is the user can invoke the form, type in his name and press the button. I'd like to store what he typed in a place that is persistent so he only has to do this once and in a way that I can grab it from the 'create function header' macro. Not sure if I'm approaching this right or where I can store the name string.
-
Are you ok with them typing it in the first time each instance of the editor, or want them to do it just once?
-
Would rather be able to do it just once but first time for each instance of the editor would be okay too.
-
You can save it to a file with the code below.
On Windows you can read the system environment variable USERNAME with get_env('USERNAME');
_command void xsave_user_name(_str username = 'fred')
{
_str filename = _ConfigPath() :+ 'mydata.ini';
int temp_view_id;
int orig_view_id = _create_temp_view(temp_view_id);
insert_line(username);
p_window_id = orig_view_id;
int status = _ini_put_section(filename, 'SectionUserName', temp_view_id);
if (status) {
_message_box('Error writing file : ' :+ filename);
}
}
_command _str xload_user_name()
{
_str filename = _ConfigPath() :+ 'mydata.ini';
int tempWID;
status := _ini_get_section(filename, 'SectionUserName', tempWID);
if (status)
{
//_message_box('Error reading file : ' :+ filename);
return '';
}
origWID := p_window_id;
p_window_id = tempWID;
top();
_str line = '';
get_line(line);
p_window_id = origWID;
// message(line);
return line;
}
-
Graeme for the win. This could be improved slightly by calling textBoxDialog to get the first value... but if they're just entering it once, the ini file should be fine.
-
Hi Dan
You just lost me slightly there. Do you mean it's easier just to use textBoxDialog and not have the ini file at all? I did think about textBoxDialog but I wasn't sure if it kept its data through an upgrade and the OP said he already made a form so I thought he would probably want to keep it.
-
Hi Dan
You just lost me slightly there. Do you mean it's easier just to use textBoxDialog and not have the ini file at all? I did think about textBoxDialog but I wasn't sure if it kept its data through an upgrade and the OP said he already made a form so I thought he would probably want to keep it.
No, just that if the ini isn't found, you could use it to prompt the first time.
-
Dan and Graeme, this sounds perfect. Thank you both very much!!!
-
If you pass a retrieve_name to textBoxDialog(), along with the TB_RETRIEVE_INIT flag, then you can take advantage of dialog box retrieval to do the heavy lifting for you. In fact, this will allow you to use F7/F8 to flip through previous results you input:
result := textBoxDialog("I have a question", // Form caption
TB_RETRIEVE_INIT, // Flags
0, // Use default textbox width
"", // Help item
"42,Cancel", // Buttons and captions
"the_answer_to_life_the_universe_and_everything", // Retrieve Name
"What is the answer:");
-
ok, do you know if the information persists through an upgrade?
-
It is stored in vrestore.slk. Also, we are looking at adding dialog retrieval support to parameterized alias expansion, so for a case like the OP's request, you wouldn't need to write any code at all.
-
If you pass a retrieve_name to textBoxDialog(), along with the TB_RETRIEVE_INIT flag, then you can take advantage of dialog box retrieval to do the heavy lifting for you. In fact, this will allow you to use F7/F8 to flip through previous results you input:
result := textBoxDialog("I have a question", // Form caption
TB_RETRIEVE_INIT, // Flags
0, // Use default textbox width
"", // Help item
"42,Cancel", // Buttons and captions
"the_answer_to_life_the_universe_and_everything", // Retrieve Name
"What is the answer:");
I think this is the best solution. They are prompted every time but will generally just hit enter after the first time because the answer is the same.
Dennis gets a hero point, not for the idea, but for the Hitchhiker's Guide reference.