Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/GlobalCommands.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ inline constexpr const char *VariableInfo = "VariableInfo";
// Editor requests information about variable below mouse
inline constexpr const char *KeywordTooltip = "KeywordTooltip";

// Open a new editor, with the attached document
inline constexpr const char *DisplayText = "DisplayText";

} // namespace GlobalCommands

namespace GlobalArguments {
Expand All @@ -56,4 +59,5 @@ inline constexpr const char *Raw = "Raw";
inline constexpr const char *Tags = "Tags";
inline constexpr const char *Tooltip = "Tooltip";
inline constexpr const char *Symbol = "Symbol";
inline constexpr const char *Content = "Content";
} // namespace GlobalArguments
43 changes: 41 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QStandardPaths>
#include <QToolButton>

#include "GlobalCommands.hpp"
#include "pluginmanager.h"
#include "plugins/CTags/CTagsPlugin.hpp"
#include "plugins/ProjectManager/ProjectManagerPlg.h"
Expand All @@ -23,7 +24,41 @@
#include "plugins/imageviewer/imageviewer_plg.h"
#include "plugins/texteditor/texteditor_plg.h"

#define USE_SPLIT
const QString WelcomContent = R"(
# Welcome to CodePointer

CodePointer - an IDE for Rust, Go, C++ and more. The application
will look like a normal text editor, but can

![CodePointer](https://raw.githubusercontent.com/diegoiast/qtedit4/337cd10aab4b123b15dee53c446fd1b7e343dc9a/qtedit4.png)

Some hints for starter:

* Normal keyboard shortcuts you are used
to should work (`control+f`, `control+o`, `control+s` and more).
* To select tabs, press `alt+1` etc.
* To select/hide/show hide sidebar, press `control+1` (this will open the file
manager).
* On the top left, you will find the application menu (shortcut is `alt+m`).
* You can access the command palette which has all the available commands
using `control+shift+p`.
* You can press `alt+control+m` to get a conservative menus+toolbars UI.
* You can split the editor horizontally by pressing

## Project management

You can also load projects, build and execute them:
* If you edit a `CMakeLists.txt` or `meson.build` or `cargo.toml` you will be
prompted to open this file as a project. A new sidebar will be opened with
the project files.
* You can also add an "existing project", by choosing a directory.
* You can choose commands to execute for building, or other tasks relevant
to this project (configure, build), and you can choose which target
to run (`control+b` and `control-r`).
* When building, errors are shown at the bottom.
* You can execute script files (python, Perl, Bash, PowerShell, etc.), by
pressing `control+shift+r`
)";

int main(int argc, char *argv[]) {
Q_INIT_RESOURCE(qutepart_syntax_files);
Expand Down Expand Up @@ -123,7 +158,11 @@ int main(int argc, char *argv[]) {
pluginManager.updateGUI();

if (pluginManager.visibleTabs() == 0) {
textEditorPlugin->fileNew();
CommandArgs args = {
{GlobalArguments::FileName, "welcome.md"},
{GlobalArguments::Content, WelcomContent},
};
pluginManager.handleCommandAsync(GlobalCommands::DisplayText, args);
pluginManager.saveSettings();
}

Expand Down
38 changes: 38 additions & 0 deletions src/plugins/texteditor/texteditor_plg.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#include <QAction>
#include <QActionGroup>
#include <QApplication>
Expand All @@ -17,6 +18,7 @@
#include <qmdiserver.h>

#include "AnsiToHTML.hpp"
#include "GlobalCommands.hpp"
#include "texteditor_plg.h"
#include "thememanager.h"
#include "widgets/HistoryLineEdit.h"
Expand Down Expand Up @@ -296,6 +298,42 @@ void TextEditorPlugin::saveConfig(QSettings &settings) {
IPlugin::saveConfig(settings);
}

int TextEditorPlugin::canHandleAsyncCommand(const QString &command, const CommandArgs &) const {
if (command == GlobalCommands::DisplayText) {
return true;
}
return false;
}

QFuture<CommandArgs> TextEditorPlugin::handleCommandAsync(const QString &command,
const CommandArgs &args) {
if (command != GlobalCommands::DisplayText) {
return {};
}

auto fileName = args[GlobalArguments::FileName].toString();
auto content = args[GlobalArguments::Content].toString();
auto editor = new qmdiEditor(dynamic_cast<QMainWindow *>(mdiServer), themeManager);
auto langInfo = ::Qutepart::chooseLanguage({}, {}, fileName);
if (langInfo.isValid()) {
editor->setEditorHighlighter(langInfo.id);
}
// auto shouldAutoPreview = editor->autoPreview;
// auto canOpenPreview = editor->hasPreview();
editor->loadFile(fileName);
editor->setPreviewEnabled(true);
editor->setPreviewVisible(true);
editor->setHistoryModel(historyModel);
editor->setPlainText(content);
applySettings(editor);
mdiServer->addClient(editor);

auto promise = new QPromise<CommandArgs>();
auto future = promise->future();
promise->finish();
return promise->future();
}

QStringList TextEditorPlugin::myExtensions() {
auto s = QStringList();
s << tr("Sources C++", "EditorPlugin::myExtensions") +
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/texteditor/texteditor_plg.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ class TextEditorPlugin : public IPlugin {
virtual void showAbout() override;
virtual void loadConfig(QSettings &settings) override;
virtual void saveConfig(QSettings &settings) override;
virtual int canHandleAsyncCommand(const QString &command,
const CommandArgs &args) const override;
virtual QFuture<CommandArgs> handleCommandAsync(const QString &command,
const CommandArgs &args) override;

QStringList myExtensions() override;
int canOpenFile(const QString &fileName) override;
Expand Down
9 changes: 8 additions & 1 deletion src/widgets/qmdieditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,9 @@ void qmdiEditor::updateClientName() {

if (mdiClientName != newName) {
mdiClientName = newName;
mdiServer->updateClientName(this);
if (mdiServer) {
mdiServer->updateClientName(this);
}
}
}

Expand Down Expand Up @@ -1072,6 +1074,11 @@ void qmdiEditor::hideBannerMessage() {

void qmdiEditor::newDocument() { loadFile(""); }

void qmdiEditor::setPlainText(const QString &plainText) {
textEditor->setPlainText(plainText);
textEditor->document()->setModified(true);
}

bool qmdiEditor::doSave() {
if (fileName.isEmpty()) {
return doSaveAs();
Expand Down
1 change: 1 addition & 0 deletions src/widgets/qmdieditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class qmdiEditor : public QWidget, public qmdiClient {
void hideBannerMessage();

void newDocument();
void setPlainText(const QString &plainText);
bool doSave();
bool doSaveAs();
bool loadFile(const QString &fileName);
Expand Down