コード例 #1
0
// See IsAdminDirTopLevel
const std::string wxExVCS::GetRelativeFile(
  const std::string& admin_dir, 
  const wxExFileName& fn) const
{
  // The .git dir only exists in the root, so check all components.
  wxFileName root(fn.GetFullPath());
  std::vector< std::string > v;

  while (root.DirExists() && root.GetDirCount() > 0)
  {
    wxFileName path(root);
    path.AppendDir(admin_dir);

    if (path.DirExists() && !path.FileExists())
    {
      std::string relative_file;

      for (int i = v.size() - 1; i >= 0; i--)
      {
        relative_file += v[i] + "/";
      }
      
      return relative_file + fn.GetFullName();
    }

    v.emplace_back(root.GetDirs().Last());
    root.RemoveLastDir();
  }
  
  return std::string();
}
コード例 #2
0
bool wxExVCS::IsAdminDirTopLevel(
  const std::string& admin_dir, 
  const wxExFileName& fn)
{
  if (!fn.IsOk() || admin_dir.empty())
  {
    return false;
  }
  
  // The .git dir only exists in the root, so check all components.
  wxFileName root(fn.GetFullPath());

  while (root.DirExists() && root.GetDirCount() > 0)
  {
    wxFileName path(root);
    path.AppendDir(admin_dir);

    if (path.DirExists() && !path.FileExists())
    {
      return true;
    }

    root.RemoveLastDir();
  }

  return false;
}
コード例 #3
0
void CheckWellFormed(const wxExFileName& fn)
{
  if (fn.GetLexer().GetLanguage() == "xml")
  {
    if (!wxXmlDocument(fn.GetFullPath()).IsOk())
    {
      wxLogStatus("not a valid XML document");
    }
  }
}
コード例 #4
0
bool wxExVCS::IsAdminDir(
  const std::string& admin_dir, 
  const wxExFileName& fn)
{
  if (admin_dir.empty() || !fn.IsOk())
  {
    return false;
  }
  
  // these cannot be combined, as AppendDir is a void (2.9.1).
  wxFileName path(fn.GetFullPath());
  path.AppendDir(admin_dir);
  return path.DirExists() && !path.FileExists();
}
コード例 #5
0
ファイル: frame.cpp プロジェクト: Emmavw/wxExtension
bool wxExFrameWithHistory::OpenFile(
  const wxExFileName& filename,
  int line_number,
  const wxString& match,
  long flags)
{
  if (wxExManagedFrame::OpenFile(filename, line_number, match, flags))
  {
    SetRecentFile(filename.GetFullPath());
    return true;
  }

  return false;
}
コード例 #6
0
ファイル: listviewfile.cpp プロジェクト: hugofvw/wxExtension
void wxExListViewFile::DoFileSave(bool save_as)
{
  wxXmlNode* root = new wxXmlNode(wxXML_ELEMENT_NODE, "files");
  wxXmlNode* comment = new wxXmlNode(
    wxXML_COMMENT_NODE,
    wxEmptyString,
    wxTheApp->GetAppDisplayName() + " project " + GetFileName().GetFullName() + 
      " "  + wxDateTime::Now().Format());

  root->AddChild(comment);

  for (int i = 0; i < GetItemCount(); i++)
  {
    const wxExFileName fn = wxExListItem(this, i).GetFileName();

    wxXmlNode* element = new wxXmlNode(
      wxXML_ELEMENT_NODE,
      (fn.FileExists() ? "file": "folder"));

    if (!fn.FileExists() && fn.DirExists())
    {
      element->AddAttribute("extensions", GetItemText(i, _("Type")));
    }
    
    wxXmlNode* text = new wxXmlNode(
      wxXML_TEXT_NODE, 
      wxEmptyString, 
      fn.GetFullPath());
      
    element->AddChild(text);
    root->AddChild(element);
  }
  
  wxXmlDocument doc;
  doc.SetRoot(root);
  doc.Save(GetFileName().GetFullPath());
}
コード例 #7
0
bool wxExViMacros::ExpandTemplate(
  wxExEx* ex, const wxExVariable& v, std::string& expanded)
{
  if (v.GetValue().empty())
  {
    return false;
  }
  
  if (!m_IsExpand)
  {
    m_IsExpand = true;
    AskForInput();
  }

  // Read the file (file name is in v.GetValue()), expand
  // all macro variables in it, and set expanded.
  const wxExFileName filename(wxExConfigDir(), v.GetValue());

  std::ifstream ifs(filename.GetFullPath());
  
  if (!ifs.is_open())
  {
    wxLogError("Could not open template file: %s", filename.GetFullPath().c_str());
    return false;
  }

  // Keep current macro, in case you cancel expanding,
  // this one is restored.
  std::string macro = m_Macro;
  
  while (ifs.good() && !ifs.eof()) 
  {
    const char c = ifs.get();
    
    if (c != '@')
    {
      expanded += c;
    }
    else
    {
      std::string variable;
      bool completed = false;
      
      while (ifs.good() && !ifs.eof() && !completed) 
      {
        const char c = ifs.get();
    
        if (c != '@')
        {
          variable += c;
        }
        else
        {
          completed = true;
        }
      }
      
      if (!completed)
      {
        m_Macro = macro;
        return false;
      }
      
      // Prevent recursion.
      if (variable == v.GetName())
      {
        m_Macro = macro;
        return false;
      }
      
      std::string value;
      
      if (!Expand(ex, variable, value))
      {
        m_Macro = macro;
        return false;
      }
      
      expanded += value;
    }
  }
  
  m_IsExpand = false;

  // Set back to normal value.  
  AskForInput();
    
  if (!m_IsRecording)
  {
    m_Macro = v.GetName();
  }
    
  return true;
}