Skip to content

Commit

Permalink
Apply open link / open file to multiple files (#322)
Browse files Browse the repository at this point in the history
Loop through all selected cells and open the files / links
  • Loading branch information
tobiolo committed Dec 30, 2022
1 parent de21ad9 commit 9607a9a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 13 deletions.
50 changes: 37 additions & 13 deletions src/document.h
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,43 @@ struct Document {
Refresh();
return nullptr;
}

case A_BROWSE: {
const wxChar *returnmessage = nullptr;
int counter = 0;
loopallcellssel(c, true) {
if (counter >= MAX_LAUNCHES) {
returnmessage = _(L"Maximum number of launches reached.");
break;
}
if (!wxLaunchDefaultBrowser(c->text.ToText(0, selected, A_EXPTEXT))) {
returnmessage = _(L"The browser could not open at least one link.");
} else {
counter++;
}
}
return returnmessage;
}

case A_BROWSEF: {
const wxChar *returnmessage = nullptr;
int counter = 0;
loopallcellssel(c, true) {
if (counter >= MAX_LAUNCHES) {
returnmessage = _(L"Maximum number of launches reached.");
break;
}
wxString f = c->text.ToText(0, selected, A_EXPTEXT);
wxFileName fn(f);
if (fn.IsRelative()) fn.MakeAbsolute(wxFileName(filename).GetPath());
if (!wxLaunchDefaultApplication(fn.GetFullPath())) {
returnmessage = _(L"At least one file could not be opened.");
} else {
counter++;
}
}
return returnmessage;
}
}

if (c || (!c && selected.IsAll())) {
Expand Down Expand Up @@ -1586,19 +1623,6 @@ struct Document {
case A_NEXT: selected.Next(this, dc, false); return nullptr;
case A_PREV: selected.Next(this, dc, true); return nullptr;

case A_BROWSE:
if (!wxLaunchDefaultBrowser(c->text.ToText(0, selected, A_EXPTEXT)))
return _(L"Cannot launch browser for this link.");
return nullptr;

case A_BROWSEF: {
wxString f = c->text.ToText(0, selected, A_EXPTEXT);
wxFileName fn(f);
if (fn.IsRelative()) fn.MakeAbsolute(wxFileName(filename).GetPath());
if (!wxLaunchDefaultApplication(fn.GetFullPath())) return _(L"Cannot find file.");
return nullptr;
}

case A_IMAGECPY: {
if (selected.Thin()) return NoThin();
if (!c->text.image) return _(L"No image in this cell.");
Expand Down
2 changes: 2 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ int g_grid_left_offset = 15;
int g_scrollratecursor = 240; // FIXME: must be configurable
int g_scrollratewheel = 2; // relative to 1 step on a fixed wheel usually being 120

const int MAX_LAUNCHES = 20;

static uint celltextcolors[] = {
0xFFFFFF, // CUSTOM COLOR!
0xFFFFFF, 0x000000, 0x202020, 0x404040, 0x606060, 0x808080, 0xA0A0A0, 0xC0C0C0, 0xD0D0D0,
Expand Down

0 comments on commit 9607a9a

Please sign in to comment.