Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small stuff #2

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified Assets/Screenshots/CommandSelectWindow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerCommands.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerIconMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerIconPrefs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerMenu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Assets/Screenshots/TrackRunnerPrefs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Assets/UserGuide/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Command Management Window


The command management window allows you to add/edit/remove/sort shortcuts.
You can drag'n'drop a script to replace the currently shown command path.
If the command is a script, the `Show in Tracker` button will open its location in a Tracker window. From there you can rename it or open it in an editor etc.


Command List
Expand Down
78 changes: 78 additions & 0 deletions Source/CommandsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
#include <IconUtils.h>
#include <LayoutBuilder.h>
#include <ListView.h>
#include <NodeInfo.h>
#include <Path.h>
#include <Resources.h>
#include <Roster.h>
#include <ScrollView.h>
#include <StringView.h>
#include <private/shared/ToolBar.h>
Expand All @@ -32,6 +34,7 @@ enum {
kUserGuideAction = 'GiDe',
kListSelectAction = 'LsTs',
kBrowseCommandAction = 'BrWz',
kShowCommandAction = 'SwWz',
kListUpdateAction = 'LsUp'
};

Expand Down Expand Up @@ -81,6 +84,7 @@ CommandsWindow::CommandsWindow(BString& title)
.SetInsets(0)
.Add(fBrowseButton = new BButton("Browse" B_UTF8_ELLIPSIS, new BMessage(kBrowseCommandAction)))
.AddGlue()
.Add(fShowButton = new BButton("Show in Tracker", new BMessage(kShowCommandAction)))
.End()
.Add(fTerminalCheckBox, 1, 3)
.End()
Expand Down Expand Up @@ -121,6 +125,9 @@ CommandsWindow::MessageReceived(BMessage* message)
case kBrowseCommandAction:
_BrowseCommand();
break;
case kShowCommandAction:
_ShowCommand();
break;
case kDeleteCommandAction:
_DeleteCommand();
break;
Expand Down Expand Up @@ -173,6 +180,73 @@ CommandsWindow::_BrowseCommand()
}


void
CommandsWindow::_ShowCommand()
{
BEntry itemEntry(_Deescape(fCommandControl->Text()));
status_t status = itemEntry.InitCheck();
if (status == B_OK) {
BEntry parentDirectory;
status = itemEntry.GetParent(&parentDirectory);
if (status == B_OK) {
entry_ref ref;
status = parentDirectory.GetRef(&ref);
if (status == B_OK) {
node_ref nref;
status = itemEntry.GetNodeRef(&nref);
if (status == B_OK)
_ShowInTracker(ref, &nref);
}
}
}
}


status_t
CommandsWindow::_ShowInTracker(const entry_ref& ref, const node_ref* nref)
{
status_t status = B_ERROR;

BMessenger tracker("application/x-vnd.Be-TRAK");
if (tracker.IsValid()) {
BMessage message(B_REFS_RECEIVED);
message.AddRef("refs", &ref);

if (nref != NULL)
message.AddData("nodeRefToSelect", B_RAW_TYPE, (void*)nref, sizeof(node_ref));

status = tracker.SendMessage(&message);
}
return status;
}


bool
CommandsWindow::_CommandIsScript()
{
BPath path = _Deescape(fCommandControl->Text());
if (path.InitCheck() != B_OK)
return false;

char mimeType[B_MIME_TYPE_LENGTH];
BNode commandNode(path.Path());
BNodeInfo(&commandNode).GetType(mimeType);
if (strncmp("text/", mimeType, 5) == 0)
return true;

return false;
}


const char*
CommandsWindow::_Deescape(const char* path)
{
BString text(path);
text.CharacterDeescape('\\');
return text.String();
}


void
CommandsWindow::_InitNewCommand()
{
Expand Down Expand Up @@ -230,6 +304,7 @@ CommandsWindow::_SelectItem()
fCommandControl->SetEnabled(true);

fBrowseButton->SetEnabled(true);
fShowButton->SetEnabled(true);

fTerminalCheckBox->SetValue(item->UseTerminal());
fTerminalCheckBox->SetEnabled(true);
Expand All @@ -252,6 +327,8 @@ CommandsWindow::_UpdateItem()
fListView->InvalidateItem(fListView->CurrentSelection());
}

fShowButton->SetEnabled(_CommandIsScript());

_SaveCommands();
}

Expand Down Expand Up @@ -319,6 +396,7 @@ CommandsWindow::_InitControls()
fCommandControl->SetEnabled(false);

fBrowseButton->SetEnabled(false);
fShowButton->SetEnabled(false);

fTerminalCheckBox->SetValue(1);
fTerminalCheckBox->SetEnabled(false);
Expand Down
5 changes: 5 additions & 0 deletions Source/CommandsWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ class CommandsWindow : public BWindow {
void _SelectItem();
void _UpdateItem();
void _BrowseCommand();
void _ShowCommand();
status_t _ShowInTracker(const entry_ref& ref, const node_ref* nref = NULL);
bool _CommandIsScript();
const char* _Deescape(const char* path);
void _RefsReceived(BMessage* message);
status_t _LoadCommands();
status_t _SaveCommands();
BBitmap* _ResourceBitmap(const char* name, float width, float height);

BButton* fBrowseButton;
BButton* fShowButton;
BCheckBox* fTerminalCheckBox;
BListView* fListView;
BFilePanel* fBrowsePanel;
Expand Down