Changed: #1307 Added some features and making little modifications

This commit is contained in:
cemycc 2011-08-04 17:19:17 +03:00
parent 5a599bc7ff
commit 9bca613c47
7 changed files with 681 additions and 613 deletions

View file

@ -80,37 +80,37 @@ void CEditorPhrase::saveAs(QString filename)
setCurrentFile(current_file); setCurrentFile(current_file);
} }
void CEditorPhrase::closeEvent(QCloseEvent *event) void CEditorPhrase::closeEvent(QCloseEvent *event)
{ {
if(isWindowModified()) if(isWindowModified())
{ {
QMessageBox msgBox; QMessageBox msgBox;
msgBox.setText("The document has been modified."); msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?"); msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel); msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save); msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec(); int ret = msgBox.exec();
switch (ret) switch (ret)
{ {
case QMessageBox::Save: case QMessageBox::Save:
save(); save();
event->accept(); event->accept();
close(); close();
break; break;
case QMessageBox::Discard: case QMessageBox::Discard:
event->accept(); event->accept();
close(); close();
break; break;
case QMessageBox::Cancel: case QMessageBox::Cancel:
event->ignore(); event->ignore();
break; break;
default: default:
break; break;
} }
} else { } else {
event->accept(); event->accept();
close(); close();
} }
} }
} }

View file

@ -65,6 +65,7 @@ private Q_SLOTS:
void worksheetEditorChanged(QTableWidgetItem * item); void worksheetEditorChanged(QTableWidgetItem * item);
void insertRow(); void insertRow();
void deleteRow(); void deleteRow();
void contextMenuEvent(QContextMenuEvent *e);
}; };
@ -123,6 +124,7 @@ public:
{ {
QTableWidgetItem* item = new QTableWidgetItem(); QTableWidgetItem* item = new QTableWidgetItem();
m_table->setItem(m_rowID, j, item); m_table->setItem(m_rowID, j, item);
m_table->scrollToBottom();
} }
} }

View file

@ -1,3 +1,4 @@
// Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/> // Translation Manager Plugin - OVQT Plugin <http://dev.ryzom.com/projects/nel/>
// Copyright (C) 2010 Winch Gate Property Limited // Copyright (C) 2010 Winch Gate Property Limited
// Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com> // Copyright (C) 2011 Emanuel Costea <cemycc@gmail.com>
@ -123,16 +124,14 @@ void CMainWindow::createToolbar()
mergeSingleFileAct->setStatusTip(tr("Merge worksheet file from local or remote directory")); mergeSingleFileAct->setStatusTip(tr("Merge worksheet file from local or remote directory"));
connect(mergeSingleFileAct, SIGNAL(triggered()), this, SLOT(mergeSingleFile())); connect(mergeSingleFileAct, SIGNAL(triggered()), this, SLOT(mergeSingleFile()));
// Windows menu // Windows menu
windowMenu = new QMenu(tr("&Windows..."), _ui.toolBar); Core::ICore *core = Core::ICore::instance();
windowMenu->setIcon(QIcon(Core::Constants::ICON_PILL)); Core::IMenuManager *menuManager = core->menuManager();
windowMenu = menuManager->menuBar()->addMenu("Window");
updateWindowsList(); updateWindowsList();
_ui.toolBar->addAction(windowMenu->menuAction());
connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList())); connect(windowMenu, SIGNAL(aboutToShow()), this, SLOT(updateWindowsList()));
// Undo, Redo actions // Undo, Redo actions
// ----------------------------- // -----------------------------
Core::ICore *core = Core::ICore::instance();
Core::IMenuManager *menuManager = core->menuManager();
QAction* undoAction = menuManager->action(Core::Constants::UNDO); QAction* undoAction = menuManager->action(Core::Constants::UNDO);
if (undoAction != 0) if (undoAction != 0)
_ui.toolBar->addAction(undoAction); _ui.toolBar->addAction(undoAction);
@ -147,10 +146,15 @@ void CMainWindow::updateToolbar(QMdiSubWindow *window)
if(_ui.mdiArea->subWindowList().size() > 0) if(_ui.mdiArea->subWindowList().size() > 0)
if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor if(QString(window->widget()->metaObject()->className()) == "QTableWidget") // Sheet Editor
{ {
QAction *insertRowAct = windowMenu->addAction("Insert new row"); //setContextMenuPolicy(Qt::ActionsContextMenu);
connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow())); QAction *insertRowAct = new QAction("Insert new row", this);
QAction *deleteRowAct = windowMenu->addAction("Delete row"); connect(insertRowAct, SIGNAL(triggered()), window, SLOT(insertRow()));
//addAction(insertRowAct);
windowMenu->addAction(insertRowAct);
QAction *deleteRowAct = new QAction("Delete row", this);
connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow())); connect(deleteRowAct, SIGNAL(triggered()), window, SLOT(deleteRow()));
//addAction(deleteRowAct);
windowMenu->addAction(deleteRowAct);
} }
} }
@ -167,7 +171,7 @@ void CMainWindow::setActiveSubWindow(QWidget* window)
void CMainWindow::activeSubWindowChanged() void CMainWindow::activeSubWindowChanged()
{ {
//TODO: nothing to be done here atm
} }
void CMainWindow::updateWindowsList() void CMainWindow::updateWindowsList()
@ -187,10 +191,11 @@ void CMainWindow::updateWindowsList()
} else { } else {
action_text = tr("%1 %2").arg(i + 1).arg(window_file); action_text = tr("%1 %2").arg(i + 1).arg(window_file);
} }
QAction *action = windowMenu->addAction(action_text); QAction *action = new QAction(action_text, this);
action->setCheckable(true); action->setCheckable(true);
action->setChecked(subWindows.at(i) == current_window); action->setChecked(subWindows.at(i) == current_window);
connect(action, SIGNAL(triggered()), windowMapper, SLOT(map())); connect(action, SIGNAL(triggered()), windowMapper, SLOT(map()));
windowMenu->addAction(action);
windowMapper->setMapping(action, subWindows.at(i)); windowMapper->setMapping(action, subWindows.at(i));
} }
} }
@ -589,7 +594,35 @@ bool CMainWindow::isPhraseEditor(QString filename)
bool CCoreListener::closeMainWindow() const bool CCoreListener::closeMainWindow() const
{ {
return true; Q_FOREACH(QMdiSubWindow *subWindow, m_MainWindow->_ui.mdiArea->subWindowList())
{
CEditor *currentEditor = qobject_cast<CEditor*>(subWindow);
if(subWindow->isWindowModified())
{
QMessageBox msgBox;
msgBox.setText(tr("The document has been modified ( %1 ).").arg(currentEditor->windowFilePath()));
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch (ret)
{
case QMessageBox::Save:
currentEditor->save();
return true;
break;
case QMessageBox::Discard:
return true;
break;
case QMessageBox::Cancel:
return false;
break;
default:
break;
}
}
}
} }
} /* namespace Plugin */ } /* namespace Plugin */

View file

@ -62,8 +62,9 @@ public:
CMainWindow(QWidget *parent = 0); CMainWindow(QWidget *parent = 0);
virtual ~CMainWindow() {} virtual ~CMainWindow() {}
QUndoStack *m_undoStack; QUndoStack *m_undoStack;
private: public:
Ui::CMainWindow _ui; Ui::CMainWindow _ui;
private:
// actions // actions
QAction *openAct; QAction *openAct;
QAction *saveAct; QAction *saveAct;
@ -111,13 +112,20 @@ class CCoreListener : public Core::ICoreListener
{ {
Q_OBJECT Q_OBJECT
public: public:
CCoreListener(QObject *parent = 0): ICoreListener(parent) {} CCoreListener(CMainWindow* mainWindow, QObject *parent = 0): ICoreListener(parent)
virtual ~CCoreListener() {} {
m_MainWindow = mainWindow;
}
virtual ~CCoreListener() {}
virtual bool closeMainWindow() const; virtual bool closeMainWindow() const;
public:
CMainWindow *m_MainWindow;
}; };
} // namespace Plugin } // namespace Plugin

View file

@ -53,10 +53,12 @@ bool TranslationManagerPlugin::initialize(ExtensionSystem::IPluginManager *plugi
{ {
Q_UNUSED(errorString); Q_UNUSED(errorString);
_plugMan = pluginManager; _plugMan = pluginManager;
// create the mainwindow
CMainWindow *mainWindow = new CMainWindow();
addAutoReleasedObject(new CTranslationManagerSettingsPage(this)); addAutoReleasedObject(new CTranslationManagerSettingsPage(this));
addAutoReleasedObject(new CTranslationManagerContext(this)); addAutoReleasedObject(new CTranslationManagerContext(mainWindow, this));
addAutoReleasedObject(new CCoreListener(this)); addAutoReleasedObject(new CCoreListener(mainWindow, this));
return true; return true;
} }
@ -75,6 +77,8 @@ void TranslationManagerPlugin::extensionsInitialized()
helpMenu->insertAction(aboutQtAction, aboutTManPlugin); helpMenu->insertAction(aboutQtAction, aboutTManPlugin);
} }
void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext) void TranslationManagerPlugin::setNelContext(NLMISC::INelContext *nelContext)
{ {
#ifdef NL_OS_WINDOWS #ifdef NL_OS_WINDOWS

View file

@ -82,9 +82,9 @@ class CTranslationManagerContext: public Core::IContext
{ {
Q_OBJECT Q_OBJECT
public: public:
CTranslationManagerContext(QObject *parent = 0): IContext(parent) CTranslationManagerContext(CMainWindow* mainWindow, QObject *parent = 0): IContext(parent)
{ {
m_MainWindow = new CMainWindow(); m_MainWindow = mainWindow;
} }
virtual ~CTranslationManagerContext() {} virtual ~CTranslationManagerContext() {}