Menu

[r1974]: / trunk / src / sdk / cbworkspace.cpp  Maximize  Restore  History

Download this file

166 lines (146 with data), 4.4 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* This file is part of Code::Blocks Studio, an open-source cross-platform IDE
* Copyright (C) 2003 Yiannis An. Mandravellos
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Contact e-mail: Yiannis An. Mandravellos <mandrav@codeblocks.org>
* Program URL : http://www.codeblocks.org
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include "cbworkspace.h"
#include "globals.h"
#include "manager.h"
#include "configmanager.h"
#include "messagemanager.h"
#include "workspaceloader.h"
#include <wx/intl.h>
#endif
#include "msvcworkspaceloader.h"
#include "msvc7workspaceloader.h"
#include <wx/filedlg.h>
cbWorkspace::cbWorkspace(const wxString& filename)
{
SC_CONSTRUCTOR_BEGIN
//ctor
if (filename.Matches(DEFAULT_WORKSPACE))
{
wxString tmp;
// if no filename given, use the default workspace
tmp = ConfigManager::GetConfigFolder() + wxFILE_SEP_PATH;
if (!wxDirExists(tmp))
wxMkdir(tmp, 0755);
tmp << wxFILE_SEP_PATH << DEFAULT_WORKSPACE;
m_Filename = tmp;
m_IsDefault = true;
}
else
{
m_Filename = filename;
m_IsDefault = false;
}
Load();
}
cbWorkspace::~cbWorkspace()
{
SC_DESTRUCTOR_BEGIN
//dtor
SC_DESTRUCTOR_END
}
void cbWorkspace::Load()
{
SANITY_CHECK();
wxString fname = m_Filename.GetFullPath();
if (fname.IsEmpty())
return;
Manager::Get()->GetMessageManager()->DebugLog(_("Loading workspace \"%s\""), fname.c_str());
if (!m_Filename.FileExists())
{
Manager::Get()->GetMessageManager()->DebugLog(_("File does not exist."));
if (!m_IsDefault)
{
wxString msg;
msg.Printf(_("Workspace '%s' does not exist..."), fname.c_str());
wxMessageBox(msg, _("Error"), wxOK | wxCENTRE | wxICON_ERROR);
}
// workspace wasn't loaded succesfully
m_IsOK = false;
return;
}
bool modified = false;
IBaseWorkspaceLoader* pWsp = 0;
switch (FileTypeOf(fname))
{
case ftCodeBlocksWorkspace: pWsp = new WorkspaceLoader; modified = false; break;
case ftMSVC6Workspace: pWsp = new MSVCWorkspaceLoader; modified = true; break;
case ftMSVC7Workspace: pWsp = new MSVC7WorkspaceLoader; modified = true; break;
default: break;
}
m_IsOK = pWsp && (pWsp->Open(fname) || m_IsDefault);
SANITY_CHECK();
m_Title = pWsp ? pWsp->GetTitle() : wxString(wxEmptyString);
SANITY_CHECK();
SANITY_CHECK();
m_Filename.SetExt(WORKSPACE_EXT);
SetModified(modified);
if (pWsp)
delete pWsp;
}
bool cbWorkspace::Save(bool force)
{
SANITY_CHECK(false);
if (m_Filename.GetFullPath().IsEmpty())
return SaveAs(_T(""));
if (!force && !m_Modified)
return true;
Manager::Get()->GetMessageManager()->DebugLog(_("Saving workspace \"%s\""), m_Filename.GetFullPath().c_str());
WorkspaceLoader wsp;
bool ret = wsp.Save(m_Title, m_Filename.GetFullPath());
SetModified(!ret);
return ret;
}
bool cbWorkspace::SaveAs(const wxString& filename)
{
SANITY_CHECK(false);
wxFileDialog* dlg = new wxFileDialog(0,
_("Save workspace"),
m_Filename.GetPath(),
m_Filename.GetFullName(),
WORKSPACES_FILES_FILTER,
wxSAVE | wxOVERWRITE_PROMPT);
PlaceWindow(dlg);
if (dlg->ShowModal() != wxID_OK)
return false;
SANITY_CHECK(false);
m_Filename = dlg->GetPath();
m_IsDefault = false;
return Save(true);
}
void cbWorkspace::SetTitle(const wxString& title)
{
SANITY_CHECK();
m_Title = title;
SetModified(true);
}
void cbWorkspace::SetModified(bool modified)
{
SANITY_CHECK();
m_Modified = modified;
}