Skip to content

Commit

Permalink
fix invalid paths in the shell: escape filepaths when opened with sys…
Browse files Browse the repository at this point in the history
…tem()
  • Loading branch information
SZinedine committed Sep 21, 2020
1 parent 73c2feb commit 716551d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/editorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*************************************************************************/
#include "markdowneditorwidget.h"
#include <QFileSystemWatcher>
#include <QToolBar>
#include "markdowneditorwidget.h"

class EditorWidget : public QWidget {
Q_OBJECT
Expand Down
11 changes: 4 additions & 7 deletions src/markdowneditorwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,18 @@
#include <QMenu>

MarkdownEditorWidget::MarkdownEditorWidget(QWidget* parent)
: QMarkdownTextEdit(parent), m_occupied(false)
{
: QMarkdownTextEdit(parent), m_occupied(false) {
setReadOnly(true);
}

void MarkdownEditorWidget::contextMenuEvent(QContextMenuEvent *event) {
QMenu *menu = createStandardContextMenu();
void MarkdownEditorWidget::contextMenuEvent(QContextMenuEvent* event) {
QMenu* menu = createStandardContextMenu();
QAction* closeFileAction = new QAction(tr("Close File"), this);
menu->addSeparator();
menu->addAction(closeFileAction);
closeFileAction->setEnabled(m_occupied);

connect(closeFileAction, &QAction::triggered, [this]{ emit this->toClose(); });
connect(closeFileAction, &QAction::triggered, [this] { emit this->toClose(); });
menu->exec(event->globalPos());

delete menu;
Expand All @@ -48,5 +47,3 @@ void MarkdownEditorWidget::setText(const QString& text) {
QMarkdownTextEdit::setText(text);
setOccupied(true);
}


10 changes: 4 additions & 6 deletions src/markdowneditorwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@
*************************************************************************/
#include <qmarkdowntextedit.h>

class MarkdownEditorWidget : public QMarkdownTextEdit
{
class MarkdownEditorWidget : public QMarkdownTextEdit {
Q_OBJECT
public:
explicit MarkdownEditorWidget(QWidget* parent=nullptr);
~MarkdownEditorWidget() {};
void contextMenuEvent(QContextMenuEvent *event) override;
explicit MarkdownEditorWidget(QWidget* parent = nullptr);
~MarkdownEditorWidget(){};
void contextMenuEvent(QContextMenuEvent* event) override;
inline void setOccupied(bool o) { m_occupied = o; }
inline bool occupied() const { return m_occupied; }
void clear();
Expand All @@ -36,4 +35,3 @@ class MarkdownEditorWidget : public QMarkdownTextEdit
/* is there a file displayed or not */
bool m_occupied;
};

6 changes: 5 additions & 1 deletion src/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ void Settings::openFile(QString editor, const QString& path, QWidget* parent) {
QDir::setCurrent(p.absolutePath());
QDesktopServices::openUrl(QUrl::fromLocalFile(p.fileName()));
} else {
QString command = editor + " \"" + path + "\"";
QString p = path;
p = p.replace("\"", "\\\"");
p = p.replace("\'", "\\\'");
QString command = editor + " \"" + p + "\"";
qDebug() << p;
std::thread([=] { std::system(command.toStdString().c_str()); }).detach();
}
saveRecentlyOpenedFile(path);
Expand Down

0 comments on commit 716551d

Please sign in to comment.