Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Q
qt-creator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tobias Hunger
qt-creator
Commits
740743dc
Commit
740743dc
authored
Nov 10, 2010
by
con
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement an external tool container + xml parsing.
parent
dd6f9b06
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
395 additions
and
6 deletions
+395
-6
.gitignore
.gitignore
+1
-0
qtcreator.pri
qtcreator.pri
+4
-2
src/plugins/coreplugin/coreplugin.pro
src/plugins/coreplugin/coreplugin.pro
+4
-2
src/plugins/coreplugin/externaltool.cpp
src/plugins/coreplugin/externaltool.cpp
+185
-0
src/plugins/coreplugin/externaltool.h
src/plugins/coreplugin/externaltool.h
+76
-0
src/qtcreatorplugin.pri
src/qtcreatorplugin.pri
+0
-2
tests/auto/externaltool/externaltool.pro
tests/auto/externaltool/externaltool.pro
+5
-0
tests/auto/externaltool/tst_externaltooltest.cpp
tests/auto/externaltool/tst_externaltooltest.cpp
+120
-0
No files found.
.gitignore
View file @
740743dc
...
...
@@ -107,4 +107,5 @@ tests/auto/qml/qmldesigner/bauhaustests/tst_bauhaus
tests/auto/qml/qmldesigner/coretests/tst_qmldesigner_core
tests/auto/qml/qmldesigner/propertyeditortests/tst_propertyeditor
tests/auto/profilewriter/tst_profilewriter
tests/auto/externaltool/tst_externaltool
qtcreator.pri
View file @
740743dc
...
...
@@ -124,11 +124,13 @@ macx {
INCLUDEPATH += \
$$IDE_SOURCE_TREE/src/libs \
$$IDE_SOURCE_TREE/tools
$$IDE_SOURCE_TREE/tools \
$$IDE_SOURCE_TREE/src/plugins
DEPENDPATH += \
$$IDE_SOURCE_TREE/src/libs \
$$IDE_SOURCE_TREE/tools
$$IDE_SOURCE_TREE/tools \
$$IDE_SOURCE_TREE/src/plugins
LIBS += -L$$IDE_LIBRARY_PATH
...
...
src/plugins/coreplugin/coreplugin.pro
View file @
740743dc
...
...
@@ -87,7 +87,8 @@ SOURCES += mainwindow.cpp \
outputpanemanager
.
cpp
\
navigationsubwidget
.
cpp
\
sidebarwidget
.
cpp
\
rssfetcher
.
cpp
rssfetcher
.
cpp
\
externaltool
.
cpp
HEADERS
+=
mainwindow
.
h
\
editmode
.
h
\
...
...
@@ -172,7 +173,8 @@ HEADERS += mainwindow.h \
outputpanemanager
.
h
\
navigationsubwidget
.
h
\
sidebarwidget
.
h
\
rssfetcher
.
h
rssfetcher
.
h
\
externaltool
.
h
FORMS
+=
dialogs
/
newdialog
.
ui
\
actionmanager
/
commandmappings
.
ui
\
...
...
src/plugins/coreplugin/externaltool.cpp
0 → 100644
View file @
740743dc
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "externaltool.h"
#include <QtCore/QXmlStreamReader>
#include <QtDebug>
using
namespace
Core
::
Internal
;
namespace
{
const
char
*
const
kExternalTool
=
"externaltool"
;
const
char
*
const
kDescription
=
"description"
;
const
char
*
const
kDisplayName
=
"displayname"
;
const
char
*
const
kCategory
=
"category"
;
const
char
*
const
kOrder
=
"order"
;
const
char
*
const
kExecutable
=
"executable"
;
const
char
*
const
kPath
=
"path"
;
const
char
*
const
kArguments
=
"arguments"
;
const
char
*
const
kWorkingDirectory
=
"workingdirectory"
;
const
char
*
const
kXmlLang
=
"xml:lang"
;
const
char
*
const
kOutput
=
"output"
;
const
char
*
const
kOutputShowInPane
=
"showinpane"
;
const
char
*
const
kOutputReplaceSelection
=
"replaceselection"
;
const
char
*
const
kOutputReloadDocument
=
"reloaddocument"
;
}
ExternalTool
::
ExternalTool
()
:
m_order
(
-
1
),
m_outputHandling
(
ShowInPane
)
{
}
QString
ExternalTool
::
description
()
const
{
return
m_description
;
}
QString
ExternalTool
::
displayName
()
const
{
return
m_displayName
;
}
QString
ExternalTool
::
displayCategory
()
const
{
return
m_displayCategory
;
}
int
ExternalTool
::
order
()
const
{
return
m_order
;
}
QStringList
ExternalTool
::
executables
()
const
{
return
m_executables
;
}
QString
ExternalTool
::
arguments
()
const
{
return
m_arguments
;
}
QString
ExternalTool
::
workingDirectory
()
const
{
return
m_workingDirectory
;
}
ExternalTool
::
OutputHandling
ExternalTool
::
outputHandling
()
const
{
return
m_outputHandling
;
}
ExternalTool
*
ExternalTool
::
createFromXml
(
const
QString
&
xml
,
QString
*
errorMessage
)
{
ExternalTool
*
tool
=
new
ExternalTool
;
QXmlStreamReader
reader
(
xml
);
if
(
!
reader
.
readNextStartElement
()
||
reader
.
name
()
!=
QLatin1String
(
kExternalTool
))
reader
.
raiseError
(
QLatin1String
(
"Missing start element <externaltool>"
));
while
(
reader
.
readNextStartElement
())
{
if
(
reader
.
name
()
==
QLatin1String
(
kDescription
))
{
// TODO locale check
if
(
!
reader
.
attributes
().
hasAttribute
(
QLatin1String
(
kXmlLang
))
&&
tool
->
m_description
.
isEmpty
())
{
tool
->
m_description
=
reader
.
readElementText
();
}
else
{
reader
.
skipCurrentElement
();
}
}
else
if
(
reader
.
name
()
==
QLatin1String
(
kDisplayName
))
{
// TODO locale check
if
(
!
reader
.
attributes
().
hasAttribute
(
QLatin1String
(
kXmlLang
))
&&
tool
->
m_displayName
.
isEmpty
())
{
tool
->
m_displayName
=
reader
.
readElementText
();
}
else
{
reader
.
skipCurrentElement
();
}
}
else
if
(
reader
.
name
()
==
QLatin1String
(
kCategory
))
{
// TODO locale check
if
(
!
reader
.
attributes
().
hasAttribute
(
QLatin1String
(
kXmlLang
))
&&
tool
->
m_displayCategory
.
isEmpty
())
{
tool
->
m_displayCategory
=
reader
.
readElementText
();
}
else
{
reader
.
skipCurrentElement
();
}
}
else
if
(
reader
.
name
()
==
QLatin1String
(
kOrder
))
{
if
(
tool
->
m_order
>=
0
)
{
reader
.
raiseError
(
QLatin1String
(
"only one <order> element allowed"
));
break
;
}
bool
ok
;
tool
->
m_order
=
reader
.
readElementText
().
toInt
(
&
ok
);
if
(
!
ok
||
tool
->
m_order
<
0
)
reader
.
raiseError
(
QLatin1String
(
"<order> element requires non-negative integer value"
));
}
else
if
(
reader
.
name
()
==
QLatin1String
(
kExecutable
))
{
if
(
reader
.
attributes
().
hasAttribute
(
QLatin1String
(
kOutput
)))
{
const
QString
output
=
reader
.
attributes
().
value
(
QLatin1String
(
kOutput
)).
toString
();
if
(
output
==
QLatin1String
(
kOutputShowInPane
))
{
tool
->
m_outputHandling
=
ExternalTool
::
ShowInPane
;
}
else
if
(
output
==
QLatin1String
(
kOutputReplaceSelection
))
{
tool
->
m_outputHandling
=
ExternalTool
::
ReplaceSelection
;
}
else
if
(
output
==
QLatin1String
(
kOutputReloadDocument
))
{
tool
->
m_outputHandling
=
ExternalTool
::
ReloadDocument
;
}
else
{
reader
.
raiseError
(
QLatin1String
(
"Allowed values for output attribute are 'showinpane','replaceselection','reloaddocument'"
));
break
;
}
}
while
(
reader
.
readNextStartElement
())
{
if
(
reader
.
name
()
==
QLatin1String
(
kPath
))
{
tool
->
m_executables
.
append
(
reader
.
readElementText
());
}
else
if
(
reader
.
name
()
==
QLatin1String
(
kArguments
))
{
if
(
!
tool
->
m_arguments
.
isEmpty
())
{
reader
.
raiseError
(
QLatin1String
(
"only one <arguments> element allowed"
));
break
;
}
tool
->
m_arguments
=
reader
.
readElementText
();
}
else
if
(
reader
.
name
()
==
QLatin1String
(
kWorkingDirectory
))
{
if
(
!
tool
->
m_workingDirectory
.
isEmpty
())
{
reader
.
raiseError
(
QLatin1String
(
"only one <workingdirectory> element allowed"
));
break
;
}
tool
->
m_workingDirectory
=
reader
.
readElementText
();
}
}
}
else
{
reader
.
raiseError
(
QString
::
fromLatin1
(
"Unknown element <%1>"
).
arg
(
reader
.
qualifiedName
().
toString
()));
}
}
if
(
reader
.
hasError
())
{
if
(
errorMessage
)
*
errorMessage
=
reader
.
errorString
();
qDebug
()
<<
reader
.
errorString
();
delete
tool
;
return
0
;
}
return
tool
;
}
src/plugins/coreplugin/externaltool.h
0 → 100644
View file @
740743dc
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
**
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef EXTERNALTOOL_H
#define EXTERNALTOOL_H
#include <QtCore/QString>
#include <QtCore/QStringList>
namespace
Core
{
namespace
Internal
{
class
ExternalTool
{
public:
enum
OutputHandling
{
ShowInPane
,
ReplaceSelection
,
ReloadDocument
};
ExternalTool
();
QString
description
()
const
;
QString
displayName
()
const
;
QString
displayCategory
()
const
;
int
order
()
const
;
OutputHandling
outputHandling
()
const
;
QStringList
executables
()
const
;
QString
arguments
()
const
;
QString
workingDirectory
()
const
;
static
ExternalTool
*
createFromXml
(
const
QString
&
xml
,
QString
*
errorMessage
=
0
);
private:
QString
m_description
;
QString
m_displayName
;
QString
m_displayCategory
;
int
m_order
;
QStringList
m_executables
;
QString
m_arguments
;
QString
m_workingDirectory
;
OutputHandling
m_outputHandling
;
};
}
// Internal
}
// Core
#endif // EXTERNALTOOL_H
src/qtcreatorplugin.pri
View file @
740743dc
...
...
@@ -9,8 +9,6 @@ isEmpty(PROVIDER) {
DESTDIR = $$IDE_PLUGIN_PATH/$$PROVIDER
LIBS += -L$$DESTDIR
INCLUDEPATH += $$IDE_SOURCE_TREE/src/plugins
DEPENDPATH += $$IDE_SOURCE_TREE/src/plugins
# copy the plugin spec
isEmpty(TARGET) {
...
...
tests/auto/externaltool/externaltool.pro
0 → 100644
View file @
740743dc
include
(..
/
qttest
.
pri
)
SOURCES
+=
tst_externaltooltest
.
cpp
\
$$
IDE_SOURCE_TREE
/
src
/
plugins
/
coreplugin
/
externaltool
.
cpp
HEADERS
+=
$$
IDE_SOURCE_TREE
/
src
/
plugins
/
coreplugin
/
externaltool
.
h
tests/auto/externaltool/tst_externaltooltest.cpp
0 → 100644
View file @
740743dc
#include <QtCore/QString>
#include <QtTest/QtTest>
#include <coreplugin/externaltool.h>
using
namespace
Core
::
Internal
;
static
const
char
*
const
TEST_XML1
=
"<externaltool>"
" <description>Synchronizes translator's ts files with the program code</description>"
" <description xml:lang=
\"
de
\"
>Synchronisiert die ts-Übersetzungsdateien mit dem Programmcode</description>"
" <displayname>Update translations (lupdate)</displayname>"
" <displayname xml:lang=
\"
de
\"
>Übersetzungen aktualisieren (lupdate)</displayname>"
" <category>Linguist</category>"
" <category xml:lang=
\"
de
\"
>Linguist</category>"
" <order>1</order>"
" <executable>"
" <path>%{QT_INSTALL_BINS}/lupdate</path>"
" <path>lupdate</path>"
" <arguments>%{CurrentProjectFilePath}</arguments>"
" <workingdirectory>%{CurrentProjectPath}</workingdirectory>"
" </executable>"
"</externaltool>"
;
static
const
char
*
const
TEST_XML2
=
"<externaltool>"
" <description>Sorts the selected text</description>"
" <description xml:lang=
\"
de
\"
>Sortiert den ausgewählten Text</description>"
" <displayname>Sort</displayname>"
" <displayname xml:lang=
\"
de
\"
>Sortieren</displayname>"
" <category>Text</category>"
" <category xml:lang=
\"
de
\"
>Text</category>"
" <executable output=
\"
replaceselection
\"
>"
" <path>sort</path>"
" <arguments>%{CurrentSelectionFilePath}</arguments>"
" <workingdirectory>%{CurrentPath}</workingdirectory>"
" </executable>"
"</externaltool>"
;
static
const
char
*
const
TEST_XML3
=
"<externaltool>"
" <description>Opens the current file in vi</description>"
" <description xml:lang=
\"
de
\"
>Öffnet die aktuelle Datei in vi</description>"
" <displayname>Edit with vi</displayname>"
" <displayname xml:lang=
\"
de
\"
>In vi öffnen</displayname>"
" <category>Text</category>"
" <category xml:lang=
\"
de
\"
>Text</category>"
" <executable output=
\"
reloaddocument
\"
>"
" <path>xterm</path>"
" <arguments>-geom %{EditorCharWidth}x%{EditorCharHeight}+%{EditorXPos}+%{EditorYPos} -e vi %{CurrentFilePath} +%{EditorLine} +
\"
normal %{EditorColumn}|
\"
</arguments>"
" <workingdirectory>%{CurrentPath}</workingdirectory>"
" </executable>"
"</externaltool>"
;
class
ExternaltoolTest
:
public
QObject
{
Q_OBJECT
private
Q_SLOTS
:
void
testRead1
();
void
testRead2
();
void
testRead3
();
};
void
ExternaltoolTest
::
testRead1
()
{
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
QLatin1String
(
TEST_XML1
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QVERIFY
(
tool
->
description
().
startsWith
(
QLatin1String
(
"Synchronizes tran"
)));
QCOMPARE
(
tool
->
displayName
(),
QString
::
fromLatin1
(
"Update translations (lupdate)"
));
QCOMPARE
(
tool
->
displayCategory
(),
QString
::
fromLatin1
(
"Linguist"
));
QCOMPARE
(
tool
->
order
(),
1
);
QCOMPARE
(
tool
->
executables
().
size
(),
2
);
QCOMPARE
(
tool
->
executables
().
at
(
0
),
QString
::
fromLatin1
(
"%{QT_INSTALL_BINS}/lupdate"
));
QCOMPARE
(
tool
->
executables
().
at
(
1
),
QString
::
fromLatin1
(
"lupdate"
));
QCOMPARE
(
tool
->
arguments
(),
QString
::
fromLatin1
(
"%{CurrentProjectFilePath}"
));
QCOMPARE
(
tool
->
workingDirectory
(),
QString
::
fromLatin1
(
"%{CurrentProjectPath}"
));
QCOMPARE
(
tool
->
outputHandling
(),
ExternalTool
::
ShowInPane
);
}
void
ExternaltoolTest
::
testRead2
()
{
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
QLatin1String
(
TEST_XML2
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QVERIFY
(
tool
->
description
().
startsWith
(
QLatin1String
(
"Sorts the"
)));
QCOMPARE
(
tool
->
displayName
(),
QString
::
fromLatin1
(
"Sort"
));
QCOMPARE
(
tool
->
displayCategory
(),
QString
::
fromLatin1
(
"Text"
));
QCOMPARE
(
tool
->
order
(),
-
1
);
QCOMPARE
(
tool
->
executables
().
size
(),
1
);
QCOMPARE
(
tool
->
executables
().
at
(
0
),
QString
::
fromLatin1
(
"sort"
));
QCOMPARE
(
tool
->
arguments
(),
QString
::
fromLatin1
(
"%{CurrentSelectionFilePath}"
));
QCOMPARE
(
tool
->
workingDirectory
(),
QString
::
fromLatin1
(
"%{CurrentPath}"
));
QCOMPARE
(
tool
->
outputHandling
(),
ExternalTool
::
ReplaceSelection
);
}
void
ExternaltoolTest
::
testRead3
()
{
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
QLatin1String
(
TEST_XML3
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QVERIFY
(
tool
->
description
().
startsWith
(
QLatin1String
(
"Opens the"
)));
QCOMPARE
(
tool
->
displayName
(),
QString
::
fromLatin1
(
"Edit with vi"
));
QCOMPARE
(
tool
->
displayCategory
(),
QString
::
fromLatin1
(
"Text"
));
QCOMPARE
(
tool
->
order
(),
-
1
);
QCOMPARE
(
tool
->
executables
().
size
(),
1
);
QCOMPARE
(
tool
->
executables
().
at
(
0
),
QString
::
fromLatin1
(
"xterm"
));
QVERIFY
(
tool
->
arguments
().
startsWith
(
QLatin1String
(
"-geom %{"
)));
QCOMPARE
(
tool
->
workingDirectory
(),
QString
::
fromLatin1
(
"%{CurrentPath}"
));
QCOMPARE
(
tool
->
outputHandling
(),
ExternalTool
::
ReloadDocument
);
}
QTEST_APPLESS_MAIN
(
ExternaltoolTest
);
#include "tst_externaltooltest.moc"
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment