diff --git a/interfaces/iuicontroller.h b/interfaces/iuicontroller.h index 507c51c27..ad51bad36 100644 --- a/interfaces/iuicontroller.h +++ b/interfaces/iuicontroller.h @@ -1,174 +1,174 @@ /*************************************************************************** * Copyright 2007 Alexander Dymo * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU Library General Public License as * * published by the Free Software Foundation; either version 2 of the * * License, or (at your option) any later version. * * * * This program 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 Library General Public * * License along with this program; if not, write to the * * Free Software Foundation, Inc., * * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ #ifndef KDEVPLATFORM_IUICONTROLLER_H #define KDEVPLATFORM_IUICONTROLLER_H #include "interfacesexport.h" #include #include class QAction; template class QExplicitlySharedDataPointer; namespace KParts { class MainWindow; } namespace Sublime{ class Controller; class View; class Area; } namespace KDevelop { class IDocument; class IAssistant; class KDEVPLATFORMINTERFACES_EXPORT IToolViewFactory { public: virtual ~IToolViewFactory() {} /** * called to create a new widget for this toolview * @param parent the parent to use as parent for the widget * @returns the new widget for the toolview */ virtual QWidget* create(QWidget *parent = nullptr) = 0; /** * @returns the identifier of this toolview. The identifier * is used to remember which areas the tool view should appear * in, and must never change. */ virtual QString id() const = 0; /** * @returns the default position where this toolview should appear */ virtual Qt::DockWidgetArea defaultPosition() = 0; /** * Fetch a list of actions to add to the toolbar of the toolview @p view * @param viewWidget the view to which the actions should be added * @returns a list of actions to be added to the toolbar */ virtual QList toolBarActions( QWidget* viewWidget ) const { return viewWidget->actions(); } /** * Fetch a list of actions to be shown in the context menu of the toolview @p view. * The default implementation will return all actions of @p viewWidget. * * @param viewWidget the view for which the context menu should be shown * @returns a list of actions to be shown in the context menu */ virtual QList contextMenuActions( QWidget* viewWidget ) const { return viewWidget->actions(); } /** * called when a new view is created from this template * @param view the new sublime view that is being shown */ virtual void viewCreated(Sublime::View* view); /** * @returns if multiple tool views can by created by this factory in the same area. */ virtual bool allowMultiple() const { return false; } }; /** * * Allows to access various parts of the user-interface, like the toolviews or the mainwindow */ class KDEVPLATFORMINTERFACES_EXPORT IUiController { public: virtual ~IUiController(); enum SwitchMode { - ThisWindow /**< indicates that the area switch should be in the this window */, + ThisWindow /**< indicates that the area switch should be in this window */, NewWindow /**< indicates that the area switch should be using a new window */ }; enum FindFlags { None = 0, Create = 1, ///The tool-view is created if it doesn't exist in the current area yet Raise = 2, ///The tool-view is raised if it was found/created CreateAndRaise = Create | Raise ///The tool view is created and raised }; virtual void switchToArea(const QString &areaName, SwitchMode switchMode) = 0; virtual void addToolView(const QString &name, IToolViewFactory *factory, FindFlags state = Create) = 0; virtual void removeToolView(IToolViewFactory *factory) = 0; /** Makes sure that this tool-view exists in the current area, raises it, and returns the contained widget * Returns zero on failure */ virtual QWidget* findToolView(const QString& name, IToolViewFactory *factory, FindFlags flags = CreateAndRaise) = 0; /** * Makes sure that the toolview that contains the widget @p toolViewWidget is visible to the user. */ virtual void raiseToolView(QWidget* toolViewWidget) = 0; /** @return active mainwindow or 0 if no such mainwindow is active.*/ virtual KParts::MainWindow *activeMainWindow() = 0; /*! @p status must implement KDevelop::IStatus */ virtual void registerStatus(QObject* status) = 0; /** * This is meant to be used by IDocument subclasses to initialize the * Sublime::Document. */ virtual Sublime::Controller* controller() = 0; /** Shows an error message in the status bar. * * Unlike all other functions in this class, this function is thread-safe. * You can call it from the background. * * @p message The message * @p timeout The timeout in seconds how long to show the message */ virtual void showErrorMessage(const QString& message, int timeout = 1) = 0; /** @return area for currently active sublime mainwindow or 0 if no sublime mainwindow is active.*/ virtual Sublime::Area *activeArea() = 0; /** * Widget which is currently responsible for consuming special events in the UI * (such as shortcuts) * * @sa IToolViewActionListener * @return QWidget implementing the IToolViewActionListener interface */ virtual QWidget* activeToolViewActionListener() const = 0; /** * @returns all areas in the shell * * @note there will be one per mainwindow, of each type, plus the default ones. */ virtual QList allAreas() const = 0; protected: IUiController(); }; } #endif diff --git a/language/editor/rangeinrevision.h b/language/editor/rangeinrevision.h index 4994ea11b..1327be84e 100644 --- a/language/editor/rangeinrevision.h +++ b/language/editor/rangeinrevision.h @@ -1,125 +1,125 @@ /* This file is part of KDevelop Copyright 2010 David Nolden This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License version 2 as published by the Free Software Foundation. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_RANGEINREVISION_H #define KDEVPLATFORM_RANGEINREVISION_H #include #include "cursorinrevision.h" #include namespace KDevelop { /** * Represents a range (start- and end cursor) within a text document. * * In KDevelop, this object is used when referencing a ranges that do _not_ point into the - * most most current document revision. Therefore, before applying such a range in the text + * most current document revision. Therefore, before applying such a range in the text * documents, it has to be translated into the current document revision explicitly, thereby replaying * eventual changes (see DUChainBase::translate...) */ class KDEVPLATFORMLANGUAGE_EXPORT RangeInRevision { public: CursorInRevision start, end; RangeInRevision(const CursorInRevision& _start, const CursorInRevision& _end) : start(_start), end(_end) { } RangeInRevision(const CursorInRevision& _start, int length) : start(_start), end(_start.line, _start.column + length) { } RangeInRevision() { } RangeInRevision(int sLine, int sCol, int eLine, int eCol) : start(sLine, sCol), end(eLine, eCol) { } static RangeInRevision invalid() { return RangeInRevision(-1, -1, -1, -1); } bool isValid() const { return start.column != -1 || start.line != -1 || end.column != -1 || end.line != -1; } bool isEmpty() const { return start == end; } enum ContainsBehavior { Default = 0, IncludeBackEdge = 1 }; /** * Checks if @p position is contained within this range (i.e. >= start and < end) * If @p cb is IncludeBackEdge, also checks that @p position == end */ bool contains(const CursorInRevision& position, ContainsBehavior cb = Default) const { return (position >= start && position < end) || (cb == IncludeBackEdge && position == end ); } bool contains(const RangeInRevision& range) const { return range.start >= start && range.end <= end; } bool operator ==( const RangeInRevision& rhs ) const { return start == rhs.start && end == rhs.end; } bool operator !=( const RangeInRevision& rhs ) const { return !(*this == rhs); } bool operator <( const RangeInRevision& rhs ) const { return start < rhs.start; } /// @warning Using this is wrong in most cases! If you want /// to transform this range to the current revision, you should do a proper /// mapping instead through @ref KDevelop::DUChainBase or @ref KDevelop::RevisionReference /// or @ref KDevelop::DocumentChangeTracker KTextEditor::Range castToSimpleRange() const { return KTextEditor::Range(start.castToSimpleCursor(), end.castToSimpleCursor()); } /// @warning Using this is wrong in most cases! If you want /// to transform this range to the current revision, you should do a proper /// mapping instead through @ref KDevelop::DUChainBase or @ref KDevelop::RevisionReference /// or @ref KDevelop::DocumentChangeTracker static RangeInRevision castFromSimpleRange(const KTextEditor::Range& range) { return RangeInRevision(range.start().line(), range.start().column(), range.end().line(), range.end().column()); } ///qDebug() stream operator. Writes this range to the debug output in a nicely formatted way. inline friend QDebug operator<< (QDebug s, const RangeInRevision& range) { s.nospace() << '[' << range.start << ", " << range.end << ']'; return s.space(); } }; inline uint qHash(const KDevelop::RangeInRevision& range) { return qHash(range.start) + qHash(range.end)*41; } } // namespace KDevelop Q_DECLARE_TYPEINFO(KDevelop::RangeInRevision, Q_MOVABLE_TYPE); Q_DECLARE_METATYPE(KDevelop::RangeInRevision) #endif diff --git a/project/projectconfigskeleton.cpp b/project/projectconfigskeleton.cpp index c4c97670c..9d37a547c 100644 --- a/project/projectconfigskeleton.cpp +++ b/project/projectconfigskeleton.cpp @@ -1,173 +1,171 @@ /* This file is part of KDevelop Copyright 2006 Adam Treat Copyright 2007 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "projectconfigskeleton.h" #include "debug.h" #include #include #include using namespace KDevelop; struct KDevelop::ProjectConfigSkeletonPrivate { QString m_developerTempFile; QString m_projectTempFile; Path m_projectFile; Path m_developerFile; bool mUseDefaults; }; ProjectConfigSkeleton::ProjectConfigSkeleton( const QString & configname ) : KConfigSkeleton( configname ), d( new ProjectConfigSkeletonPrivate ) { d->m_developerTempFile = configname; } ProjectConfigSkeleton::ProjectConfigSkeleton( KSharedConfigPtr config ) : KConfigSkeleton( config ), d( new ProjectConfigSkeletonPrivate ) { - // FIXME: Check if that does the right thing. - // https://phabricator.kde.org/D3386 broke source compat in kconfig, thus requiring us to make this ctor public Q_ASSERT(config); d->m_developerTempFile = config->name(); } void ProjectConfigSkeleton::setDeveloperTempFile( const QString& cfg ) { d->m_developerTempFile = cfg; setSharedConfig( KSharedConfig::openConfig( cfg ) ); } void ProjectConfigSkeleton::setProjectTempFile( const QString& cfg ) { d->m_projectTempFile = cfg; config()->addConfigSources( QStringList() << cfg ); load(); } void ProjectConfigSkeleton::setProjectFile( const Path& cfg ) { d->m_projectFile = cfg; } void ProjectConfigSkeleton::setDeveloperFile( const Path& cfg ) { d->m_developerFile = cfg; } Path ProjectConfigSkeleton::projectFile() const { return d->m_projectFile; } Path ProjectConfigSkeleton::developerFile() const { return d->m_developerFile; } void ProjectConfigSkeleton::setDefaults() { qCDebug(PROJECT) << "Setting Defaults"; KConfig cfg( d->m_projectTempFile ); Q_FOREACH( KConfigSkeletonItem* item, items() ) { item->swapDefault(); if( cfg.hasGroup( item->group() ) ) { KConfigGroup grp = cfg.group( item->group() ); if( grp.hasKey( item->key() ) ) item->setProperty( grp.readEntry( item->key(), item->property() ) ); } } } bool ProjectConfigSkeleton::useDefaults( bool b ) { if( b == d->mUseDefaults ) return d->mUseDefaults; if( b ) { KConfig cfg( d->m_projectTempFile ); Q_FOREACH( KConfigSkeletonItem* item, items() ) { item->swapDefault(); if( cfg.hasGroup( item->group() ) ) { qCDebug(PROJECT) << "reading"; KConfigGroup grp = cfg.group( item->group() ); if( grp.hasKey( item->key() ) ) item->setProperty( grp.readEntry( item->key(), item->property() ) ); } } } else { KConfig cfg( d->m_developerTempFile ); KConfig defCfg( d->m_projectTempFile ); Q_FOREACH( KConfigSkeletonItem* item, items() ) { if( cfg.hasGroup( item->group() ) ) { KConfigGroup grp = cfg.group( item->group() ); if( grp.hasKey( item->key() ) ) item->setProperty( grp.readEntry( item->key(), item->property() ) ); else { KConfigGroup grp = defCfg.group( item->group() ); item->setProperty( grp.readEntry( item->key(), item->property() ) ); } } else { KConfigGroup grp = defCfg.group( item->group() ); item->setProperty( grp.readEntry( item->key(), item->property() ) ); } } } d->mUseDefaults = b; return !d->mUseDefaults; } bool ProjectConfigSkeleton::writeConfig() { KConfigSkeletonItem::List myitems = items(); KConfigSkeletonItem::List::ConstIterator it; for( it = myitems.constBegin(); it != myitems.constEnd(); ++it ) { (*it)->writeConfig( config() ); } config()->sync(); load(); auto copyJob = KIO::copy(QUrl::fromLocalFile(d->m_developerTempFile), d->m_developerFile.toUrl()); copyJob ->exec(); emit configChanged(); return true; } ProjectConfigSkeleton::~ProjectConfigSkeleton() { delete d; } diff --git a/project/projectconfigskeleton.h b/project/projectconfigskeleton.h index c8314df9f..ad3c06359 100644 --- a/project/projectconfigskeleton.h +++ b/project/projectconfigskeleton.h @@ -1,68 +1,67 @@ /* This file is part of KDevelop Copyright 2006 Adam Treat Copyright 2007 Andreas Pakulat This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library 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 Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; see the file COPYING.LIB. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef KDEVPLATFORM_PROJECTCONFIGSKELETON_H #define KDEVPLATFORM_PROJECTCONFIGSKELETON_H #include "projectexport.h" #include namespace KDevelop { class Path; class KDEVPLATFORMPROJECT_EXPORT ProjectConfigSkeleton: public KConfigSkeleton { Q_OBJECT -public: - - /** - * Constructs a new skeleton, the skeleton will write to the developer - * configuration file, which is by default located in projectdir/.kdev4 - * The defaults will be set from the project file, which is in the projectdir - * - * @param configname The absolute filename of the developer configuration file - */ - explicit ProjectConfigSkeleton( const QString & configname ); +public: ~ProjectConfigSkeleton() override; void setDeveloperTempFile( const QString& ); void setProjectTempFile( const QString& ); void setProjectFile( const Path& ); void setDeveloperFile( const Path& ); void setDefaults() override; bool useDefaults( bool b ) override; bool writeConfig(); Path projectFile() const; Path developerFile() const; protected: explicit ProjectConfigSkeleton( KSharedConfigPtr config ); + /** + * Constructs a new skeleton, the skeleton will write to the developer + * configuration file, which is by default located in projectdir/.kdev4 + * The defaults will be set from the project file, which is in the projectdir + * + * @param configname The absolute filename of the developer configuration file + */ + explicit ProjectConfigSkeleton( const QString & configname ); private: struct ProjectConfigSkeletonPrivate * const d; }; } #endif