From 69955dd988866c9260bc7f8363616569a850f3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Wed, 21 Oct 2009 08:33:17 +0000 Subject: [PATCH] Add a --name argument to preset the name of the file to save. I should probably use getopts() here... git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33692 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/bin/filepanel.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bin/filepanel.cpp b/src/bin/filepanel.cpp index a02d0ebddf..3f66e6f7de 100644 --- a/src/bin/filepanel.cpp +++ b/src/bin/filepanel.cpp @@ -96,6 +96,7 @@ usage(char *pname, int error) fprintf(stderr, "-d\t--directory\topen at \n"); fprintf(stderr, "-l\t--load\tuse a load FilePanel (default)\n"); fprintf(stderr, "-s\t--save\tuse a save FilePanel\n"); + fprintf(stderr, "-n\t--name\tset the default name for saving\n"); fprintf(stderr, "-k\t--kind\tkind of entries that can be opened (flavour): any combination of f, d, s (file (default), directory, symlink)\n"); fprintf(stderr, "-t\t--title\tset the FilePanel window title\n"); fprintf(stderr, "-1\t--single\tallow only 1 file to be selected\n"); @@ -120,6 +121,7 @@ main(int argc, char **argv) char *windowTitle = NULL; bool allowMultiSelect = true; bool makeModal = false; + const char *defaultName = NULL; for (i = 1; i < argc; i++) { if (strncmp(argv[i], "--", 2) && ((*(argv[i]) == '-' && strlen(argv[i]) != 2) || *(argv[i]) != '-')) { @@ -138,6 +140,12 @@ main(int argc, char **argv) fpMode = B_OPEN_PANEL; } else if (!strcmp(argv[i], "--save") || !strcmp(argv[i], "-s")) { fpMode = B_SAVE_PANEL; + } else if (!strcmp(argv[i], "--name") || !strcmp(argv[i], "-n")) { + if (++i >= argc) { + fprintf(stderr, "%s: this option requires a parameter\n", argv[i-1]); + return usage(argv[0], 2); + } + defaultName = (const char *)argv[i]; } else if (!strcmp(argv[i], "--kind") || !strcmp(argv[i], "-k")) { if (++i >= argc) { fprintf(stderr, "%s: this option requires a parameter\n", argv[i-1]); @@ -182,6 +190,8 @@ main(int argc, char **argv) fPanel->SetPanelDirectory(openAt); if (windowTitle) fPanel->Window()->SetTitle(windowTitle); + if (fpMode == B_SAVE_PANEL && defaultName) + fPanel->SetSaveText(defaultName); fPanel->Show(); /**/