~ubuntu-branches/ubuntu/vivid/kate/vivid-updates

« back to all changes in this revision

Viewing changes to part/syntax/katehighlightmenu.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2014-12-04 16:49:41 UTC
  • mfrom: (1.6.6)
  • Revision ID: package-import@ubuntu.com-20141204164941-l3qbvsly83hhlw2v
Tags: 4:14.11.97-0ubuntu1
* New upstream release
* Update build-deps and use pkg-kde v3 for Qt 5 build
* kate-data now kate5-data for co-installability

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* This file is part of the KDE libraries
2
 
   Copyright (C) 2001-2003 Christoph Cullmann <cullmann@kde.org>
3
 
 
4
 
   This library is free software; you can redistribute it and/or
5
 
   modify it under the terms of the GNU Library General Public
6
 
   License version 2 as published by the Free Software Foundation.
7
 
 
8
 
   This library is distributed in the hope that it will be useful,
9
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11
 
   Library General Public License for more details.
12
 
 
13
 
   You should have received a copy of the GNU Library General Public License
14
 
   along with this library; see the file COPYING.LIB.  If not, write to
15
 
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16
 
   Boston, MA 02110-1301, USA.
17
 
*/
18
 
 
19
 
//BEGIN Includes
20
 
#include "katehighlightmenu.h"
21
 
#include "katehighlightmenu.moc"
22
 
 
23
 
#include "katedocument.h"
24
 
#include "kateconfig.h"
25
 
#include "kateview.h"
26
 
#include "kateglobal.h"
27
 
#include "katesyntaxmanager.h"
28
 
#include "katesyntaxdocument.h"
29
 
 
30
 
#include "ui_filetypeconfigwidget.h"
31
 
 
32
 
#include <kconfig.h>
33
 
#include <kmimetype.h>
34
 
#include <kmimetypechooser.h>
35
 
#include <kdebug.h>
36
 
#include <kiconloader.h>
37
 
#include <knuminput.h>
38
 
#include <klocale.h>
39
 
#include <kmenu.h>
40
 
 
41
 
#include <QtCore/QRegExp>
42
 
#include <QtGui/QCheckBox>
43
 
#include <QtGui/QComboBox>
44
 
#include <QtGui/QGroupBox>
45
 
 
46
 
#include <QtGui/QLabel>
47
 
#include <QtGui/QLayout>
48
 
#include <QtGui/QPushButton>
49
 
#include <QtGui/QToolButton>
50
 
#include <kvbox.h>
51
 
//END Includes
52
 
 
53
 
KateHighlightingMenu::~KateHighlightingMenu()
54
 
{
55
 
  qDeleteAll (subMenus);
56
 
}
57
 
 
58
 
void KateHighlightingMenu::init()
59
 
{
60
 
  m_doc = 0;
61
 
 
62
 
  connect(menu(),SIGNAL(aboutToShow()),this,SLOT(slotAboutToShow()));
63
 
  m_actionGroup = new QActionGroup(menu());
64
 
}
65
 
 
66
 
void KateHighlightingMenu::updateMenu (KateDocument *doc)
67
 
{
68
 
  m_doc = doc;
69
 
}
70
 
 
71
 
void KateHighlightingMenu::slotAboutToShow()
72
 
{
73
 
  for (int z=0; z < KateHlManager::self()->highlights(); z++)
74
 
  {
75
 
    QString hlName = KateHlManager::self()->hlNameTranslated (z);
76
 
    QString hlSection = KateHlManager::self()->hlSection (z);
77
 
 
78
 
    if (!KateHlManager::self()->hlHidden(z))
79
 
    {
80
 
      if ( !hlSection.isEmpty() && !names.contains(hlName) )
81
 
      {
82
 
        if (!subMenusName.contains(hlSection))
83
 
        {
84
 
          subMenusName << hlSection;
85
 
          QMenu *qmenu = new QMenu ('&'+hlSection);
86
 
          subMenus.append(qmenu);
87
 
          menu()->addMenu( qmenu );
88
 
        }
89
 
 
90
 
        int m = subMenusName.indexOf (hlSection);
91
 
        names << hlName;
92
 
        QAction *a=subMenus.at(m)->addAction( '&' + hlName, this, SLOT(setHl()));
93
 
        m_actionGroup->addAction(a);
94
 
        a->setData(KateHlManager::self()->hlName (z));
95
 
        a->setCheckable(true);
96
 
        subActions.append(a);
97
 
      }
98
 
      else if (!names.contains(hlName))
99
 
      {
100
 
        names << hlName;
101
 
        QAction *a=menu()->addAction ( '&' + hlName, this, SLOT(setHl()));
102
 
        m_actionGroup->addAction(a);
103
 
        a->setData(KateHlManager::self()->hlName (z));
104
 
        a->setCheckable(true);
105
 
        subActions.append(a);
106
 
      }
107
 
    }
108
 
  }
109
 
 
110
 
  if (!m_doc) return;
111
 
  QString mode=m_doc->highlightingMode();
112
 
  for (int i=0;i<subActions.count();i++) {
113
 
        subActions[i]->setChecked(subActions[i]->data().toString()==mode);
114
 
  }
115
 
}
116
 
 
117
 
void KateHighlightingMenu::setHl ()
118
 
{
119
 
  if (!m_doc || !sender()) return;
120
 
  QAction *action=qobject_cast<QAction*>(sender());
121
 
  if (!action) return;
122
 
  QString mode=action->data().toString();
123
 
  m_doc->setHighlightingMode(mode);
124
 
 
125
 
  // use change, honor this
126
 
  m_doc->setDontChangeHlOnSave();
127
 
}
128
 
 
129
 
// kate: space-indent on; indent-width 2; replace-tabs on;