diff --git a/plugins/okteta/oktetadocument.cpp b/plugins/okteta/oktetadocument.cpp index 9acc3320b3..bee5564527 100644 --- a/plugins/okteta/oktetadocument.cpp +++ b/plugins/okteta/oktetadocument.cpp @@ -1,249 +1,249 @@ /* This file is part of the KDevelop Okteta module, part of the KDE project. Copyright 2010-2011 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "oktetadocument.h" // plugin #include "oktetaplugin.h" #include "oktetaview.h" // Okteta -#include -#include -#include -#include +#include +#include +#include +#include // Kasten #include #include #include #include #include // KDevelop #include #include #include #include // Sublime #include #include #include #include // KF #include #include #include // Qt #include #include namespace KDevelop { OktetaDocument::OktetaDocument( const QUrl &url , ICore* core ) : Sublime::UrlDocument( core->uiController()->controller(), url ) , IDocument( core ) , mPlugin( nullptr ) , mByteArrayDocument( nullptr ) { } QUrl OktetaDocument::url() const { return Sublime::UrlDocument::url(); } // TODO: use fromContentAndUrl(ByteArrayIODevice) if document loaded QMimeType OktetaDocument::mimeType() const { return QMimeDatabase().mimeTypeForUrl( url() ); } KParts::Part* OktetaDocument::partForView( QWidget* ) const { return nullptr; } KTextEditor::Document* OktetaDocument::textDocument() const { return nullptr; } KTextEditor::Cursor OktetaDocument::cursorPosition() const { return KTextEditor::Cursor(); } IDocument::DocumentState OktetaDocument::state() const { return mByteArrayDocument ? ( mByteArrayDocument->synchronizer()->localSyncState() == Kasten::LocalHasChanges ? IDocument::Modified : IDocument::Clean ) : IDocument::Clean; } bool OktetaDocument::save( IDocument::DocumentSaveMode mode ) { if( mode & Discard ) return true; if( state() == IDocument::Clean ) return false; Kasten::AbstractModelSynchronizer* synchronizer = mByteArrayDocument->synchronizer(); Kasten::AbstractSyncToRemoteJob* syncJob = synchronizer->startSyncToRemote(); const bool syncSucceeded = Kasten::JobManager::executeJob( syncJob ); if( syncSucceeded ) { notifySaved(); notifyStateChanged(); } return syncSucceeded; } void OktetaDocument::reload() { Kasten::AbstractModelSynchronizer* synchronizer = mByteArrayDocument->synchronizer(); Kasten::AbstractSyncFromRemoteJob* syncJob = synchronizer->startSyncFromRemote(); const bool syncSucceeded = Kasten::JobManager::executeJob( syncJob ); if( syncSucceeded ) notifyStateChanged(); } bool OktetaDocument::close( IDocument::DocumentSaveMode mode ) { bool isCanceled = false; if( !(mode & Discard) ) { if (mode & Silent) { if (!save(mode)) isCanceled = true; } else { if( state() == IDocument::Modified ) { // TODO: use Kasten::*Manager int code = KMessageBox::warningYesNoCancel( qApp->activeWindow(), i18n("The document \"%1\" has unsaved changes. Would you like to save them?", url().toLocalFile()), i18n("Close Document")); if (code == KMessageBox::Yes) { if (!save(mode)) isCanceled = true; } else if (code == KMessageBox::Cancel) isCanceled = true; } else if( state() == IDocument::DirtyAndModified ) { if( !save(mode) ) isCanceled = true; } } } if( isCanceled ) return false; //close all views and then delete ourself ///@todo test this const QList& allAreas = ICore::self()->uiController()->controller()->allAreas(); for (Sublime::Area* area : allAreas ) { const QList areaViews = area->views(); for (Sublime::View* view : areaViews) { if (views().contains(view)) { area->removeView(view); delete view; } } } // The document is deleted automatically when there are no views left return true; } bool OktetaDocument::isActive() const { return Core::self()->uiControllerInternal()->activeSublimeWindow()->activeView()->document() == this; } void OktetaDocument::setCursorPosition( const KTextEditor::Cursor& ) {} void OktetaDocument::setTextSelection( const KTextEditor::Range& ) {} void OktetaDocument::activate( Sublime::View* /* view */, KParts::MainWindow* /* mainWindow */ ) { notifyActivated(); } void OktetaDocument::setPlugin( OktetaPlugin* plugin ) { mPlugin = plugin; } Sublime::View* OktetaDocument::newView( Sublime::Document* /* document */ ) { if( mByteArrayDocument == nullptr ) { Kasten::ByteArrayRawFileSynchronizerFactory* synchronizerFactory = new Kasten::ByteArrayRawFileSynchronizerFactory(); Kasten::AbstractModelSynchronizer* synchronizer = synchronizerFactory->createSynchronizer(); Kasten::AbstractLoadJob* loadJob = synchronizer->startLoad( url() ); connect( loadJob, &Kasten::AbstractLoadJob::documentLoaded, this, &OktetaDocument::onByteArrayDocumentLoaded ); Kasten::JobManager::executeJob( loadJob ); delete synchronizerFactory; } Kasten::ByteArrayViewProfileManager* const viewProfileManager = mPlugin->viewProfileManager(); Kasten::ByteArrayViewProfileSynchronizer* viewProfileSynchronizer = new Kasten::ByteArrayViewProfileSynchronizer( viewProfileManager ); viewProfileSynchronizer->setViewProfileId( viewProfileManager->defaultViewProfileId() ); return new OktetaView( this, viewProfileSynchronizer ); } bool OktetaDocument::closeDocument(bool silent) { return close(silent ? Silent : Default); } void OktetaDocument::onByteArrayDocumentLoaded( Kasten::AbstractDocument* document ) { if( document ) { mByteArrayDocument = static_cast( document ); connect( mByteArrayDocument->synchronizer(), &Kasten::AbstractModelSynchronizer::localSyncStateChanged, this, &OktetaDocument::onByteArrayDocumentChanged ); } } void OktetaDocument::onByteArrayDocumentChanged() { notifyStateChanged(); } OktetaDocument::~OktetaDocument() { delete mByteArrayDocument; } } diff --git a/plugins/okteta/oktetadocument.h b/plugins/okteta/oktetadocument.h index 2b823ab9e4..12cafec956 100644 --- a/plugins/okteta/oktetadocument.h +++ b/plugins/okteta/oktetadocument.h @@ -1,98 +1,98 @@ /* This file is part of the KDevelop Okteta module, part of the KDE project. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef OKTETADOCUMENT_H #define OKTETADOCUMENT_H // Kasten core -#include +#include // KDevPlatform #include #include namespace Kasten { class ByteArrayDocument; class AbstractDocument; } namespace KDevelop { class ICore; class OktetaPlugin; class OktetaDocument : public Sublime::UrlDocument, public IDocument { Q_OBJECT public: OktetaDocument( const QUrl &url, ICore* core ); ~OktetaDocument() override; public: // KDevelop::IDocument API KTextEditor::Cursor cursorPosition() const override; bool isActive() const override; QMimeType mimeType() const override; KParts::Part* partForView( QWidget* widget ) const override; DocumentState state() const override; KTextEditor::Document* textDocument() const override; QUrl url() const override; void activate( Sublime::View* view, KParts::MainWindow* mainWindow ) override; bool close( IDocument::DocumentSaveMode = IDocument::Default ) override; void reload() override; bool save( IDocument::DocumentSaveMode = IDocument::Default ) override; void setCursorPosition( const KTextEditor::Cursor& cursor ) override; void setTextSelection( const KTextEditor::Range& range ) override; public: // Sublime::Document API bool closeDocument(bool silent) override; public: OktetaPlugin* plugin() const; Kasten::ByteArrayDocument* byteArrayDocument() const; public: void setPlugin( OktetaPlugin* plugin ); protected Q_SLOTS: // Sublime::Document API Sublime::View* newView( Sublime::Document* document ) override; protected Q_SLOTS: void onByteArrayDocumentChanged(); // Moc is too primitive to know about namespace aliase void onByteArrayDocumentLoaded( Kasten::AbstractDocument* document ); private: OktetaPlugin* mPlugin; Kasten::ByteArrayDocument* mByteArrayDocument; }; inline OktetaPlugin* OktetaDocument::plugin() const { return mPlugin; } inline Kasten::ByteArrayDocument* OktetaDocument::byteArrayDocument() const { return mByteArrayDocument; } } #endif diff --git a/plugins/okteta/oktetaplugin.cpp b/plugins/okteta/oktetaplugin.cpp index a8883a4925..35b87f2743 100644 --- a/plugins/okteta/oktetaplugin.cpp +++ b/plugins/okteta/oktetaplugin.cpp @@ -1,154 +1,154 @@ /* This file is part of the KDevelop Okteta module, part of the KDE project. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "oktetaplugin.h" // plugin #include "oktetadocumentfactory.h" #include "oktetatoolviewfactory.h" #include "oktetadocument.h" // Okteta Kasten tools -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include // #include // #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #ifndef BIG_ENDIAN -#include -#include +#include +#include #endif // Okteta Kasten -#include +#include // KDev #include #include #include #include #include #include // KDE #include #include #include #include K_PLUGIN_FACTORY_WITH_JSON(OktetaPluginFactory, "kdevokteta.json", registerPlugin(); ) namespace KDevelop { static inline void addTool( IUiController* uiController, Kasten::AbstractToolViewFactory* toolViewFactory, Kasten::AbstractToolFactory* toolFactory ) { OktetaToolViewFactory* factory = new OktetaToolViewFactory( toolViewFactory, toolFactory ); uiController->addToolView( toolViewFactory->title(), factory ); } OktetaPlugin::OktetaPlugin( QObject* parent, const QVariantList& args ) : IPlugin( QStringLiteral("kdevokteta"), parent ) , mDocumentFactory( new OktetaDocumentFactory(this) ) , mViewProfileManager( new Kasten::ByteArrayViewProfileManager() ) { Q_UNUSED(args) IUiController* uiController = core()->uiController(); addTool( uiController, new Kasten::ChecksumToolViewFactory(), new Kasten::ChecksumToolFactory() ); addTool( uiController, new Kasten::FilterToolViewFactory(), new Kasten::FilterToolFactory() ); addTool( uiController, new Kasten::StringsExtractToolViewFactory, new Kasten::StringsExtractToolFactory() ); addTool( uiController, new Kasten::ByteTableToolViewFactory(), new Kasten::ByteTableToolFactory() ); addTool( uiController, new Kasten::InfoToolViewFactory(), new Kasten::InfoToolFactory() ); addTool( uiController, new Kasten::PodDecoderToolViewFactory(), new Kasten::PodDecoderToolFactory() ); // disable Okteta Structures tool on big-endian as it's disable in kdesdk #ifndef BIG_ENDIAN addTool( uiController, new Kasten::StructuresToolViewFactory(), new Kasten::StructuresToolFactory() ); #endif addTool( uiController, new Kasten::BookmarksToolViewFactory, new Kasten::BookmarksToolFactory() ); KDevelop::IDocumentController* documentController = core()->documentController(); documentController->registerDocumentForMimetype(QStringLiteral("application/octet-stream"), mDocumentFactory); } ContextMenuExtension OktetaPlugin::contextMenuExtension(Context* context, QWidget* parent) { OpenWithContext* openWithContext = dynamic_cast( context ); if( openWithContext && !openWithContext->mimeType().inherits(QStringLiteral("inode/directory"))) { QAction* openAction = new QAction(i18n("Hex Editor"), parent); openAction->setIcon( QIcon::fromTheme(QStringLiteral("document-open")) ); openAction->setData( QVariant::fromValue(openWithContext->urls()) ); connect( openAction, &QAction::triggered, this, &OktetaPlugin::onOpenTriggered ); KDevelop::ContextMenuExtension contextMenuExtension; contextMenuExtension.addAction( KDevelop::ContextMenuExtension::OpenEmbeddedGroup, openAction ); return contextMenuExtension; } return KDevelop::IPlugin::contextMenuExtension(context, parent); } void OktetaPlugin::onOpenTriggered() { QAction* action = qobject_cast(sender()); Q_ASSERT(action); KDevelop::ICore* core = KDevelop::ICore::self(); IDocumentController* documentController = core->documentController(); foreach( const QUrl &url, action->data().value>() ) { IDocument* existingDocument = documentController->documentForUrl(url); if( existingDocument ) if( ! existingDocument->close() ) continue; IDocument* createdDocument = mDocumentFactory->create( url, core ); if( createdDocument ) documentController->openDocument( createdDocument ); } } OktetaPlugin::~OktetaPlugin() { delete mDocumentFactory; } } #include "oktetaplugin.moc" diff --git a/plugins/okteta/oktetaview.cpp b/plugins/okteta/oktetaview.cpp index 9fe65e5f19..96c1b262b0 100644 --- a/plugins/okteta/oktetaview.cpp +++ b/plugins/okteta/oktetaview.cpp @@ -1,54 +1,54 @@ /* This file is part of the KDevelop Okteta module, part of the KDE project. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "oktetaview.h" // lib #include "oktetaplugin.h" #include "oktetadocument.h" #include "oktetawidget.h" // Okteta Kasten -#include +#include namespace KDevelop { OktetaView::OktetaView( OktetaDocument* document, Kasten::ByteArrayViewProfileSynchronizer* viewProfileSynchronizer ) : Sublime::View( document, View::TakeOwnership ), mByteArrayView( new Kasten::ByteArrayView( document->byteArrayDocument(), viewProfileSynchronizer ) ) { } QWidget* OktetaView::createWidget( QWidget* parent ) { OktetaPlugin* plugin = static_cast( document() )->plugin(); return new OktetaWidget( parent, mByteArrayView, plugin ); } OktetaView::~OktetaView() { delete mByteArrayView; } } diff --git a/plugins/okteta/oktetawidget.cpp b/plugins/okteta/oktetawidget.cpp index 0ad78d1e00..8ce89a2a73 100644 --- a/plugins/okteta/oktetawidget.cpp +++ b/plugins/okteta/oktetawidget.cpp @@ -1,158 +1,158 @@ /* This file is part of the KDevelop Okteta module, part of the KDE project. Copyright 2010 Friedrich W. H. Kossebau This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "oktetawidget.h" // plugin #include "oktetadocument.h" #include "oktetaplugin.h" // Okteta Kasten -#include -//#include -//#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +//#include +//#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // Kasten -#include +#include // #include // #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include +#include +#include // KDevelop #include // KDE #include -#include #include #include // Qt #include +#include namespace KDevelop { OktetaWidget::OktetaWidget( QWidget* parent, Kasten::ByteArrayView* byteArrayView, OktetaPlugin* plugin ) : QWidget( parent ), KXMLGUIClient(), mByteArrayView( byteArrayView ) { setComponentName( QStringLiteral("kdevokteta") , QStringLiteral("KDevelop Okteta")); setXMLFile( QStringLiteral("kdevokteta.rc") ); setupActions(plugin); QVBoxLayout* layout = new QVBoxLayout( this ); layout->setMargin( 0 ); QWidget* widget = mByteArrayView->widget(); layout->addWidget( widget ); setFocusProxy( widget ); } void OktetaWidget::setupActions(OktetaPlugin* plugin) { Kasten::ByteArrayViewProfileManager* viewProfileManager = plugin->viewProfileManager(); mControllers = { new Kasten::VersionController(this), new Kasten::ReadOnlyController(this), // TODO: save_as // mControllers.append( new ExportController(mProgram->viewManager(),mProgram->documentManager(),this) ); new Kasten::ZoomController(this), new Kasten::SelectController(this), new Kasten::ClipboardController(this), // if( modus != BrowserViewModus ) // mControllers.append( new Kasten::InsertController(mProgram->viewManager(),mProgram->documentManager(),this) ); // mControllers.append( new Kasten::CopyAsController(mProgram->viewManager(),mProgram->documentManager(),this) ); new Kasten::OverwriteModeController(this), new Kasten::SearchController(this,this), new Kasten::ReplaceController(this,this), // mControllers.append( new Kasten::GotoOffsetController(mGroupedViews,this) ); // mControllers.append( new Kasten::SelectRangeController(mGroupedViews,this) ); new Kasten::BookmarksController(this), new Kasten::PrintController(this), new Kasten::ViewConfigController(this), new Kasten::ViewModeController(this), new Kasten::ViewProfileController(viewProfileManager, mByteArrayView->widget(), this), new Kasten::ViewProfilesManageController(this, viewProfileManager, mByteArrayView->widget()), }; // update the text of the viewprofiles_manage action, to make clear this is just for byte arrays QAction* viewprofilesManageAction = actionCollection()->action(QStringLiteral("settings_viewprofiles_manage")); viewprofilesManageAction->setText( i18nc("@action:inmenu", "Manage Byte Array View Profiles...") ); // Kasten::StatusBar* bottomBar = static_cast( statusBar() ); // mControllers.append( new ViewStatusController(bottomBar) ); // mControllers.append( new ReadOnlyBarController(bottomBar) ); // mControllers.append( new ZoomBarController(bottomBar) ); foreach( Kasten::AbstractXmlGuiController* controller, mControllers ) controller->setTargetModel( mByteArrayView ); #if 0 QDesignerFormWindowManagerInterface* manager = mDocument->form()->core()->formWindowManager(); KActionCollection* ac = actionCollection(); KStandardAction::save( this, SLOT(save()), ac); ac->addAction( "adjust_size", manager->actionAdjustSize() ); ac->addAction( "break_layout", manager->actionBreakLayout() ); ac->addAction( "designer_cut", manager->actionCut() ); ac->addAction( "designer_copy", manager->actionCopy() ); ac->addAction( "designer_paste", manager->actionPaste() ); ac->addAction( "designer_delete", manager->actionDelete() ); ac->addAction( "layout_grid", manager->actionGridLayout() ); ac->addAction( "layout_horiz", manager->actionHorizontalLayout() ); ac->addAction( "layout_vertical", manager->actionVerticalLayout() ); ac->addAction( "layout_split_horiz", manager->actionSplitHorizontal() ); ac->addAction( "layout_split_vert", manager->actionSplitVertical() ); ac->addAction( "designer_undo", manager->actionUndo() ); ac->addAction( "designer_redo", manager->actionRedo() ); ac->addAction( "designer_select_all", manager->actionSelectAll() ); #endif } #if 0 void OktetaWidget::save() { mDocument->save(); } #endif OktetaWidget::~OktetaWidget() { qDeleteAll( mControllers ); } }