Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
371478ff
Commit
371478ff
authored
Nov 11, 2010
by
con
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Read external tools from resources and show them in menu.
parent
e07e9145
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
128 additions
and
11 deletions
+128
-11
src/plugins/coreplugin/actionmanager/actionmanager.h
src/plugins/coreplugin/actionmanager/actionmanager.h
+1
-1
src/plugins/coreplugin/coreconstants.h
src/plugins/coreplugin/coreconstants.h
+1
-0
src/plugins/coreplugin/externaltool.cpp
src/plugins/coreplugin/externaltool.cpp
+90
-1
src/plugins/coreplugin/externaltool.h
src/plugins/coreplugin/externaltool.h
+22
-1
src/plugins/coreplugin/mainwindow.cpp
src/plugins/coreplugin/mainwindow.cpp
+3
-1
tests/auto/externaltool/tst_externaltooltest.cpp
tests/auto/externaltool/tst_externaltooltest.cpp
+11
-7
No files found.
src/plugins/coreplugin/actionmanager/actionmanager.h
View file @
371478ff
...
...
@@ -36,6 +36,7 @@
#include "coreplugin/core_global.h"
#include "coreplugin/uniqueidmanager.h"
#include <coreplugin/actionmanager/command.h>
#include "coreplugin/icontext.h"
#include <QtCore/QObject>
...
...
@@ -50,7 +51,6 @@ QT_END_NAMESPACE
namespace
Core
{
class
ActionContainer
;
class
Command
;
class
CORE_EXPORT
ActionManager
:
public
QObject
{
...
...
src/plugins/coreplugin/coreconstants.h
View file @
371478ff
...
...
@@ -91,6 +91,7 @@ const char * const M_FILE_RECENTFILES = "QtCreator.Menu.File.RecentFiles";
const
char
*
const
M_EDIT
=
"QtCreator.Menu.Edit"
;
const
char
*
const
M_EDIT_ADVANCED
=
"QtCreator.Menu.Edit.Advanced"
;
const
char
*
const
M_TOOLS
=
"QtCreator.Menu.Tools"
;
const
char
*
const
M_TOOLS_EXTERNAL
=
"QtCreator.Menu.Tools.External"
;
const
char
*
const
M_WINDOW
=
"QtCreator.Menu.Window"
;
const
char
*
const
M_WINDOW_PANES
=
"QtCreator.Menu.Window.Panes"
;
const
char
*
const
M_WINDOW_VIEWS
=
"QtCreator.Menu.Window.Views"
;
...
...
src/plugins/coreplugin/externaltool.cpp
View file @
371478ff
...
...
@@ -28,11 +28,21 @@
**************************************************************************/
#include "externaltool.h"
#include "actionmanager.h"
#include "actioncontainer.h"
#include "command.h"
#include "coreconstants.h"
#include <QtCore/QXmlStreamReader>
#include <QtCore/QDir>
#include <QtCore/QFile>
#include <QtGui/QMenu>
#include <QtGui/QMenuItem>
#include <QtGui/QAction>
#include <QtDebug>
using
namespace
Core
;
using
namespace
Core
::
Internal
;
namespace
{
...
...
@@ -53,6 +63,8 @@ namespace {
const
char
*
const
kOutputReloadDocument
=
"reloaddocument"
;
}
// #pragma mark -- ExternalTool
ExternalTool
::
ExternalTool
()
:
m_order
(
-
1
),
m_outputHandling
(
ShowInPane
)
...
...
@@ -147,7 +159,7 @@ static void localizedText(const QStringList &locales, QXmlStreamReader *reader,
}
}
ExternalTool
*
ExternalTool
::
createFromXml
(
const
Q
String
&
xml
,
QString
*
errorMessage
,
const
QString
&
locale
)
ExternalTool
*
ExternalTool
::
createFromXml
(
const
Q
ByteArray
&
xml
,
QString
*
errorMessage
,
const
QString
&
locale
)
{
int
descriptionLocale
=
-
1
;
int
nameLocale
=
-
1
;
...
...
@@ -220,3 +232,80 @@ ExternalTool * ExternalTool::createFromXml(const QString &xml, QString *errorMes
}
return
tool
;
}
// #pragma mark -- ExternalToolManager
ExternalToolManager
::
ExternalToolManager
(
Core
::
ICore
*
core
)
:
QObject
(
core
),
m_core
(
core
)
{
initialize
();
}
ExternalToolManager
::~
ExternalToolManager
()
{
qDeleteAll
(
m_tools
);
}
void
ExternalToolManager
::
initialize
()
{
ActionManager
*
am
=
m_core
->
actionManager
();
ActionContainer
*
mexternaltools
=
am
->
createMenu
(
Id
(
Constants
::
M_TOOLS_EXTERNAL
));
mexternaltools
->
menu
()
->
setTitle
(
tr
(
"External"
));
ActionContainer
*
mtools
=
am
->
actionContainer
(
Constants
::
M_TOOLS
);
Command
*
cmd
;
QAction
*
sep
=
new
QAction
(
this
);
sep
->
setSeparator
(
true
);
cmd
=
am
->
registerAction
(
sep
,
Id
(
"Tools.Separator"
),
Context
(
Constants
::
C_GLOBAL
));
mtools
->
addAction
(
cmd
,
Constants
::
G_DEFAULT_THREE
);
mtools
->
addMenu
(
mexternaltools
,
Constants
::
G_DEFAULT_THREE
);
QMap
<
QString
,
ActionContainer
*>
categoryMenus
;
QDir
dir
(
m_core
->
resourcePath
()
+
QLatin1String
(
"/externaltools"
),
QLatin1String
(
"*.xml"
),
QDir
::
Unsorted
,
QDir
::
Files
|
QDir
::
Readable
);
foreach
(
const
QFileInfo
&
info
,
dir
.
entryInfoList
())
{
QFile
file
(
info
.
absoluteFilePath
());
if
(
file
.
open
(
QIODevice
::
ReadOnly
))
{
const
QByteArray
&
bytes
=
file
.
readAll
();
file
.
close
();
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
bytes
,
&
error
,
m_core
->
userInterfaceLanguage
());
if
(
!
tool
)
{
// TODO error handling
qDebug
()
<<
tr
(
"Error while parsing external tool %1: %2"
).
arg
(
file
.
fileName
(),
error
);
continue
;
}
if
(
m_tools
.
contains
(
tool
->
id
()))
{
// TODO error handling
qDebug
()
<<
tr
(
"Error: External tool in %1 has duplicate id"
).
arg
(
file
.
fileName
());
delete
tool
;
continue
;
}
m_tools
.
insert
(
tool
->
id
(),
tool
);
// category menus
ActionContainer
*
container
;
if
(
tool
->
displayCategory
().
isEmpty
())
container
=
mexternaltools
;
else
container
=
categoryMenus
.
value
(
tool
->
displayCategory
());
if
(
!
container
)
{
container
=
am
->
createMenu
(
Id
(
"Tools.External.Category."
+
tool
->
displayCategory
()));
container
->
menu
()
->
setTitle
(
tool
->
displayCategory
());
mexternaltools
->
addMenu
(
container
,
Constants
::
G_DEFAULT_ONE
);
}
// tool action
QAction
*
action
=
new
QAction
(
tool
->
displayName
(),
this
);
action
->
setToolTip
(
tool
->
description
());
action
->
setWhatsThis
(
tool
->
description
());
action
->
setData
(
tool
->
id
());
cmd
=
am
->
registerAction
(
action
,
Id
(
"Tools.External."
+
tool
->
id
()),
Context
(
Constants
::
C_GLOBAL
));
container
->
addAction
(
cmd
,
Constants
::
G_DEFAULT_TWO
);
}
}
}
void
ExternalToolManager
::
menuActivated
()
{
}
src/plugins/coreplugin/externaltool.h
View file @
371478ff
...
...
@@ -30,6 +30,9 @@
#ifndef EXTERNALTOOL_H
#define EXTERNALTOOL_H
#include "icore.h"
#include <QtCore/QObject>
#include <QtCore/QString>
#include <QtCore/QStringList>
...
...
@@ -58,7 +61,7 @@ public:
QString
arguments
()
const
;
QString
workingDirectory
()
const
;
static
ExternalTool
*
createFromXml
(
const
Q
String
&
xml
,
QString
*
errorMessage
=
0
,
const
QString
&
locale
=
QString
());
static
ExternalTool
*
createFromXml
(
const
Q
ByteArray
&
xml
,
QString
*
errorMessage
=
0
,
const
QString
&
locale
=
QString
());
private:
QString
m_id
;
...
...
@@ -72,6 +75,24 @@ private:
OutputHandling
m_outputHandling
;
};
class
ExternalToolManager
:
public
QObject
{
Q_OBJECT
public:
ExternalToolManager
(
Core
::
ICore
*
core
);
~
ExternalToolManager
();
void
initialize
();
private
slots
:
void
menuActivated
();
private:
Core
::
ICore
*
m_core
;
QMap
<
QString
,
ExternalTool
*>
m_tools
;
};
}
// Internal
}
// Core
...
...
src/plugins/coreplugin/mainwindow.cpp
View file @
371478ff
...
...
@@ -38,10 +38,12 @@
#include "coreimpl.h"
#include "coreconstants.h"
#include "editormanager.h"
#include "externaltool.h"
#include "fancytabwidget.h"
#include "filemanager.h"
#include "generalsettings.h"
#include "helpmanager.h"
#include "ieditor.h"
#include "ifilefactory.h"
#include "messagemanager.h"
#include "modemanager.h"
...
...
@@ -54,7 +56,6 @@
#include "progressview.h"
#include "shortcutsettings.h"
#include "vcsmanager.h"
#include "ieditor.h"
#include "scriptmanager_p.h"
#include "settingsdialog.h"
...
...
@@ -205,6 +206,7 @@ MainWindow::MainWindow() :
m_messageManager
=
new
MessageManager
;
m_editorManager
=
new
EditorManager
(
m_coreImpl
,
this
);
m_editorManager
->
hide
();
new
ExternalToolManager
(
m_coreImpl
);
setCentralWidget
(
m_modeStack
);
connect
(
QApplication
::
instance
(),
SIGNAL
(
focusChanged
(
QWidget
*
,
QWidget
*
)),
...
...
tests/auto/externaltool/tst_externaltooltest.cpp
View file @
371478ff
...
...
@@ -6,6 +6,7 @@
using
namespace
Core
::
Internal
;
static
const
char
*
const
TEST_XML1
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
"<externaltool id=
\"
lupdate
\"
>"
" <description>Synchronizes translator's ts files with the program code</description>"
" <description xml:lang=
\"
de
\"
>Synchronisiert die ts-Übersetzungsdateien mit dem Programmcode</description>"
...
...
@@ -24,6 +25,7 @@ static const char * const TEST_XML1 =
;
static
const
char
*
const
TEST_XML2
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
"<externaltool id=
\"
sort
\"
>"
" <description>Sorts the selected text</description>"
" <description xml:lang=
\"
de
\"
>Sortiert den ausgewählten Text</description>"
...
...
@@ -39,6 +41,7 @@ static const char * const TEST_XML2 =
"</externaltool>"
;
static
const
char
*
const
TEST_XML3
=
"<?xml version=
\"
1.0
\"
encoding=
\"
UTF-8
\"
?>"
"<externaltool id=
\"
vi
\"
>"
" <description>Opens the current file in vi</description>"
" <description xml:lang=
\"
de
\"
>Öffnet die aktuelle Datei in vi</description>"
...
...
@@ -54,6 +57,7 @@ static const char * const TEST_XML3 =
"</externaltool>"
;
static
const
char
*
const
TEST_XML_LANG
=
"<?xml version=
\"
1.0
\"
encoding=
\"
Latin-1
\"
?>"
"<externaltool id=
\"
temp
\"
>"
" <description>Hi</description>"
" <description xml:lang=
\"
de
\"
>Hallo</description>"
...
...
@@ -83,7 +87,7 @@ private Q_SLOTS:
void
ExternaltoolTest
::
testRead1
()
{
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML1
),
&
error
);
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML1
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
id
(),
QString
::
fromLatin1
(
"lupdate"
));
...
...
@@ -103,7 +107,7 @@ void ExternaltoolTest::testRead1()
void
ExternaltoolTest
::
testRead2
()
{
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML2
),
&
error
);
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML2
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
id
(),
QString
::
fromLatin1
(
"sort"
));
...
...
@@ -122,7 +126,7 @@ void ExternaltoolTest::testRead2()
void
ExternaltoolTest
::
testRead3
()
{
QString
error
;
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML3
),
&
error
);
ExternalTool
*
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML3
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
id
(),
QString
::
fromLatin1
(
"vi"
));
...
...
@@ -143,7 +147,7 @@ void ExternaltoolTest::testReadLocale()
QString
error
;
ExternalTool
*
tool
;
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML_LANG
),
&
error
);
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML_LANG
),
&
error
);
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
description
(),
QString
::
fromLatin1
(
"Hi"
));
...
...
@@ -151,7 +155,7 @@ void ExternaltoolTest::testReadLocale()
QCOMPARE
(
tool
->
displayCategory
(),
QString
::
fromLatin1
(
"Hi"
));
delete
tool
;
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML_LANG
),
&
error
,
QLatin1String
(
"uk"
));
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML_LANG
),
&
error
,
QLatin1String
(
"uk"
));
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
description
(),
QString
::
fromLatin1
(
"Hi"
));
...
...
@@ -159,7 +163,7 @@ void ExternaltoolTest::testReadLocale()
QCOMPARE
(
tool
->
displayCategory
(),
QString
::
fromLatin1
(
"Hi"
));
delete
tool
;
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML_LANG
),
&
error
,
QLatin1String
(
"de_DE.UTF-8"
));
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML_LANG
),
&
error
,
QLatin1String
(
"de_DE.UTF-8"
));
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
description
(),
QString
::
fromLatin1
(
"Hallo"
));
...
...
@@ -167,7 +171,7 @@ void ExternaltoolTest::testReadLocale()
QCOMPARE
(
tool
->
displayCategory
(),
QString
::
fromLatin1
(
"Hallo"
));
delete
tool
;
tool
=
ExternalTool
::
createFromXml
(
Q
Latin1String
(
TEST_XML_LANG
),
&
error
,
QLatin1String
(
"de_CH"
));
tool
=
ExternalTool
::
createFromXml
(
Q
ByteArray
(
TEST_XML_LANG
),
&
error
,
QLatin1String
(
"de_CH"
));
QVERIFY
(
tool
!=
0
);
QVERIFY
(
error
.
isEmpty
());
QCOMPARE
(
tool
->
description
(),
QString
::
fromLatin1
(
"Grüezi"
));
...
...
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