+++ /dev/null
-<RCC>
- <qresource prefix="/main">
- <file>icons/action_go.png</file>
- <file>icons/action_paste.png</file>
- <file>icons/arrow_turn_left.png</file>
- <file>icons/bullet_go.png</file>
- <file>icons/cog_edit.png</file>
- <file>icons/database_save.png</file>
- <file>icons/disk.png</file>
- <file>icons/door_in.png</file>
- <file>icons/eye.png</file>
- <file>icons/folder_find.png</file>
- <file>icons/folder_go.png</file>
- <file>icons/folder_magnify.png</file>
- <file>icons/folder.png</file>
- <file>icons/layout_add.png</file>
- <file>icons/paste_plain.png</file>
- <file>icons/resultset_next.png</file>
- <file>icons/sitemap_color.png</file>
- <file>icons/table.png</file>
- <file>icons/tables.png</file>
- <file>icons/wand.png</file>
- <file>icons/wrench.png</file>
- <file>icons/folder_page.png</file>
- </qresource>
-</RCC>
+++ /dev/null
-/*
- * main.cpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-#include "reditor.hpp"
-#include <QApplication>
-
-int main(int argc, char *argv[]) {
- const char* workspace = NULL;
- const char* project = NULL;
- for (int ix = 1; ix < argc; ix++) {
- if (argv[ix][0] == '-') {
- if (strcmp(argv[ix], "-w") == 0 && ix < argc - 1) {
- workspace = argv[++ix];
- } else if (strncmp(argv[ix], "--workspace=", 12) == 0) {
- workspace = argv[ix] + 12;
- } else if (strcmp(argv[ix], "-p") == 0 && ix < argc - 1) {
- project = argv[++ix];
- } else if (strncmp(argv[ix], "--project=", 10) == 0) {
- workspace = argv[ix] + 10;
- }
- }
- }
- QApplication a(argc, argv);
- ReLogger logger;
- ReDebugAppender appender;
- appender.setAutoDelete(false);
- logger.addAppender(&appender);
- MainWindow w(workspace, project, &logger);
- logger.log(LOG_INFO, 1, "start");
- w.show();
-
- return a.exec();
-}
+++ /dev/null
-/*
- * mainwindow.cpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#include "reditor.hpp"
-#include "ui_mainwindow.h"
-#include <QFileDialog>
-
-MainWindow::MainWindow(const char* workspace, const char* project,
- ReLogger* logger, QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow),
- m_project(NULL),
- m_workspace(NULL),
- m_logger(logger),
- m_fileTree(NULL),
- m_dockProjectTree(NULL) {
- if (workspace == NULL)
- workspace = QDir::homePath().toUtf8();
- changeWorkspace(workspace == NULL ? QDir::homePath() : workspace);
-
- QString proj(project == NULL ? "" : project);
- if (project == NULL) {
- QStringList lastProjects;
- m_workspace->historyAsList("projects", lastProjects);
- int ix = 0;
- while (proj.isEmpty() && ix < lastProjects.size()) {
- QFileInfo dir(lastProjects.at(ix));
- if (dir.isDir() && dir.isWritable())
- proj = lastProjects.at(ix);
- }
- if (!proj.isEmpty())
- changeProject(proj);
- }
-
- ui->setupUi(this);
- ReEdit* edit = ui->widget;
-#if defined __linux__
- m_file = new ReFile("/home/hm/editor.txt", false);
-#else
- m_file = new ReFile("U:\\ws_cpp\\rplqt\\Doxyfile", false);
-#endif
- edit->setLines(m_file);
- edit->setCursorLine(0);
- connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()));
- open();
-}
-
-MainWindow::~MainWindow() {
- delete ui;
-}
-
-/**
- * Change the current project.
- *
- * @param path the directory containing the project data
- */
-void MainWindow::changeProject(QString path) {
- delete m_project;
- if (path.endsWith(OS_SEPARATOR_STR))
- path.remove(path.size() - 1, 1);
- m_project = new Project(path, this);
- int maxEntries = m_workspace->intValue("history.max_projects");
- m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_PROJECTS, path, ';',
- maxEntries);
- if (m_fileTree == NULL) {
- m_fileTree = new ReFileTree(path, m_logger, this);
- m_dockProjectTree = new QDockWidget("", this);
- m_dockProjectTree->setWidget(m_fileTree);
- addDockWidget(Qt::LeftDockWidgetArea, m_dockProjectTree);
- }
- m_fileTree->setPath(path);
- m_dockProjectTree->setWindowTitle(
- tr("Project") + " " + ReQStringUtils::nodeOf(path));
-
-}
-
-/**
- * Change the workspace.
- *
- * @param path the directory containing the workspace data
- */
-void MainWindow::changeWorkspace(const QString& path) {
- delete m_workspace;
- m_workspace = new Workspace(path, m_logger);
-}
-
-/**
- * Calls the file selection dialog.
- */
-void MainWindow::openFile(const QString& name) {
- m_file = new ReFile(name, false);
-
- ReEdit* edit = ui->widget;
- edit->setLines(m_file);
- edit->setCursorLine(0);
- int maxEntries = m_workspace->intValue("history.max_files");
- m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_FILES, name, ';',
- maxEntries);
-}
-
-/**
- * Closes the current project.
- */
-void MainWindow::closeProject() {
- delete m_project;
- m_project = NULL;
-}
-
-/**
- * Shows the "open project/file dialog".
- */
-void MainWindow::open() {
- ProjectSelection dialog(this);
- dialog.exec();
-}
-ReLogger* MainWindow::logger() const {
- return m_logger;
-}
-
-/**
- * Returns the current workspace.
- *
- * @return the current workspace
- */
-Project* MainWindow::project() const {
- return m_project;
-}
-
-Workspace* MainWindow::workspace() const {
- return m_workspace;
-}
-
+++ /dev/null
-/*
- * mainwindow.hpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#ifndef MAINWINDOW_HPP
-#define MAINWINDOW_HPP
-
-#include <QMainWindow>
-#ifndef REBASE_HPP
-#include "reditor.hpp"
-#endif
-namespace Ui {
-class MainWindow;
-}
-
-class MainWindow: public QMainWindow {
- Q_OBJECT
-
-public:
- explicit MainWindow(const char* workspace, const char* project,
- ReLogger* logger, QWidget *parent = 0);
- ~MainWindow();
- void changeProject(QString path);
- void changeWorkspace(const QString& path);
- void closeProject();
- void openFile(const QString& name);
- Project* project() const;
- Workspace* workspace() const;
- ReLogger* logger() const;
-
-public slots:
- void open();
-private:
- Ui::MainWindow *ui;
- ReFile* m_file;
- Project* m_project;
- Workspace* m_workspace;
- ReLogger* m_logger;
- ReFileTree* m_fileTree;
- QDockWidget* m_dockProjectTree;
-};
-
-#endif // MAINWINDOW_HPP
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>MainWindow</class>
- <widget class="QMainWindow" name="MainWindow">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>803</width>
- <height>642</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>MainWindow</string>
- </property>
- <widget class="QWidget" name="centralWidget">
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <widget class="ReEdit" name="widget" native="true"/>
- </item>
- </layout>
- </widget>
- <widget class="QMenuBar" name="menuBar">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>803</width>
- <height>23</height>
- </rect>
- </property>
- </widget>
- <widget class="QToolBar" name="mainToolBar">
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- <addaction name="actionOpen"/>
- <addaction name="actionSave"/>
- </widget>
- <widget class="QStatusBar" name="statusBar"/>
- <widget class="QToolBar" name="toolBar">
- <property name="windowTitle">
- <string>toolBar</string>
- </property>
- <attribute name="toolBarArea">
- <enum>TopToolBarArea</enum>
- </attribute>
- <attribute name="toolBarBreak">
- <bool>false</bool>
- </attribute>
- </widget>
- <action name="actionOpen">
- <property name="icon">
- <iconset resource="editor.qrc">
- <normaloff>:/main/icons/table.png</normaloff>:/main/icons/table.png</iconset>
- </property>
- <property name="text">
- <string>Open</string>
- </property>
- <property name="toolTip">
- <string>Open a file</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+O</string>
- </property>
- </action>
- <action name="actionSave">
- <property name="icon">
- <iconset resource="editor.qrc">
- <normaloff>:/main/icons/disk.png</normaloff>:/main/icons/disk.png</iconset>
- </property>
- <property name="text">
- <string>Save</string>
- </property>
- <property name="toolTip">
- <string>Save the file</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+S</string>
- </property>
- </action>
- </widget>
- <layoutdefault spacing="6" margin="11"/>
- <customwidgets>
- <customwidget>
- <class>ReEdit</class>
- <extends>QWidget</extends>
- <header>gui/regui.hpp</header>
- <container>1</container>
- </customwidget>
- </customwidgets>
- <resources>
- <include location="editor.qrc"/>
- </resources>
- <connections/>
-</ui>
+++ /dev/null
-/*
- * project.cpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#include "reditor.hpp"
-
-const char* Project::KEY_HISTORY_OPEN_FILES = "openFiles";
-/**
- * Constructor.
- *
- * @param path the directory containing the configuration
- * @param logger the logger
- */
-Project::Project(const QString& path, MainWindow* mainWindow) :
- ReSettings(path, ".reditor.proj", mainWindow->logger()),
- m_mainWindow(mainWindow) {
- QString filename = topOfHistory(KEY_HISTORY_OPEN_FILES);
- QFileInfo info(filename);
- if (!filename.isEmpty() && info.exists() && !info.isDir()) {
- m_mainWindow->openFile(filename);
- }
-}
-
-/**
- * Opens a file in the project directory.
- *
- * @param filename the filename relative to the project directory
- */
-void Project::openFile(const QString& filename) {
- QString full = m_path + OS_SEPARATOR_STR + filename;
- addHistoryEntry(KEY_HISTORY_OPEN_FILES, filename, ';', 1);
- m_mainWindow->openFile(full);
-}
-
+++ /dev/null
-/*
- * project.hpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#ifndef PROJECT_HPP
-#define PROJECT_HPP
-
-class MainWindow;
-
-class Project: public ReSettings {
-public:
- static const char* KEY_HISTORY_OPEN_FILES;
-public:
- Project(const QString& path, MainWindow* mainWindow);
-public:
- void openFile(const QString& filename);
-
-private:
- MainWindow* m_mainWindow;
-};
-
-#endif // PROJECT_HPP
+++ /dev/null
-/*
- * projectselection.cpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#include "reditor.hpp"
-#include "ui_projectselection.h"
-#include <QFileDialog>
-#include <QMessageBox>
-
-/**
- * Constructor.
- *
- * @param parent NULL or the parent
- * @param mainWindow the main window
- */
-ProjectSelection::ProjectSelection(MainWindow* mainWindow, QWidget *parent) :
- QDialog(parent),
- ui(new Ui::ProjectSelection),
- m_mainWindow(mainWindow) {
- ui->setupUi(this);
- connect(ui->toolButtonSelectFile, SIGNAL(clicked()), this,
- SLOT(selectFile()));
- connect(ui->toolButtonSelectProject, SIGNAL(clicked()), this,
- SLOT(selectDir()));
- connect(ui->pushButtonOpen, SIGNAL(clicked()), this, SLOT(open()));
- connect(ui->lineEditFilterLastFile, SIGNAL(textChanged(QString)), this,
- SLOT(textChangedFilterFiles(QString)));
- connect(ui->tableWidgetFiles, SIGNAL(cellEntered(int,int)), this,
- SLOT(cellEnteredFiles(int, int)));
- connect(ui->tableWidgetProjects, SIGNAL(cellEntered(int,int)), this,
- SLOT(cellEnteredProjects(int, int)));
- Workspace* workspace = mainWindow->workspace();
- buildTableInfo(workspace, Workspace::KEY_HISTORY_FILES, true, m_files);
- buildTableInfo(workspace, Workspace::KEY_HISTORY_PROJECTS, false,
- m_projects);
- buildTable("", m_files, ui->tableWidgetFiles);
- buildTable("", m_projects, ui->tableWidgetProjects);
-}
-
-/**
- * Destructor.
- */
-ProjectSelection::~ProjectSelection() {
- delete ui;
-}
-/**
- * Handles the event cellEntered for the last opened files.
- *
- * @param row the row of the entered cell
- * @param col the column of the entered cell
- */
-void ProjectSelection::cellEnteredFiles(int row, int col) {
- ReUseParameter(col);
- QString file = fileOfTable(ui->tableWidgetFiles, row);
- ui->lineEditOpen->setText(file);
-}
-
-/**
- * Handles the event cellEntered for the last opened projects.
- *
- * @param row the row of the entered cell
- * @param col the column of the entered cell
- */
-void ProjectSelection::cellEnteredProjects(int row, int col) {
- ReUseParameter(col);
- QString file = fileOfTable(ui->tableWidgetProjects, row);
- ui->lineEditOpen->setText(file);
-}
-
-/**
- * Builds the table from the table using a filter expression.
- *
- * @param filter a filter expression with wildcards '*'
- * @param lines the full table info
- * @param table OUT: will be filled with all lines matching the filter
- */
-void ProjectSelection::buildTable(const QString& filter,
- const QStringList& lines, QTableWidget* table) {
- QStringList::const_iterator it;
- int rowCount = 0;
- ReMatcher matcher(filter, Qt::CaseInsensitive, true);
- for (it = lines.cbegin(); it != lines.cend(); ++it) {
- if (matcher.matches(*it))
- rowCount++;
- }
- table->setRowCount(rowCount);
- int row = -1;
- for (it = lines.cbegin(); it != lines.cend(); ++it) {
- if (matcher.matches(*it)) {
- row++;
- QStringList cols = it->split('\t');
- for (int col = 0; col < cols.size(); col++) {
- QTableWidgetItem* item = table->item(row, col);
- if (item != NULL)
- item->setText(cols.at(col));
- else {
- item = new QTableWidgetItem(cols.at(col));
- table->setItem(row, col, item);
- }
- }
- }
- }
-}
-
-/**
- * Build the info for a table (last opened files or last opened projects).
- *
- * Note: the table shows a filtered part of this info.
- *
- * @param settings the history container
- * @param key the name of the history entry
- * @param withDate the file's name is part of the info
- * @param tableContent OUT: the list containing the table info
- */
-void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
- bool withDate, QStringList& tableContent) {
- QStringList files;
- settings->historyAsList(key, files);
- QStringList::const_iterator it;
- for (it = files.cbegin(); it != files.cend(); ++it) {
- QFileInfo file(*it);
- if (file.exists()) {
- QString info = file.baseName();
- if (withDate)
- info.append("\t").append(
- file.lastModified().toString("yyyy.mm.dd/HH:MM:SS"));
- info.append("\t").append(file.path());
- tableContent.append(info);
- }
- }
-}
-
-/**
- * Shows an error message.
- *
- * @param message message to show
- */
-void ProjectSelection::error(const QString& message) {
- QMessageBox dialog(QMessageBox::Critical, "Error", message,
- QMessageBox::Close);
- dialog.exec();
-}
-
-/**
- * Extracts the full filename of a given table.
- *
- * The node is the first column, the path the last.
- *
- * @param table the table from which the filename is taken
- * @param row the row where the filename is
- * @return the full name of the file in the given row
- */
-QString ProjectSelection::fileOfTable(QTableWidget* table, int row) {
- int colPath = table->columnCount() - 1;
- QString file = table->item(row, colPath)->text() + OS_SEPARATOR_STR
- + table->item(row, 0)->text();
- return file;
-}
-/**
- * Opens a file or a directory (project directory).
- */
-void ProjectSelection::open() {
- QString name = ui->lineEditOpen->text();
- if (name.isEmpty())
- error("missing filename/project directory");
- else {
- QFileInfo file(name);
- if (!file.exists())
- error("does not exists: " + name);
- else {
- if (file.isDir())
- m_mainWindow->changeProject(name);
- else
- m_mainWindow->openFile(name);
- close();
- }
- }
-}
-
-/**
- * Selects a directory (project directory) with an open dialog.
- */
-void ProjectSelection::selectDir() {
- QString name = ui->lineEditOpen->text();
- if (name.isEmpty() && m_mainWindow->project() != NULL)
- name = m_mainWindow->project()->path();
- name = QFileDialog::getExistingDirectory(this,
- tr("Select Project Directory"), name);
- if (!name.isEmpty()) {
- ui->lineEditOpen->setText(name);
- open();
- }
-}
-
-/**
- * Selects a file with a file open dialog.
- */
-void ProjectSelection::selectFile() {
- QString name = ui->lineEditOpen->text();
- name = QFileDialog::getOpenFileName(this, tr("Select File"), name);
- if (!name.isEmpty()) {
- ui->lineEditOpen->setText(name);
- open();
- }
-}
-
-/**
- * Handles the filter text change for a given table.
- *
- * @param text the filter text
- * @param table the table which will be filled
- * @param lines the full (unfiltered) table info
- */
-void ProjectSelection::textChanged(const QString& text, QTableWidget* table,
- const QStringList& lines) {
- buildTable(text, lines, table);
- if (table->rowCount() > 0) {
- QString file = fileOfTable(table, 0);
- ui->lineEditOpen->setText(file);
- }
-}
-
-/**
- * Handles the event "text changed" of the last opened files.
- *
- * @param text the new text
- */
-void ProjectSelection::textChangedFilterFiles(const QString& text) {
- textChanged(text, ui->tableWidgetFiles, m_files);
-}
-
-/**
- * Handles the event "text changed" of the last opened projects.
- *
- * @param text the new text
- */
-void ProjectSelection::textChangedFilterProjects(const QString& text) {
- textChanged(text, ui->tableWidgetProjects, m_projects);
-}
+++ /dev/null
-/*
- * projectselection.hpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#ifndef PROJECTSELECTION_HPP
-#define PROJECTSELECTION_HPP
-#include "reditor.hpp"
-#include <QDialog>
-#include <QTableWidget>
-namespace Ui {
-class ProjectSelection;
-}
-class MainWindow;
-class ProjectSelection: public QDialog {
- Q_OBJECT
-
-public:
- explicit ProjectSelection(MainWindow* mainWindow, QWidget *parent = 0);
- ~ProjectSelection();
-
-public slots:
- void open();
- void selectDir();
- void selectFile();
-protected:
- void buildTable(const QString& filter, const QStringList& lines,
- QTableWidget* table);
- void buildTableInfo(ReSettings* settings, const char* key, bool withDate,
- QStringList& tableContent);
- QString fileOfTable(QTableWidget* table, int row);
- void textChanged(const QString& text, QTableWidget* table,
- const QStringList& lines);protected slots:
- void cellEnteredFiles(int row, int col);
- void cellEnteredProjects(int row, int col);
- void textChangedFilterFiles(const QString& text);
- void textChangedFilterProjects(const QString& text);
-private:
- void error(const QString& message);
-private:
- Ui::ProjectSelection *ui;
- MainWindow* m_mainWindow;
- QStringList m_files;
- QStringList m_projects;
-};
-
-#endif // PROJECTSELECTION_HPP
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<ui version="4.0">
- <class>ProjectSelection</class>
- <widget class="QDialog" name="ProjectSelection">
- <property name="geometry">
- <rect>
- <x>0</x>
- <y>0</y>
- <width>1034</width>
- <height>703</height>
- </rect>
- </property>
- <property name="windowTitle">
- <string>Dialog</string>
- </property>
- <layout class="QVBoxLayout" name="verticalLayout_3">
- <item>
- <widget class="QGroupBox" name="groupBox">
- <property name="maximumSize">
- <size>
- <width>16777215</width>
- <height>75</height>
- </size>
- </property>
- <property name="title">
- <string>Open new file/project:</string>
- </property>
- <layout class="QHBoxLayout" name="horizontalLayout_4">
- <item>
- <widget class="QLineEdit" name="lineEditOpen">
- <property name="toolTip">
- <string>Name of the file/project directory to open</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QPushButton" name="pushButtonOpen">
- <property name="toolTip">
- <string>Opens the file/project (Control-O)</string>
- </property>
- <property name="text">
- <string>Open</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="toolButtonSelectFile">
- <property name="toolTip">
- <string>Selects a file wit a file open dialog box (Control-Shift-F)</string>
- </property>
- <property name="text">
- <string>...</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+Shift+F</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QToolButton" name="toolButtonSelectProject">
- <property name="toolTip">
- <string>Select a project directory with a directory open box (Control-Shift-P)</string>
- </property>
- <property name="text">
- <string>...</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+Shift+P</string>
- </property>
- </widget>
- </item>
- </layout>
- </widget>
- </item>
- <item>
- <widget class="QSplitter" name="splitter">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="handleWidth">
- <number>3</number>
- </property>
- <widget class="QWidget" name="layoutWidget">
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QLabel" name="label">
- <property name="text">
- <string>Last opened files:</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLineEdit" name="lineEditFilterLastFile">
- <property name="toolTip">
- <string>Filter for last opened files.
-Use wildcards: '*' (any string) and '?' (any character)</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QTableWidget" name="tableWidgetFiles">
- <property name="mouseTracking">
- <bool>true</bool>
- </property>
- <property name="editTriggers">
- <set>QAbstractItemView::NoEditTriggers</set>
- </property>
- <property name="columnCount">
- <number>3</number>
- </property>
- <attribute name="horizontalHeaderMinimumSectionSize">
- <number>1</number>
- </attribute>
- <attribute name="horizontalHeaderStretchLastSection">
- <bool>true</bool>
- </attribute>
- <column>
- <property name="text">
- <string>File</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Modified</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Directory</string>
- </property>
- </column>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_5" stretch=""/>
- </item>
- </layout>
- </widget>
- <widget class="QWidget" name="layoutWidget">
- <layout class="QVBoxLayout" name="verticalLayout_2">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Last opened projects:</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_2">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>40</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QLineEdit" name="lineEditFilterLastProjects">
- <property name="toolTip">
- <string>Filter for last opened projects.
-Use wildcards: '*' (any string) and '?' (any character)</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="QTableWidget" name="tableWidgetProjects">
- <property name="mouseTracking">
- <bool>true</bool>
- </property>
- <property name="columnCount">
- <number>2</number>
- </property>
- <attribute name="horizontalHeaderStretchLastSection">
- <bool>true</bool>
- </attribute>
- <attribute name="verticalHeaderStretchLastSection">
- <bool>false</bool>
- </attribute>
- <column>
- <property name="text">
- <string>Name</string>
- </property>
- </column>
- <column>
- <property name="text">
- <string>Parent</string>
- </property>
- </column>
- </widget>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_7"/>
- </item>
- </layout>
- </widget>
- </widget>
- </item>
- </layout>
- </widget>
- <resources/>
- <connections/>
-</ui>
+++ /dev/null
-/*
- * reditor.hpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#ifndef REDITOR_HPP
-#define REDITOR_HPP
-#include <QDockWidget>
-#include "base/rebase.hpp"
-#include "gui/regui.hpp"
-#include "workspace.hpp"
-#include "project.hpp"
-#include "mainwindow.hpp"
-#include "projectselection.hpp"
-#endif // REDITOR_HPP
-
+++ /dev/null
-#-------------------------------------------------
-#
-# Project created by QtCreator 2015-06-03T20:56:48
-#
-#-------------------------------------------------
-
-QT += core gui
-
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-
-TARGET = ReEditor
-TEMPLATE = app
-
-INCLUDEPATH += ../..
-
-SOURCES += \
- ../../gui/ReEdit.cpp \
- ../../gui/ReStateStorage.cpp \
- ../../gui/ReSettings.cpp \
- ../../base/ReFile.cpp \
- ../../gui/ReFileTree.cpp \
- mainwindow.cpp \
- ../../base/ReLogger.cpp \
- ../../base/ReQStringUtils.cpp \
- ../../base/ReFileUtils.cpp \
- ../../base/ReException.cpp \
- projectselection.cpp \
- workspace.cpp \
- project.cpp \
- main.cpp
-
-
-HEADERS += mainwindow.hpp \
- ../../base/rebase.hpp \
- ../../gui/regui.hpp \
- ../../gui/ReEdit.hpp \
- ../../base/ReStringUtils.hpp \
- ../../base/ReQStringUtils.hpp \
- ../../base/ReException.hpp \
- projectselection.hpp \
- workspace.hpp \
- project.hpp \
- reditor.hpp \
- storage.hpp
-
-FORMS += mainwindow.ui \
- projectselection.ui
-
-RESOURCES += \
- editor.qrc
+++ /dev/null
-/*
- * workspace.cpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#include "reditor.hpp"
-
-const char* Workspace::KEY_HISTORY_FILES = "files";
-const char* Workspace::KEY_HISTORY_PROJECTS = "projecs";
-
-/**
- * Constructor.
- *
- * @param path the directory containing the configuration
- * @param logger the logger
- */
-Workspace::Workspace(const QString& path, ReLogger* logger) :
- ReSettings(path, ".reditor.ws", logger) {
- insertProperty(
- new ReProperty("editor.tabwidth", QObject::tr("Tabulator width"),
- QObject::tr("Maximal length of the gap displaying a tabulator"),
- "4", PT_INT, "[1,16]"));
- insertProperty(
- new ReProperty("history.max_projects",
- QObject::tr("Maximal project entries"),
- QObject::tr(
- "Maximal number of projects in the 'last opened projects'"),
- "20", PT_INT, "[1,100]"));
- insertProperty(
- new ReProperty("history.max_files", QObject::tr("Maximal file entries"),
- QObject::tr("Maximal number of files in the 'last opened files'"),
- "20", PT_INT, "[1,100]"));
-}
-
+++ /dev/null
-/*
- * workspace.hpp
- *
- * License: Public Domain
- * You can use and modify this file without any restriction.
- * Do what you want.
- * No warranties and disclaimer of any damages.
- * You also can use this license: http://www.wtfpl.net
- * The latest sources: https://github.com/republib
- */
-
-#ifndef WORKSPACE_HPP
-#define WORKSPACE_HPP
-
-class Workspace: public ReSettings {
-public:
- static const char* KEY_HISTORY_FILES;
- static const char* KEY_HISTORY_PROJECTS;
-public:
- Workspace(const QString& path, ReLogger* logger);
-};
-
-#endif // WORKSPACE_HPP
--- /dev/null
+<RCC>
+ <qresource prefix="/main">
+ <file>icons/action_go.png</file>
+ <file>icons/action_paste.png</file>
+ <file>icons/arrow_turn_left.png</file>
+ <file>icons/bullet_go.png</file>
+ <file>icons/cog_edit.png</file>
+ <file>icons/database_save.png</file>
+ <file>icons/disk.png</file>
+ <file>icons/door_in.png</file>
+ <file>icons/eye.png</file>
+ <file>icons/folder_find.png</file>
+ <file>icons/folder_go.png</file>
+ <file>icons/folder_magnify.png</file>
+ <file>icons/folder.png</file>
+ <file>icons/layout_add.png</file>
+ <file>icons/paste_plain.png</file>
+ <file>icons/resultset_next.png</file>
+ <file>icons/sitemap_color.png</file>
+ <file>icons/table.png</file>
+ <file>icons/tables.png</file>
+ <file>icons/wand.png</file>
+ <file>icons/wrench.png</file>
+ <file>icons/folder_page.png</file>
+ </qresource>
+</RCC>
--- /dev/null
+/*
+ * main.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+#include "reditor.hpp"
+#include <QApplication>
+
+int main(int argc, char *argv[]) {
+ const char* workspace = NULL;
+ const char* project = NULL;
+ for (int ix = 1; ix < argc; ix++) {
+ if (argv[ix][0] == '-') {
+ if (strcmp(argv[ix], "-w") == 0 && ix < argc - 1) {
+ workspace = argv[++ix];
+ } else if (strncmp(argv[ix], "--workspace=", 12) == 0) {
+ workspace = argv[ix] + 12;
+ } else if (strcmp(argv[ix], "-p") == 0 && ix < argc - 1) {
+ project = argv[++ix];
+ } else if (strncmp(argv[ix], "--project=", 10) == 0) {
+ workspace = argv[ix] + 10;
+ }
+ }
+ }
+ QApplication a(argc, argv);
+ ReLogger logger;
+ ReDebugAppender appender;
+ appender.setAutoDelete(false);
+ logger.addAppender(&appender);
+ MainWindow w(workspace, project, &logger);
+ logger.log(LOG_INFO, 1, "start");
+ w.show();
+
+ return a.exec();
+}
--- /dev/null
+/*
+ * mainwindow.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reditor.hpp"
+#include "ui_mainwindow.h"
+#include <QFileDialog>
+
+MainWindow::MainWindow(const char* workspace, const char* project,
+ ReLogger* logger, QWidget *parent) :
+ QMainWindow(parent),
+ ui(new Ui::MainWindow),
+ m_project(NULL),
+ m_workspace(NULL),
+ m_logger(logger),
+ m_fileTree(NULL),
+ m_dockProjectTree(NULL) {
+ if (workspace == NULL)
+ workspace = QDir::homePath().toUtf8();
+ changeWorkspace(workspace == NULL ? QDir::homePath() : workspace);
+
+ QString proj(project == NULL ? "" : project);
+ if (project == NULL) {
+ QStringList lastProjects;
+ m_workspace->historyAsList("projects", lastProjects);
+ int ix = 0;
+ while (proj.isEmpty() && ix < lastProjects.size()) {
+ QFileInfo dir(lastProjects.at(ix));
+ if (dir.isDir() && dir.isWritable())
+ proj = lastProjects.at(ix);
+ }
+ if (!proj.isEmpty())
+ changeProject(proj);
+ }
+
+ ui->setupUi(this);
+ ReEdit* edit = ui->widget;
+#if defined __linux__
+ m_file = new ReFile("/home/hm/editor.txt", false);
+#else
+ m_file = new ReFile("U:\\ws_cpp\\rplqt\\Doxyfile", false);
+#endif
+ edit->setLines(m_file);
+ edit->setCursorLine(0);
+ connect(ui->actionOpen, SIGNAL(triggered()), this, SLOT(open()));
+ open();
+}
+
+MainWindow::~MainWindow() {
+ delete ui;
+}
+
+/**
+ * Change the current project.
+ *
+ * @param path the directory containing the project data
+ */
+void MainWindow::changeProject(QString path) {
+ delete m_project;
+ if (path.endsWith(OS_SEPARATOR_STR))
+ path.remove(path.size() - 1, 1);
+ m_project = new Project(path, this);
+ int maxEntries = m_workspace->intValue("history.max_projects");
+ m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_PROJECTS, path, ';',
+ maxEntries);
+ if (m_fileTree == NULL) {
+ m_fileTree = new ReFileTree(path, m_logger, this);
+ m_dockProjectTree = new QDockWidget("", this);
+ m_dockProjectTree->setWidget(m_fileTree);
+ addDockWidget(Qt::LeftDockWidgetArea, m_dockProjectTree);
+ }
+ m_fileTree->setPath(path);
+ m_dockProjectTree->setWindowTitle(
+ tr("Project") + " " + ReQStringUtils::nodeOf(path));
+
+}
+
+/**
+ * Change the workspace.
+ *
+ * @param path the directory containing the workspace data
+ */
+void MainWindow::changeWorkspace(const QString& path) {
+ delete m_workspace;
+ m_workspace = new Workspace(path, m_logger);
+}
+
+/**
+ * Calls the file selection dialog.
+ */
+void MainWindow::openFile(const QString& name) {
+ m_file = new ReFile(name, false);
+
+ ReEdit* edit = ui->widget;
+ edit->setLines(m_file);
+ edit->setCursorLine(0);
+ int maxEntries = m_workspace->intValue("history.max_files");
+ m_workspace->addHistoryEntry(Workspace::KEY_HISTORY_FILES, name, ';',
+ maxEntries);
+}
+
+/**
+ * Closes the current project.
+ */
+void MainWindow::closeProject() {
+ delete m_project;
+ m_project = NULL;
+}
+
+/**
+ * Shows the "open project/file dialog".
+ */
+void MainWindow::open() {
+ ProjectSelection dialog(this);
+ dialog.exec();
+}
+ReLogger* MainWindow::logger() const {
+ return m_logger;
+}
+
+/**
+ * Returns the current workspace.
+ *
+ * @return the current workspace
+ */
+Project* MainWindow::project() const {
+ return m_project;
+}
+
+Workspace* MainWindow::workspace() const {
+ return m_workspace;
+}
+
--- /dev/null
+/*
+ * mainwindow.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef MAINWINDOW_HPP
+#define MAINWINDOW_HPP
+
+#include <QMainWindow>
+#ifndef REBASE_HPP
+#include "reditor.hpp"
+#endif
+namespace Ui {
+class MainWindow;
+}
+
+class MainWindow: public QMainWindow {
+ Q_OBJECT
+
+public:
+ explicit MainWindow(const char* workspace, const char* project,
+ ReLogger* logger, QWidget *parent = 0);
+ ~MainWindow();
+ void changeProject(QString path);
+ void changeWorkspace(const QString& path);
+ void closeProject();
+ void openFile(const QString& name);
+ Project* project() const;
+ Workspace* workspace() const;
+ ReLogger* logger() const;
+
+public slots:
+ void open();
+private:
+ Ui::MainWindow *ui;
+ ReFile* m_file;
+ Project* m_project;
+ Workspace* m_workspace;
+ ReLogger* m_logger;
+ ReFileTree* m_fileTree;
+ QDockWidget* m_dockProjectTree;
+};
+
+#endif // MAINWINDOW_HPP
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>MainWindow</class>
+ <widget class="QMainWindow" name="MainWindow">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>803</width>
+ <height>642</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>MainWindow</string>
+ </property>
+ <widget class="QWidget" name="centralWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <widget class="ReEdit" name="widget" native="true"/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QMenuBar" name="menuBar">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>803</width>
+ <height>23</height>
+ </rect>
+ </property>
+ </widget>
+ <widget class="QToolBar" name="mainToolBar">
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ <addaction name="actionOpen"/>
+ <addaction name="actionSave"/>
+ </widget>
+ <widget class="QStatusBar" name="statusBar"/>
+ <widget class="QToolBar" name="toolBar">
+ <property name="windowTitle">
+ <string>toolBar</string>
+ </property>
+ <attribute name="toolBarArea">
+ <enum>TopToolBarArea</enum>
+ </attribute>
+ <attribute name="toolBarBreak">
+ <bool>false</bool>
+ </attribute>
+ </widget>
+ <action name="actionOpen">
+ <property name="icon">
+ <iconset resource="editor.qrc">
+ <normaloff>:/main/icons/table.png</normaloff>:/main/icons/table.png</iconset>
+ </property>
+ <property name="text">
+ <string>Open</string>
+ </property>
+ <property name="toolTip">
+ <string>Open a file</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+O</string>
+ </property>
+ </action>
+ <action name="actionSave">
+ <property name="icon">
+ <iconset resource="editor.qrc">
+ <normaloff>:/main/icons/disk.png</normaloff>:/main/icons/disk.png</iconset>
+ </property>
+ <property name="text">
+ <string>Save</string>
+ </property>
+ <property name="toolTip">
+ <string>Save the file</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+S</string>
+ </property>
+ </action>
+ </widget>
+ <layoutdefault spacing="6" margin="11"/>
+ <customwidgets>
+ <customwidget>
+ <class>ReEdit</class>
+ <extends>QWidget</extends>
+ <header>gui/regui.hpp</header>
+ <container>1</container>
+ </customwidget>
+ </customwidgets>
+ <resources>
+ <include location="editor.qrc"/>
+ </resources>
+ <connections/>
+</ui>
--- /dev/null
+/*
+ * project.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reditor.hpp"
+
+const char* Project::KEY_HISTORY_OPEN_FILES = "openFiles";
+/**
+ * Constructor.
+ *
+ * @param path the directory containing the configuration
+ * @param logger the logger
+ */
+Project::Project(const QString& path, MainWindow* mainWindow) :
+ ReSettings(path, ".reditor.proj", mainWindow->logger()),
+ m_mainWindow(mainWindow) {
+ QString filename = topOfHistory(KEY_HISTORY_OPEN_FILES);
+ QFileInfo info(filename);
+ if (!filename.isEmpty() && info.exists() && !info.isDir()) {
+ m_mainWindow->openFile(filename);
+ }
+}
+
+/**
+ * Opens a file in the project directory.
+ *
+ * @param filename the filename relative to the project directory
+ */
+void Project::openFile(const QString& filename) {
+ QString full = m_path + OS_SEPARATOR_STR + filename;
+ addHistoryEntry(KEY_HISTORY_OPEN_FILES, filename, ';', 1);
+ m_mainWindow->openFile(full);
+}
+
--- /dev/null
+/*
+ * project.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef PROJECT_HPP
+#define PROJECT_HPP
+
+class MainWindow;
+
+class Project: public ReSettings {
+public:
+ static const char* KEY_HISTORY_OPEN_FILES;
+public:
+ Project(const QString& path, MainWindow* mainWindow);
+public:
+ void openFile(const QString& filename);
+
+private:
+ MainWindow* m_mainWindow;
+};
+
+#endif // PROJECT_HPP
--- /dev/null
+/*
+ * projectselection.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reditor.hpp"
+#include "ui_projectselection.h"
+#include <QFileDialog>
+#include <QMessageBox>
+
+/**
+ * Constructor.
+ *
+ * @param parent NULL or the parent
+ * @param mainWindow the main window
+ */
+ProjectSelection::ProjectSelection(MainWindow* mainWindow, QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::ProjectSelection),
+ m_mainWindow(mainWindow) {
+ ui->setupUi(this);
+ connect(ui->toolButtonSelectFile, SIGNAL(clicked()), this,
+ SLOT(selectFile()));
+ connect(ui->toolButtonSelectProject, SIGNAL(clicked()), this,
+ SLOT(selectDir()));
+ connect(ui->pushButtonOpen, SIGNAL(clicked()), this, SLOT(open()));
+ connect(ui->lineEditFilterLastFile, SIGNAL(textChanged(QString)), this,
+ SLOT(textChangedFilterFiles(QString)));
+ connect(ui->tableWidgetFiles, SIGNAL(cellEntered(int,int)), this,
+ SLOT(cellEnteredFiles(int, int)));
+ connect(ui->tableWidgetProjects, SIGNAL(cellEntered(int,int)), this,
+ SLOT(cellEnteredProjects(int, int)));
+ Workspace* workspace = mainWindow->workspace();
+ buildTableInfo(workspace, Workspace::KEY_HISTORY_FILES, true, m_files);
+ buildTableInfo(workspace, Workspace::KEY_HISTORY_PROJECTS, false,
+ m_projects);
+ buildTable("", m_files, ui->tableWidgetFiles);
+ buildTable("", m_projects, ui->tableWidgetProjects);
+}
+
+/**
+ * Destructor.
+ */
+ProjectSelection::~ProjectSelection() {
+ delete ui;
+}
+/**
+ * Handles the event cellEntered for the last opened files.
+ *
+ * @param row the row of the entered cell
+ * @param col the column of the entered cell
+ */
+void ProjectSelection::cellEnteredFiles(int row, int col) {
+ ReUseParameter(col);
+ QString file = fileOfTable(ui->tableWidgetFiles, row);
+ ui->lineEditOpen->setText(file);
+}
+
+/**
+ * Handles the event cellEntered for the last opened projects.
+ *
+ * @param row the row of the entered cell
+ * @param col the column of the entered cell
+ */
+void ProjectSelection::cellEnteredProjects(int row, int col) {
+ ReUseParameter(col);
+ QString file = fileOfTable(ui->tableWidgetProjects, row);
+ ui->lineEditOpen->setText(file);
+}
+
+/**
+ * Builds the table from the table using a filter expression.
+ *
+ * @param filter a filter expression with wildcards '*'
+ * @param lines the full table info
+ * @param table OUT: will be filled with all lines matching the filter
+ */
+void ProjectSelection::buildTable(const QString& filter,
+ const QStringList& lines, QTableWidget* table) {
+ QStringList::const_iterator it;
+ int rowCount = 0;
+ ReMatcher matcher(filter, Qt::CaseInsensitive, true);
+ for (it = lines.cbegin(); it != lines.cend(); ++it) {
+ if (matcher.matches(*it))
+ rowCount++;
+ }
+ table->setRowCount(rowCount);
+ int row = -1;
+ for (it = lines.cbegin(); it != lines.cend(); ++it) {
+ if (matcher.matches(*it)) {
+ row++;
+ QStringList cols = it->split('\t');
+ for (int col = 0; col < cols.size(); col++) {
+ QTableWidgetItem* item = table->item(row, col);
+ if (item != NULL)
+ item->setText(cols.at(col));
+ else {
+ item = new QTableWidgetItem(cols.at(col));
+ table->setItem(row, col, item);
+ }
+ }
+ }
+ }
+}
+
+/**
+ * Build the info for a table (last opened files or last opened projects).
+ *
+ * Note: the table shows a filtered part of this info.
+ *
+ * @param settings the history container
+ * @param key the name of the history entry
+ * @param withDate the file's name is part of the info
+ * @param tableContent OUT: the list containing the table info
+ */
+void ProjectSelection::buildTableInfo(ReSettings* settings, const char* key,
+ bool withDate, QStringList& tableContent) {
+ QStringList files;
+ settings->historyAsList(key, files);
+ QStringList::const_iterator it;
+ for (it = files.cbegin(); it != files.cend(); ++it) {
+ QFileInfo file(*it);
+ if (file.exists()) {
+ QString info = file.baseName();
+ if (withDate)
+ info.append("\t").append(
+ file.lastModified().toString("yyyy.mm.dd/HH:MM:SS"));
+ info.append("\t").append(file.path());
+ tableContent.append(info);
+ }
+ }
+}
+
+/**
+ * Shows an error message.
+ *
+ * @param message message to show
+ */
+void ProjectSelection::error(const QString& message) {
+ QMessageBox dialog(QMessageBox::Critical, "Error", message,
+ QMessageBox::Close);
+ dialog.exec();
+}
+
+/**
+ * Extracts the full filename of a given table.
+ *
+ * The node is the first column, the path the last.
+ *
+ * @param table the table from which the filename is taken
+ * @param row the row where the filename is
+ * @return the full name of the file in the given row
+ */
+QString ProjectSelection::fileOfTable(QTableWidget* table, int row) {
+ int colPath = table->columnCount() - 1;
+ QString file = table->item(row, colPath)->text() + OS_SEPARATOR_STR
+ + table->item(row, 0)->text();
+ return file;
+}
+/**
+ * Opens a file or a directory (project directory).
+ */
+void ProjectSelection::open() {
+ QString name = ui->lineEditOpen->text();
+ if (name.isEmpty())
+ error("missing filename/project directory");
+ else {
+ QFileInfo file(name);
+ if (!file.exists())
+ error("does not exists: " + name);
+ else {
+ if (file.isDir())
+ m_mainWindow->changeProject(name);
+ else
+ m_mainWindow->openFile(name);
+ close();
+ }
+ }
+}
+
+/**
+ * Selects a directory (project directory) with an open dialog.
+ */
+void ProjectSelection::selectDir() {
+ QString name = ui->lineEditOpen->text();
+ if (name.isEmpty() && m_mainWindow->project() != NULL)
+ name = m_mainWindow->project()->path();
+ name = QFileDialog::getExistingDirectory(this,
+ tr("Select Project Directory"), name);
+ if (!name.isEmpty()) {
+ ui->lineEditOpen->setText(name);
+ open();
+ }
+}
+
+/**
+ * Selects a file with a file open dialog.
+ */
+void ProjectSelection::selectFile() {
+ QString name = ui->lineEditOpen->text();
+ name = QFileDialog::getOpenFileName(this, tr("Select File"), name);
+ if (!name.isEmpty()) {
+ ui->lineEditOpen->setText(name);
+ open();
+ }
+}
+
+/**
+ * Handles the filter text change for a given table.
+ *
+ * @param text the filter text
+ * @param table the table which will be filled
+ * @param lines the full (unfiltered) table info
+ */
+void ProjectSelection::textChanged(const QString& text, QTableWidget* table,
+ const QStringList& lines) {
+ buildTable(text, lines, table);
+ if (table->rowCount() > 0) {
+ QString file = fileOfTable(table, 0);
+ ui->lineEditOpen->setText(file);
+ }
+}
+
+/**
+ * Handles the event "text changed" of the last opened files.
+ *
+ * @param text the new text
+ */
+void ProjectSelection::textChangedFilterFiles(const QString& text) {
+ textChanged(text, ui->tableWidgetFiles, m_files);
+}
+
+/**
+ * Handles the event "text changed" of the last opened projects.
+ *
+ * @param text the new text
+ */
+void ProjectSelection::textChangedFilterProjects(const QString& text) {
+ textChanged(text, ui->tableWidgetProjects, m_projects);
+}
--- /dev/null
+/*
+ * projectselection.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef PROJECTSELECTION_HPP
+#define PROJECTSELECTION_HPP
+#include "reditor.hpp"
+#include <QDialog>
+#include <QTableWidget>
+namespace Ui {
+class ProjectSelection;
+}
+class MainWindow;
+class ProjectSelection: public QDialog {
+ Q_OBJECT
+
+public:
+ explicit ProjectSelection(MainWindow* mainWindow, QWidget *parent = 0);
+ ~ProjectSelection();
+
+public slots:
+ void open();
+ void selectDir();
+ void selectFile();
+protected:
+ void buildTable(const QString& filter, const QStringList& lines,
+ QTableWidget* table);
+ void buildTableInfo(ReSettings* settings, const char* key, bool withDate,
+ QStringList& tableContent);
+ QString fileOfTable(QTableWidget* table, int row);
+ void textChanged(const QString& text, QTableWidget* table,
+ const QStringList& lines);protected slots:
+ void cellEnteredFiles(int row, int col);
+ void cellEnteredProjects(int row, int col);
+ void textChangedFilterFiles(const QString& text);
+ void textChangedFilterProjects(const QString& text);
+private:
+ void error(const QString& message);
+private:
+ Ui::ProjectSelection *ui;
+ MainWindow* m_mainWindow;
+ QStringList m_files;
+ QStringList m_projects;
+};
+
+#endif // PROJECTSELECTION_HPP
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>ProjectSelection</class>
+ <widget class="QDialog" name="ProjectSelection">
+ <property name="geometry">
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>1034</width>
+ <height>703</height>
+ </rect>
+ </property>
+ <property name="windowTitle">
+ <string>Dialog</string>
+ </property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="maximumSize">
+ <size>
+ <width>16777215</width>
+ <height>75</height>
+ </size>
+ </property>
+ <property name="title">
+ <string>Open new file/project:</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_4">
+ <item>
+ <widget class="QLineEdit" name="lineEditOpen">
+ <property name="toolTip">
+ <string>Name of the file/project directory to open</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="pushButtonOpen">
+ <property name="toolTip">
+ <string>Opens the file/project (Control-O)</string>
+ </property>
+ <property name="text">
+ <string>Open</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="toolButtonSelectFile">
+ <property name="toolTip">
+ <string>Selects a file wit a file open dialog box (Control-Shift-F)</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+F</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QToolButton" name="toolButtonSelectProject">
+ <property name="toolTip">
+ <string>Select a project directory with a directory open box (Control-Shift-P)</string>
+ </property>
+ <property name="text">
+ <string>...</string>
+ </property>
+ <property name="shortcut">
+ <string>Ctrl+Shift+P</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QSplitter" name="splitter">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="handleWidth">
+ <number>3</number>
+ </property>
+ <widget class="QWidget" name="layoutWidget">
+ <layout class="QVBoxLayout" name="verticalLayout">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <item>
+ <widget class="QLabel" name="label">
+ <property name="text">
+ <string>Last opened files:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditFilterLastFile">
+ <property name="toolTip">
+ <string>Filter for last opened files.
+Use wildcards: '*' (any string) and '?' (any character)</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTableWidget" name="tableWidgetFiles">
+ <property name="mouseTracking">
+ <bool>true</bool>
+ </property>
+ <property name="editTriggers">
+ <set>QAbstractItemView::NoEditTriggers</set>
+ </property>
+ <property name="columnCount">
+ <number>3</number>
+ </property>
+ <attribute name="horizontalHeaderMinimumSectionSize">
+ <number>1</number>
+ </attribute>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>File</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Modified</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Directory</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_5" stretch=""/>
+ </item>
+ </layout>
+ </widget>
+ <widget class="QWidget" name="layoutWidget">
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Last opened projects:</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <spacer name="horizontalSpacer_2">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>40</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item>
+ <widget class="QLineEdit" name="lineEditFilterLastProjects">
+ <property name="toolTip">
+ <string>Filter for last opened projects.
+Use wildcards: '*' (any string) and '?' (any character)</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTableWidget" name="tableWidgetProjects">
+ <property name="mouseTracking">
+ <bool>true</bool>
+ </property>
+ <property name="columnCount">
+ <number>2</number>
+ </property>
+ <attribute name="horizontalHeaderStretchLastSection">
+ <bool>true</bool>
+ </attribute>
+ <attribute name="verticalHeaderStretchLastSection">
+ <bool>false</bool>
+ </attribute>
+ <column>
+ <property name="text">
+ <string>Name</string>
+ </property>
+ </column>
+ <column>
+ <property name="text">
+ <string>Parent</string>
+ </property>
+ </column>
+ </widget>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_7"/>
+ </item>
+ </layout>
+ </widget>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
--- /dev/null
+/*
+ * reditor.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef REDITOR_HPP
+#define REDITOR_HPP
+#include <QDockWidget>
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+#include "workspace.hpp"
+#include "project.hpp"
+#include "mainwindow.hpp"
+#include "projectselection.hpp"
+#endif // REDITOR_HPP
+
--- /dev/null
+#-------------------------------------------------
+#
+# Project created by QtCreator 2015-06-03T20:56:48
+#
+#-------------------------------------------------
+
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+
+TARGET = ReEditor
+TEMPLATE = app
+
+INCLUDEPATH += ../..
+
+SOURCES += \
+ ../../gui/ReEdit.cpp \
+ ../../gui/ReStateStorage.cpp \
+ ../../gui/ReSettings.cpp \
+ ../../base/ReFile.cpp \
+ ../../gui/ReFileTree.cpp \
+ mainwindow.cpp \
+ ../../base/ReLogger.cpp \
+ ../../base/ReQStringUtils.cpp \
+ ../../base/ReFileUtils.cpp \
+ ../../base/ReException.cpp \
+ projectselection.cpp \
+ workspace.cpp \
+ project.cpp \
+ main.cpp
+
+
+HEADERS += mainwindow.hpp \
+ ../../base/rebase.hpp \
+ ../../gui/regui.hpp \
+ ../../gui/ReEdit.hpp \
+ ../../base/ReStringUtils.hpp \
+ ../../base/ReQStringUtils.hpp \
+ ../../base/ReException.hpp \
+ projectselection.hpp \
+ workspace.hpp \
+ project.hpp \
+ reditor.hpp \
+ storage.hpp
+
+FORMS += mainwindow.ui \
+ projectselection.ui
+
+RESOURCES += \
+ editor.qrc
--- /dev/null
+/*
+ * workspace.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#include "reditor.hpp"
+
+const char* Workspace::KEY_HISTORY_FILES = "files";
+const char* Workspace::KEY_HISTORY_PROJECTS = "projecs";
+
+/**
+ * Constructor.
+ *
+ * @param path the directory containing the configuration
+ * @param logger the logger
+ */
+Workspace::Workspace(const QString& path, ReLogger* logger) :
+ ReSettings(path, ".reditor.ws", logger) {
+ insertProperty(
+ new ReProperty("editor.tabwidth", QObject::tr("Tabulator width"),
+ QObject::tr("Maximal length of the gap displaying a tabulator"),
+ "4", PT_INT, "[1,16]"));
+ insertProperty(
+ new ReProperty("history.max_projects",
+ QObject::tr("Maximal project entries"),
+ QObject::tr(
+ "Maximal number of projects in the 'last opened projects'"),
+ "20", PT_INT, "[1,100]"));
+ insertProperty(
+ new ReProperty("history.max_files", QObject::tr("Maximal file entries"),
+ QObject::tr("Maximal number of files in the 'last opened files'"),
+ "20", PT_INT, "[1,100]"));
+}
+
--- /dev/null
+/*
+ * workspace.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use this license: http://www.wtfpl.net
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef WORKSPACE_HPP
+#define WORKSPACE_HPP
+
+class Workspace: public ReSettings {
+public:
+ static const char* KEY_HISTORY_FILES;
+ static const char* KEY_HISTORY_PROJECTS;
+public:
+ Workspace(const QString& path, ReLogger* logger);
+};
+
+#endif // WORKSPACE_HPP