summaryrefslogtreecommitdiff
path: root/LiteEditor/fileview.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'LiteEditor/fileview.cpp')
-rw-r--r--LiteEditor/fileview.cpp204
1 files changed, 109 insertions, 95 deletions
diff --git a/LiteEditor/fileview.cpp b/LiteEditor/fileview.cpp
index cb613d33..f7f3ae90 100644
--- a/LiteEditor/fileview.cpp
+++ b/LiteEditor/fileview.cpp
@@ -71,6 +71,7 @@
#include <project.h>
#include "compiler.h"
#include "ICompilerLocator.h"
+#include "fileutils.h"
IMPLEMENT_DYNAMIC_CLASS(FileViewTree, wxTreeCtrl)
@@ -111,6 +112,8 @@ EVT_MENU(XRCID("import_directory"), FileViewTree::OnImportDirectory)
EVT_MENU(XRCID("reconcile_project"), FileViewTree::OnReconcileProject)
EVT_MENU(XRCID("open_in_editor"), FileViewTree::OnOpenInEditor)
EVT_MENU(XRCID("compile_item"), FileViewTree::OnCompileItem)
+EVT_MENU(XRCID("cxx_fileview_open_shell_from_filepath"), FileViewTree::OnOpenShellFromFilePath)
+EVT_MENU(XRCID("cxx_fileview_open_file_explorer"), FileViewTree::OnOpenFileExplorerFromFilePath)
EVT_MENU(XRCID("exclude_from_build"), FileViewTree::OnExcludeFromBuild)
EVT_MENU(XRCID("preprocess_item"), FileViewTree::OnPreprocessItem)
EVT_MENU(XRCID("rename_item"), FileViewTree::OnRenameItem)
@@ -152,6 +155,7 @@ static int PROJECT_IMG_IDX = wxNOT_FOUND;
static int FOLDER_IMG_IDX = wxNOT_FOUND;
static int WORKSPACE_IMG_IDX = wxNOT_FOUND;
static int ACTIVE_PROJECT_IMG_IDX = wxNOT_FOUND;
+static int FOLDER_EXPAND_IMG_IDX = wxNOT_FOUND;
FileViewTree::FileViewTree() {}
@@ -161,6 +165,7 @@ FileViewTree::FileViewTree(wxWindow* parent, const wxWindowID id, const wxPoint&
{
Create(parent, id, pos, size, style);
MSWSetNativeTheme(this);
+ m_keyboardHelper.reset(new clTreeKeyboardInput(this));
// Initialise images map
BitmapLoader* bmpLoader = PluginManager::Get()->GetStdIcons();
@@ -168,8 +173,9 @@ FileViewTree::FileViewTree(wxWindow* parent, const wxWindowID id, const wxPoint&
// Prepare the standard mime-type image list
wxImageList* images = bmpLoader->MakeStandardMimeImageList();
- FOLDER_IMG_IDX = images->Add(bmpLoader->LoadBitmap(wxT("mime/16/folder")));
- ACTIVE_PROJECT_IMG_IDX = images->Add(bmpLoader->LoadBitmap(wxT("workspace/16/project_active")));
+ FOLDER_EXPAND_IMG_IDX = bmpLoader->GetMimeImageId(FileExtManager::TypeFolderExpanded);
+ FOLDER_IMG_IDX = images->Add(bmpLoader->LoadBitmap(wxT("folder-yellow")));
+ ACTIVE_PROJECT_IMG_IDX = images->Add(bmpLoader->LoadBitmap(wxT("project")));
WORKSPACE_IMG_IDX = bmpLoader->GetMimeImageId(FileExtManager::TypeWorkspace);
PROJECT_IMG_IDX = bmpLoader->GetMimeImageId(FileExtManager::TypeProject);
@@ -195,6 +201,7 @@ FileViewTree::~FileViewTree()
EventNotifier::Get()->Disconnect(
wxEVT_CMD_CLEAN_PROJECT_ONLY, wxCommandEventHandler(FileViewTree::OnCleanProjectOnlyInternal), NULL, this);
Unbind(wxEVT_DND_FOLDER_DROPPED, &FileViewTree::OnFolderDropped, this);
+ m_keyboardHelper.reset(NULL);
}
void FileViewTree::Create(wxWindow* parent, const wxWindowID id, const wxPoint& pos, const wxSize& size, long style)
@@ -338,12 +345,14 @@ void FileViewTree::BuildProjectNode(const wxString& projectName)
projectIconIndex = GetIconIndex(node->GetData());
}
- wxTreeItemId hti = AppendItem(parentHti, // parent
- node->GetData().GetDisplayName(), // display name
- projectIconIndex, // item image index
- projectIconIndex, // selected item image
- new FilewViewTreeItemData(node->GetData()));
-
+ wxTreeItemId hti = AppendItem(parentHti, // parent
+ node->GetData().GetDisplayName(), // display name
+ projectIconIndex, // item image index
+ projectIconIndex, // selected item image
+ new FilewViewTreeItemData(node->GetData()));
+ if(node->GetData().GetKind() == ProjectItem::TypeVirtualDirectory) {
+ SetItemImage(hti, FOLDER_EXPAND_IMG_IDX, wxTreeItemIcon_Expanded);
+ }
// FIXME ::
// Use a more efficient way for checking if a file is 'Excluded' from the build
@@ -426,7 +435,7 @@ void FileViewTree::ShowProjectContextMenu(const wxString& projectName)
// set the icon for the default actions (build, clean and settings)
wxBitmap bmpBuild = PluginManager::Get()->GetStdIcons()->LoadBitmap("toolbars/16/build/build");
wxBitmap bmpClean = PluginManager::Get()->GetStdIcons()->LoadBitmap("toolbars/16/build/clean");
- wxBitmap bmpSettings = wxXmlResource::Get()->LoadBitmap(wxT("configure"));
+ wxBitmap bmpSettings = PluginManager::Get()->GetStdIcons()->LoadBitmap("cog");
menu->FindItem(XRCID("build_project"))->SetBitmap(bmpBuild);
menu->FindItem(XRCID("clean_project"))->SetBitmap(bmpClean);
@@ -435,19 +444,6 @@ void FileViewTree::ShowProjectContextMenu(const wxString& projectName)
BuildConfigPtr bldConf = clCxxWorkspaceST::Get()->GetProjBuildConf(projectName, wxEmptyString);
if(bldConf && bldConf->IsCustomBuild()) {
wxMenuItem* item = NULL;
-#if 0
- wxString toolName = bldConf->GetToolName();
- if(toolName != wxT("None")) {
-
- // add the custom execution command
- item = new wxMenuItem(menu, wxID_SEPARATOR);
- menu->Prepend(item);
- wxString menu_text(_("Run ") + toolName);
-
- item = new wxMenuItem(menu, XRCID("generate_makefile"), menu_text, wxEmptyString, wxITEM_NORMAL);
- menu->Prepend(item);
- }
-#endif
// append the custom build targets
const BuildConfig::StringMap_t& targets = bldConf->GetCustomTargets();
if(targets.empty() == false) {
@@ -458,10 +454,9 @@ void FileViewTree::ShowProjectContextMenu(const wxString& projectName)
CustomTargetsMgr::Map_t::const_iterator iter = targetsMap.begin();
for(; iter != targetsMap.end(); ++iter) {
item = new wxMenuItem(customTargetsMenu,
- iter->first, // Menu ID
- iter->second.first, // Menu Name
- wxEmptyString,
- wxITEM_NORMAL);
+ iter->first, // Menu ID
+ iter->second.first, // Menu Name
+ wxEmptyString, wxITEM_NORMAL);
customTargetsMenu->Append(item);
}
@@ -612,7 +607,7 @@ void FileViewTree::DoItemActivated(wxTreeItemId& item, wxEvent& event)
wxString filename = itemData->GetData().GetFile();
wxString key = itemData->GetData().Key();
wxString project;
- if (key.GetChar(0) == ':') {
+ if(key.GetChar(0) == ':') {
// All the entries I've tested have started with a : so exclude this one, otherwise the project is always ""
project = key.AfterFirst(':').BeforeFirst(wxT(':'));
} else {
@@ -711,11 +706,11 @@ bool FileViewTree::AddFilesToVirtualFolder(const wxString& vdFullPath, wxArraySt
path += fnFileName.GetFullName();
ProjectItem projItem(path, fnFileName.GetFullName(), fnFileName.GetFullPath(), ProjectItem::TypeFile);
- wxTreeItemId hti = AppendItem(item, // parent
- projItem.GetDisplayName(), // display name
- GetIconIndex(projItem), // item image index
- GetIconIndex(projItem), // selected item image
- new FilewViewTreeItemData(projItem));
+ wxTreeItemId hti = AppendItem(item, // parent
+ projItem.GetDisplayName(), // display name
+ GetIconIndex(projItem), // item image index
+ GetIconIndex(projItem), // selected item image
+ new FilewViewTreeItemData(projItem));
wxUnusedVar(hti);
}
@@ -805,11 +800,11 @@ bool FileViewTree::AddFilesToVirtualFolder(wxTreeItemId& item, wxArrayString& pa
path += fnFileName.GetFullName();
ProjectItem projItem(path, fnFileName.GetFullName(), fnFileName.GetFullPath(), ProjectItem::TypeFile);
- wxTreeItemId hti = AppendItem(item, // parent
- projItem.GetDisplayName(), // display name
- GetIconIndex(projItem), // item image index
- GetIconIndex(projItem), // selected item image
- new FilewViewTreeItemData(projItem));
+ wxTreeItemId hti = AppendItem(item, // parent
+ projItem.GetDisplayName(), // display name
+ GetIconIndex(projItem), // item image index
+ GetIconIndex(projItem), // selected item image
+ new FilewViewTreeItemData(projItem));
wxUnusedVar(hti);
}
@@ -827,8 +822,7 @@ void FileViewTree::OnAddExistingItem(wxCommandEvent& WXUNUSED(event))
return;
}
- const wxString ALL(
- wxT("All Files (*)|*|") wxT("C/C++ Source Files (*.c;*.cpp;*.cxx;*.cc)|*.c;*.cpp;*.cxx;*.cc|")
+ const wxString ALL(wxT("All Files (*)|*|") wxT("C/C++ Source Files (*.c;*.cpp;*.cxx;*.cc)|*.c;*.cpp;*.cxx;*.cc|")
wxT("C/C++ Header Files (*.h;*.hpp;*.hxx;*.hh;*.inl;*.inc)|*.h;*.hpp;*.hxx;*.hh;*.inl;*.inc"));
wxString vdPath = GetItemPath(item);
@@ -979,10 +973,8 @@ void FileViewTree::DoRemoveItems()
if((num > 1) && ((i + 1) < num)) {
// For multiple selections, use a YesToAll dialog
- wxRichMessageDialog dlg(wxTheApp->GetTopWindow(),
- message,
- _("Confirm"),
- wxYES_NO | wxYES_DEFAULT | wxCANCEL | wxCENTER | wxICON_QUESTION);
+ wxRichMessageDialog dlg(wxTheApp->GetTopWindow(), message, _("Confirm"),
+ wxYES_NO | wxYES_DEFAULT | wxCANCEL | wxCENTER | wxICON_QUESTION);
dlg.ShowCheckBox(_("Remember my answer and apply it all files"), false);
result = dlg.ShowModal();
ApplyToEachFileRemoval = dlg.IsCheckBoxChecked();
@@ -1002,8 +994,8 @@ void FileViewTree::DoRemoveItems()
// Remove the file. Do not fire an event here, we will send a "bulk" event
// with a list of all files removed
wxString fullpathOfFileRemoved;
- if(ManagerST::Get()
- ->RemoveFile(data->GetData().GetFile(), path, fullpathOfFileRemoved, false)) {
+ if(ManagerST::Get()->RemoveFile(
+ data->GetData().GetFile(), path, fullpathOfFileRemoved, false)) {
filesRemoved.Add(fullpathOfFileRemoved);
}
@@ -1017,11 +1009,8 @@ void FileViewTree::DoRemoveItems()
message << _("Do you also want to delete the file '") << name << _("' from disc?");
if((num > 1) && ((i + 1) < num)) {
// For multiple selections, use a YesToAll dialog
- wxRichMessageDialog dlg(wxTheApp->GetTopWindow(),
- message,
- _("Confirm"),
- wxYES_NO | wxYES_DEFAULT | wxCANCEL | wxCENTER |
- wxICON_QUESTION);
+ wxRichMessageDialog dlg(wxTheApp->GetTopWindow(), message, _("Confirm"),
+ wxYES_NO | wxYES_DEFAULT | wxCANCEL | wxCENTER | wxICON_QUESTION);
dlg.ShowCheckBox(_("Remember my answer and apply it all files"), false);
DeleteThisItemFromDisc = dlg.ShowModal();
ApplyToEachFileDeletion = dlg.IsCheckBoxChecked();
@@ -1032,7 +1021,7 @@ void FileViewTree::DoRemoveItems()
}
if((DeleteThisItemFromDisc == wxID_YES || DeleteThisItemFromDisc == wxYES) ||
- AlsoDeleteFromDisc) {
+ AlsoDeleteFromDisc) {
AlsoDeleteFromDisc = ApplyToEachFileDeletion; // If we're here, ApplyToAll means delete all
wxString message(_("An error occurred during file removal. Maybe it has been already "
@@ -1075,7 +1064,7 @@ void FileViewTree::DoRemoveVirtualFolder(wxTreeItemId& item)
{
wxString name = GetItemText(item);
wxString message(wxT("'") + name + wxT("'"));
- message << _(" and all its content will be removed from the project.");
+ message << _(" and all its contents will be removed from the project.");
if(wxMessageBox(message, _("CodeLite"), wxYES_NO | wxICON_WARNING) == wxYES) {
wxString path = GetItemPath(item);
@@ -1113,11 +1102,11 @@ wxTreeItemId FileViewTree::DoAddVirtualFolder(wxTreeItemId& parent, const wxStri
wxTreeItemId item;
ProjectItem itemData(path, text, wxEmptyString, ProjectItem::TypeVirtualDirectory);
- item = AppendItem(parent, // parent
- itemData.GetDisplayName(), // display name
- GetIconIndex(itemData), // item image index
- GetIconIndex(itemData), // selected item image
- new FilewViewTreeItemData(itemData));
+ item = AppendItem(parent, // parent
+ itemData.GetDisplayName(), // display name
+ GetIconIndex(itemData), // item image index
+ GetIconIndex(itemData), // selected item image
+ new FilewViewTreeItemData(itemData));
SortItem(parent);
Expand(parent);
@@ -1192,7 +1181,7 @@ void FileViewTree::OnLocalPrefs(wxCommandEvent& event)
EditorSettingsLocal dlg(higherOptions, lpnode, pLevel_project, this);
if(dlg.ShowModal() == wxID_OK &&
- LocalWorkspaceST::Get()->SetProjectOptions(dlg.GetLocalOpts(), GetItemText(item))) {
+ LocalWorkspaceST::Get()->SetProjectOptions(dlg.GetLocalOpts(), GetItemText(item))) {
clMainFrame::Get()->GetMainBook()->ApplySettingsChanges();
// Notify plugins that some settings have changed
PostCmdEvent(wxEVT_EDITOR_SETTINGS_CHANGED);
@@ -1221,8 +1210,8 @@ void FileViewTree::DoRemoveProject(const wxString& name)
int FileViewTree::OnCompareItems(const wxTreeItemId& item1, const wxTreeItemId& item2)
{
// used for SortChildren, reroute to our sort routine
- FilewViewTreeItemData* a = (FilewViewTreeItemData*)GetItemData(item1),
- * b = (FilewViewTreeItemData*)GetItemData(item2);
+ FilewViewTreeItemData *a = (FilewViewTreeItemData *)GetItemData(item1),
+ *b = (FilewViewTreeItemData *)GetItemData(item2);
if(a && b) return OnCompareItems(a, b);
return 0;
@@ -1234,7 +1223,7 @@ int FileViewTree::OnCompareItems(const FilewViewTreeItemData* a, const FilewView
if(a->GetData().GetKind() == ProjectItem::TypeVirtualDirectory && b->GetData().GetKind() == ProjectItem::TypeFile)
return -1;
else if(b->GetData().GetKind() == ProjectItem::TypeVirtualDirectory &&
- a->GetData().GetKind() == ProjectItem::TypeFile)
+ a->GetData().GetKind() == ProjectItem::TypeFile)
return 1;
// else let ascii fight it out
@@ -1507,11 +1496,11 @@ void FileViewTree::OnItemEndDrag(wxTreeEvent& event)
if(ManagerST::Get()->MoveFileToVD(filename, fromVD, targetVD)) {
// remove the item from its current node, and place it under the
// new parent node
- AppendItem(target, // parent
- itemData.GetDisplayName(), // display name
- GetIconIndex(itemData), // item image index
- GetIconIndex(itemData), // selected item image
- new FilewViewTreeItemData(itemData));
+ AppendItem(target, // parent
+ itemData.GetDisplayName(), // display name
+ GetIconIndex(itemData), // item image index
+ GetIconIndex(itemData), // selected item image
+ new FilewViewTreeItemData(itemData));
Delete(itemSrc);
Expand(target);
SendCmdEvent(wxEVT_FILE_VIEW_REFRESHED);
@@ -1556,10 +1545,9 @@ void FileViewTree::ExpandToPath(const wxString& project, const wxFileName& fileN
for(wxTreeItemId child = GetFirstChild(root, cookie); child.IsOk(); child = GetNextChild(root, cookie)) {
FilewViewTreeItemData* childData = static_cast<FilewViewTreeItemData*>(GetItemData(child));
if(childData->GetData().GetDisplayName() == project) {
- wxTreeItemId fileItem =
- fileName.GetName().IsEmpty() ?
- child :
- FindItemByPath(child, ManagerST::Get()->GetProjectCwd(project), fileName.GetFullPath());
+ wxTreeItemId fileItem = fileName.GetName().IsEmpty() ?
+ child :
+ FindItemByPath(child, ManagerST::Get()->GetProjectCwd(project), fileName.GetFullPath());
if(fileItem.IsOk()) {
// Now we're using a wxTR_MULTIPLE tree, we need to unselect here, otherwise all project files get
// selected
@@ -1592,7 +1580,7 @@ wxTreeItemId FileViewTree::FindItemByPath(wxTreeItemId& parent, const wxString&
if(!ItemHasChildren(parent)) return wxTreeItemId();
#if defined(__WXGTK__)
- wxString realpathItem = CLRealPath(fileName);
+ wxString realpathItem = CLRealPath(fileName);
#endif
wxTreeItemIdValue cookie;
@@ -1603,14 +1591,14 @@ wxTreeItemId FileViewTree::FindItemByPath(wxTreeItemId& parent, const wxString&
fn.MakeAbsolute(projectPath);
if(fn.GetFullPath().CmpNoCase(fileName) == 0) {
return child;
- }
+ }
#if defined(__WXGTK__)
- else { // Try again, dereferencing fn
- wxString fdest = CLRealPath(fn.GetFullPath());
- if(fdest.CmpNoCase(realpathItem) == 0) {
- return child;
- }
- }
+ else { // Try again, dereferencing fn
+ wxString fdest = CLRealPath(fn.GetFullPath());
+ if(fdest.CmpNoCase(realpathItem) == 0) {
+ return child;
+ }
+ }
#endif
if(ItemHasChildren(child)) {
@@ -1676,10 +1664,10 @@ void FileViewTree::OnImportDirectory(wxCommandEvent& e)
}
void FileViewTree::DoImportFolder(ProjectPtr proj,
- const wxString& baseDir,
- const wxArrayString& all_files,
- const wxString& filespec,
- bool extlessFiles)
+ const wxString& baseDir,
+ const wxArrayString& all_files,
+ const wxString& filespec,
+ bool extlessFiles)
{
wxStringTokenizer tok(filespec, wxT(";"));
wxStringSet_t specMap;
@@ -1707,12 +1695,12 @@ void FileViewTree::DoImportFolder(ProjectPtr proj,
for(size_t j = 0; j < dirs.GetCount() && cont; j++) {
wxString filepath = fn.GetPath();
if(dirs.Item(j) == wxT(".svn") || dirs.Item(j) == wxT(".cvs") || dirs.Item(j) == wxT(".arch-ids") ||
- dirs.Item(j) == wxT("arch-inventory") || dirs.Item(j) == wxT("autom4te.cache") ||
- dirs.Item(j) == wxT("BitKeeper") || dirs.Item(j) == wxT(".bzr") || dirs.Item(j) == wxT(".bzrignore") ||
- dirs.Item(j) == wxT("CVS") || dirs.Item(j) == wxT(".cvsignore") || dirs.Item(j) == wxT("_darcs") ||
- dirs.Item(j) == wxT(".deps") || dirs.Item(j) == wxT("EIFGEN") || dirs.Item(j) == wxT(".git") ||
- dirs.Item(j) == wxT(".hg") || dirs.Item(j) == wxT("PENDING") || dirs.Item(j) == wxT("RCS") ||
- dirs.Item(j) == wxT("RESYNC") || dirs.Item(j) == wxT("SCCS") || dirs.Item(j) == wxT("{arch}")) {
+ dirs.Item(j) == wxT("arch-inventory") || dirs.Item(j) == wxT("autom4te.cache") ||
+ dirs.Item(j) == wxT("BitKeeper") || dirs.Item(j) == wxT(".bzr") || dirs.Item(j) == wxT(".bzrignore") ||
+ dirs.Item(j) == wxT("CVS") || dirs.Item(j) == wxT(".cvsignore") || dirs.Item(j) == wxT("_darcs") ||
+ dirs.Item(j) == wxT(".deps") || dirs.Item(j) == wxT("EIFGEN") || dirs.Item(j) == wxT(".git") ||
+ dirs.Item(j) == wxT(".hg") || dirs.Item(j) == wxT("PENDING") || dirs.Item(j) == wxT("RCS") ||
+ dirs.Item(j) == wxT("RESYNC") || dirs.Item(j) == wxT("SCCS") || dirs.Item(j) == wxT("{arch}")) {
cont = false;
break;
}
@@ -1975,8 +1963,8 @@ void FileViewTree::OnRenameVirtualFolder(wxCommandEvent& e)
path = path.AfterFirst(wxT(':'));
ProjectPtr p = ManagerST::Get()->GetProject(proj);
if(!p) {
- wxLogMessage(_("failed to rename virtual folder: ") + path + _(", reason: could not locate project ") +
- proj);
+ wxLogMessage(
+ _("failed to rename virtual folder: ") + path + _(", reason: could not locate project ") + proj);
return;
}
@@ -2116,11 +2104,11 @@ bool FileViewTree::DoAddNewItem(wxTreeItemId& item, const wxString& filename, co
path += fnFileName.GetFullName();
ProjectItem projItem(path, fnFileName.GetFullName(), fnFileName.GetFullPath(), ProjectItem::TypeFile);
- wxTreeItemId hti = AppendItem(item, // parent
- projItem.GetDisplayName(), // display name
- GetIconIndex(projItem), // item image index
- GetIconIndex(projItem), // selected item image
- new FilewViewTreeItemData(projItem));
+ wxTreeItemId hti = AppendItem(item, // parent
+ projItem.GetDisplayName(), // display name
+ GetIconIndex(projItem), // item image index
+ GetIconIndex(projItem), // selected item image
+ new FilewViewTreeItemData(projItem));
wxUnusedVar(hti);
SortItem(item);
Expand(item);
@@ -2548,3 +2536,29 @@ void FileViewTree::FolderDropped(const wxArrayString& folders)
dummy.SetStrings(folders);
OnFolderDropped(dummy);
}
+
+void FileViewTree::OnOpenShellFromFilePath(wxCommandEvent& e)
+{
+ wxUnusedVar(e);
+ wxTreeItemId item = GetSingleSelection();
+ if(item.IsOk()) {
+ FilewViewTreeItemData* data = static_cast<FilewViewTreeItemData*>(GetItemData(item));
+ if(data->GetData().GetKind() == ProjectItem::TypeFile) {
+ wxFileName fn(data->GetData().GetFile());
+ FileUtils::OpenTerminal(fn.GetPath());
+ }
+ }
+}
+
+void FileViewTree::OnOpenFileExplorerFromFilePath(wxCommandEvent& e)
+{
+ wxUnusedVar(e);
+ wxTreeItemId item = GetSingleSelection();
+ if(item.IsOk()) {
+ FilewViewTreeItemData* data = static_cast<FilewViewTreeItemData*>(GetItemData(item));
+ if(data->GetData().GetKind() == ProjectItem::TypeFile) {
+ wxFileName fn(data->GetData().GetFile());
+ FileUtils::OpenFileExplorerAndSelect(fn.GetFullPath());
+ }
+ }
+}