]> git.saurik.com Git - wxWidgets.git/commitdiff
wxrcedit bugfixes
authorVáclav Slavík <vslavik@fastmail.fm>
Fri, 24 Nov 2000 17:19:48 +0000 (17:19 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Fri, 24 Nov 2000 17:19:48 +0000 (17:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8807 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

contrib/utils/wxrcedit/editor.cpp
contrib/utils/wxrcedit/editor.h
contrib/utils/wxrcedit/pe_adv.cpp
contrib/utils/wxrcedit/pe_adv.h
contrib/utils/wxrcedit/pe_basic.cpp
contrib/utils/wxrcedit/preview.cpp
contrib/utils/wxrcedit/preview.h
contrib/utils/wxrcedit/propedit.cpp
contrib/utils/wxrcedit/propframe.cpp

index c340043ff1a7420950ee2e8f009d6fcd0f695df7..9e313c75973747b72c01a51bc804d2f845a488a1 100644 (file)
@@ -98,6 +98,7 @@ BEGIN_EVENT_TABLE(EditorFrame, wxFrame)
     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()
 
 
@@ -126,6 +127,7 @@ EditorFrame::EditorFrame(wxFrame *parent, const wxString& filename)
     ms_Instance = this;
 
     m_Clipboard = NULL;
+    m_Modified = FALSE;
     
     wxConfigBase *cfg = wxConfigBase::Get();
     
@@ -224,10 +226,13 @@ EditorFrame::~EditorFrame()
 
 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))
     {
@@ -240,8 +245,8 @@ void EditorFrame::LoadFile(const wxString& filename)
     {
         m_FileName = filename;
         RefreshTree();
-        SetTitle("wxrcedit - " + wxFileNameFromPath(m_FileName));
     }
+    RefreshTitle();
 }
 
 
@@ -249,24 +254,42 @@ void EditorFrame::LoadFile(const wxString& filename)
 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);
 }
 
 
@@ -356,6 +379,14 @@ void EditorFrame::NotifyChanged(int change_type)
         int icon = NodeHandler::Find(m_SelectedNode)->GetTreeIcon(m_SelectedNode);
         m_TreeCtrl->SetItemImage(sel, icon);
     }
+    
+    if (!m_Modified)
+    {
+        m_Modified = TRUE;
+        RefreshTitle();
+    }
+    
+    PreviewFrame::Get()->MakeDirty();
 }
 
 
@@ -421,7 +452,9 @@ void EditorFrame::OnToolbar(wxCommandEvent& event)
 
         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;
@@ -433,7 +466,9 @@ void EditorFrame::OnToolbar(wxCommandEvent& event)
 
         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;
@@ -664,3 +699,27 @@ void EditorFrame::OnClipboardAction(wxCommandEvent& event)
     }
 }
 
+
+
+
+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();
+}
index bb1d365c79d6e7bebf5eacbf17c60011d392d093..3afd1c19c2d0b860480817cca0269b38d790fc1d 100644 (file)
@@ -61,6 +61,7 @@ class EditorFrame : public wxFrame
         wxString GetFileName() { return m_FileName; }
         
         void RefreshTree();
+        void RefreshTitle();
         bool SelectNode(wxXmlNode *node, wxTreeItemId *root = NULL);
         
         wxTreeItemId CreateTreeNode(wxTreeCtrl *treectrl, wxTreeItemId parent, wxXmlNode *node);
@@ -80,6 +81,11 @@ class EditorFrame : public wxFrame
 
         wxString m_FileName;
         wxXmlDocument *m_Resource;
+        
+        bool m_Modified;
+        
+        bool AskToSave();
+        void DeleteSelectedNode();
 
         DECLARE_EVENT_TABLE()
         void OnTreeSel(wxTreeEvent& event);
@@ -88,8 +94,7 @@ class EditorFrame : public wxFrame
         void OnNewNode(wxCommandEvent& event);
         void OnRightClickTree(wxPoint pos);
         void OnClipboardAction(wxCommandEvent& event);
-        
-        void DeleteSelectedNode();
+        void OnCloseWindow(wxCloseEvent&);
 };
 
 
index 415ea6e5c18f398aaf850874f18fe71727a9860c..9c570d096bb137a8364b8686cf6f35212b207f70 100644 (file)
@@ -96,7 +96,11 @@ void PropEditCtrlChoice::WriteValue()
 
 void PropEditCtrlChoice::OnChoice(wxCommandEvent& event)
 {
-    if (CanSave()) WriteValue();
+    if (CanSave()) 
+    {
+        WriteValue();
+        EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);    
+    }
 }
 
 
@@ -193,3 +197,66 @@ void PropEditCtrlFlags::OnDetails()
 }
 
 
+
+
+
+
+
+
+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 (*)|*");
+}
index f99c1b726ede97a1c3e4b57973e1d854ecbbd26d..b72c569a02f35d152209ca59fc573014ab0ba87e 100644 (file)
@@ -76,6 +76,26 @@ class PropEditCtrlFlags : public PropEditCtrlTxt
 
 
 
+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
index 7bef53dc7aa465c193469bd733e06a4a9a6d3db3..fdc338b06ce33ced7bd95443b64d3367e9346872 100644 (file)
@@ -40,7 +40,11 @@ wxWindow *PropEditCtrlTxt::CreateEditCtrl()
 
 void PropEditCtrlTxt::OnText(wxCommandEvent& event)
 {
-    if (CanSave()) WriteValue();
+    if (CanSave()) 
+    {
+        WriteValue();
+        EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
+    }
 }
 
 
@@ -121,7 +125,11 @@ wxString PropEditCtrlBool::GetValueAsText(wxTreeItemId ti)
 
 void PropEditCtrlBool::OnChoice(wxCommandEvent& event)
 {
-    if (CanSave()) WriteValue();
+    if (CanSave()) 
+    {
+        WriteValue();
+        EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);
+    }
 }
 
 
@@ -410,6 +418,7 @@ void PropEditCtrlXMLID::OnDetails()
     if (!s) return;
     m_TextCtrl->SetValue(s);
     WriteValue();
+    EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);    
 }
 
 
index 82729ec3074190cfb2f00a672b37f74988fcd8ad..7ed924bb1c2c0c09d7f3db7fa886951de322a6aa 100644 (file)
@@ -63,6 +63,7 @@ PreviewFrame *PreviewFrame::Get()
 PreviewFrame::PreviewFrame()
     : wxFrame(NULL, -1, _("Preview"))
 {
+    m_Dirty = FALSE;
     ms_Instance = this;
     m_Node = NULL;
     
@@ -109,6 +110,18 @@ PreviewFrame::~PreviewFrame()
 
 
         
+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();
@@ -152,6 +165,8 @@ void PreviewFrame::Preview(wxXmlNode *node)
    
    wxSetWorkingDirectory(oldcwd);
    wxLog::SetActiveTarget(oldlog);
+   
+   m_Dirty = FALSE;
 }
 
 
@@ -193,3 +208,14 @@ void PreviewFrame::PreviewPanel()
                                    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);
+}
index ee7f86d7632a5310925f7b4e759de9e856c52456..7fee0baa7a866a0a76434f2cee163e5dde9a6dc1 100644 (file)
@@ -32,6 +32,9 @@ class PreviewFrame : public wxFrame
         ~PreviewFrame();
         
         void Preview(wxXmlNode *node);
+        void MakeDirty();
+                // current node updated, needs preview refresh
+                // (will be done once mouse enters preview win)
       
         static PreviewFrame *Get();
         
@@ -49,6 +52,11 @@ class PreviewFrame : public wxFrame
         
         wxXmlResource *m_RC;
         wxString m_TmpFile;
+        
+        bool m_Dirty;
+        
+        DECLARE_EVENT_TABLE()
+        void OnMouseEnter(wxMouseEvent& event);
 };
 
 
index 07f2d40c009191f065d49e5749a36a25e64d4356..a2021b83d0c77a5140037832071be3921d338b86 100644 (file)
@@ -22,6 +22,7 @@
 #include "propframe.h"
 #include "propedit.h"
 #include "xmlhelpr.h"
+#include "editor.h"
 
 enum
 {
@@ -44,6 +45,7 @@ void PropEditCtrl::OnButtonDetails(wxCommandEvent& event)
 void PropEditCtrl::OnButtonClear(wxCommandEvent& event)
 {
     Clear();
+    EditorFrame::Get()->NotifyChanged(CHANGED_PROPS);        
 }
 
 
index 6c8af96feed417f62da9ad39354383d1c131dc1b..b03e2142c169482434ae9dc4178b0c869c0ebefa 100644 (file)
@@ -228,6 +228,8 @@ PropertiesFrame::PropertiesFrame()
     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();