[rkward] /: Add menu action to open any supported file type, directly
Thomas Friedrichsmeier
null at kde.org
Sat Apr 11 21:15:29 BST 2020
Git commit 0bfe907a4907f73b4ef640420d805d0aed41c327 by Thomas Friedrichsmeier.
Committed on 11/04/2020 at 20:15.
Pushed by tfry into branch 'master'.
Add menu action to open any supported file type, directly
M +1 -0 ChangeLog
M +48 -0 rkward/rkward.cpp
M +2 -0 rkward/rkward.h
M +2 -1 rkward/rkwardui.rc
https://commits.kde.org/rkward/0bfe907a4907f73b4ef640420d805d0aed41c327
diff --git a/ChangeLog b/ChangeLog
index 65dfc7f2..5b9e1ebb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,5 @@
--- Version 0.7.2 - UNRELEASED
+- Add menu action to open any supported file type, directly
- Support using QWebEngine instead of QtWebKit (still supported)
- TODO:
- Should all KIO-schemes be supported (not too hard to do, help:/ already supported)?
diff --git a/rkward/rkward.cpp b/rkward/rkward.cpp
index cfa49ffa..b8dd5d8f 100644
--- a/rkward/rkward.cpp
+++ b/rkward/rkward.cpp
@@ -29,6 +29,7 @@
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QIcon>
+#include <QComboBox>
// include files for KDE
#include <kmessagebox.h>
@@ -501,6 +502,12 @@ void RKWardMainWindow::initActions() {
fileOpen = actionCollection ()->addAction (KStandardAction::Open, "file_openy", this, SLOT(slotOpenCommandEditor()));
fileOpen->setText (i18n ("Open R Script File..."));
+ QAction *file_open_any = actionCollection ()->addAction (KStandardAction::Open, "file_open_any");
+ connect (file_open_any, &QAction::triggered, this, &RKWardMainWindow::openAnyFile);
+
+ file_open_any->setText (i18n ("Open any File..."));
+ actionCollection ()->setDefaultShortcut (file_open_any, Qt::ControlModifier + Qt::AltModifier + Qt::Key_O);
+
fileOpenRecent = static_cast<KRecentFilesAction*> (actionCollection ()->addAction (KStandardAction::OpenRecent, "file_open_recenty", this, SLOT(slotOpenCommandEditor(QUrl))));
fileOpenRecent->setText (i18n ("Open Recent R Script File"));
@@ -961,6 +968,47 @@ void RKWardMainWindow::addScriptUrl (const QUrl &url) {
if (!url.isEmpty ()) fileOpenRecent->addUrl (url);
}
+void RKWardMainWindow::openAnyFile () {
+ RK_TRACE (APP);
+
+ QFileDialog dialog (0, QString (), RKSettingsModuleGeneral::lastUsedUrlFor ("rscripts").toLocalFile (), QString ("*|All Files (*)\n%1|R Script Files (%1)").arg (RKSettingsModuleCommandEditor::scriptFileFilter ()));
+ dialog.setFileMode (QFileDialog::ExistingFiles);
+
+// Create a type selection widget, and hack it into the dialog:
+ QFrame dummy (this);
+ dummy.setWindowTitle (i18n ("Open"));
+ QVBoxLayout layout (&dummy);
+ QHBoxLayout hbox;
+ layout.addLayout (&hbox);
+ hbox.addWidget (new QLabel (i18n ("Opening mode:")));
+ QComboBox open_mode;
+ open_mode.addItems (QStringList () << i18n ("Guess file type, automatically") << i18n ("Open as text / script file") << i18n ("Open as text file and force R highlighting") << ("Open as R workspace"));
+ hbox.addWidget (&open_mode);
+ hbox.setStretchFactor (&open_mode, 100);
+
+ dummy.setWindowFlags (dialog.windowFlags ());
+ dialog.setOption (QFileDialog::DontUseNativeDialog);
+ dialog.setWindowFlags (Qt::Widget);
+ layout.addWidget (&dialog);
+ dummy.show ();
+ auto res = dialog.exec ();
+
+ if (res != QDialog::Accepted) return;
+ QUrl url = QUrl::fromLocalFile (dialog.selectedFiles ().value (0));
+ if (open_mode.currentIndex () == 0) {
+ RKWorkplace::mainWorkplace ()->openAnyUrl (url);
+ } else if (open_mode.currentIndex () == 1) {
+ RKWorkplace::mainWorkplace ()->openScriptEditor (url);
+ RKSettingsModuleGeneral::updateLastUsedUrl ("rscripts", url.adjusted (QUrl::RemoveFilename));
+ } else if (open_mode.currentIndex () == 2) {
+ RKWorkplace::mainWorkplace ()->openScriptEditor (url, QString (), RKCommandEditorFlags::DefaultFlags | RKCommandEditorFlags::ForceRHighlighting);
+ RKSettingsModuleGeneral::updateLastUsedUrl ("rscripts", url.adjusted (QUrl::RemoveFilename));
+ } else if (open_mode.currentIndex () == 3) {
+ openWorkspace (url);
+ RKSettingsModuleGeneral::updateLastUsedUrl ("workspaces", url.adjusted (QUrl::RemoveFilename));
+ }
+}
+
void RKWardMainWindow::slotOpenCommandEditor (const QUrl &url, const QString &encoding) {
RK_TRACE (APP);
diff --git a/rkward/rkward.h b/rkward/rkward.h
index f1d0bf81..e6e49da6 100644
--- a/rkward/rkward.h
+++ b/rkward/rkward.h
@@ -139,6 +139,8 @@ public slots:
private slots:
void partChanged (KParts::Part *new_part);
private:
+/** Prompt for a local file to open, providing a choice of how to open the file (as R script, text, workspace, auto) */
+ void openAnyFile ();
/** Opens a new workspace, without asking or closing anything. */
void openWorkspace (const QUrl &url);
diff --git a/rkward/rkwardui.rc b/rkward/rkwardui.rc
index 3be48bcd..39cfa543 100644
--- a/rkward/rkwardui.rc
+++ b/rkward/rkwardui.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui>
-<kpartgui name="rkward_main" version="700">
+<kpartgui name="rkward_main" version="720">
<MenuBar>
<!-- The Main Window ui.rc is the only one, where merging happens, reliably. That is, why we need to define
a lot of merge points, here, which can then be used be mdi windows and their children.
@@ -10,6 +10,7 @@
<Action name="new_command_editor"/>
</Menu>
<Action name="file_openy"/>
+ <Action name="file_open_any"/>
<Action name="file_open_recenty"/>
<Separator/>
<Menu name="import"><text>&Import</text>
More information about the rkward-tracker
mailing list