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

Add option to open folder recursively #50

Closed
wants to merge 1 commit into from
Closed
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
Add option to open folder recursively
  • Loading branch information
FLeXyo committed Feb 18, 2021
commit 02e515a87e1584c0d5a1d178574c5a24620a960e
1,698 changes: 856 additions & 842 deletions quick-picture-viewer/MainForm.Designer.cs

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions quick-picture-viewer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public partial class MainForm : Form
private Point panelMouseDownLocation;
private bool fullscreen = false;
private string currentFolder;
private string selectedFolder;
private string currentFile;
private bool alwaysOnTop = false;
private bool imageChanged = false;
Expand Down Expand Up @@ -196,6 +197,7 @@ private void InitLanguage()
externalChooseBtn.Text = LangMan.Get("open-with-choose") + " ...";

openButton.Text = LangMan.Get("open-file") + " | Ctrl+O";
openFolderButton.Text = LangMan.Get("open-folder") + " | Ctrl+Shift+O";
saveAsButton.Text = LangMan.Get("save-as") + " | Ctrl+S";
pasteButton.Text = LangMan.Get("paste-image") + " | Ctrl+V";
checkboardButton.Text = LangMan.Get("checkboard-background") + " | Ctrl+B";
Expand Down Expand Up @@ -266,10 +268,25 @@ private void openButton_Click_1(object sender, EventArgs e)
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
openFile(openFileDialog1.FileName);
selectedFolder = null;
}
openFileDialog1.Dispose();
}

private void openFolderButton_Click(object sender, EventArgs e)
{
setSlideshow(false);

openFolderDialog1.Description = LangMan.Get("open-folder");

if(openFolderDialog1.ShowDialog() == DialogResult.OK)
{
currentFolder = openFolderDialog1.SelectedPath;
selectedFolder = openFolderDialog1.SelectedPath;
openFile(getCurrentFiles(true).FirstOrDefault());
}
}

private void MainForm_Load(object sender, EventArgs e)
{
try
Expand Down Expand Up @@ -1272,6 +1289,10 @@ private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
miniViewButton.PerformClick();
}
else if (e.KeyCode == Keys.O)
{
openFolderButton.PerformClick();
}
}
else
{
Expand Down Expand Up @@ -1434,7 +1455,8 @@ private void onTopButton_Click(object sender, EventArgs e)

public int nextFile()
{
string[] filePaths = getCurrentFiles();

string[] filePaths = selectedFolder != null ? getCurrentFiles(true) : getCurrentFiles();

int currentIndex = -1;
for (int i = 0; i < filePaths.Length; i++)
Expand Down Expand Up @@ -1474,7 +1496,7 @@ private void nextButton_Click(object sender, EventArgs e)

public void prevFile()
{
string[] filePaths = getCurrentFiles();
string[] filePaths = selectedFolder != null ? getCurrentFiles(true) : getCurrentFiles();

int currentIndex = -1;
for (int i = 0; i < filePaths.Length; i++)
Expand Down Expand Up @@ -1508,14 +1530,14 @@ private void prevButton_Click(object sender, EventArgs e)
prevFile();
}

private string[] getCurrentFiles()
private string[] getCurrentFiles(bool recursive = false)
{
string[] exts = { ".png", ".jpg", ".jpeg", ".jpe", ".jfif", ".exif", ".gif", ".bmp", ".dib", ".rle", ".ico", ".webp", ".svg", ".dds", ".tga", ".psd" };
List<string> arlist = new List<string>();

if (currentFolder != null)
{
string[] allFiles = Directory.GetFiles(currentFolder);
string[] allFiles = recursive ? Directory.GetFiles(selectedFolder, "*", System.IO.SearchOption.AllDirectories) : Directory.GetFiles(currentFolder);
for (int i = 0; i < allFiles.Length; i++)
{
string ext = Path.GetExtension(allFiles[i]).ToLower();
Expand Down Expand Up @@ -1677,6 +1699,7 @@ private void SetDarkMode(bool dark)
statusStrip1.BackColor = ThemeMan.DarkSecondColor;

openButton.Image = Properties.Resources.white_open;
openFolderButton.Image = Properties.Resources.white_picfolder;
saveAsButton.Image = Properties.Resources.white_saveas;
printButton.Image = Properties.Resources.white_print;
deleteBtn.Image = Properties.Resources.white_trash;
Expand Down Expand Up @@ -2467,5 +2490,5 @@ private void showToolbarBtn_Click(object sender, EventArgs e)
Properties.Settings.Default.ShowToolbar = toolStrip1.Visible;
Properties.Settings.Default.Save();
}
}
}
}
Loading