Skip to content

Commit

Permalink
Add support for open-with #195
Browse files Browse the repository at this point in the history
  • Loading branch information
DamirPorobic committed Oct 17, 2019
1 parent 622c6da commit 985ce71
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@
* New: Provide option to use previous capture area. ([#150](https://github.com/DamirPorobic/kImageAnnotator/issues/150))
* New: Add System Tray Icon. ([#163](https://github.com/DamirPorobic/kImageAnnotator/issues/163))
* New: Show tray icon notification after image was uploaded to imgur or saved. ([#220](https://github.com/DamirPorobic/kImageAnnotator/issues/220))
* New: Add support for Open-with. ([#195](https://github.com/DamirPorobic/kImageAnnotator/issues/195))
* New kImageAnnotator: Edit text box content. ([#51](https://github.com/DamirPorobic/kImageAnnotator/issues/51))
* New kImageAnnotator: Panning image by holding space or mouse middle button and dragging. ([#9](https://github.com/DamirPorobic/kImageAnnotator/issues/9))
* New kImageAnnotator: Change annotation element config after drawing. ([#44](https://github.com/DamirPorobic/kImageAnnotator/issues/44))
Expand Down
20 changes: 11 additions & 9 deletions src/backend/KsnipCommandLine.cpp
Expand Up @@ -26,7 +26,8 @@ KsnipCommandLine::KsnipCommandLine(const QCoreApplication &app, const QList<Capt
addVersionOptions();
addImageGrabberOptions(captureModes);
addDefaultOptions();
process(app);
addPositionalArguments();
process(app);
}

KsnipCommandLine::~KsnipCommandLine()
Expand Down Expand Up @@ -140,7 +141,7 @@ bool KsnipCommandLine::isCursorSet() const

bool KsnipCommandLine::isEditSet() const
{
return mEditOption != nullptr && isSet(*mEditOption);
return (mEditOption != nullptr && isSet(*mEditOption)) || positionalArguments().count() == 1;
}

bool KsnipCommandLine::isSaveSet() const
Expand All @@ -157,16 +158,12 @@ int KsnipCommandLine::delay() const
{
auto valid = true;
auto delay = value(*mDelayOption).toInt(&valid);
if (!valid || delay < 0) {
return -1;
} else {
return delay;
}
return valid && delay >= 0 ? delay : -1;
}

QString KsnipCommandLine::image() const
QString KsnipCommandLine::imagePath() const
{
return value(*mEditOption);
return positionalArguments().count() == 1 ? positionalArguments().first() : value(*mEditOption);
}

bool KsnipCommandLine::isCaptureModeSet() const
Expand All @@ -190,3 +187,8 @@ CaptureModes KsnipCommandLine::captureMode() const
return CaptureModes::RectArea;
}
}

void KsnipCommandLine::addPositionalArguments()
{
addPositionalArgument(QStringLiteral("image"), QStringLiteral("Edit existing image in ksnip"), QStringLiteral("[image]"));
}
3 changes: 2 additions & 1 deletion src/backend/KsnipCommandLine.h
Expand Up @@ -45,7 +45,7 @@ class KsnipCommandLine : public QCommandLineParser
bool isVersionSet() const;
bool isCaptureModeSet() const;
int delay() const;
QString image() const;
QString imagePath() const;
CaptureModes captureMode() const;

private:
Expand All @@ -67,6 +67,7 @@ class KsnipCommandLine : public QCommandLineParser
QString translateText(const QString &text);
QCommandLineOption* addOption(const QString &shortName, const QString &longName, const QString &description);
QCommandLineOption* addParameterOption(const QString &shortName, const QString &longName, const QString &description, const QString &parameter);
void addPositionalArguments();
};

#endif //KSNIP_KSNIPCOMMANDLINE_H
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -65,7 +65,7 @@ int main(int argc, char** argv)
}

if (commandLine.isEditSet()) {
auto pathToImage = commandLine.image();
auto pathToImage = commandLine.imagePath();
QPixmap pixmap(pathToImage);

if (pixmap.isNull()) {
Expand Down

0 comments on commit 985ce71

Please sign in to comment.