summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-05-21 19:59:39 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-05-21 19:59:39 +0000
commitc2d90a8019125dc260db1882ebc292e4e52f3969 (patch)
tree1ec02bf2731e7dde2a0405d1716c2e179b78cbce
parentfa85318e91ea9bbe4638092767b3b8e0ea64f57c (diff)
downloadsigen-c2d90a8019125dc260db1882ebc292e4e52f3969.tar.gz
sigen-c2d90a8019125dc260db1882ebc292e4e52f3969.tar.xz
sigen-c2d90a8019125dc260db1882ebc292e4e52f3969.zip
[FIX] Closing PokeMods works now
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@162 6ecfd1a5-f3ed-3746-8530-beee90d26b22
-rw-r--r--Changelog7
-rw-r--r--pokemodr/PokeModrUI.cpp149
-rw-r--r--pokemodr/PokeModrUI.h7
-rw-r--r--pokemodr/PokemodTree.cpp49
-rw-r--r--pokemodr/PokemodTree.h11
5 files changed, 139 insertions, 84 deletions
diff --git a/Changelog b/Changelog
index 9e395586..4eee2ddf 100644
--- a/Changelog
+++ b/Changelog
@@ -1,4 +1,11 @@
-----------------
+Rev: 162
+Date: 21 May 2008
+User: MathStuf
+-----------------
+[FIX] Closing PokeMods works now
+
+-----------------
Rev: 161
Date: 21 May 2008
User: MathStuf
diff --git a/pokemodr/PokeModrUI.cpp b/pokemodr/PokeModrUI.cpp
index bfe9c1a9..a673d2e8 100644
--- a/pokemodr/PokeModrUI.cpp
+++ b/pokemodr/PokeModrUI.cpp
@@ -59,6 +59,7 @@ PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* paren
menuFile->addAction(KStandardAction::openNew(this, SLOT(newPokemod()), menuFile));
menuFile->addAction(KStandardAction::open(this, SLOT(openPokemod()), menuFile));
menuFile->addAction(KStandardAction::openRecent(this, SLOT(openPokemod(const KUrl&)), menuFile));
+ menuFile->addAction(KStandardAction::close(this, SLOT(closePokemod()), menuFile));
menuFile->addSeparator();
menuFile->addAction(KStandardAction::save(this, SLOT(savePokemod()), menuFile));
menuFile->addAction(KStandardAction::saveAs(this, SLOT(saveAsPokemod()), menuFile));
@@ -91,6 +92,7 @@ PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* paren
toolbar->addAction(KStandardAction::openNew(this, SLOT(newPokemod()), toolbar));
toolbar->addAction(KStandardAction::open(this, SLOT(openPokemod()), toolbar));
toolbar->addAction(KStandardAction::openRecent(this, SLOT(openPokemod(const KUrl&)), toolbar));
+ toolbar->addAction(KStandardAction::close(this, SLOT(closePokemod()), toolbar));
toolbar->addSeparator();
toolbar->addAction(KStandardAction::save(this, SLOT(savePokemod()), toolbar));
toolbar->addAction(KStandardAction::saveAs(this, SLOT(saveAsPokemod()), toolbar));
@@ -114,7 +116,6 @@ PokeModrUI::PokeModrUI(KConfigGroup config, KConfigGroup history, QWidget* paren
toolbar->addAction(KStandardAction::quit(this, SLOT(quit()), toolbar));
addToolBar(toolbar);
splitter->setSizes(QList<int>() << config.readEntry("treeWidth", 100) << config.readEntry("panelWidth", 100));
- treePokemod->setModel(new PokemodTreeModel(treePokemod));
connect(buttonApply, SIGNAL(clicked()), this, SLOT(update()));
KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
if (args)
@@ -153,6 +154,12 @@ void PokeModrUI::setChangedTitle(const bool changed)
setWindowTitle(QString::fromUtf8("%1%2 - PokéModr").arg(treePokemod->description(treePokemod->currentIndex()), changed ? "*" : ""));
}
+void PokeModrUI::setDirty(const bool dirty)
+{
+ const Pokemod* pokemod = static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod());
+ treePokemod->setDirty(pokemod, dirty);
+}
+
void PokeModrUI::newPokemod()
{
treePokemod->addPokemod(new Pokemod());
@@ -218,96 +225,94 @@ bool PokeModrUI::openPokemod(const QString& path)
void PokeModrUI::savePokemod()
{
- // TODO: safer way of doing this?
- const Pokemod* pokemod = static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod());
- KUrl url = treePokemod->url(pokemod);
- if (url.isEmpty())
- saveAsPokemod();
- else
- savePokemod(url);
+ const Pokemod* pokemod = currentPokemod();
+ if (pokemod)
+ {
+ KUrl url = treePokemod->url(pokemod);
+ if (url.isEmpty())
+ saveAsPokemod();
+ else
+ savePokemod(url);
+ }
}
void PokeModrUI::saveAsPokemod()
{
- // TODO: safer way of doing this?
- Pokemod* pokemod = const_cast<Pokemod*>(static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod()));
- KUrl url = KFileDialog::getSaveUrl(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this, QString::fromUtf8("Open PokéMod"));
- if (!url.isEmpty())
+ const Pokemod* pokemod = currentPokemod();
+ if (pokemod)
{
- if (savePokemod(url))
- treePokemod->setUrl(pokemod, url);
+ KUrl url = KFileDialog::getSaveUrl(KUrl("kfiledialog:///pokemod"), QString::fromUtf8("*.pmod|PokéMod files"), this, QString::fromUtf8("Open PokéMod"));
+ if (!url.isEmpty())
+ {
+ if (savePokemod(url))
+ treePokemod->setUrl(pokemod, url);
+ }
}
}
bool PokeModrUI::savePokemod(const KUrl& url)
{
- const Pokemod* pokemod = static_cast<const Pokemod*>(static_cast<Object*>(treePokemod->currentIndex().internalPointer())->pokemod());
- if (url.isLocalFile())
+ const Pokemod* pokemod = currentPokemod();
+ if (pokemod)
{
- QFile file(url.path());
- if (file.open(QIODevice::ReadWrite))
+ if (url.isLocalFile())
{
- file.write(Object::xml(pokemod).toByteArray());
- file.close();
- return true;
+ QFile file(url.path());
+ if (file.open(QIODevice::ReadWrite))
+ {
+ file.write(Object::xml(pokemod).toByteArray());
+ file.close();
+ return true;
+ }
+ else
+ KMessageBox::error(this, QString::fromUtf8("Error saving the PokéMod!"), "Save error");
}
else
- KMessageBox::error(this, QString::fromUtf8("Error saving the PokéMod!"), "Save error");
- }
- else
- {
- KTemporaryFile temp;
- if (temp.open())
{
- temp.write(Object::xml(pokemod).toByteArray());
- if (KIO::NetAccess::upload(temp.fileName(), url, this))
- return true;
+ KTemporaryFile temp;
+ if (temp.open())
+ {
+ temp.write(Object::xml(pokemod).toByteArray());
+ if (KIO::NetAccess::upload(temp.fileName(), url, this))
+ return true;
+ else
+ KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
+ }
else
- KMessageBox::error(this, KIO::NetAccess::lastErrorString(), "KIO Error");
+ KMessageBox::error(this, QString::fromUtf8("Error saving the PokéMod!"), "Save error");
}
- else
- KMessageBox::error(this, QString::fromUtf8("Error saving the PokéMod!"), "Save error");
}
return false;
}
-void PokeModrUI::closePokeMod()
+void PokeModrUI::closePokemod()
+{
+ closePokemod(currentPokemod());
+}
+
+void PokeModrUI::closePokemod(const Pokemod* pokemod)
{
- // TODO: Close the Pokemod with the current editor open
-// if (formPanel->widget())
-// {
-// ObjectUI* o = static_cast<ObjectUI*>(formPanel->widget());
-// const Pokemod* p = o->original()->pokemod();
-// if (!o->close())
-// return;
-// switch (KMessageBox::questionYesNoCancel(this, "You have unsaved changes, would you like to save them?", "Unsaved PokéMod"))
-// {
-// case KMessageBox::Yes:
-// on_actionSave_triggered();
-// case KMessageBox::No:
-// break;
-// case KMessageBox::Cancel:
-// return;
-// }
-// for (QMutableListIterator<Pokemod*> i(m_pokemods); i.hasNext(); i.next())
-// {
-// if (i.value() == p)
-// {
-// i.remove();
-// break;
-// }
-// }
-// delete p;
-// }
+ if (pokemod)
+ {
+ if (treePokemod->dirty(pokemod))
+ {
+ switch (KMessageBox::questionYesNoCancel(this, "You have unsaved changes, would you like to save them?", QString::fromUtf8("Unsaved PokéMod")))
+ {
+ case KMessageBox::Yes:
+ savePokemod();
+ case KMessageBox::No:
+ break;
+ case KMessageBox::Cancel:
+ return;
+ }
+ }
+ treePokemod->deletePokemod(currentPokemod());
+ }
}
void PokeModrUI::quit()
{
- // TODO: clean up the tree
-// while (m_pokemods.size())
-// closePokeMod();
-// if (m_clipboard)
-// delete m_clipboard;
+ // TODO: close all pokemods and cancel if any are left open
close();
}
@@ -360,6 +365,8 @@ void PokeModrUI::on_treePokemod_clicked(const QModelIndex& index)
connect(widget, SIGNAL(changed(bool)), this, SLOT(setChangedTitle(bool)));
connect(widget, SIGNAL(changed(bool)), boxButtons, SLOT(setEnabled(bool)));
connect(buttonApply, SIGNAL(clicked()), widget, SLOT(apply()));
+ // TODO: set as dirty
+// connect(buttonApply, SIGNAL(clicked(bool)), this, SLOT(setDirty()));
connect(buttonDiscard, SIGNAL(clicked()), widget, SLOT(discard()));
setChangedTitle(false);
formPanel->setWidget(widget);
@@ -373,3 +380,15 @@ void PokeModrUI::on_treePokemod_customContextMenuRequested(const QPoint& positio
if (menu)
menu->popup(mapToGlobal(position));
}
+
+const Pokemod* PokeModrUI::currentPokemod() const
+{
+ QModelIndex index = treePokemod->currentIndex();
+ if (index.isValid())
+ {
+ const Object* object = static_cast<BaseModel*>(index.internalPointer())->object();
+ if (object)
+ return static_cast<const Pokemod*>(object->pokemod());
+ }
+ return NULL;
+}
diff --git a/pokemodr/PokeModrUI.h b/pokemodr/PokeModrUI.h
index 41298479..5c5a346f 100644
--- a/pokemodr/PokeModrUI.h
+++ b/pokemodr/PokeModrUI.h
@@ -48,6 +48,8 @@ class PokeModrUI : public KMainWindow, private Ui::formPokeModr
void setChangedTitle(const bool changed);
+ void setDirty(const bool dirty = true);
+
void newPokemod();
void openPokemod();
bool openPokemod(const KUrl& url);
@@ -55,7 +57,8 @@ class PokeModrUI : public KMainWindow, private Ui::formPokeModr
void savePokemod();
void saveAsPokemod();
bool savePokemod(const KUrl& url);
- void closePokeMod();
+ void closePokemod();
+ void closePokemod(const Pokemod* pokemod);
void quit();
void cutObject();
void copyObject();
@@ -65,6 +68,8 @@ class PokeModrUI : public KMainWindow, private Ui::formPokeModr
void on_treePokemod_clicked(const QModelIndex& index);
void on_treePokemod_customContextMenuRequested(const QPoint& position);
private:
+ const Pokemod* currentPokemod() const;
+
KConfigGroup m_config;
KRecentFilesAction* m_recent;
QDomDocument m_clipboard;
diff --git a/pokemodr/PokemodTree.cpp b/pokemodr/PokemodTree.cpp
index fee1d26e..9c38663b 100644
--- a/pokemodr/PokemodTree.cpp
+++ b/pokemodr/PokemodTree.cpp
@@ -32,6 +32,8 @@ PokemodTree::PokemodTree(QWidget* parent) :
QTreeView(parent)
{
header()->hide();
+ setModel(new PokemodTreeModel(this));
+ setRootIndex(model()->index(-1, 0, QModelIndex()));
}
QString PokemodTree::description(const QModelIndex& index)
@@ -67,32 +69,49 @@ void PokemodTree::paste(const QModelIndex& index, const QDomDocument& data)
model()->setData(index, data.toString(), BaseModel::XmlRole);
}
-KUrl PokemodTree::url(const Pokemod* pokemod) const
+void PokemodTree::addPokemod(Pokemod* pokemod)
{
- if (m_urls.contains(pokemod))
- return m_urls[pokemod];
- return KUrl();
+ static_cast<PokemodTreeModel*>(model())->addPokemod(pokemod);
+ m_pokemods[pokemod] = QPair<KUrl, bool>(KUrl(), false);
}
-void PokemodTree::setUrl(Pokemod* pokemod, const KUrl& url)
+void PokemodTree::addPokemod(Pokemod* pokemod, const KUrl& url)
{
- m_urls[pokemod] = url;
+ static_cast<PokemodTreeModel*>(model())->addPokemod(pokemod);
+ m_pokemods[pokemod] = QPair<KUrl, bool>(url, false);
}
-void PokemodTree::addPokemod(Pokemod* pokemod)
+void PokemodTree::deletePokemod(const Pokemod* pokemod)
{
- static_cast<PokemodTreeModel*>(model())->addPokemod(pokemod);
- m_urls[pokemod] = "";
+ if (m_pokemods.contains(pokemod))
+ {
+ static_cast<PokemodTreeModel*>(model())->deletePokemod(pokemod);
+ m_pokemods.remove(pokemod);
+ }
}
-void PokemodTree::addPokemod(Pokemod* pokemod, const KUrl& url)
+KUrl PokemodTree::url(const Pokemod* pokemod) const
{
- static_cast<PokemodTreeModel*>(model())->addPokemod(pokemod);
- m_urls[pokemod] = url;
+ if (m_pokemods.contains(pokemod))
+ return m_pokemods[pokemod].first;
+ return KUrl();
}
-void PokemodTree::deletePokemod(const Pokemod* pokemod)
+void PokemodTree::setUrl(const Pokemod* pokemod, const KUrl& url)
+{
+ if (m_pokemods.contains(pokemod))
+ m_pokemods[pokemod] = QPair<KUrl, bool>(url, false);
+}
+
+bool PokemodTree::dirty(const Pokemod* pokemod) const
+{
+ if (m_pokemods.contains(pokemod))
+ return m_pokemods[pokemod].second;
+ return false;
+}
+
+void PokemodTree::setDirty(const Pokemod* pokemod, const bool dirty)
{
- static_cast<PokemodTreeModel*>(model())->deletePokemod(pokemod);
- m_urls.remove(pokemod);
+ if (m_pokemods.contains(pokemod))
+ m_pokemods[pokemod].second = dirty;
}
diff --git a/pokemodr/PokemodTree.h b/pokemodr/PokemodTree.h
index bf2f4331..6cf8bb4f 100644
--- a/pokemodr/PokemodTree.h
+++ b/pokemodr/PokemodTree.h
@@ -46,13 +46,18 @@ class PokemodTree : public QTreeView
QDomDocument copy(const QModelIndex& index);
void paste(const QModelIndex& index, const QDomDocument& data);
- KUrl url(const Pokemod* pokemod) const;
- void setUrl(Pokemod* pokemod, const KUrl& url);
void addPokemod(Pokemod* pokemod);
void addPokemod(Pokemod* pokemod, const KUrl& url);
void deletePokemod(const Pokemod* pokemod);
+ void deleteAllPokemods();
+
+ KUrl url(const Pokemod* pokemod) const;
+ void setUrl(const Pokemod* pokemod, const KUrl& url);
+
+ bool dirty(const Pokemod* pokemod) const;
+ void setDirty(const Pokemod*, const bool dirty);
private:
- QMap<const Pokemod*, KUrl> m_urls;
+ QMap<const Pokemod*, QPair<KUrl, bool> > m_pokemods;
};
#endif