-
Notifications
You must be signed in to change notification settings - Fork 2
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
Small stuff #2
Conversation
humdingerb
commented
Feb 20, 2024
- Accept files dropped on the CommandsWindow
- Add an "Edit" button that opens a command script in the editor
- Update user guide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on it! I need to add a better way to get the path from the command string for this as well as the icon lookup code.
Source/CommandsWindow.cpp
Outdated
.AddGlue() | ||
.Add(fEditButton = new BButton("Edit" B_UTF8_ELLIPSIS, new BMessage(kEditCommandAction))) | ||
.End() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still debating about the text of the button. It might be better to be more explicit and say "Edit file". We can probably leave it like this for now until I get around to adding translation support.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about icon buttons. A folder icon for the "Browse" and a text icon + pen for the "Edit"?
Those could be put to the right of the BTextControl which would free up the space below as a positive side-effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not against having icons but I was more concerned about making it clear that the file would be opened, instead of opening an editor that could be used to edit the current command line arguments. Maybe I'm overthinking it or not giving the users enough credit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it's really a problem. I think the user will click on the icon and sees what happens and will know now what it exactly does. It's non-destructive, so nothing can really go wrong. Plus we can add a tooltip.
Source/CommandsWindow.cpp
Outdated
void | ||
CommandsWindow::_EditCommand() | ||
{ | ||
if (_CommandIsScript()) { | ||
const char* argv[] = { fCommandControl->Text(), NULL }; | ||
be_roster->Launch("text/x-source-code", 1, argv); | ||
} | ||
} | ||
|
||
|
||
bool | ||
CommandsWindow::_CommandIsScript() | ||
{ | ||
BPath path = 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; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is going to cause a problem if fCommandControl
has shell escapes/quotes in the command or command line arguments. For example, if the command was /boot/home/myscript.sh --myarg
then it would need to have the --myarg
removed. I have some really ugly and crude code at
TrackRunner/Source/RunnerAddOn.cpp
Line 191 in 0268125
// attempt to find the actual file by splitting the command/arguments at the spaces |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haven't thought about that...
It'd be easiest and probably most robust to split that in two BTextControls:
Command/Script: /boot/home/myscript.sh
Arguments: --myarg 5038 --myarg2 etc.
Or do you deem that too crude... :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly I've thought about splitting it up, and I may end up doing that eventually, but I was really avoiding doing that because I think it makes the user interface more cumbersome to use. Much easier to see or type out a whole command in one input box. I'll have to think about it to see if there are any other consequences of changing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One problem is going to be migrating existing users to the new system. It would be difficult to automatically convert the old commands to the split version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True. Good luck with your command/argument parse&split then... :)
I'm currently having the hardest time with script filename with a space. The path needs to be escaped when actually running the command, but deescaped when launching the script for editing in a text editor (_EditCommand()) and checking if to enable the edit button (_CommandIsScript()). I'll keep at it for a bit... |
a8f29f9
to
096e741
Compare
Quick question: I'm only used to our simple makefile_engine makefiles. How can I build a debug version with cmake? |
Unfortunately this is only one of many possible variations. It doesn't necessarily even have to do with spaces. I could quote a command like |
|
thanks! |
It seems like someone has probably created a regular expression to do the splitting and that's probably the most reliable way to do it. A quick search kept giving me results for splitting inside of bash but that's not what I want. I'll have to do a more thorough search when I get time. |
096e741
to
c05fe36
Compare
JFYI, "Edit file..." now works with spaces in filenames. I'm unsure why, but it does after changing
to
|
c05fe36
to
e0204f0
Compare
It doesn't look like it handles command line arguments though. I can probably come up with other examples that won't get parsed properly and I'd like to have the button working more reliably before it gets put into the app. |
Correct. Once you've solved the hard problem of parsing out the command/script from the arguments - :) - it should be easy to provide _CommandIsScript() and _EditCommand() with the correct path. |
I haven't forgotten about this but I'm still undecided about the edit button. If you want to split the DnD part into a separate PR then I'll merge it. |
OK, moved the d'n'd to #5. |
After more thinking, I would probably prefer having a "Show in Tracker" button instead of "Edit File". Once it's clicked and the file is shown in Tracker then the user could edit/rename/copy/whatever... Would this be something that you want to work on? |
* _CommandIsScript() simply checks if the command's path is valid and points to a text file. * _ShowCommand() opens the current script's location in Tracker and selects it. * Only enable the "Show in Tracker" button, if the command is a text file. It stays disabled, e.g. for a simple CLI command like /bin/ls.
* Mention the new "Show in Tracker" button and drag'n'drop of a script file to set the command. * Updated screenshot. * Optimized all PNGs.
Yes. As it happens, I worked on something similar to "Show in Tracker" for Genio recently. I could therefore very easily adopt that code. :) |
Nice. Thanks for working on it. I'll try to find some time to put out a new release. |
Very good! |