Patch #2162 2007-08-28 12:16
olipfei
Patch for Feature Request #3547- Download
- 2162-Patch_for_Feat.patch (7.1 KB)
Index: src/include/editormanager.h
===================================================================
--- src/include/editormanager.h (Revision 5294)
+++ src/include/editormanager.h (Arbeitskopie)
@@ -136,6 +136,8 @@
void OnSwapHeaderSource(wxCommandEvent& event);
void OnTabPosition(wxCommandEvent& event);
void OnProperties(wxCommandEvent& event);
+ void OnAddFileToProject(wxCommandEvent& event);
+ void OnRemoveFileFromProject(wxCommandEvent& event);
void OnAppDoneStartup(wxCommandEvent& event);
void OnAppStartShutdown(wxCommandEvent& event);
void OnUpdateUI(wxUpdateUIEvent& event);
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (Revision 5294)
+++ src/sdk/cbeditor.cpp (Arbeitskopie)
@@ -398,6 +398,8 @@
const int idUnsplit = wxNewId();
const int idConfigureEditor = wxNewId();
const int idProperties = wxNewId();
+const int idAddFileToProject = wxNewId();
+const int idRemoveFileFromProject = wxNewId();
const int idBookmarkAdd = wxNewId();
const int idBookmarkRemove = wxNewId();
@@ -431,6 +433,8 @@
EVT_MENU(idFoldingToggleCurrent, cbEditor::OnContextMenuEntry)
EVT_MENU(idConfigureEditor, cbEditor::OnContextMenuEntry)
EVT_MENU(idProperties, cbEditor::OnContextMenuEntry)
+ EVT_MENU(idAddFileToProject, cbEditor::OnContextMenuEntry)
+ EVT_MENU(idRemoveFileFromProject, cbEditor::OnContextMenuEntry)
EVT_MENU(idBookmarkAdd, cbEditor::OnContextMenuEntry)
EVT_MENU(idBookmarkRemove, cbEditor::OnContextMenuEntry)
EVT_MENU(idBreakpointAdd, cbEditor::OnContextMenuEntry)
@@ -662,13 +666,13 @@
else
m_Shortname = m_pProjectFile->file.GetFullName();
SetEditorTitle(m_Shortname);
+
+ if (!wxFileExists(m_Filename))
+ m_pProjectFile->SetFileState(fvsMissing);
+ else if (!wxFile::Access(m_Filename.c_str(), wxFile::write)) // readonly
+ m_pProjectFile->SetFileState(fvsReadOnly);
}
- if (!wxFileExists(m_Filename))
- m_pProjectFile->SetFileState(fvsMissing);
- else if (!wxFile::Access(m_Filename.c_str(), wxFile::write)) // readonly
- m_pProjectFile->SetFileState(fvsReadOnly);
-
#if 0
wxString dbg;
dbg << _T("[ed] Filename: ") << GetFilename() << _T('\n');
@@ -1418,6 +1422,9 @@
fname.Assign(m_Filename);
m_Shortname = fname.GetFullName();
SetEditorTitle(m_Shortname);
+ // invalidate m_pProjectFile, because if kept, it would point to the ProjectFile with old name and
+ // cause ProjectManager::RemoveFileFromProject called via context menu to crash
+ SetProjectFile(0);
//Manager::Get()->GetLogManager()->Log(mltDevDebug, "Filename=%s\nShort=%s", m_Filename.c_str(), m_Shortname.c_str());
m_IsOK = true;
SetModified(true);
@@ -2239,6 +2246,15 @@
popup->Append(idConfigureEditor, _("Configure editor..."));
popup->Append(idProperties, _("Properties..."));
+ if (Manager::Get()->GetProjectManager()->GetActiveProject()) // project must be open
+ {
+ popup->AppendSeparator();
+
+ if (m_pProjectFile)
+ popup->Append(idRemoveFileFromProject, _("Remove file from project"));
+ else
+ popup->Append(idAddFileToProject, _("Add file to active project"));
+ }
// remove "Insert/Empty" if more than one entry
wxMenu* insert = 0;
wxMenuItem* insertitem = popup->FindItem(idInsert);
@@ -2467,6 +2483,27 @@
dlg.ShowModal();
}
}
+ else if (id == idAddFileToProject)
+ {
+ cbProject *prj = Manager::Get()->GetProjectManager()->GetActiveProject();
+
+ wxArrayInt targets;
+ if (Manager::Get()->GetProjectManager()->AddFileToProject(m_Filename, prj, targets) != 0)
+ {
+ ProjectFile* pf = prj->GetFileByFilename(m_Filename, false);
+ SetProjectFile(pf);
+ Manager::Get()->GetProjectManager()->RebuildTree();
+ }
+ }
+ else if (id == idRemoveFileFromProject)
+ {
+ if (m_pProjectFile)
+ {
+ cbProject *prj = m_pProjectFile->GetParentProject();
+ Manager::Get()->GetProjectManager()->RemoveFileFromProject(m_pProjectFile, prj);
+ Manager::Get()->GetProjectManager()->RebuildTree();
+ }
+ }
else if (id == idBreakpointAdd)
AddBreakpoint(m_pData->m_LastMarginMenuLine);
else if (id == idBreakpointEdit)
Index: src/sdk/editormanager.cpp
===================================================================
--- src/sdk/editormanager.cpp (Revision 5294)
+++ src/sdk/editormanager.cpp (Arbeitskopie)
@@ -105,6 +105,8 @@
static const int idNBTabTop = wxNewId();
static const int idNBTabBottom = wxNewId();
static const int idNBProperties = wxNewId();
+static const int idNBAddFileToProject = wxNewId();
+static const int idNBRemoveFileFromProj
download for full patch...
History
New item 'Add file to active project' in EditorManager and cbEditor popup menus. I actually also added 'Remove file from project' functionality to these menus, but to this purpose I had to insert a function to the public interface of class ProjectManager which I don't know if I'm allowed to do so as 'external' developer. It would be fine if someone could give me a hint how to implement a more suitable and generic version of ProjectManager::RemoveFileFromProject, compared with AddFileToProject.
Forgot to remove two comments from my other experiments, thus uploaded corrected patch.
I just became aware of this patch and would like to experiment with it. So far I have not been able to apply the patch. Maybe my procedure is wrong:
Open View Raw Patch above and save file in src directory, with .patch extension.
Right-click file->TortoiseSVN->Apply patch....
This gives error "An unknown line type was found in line 109!".
Any suggestions?
Thanks.
The procedure seems fine (though I have no experience with TortoiseSVN), but the patch is definitely too old. I wrote it with respect to revision 4403, now CB is at revision >5000. I will soon upload an adapted patch, but cannot do so before next week.
Great. I look forward to experimenting with your new patch. This is a MSVC feature that I have really missed in CodeBlocks.
Sorry for the (expectable ;-) delay! I have adapted the patch to revision 5081. Can you please crosscheck if it works now (applying the patch and compiling)?
I just noticed your updated patch. I will definitely try it out, but it will probably be this weekend before I can get to it. Thanks.
I applied the patch (Windows XP) and it appears to work as you intended. Good work!
However, it does not do quite what I had hoped. I often have a project file, say a header, open in the editor and decide I need another file. I do a File->Save as and enter the new file name, which opens in the editor. I then want to add this to the project, but the context menu continues with the option "Remove file from project" . This new file is not yet in the project and two attempts to remove it will cause CB to crash. If you can fix this, I think this would be an excellent additional feature for CB.
Uploaded corrected patch which now also fixes a minor flaw in cbEditor::SaveAs that causes another part of the patch to crash. Thanks to 'rhf' for drawing my attention to this issue.
Cleaned up the patch a little bit and incorporated a further suggestion due to 'rhf'. I would not mind if it were accepted now ;-)
Excellent! I really like this feature and hope that the patch will be incorporated into CodeBlocks. Good work, Olipfei.
I have been using this excellent patch for nearly a month (on Windows XP) with absolutely no problems. Today SVN Rev 5174 caused a conflict with the patched file 'trunk/src/sdk/projectmanager.cpp'. I really don't know how to fix the conflict so I have reverted to an earlier Rev. However, it would really be nice if this feature could be incorporated into the main program. If I could help a developer in any way, perhaps with testing, I would be happy to do so.
Thanks.
Uploaded updated patch to match revision 5200, due to rhf's request.
Thanks very much for the updated patch. It would be great if it were incorporated into the trunk.
I have applied the patch partially.
For the rest (to add the menu entry):
I am not satisfied with it. The menu entry is just below "Switch header / source" which is *really* often used. I for myself chose "Remove file from project" a lot by mistake because it's on the "Switch..." things original position. this is very annoying as you really have to add the file again. A message box warning about the file to be removed would be really welcome here. In addition: Probably you can make this menu entry to appear on the very bottom of the menu?
Anyways: It would be nice if you could update the patch so it matches trunk again.
Thanks for pointing me to this, I also had some concerns about the 'ideal' place for the menu entry. Usually I'm a keen keyboard user, I press F11 to switch between source and header, and so I didn't observe that the old position caused confusion. But are you sure you want to have another dialog popping up? The 'Remove file' procedure in the project management pane which was already there before my patch doesn't warn before it acts either. And you have to admit that some UI parts of CB could bear some streamlining...
I placed my entries at the bottom of the menu now (after the 'Properties...' menu entry, internally) and synced the code with rev 5294. Note that my patch also includes two minor fixes for problems (possibly crashes) of CB in cbEditor::SetProjectFile and cbEditor::SaveAs (see conversation below).
Oops, forgot checkbox to upload revised patch.
Guys, I applied olipfei's updated patch of Oct 27 to rev 5294.
It seems to work fine for me on Windows XP. Also, I like the menu entry at the bottom; it makes it easier to find. Thanks.
Just for the record: I am still on this... it's not forgotten. :-)
Thanks, mortenmacfly. If I can help in any way, perhaps with testing, I would be glad to do so.