EVT_TOOL_RANGE(ID_PREVIEW, ID_EXIT, EditorFrame::OnToolbar)
EVT_MENU_RANGE(ID_NEWDIALOG, ID_NEWSYBNODE + 1000, EditorFrame::OnNewNode)
EVT_MENU_RANGE(ID_CUT, ID_COPY, EditorFrame::OnClipboardAction)
+ EVT_CLOSE(EditorFrame::OnCloseWindow)
END_EVENT_TABLE()
ms_Instance = this;
m_Clipboard = NULL;
+ m_Modified = FALSE;
wxConfigBase *cfg = wxConfigBase::Get();
void EditorFrame::LoadFile(const wxString& filename)
{
+ if (!AskToSave()) return;
+
delete m_Resource;
m_FileName = "";
m_Resource = new wxXmlDocument;
+ m_Modified = FALSE;
if (!m_Resource->Load(filename))
{
{
m_FileName = filename;
RefreshTree();
- SetTitle("wxrcedit - " + wxFileNameFromPath(m_FileName));
}
+ RefreshTitle();
}
void EditorFrame::SaveFile(const wxString& filename)
{
m_FileName = filename;
- SetTitle("wxrcedit - " + wxFileNameFromPath(m_FileName));
if (!m_Resource->Save(filename, wxXML_IO_LIBXML))
- wxLogError("Error saving " + filename);
+ wxLogError(_("Error saving ") + filename);
+ else
+ m_Modified = FALSE;
+
+ RefreshTitle();
}
void EditorFrame::NewFile()
{
+ if (!AskToSave()) return;
+
delete m_Resource;
m_FileName = "";
m_Resource = new wxXmlDocument;
- m_Resource->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, "resource"));
+ m_Resource->SetRoot(new wxXmlNode(wxXML_ELEMENT_NODE, _("resource")));
+ m_Modified = FALSE;
RefreshTree();
- SetTitle("unnamed");
+ RefreshTitle();
+}
+
+
+
+void EditorFrame::RefreshTitle()
+{
+ wxString s;
+ if (m_Modified) s << _T("* ");
+ s << _("wxrcedit");
+ if (!m_FileName)
+ s << _T(" - ") << wxFileNameFromPath(m_FileName);
+ SetTitle(s);
}
int icon = NodeHandler::Find(m_SelectedNode)->GetTreeIcon(m_SelectedNode);
m_TreeCtrl->SetItemImage(sel, icon);
}
+
+ if (!m_Modified)
+ {
+ m_Modified = TRUE;
+ RefreshTitle();
+ }
+
+ PreviewFrame::Get()->MakeDirty();
}
case ID_OPEN :
{
+ wxString cwd = wxGetCwd(); // workaround for 2.2
wxString name = wxFileSelector(_("Open XML resource"), _T(""), _T(""), _T(""), _("XML resources (*.xrc)|*.xrc"), wxOPEN | wxFILE_MUST_EXIST);
+ wxSetWorkingDirectory(cwd);
if (!name.IsEmpty())
LoadFile(name);
break;
case ID_SAVEAS :
{
+ wxString cwd = wxGetCwd(); // workaround for 2.2
wxString name = wxFileSelector(_("Save as"), _T(""), m_FileName, _T(""), _("XML resources (*.xrc)|*.xrc"), wxSAVE | wxOVERWRITE_PROMPT);
+ wxSetWorkingDirectory(cwd);
if (!name.IsEmpty())
SaveFile((m_FileName = name));
break;
}
}
+
+
+
+bool EditorFrame::AskToSave()
+ // asks the user to save current document (if modified)
+ // returns FALSE if user cancelled the action, TRUE of he choosed
+ // 'yes' or 'no'
+{
+ if (!m_Modified) return TRUE;
+
+ int res = wxMessageBox(_("File modified. Do you want to save changes?"), _("Save changes"),
+ wxYES_NO | wxCANCEL | wxCENTRE | wxICON_QUESTION);
+ if (res == wxYES)
+ SaveFile(m_FileName);
+ return (res != wxCANCEL);
+}
+
+
+
+void EditorFrame::OnCloseWindow(wxCloseEvent&)
+{
+ if (!AskToSave()) return;
+ Destroy();
+}
wxString GetFileName() { return m_FileName; }
void RefreshTree();
+ void RefreshTitle();
bool SelectNode(wxXmlNode *node, wxTreeItemId *root = NULL);
wxTreeItemId CreateTreeNode(wxTreeCtrl *treectrl, wxTreeItemId parent, wxXmlNode *node);
wxString m_FileName;
wxXmlDocument *m_Resource;
+
+ bool m_Modified;
+
+ bool AskToSave();
+ void DeleteSelectedNode();
DECLARE_EVENT_TABLE()
void OnTreeSel(wxTreeEvent& event);
void OnNewNode(wxCommandEvent& event);
void OnRightClickTree(wxPoint pos);
void OnClipboardAction(wxCommandEvent& event);
-
- void DeleteSelectedNode();
+ void OnCloseWindow(wxCloseEvent&);
};
void PropEditCtrlChoice::OnChoice(wxCommandEvent& event)
{
- if (CanSave()) WriteValue();
+ if (CanSave())
+ {
+ WriteValue();
+ EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
+ }
}
}
+
+
+
+
+
+
+wxString PropEditCtrlFile::GetFileTypes()
+{
+ return m_PropInfo->MoreInfo;
+}
+
+
+
+void PropEditCtrlFile::OnDetails()
+{
+ wxString txt = m_TextCtrl->GetValue();
+ txt = wxPathOnly(EditorFrame::Get()->GetFileName()) + _T("/") + txt;
+ wxString name = wxFileSelector(_("Choose file"),
+ wxPathOnly(txt),
+ wxFileNameFromPath(txt),
+ _T(""),
+ GetFileTypes(),
+ wxOPEN | wxFILE_MUST_EXIST);
+ if (!name) return;
+
+ // compute relative path:
+ wxArrayString axrc, afile;
+ wxStringTokenizer tkn;
+ tkn.SetString(name, _T("/\\"));
+ while (tkn.HasMoreTokens()) afile.Add(tkn.GetNextToken());
+ tkn.SetString(EditorFrame::Get()->GetFileName(), _T("/\\"));
+ while (tkn.HasMoreTokens()) axrc.Add(tkn.GetNextToken());
+
+ if (afile.GetCount() == 0 || axrc.GetCount() == 0)
+ txt = name;
+ else
+ {
+ while (axrc[0] == afile[0])
+ {
+ afile.Remove(0u);
+ axrc.Remove(0u);
+ }
+ size_t i;
+ txt.Empty();
+ for (i = 0; i < axrc.GetCount()-1/*w/o filename*/; i++) txt << _T("../");
+ for (i = 0; i < afile.GetCount(); i++) txt << afile[i] << _T("/");
+ txt.RemoveLast();
+ }
+
+ m_TextCtrl->SetValue(txt);
+ WriteValue();
+}
+
+
+
+wxString PropEditCtrlImageFile::GetFileTypes()
+{
+ return _("GIF files (*.gif)|*.gif|"
+ "JPEG files (*.jpg)|*.jpg|"
+ "PNG files (*.png)|*.png|"
+ "BMP files (*.bmp)|*.bmp|"
+ "All files (*)|*");
+}
+class PropEditCtrlFile : public PropEditCtrlTxt
+{
+ public:
+ PropEditCtrlFile(PropertiesFrame *propFrame)
+ : PropEditCtrlTxt(propFrame) {}
+ virtual bool HasDetails() { return TRUE; }
+ virtual void OnDetails();
+
+ virtual wxString GetFileTypes();
+};
+
+
+class PropEditCtrlImageFile : public PropEditCtrlFile
+{
+ public:
+ PropEditCtrlImageFile(PropertiesFrame *propFrame)
+ : PropEditCtrlFile(propFrame) {}
+
+ virtual wxString GetFileTypes();
+};
#endif
void PropEditCtrlTxt::OnText(wxCommandEvent& event)
{
- if (CanSave()) WriteValue();
+ if (CanSave())
+ {
+ WriteValue();
+ EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
+ }
}
void PropEditCtrlBool::OnChoice(wxCommandEvent& event)
{
- if (CanSave()) WriteValue();
+ if (CanSave())
+ {
+ WriteValue();
+ EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
+ }
}
if (!s) return;
m_TextCtrl->SetValue(s);
WriteValue();
+ EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
}
PreviewFrame::PreviewFrame()
: wxFrame(NULL, -1, _("Preview"))
{
+ m_Dirty = FALSE;
ms_Instance = this;
m_Node = NULL;
+void PreviewFrame::MakeDirty()
+{
+ if (m_Node == NULL) return;
+ if (m_Dirty) return;
+ m_Dirty = TRUE;
+ m_LogCtrl->Clear();
+ m_LogCtrl->SetValue(_("Resource modified.\n"
+ "Move mouse cursor over the preview window to refresh it."));
+}
+
+
+
void PreviewFrame::Preview(wxXmlNode *node)
{
while (node->GetParent()->GetParent() != NULL) node = node->GetParent();
wxSetWorkingDirectory(oldcwd);
wxLog::SetActiveTarget(oldlog);
+
+ m_Dirty = FALSE;
}
0, 0, TRUE);
}
}
+
+
+
+BEGIN_EVENT_TABLE(PreviewFrame, wxFrame)
+ EVT_ENTER_WINDOW(PreviewFrame::OnMouseEnter)
+END_EVENT_TABLE()
+
+void PreviewFrame::OnMouseEnter(wxMouseEvent& event)
+{
+ if (m_Dirty) Preview(m_Node);
+}
~PreviewFrame();
void Preview(wxXmlNode *node);
+ void MakeDirty();
+ // current node updated, needs preview refresh
+ // (will be done once mouse enters preview win)
static PreviewFrame *Get();
wxXmlResource *m_RC;
wxString m_TmpFile;
+
+ bool m_Dirty;
+
+ DECLARE_EVENT_TABLE()
+ void OnMouseEnter(wxMouseEvent& event);
};
#include "propframe.h"
#include "propedit.h"
#include "xmlhelpr.h"
+#include "editor.h"
enum
{
void PropEditCtrl::OnButtonClear(wxCommandEvent& event)
{
Clear();
+ EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
}
m_EditCtrls.Put(_T("xmlid"), new PropEditCtrlXMLID(this));
m_EditCtrls.Put(_T("font"), new PropEditCtrlFont(this));
m_EditCtrls.Put(_T("choice"), new PropEditCtrlChoice(this));
+ m_EditCtrls.Put(_T("file"), new PropEditCtrlFile(this));
+ m_EditCtrls.Put(_T("imagefile"), new PropEditCtrlImageFile(this));
m_EditCtrls.Put(_T(""), new PropEditCtrlNull(this));
ClearProps();