Skip to content

Commit

Permalink
TextEditorPlugin: new file command
Browse files Browse the repository at this point in the history
When you press control+n a new empty tab is created. This needed fixes
inside qmdilib.

Also inside this commit:

- some text are translated
- using standard actions for some commands
- using theme definitions instead of icon names for actions
- a bug in the text editor plugin, which prevented from opening new
empty files in the text editor (the hex viewer took ownership).
  • Loading branch information
diegoiast committed Sep 24, 2024
1 parent 124750d commit dce76b6
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 30 deletions.
2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Tasks for v0.0.1
1. ~~Quick jump inside open files~~
1. ~~Save zoom level per document~~
1. ~~File watcher on created file not stopped while saving~~
1. Control+N should open a new tab.
1. ~~Control+N should open a new tab.~~
1. ~~Line ending on save (Unix/Windows/Keep original)~~~
1. ~~Trim spaces on save (edit?)~~
1. ~~Add line/column to margin display~~
Expand Down
9 changes: 8 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <QDir>
#include <QIcon>
#include <QStandardPaths>
#include <QToolButton>

#include "pluginmanager.h"
#include "plugins/ProjectManager/ProjectManagerPlg.h"
Expand Down Expand Up @@ -69,10 +70,13 @@ int main(int argc, char *argv[]) {
auto filePath = QStandardPaths::writableLocation(QStandardPaths::AppConfigLocation);
auto iniFilePath = filePath + "/qtedit4.ini";
auto windowIcon = QIcon(":qtedit4.ico");

auto textEditorPlugin = new TextEditorPlugin;

pluginManager.setWindowTitle("qtedit4");
pluginManager.setWindowIcon(windowIcon);
pluginManager.setFileSettingsManager(iniFilePath);
pluginManager.addPlugin(new TextEditorPlugin);
pluginManager.addPlugin(textEditorPlugin);
pluginManager.addPlugin(new FileSystemBrowserPlugin);
pluginManager.addPlugin(new HelpPlugin);
pluginManager.addPlugin(new ProjectManagerPlugin);
Expand All @@ -83,6 +87,9 @@ int main(int argc, char *argv[]) {
pluginManager.restoreSettings();
pluginManager.show();

pluginManager.connect(&pluginManager, &PluginManager::newFileRequested,
[textEditorPlugin]() { textEditorPlugin->fileNew(); });

pluginManager.openFiles(parser.positionalArguments());
return app.exec();
}
21 changes: 6 additions & 15 deletions src/plugins/texteditor/texteditor_plg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ TextEditorPlugin::TextEditorPlugin() {
autoEnabled = true;
alwaysEnabled = false;

actionNewFile = new QAction(tr("New blank file"), this);
actionNewCPP = new QAction(tr("New source"), this);
actionNewHeader = new QAction(tr("New header"), this);
myNewActions = new QActionGroup(this);
myNewActions->addAction(actionNewFile);
myNewActions->addAction(actionNewCPP);
myNewActions->addAction(actionNewHeader);

/*
#if defined(WIN32)
auto installPrefix = QCoreApplication::applicationDirPath();
Expand All @@ -61,10 +53,8 @@ TextEditorPlugin::TextEditorPlugin() {
#endif
*/

connect(myNewActions, &QActionGroup::triggered, this, &TextEditorPlugin::fileNew);

config.pluginName = "Text editor";
config.description = "Default text editor, based on QutePart";
config.pluginName = tr("Text editor");
config.description = tr("Default text editor, based on QutePart");
config.configItems.push_back(qmdiConfigItem::Builder()
.setDisplayName(tr("Trim spaces"))
.setDescription(tr("Remove spaces from end of lines, on save"))
Expand Down Expand Up @@ -144,8 +134,6 @@ void TextEditorPlugin::showAbout() {
"This plugin gives a QtSourceView based text editor");
}

QActionGroup *TextEditorPlugin::newFileActions() { return myNewActions; }

QStringList TextEditorPlugin::myExtensions() {
auto s = QStringList();
s << tr("Sources", "EditorPlugin::myExtensions") + " (*.c *.cpp *.cxx *.h *.hpp *.hxx *.inc)";
Expand All @@ -157,6 +145,9 @@ QStringList TextEditorPlugin::myExtensions() {
}

int TextEditorPlugin::canOpenFile(const QString fileName) {
if (fileName.isEmpty()) {
return 5;
}
auto u = QUrl(fileName);

// if the scheme is a single line, lets assume this is a windows drive
Expand Down Expand Up @@ -260,7 +251,7 @@ void TextEditorPlugin::configurationHasBeenModified() {
}
}

void TextEditorPlugin::fileNew(QAction *) {
void TextEditorPlugin::fileNew() {
auto editor = new qmdiEditor(dynamic_cast<QMainWindow *>(mdiServer));
mdiServer->addClient(editor);
}
14 changes: 1 addition & 13 deletions src/plugins/texteditor/texteditor_plg.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#include "endlinestyle.h"
#include "iplugin.h"

class QsvColorDefFactory;

class TextEditorPlugin : public IPlugin {

struct Config {
CONFIG_DEFINE(TrimSpaces, bool)
CONFIG_DEFINE(SmartHome, bool)
Expand All @@ -40,7 +37,6 @@ class TextEditorPlugin : public IPlugin {
~TextEditorPlugin();

void showAbout() override;
QActionGroup *newFileActions() override;
QStringList myExtensions() override;
int canOpenFile(const QString fileName) override;
bool openFile(const QString fileName, int x = -1, int y = -1, int z = -1) override;
Expand All @@ -49,13 +45,5 @@ class TextEditorPlugin : public IPlugin {

public slots:
virtual void configurationHasBeenModified() override;
void fileNew(QAction *);

private:
QActionGroup *myNewActions;
QAction *actionNewFile;
QAction *actionNewCPP;
QAction *actionNewHeader;

QsvColorDefFactory *editorColors;
void fileNew();
};

0 comments on commit dce76b6

Please sign in to comment.