From 8e57f48cb7a6cf7fe85d65ba72f58e1f04843a03 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 11 Jul 2015 13:10:57 +0000 Subject: [PATCH] + presets & macros (WIP) --- .../net/filebot/resources/action.script.png | Bin 0 -> 861 bytes source/net/filebot/resources/script.add.png | Bin 0 -> 1292 bytes .../net/filebot/resources/script.remove.png | Bin 0 -> 1287 bytes source/net/filebot/ui/rename/Preset.java | 122 ++++++++++++++ source/net/filebot/ui/rename/RenamePanel.java | 152 +++++++++++++++++- 5 files changed, 268 insertions(+), 6 deletions(-) create mode 100755 source/net/filebot/resources/action.script.png create mode 100755 source/net/filebot/resources/script.add.png create mode 100755 source/net/filebot/resources/script.remove.png create mode 100644 source/net/filebot/ui/rename/Preset.java diff --git a/source/net/filebot/resources/action.script.png b/source/net/filebot/resources/action.script.png new file mode 100755 index 0000000000000000000000000000000000000000..56fcf84a8518f692988061347375c9f6ff8d0dae GIT binary patch literal 861 zcmV-j1ETziP)-~Z!n@9pW{oO5sFQkR#oNEERoq9}~OLlE7(C>^?38iHU~FCGf)7!g^i zr#b|KB0a>q#9E#VC2d>I$+ouU+sE5`|IdEEpe##p>ifB)xbn@_=$0}CvEq;yxiY$Ba;K;UP=U?3g05+4N(N2oSY9}8}Qr5e<+2svC{=In|=VE{& z%bNW?0hoJ|s|0~KAd2a&g!c4?qA*m6I5b-GRHHul#pL5pLx4O@`|B}T!Fm#Cr9A1< z>d@-2vc=Ly4lZ7Q=-61@^Fx(gF+iTCgWG#Tn_V_LxiAdGh$6y>NFWL*5aerqn_hMM zVe4@WkS9sAQH!*;GVN|D3`%4zyI{*%a_aem2=mJ zaOvo?dn~M#W*2kyDxFqK6h)fNrs3gXwJQC6lx1LjecjyLoayOlah@b^;KUzyXRL0; zHoB!WFBREABOCJu2N#TujhP((+Eh^5^Ym^jD=Y5Yx$`A1#Ce(?e*3i-Y9F6`2>|3J z*S?v;fQ5wxM-Cs<>2%D@%xE+k@LsJ}dq2+8bY@|><=V}=2Da4<^j8hkdo}941_p;* zy?WILAD%V!`=rIiMayN=ty`a$S(e?rapOiF96EVr21Po+|=RvfC` nv$VA2&+^D$IC=Zp*(vxR7Y$Nw@UeaB00000NkvXXu0mjf2&J7q literal 0 HcmV?d00001 diff --git a/source/net/filebot/resources/script.add.png b/source/net/filebot/resources/script.add.png new file mode 100755 index 0000000000000000000000000000000000000000..aedecc2fb2dfb9d1142ccf13d7f7cc376637d408 GIT binary patch literal 1292 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmUzPnffIy#(^vlDyqr zfHV;NblzPLq&N#aB8!2v2N=7Z%(epwmK8Xr18J~%3^B*n9%f)*I_2r&7-Dfcbn@Bk zm{gHt_3wY*vooCMn02P6zdyRs@)a9lSPa+D1-K_42fLb9cT!ZX0{%#xZs|i|*pO=N}FPDlr|{ z*q<-McJ9sX$eAZ&9G`K;1YY>)%Cx0{SAl^yLHLKj4vCB55C2XMer%oQXJdY;^m`C&;5Wldg>&U?{KF{sX&+@I=&djh}EPUq8=%*JaR+!vkli0U^ ziD$9LZpO8uf(bks%xtZJ0SsCuk^8Pan0|Fh9e={xh};7cN^BzaGIS+)tu%VrniF^w z+P0>hySe^f9@Fu6OnbIYPHr~z4FABuq^7au%O-PKpetG-5(T1N- zD%SdBu`WHR(aL7B;FqnJ153?3;T$;zrG}lY`s_-Jy`M%TJ3A;hT!_9W9o}&5fzyJy zX>u9&SbyB<3tKH(Vz0t7g{jx+*Vn15z5kTHEslz8R-8L?$=))lXZQMkJ-;s=>g^)c z6V~F?=%HW8y8qu#!Pz&j@A+^>*oVjd%+jg;S3bSpF1GCcjjh4<*843Ut&O$VQ*XX~ z)}gOk54;Ui*ec)>;PoRjb>i{w{(>b5uMS2w75T_la6R~{5mC)j@$$L${|hf%wiF*^ zRV?Rv&0V9Bq55BFwd|fBC$bslSQO1$djA~b{Ln=Y?ko(SU!U_}?c&S-e>W;TXiBi% zQ>2x+^dIx|*Y^vHzA@k1Suv+eley&VkH($tZCO{Rn@9Iu{W|4q+Vr$%1#t#Z!Cj(? zPij6N7pgw?ZNtR7DxTMW{`<7uWc#PhuO3`9Rz6^3z-e>gd%*pzUYdQ{Qzb%oxv1*| zdx!@}o~S-J-{TcTH+c}l3bLUSdyxn0wfrW3=AxF4Gnb-%|eWf ztPCxz49#^7%&iOzq8a`jglPb&w1VgYYA`g=H2`Wb3^6dXGBvU?HGybYW_;ZQMMG|W zN@iLmZVlJ-@;iVUl0Z)K$xKeoD^6v|C@Cqh($@#um06aWoS&PUpI5AxUzDz&15r|} zpH!)DtY@IFkYA)gq;exYQ~mBXn^c(dATEOkfSIm=v96&}h>@X{DbPz$|Lop)OBSd> z66Cz#{Irtt#G+IN$CUh}R0Yr6#Prml)Wnp^!jq{sKt<9JMWsc_sSIw8z7V7koSBoY z;F%2cKvPx9Z=f<`gtGY1ARm}-%gf94(h_qaNDt^|{hY)k{Y;QX{bHaQ`iGA2@&dIp Nc)I$ztaD0e0s#NI0SEv9 literal 0 HcmV?d00001 diff --git a/source/net/filebot/resources/script.remove.png b/source/net/filebot/resources/script.remove.png new file mode 100755 index 0000000000000000000000000000000000000000..3bc13c481d351dbdfc0ed9c5c06b0db37c81fd75 GIT binary patch literal 1287 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Ea{HEjtmUzPnffIy#(^vlDyqr zfHV;NblzPLq&N#aB8!2v2N=7Z%(epwmK8Xr18J~%3^B*n9%f)*I_l}-7-Dfcbh2;8 zoKTUr`PJ|KK0BUioa^Hu)m7N#^8u6ZdcdxJg*UX=lRwETSeOSHKTs}Nv*>BU;)byL32FS-%$OPS>-L?=S$u47^35GL*(B~p3VmYw zROjH5$gtMYBts<1ktHPK^W#TW;?ttF%^9!xU0FRV?EGb2Atg>-1;>S~CY);xXN8{yiyMesS_oaA0p;(pc?#NJUYNBl1A>eT&bp9$(M5+Hmws%3hy5 zVJ`>mRtBaO4`rt+sD5yD+~CS!z|em0-@2?VQ%=oHaCY!;Nc!+&K`f)v1E&Pz_f-q_ zvVLflU4K>UM1T7YrgZ$c0JVU z@=)ZOdrgPT?y8xmQkdse=DzNpz5UyQ#k=mZJeR9_c=GpZbw2xV`(-&eV>}}G#p`A* z`u*Dc%D$@BMc?&f7hJx^a<*&Up7$4Icfa2He3tC-Pf_QhcKh#sU0}D+RU@@)Qddlr zMRN+*^5UqoM;@(ec~BYu*1jf-$AZs?c{|_c>KRo_r=(8xI(D#N-ps4(Z_YH|=yt8- z)AITAKEJ=m@RGyJYnJChV1i~)Epd$~NiIrFEJ@W(0TK*G1_qY8hK9O^W+6sKR)!W< zhUU5k=2iv<(G33%!Zd(XT0wLHH5eM`8UQsIh8UPxnHpJ{m_jt1d3Q$+MMG|WN@iLm zZVh`krz`?$NCG*@Co?%UuQ-($yV@8 z26~{WD&;p&nK43Hd}xpl%(vy`<$7s}xe%lW^s|0WVv>F)NTYr+& presets = new ArrayList(); + + // TODO load presets via prefs + + final ActionPopup actionPopup = new ActionPopup("Presets", ResourceManager.getIcon("action.script")); + + if (presets.size() > 0) { + actionPopup.addDescription(new JLabel("Apply:")); + for (Preset it : presets) { + actionPopup.add(new ApplyPresetAction(it)); + } + } + + actionPopup.addDescription(new JLabel("Options:")); + actionPopup.add(new AbstractAction("New Preset", ResourceManager.getIcon("script.add")) { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + } + }); + actionPopup.add(new AbstractAction("Delete Preset", ResourceManager.getIcon("script.remove")) { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + } + }); + + return actionPopup; + } + protected ActionPopup createFetchPopup() { final ActionPopup actionPopup = new ActionPopup("Fetch & Match Data", ResourceManager.getIcon("action.fetch")); @@ -596,6 +637,84 @@ public class RenamePanel extends JComponent { } }; + protected class ShowPresetsPopupAction extends AbstractAction { + + public ShowPresetsPopupAction(String name, Icon icon) { + super(name, icon); + } + + @Override + public void actionPerformed(ActionEvent e) { + // display popup below component + JComponent source = (JComponent) e.getSource(); + createPresetsPopup().show(source, -3, source.getHeight() + 4); + } + }; + + protected class ApplyPresetAction extends AutoCompleteAction { + + private Preset preset; + + public ApplyPresetAction(Preset preset) { + super(preset.getName(), ResourceManager.getIcon("script.go"), preset.getAutoCompleteMatcher()); + this.preset = preset; + } + + public List getFiles(ActionEvent evt) { + List input = new ArrayList(); + if (preset.getInputFolder() != null) { + for (File f : FileUtilities.listFiles(preset.getInputFolder())) { + if (preset.getIncludePattern() == null || preset.getIncludePattern().matcher(f.getPath()).find()) { + input.add(f); + } + } + renameModel.clear(); + renameModel.files().addAll(input); + } else { + input.addAll(super.getFiles(evt)); + } + return input; + } + + public boolean isStrict(ActionEvent evt) { + return preset.getMatchMode() != null ? MATCH_MODE_STRICT.equals(preset.getMatchMode()) : super.isStrict(evt); + } + + public SortOrder getSortOrder(ActionEvent evt) { + return preset.getSortOrder() != null ? preset.getSortOrder() : super.getSortOrder(evt); + } + + public Locale getLocale(ActionEvent evt) { + return preset.getLanguage() != null ? preset.getLanguage() : super.getLocale(evt); + } + + @Override + public void actionPerformed(ActionEvent evt) { + if (preset.getFormat() != null) { + switch (preset.getMode()) { + case Episode: + renameModel.useFormatter(Episode.class, new ExpressionFormatter(preset.getFormat().getExpression(), EpisodeFormat.SeasonEpisode, Episode.class)); + break; + case Movie: + renameModel.useFormatter(Movie.class, new ExpressionFormatter(preset.getFormat().getExpression(), MovieFormat.NameYear, Movie.class)); + break; + case Music: + renameModel.useFormatter(AudioTrack.class, new ExpressionFormatter(preset.getFormat().getExpression(), new AudioTrackFormat(), AudioTrack.class)); + break; + case File: + renameModel.useFormatter(File.class, new ExpressionFormatter(preset.getFormat().getExpression(), new FileNameFormat(), File.class)); + break; + } + } + + if (preset.getRenameAction() != null) { + new SetRenameAction(preset.getRenameAction(), preset.getRenameAction().getDisplayName(), ResourceManager.getIcon("rename.action." + preset.getRenameAction().toString().toLowerCase())).actionPerformed(evt); + } + + super.actionPerformed(evt); + } + } + protected class SetRenameMode extends AbstractAction { private final boolean activate; @@ -640,7 +759,7 @@ public class RenamePanel extends JComponent { protected class AutoCompleteAction extends AbstractAction { - private final AutoCompleteMatcher matcher; + protected final AutoCompleteMatcher matcher; public AutoCompleteAction(String name, Icon icon, AutoCompleteMatcher matcher) { super(name, icon); @@ -658,16 +777,36 @@ public class RenamePanel extends JComponent { }); } + public List getFiles(ActionEvent evt) { + return renameModel.files(); + } + + public boolean isStrict(ActionEvent evt) { + return isMatchModeStrict(); + } + + public SortOrder getSortOrder(ActionEvent evt) { + return SortOrder.forName(persistentPreferredEpisodeOrder.getValue()); + } + + private Locale getLocale(ActionEvent evt) { + return new Locale(persistentPreferredLanguage.getValue()); + } + + private boolean isAutoDetectionEnabled(ActionEvent evt) { + return !isShiftOrAltDown(evt); // skip name auto-detection if SHIFT is pressed + } + @Override public void actionPerformed(final ActionEvent evt) { // clear names list renameModel.values().clear(); - final List remainingFiles = new LinkedList(renameModel.files()); - final boolean strict = isMatchModeStrict(); - final SortOrder order = SortOrder.forName(persistentPreferredEpisodeOrder.getValue()); - final Locale locale = new Locale(persistentPreferredLanguage.getValue()); - final boolean autodetection = !isShiftOrAltDown(evt); // skip name auto-detection if SHIFT is pressed + final List remainingFiles = new LinkedList(getFiles(evt)); + final boolean strict = isStrict(evt); + final SortOrder order = getSortOrder(evt); + final Locale locale = getLocale(evt); + final boolean autodetection = isAutoDetectionEnabled(evt); if (isMacSandbox()) { if (!MacAppUtilities.askUnlockFolders(getWindow(RenamePanel.this), remainingFiles)) { @@ -721,6 +860,7 @@ public class RenamePanel extends JComponent { worker.execute(); } + } }