1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
5 **
6 ** This file is part of Qt Creator.
7 **
8 ** Commercial License Usage
9 ** Licensees holding valid commercial Qt licenses may use this file in
10 ** accordance with the commercial license agreement provided with the
11 ** Software or, alternatively, in accordance with the terms contained in
12 ** a written agreement between you and The Qt Company. For licensing terms
13 ** and conditions see https://www.qt.io/terms-conditions. For further
14 ** information use the contact form at https://www.qt.io/contact-us.
15 **
16 ** GNU General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU
18 ** General Public License version 3 as published by the Free Software
19 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
20 ** included in the packaging of this file. Please review the following
21 ** information to ensure the GNU General Public License requirements will
22 ** be met: https://www.gnu.org/licenses/gpl-3.0.html.
23 **
24 ****************************************************************************/
25
26 #include "androidmanifesteditor.h"
27 #include "androidmanifestdocument.h"
28 #include "androidmanifesteditorwidget.h"
29 #include "androidconstants.h"
30
31 #include <texteditor/texteditorconstants.h>
32
33 #include <QActionGroup>
34 #include <QToolBar>
35 #include <QTextBlock>
36
37 using namespace Android;
38 using namespace Internal;
39
AndroidManifestEditor(AndroidManifestEditorWidget * editorWidget)40 AndroidManifestEditor::AndroidManifestEditor(AndroidManifestEditorWidget *editorWidget)
41 : m_toolBar(nullptr)
42 {
43 m_toolBar = new QToolBar(editorWidget);
44 m_actionGroup = new QActionGroup(this);
45 connect(m_actionGroup, &QActionGroup::triggered,
46 this, &AndroidManifestEditor::changeEditorPage);
47
48 QAction *generalAction = m_toolBar->addAction(tr("General"));
49 generalAction->setData(AndroidManifestEditorWidget::General);
50 generalAction->setCheckable(true);
51 m_actionGroup->addAction(generalAction);
52
53 QAction *sourceAction = m_toolBar->addAction(tr("XML Source"));
54 sourceAction->setData(AndroidManifestEditorWidget::Source);
55 sourceAction->setCheckable(true);
56 m_actionGroup->addAction(sourceAction);
57
58 generalAction->setChecked(true);
59
60 setWidget(editorWidget);
61 }
62
toolBar()63 QWidget *AndroidManifestEditor::toolBar()
64 {
65 return m_toolBar;
66 }
67
widget() const68 AndroidManifestEditorWidget *AndroidManifestEditor::widget() const
69 {
70 return static_cast<AndroidManifestEditorWidget *>(Core::IEditor::widget());
71 }
72
document() const73 Core::IDocument *AndroidManifestEditor::document() const
74 {
75 return textEditor()->textDocument();
76 }
77
textEditor() const78 TextEditor::TextEditorWidget *AndroidManifestEditor::textEditor() const
79 {
80 return widget()->textEditorWidget();
81 }
82
currentLine() const83 int AndroidManifestEditor::currentLine() const
84 {
85 return textEditor()->textCursor().blockNumber() + 1;
86 }
87
currentColumn() const88 int AndroidManifestEditor::currentColumn() const
89 {
90 QTextCursor cursor = textEditor()->textCursor();
91 return cursor.position() - cursor.block().position() + 1;
92 }
93
gotoLine(int line,int column,bool centerLine)94 void AndroidManifestEditor::gotoLine(int line, int column, bool centerLine)
95 {
96 textEditor()->gotoLine(line, column, centerLine);
97 }
98
changeEditorPage(QAction * action)99 void AndroidManifestEditor::changeEditorPage(QAction *action)
100 {
101 if (!widget()->setActivePage(static_cast<AndroidManifestEditorWidget::EditorPage>(action->data().toInt()))) {
102 foreach (QAction *action, m_actionGroup->actions()) {
103 if (action->data().toInt() == widget()->activePage()) {
104 action->setChecked(true);
105 break;
106 }
107 }
108 }
109 }
110