void StringUtil::splitInternal(vector<string> &output, const string& input, const string& delimiter)
{
	size_t start = 0;

	string temp = input;
	start = temp.find(delimiter);
	while(start!=string::npos)
	{
		if(start!=0)
		{
			output.push_back(temp.substr(0, start));
		}
		else
		{
			output.push_back("");
		}
		if(temp.length()>start+delimiter.length())
		{
			temp = temp.substr(start+delimiter.length());
			start = temp.find(delimiter);
		}
		else
		{
			temp = temp.substr(start);
			break;
		}
	}
	replaceFirst(temp, delimiter, "");
	output.push_back(temp);
}
Exemple #2
0
/*将str1出现的所有的str2都替换为str3*/
void replace(char *str1,char *str2,char *str3)
{
	while(strstr(str1,str2)!=NULL)
	{
		replaceFirst(str1,str2,str3);
	}
}
void linkDirs(const string & sourceFolder, const string & destFolder, const vector<string> & dirs)
{
	assertExists(destFolder);
	for (size_t i = 0; i < dirs.size(); i++)
	{
		string source = sourceFolder + dirs[i];
		string target = destFolder   + dirs[i];

		// Check for redundant monad/ directory
		// This allows the monad/ dir to be safely renamed
		if (replaceFirst(source, "/../monad/","/"))
			replaceFirst(target, "/monad/","/");

		assertExists(destFolder + source + '/');

		if (symlink(source.c_str(), target.c_str()) != 0)
		{
			cerr << "symlink failed: " << target << ": ";
			perror(NULL);
			exit(-1);
		}
	}
}
string StringUtil::replaceFirstCopy(const string &str, const string& ths, const string& with)
{
	string strn = str;
	replaceFirst(strn, ths, with);
	return strn;
}
QFEHelpEditorWidget::QFEHelpEditorWidget(QWidget* parent) :
    QWidget(parent),
    ui(new Ui::QFEHelpEditorWidget)
{
    modified=false;
    newScript=true;
    ui->setupUi(this);

    ui->edtScript->getEditor()->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
    ui->edtScript->getEditor()->setLineWrapMode(QTextEdit::WidgetWidth);
    connect(ui->edtScript->getEditor()->document(), SIGNAL(contentsChanged()), this, SLOT(documentWasModified()));



    highlighter=new QFHTMLHighlighter("", ui->edtScript->getEditor()->document());
    highlighter->setUseSpecial2("$(", ")$");
    highlighter->setUseSpecial1("$$", "$$");

    completer = new QCompleter(ui->edtScript->getEditor());
    completermodel=modelFromFile(ProgramOptions::getInstance()->getAssetsDirectory()+"/qtscript/completer.txt");
    completer->setModel(completermodel);
    completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    completer->setWrapAround(false);
    ui->edtScript->getEditor()->setCompleter(completer);



    recentHelpFiles=new QRecentFilesMenu(this);
    recentHelpFiles->setUseSystemFileIcons(false);
    recentHelpFiles->setAlwaysEnabled(true);
    connect(recentHelpFiles, SIGNAL(openRecentFile(QString)), this, SLOT(openScriptNoAsk(QString)));
    ui->btnOpen->setMenu(recentHelpFiles);
    connect(ui->edtScript->getEditor(), SIGNAL(cursorPositionChanged()), this, SLOT(edtScript_cursorPositionChanged()));


    actLoadAutosave=new QFActionWithNoMenuRole(tr("load last autosaved file ..."), this);
    connect(actLoadAutosave, SIGNAL(triggered()), this, SLOT(reloadLastAutosave()));

    cutAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_cut.png"), tr("Cu&t"), this);
    cutAct->setShortcut(tr("Ctrl+X"));
    cutAct->setToolTip(tr("Cut the current selection's contents to the "
                            "clipboard"));
    connect(cutAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(cut()));

    copyAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_copy.png"), tr("&Copy"), this);
    copyAct->setShortcut(tr("Ctrl+C"));
    copyAct->setToolTip(tr("Copy the current selection's contents to the "
                             "clipboard"));
    connect(copyAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(copy()));

    pasteAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_paste.png"), tr("&Paste"), this);
    pasteAct->setShortcut(tr("Ctrl+V"));
    pasteAct->setToolTip(tr("Paste the clipboard's contents into the current "
                              "selection"));
    connect(pasteAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(paste()));

    undoAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_undo.png"), tr("&Undo"), this);
    undoAct->setShortcut(tr("Ctrl+Z"));
    undoAct->setToolTip(tr("Undo the last change "));
    connect(undoAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(undo()));

    redoAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_redo.png"), tr("&Redo"), this);
    redoAct->setShortcut(tr("Ctrl+Shift+Z"));
    redoAct->setToolTip(tr("Redo the last undone change "));
    connect(redoAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(redo()));

    findAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_find.png"), tr("&Find ..."), this);
    findAct->setShortcut(tr("Ctrl+F"));
    findAct->setToolTip(tr("Find a string in sequence "));
    connect(findAct, SIGNAL(triggered()), this, SLOT(findFirst()));

    findNextAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_find_next.png"), tr("Find &next"), this);
    findNextAct->setShortcut(tr("F3"));
    findNextAct->setToolTip(tr("Find the next occurence "));
    connect(findNextAct, SIGNAL(triggered()), this, SLOT(findNext()));
    findNextAct->setEnabled(false);

    replaceAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_find_replace.png"), tr("Find && &replace ..."), this);
    replaceAct->setShortcut(tr("Ctrl+R"));
    replaceAct->setToolTip(tr("Find a string in sequence and replace it with another string "));
    connect(replaceAct, SIGNAL(triggered()), this, SLOT(replaceFirst()));

    commentAct = new QFActionWithNoMenuRole(tr("&Comment text"), this);
    commentAct->setShortcut(tr("Ctrl+B"));
    commentAct->setToolTip(tr("add (single line) comment at the beginning of each line "));
    connect(commentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(comment()));

    unCommentAct = new QFActionWithNoMenuRole(tr("&Uncomment text"), this);
    unCommentAct->setShortcut(tr("Ctrl+Shift+B"));
    unCommentAct->setToolTip(tr("remove (single line) comment at the beginning of each line "));
    connect(unCommentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(uncomment()));

    indentAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_indent.png"), tr("&Increase indention"), this);
    commentAct->setShortcut(tr("Ctrl+I"));
    indentAct->setToolTip(tr("increase indention "));
    connect(indentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(indentInc()));

    unindentAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_unindent.png"), tr("&Decrease indention"), this);
    unindentAct->setShortcut(tr("Ctrl+Shift+I"));
    unindentAct->setToolTip(tr("decrease indention "));
    connect(unindentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(indentDec()));

    gotoLineAct = new QFActionWithNoMenuRole(tr("&Goto line ..."), this);
    gotoLineAct->setShortcut(tr("Alt+G"));
    gotoLineAct->setToolTip(tr("goto a line in the opened file "));
    connect(gotoLineAct, SIGNAL(triggered()), this, SLOT(gotoLine()));

    printAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/script_print.png"), tr("&Print ..."), this);
    printAct->setToolTip(tr("print the current SDFF file "));
    connect(printAct, SIGNAL(triggered()), this, SLOT(print()));

    actInsertIcon = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/insert_image.png"), tr("&Insert icon ..."), this);
    actInsertIcon->setToolTip(tr("print the current SDFF file "));
    connect(actInsertIcon, SIGNAL(triggered()), this, SLOT(insertIcon()));


    toEntityAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/toentity.png"), tr("&Convert characters to entities ..."), this);
    toEntityAct->setToolTip(tr("convert characters in the selected text to HTML entities"));
    connect(toEntityAct, SIGNAL(triggered()), this, SLOT(toEntity()));

    toCharAct = new QFActionWithNoMenuRole(QIcon(":/qfe_helpeditor/tochars.png"), tr("&Convert entities to characters ..."), this);
    toCharAct->setToolTip(tr("convert HTML entities in the selected text to characters"));
    connect(toCharAct, SIGNAL(triggered()), this, SLOT(toChars()));

    cutAct->setEnabled(false);
    copyAct->setEnabled(false);
    undoAct->setEnabled(false);
    redoAct->setEnabled(false);
    connect(ui->edtScript->getEditor(), SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(undoAvailable(bool)), undoAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(redoAvailable(bool)), redoAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(findNextAvailable(bool)), findNextAct, SLOT(setEnabled(bool)));


    QMenu* menuMore=new QMenu(ui->tbMoreOptions);
    menuMore->addAction(indentAct);
    menuMore->addAction(unindentAct);
    menuMore->addAction(commentAct);
    menuMore->addAction(unCommentAct);
    menuMore->addSeparator();
    menuMore->addAction(toEntityAct);
    menuMore->addAction(toCharAct);
    menuMore->addSeparator();
    menuMore->addAction(actInsertIcon);
    menuMore->addSeparator();
    menuMore->addAction(gotoLineAct);
    menuMore->addAction(findAct);
    menuMore->addAction(replaceAct);
    menuMore->addAction(findNextAct);
    menuMore->addSeparator();
    menuMore->addAction(actLoadAutosave);
    ui->tbMoreOptions->setMenu(menuMore);
    ui->tbFind->setDefaultAction(findAct);
    ui->tbFindNext->setDefaultAction(findNextAct);
    ui->tbReplace->setDefaultAction(replaceAct);
    ui->tbPrint->setDefaultAction(printAct);
    ui->tbCopy->setDefaultAction(copyAct);
    ui->tbCut->setDefaultAction(cutAct);
    ui->tbPaste->setDefaultAction(pasteAct);
    ui->tbRedo->setDefaultAction(redoAct);
    ui->tbUndo->setDefaultAction(undoAct);
    ui->tbEntity->setDefaultAction(toEntityAct);
    ui->tbChars->setDefaultAction(toCharAct);



    setScriptFilename("");
    QMenu* menu;
    menu=new QMenu(tr("directories"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$mainhelpdir$$");
    addInsertAction(menu, "$$mainhelppicdir$$");
    addInsertAction(menu, "$$assetsdir$$");
    addInsertAction(menu, "$$examplesdir$$");
    addInsertAction(menu, "$$configdir$$");
    addInsertAction(menu, "$$maindir$$");
    addInsertAction(menu, "$$sourcedir$$");

    menu=new QMenu(tr("version/copyright info"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$version.svnrevision$$");
    addInsertAction(menu, "$$version.status$$");
    addInsertAction(menu, "$$version.date$$");
    addInsertAction(menu, "$$version$$");
    addInsertAction(menu, "$$version_full$$");
    menu->addSeparator();
    addInsertAction(menu, "$$thanksto$$");
    addInsertAction(menu, "$$copyright$$");
    addInsertAction(menu, "$$author$$");
    addInsertAction(menu, "$$weblink$$");
    addInsertAction(menu, "$$license$$");
    addInsertAction(menu, "$$maillist$$");
    addInsertAction(menu, "$$maillistrequest$$");
    menu->addSeparator();
    addInsertAction(menu, "$$qfcitation$$");
    addInsertAction(menu, "$$qfcitation_bibtex$$");
    addInsertAction(menu, "$$jankrieger_phdthesis$$");
    addInsertAction(menu, "$$jankrieger_phdthesis_ref$$");

    menu=new QMenu(tr("general help links"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, tr("Link: RDR general help"), "<a href=\"$qf_ui_rdr_helpfile$$\">$$qf_ui_rdr_helpfiletitle$$</a>" );
    addInsertAction(menu, tr("Link: Evaluation general help"), "<a href=\"$$qf_ui_eval_helpfile$$\">$$qf_ui_eval_helpfiletitle$$</a>" );
    addInsertAction(menu, tr("Link: Plotter Widget general help"), "<a href=\"$$qf_ui_jkqtplotter_helpfile$$\">$$qf_ui_jkqtplotter_helpfiletitle$$</a>" );
    addInsertAction(menu, tr("Link: LaTeX parser general help"), "<a href=\"$$qf_ui_latex_helpfile$$\">$$qf_ui_latex_helpfiletitle$$</a>" );
    addInsertAction(menu, tr("Link: Expression parser help"), "<a href=\"$$qf_mathparser_helpfile$$\">$$qf_mathparser_helpfiletitle$$</a>" );
    //addInsertAction(menu, tr("Link:  help"), "<a href=\"$$aa$$\">$$aa$$</a>" );
    //addInsertAction(menu, tr("Link:  help"), QString("<a href=\"$$mainhelpdir$$aa\">aa</a>") );
    addInsertAction(menu, tr("Link: Custom color palettes help"), QString("<a href=\"$$mainhelpdir$$colorpalettes.html\">custom color paletes</a>") );
    addInsertAction(menu, tr("Link: Available color palettes"), QString("<a href=\"$$mainhelpdir$$installedcolorpalettes.html\">available color paletes</a>") );
    addInsertAction(menu, tr("Link: Regular Expressions"), QString("<a href=\"$$mainhelpdir$$qf3_qtregexp.html\">regular expressions</a>") );
    addInsertAction(menu, tr("Link: Fit Functions"), QString("<a href=\"$$mainhelpdir$$qf3_fitfunc.html\">fit functions</a>") );
    addInsertAction(menu, tr("Link: Fit Algorithms"), QString("<a href=\"$$mainhelpdir$$qf3_fitalg.html\">fit algorithms</a>") );
    addInsertAction(menu, tr("Link: File Formats"), QString("<a href=\"$$mainhelpdir$$qf3_fileformats.html\">file formats</a>") );
    addInsertAction(menu, tr("Link: GPL 3.0"), QString("<a href=\"$$mainhelpdir$$gpl3_0.html\">GPL 3.0</a>") );
    addInsertAction(menu, tr("Link: FAQs"), QString("<a href=\"$$qf_faqfile$$\">Frequently asked questions</a>") );

    menu->addSeparator();
    addInsertAction(menu, "$$qf_ui_rdr_helpfile$$");
    addInsertAction(menu, "$$qf_ui_rdr_helpfiletitle$$");
    addInsertAction(menu, "$$qf_ui_eval_helpfile$$");
    addInsertAction(menu, "$$qf_ui_eval_helpfiletitle$$");
    addInsertAction(menu, "$$qf_ui_jkqtplotter_helpfile$$");
    addInsertAction(menu, "$$qf_ui_jkqtplotter_helpfiletitle$$");
    addInsertAction(menu, "$$qf_ui_latex_helpfile$$");
    addInsertAction(menu, "$$qf_ui_latex_helpfiletitle$$");
    addInsertAction(menu, "$$qf_mathparser_helpfile$$");
    addInsertAction(menu, "$$qf_mathparser_helpfiletitle$$");
    addInsertAction(menu, "$$qf_faqfile$$");


    menu=new QMenu(tr("page header/footer"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$qf_commondoc_backtop$$");
    menu->addSeparator();
    addInsertAction(menu, "$$qf_commondoc_footer.start$$");
    addInsertAction(menu, "$$qf_commondoc_footer.end$$");
    menu->addSeparator();
    addInsertAction(menu, "$$qf_commondoc_header.start$$");
    addInsertAction(menu, "$$qf_commondoc_header.end$$");
    addInsertAction(menu, "$$qf_commondoc_header.end_notitle$$");
    addInsertAction(menu, "$$qf_commondoc_header.rdr$$");
    addInsertAction(menu, "$$qf_commondoc_header.eval$$");
    addInsertAction(menu, "$$qf_commondoc_header.extension$$");
    addInsertAction(menu, "$$qf_commondoc_header.fitfunc$$");
    addInsertAction(menu, "$$qf_commondoc_header.fitalg$$");
    addInsertAction(menu, "$$qf_commondoc_header.separator$$");


    menu=new QMenu(tr("plugin info"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$local_plugin_icon$$");
    addInsertAction(menu, "$$local_plugin_iconfilename$$");
    addInsertAction(menu, "$$local_plugin_name$$");
    addInsertAction(menu, "$$local_plugin_author$$");
    addInsertAction(menu, "$$local_plugin_copyright$$");
    addInsertAction(menu, "$$local_plugin_weblink_url$$");
    addInsertAction(menu, "$$local_plugin_weblink$$");
    addInsertAction(menu, "$$local_plugin_id$$");
    addInsertAction(menu, "$$local_plugin_subid$$");
    addInsertAction(menu, "$$local_plugin_subname$$");
    addInsertAction(menu, "$$local_plugin_subshortname$$");
    addInsertAction(menu, "$$local_plugin_tutorial_file$$");
    addInsertAction(menu, "$$local_plugin_tutorial_link$$");
    addInsertAction(menu, "$$local_plugin_mainhelp_file$$");
    addInsertAction(menu, "$$local_plugin_mainhelp_link$$");
    addInsertAction(menu, "$$local_plugin_version$$");
    addInsertAction(menu, "$$local_plugin_typehelp_link$$");
    addInsertAction(menu, "$$local_plugin_typehelp_file$$");
    addInsertAction(menu, "$$local_plugin_assets$$");
    addInsertAction(menu, "$$local_plugin_examples$$");
    addInsertAction(menu, "$$local_plugin_help$$");
    addInsertAction(menu, "$$local_plugin_config$$");
    addInsertAction(menu, "$$local_plugin_tutorials$$");
    menu->addSeparator();
    addInsertAction(menu, "$$plugin_info:help:PLUGINID$$");
    addInsertAction(menu, "$$plugin_info:tutorial:PLUGINID$$");
    addInsertAction(menu, "$$plugin_info:helpdir:PLUGINID$$");
    addInsertAction(menu, "$$plugin_info:assetsdir:PLUGINID$$");
    addInsertAction(menu, "$$plugin_info:examplesdir:PLUGINID$$");
    addInsertAction(menu, "$$plugin_info:configdir:PLUGINID$$");
    menu->addSeparator();
    addInsertAction(menu, "$$fitfunction:help:PLUGINID$$");
    addInsertAction(menu, "$$fitfunction:name:PLUGINID$$");
    addInsertAction(menu, "$$fitfunction:short_name:PLUGINID$$");
    menu->addSeparator();
    addInsertAction(menu, "$$fitalgorithm:help:PLUGINID$$");
    addInsertAction(menu, "$$fitalgorithm:name:PLUGINID$$");
    addInsertAction(menu, "$$fitalgorithm:short_name:PLUGINID$$");
    menu->addSeparator();
    addInsertAction(menu, "$$importer:help:PLUGINID$$");
    addInsertAction(menu, "$$importer:name:PLUGINID$$");
    addInsertAction(menu, "$$exporter:help:PLUGINID$$");
    addInsertAction(menu, "$$exporter:name:PLUGINID$$");



    menu=new QMenu(tr("plugin lists"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$list:extension:INTERFACENAME$$");
    addInsertAction(menu, "$$list:fitfunc:$$");
    addInsertAction(menu, "$$list:fitfunc:STARTSWITH$$");
    addInsertAction(menu, "$$list:fitfunc_inplugin:PLUGIN_ID|STARTSWITH$$");
    addInsertAction(menu, "$$list:fitfunc_inplugin:PLUGIN_ID$$");
    addInsertAction(menu, "$$list:fitalg:$$");
    addInsertAction(menu, "$$list:fitalg:STARTSWITH$$");
    addInsertAction(menu, "$$list:importers:STARTSWITH$$");
    addInsertAction(menu, "$$list:exporters:STARTSWITH$$");
    addInsertAction(menu, "$$list:plugin_tutorials:PLUGIN_ID$$");


    menu=new QMenu(tr("help lists"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$tutorials_contents$$");
    addInsertAction(menu, "$$help_contents$$");
    addInsertAction(menu, "$$settings_contents$$");


    menu=new QMenu(tr("insert files"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$insert:FILENAME$$");
    addInsertAction(menu, "$$insertglobal:FILENAME$$");


    menu=new QMenu(tr("insert Equations (LaTeX)"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$math:LATEX$$");
    addInsertAction(menu, "$(LATEX)$");
    addInsertAction(menu, "$$bmath:LATEX$$");
    addInsertAction(menu, "$[LATEX]$");


    menu=new QMenu(tr("insert Literature References"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$ref:<ID>:Text$$");
    addInsertAction(menu, "$$ref:<ID>:$$");
    addInsertAction(menu, "$$invisibleref:<ID>:Text$$");
    addInsertAction(menu, "$$references$$");


    menu=new QMenu(tr("insert Figures"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$fig:FILENAME:CAPTION$$");


    menu=new QMenu(tr("insert Info boxes"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$see:Text$$");
    addInsertAction(menu, "$$note:Text$$");
    addInsertAction(menu, "$$info:Text$$");
    addInsertAction(menu, "$$warning:Text$$");
    addInsertAction(menu, "$$example:Text$$");
    addInsertAction(menu, "$$codeexample:Text$$");
    addInsertAction(menu, "$$bqtt:Text$$");
    addInsertAction(menu, "$$bqcode:Text$$");
    menu->addSeparator();
    addInsertAction(menu, "$$startbox$$");
    addInsertAction(menu, "$$startbox_info$$");
    addInsertAction(menu, "$$startbox_note$$");
    addInsertAction(menu, "$$startbox_see$$");
    addInsertAction(menu, "$$startbox_warning$$");
    addInsertAction(menu, "$$startbox_example$$");
    addInsertAction(menu, "$$startbox:backgroundcolor:bordercolor$$");
    addInsertAction(menu, "$$startbox:lightgrey:midnightblue$$");
    addInsertAction(menu, "$$endbox$$");


    menu=new QMenu(tr("insert Tooltips"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$tooltip:PHRASE$$");


    menu=new QMenu(tr("FAQs"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, tr("FAQ entry"), "$$faq_start$$\n  <a name=\"FAQ1\"><b>Question?</b>\n$$faq_answer$$\n  Answer ...\n$$faq_end$$");
    menu->addSeparator();
    addInsertAction(menu, "$$faq_start");
    addInsertAction(menu, "$$faq_answer");
    addInsertAction(menu, "$$faq_end");

    menu=new QMenu(tr("Function References"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, tr("Function reference entry"), "$$funcref_start$$<a name=\"NAME\"/><!-- func:NAME -->\n  <b><tt><!-- template -->NAME<!-- /template --></tt> - <i> DESCRIPTION </i>:</b>\n$$funcref_description$$\n    DESCRIPTION\n  <!-- /func:NAME -->\n$$funcref_end$$");
    menu->addSeparator();
    addInsertAction(menu, "$$funcref_start");
    addInsertAction(menu, "$$funcref_description");
    addInsertAction(menu, "$$funcref_end");

    menu=new QMenu(tr("insert other markups"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$$tt:Text$$");


    menu=new QMenu(tr("LaTeX"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "\\left(%1#\\right)");
    addInsertAction(menu, "\\left[%1#\\right]");
    addInsertAction(menu, "\\left\\{%1#\\right\\}");
    addInsertAction(menu, "\\left\\langle%1#\\right\\rangle");
    menu->addSeparator();
    addInsertAction(menu, "\\sqrt{%1#}");
    menu->addSeparator();
    addInsertAction(menu, "\\sum_{#}^{}%1");
    addInsertAction(menu, "\\prod_{#}^{}%1");
    addInsertAction(menu, "\\int_{#}^{}%1\\;\\mathrm{d}x");
    addInsertAction(menu, "\\iint_{#}^{}%1\\;\\mathrm{d}^2x");
    addInsertAction(menu, "\\iiint_{#}^{}%1\\;\\mathrm{d}^3x");
    addInsertAction(menu, "\\oint_{#}^{}%1\\;\\mathrm{d}x");
    addInsertAction(menu, "\\lim_{%1#}");
    addInsertAction(menu, "\\argmin_{%1#}");
    addInsertAction(menu, "\\argmax_{%1#}");
    menu->addSeparator();
    addInsertAction(menu, "\\vec{%1#}");
    addInsertAction(menu, "\\hat{%1#}");
    addInsertAction(menu, "\\tilde{%1#}");
    addInsertAction(menu, "\\mathbf{%1#}");
    addInsertAction(menu, "\\mathrm{%1#}");
    addInsertAction(menu, "\\mathit{%1#}");
    addInsertAction(menu, "\\mathsf{%1#}");
    addInsertAction(menu, "\\mathbb{%1#}");
    addInsertAction(menu, "\\mathscript{%1#}");
    addInsertAction(menu, "\\underline{%1#}");
    //addInsertAction(menu, "$$$$");

    menu=new QMenu(tr("Special Characters"), this);
    ui->edtScript->getEditor()->addAction(menu->menuAction());
    addInsertAction(menu, "$" "&#36;");
    addInsertAction(menu, "$$" "&#36;&#36;");


    QTimer::singleShot(AUTOSAVE_INTERVAL_MSEC, this, SLOT(autosave()));

}
QFESPIMB040ScriptedAcquisition::QFESPIMB040ScriptedAcquisition(QFESPIMB040MainWindow2* mainWindow, QFESPIMB040AcquisitionTools* acqTools, QFPluginLogService* log, QWidget* parent, QFPluginServices* pluginServices, QFESPIMB040OpticsSetupBase* opticsSetup, QFESPIMB040AcquisitionDescription* acqDescription, QFESPIMB040ExperimentDescription* expDescription, QString /*configDirectory*/) :
    QWidget(parent),
    ui(new Ui::QFESPIMB040ScriptedAcquisition)
{

    this->m_pluginServices=pluginServices;
    this->opticsSetup=opticsSetup;
    this->acqDescription=acqDescription;
    this->expDescription=expDescription;
    this->log=log;
    this->acqTools=acqTools;
    this->mainWindow=mainWindow;

    acquisitionTools=new QFESPIMB040ScriptedAcquisitionTools(this, mainWindow, acqTools, log, this, pluginServices, opticsSetup, acqDescription, expDescription);
    instrumentControl=new QFESPIMB040ScriptedAcquisitionInstrumentControl(this, mainWindow, acqTools, log, this, pluginServices, opticsSetup, acqDescription, expDescription);
    acquisitionControl=new QFESPIMB040ScriptedAcquisitionAcquisitionControl(this, mainWindow, acqTools, log, this, pluginServices, opticsSetup, acqDescription, expDescription);


    engine=new QScriptEngine();


    ui->setupUi(this);
    findDlg=new QFESPIMB040FindDialog(this);
    replaceDlg=new QFESPIMB040ReplaceDialog(this);

    highlighter=new QFQtScriptHighlighter("", ui->edtScript->getEditor()->document());

    completer = new QCompleter(ui->edtScript->getEditor());
    completermodel=modelFromFile(ProgramOptions::getInstance()->getAssetsDirectory()+"/qtscript/completer.txt");
    completer->setModel(completermodel);
    completer->setModelSorting(QCompleter::CaseInsensitivelySortedModel);
    completer->setCaseSensitivity(Qt::CaseInsensitive);
    completer->setWrapAround(false);
    ui->edtScript->getEditor()->setCompleter(completer);

    recentMaskFiles=new QRecentFilesMenu(this);
    recentMaskFiles->setUseSystemFileIcons(false);
    recentMaskFiles->setAlwaysEnabled(true);
    connect(recentMaskFiles, SIGNAL(openRecentFile(QString)), this, SLOT(openScriptNoAsk(QString)));
    ui->btnOpen->setMenu(recentMaskFiles);
    connect(ui->edtScript->getEditor(), SIGNAL(cursorPositionChanged()), this, SLOT(edtScript_cursorPositionChanged()));



    cutAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_cut.png"), tr("Cu&t"), this);
    cutAct->setShortcut(tr("Ctrl+X"));
    cutAct->setStatusTip(tr("Cut the current selection's contents to the "
                            "clipboard"));
    connect(cutAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(cut()));

    copyAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_copy.png"), tr("&Copy"), this);
    copyAct->setShortcut(tr("Ctrl+C"));
    copyAct->setStatusTip(tr("Copy the current selection's contents to the "
                             "clipboard"));
    connect(copyAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(copy()));

    pasteAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_paste.png"), tr("&Paste"), this);
    pasteAct->setShortcut(tr("Ctrl+V"));
    pasteAct->setStatusTip(tr("Paste the clipboard's contents into the current "
                              "selection"));
    connect(pasteAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(paste()));

    undoAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_undo.png"), tr("&Undo"), this);
    undoAct->setShortcut(tr("Ctrl+Z"));
    undoAct->setStatusTip(tr("Undo the last change "));
    connect(undoAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(undo()));

    redoAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_redo.png"), tr("&Redo"), this);
    redoAct->setShortcut(tr("Ctrl+Shift+Z"));
    redoAct->setStatusTip(tr("Redo the last undone change "));
    connect(redoAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(redo()));

    findAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_find.png"), tr("&Find ..."), this);
    findAct->setShortcut(tr("Ctrl+F"));
    findAct->setStatusTip(tr("Find a string in sequence "));
    connect(findAct, SIGNAL(triggered()), this, SLOT(findFirst()));

    findNextAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_find_next.png"), tr("Find &next"), this);
    findNextAct->setShortcut(tr("F3"));
    findNextAct->setStatusTip(tr("Find the next occurence "));
    connect(findNextAct, SIGNAL(triggered()), this, SLOT(findNext()));
    findNextAct->setEnabled(false);

    replaceAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_find_replace.png"), tr("Find && &replace ..."), this);
    replaceAct->setShortcut(tr("Ctrl+R"));
    replaceAct->setStatusTip(tr("Find a string in sequence and replace it with another string "));
    connect(replaceAct, SIGNAL(triggered()), this, SLOT(replaceFirst()));

    commentAct = new QFActionWithNoMenuRole(tr("&Comment text"), this);
    commentAct->setShortcut(tr("Ctrl+B"));
    commentAct->setStatusTip(tr("add (single line) comment at the beginning of each line "));
    connect(commentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(comment()));

    unCommentAct = new QFActionWithNoMenuRole(tr("&Uncomment text"), this);
    unCommentAct->setShortcut(tr("Ctrl+Shift+B"));
    unCommentAct->setStatusTip(tr("remove (single line) comment at the beginning of each line "));
    connect(unCommentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(uncomment()));

    indentAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_indent.png"), tr("&Increase indention"), this);
    commentAct->setShortcut(tr("Ctrl+I"));
    indentAct->setStatusTip(tr("increase indention "));
    connect(indentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(indentInc()));

    unindentAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_unindent.png"), tr("&Decrease indention"), this);
    unindentAct->setShortcut(tr("Ctrl+Shift+I"));
    unindentAct->setStatusTip(tr("decrease indention "));
    connect(unindentAct, SIGNAL(triggered()), ui->edtScript->getEditor(), SLOT(indentDec()));

    gotoLineAct = new QFActionWithNoMenuRole(tr("&Goto line ..."), this);
    gotoLineAct->setShortcut(tr("Alt+G"));
    gotoLineAct->setStatusTip(tr("goto a line in the opened file "));
    connect(gotoLineAct, SIGNAL(triggered()), this, SLOT(gotoLine()));

    printAct = new QFActionWithNoMenuRole(QIcon(":/spimb040/script_print.png"), tr("&Print ..."), this);
    printAct->setStatusTip(tr("print the current SDFF file "));
    connect(printAct, SIGNAL(triggered()), this, SLOT(print()));

    cutAct->setEnabled(false);
    copyAct->setEnabled(false);
    undoAct->setEnabled(false);
    redoAct->setEnabled(false);
    connect(ui->edtScript->getEditor(), SIGNAL(copyAvailable(bool)), cutAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(copyAvailable(bool)), copyAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(undoAvailable(bool)), undoAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(redoAvailable(bool)), redoAct, SLOT(setEnabled(bool)));
    connect(ui->edtScript->getEditor(), SIGNAL(findNextAvailable(bool)), findNextAct, SLOT(setEnabled(bool)));


    QMenu* menuMore=new QMenu(ui->tbMoreOptions);
    menuMore->addAction(indentAct);
    menuMore->addAction(unindentAct);
    menuMore->addAction(commentAct);
    menuMore->addAction(unCommentAct);
    menuMore->addSeparator();
    menuMore->addAction(gotoLineAct);
    menuMore->addAction(findAct);
    menuMore->addAction(replaceAct);
    menuMore->addAction(findNextAct);
    ui->tbMoreOptions->setMenu(menuMore);
    ui->tbFind->setDefaultAction(findAct);
    ui->tbFindNext->setDefaultAction(findNextAct);
    ui->tbReplace->setDefaultAction(replaceAct);
    ui->tbPrint->setDefaultAction(printAct);
    ui->tbCopy->setDefaultAction(copyAct);
    ui->tbCut->setDefaultAction(cutAct);
    ui->tbPaste->setDefaultAction(pasteAct);
    ui->tbRedo->setDefaultAction(redoAct);
    ui->tbUndo->setDefaultAction(undoAct);



    updateReplaces();
    //bindLineEdit(ui->edtPrefix1);
    ui->btnCancel->setVisible(false);
    ui->widProgress->setVisible(false);
    ui->labStatus->setVisible(false);
    setScriptFilename(tr("new_acquisition_script.js"));


    QDir d(QFPluginServices::getInstance()->getPluginHelpDirectory("ext_spimb040")+"acquisition_script/");
    QStringList filter;
    filter<<"*.html"<<"*.htm"<<"*.txt";
    QStringList files=d.entryList(filter, QDir::Files);
    threadsFinished=0;
    maxThreads=2;
    QList<QStringList> absFiles;

    for (int i=0; i<maxThreads; i++) {
        QStringList sl;
        absFiles.push_back(sl);
    }
    for (int i=0; i<files.size(); i++) {
        QString file=d.absoluteFilePath(files[i]);
        absFiles[i%maxThreads].append(file);
    }
    for (int i=0; i<maxThreads; i++) {
        threads.append(new QFESPIMB040ScriptedAcquisitionDocSearchThread(absFiles[i], this));
        connect(threads[i], SIGNAL(finished()), this, SLOT(threadFinished()));
        connect(threads[i], SIGNAL(foundFunction(QString,QString,QString)), this, SLOT(addFunction(QString,QString,QString)));
    }
    QTimer::singleShot(10, this, SLOT(delayedStartSearchThreads()));
}