File: commandhelp.cpp

package info (click to toggle)
copyq 3.7.3-1~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 10,480 kB
  • sloc: cpp: 51,894; sh: 734; python: 211; xml: 57; makefile: 34
file content (195 lines) | stat: -rw-r--r-- 9,231 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
/*
    Copyright (c) 2018, Lukas Holecek <hluk@email.cz>

    This file is part of CopyQ.

    CopyQ is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    CopyQ is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with CopyQ.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "commandhelp.h"

#include "common/common.h"
#include "scriptable/scriptable.h"

CommandHelp::CommandHelp()
    : cmd()
    , desc()
    , args()
{
}

CommandHelp::CommandHelp(const char *command, const QString &description)
    : cmd(command)
    , desc(description)
    , args()
{
}

CommandHelp &CommandHelp::addArg(const QString &arg)
{
    args.append(' ');
    args.append(arg);
    return *this;
}

QString CommandHelp::toString() const
{
    if (cmd.isNull())
        return "\n";

    const int indent = 23;
    bool indentFirst = desc.startsWith('\n');
    return QString("    %1").arg(cmd + args, indentFirst ? 0 : -indent)
            + (indentFirst ? QString() : QString("  "))
            + QString(desc).replace('\n', "\n" + QString(' ')
                                    .repeated(4 + 2 + (indentFirst ? 0 : indent))) + "\n";
}

QList<CommandHelp> commandHelp()
{
    return QList<CommandHelp>()
            << CommandHelp("show",
                           Scriptable::tr("Show main window and optionally open tab with given name."))
               .addArg("[" + Scriptable::tr("NAME") + "]")
            << CommandHelp("hide",
                           Scriptable::tr("Hide main window."))
            << CommandHelp("toggle",
                           Scriptable::tr("Show or hide main window."))
            << CommandHelp("menu",
                           Scriptable::tr("Open context menu."))
            << CommandHelp("exit",
                           Scriptable::tr("Exit server."))
            << CommandHelp("disable, enable",
                           Scriptable::tr("Disable or enable clipboard content storing."))
            << CommandHelp()
            << CommandHelp("clipboard",
                           Scriptable::tr("Print clipboard content."))
               .addArg("[" + Scriptable::tr("MIME") + "]")
           #ifdef HAS_MOUSE_SELECTIONS
            << CommandHelp("selection",
                           Scriptable::tr("Print X11 selection content."))
               .addArg("[" + Scriptable::tr("MIME") + "]")
           #endif
            << CommandHelp("paste",
                           Scriptable::tr("Paste clipboard to current window\n"
                                          "(may not work with some applications)."))
            << CommandHelp("copy", Scriptable::tr("Set clipboard text."))
               .addArg(Scriptable::tr("TEXT"))
            << CommandHelp("copy", Scriptable::tr("\nSet clipboard content."))
               .addArg(Scriptable::tr("MIME"))
               .addArg(Scriptable::tr("DATA"))
               .addArg("[" + Scriptable::tr("MIME") + " " + Scriptable::tr("DATA") + "]...")
            << CommandHelp()
            << CommandHelp("count",
                           Scriptable::tr("Print amount of items in current tab."))
            << CommandHelp("select",
                           Scriptable::tr("Copy item in the row to clipboard."))
               .addArg("[" + Scriptable::tr("ROW") + "=0]")
            << CommandHelp("next",
                           Scriptable::tr("Copy next item from current tab to clipboard."))
            << CommandHelp("previous",
                           Scriptable::tr("Copy previous item from current tab to clipboard."))
            << CommandHelp("add",
                           Scriptable::tr("Add text into clipboard."))
               .addArg(Scriptable::tr("TEXT") + "...")
            << CommandHelp("insert",
                           Scriptable::tr("Insert text into given row."))
               .addArg(Scriptable::tr("ROW"))
               .addArg(Scriptable::tr("TEXT"))
            << CommandHelp("remove",
                           Scriptable::tr("Remove items in given rows."))
               .addArg("[" + Scriptable::tr("ROWS") + "=0...]")
            << CommandHelp("edit",
                           Scriptable::tr("Edit items or edit new one.\n"
                                          "Value -1 is for current text in clipboard."))
               .addArg("[" + Scriptable::tr("ROW") + "=-1...]")
            << CommandHelp()
            << CommandHelp("separator",
                           Scriptable::tr("Set separator for items on output."))
               .addArg(Scriptable::tr("SEPARATOR"))
            << CommandHelp("read",
                           Scriptable::tr("Print raw data of clipboard or item in row."))
               .addArg("[" + Scriptable::tr("MIME") + "|" + Scriptable::tr("ROW") + "]...")
            << CommandHelp("write", Scriptable::tr("\nWrite raw data to given row."))
               .addArg("[" + Scriptable::tr("ROW") + "=0]")
               .addArg(Scriptable::tr("MIME"))
               .addArg(Scriptable::tr("DATA"))
               .addArg("[" + Scriptable::tr("MIME") + " " + Scriptable::tr("DATA") + "]...")
            << CommandHelp()
            << CommandHelp("action",
                           Scriptable::tr("Show action dialog."))
               .addArg("[" + Scriptable::tr("ROWS") + "=0...]")
            << CommandHelp("action",
                           Scriptable::tr("\nRun PROGRAM on item text in the rows.\n"
                                          "Use %1 in PROGRAM to pass text as argument."))
               .addArg("[" + Scriptable::tr("ROWS") + "=0...]")
               .addArg("[" + Scriptable::tr("PROGRAM") + " [" + Scriptable::tr("SEPARATOR") + "=\\n]]")
            << CommandHelp("popup",
                           Scriptable::tr("\nShow tray popup message for TIME milliseconds."))
               .addArg(Scriptable::tr("TITLE"))
               .addArg(Scriptable::tr("MESSAGE"))
               .addArg("[" + Scriptable::tr("TIME") + "=8000]")
            << CommandHelp()
            << CommandHelp("tab",
                           Scriptable::tr("List available tab names."))
            << CommandHelp("tab",
                           Scriptable::tr("Run command on tab with given name.\n"
                                          "Tab is created if it doesn't exist.\n"
                                          "Default is the first tab."))
               .addArg(Scriptable::tr("NAME"))
               .addArg("[" + Scriptable::tr("COMMAND") + "]")
            << CommandHelp("removetab",
                           Scriptable::tr("Remove tab."))
               .addArg(Scriptable::tr("NAME"))
            << CommandHelp("renametab",
                           Scriptable::tr("Rename tab."))
               .addArg(Scriptable::tr("NAME"))
               .addArg(Scriptable::tr("NEW_NAME"))
            << CommandHelp()
            << CommandHelp("exporttab",
                           Scriptable::tr("Export items to file."))
               .addArg(Scriptable::tr("FILE_NAME"))
            << CommandHelp("importtab",
                           Scriptable::tr("Import items from file."))
               .addArg(Scriptable::tr("FILE_NAME"))
            << CommandHelp()
            << CommandHelp("config",
                           Scriptable::tr("List all options."))
            << CommandHelp("config",
                           Scriptable::tr("Get option value."))
               .addArg(Scriptable::tr("OPTION"))
            << CommandHelp("config",
                           Scriptable::tr("Set option value."))
               .addArg(Scriptable::tr("OPTION"))
               .addArg(Scriptable::tr("VALUE"))
            << CommandHelp()
            << CommandHelp("eval, -e",
                           Scriptable::tr("\nEvaluate ECMAScript program.\n"
                                          "Arguments are accessible using with \"arguments[0..N]\"."))
               .addArg("[" + Scriptable::tr("SCRIPT") + "]")
               .addArg("[" + Scriptable::tr("ARGUMENTS") + "]...")
            << CommandHelp("session, -s, --session",
                           Scriptable::tr("\nStarts or connects to application instance with given session name."))
               .addArg(Scriptable::tr("SESSION"))
            << CommandHelp("help, -h, --help",
                           Scriptable::tr("\nPrint help for COMMAND or all commands."))
               .addArg("[" + Scriptable::tr("COMMAND") + "]...")
            << CommandHelp("version, -v, --version",
                           Scriptable::tr("\nPrint version of program and libraries."))
#ifdef HAS_TESTS
            << CommandHelp("tests, --tests",
                           Scriptable::tr("Run application tests (append --help argument for more info)."))
#endif
               ;
}