Apparently there was a newer version, this one are not dependent on the path to terminal.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32355 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007 - 2008 Chris Roberts. All rights reserved.
|
* Copyright 2007 - 2009 Chris Roberts. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
@@ -8,45 +8,106 @@
|
|||||||
|
|
||||||
#include <StorageKit.h>
|
#include <StorageKit.h>
|
||||||
#include <SupportKit.h>
|
#include <SupportKit.h>
|
||||||
|
#include <AppKit.h>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include <add-ons/tracker/TrackerAddOn.h>
|
#include <add-ons/tracker/TrackerAddOn.h>
|
||||||
|
|
||||||
#define APPLICATION "/boot/system/apps/Terminal &"
|
const char* kTerminalSignature = "application/x-vnd.Haiku-Terminal";
|
||||||
// The trailing '&' is so that it forks to the background and doesn't block
|
const directory_which kAppsDirectory = B_SYSTEM_APPS_DIRECTORY;
|
||||||
//execution
|
|
||||||
|
|
||||||
void
|
void
|
||||||
launch_terminal(BEntry* entry)
|
launch_terminal(BEntry* targetEntry, BPath* terminalPath) {
|
||||||
{
|
|
||||||
BPath path;
|
BPath targetPath;
|
||||||
if (entry->GetPath(&path) != B_OK)
|
|
||||||
|
if (targetEntry->GetPath(&targetPath) != B_OK)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
chdir(path.Path());
|
// Escape paths which contain an apostraphe
|
||||||
system (APPLICATION);
|
BString target(targetPath.Path());
|
||||||
|
target.ReplaceAll("'", "'\\''");
|
||||||
|
|
||||||
|
BString terminal(terminalPath->Path());
|
||||||
|
terminal.ReplaceAll("'", "'\\''");
|
||||||
|
|
||||||
|
// Build the command to "cd '/my/target/folder'; '/path/to/Terminal' &"
|
||||||
|
BString command("cd '");
|
||||||
|
command << target << "'; '" << terminal << "' &";
|
||||||
|
|
||||||
|
// Launch the Terminal.
|
||||||
|
system(command.String());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
process_refs(entry_ref base_ref, BMessage* message, void* reserved)
|
process_refs(entry_ref base_ref, BMessage* message, void* reserved)
|
||||||
{
|
{
|
||||||
|
BPath terminalPath;
|
||||||
|
|
||||||
|
bool terminalFound = false;
|
||||||
|
|
||||||
|
// Search for Terminal path by asking BRoster.
|
||||||
|
entry_ref terminalRef;
|
||||||
|
if (be_roster->FindApp(kTerminalSignature, &terminalRef) == B_OK) {
|
||||||
|
if (terminalPath.SetTo(&terminalRef) == B_OK)
|
||||||
|
terminalFound = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fall back to manually creating a path if BRoster didn't find it.
|
||||||
|
if (!terminalFound) {
|
||||||
|
if (find_directory(kAppsDirectory, &terminalPath) != B_OK)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (terminalPath.Append("Terminal") != B_OK)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
BEntry entry;
|
BEntry entry;
|
||||||
int32 i;
|
int32 i;
|
||||||
entry_ref tracker_ref;
|
entry_ref tracker_ref;
|
||||||
|
vector<BEntry> entries;
|
||||||
|
|
||||||
for (i = 0; message->FindRef("refs", i, &tracker_ref) == B_OK; i++) {
|
// Iterate through the refs that Tracker has sent us.
|
||||||
// Pass 'true' as the traverse argument so that if the ref is a
|
for (i = 0; message->FindRef("refs", i, &tracker_ref) == B_OK; i++) {
|
||||||
// symbolic link, we get the target of the link to ensure that it
|
|
||||||
// actually exists
|
// Pass 'true' as the traverse argument below, so that if the ref
|
||||||
if (entry.SetTo(&tracker_ref, true) == B_OK) {
|
// is a symbolic link we get the target of the link to ensure that
|
||||||
if (entry.IsDirectory())
|
// it actually exists.
|
||||||
launch_terminal(&entry);
|
if (entry.SetTo(&tracker_ref, true) != B_OK)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// If the entry is a file then look for the parent directory.
|
||||||
|
if (!entry.IsDirectory()) {
|
||||||
|
if (entry.GetParent(&entry) != B_OK)
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool duplicate = false;
|
||||||
|
|
||||||
|
// Check for duplicates.
|
||||||
|
for (uint x = 0; x < entries.size(); x++) {
|
||||||
|
if (entries[x] == entry) {
|
||||||
|
duplicate = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is a duplicate. Continue to next ref.
|
||||||
|
if (duplicate)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
// Push entry onto the vector so we can check for duplicates later.
|
||||||
|
entries.push_back(BEntry(entry));
|
||||||
|
|
||||||
|
launch_terminal(&entry, &terminalPath);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// No folders were selected so we'll use the base folder
|
// If nothing was selected we'll use the base folder.
|
||||||
if (i == 0) {
|
if (i == 0) {
|
||||||
if (entry.SetTo(&base_ref) == B_OK)
|
if (entry.SetTo(&base_ref) == B_OK)
|
||||||
launch_terminal(&entry);
|
launch_terminal(&entry, &terminalPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user