]> git.sven.stormbind.net Git - sven/vym.git/blob - src/macros.cpp
New upstream version 2.9.22
[sven/vym.git] / src / macros.cpp
1 #include "macros.h"
2
3 #include "settings.h"
4
5 #include <QDebug>
6 #include <QDir>
7 #include <QMessageBox>
8 #include <QTextStream>
9
10 extern Settings settings;
11 extern QDir vymBaseDir;
12
13 QString Macros::getPath()
14 {
15     return macrosPath;
16 }
17
18 bool Macros::setPath(const QString &path)
19 {
20     if (pathExists(path)) {
21         macrosPath = path;
22         return true;
23     } else
24         return false;
25 }
26
27 QString Macros::get()
28 {
29     QFile f(macrosPath);
30     if (!f.open(QIODevice::ReadOnly)) {
31         qWarning() << "Couldn't read macros in get()";
32         return QString();
33     }
34         
35     QTextStream ts(&f);
36     QString macros = ts.readAll();
37
38     return macros;
39 }
40
41 bool Macros::pathExists(const QString &path)
42 {
43     QFile f(path);
44     if (!f.open(QIODevice::ReadOnly)) {
45         QMessageBox::warning(
46             0, QObject::tr("Warning"),
47                 QObject::tr("Couldn't find macros at  %1.\n","Macros::pathExists").arg(path) +
48                     QObject::tr("Please use Settings->") +
49                     QObject::tr("Set directory for vym macros"));
50         return false;
51     } else
52         return true;
53 }
54
55 QString Macros::help()
56 {
57     QRegExp re("^//.*Macro.*F[0-9]{1,2}");
58     return get().split("\n").filter(re).replaceInStrings("// ", "").join("\n");
59 }